RandomX: returned old soft AES impl and auto-select between the two
This commit is contained in:
parent
852fe14604
commit
8d1168385a
16 changed files with 194 additions and 101 deletions
|
@ -343,7 +343,6 @@ namespace randomx {
|
|||
r[j] = k;
|
||||
}
|
||||
|
||||
constexpr uint64_t instr_mask = (uint64_t(-1) - (0xFFFF << 8)) | ((RegistersCount - 1) << 8) | ((RegistersCount - 1) << 16);
|
||||
for (int i = 0, n = static_cast<int>(RandomX_CurrentConfig.ProgramSize); i < n; i += 4) {
|
||||
Instruction& instr1 = prog(i);
|
||||
Instruction& instr2 = prog(i + 1);
|
||||
|
@ -355,16 +354,9 @@ namespace randomx {
|
|||
InstructionGeneratorX86 gen3 = engine[instr3.opcode];
|
||||
InstructionGeneratorX86 gen4 = engine[instr4.opcode];
|
||||
|
||||
*((uint64_t*)&instr1) &= instr_mask;
|
||||
(this->*gen1)(instr1);
|
||||
|
||||
*((uint64_t*)&instr2) &= instr_mask;
|
||||
(this->*gen2)(instr2);
|
||||
|
||||
*((uint64_t*)&instr3) &= instr_mask;
|
||||
(this->*gen3)(instr3);
|
||||
|
||||
*((uint64_t*)&instr4) &= instr_mask;
|
||||
(this->*gen4)(instr4);
|
||||
}
|
||||
|
||||
|
@ -518,7 +510,7 @@ namespace randomx {
|
|||
template void JitCompilerX86::genAddressReg<true>(const Instruction& instr, const uint32_t src, uint8_t* code, uint32_t& codePos);
|
||||
|
||||
FORCE_INLINE void JitCompilerX86::genAddressRegDst(const Instruction& instr, uint8_t* code, uint32_t& codePos) {
|
||||
const uint32_t dst = static_cast<uint32_t>(instr.dst) << 16;
|
||||
const uint32_t dst = static_cast<uint32_t>(instr.dst % RegistersCount) << 16;
|
||||
*(uint32_t*)(code + codePos) = 0x24808d41 + dst;
|
||||
codePos += (dst == (RegisterNeedsSib << 16)) ? 4 : 3;
|
||||
|
||||
|
@ -540,8 +532,8 @@ namespace randomx {
|
|||
uint32_t pos = codePos;
|
||||
uint8_t* const p = code + pos;
|
||||
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t sib = (instr.getModShift() << 6) | (instr.src << 3) | dst;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
const uint32_t sib = (instr.getModShift() << 6) | ((instr.src % RegistersCount) << 3) | dst;
|
||||
|
||||
uint32_t k = 0x048d4f + (dst << 19);
|
||||
if (dst == RegisterNeedsDisplacement)
|
||||
|
@ -560,8 +552,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -585,8 +577,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
*(uint32_t*)(p + pos) = 0xc02b4d + (dst << 19) + (src << 16);
|
||||
|
@ -606,8 +598,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -627,8 +619,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
emit32(0xc0af0f4d + ((dst * 8 + src) << 24), p, pos);
|
||||
|
@ -647,8 +639,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -668,8 +660,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
*(uint32_t*)(p + pos) = 0xc08b49 + (dst << 16);
|
||||
*(uint32_t*)(p + pos + 3) = 0xe0f749 + (src << 16);
|
||||
|
@ -684,8 +676,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
*(uint32_t*)(p + pos) = 0xC4D08B49 + (dst << 16);
|
||||
*(uint32_t*)(p + pos + 4) = 0xC0F6FB42 + (dst << 27) + (src << 24);
|
||||
|
@ -699,8 +691,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<false>(instr, src, p, pos);
|
||||
|
@ -723,8 +715,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<false>(instr, src, p, pos);
|
||||
|
@ -746,8 +738,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
*(uint64_t*)(p + pos) = 0x8b4ce8f749c08b49ull + (dst << 16) + (src << 40);
|
||||
pos += 8;
|
||||
|
@ -761,8 +753,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<false>(instr, src, p, pos);
|
||||
|
@ -792,7 +784,7 @@ namespace randomx {
|
|||
|
||||
emit64(randomx_reciprocal_fast(divisor), p, pos);
|
||||
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
emit32(0xc0af0f4c + (dst << 27), p, pos);
|
||||
|
||||
registerUsage[dst] = pos;
|
||||
|
@ -805,7 +797,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
*(uint32_t*)(p + pos) = 0xd8f749 + (dst << 16);
|
||||
pos += 3;
|
||||
|
||||
|
@ -817,8 +809,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
*(uint32_t*)(p + pos) = 0xc0334d + (((dst << 3) + src) << 16);
|
||||
|
@ -838,8 +830,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -859,8 +851,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
*(uint64_t*)(p + pos) = 0xc8d349c88b41ull + (src << 16) + (dst << 40);
|
||||
|
@ -880,8 +872,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
*(uint64_t*)(p + pos) = 0xc0d349c88b41ull + (src << 16) + (dst << 40);
|
||||
|
@ -901,8 +893,8 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t dst = instr.dst;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegistersCount;
|
||||
|
||||
if (src != dst) {
|
||||
*(uint32_t*)(p + pos) = 0xc0874d + (((dst << 3) + src) << 16);
|
||||
|
@ -918,7 +910,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t dst = instr.dst;
|
||||
const uint64_t dst = instr.dst % RegistersCount;
|
||||
|
||||
*(uint64_t*)(p + pos) = 0x01c0c60f66ull + (((dst << 3) + dst) << 24);
|
||||
pos += 5;
|
||||
|
@ -943,7 +935,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegisterCountFlt;
|
||||
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -971,7 +963,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint32_t dst = instr.dst % RegisterCountFlt;
|
||||
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -1010,7 +1002,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
const uint64_t dst = instr.dst % RegisterCountFlt;
|
||||
|
||||
genAddressReg<true>(instr, src, p, pos);
|
||||
|
@ -1046,7 +1038,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint32_t src = instr.src;
|
||||
const uint32_t src = instr.src % RegistersCount;
|
||||
|
||||
*(uint32_t*)(p + pos) = 0x00C08B49 + (src << 16);
|
||||
const int rotate = (static_cast<int>(instr.getImm32() & 63) - 2) & 63;
|
||||
|
@ -1070,7 +1062,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const uint64_t src = instr.src;
|
||||
const uint64_t src = instr.src % RegistersCount;
|
||||
|
||||
const uint64_t rotate = (static_cast<int>(instr.getImm32() & 63) - 2) & 63;
|
||||
*(uint64_t*)(p + pos) = 0xC0F0FBC3C4ULL | (src << 32) | (rotate << 40);
|
||||
|
@ -1093,7 +1085,7 @@ namespace randomx {
|
|||
uint8_t* const p = code;
|
||||
uint32_t pos = codePos;
|
||||
|
||||
const int reg = instr.dst;
|
||||
const int reg = instr.dst % RegistersCount;
|
||||
int32_t jmp_offset = registerUsage[reg] - (pos + 16);
|
||||
|
||||
if (BranchesWithin32B) {
|
||||
|
@ -1140,7 +1132,7 @@ namespace randomx {
|
|||
uint32_t pos = codePos;
|
||||
|
||||
genAddressRegDst(instr, p, pos);
|
||||
emit32(0x0604894c + (static_cast<uint32_t>(instr.src) << 19), p, pos);
|
||||
emit32(0x0604894c + (static_cast<uint32_t>(instr.src % RegistersCount) << 19), p, pos);
|
||||
|
||||
codePos = pos;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue