From 9b1f020a8b54f00403c45ee4055cc0657de7678d Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 17 May 2021 11:26:40 +0200 Subject: [PATCH] Enabled IMUL_RCP optimization for light mode mining Better fix for #2377 --- .../randomx/asm/program_read_dataset_sshash_fin.inc | 2 +- .../randomx/asm/program_read_dataset_sshash_init.inc | 2 +- src/crypto/randomx/jit_compiler_x86.cpp | 10 +++++----- src/crypto/randomx/jit_compiler_x86.hpp | 2 +- src/crypto/randomx/randomx.cpp | 5 ----- src/crypto/randomx/randomx.h | 1 - 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/crypto/randomx/asm/program_read_dataset_sshash_fin.inc b/src/crypto/randomx/asm/program_read_dataset_sshash_fin.inc index f5a067d2..e64c0bab 100644 --- a/src/crypto/randomx/asm/program_read_dataset_sshash_fin.inc +++ b/src/crypto/randomx/asm/program_read_dataset_sshash_fin.inc @@ -7,4 +7,4 @@ xor r13, qword ptr [rsp+16] xor r14, qword ptr [rsp+8] xor r15, qword ptr [rsp+0] - add rsp, 72 \ No newline at end of file + add rsp, 200 \ No newline at end of file diff --git a/src/crypto/randomx/asm/program_read_dataset_sshash_init.inc b/src/crypto/randomx/asm/program_read_dataset_sshash_init.inc index 6fe9525d..b4be42f4 100644 --- a/src/crypto/randomx/asm/program_read_dataset_sshash_init.inc +++ b/src/crypto/randomx/asm/program_read_dataset_sshash_init.inc @@ -1,4 +1,4 @@ - sub rsp, 72 + sub rsp, 200 mov qword ptr [rsp+64], rbx mov qword ptr [rsp+56], r8 mov qword ptr [rsp+48], r9 diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index d7ebc25f..04db010a 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -320,7 +320,7 @@ namespace randomx { vm_flags = flags; - generateProgramPrologue(prog, pcfg, false); + generateProgramPrologue(prog, pcfg); uint8_t* p; uint32_t n; @@ -339,8 +339,8 @@ namespace randomx { } void JitCompilerX86::generateProgramLight(Program& prog, ProgramConfiguration& pcfg, uint32_t datasetOffset) { - generateProgramPrologue(prog, pcfg, true); - emit(RandomX_CurrentConfig.codeReadDatasetLightSshInitTweaked, readDatasetLightInitSize, code, codePos); + generateProgramPrologue(prog, pcfg); + emit(codeReadDatasetLightSshInit, readDatasetLightInitSize, code, codePos); *(uint32_t*)(code + codePos) = 0xc381; codePos += 2; emit32(datasetOffset / CacheLineSize, code, codePos); @@ -415,7 +415,7 @@ namespace randomx { } } - void JitCompilerX86::generateProgramPrologue(Program& prog, ProgramConfiguration& pcfg, bool light) { + void JitCompilerX86::generateProgramPrologue(Program& prog, ProgramConfiguration& pcfg) { codePos = ADDR(randomx_program_prologue_first_load) - ADDR(randomx_program_prologue); *(uint32_t*)(code + codePos + 4) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated; *(uint32_t*)(code + codePos + 14) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated; @@ -429,7 +429,7 @@ namespace randomx { # endif imul_rcp_storage = code + (ADDR(randomx_program_imul_rcp_store) - codePrologue) + 2; - imul_rcp_storage_used = light ? 0xFFFFFFFFUL : 0; + imul_rcp_storage_used = 0; memcpy(imul_rcp_storage - 34, &pcfg.eMask, sizeof(pcfg.eMask)); codePos = codePosFirst; diff --git a/src/crypto/randomx/jit_compiler_x86.hpp b/src/crypto/randomx/jit_compiler_x86.hpp index b1bd42aa..abc8e74f 100644 --- a/src/crypto/randomx/jit_compiler_x86.hpp +++ b/src/crypto/randomx/jit_compiler_x86.hpp @@ -107,7 +107,7 @@ namespace randomx { uint8_t* imul_rcp_storage = nullptr; uint32_t imul_rcp_storage_used = 0; - void generateProgramPrologue(Program&, ProgramConfiguration&, bool light); + void generateProgramPrologue(Program&, ProgramConfiguration&); void generateProgramEpilogue(Program&, ProgramConfiguration&); template static void genAddressReg(const Instruction&, const uint32_t src, uint8_t* code, uint32_t& codePos); diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index 527cca92..00af0dc5 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -177,11 +177,6 @@ RandomX_ConfigurationBase::RandomX_ConfigurationBase() memcpy(codeReadDatasetRyzenTweaked, a, b - a); codeReadDatasetRyzenTweakedSize = b - a; } - { - const uint8_t* a = addr(randomx_program_read_dataset_sshash_init); - const uint8_t* b = addr(randomx_program_read_dataset_sshash_fin); - memcpy(codeReadDatasetLightSshInitTweaked, a, b - a); - } { const uint8_t* a = addr(randomx_prefetch_scratchpad); const uint8_t* b = addr(randomx_prefetch_scratchpad_end); diff --git a/src/crypto/randomx/randomx.h b/src/crypto/randomx/randomx.h index f81df9db..ca79f778 100644 --- a/src/crypto/randomx/randomx.h +++ b/src/crypto/randomx/randomx.h @@ -129,7 +129,6 @@ struct RandomX_ConfigurationBase uint32_t codeReadDatasetTweakedSize; uint8_t codeReadDatasetRyzenTweaked[72]; uint32_t codeReadDatasetRyzenTweakedSize; - uint8_t codeReadDatasetLightSshInitTweaked[68]; uint8_t codePrefetchScratchpadTweaked[32]; uint32_t AddressMask_Calculated[4];