mirror of
https://github.com/wownero/RandomX.git
synced 2026-10-17 23:41:39 +02:00
ASM code generator for "small" programs that fit into the uOP cache
This commit is contained in:
@@ -25,6 +25,12 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace RandomX {
|
||||
|
||||
constexpr int mantissaSize = 52;
|
||||
constexpr int exponentSize = 11;
|
||||
constexpr uint64_t mantissaMask = (1ULL << mantissaSize) - 1;
|
||||
constexpr uint64_t exponentMask = (1ULL << exponentSize) - 1;
|
||||
constexpr int exponentBias = 1023;
|
||||
|
||||
CompiledVirtualMachine::CompiledVirtualMachine() {
|
||||
totalSize = 0;
|
||||
}
|
||||
@@ -37,25 +43,42 @@ namespace RandomX {
|
||||
memcpy(scratchpad, mem.ds.dataset + ScratchpadSize * index, ScratchpadSize);
|
||||
}
|
||||
|
||||
static uint64_t getSmallPositiveFloatBits(uint64_t entropy) {
|
||||
auto exponent = entropy >> 60; //0..15
|
||||
auto mantissa = entropy & mantissaMask;
|
||||
exponent += exponentBias;
|
||||
exponent &= exponentMask;
|
||||
exponent <<= mantissaSize;
|
||||
return exponent | mantissa;
|
||||
}
|
||||
|
||||
void CompiledVirtualMachine::initializeProgram(const void* seed) {
|
||||
Pcg32 gen(seed);
|
||||
for (unsigned i = 0; i < sizeof(reg) / sizeof(Pcg32::result_type); ++i) {
|
||||
*(((uint32_t*)®) + i) = gen();
|
||||
}
|
||||
FPINIT();
|
||||
for (int i = 0; i < RegistersCount; ++i) {
|
||||
/*for (int i = 0; i < RegistersCount / 2; ++i) {
|
||||
reg.f[i].lo.f64 = (double)reg.f[i].lo.i64;
|
||||
reg.f[i].hi.f64 = (double)reg.f[i].hi.i64;
|
||||
}
|
||||
for (int i = 0; i < RegistersCount / 2; ++i) {
|
||||
reg.g[i].lo.f64 = std::abs((double)reg.g[i].lo.i64);
|
||||
reg.g[i].hi.f64 = std::abs((double)reg.g[i].hi.i64);
|
||||
}*/
|
||||
for (int i = 0; i < RegistersCount / 2; ++i) {
|
||||
reg.a[i].lo.u64 = getSmallPositiveFloatBits(reg.f[i].lo.u64);
|
||||
reg.a[i].hi.u64 = getSmallPositiveFloatBits(reg.f[i].hi.u64);
|
||||
}
|
||||
compiler.generateProgram(gen);
|
||||
mem.ma = (gen() ^ *(((uint32_t*)seed) + 4)) & ~7;
|
||||
mem.mx = *(((uint32_t*)seed) + 5);
|
||||
}
|
||||
|
||||
void CompiledVirtualMachine::execute() {
|
||||
//executeProgram(reg, mem, scratchpad, readDataset);
|
||||
executeProgram(reg, mem, scratchpad, InstructionCount);
|
||||
totalSize += compiler.getCodeSize();
|
||||
compiler.getProgramFunc()(reg, mem, scratchpad);
|
||||
//compiler.getProgramFunc()(reg, mem, scratchpad);
|
||||
#ifdef TRACEVM
|
||||
for (int32_t i = InstructionCount - 1; i >= 0; --i) {
|
||||
std::cout << std::hex << tracepad[i].u64 << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user