mirror of
https://github.com/wownero/RandomX.git
synced 2026-12-05 06:24:05 +01:00
Fixed IMUL_RCP if divisor is a power of 2
This commit is contained in:
@@ -428,9 +428,10 @@ namespace randomx {
|
||||
}
|
||||
|
||||
void AssemblyGeneratorX86::h_IMUL_RCP(Instruction& instr, int i) {
|
||||
if (instr.getImm32() != 0) {
|
||||
uint64_t divisor = instr.getImm32();
|
||||
if (!isPowerOf2(divisor)) {
|
||||
registerUsage[instr.dst].lastUsed = i;
|
||||
asmCode << "\tmov rax, " << randomx_reciprocal(instr.getImm32()) << std::endl;
|
||||
asmCode << "\tmov rax, " << randomx_reciprocal(divisor) << std::endl;
|
||||
asmCode << "\timul " << regR[instr.dst] << ", rax" << std::endl;
|
||||
traceint(instr);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,10 @@ namespace randomx {
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
inline bool isPowerOf2(uint64_t x) {
|
||||
return (x & (x - 1)) == 0;
|
||||
}
|
||||
|
||||
constexpr int mantissaSize = 52;
|
||||
constexpr int exponentSize = 11;
|
||||
constexpr uint64_t mantissaMask = (1ULL << mantissaSize) - 1;
|
||||
|
||||
@@ -266,8 +266,6 @@ namespace randomx {
|
||||
SuperscalarProgram& prog = programs[j];
|
||||
for (unsigned i = 0; i < prog.getSize(); ++i) {
|
||||
Instruction& instr = prog(i);
|
||||
instr.src %= RegistersCount;
|
||||
instr.dst %= RegistersCount;
|
||||
generateSuperscalarCode(instr, reciprocalCache);
|
||||
}
|
||||
emit(codeShhLoad, codeSshLoadSize);
|
||||
@@ -614,10 +612,11 @@ namespace randomx {
|
||||
}
|
||||
|
||||
void JitCompilerX86::h_IMUL_RCP(Instruction& instr, int i) {
|
||||
if (instr.getImm32() != 0) {
|
||||
uint64_t divisor = instr.getImm32();
|
||||
if (!isPowerOf2(divisor)) {
|
||||
registerUsage[instr.dst].lastUsed = i;
|
||||
emit(MOV_RAX_I);
|
||||
emit64(randomx_reciprocal(instr.getImm32()));
|
||||
emit64(randomx_reciprocal(divisor));
|
||||
emit(REX_IMUL_RM);
|
||||
emitByte(0xc0 + 8 * instr.dst);
|
||||
}
|
||||
|
||||
@@ -435,8 +435,8 @@ namespace randomx {
|
||||
} break;
|
||||
|
||||
CASE_REP(IMUL_RCP) {
|
||||
uint32_t divisor = instr.getImm32();
|
||||
if (divisor != 0) {
|
||||
uint64_t divisor = instr.getImm32();
|
||||
if (!isPowerOf2(divisor)) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
ibc.type = InstructionType::IMUL_R;
|
||||
ibc.idst = &r[dst];
|
||||
|
||||
Reference in New Issue
Block a user