RandomX refactoring, moved more stuff to compile time
Small x86 JIT compiler speedup.
This commit is contained in:
parent
d11a313d88
commit
c7476e076b
11 changed files with 149 additions and 160 deletions
|
@ -79,9 +79,9 @@ namespace randomx {
|
|||
}
|
||||
|
||||
void BytecodeMachine::compileInstruction(RANDOMX_GEN_ARGS) {
|
||||
int opcode = instr.opcode;
|
||||
uint32_t opcode = instr.opcode;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IADD_RS) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IADD_RS) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IADD_RS;
|
||||
|
@ -99,8 +99,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IADD_RS;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IADD_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IADD_M) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IADD_M;
|
||||
|
@ -117,8 +118,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IADD_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_ISUB_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_ISUB_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::ISUB_R;
|
||||
|
@ -133,8 +135,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_ISUB_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_ISUB_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_ISUB_M) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::ISUB_M;
|
||||
|
@ -151,8 +154,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_ISUB_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IMUL_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IMUL_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IMUL_R;
|
||||
|
@ -167,8 +171,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IMUL_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IMUL_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IMUL_M) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IMUL_M;
|
||||
|
@ -185,8 +190,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IMUL_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IMULH_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IMULH_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IMULH_R;
|
||||
|
@ -195,8 +201,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IMULH_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IMULH_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IMULH_M) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IMULH_M;
|
||||
|
@ -213,8 +220,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IMULH_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_ISMULH_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_ISMULH_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::ISMULH_R;
|
||||
|
@ -223,8 +231,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_ISMULH_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_ISMULH_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_ISMULH_M) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::ISMULH_M;
|
||||
|
@ -241,8 +250,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_ISMULH_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IMUL_RCP) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IMUL_RCP) {
|
||||
uint64_t divisor = instr.getImm32();
|
||||
if (!isZeroOrPowerOf2(divisor)) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
|
@ -257,16 +267,18 @@ namespace randomx {
|
|||
}
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IMUL_RCP;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_INEG_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_INEG_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
ibc.type = InstructionType::INEG_R;
|
||||
ibc.idst = &nreg->r[dst];
|
||||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_INEG_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IXOR_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IXOR_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IXOR_R;
|
||||
|
@ -281,8 +293,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IXOR_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IXOR_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IXOR_M) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IXOR_M;
|
||||
|
@ -299,8 +312,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IXOR_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IROR_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IROR_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IROR_R;
|
||||
|
@ -315,8 +329,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IROR_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_IROL_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_IROL_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::IROL_R;
|
||||
|
@ -331,8 +346,9 @@ namespace randomx {
|
|||
registerUsage[dst] = i;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_IROL_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_ISWAP_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_ISWAP_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
if (src != dst) {
|
||||
|
@ -347,8 +363,9 @@ namespace randomx {
|
|||
}
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_ISWAP_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FSWAP_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FSWAP_R) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
ibc.type = InstructionType::FSWAP_R;
|
||||
if (dst < RegisterCountFlt)
|
||||
|
@ -357,8 +374,9 @@ namespace randomx {
|
|||
ibc.fdst = &nreg->e[dst - RegisterCountFlt];
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FSWAP_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FADD_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FADD_R) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
auto src = instr.src % RegisterCountFlt;
|
||||
ibc.type = InstructionType::FADD_R;
|
||||
|
@ -366,8 +384,9 @@ namespace randomx {
|
|||
ibc.fsrc = &nreg->a[src];
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FADD_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FADD_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FADD_M) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::FADD_M;
|
||||
|
@ -377,8 +396,9 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FADD_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FSUB_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FSUB_R) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
auto src = instr.src % RegisterCountFlt;
|
||||
ibc.type = InstructionType::FSUB_R;
|
||||
|
@ -386,8 +406,9 @@ namespace randomx {
|
|||
ibc.fsrc = &nreg->a[src];
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FSUB_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FSUB_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FSUB_M) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::FSUB_M;
|
||||
|
@ -397,15 +418,17 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FSUB_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FSCAL_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FSCAL_R) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
ibc.fdst = &nreg->f[dst];
|
||||
ibc.type = InstructionType::FSCAL_R;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FSCAL_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FMUL_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FMUL_R) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
auto src = instr.src % RegisterCountFlt;
|
||||
ibc.type = InstructionType::FMUL_R;
|
||||
|
@ -413,8 +436,9 @@ namespace randomx {
|
|||
ibc.fsrc = &nreg->a[src];
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FMUL_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FDIV_M) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FDIV_M) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::FDIV_M;
|
||||
|
@ -424,41 +448,44 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FDIV_M;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_FSQRT_R) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_FSQRT_R) {
|
||||
auto dst = instr.dst % RegisterCountFlt;
|
||||
ibc.type = InstructionType::FSQRT_R;
|
||||
ibc.fdst = &nreg->e[dst];
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_FSQRT_R;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_CBRANCH) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_CBRANCH) {
|
||||
ibc.type = InstructionType::CBRANCH;
|
||||
//jump condition
|
||||
int creg = instr.dst % RegistersCount;
|
||||
ibc.idst = &nreg->r[creg];
|
||||
ibc.target = registerUsage[creg];
|
||||
int shift = instr.getModCond() + RandomX_CurrentConfig.JumpOffset;
|
||||
ibc.imm = signExtend2sCompl(instr.getImm32()) | (1ULL << shift);
|
||||
if (RandomX_CurrentConfig.JumpOffset > 0 || shift > 0) //clear the bit below the condition mask - this limits the number of successive jumps to 2
|
||||
ibc.imm &= ~(1ULL << (shift - 1));
|
||||
ibc.memMask = RandomX_CurrentConfig.ConditionMask_Calculated << shift;
|
||||
const int shift = instr.getModCond();
|
||||
ibc.imm = signExtend2sCompl(instr.getImm32()) | ((1ULL << RandomX_ConfigurationBase::JumpOffset) << shift);
|
||||
ibc.imm &= ~((1ULL << (RandomX_ConfigurationBase::JumpOffset - 1)) << shift);
|
||||
ibc.memMask = RandomX_ConfigurationBase::ConditionMask_Calculated << shift;
|
||||
//mark all registers as used
|
||||
for (unsigned j = 0; j < RegistersCount; ++j) {
|
||||
registerUsage[j] = i;
|
||||
}
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_CBRANCH;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_CFROUND) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_CFROUND) {
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.type = InstructionType::CFROUND;
|
||||
ibc.imm = instr.getImm32() & 63;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_CFROUND;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_ISTORE) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_ISTORE) {
|
||||
auto dst = instr.dst % RegistersCount;
|
||||
auto src = instr.src % RegistersCount;
|
||||
ibc.type = InstructionType::ISTORE;
|
||||
|
@ -471,8 +498,9 @@ namespace randomx {
|
|||
ibc.memMask = ScratchpadL3Mask;
|
||||
return;
|
||||
}
|
||||
opcode -= RandomX_CurrentConfig.RANDOMX_FREQ_ISTORE;
|
||||
|
||||
if (opcode < RandomX_CurrentConfig.CEIL_NOP) {
|
||||
if (opcode < RandomX_CurrentConfig.RANDOMX_FREQ_NOP) {
|
||||
ibc.type = InstructionType::NOP;
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue