Fixed IMUL_RCP if divisor is a power of 2

This commit is contained in:
tevador
2019-05-04 18:00:17 +02:00
parent 197cd90e07
commit b1f1e1d6ad
5 changed files with 14 additions and 10 deletions
+3 -2
View File
@@ -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);
}
+4
View File
@@ -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;
+3 -4
View File
@@ -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);
}
+2 -2
View File
@@ -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];