@@ -44,14 +44,12 @@ namespace randomx {
4444 static const char * regScratchpadAddr = " rsi" ;
4545
4646 void AssemblyGeneratorX86::generateProgram (Program& prog) {
47- for (unsigned i = 0 ; i < 8 ; ++i) {
47+ for (unsigned i = 0 ; i < RegistersCount ; ++i) {
4848 registerUsage[i] = -1 ;
4949 }
5050 asmCode.str (std::string ()); // clear
5151 for (unsigned i = 0 ; i < prog.getSize (); ++i) {
52- #if RANDOMX_JUMP
5352 asmCode << " randomx_isn_" << i << " :" << std::endl;
54- #endif
5553 Instruction& instr = prog (i);
5654 instr.src %= RegistersCount;
5755 instr.dst %= RegistersCount;
@@ -261,7 +259,7 @@ namespace randomx {
261259 void AssemblyGeneratorX86::genAddressRegDst (Instruction& instr, int maskAlign = 8 ) {
262260 asmCode << " \t lea eax, [" << regR32[instr.dst ] << std::showpos << (int32_t )instr.getImm32 () << std::noshowpos << " ]" << std::endl;
263261 int mask;
264- if (instr.getModCond ()) {
262+ if (instr.getModCond () < StoreL3Condition ) {
265263 mask = instr.getModMem () ? ScratchpadL1Mask : ScratchpadL2Mask;
266264 }
267265 else {
@@ -277,9 +275,9 @@ namespace randomx {
277275 void AssemblyGeneratorX86::h_IADD_RS (Instruction& instr, int i) {
278276 registerUsage[instr.dst ] = i;
279277 if (instr.dst == RegisterNeedsDisplacement)
280- asmCode << " \t lea " << regR[instr.dst ] << " , [" << regR[instr.dst ] << " +" << regR[instr.src ] << " *" << (1 << (instr.getModMem ())) << std::showpos << (int32_t )instr.getImm32 () << std::noshowpos << " ]" << std::endl;
278+ asmCode << " \t lea " << regR[instr.dst ] << " , [" << regR[instr.dst ] << " +" << regR[instr.src ] << " *" << (1 << (instr.getModShift ())) << std::showpos << (int32_t )instr.getImm32 () << std::noshowpos << " ]" << std::endl;
281279 else
282- asmCode << " \t lea " << regR[instr.dst ] << " , [" << regR[instr.dst ] << " +" << regR[instr.src ] << " *" << (1 << (instr.getModMem ())) << " ]" << std::endl;
280+ asmCode << " \t lea " << regR[instr.dst ] << " , [" << regR[instr.dst ] << " +" << regR[instr.src ] << " *" << (1 << (instr.getModShift ())) << " ]" << std::endl;
283281 traceint (instr);
284282 }
285283
@@ -542,55 +540,18 @@ namespace randomx {
542540 tracenop (instr);
543541 }
544542
545- static inline const char * condition (Instruction& instr) {
546- switch (instr.getModCond ())
547- {
548- case 0 :
549- return " be" ;
550- case 1 :
551- return " a" ;
552- case 2 :
553- return " s" ;
554- case 3 :
555- return " ns" ;
556- case 4 :
557- return " o" ;
558- case 5 :
559- return " no" ;
560- case 6 :
561- return " l" ;
562- case 7 :
563- return " ge" ;
564- default :
565- UNREACHABLE;
566- }
567- }
568-
569- void AssemblyGeneratorX86::handleCondition (Instruction& instr, int i) {
570- const int shift = instr.getModShift ();
571- const int conditionMask = ((1 << RANDOMX_JUMP_BITS) - 1 ) << shift;
543+ void AssemblyGeneratorX86::h_CBRANCH (Instruction& instr, int i) {
572544 int reg = getConditionRegister ();
573545 int target = registerUsage[reg] + 1 ;
574- registerUsage[reg] = i ;
575- asmCode << " \t add " << regR[reg] << " , " << (1 << shift) << std::endl;
576- asmCode << " \t test " << regR[reg] << " , " << conditionMask << std::endl;
546+ int shift = instr. getModCond () ;
547+ asmCode << " \t add " << regR[reg] << " , " << (int32_t )(instr. getImm32 () | ( 1 << shift) ) << std::endl;
548+ asmCode << " \t test " << regR[reg] << " , " << (ConditionMask << shift) << std::endl;
577549 asmCode << " \t jz randomx_isn_" << target << std::endl;
578- for (unsigned j = 0 ; j < 8 ; ++j) { // mark all registers as used
550+ for (unsigned j = 0 ; j < RegistersCount ; ++j) { // mark all registers as used
579551 registerUsage[j] = i;
580552 }
581553 }
582554
583- void AssemblyGeneratorX86::h_COND_R (Instruction& instr, int i) {
584- #if RANDOMX_JUMP
585- handleCondition (instr, i);
586- #endif
587- asmCode << " \t xor ecx, ecx" << std::endl;
588- asmCode << " \t cmp " << regR32[instr.src ] << " , " << (int32_t )instr.getImm32 () << std::endl;
589- asmCode << " \t set" << condition (instr) << " cl" << std::endl;
590- asmCode << " \t add " << regR[instr.dst ] << " , rcx" << std::endl;
591- traceint (instr);
592- }
593-
594555 void AssemblyGeneratorX86::h_ISTORE (Instruction& instr, int i) {
595556 genAddressRegDst (instr);
596557 asmCode << " \t mov qword ptr [" << regScratchpadAddr << " +rax], " << regR[instr.src ] << std::endl;
@@ -632,7 +593,7 @@ namespace randomx {
632593 INST_HANDLE (FMUL_R)
633594 INST_HANDLE (FDIV_M)
634595 INST_HANDLE (FSQRT_R)
635- INST_HANDLE (COND_R )
596+ INST_HANDLE (CBRANCH )
636597 INST_HANDLE (CFROUND)
637598 INST_HANDLE (ISTORE)
638599 INST_HANDLE (NOP)
0 commit comments