Skip to content

Commit 4c66b23

Browse files
committed
Formatting & refactoring
1 parent 87b8253 commit 4c66b23

12 files changed

+47
-187
lines changed

src/assembly_generator_x86.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ namespace randomx {
3434
static const char* regE[4] = { "xmm4", "xmm5", "xmm6", "xmm7" };
3535
static const char* regA[4] = { "xmm8", "xmm9", "xmm10", "xmm11" };
3636

37-
static const char* fsumInstr[4] = { "paddb", "paddw", "paddd", "paddq" };
38-
3937
static const char* regA4 = "xmm12";
4038
static const char* dblMin = "xmm13";
4139
static const char* absMask = "xmm14";
@@ -58,7 +56,6 @@ namespace randomx {
5856
instr.src %= RegistersCount;
5957
instr.dst %= RegistersCount;
6058
generateCode(instr, i);
61-
//asmCode << std::endl;
6259
}
6360
}
6461

@@ -494,7 +491,6 @@ namespace randomx {
494491
//2 uOPs
495492
void AssemblyGeneratorX86::h_ISWAP_R(Instruction& instr, int i) {
496493
if (instr.src != instr.dst) {
497-
//std::swap(registerUsage[instr.dst], registerUsage[instr.src]);
498494
registerUsage[instr.dst] = i;
499495
registerUsage[instr.src] = i;
500496
asmCode << "\txchg " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
@@ -516,7 +512,6 @@ namespace randomx {
516512
instr.dst %= 4;
517513
instr.src %= 4;
518514
asmCode << "\taddpd " << regF[instr.dst] << ", " << regA[instr.src] << std::endl;
519-
//asmCode << "\t" << fsumInstr[instr.mod % 4] << " " << signMask << ", " << regF[instr.dst] << std::endl;
520515
traceflt(instr);
521516
}
522517

@@ -534,7 +529,6 @@ namespace randomx {
534529
instr.dst %= 4;
535530
instr.src %= 4;
536531
asmCode << "\tsubpd " << regF[instr.dst] << ", " << regA[instr.src] << std::endl;
537-
//asmCode << "\t" << fsumInstr[instr.mod % 4] << " " << signMask << ", " << regF[instr.dst] << std::endl;
538532
traceflt(instr);
539533
}
540534

src/configuration.h

-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
4040
//Dataset size in bytes. Must be a power of 2.
4141
#define RANDOMX_DATASET_SIZE (2ULL * 1024 * 1024 * 1024)
4242

43-
//Number of blocks per epoch
44-
#define RANDOMX_EPOCH_BLOCKS 2048
45-
46-
//Number of blocks between the seed block and the start of new epoch
47-
#define RANDOMX_EPOCH_LAG 64
48-
4943
//Number of instructions in a RandomX program
5044
#define RANDOMX_PROGRAM_SIZE 256
5145

src/dataset.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
4040
#include "argon2.h"
4141
#include "argon2_core.h"
4242

43-
#if defined(__SSE2__)
44-
#include <wmmintrin.h>
45-
#define PREFETCHNTA(x) _mm_prefetch((const char *)(x), _MM_HINT_NTA)
46-
#else
47-
#define PREFETCH(memory)
48-
#endif
49-
5043
randomx_dataset::~randomx_dataset() {
5144

5245
}

src/instruction.hpp

+21-24
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,27 @@ namespace randomx {
4343
constexpr int ISMULH_R = 10;
4444
constexpr int ISMULH_M = 11;
4545
constexpr int IMUL_RCP = 12;
46-
//constexpr int ISDIV_C = 13;
47-
constexpr int INEG_R = 14;
48-
constexpr int IXOR_R = 15;
49-
constexpr int IXOR_M = 16;
50-
constexpr int IROR_R = 17;
51-
constexpr int IROL_R = 18;
52-
constexpr int ISWAP_R = 19;
53-
constexpr int FSWAP_R = 20;
54-
constexpr int FADD_R = 21;
55-
constexpr int FADD_M = 22;
56-
constexpr int FSUB_R = 23;
57-
constexpr int FSUB_M = 24;
58-
constexpr int FSCAL_R = 25;
59-
constexpr int FMUL_R = 26;
60-
constexpr int FMUL_M = 27;
61-
constexpr int FDIV_R = 28;
62-
constexpr int FDIV_M = 29;
63-
constexpr int FSQRT_R = 30;
64-
constexpr int COND_R = 31;
65-
constexpr int COND_M = 32;
66-
constexpr int CFROUND = 33;
67-
constexpr int ISTORE = 34;
68-
constexpr int FSTORE = 35;
69-
constexpr int NOP = 36;
46+
constexpr int INEG_R = 13;
47+
constexpr int IXOR_R = 14;
48+
constexpr int IXOR_M = 15;
49+
constexpr int IROR_R = 16;
50+
constexpr int IROL_R = 17;
51+
constexpr int ISWAP_R = 18;
52+
constexpr int FSWAP_R = 19;
53+
constexpr int FADD_R = 20;
54+
constexpr int FADD_M = 21;
55+
constexpr int FSUB_R = 22;
56+
constexpr int FSUB_M = 23;
57+
constexpr int FSCAL_R = 24;
58+
constexpr int FMUL_R = 25;
59+
constexpr int FDIV_M = 26;
60+
constexpr int FSQRT_R = 27;
61+
constexpr int COND_R = 28;
62+
constexpr int COND_M = 29;
63+
constexpr int CFROUND = 30;
64+
constexpr int ISTORE = 31;
65+
constexpr int FSTORE = 32;
66+
constexpr int NOP = 33;
7067
}
7168

7269
class Instruction {

src/instructions_portable.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
7373
#define HAVE_SMULH
7474
#endif
7575

76-
static void setRoundMode__(uint32_t mode) {
76+
static void setRoundMode_(uint32_t mode) {
7777
_controlfp(mode, _MCW_RC);
7878
}
7979
#define HAVE_SETROUNDMODE_IMPL
8080
#endif
8181

8282
#ifndef HAVE_SETROUNDMODE_IMPL
83-
static void setRoundMode__(uint32_t mode) {
83+
static void setRoundMode_(uint32_t mode) {
8484
fesetround(mode);
8585
}
8686
#endif
@@ -135,7 +135,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
135135

136136
#if defined(__has_builtin)
137137
#if __has_builtin(__builtin_sub_overflow)
138-
static inline bool subOverflow__(uint32_t a, uint32_t b) {
138+
static inline bool subOverflow_(uint32_t a, uint32_t b) {
139139
int32_t temp;
140140
return __builtin_sub_overflow(unsigned32ToSigned2sCompl(a), unsigned32ToSigned2sCompl(b), &temp);
141141
}
@@ -144,7 +144,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
144144
#endif
145145

146146
#ifndef HAVE_SUB_OVERFLOW
147-
static inline bool subOverflow__(uint32_t a, uint32_t b) {
147+
static inline bool subOverflow_(uint32_t a, uint32_t b) {
148148
auto c = unsigned32ToSigned2sCompl(a - b);
149149
return (c < unsigned32ToSigned2sCompl(a)) != (unsigned32ToSigned2sCompl(b) > 0);
150150
}
@@ -166,16 +166,16 @@ static inline double FlushNaN(double x) {
166166
void setRoundMode(uint32_t rcflag) {
167167
switch (rcflag & 3) {
168168
case RoundDown:
169-
setRoundMode__(FE_DOWNWARD);
169+
setRoundMode_(FE_DOWNWARD);
170170
break;
171171
case RoundUp:
172-
setRoundMode__(FE_UPWARD);
172+
setRoundMode_(FE_UPWARD);
173173
break;
174174
case RoundToZero:
175-
setRoundMode__(FE_TOWARDZERO);
175+
setRoundMode_(FE_TOWARDZERO);
176176
break;
177177
case RoundToNearest:
178-
setRoundMode__(FE_TONEAREST);
178+
setRoundMode_(FE_TONEAREST);
179179
break;
180180
default:
181181
UNREACHABLE;
@@ -194,9 +194,9 @@ bool condition(uint32_t type, uint32_t value, uint32_t imm32) {
194194
case 3:
195195
return unsigned32ToSigned2sCompl(value - imm32) >= 0;
196196
case 4:
197-
return subOverflow__(value, imm32);
197+
return subOverflow_(value, imm32);
198198
case 5:
199-
return !subOverflow__(value, imm32);
199+
return !subOverflow_(value, imm32);
200200
case 6:
201201
return unsigned32ToSigned2sCompl(value) < unsigned32ToSigned2sCompl(imm32);
202202
case 7:

src/jit_compiler_x86.cpp

+9-89
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ namespace randomx {
103103
; xmm11 -> "a3"
104104
; xmm12 -> temporary
105105
; xmm13 -> mantissa mask = 0x000fffffffffffff000fffffffffffff
106-
; xmm14 -> exponent 2**-240 = 0x30f000000000000030f0000000000000
106+
; xmm14 -> exponent 2**-240 = 0x30f00000000xxxxx30f00000000xxxxx
107107
; xmm15 -> scale mask = 0x81f000000000000081f0000000000000
108108
109109
*/
110110

111-
#define NOP_TEST true
112-
113111
const uint8_t* codePrologue = (uint8_t*)&randomx_program_prologue;
114112
const uint8_t* codeLoopBegin = (uint8_t*)&randomx_program_loop_begin;
115113
const uint8_t* codeLoopLoad = (uint8_t*)&randomx_program_loop_load;
@@ -254,18 +252,10 @@ namespace randomx {
254252

255253
void JitCompilerX86::generateProgramLight(Program& prog, ProgramConfiguration& pcfg) {
256254
generateProgramPrologue(prog, pcfg);
257-
//if (superscalar) {
258255
emit(codeReadDatasetLightSshInit, readDatasetLightInitSize);
259256
emitByte(CALL);
260257
emit32(superScalarHashOffset - (codePos + 4));
261258
emit(codeReadDatasetLightSshFin, readDatasetLightFinSize);
262-
/*}
263-
else {
264-
memcpy(code + codePos, codeReadDatasetLight, readDatasetLightSize);
265-
codePos += readDatasetLightSize;
266-
emitByte(CALL);
267-
emit32(readDatasetLightSubOffset - (codePos + 4));
268-
}*/
269259
generateProgramEpilogue(prog);
270260
}
271261

@@ -483,10 +473,6 @@ namespace randomx {
483473
emitByte(0xc0 + instr.dst);
484474
emit32(instr.getImm32());
485475
}*/
486-
if (false && NOP_TEST) {
487-
emit(NOP4);
488-
return;
489-
}
490476
emit(REX_LEA);
491477
if (instr.dst == RegisterNeedsDisplacement)
492478
emitByte(0xac);
@@ -527,18 +513,10 @@ namespace randomx {
527513
void JitCompilerX86::h_ISUB_R(Instruction& instr, int i) {
528514
registerUsage[instr.dst] = i;
529515
if (instr.src != instr.dst) {
530-
if (false && NOP_TEST) {
531-
emit(NOP3);
532-
return;
533-
}
534516
emit(REX_SUB_RR);
535517
emitByte(0xc0 + 8 * instr.dst + instr.src);
536518
}
537519
else {
538-
if (false && NOP_TEST) {
539-
emit(NOP7);
540-
return;
541-
}
542520
emit(REX_81);
543521
emitByte(0xe8 + instr.dst);
544522
emit32(instr.getImm32());
@@ -571,18 +549,10 @@ namespace randomx {
571549
void JitCompilerX86::h_IMUL_R(Instruction& instr, int i) {
572550
registerUsage[instr.dst] = i;
573551
if (instr.src != instr.dst) {
574-
if (false && NOP_TEST) {
575-
emit(NOP4);
576-
return;
577-
}
578552
emit(REX_IMUL_RR);
579553
emitByte(0xc0 + 8 * instr.dst + instr.src);
580554
}
581555
else {
582-
if (false && NOP_TEST) {
583-
emit(NOP7);
584-
return;
585-
}
586556
emit(REX_IMUL_RRI);
587557
emitByte(0xc0 + 9 * instr.dst);
588558
emit32(instr.getImm32());
@@ -606,12 +576,6 @@ namespace randomx {
606576

607577
void JitCompilerX86::h_IMULH_R(Instruction& instr, int i) {
608578
registerUsage[instr.dst] = i;
609-
if (false && NOP_TEST) {
610-
emit(NOP3);
611-
emit(NOP3);
612-
emit(NOP3);
613-
return;
614-
}
615579
emit(REX_MOV_RR64);
616580
emitByte(0xc0 + instr.dst);
617581
emit(REX_MUL_R);
@@ -641,12 +605,6 @@ namespace randomx {
641605

642606
void JitCompilerX86::h_ISMULH_R(Instruction& instr, int i) {
643607
registerUsage[instr.dst] = i;
644-
if (false && NOP_TEST) {
645-
emit(NOP3);
646-
emit(NOP3);
647-
emit(NOP3);
648-
return;
649-
}
650608
emit(REX_MOV_RR64);
651609
emitByte(0xc0 + instr.dst);
652610
emit(REX_MUL_R);
@@ -676,13 +634,6 @@ namespace randomx {
676634

677635
void JitCompilerX86::h_IMUL_RCP(Instruction& instr, int i) {
678636
if (instr.getImm32() != 0) {
679-
if (false && NOP_TEST) {
680-
emitByte(0x66);
681-
emitByte(0x66);
682-
emit(NOP8);
683-
emit(NOP4);
684-
return;
685-
}
686637
registerUsage[instr.dst] = i;
687638
emit(MOV_RAX_I);
688639
emit64(randomx_reciprocal(instr.getImm32()));
@@ -704,18 +655,10 @@ namespace randomx {
704655
void JitCompilerX86::h_IXOR_R(Instruction& instr, int i) {
705656
registerUsage[instr.dst] = i;
706657
if (instr.src != instr.dst) {
707-
if (false && NOP_TEST) {
708-
emit(NOP3);
709-
return;
710-
}
711658
emit(REX_XOR_RR);
712659
emitByte(0xc0 + 8 * instr.dst + instr.src);
713660
}
714661
else {
715-
if (false && NOP_TEST) {
716-
emit(NOP7);
717-
return;
718-
}
719662
emit(REX_XOR_RI);
720663
emitByte(0xf0 + instr.dst);
721664
emit32(instr.getImm32());
@@ -740,21 +683,12 @@ namespace randomx {
740683
void JitCompilerX86::h_IROR_R(Instruction& instr, int i) {
741684
registerUsage[instr.dst] = i;
742685
if (instr.src != instr.dst) {
743-
if (false && NOP_TEST) {
744-
emit(NOP3);
745-
emit(NOP3);
746-
return;
747-
}
748686
emit(REX_MOV_RR);
749687
emitByte(0xc8 + instr.src);
750688
emit(REX_ROT_CL);
751689
emitByte(0xc8 + instr.dst);
752690
}
753691
else {
754-
if (false && NOP_TEST) {
755-
emit(NOP4);
756-
return;
757-
}
758692
emit(REX_ROT_I8);
759693
emitByte(0xc8 + instr.dst);
760694
emitByte(instr.getImm32() & 63);
@@ -949,21 +883,14 @@ namespace randomx {
949883
const int conditionMask = ((1 << RANDOMX_CONDITION_BITS) - 1) << shift;
950884
int reg = getConditionRegister();
951885
int target = registerUsage[reg] + 1;
952-
if (false && NOP_TEST) {
953-
emit(NOP7);
954-
emit(NOP7);
955-
emit(NOP6);
956-
}
957-
else {
958-
emit(REX_ADD_I);
959-
emitByte(0xc0 + reg);
960-
emit32(1 << shift);
961-
emit(REX_TEST);
962-
emitByte(0xc0 + reg);
963-
emit32(conditionMask);
964-
emit(JZ);
965-
emit32(instructionOffsets[target] - (codePos + 4));
966-
}
886+
emit(REX_ADD_I);
887+
emitByte(0xc0 + reg);
888+
emit32(1 << shift);
889+
emit(REX_TEST);
890+
emitByte(0xc0 + reg);
891+
emit32(conditionMask);
892+
emit(JZ);
893+
emit32(instructionOffsets[target] - (codePos + 4));
967894
for (unsigned j = 0; j < 8; ++j) { //mark all registers as used
968895
registerUsage[j] = i;
969896
}
@@ -973,13 +900,6 @@ namespace randomx {
973900
#ifdef RANDOMX_JUMP
974901
handleCondition(instr, i);
975902
#endif
976-
if (false && NOP_TEST) {
977-
emit(NOP3);
978-
emit(NOP7);
979-
emit(NOP3);
980-
emit(NOP3);
981-
return;
982-
}
983903
emit(XOR_ECX_ECX);
984904
emit(REX_CMP_R32I);
985905
emitByte(0xf8 + instr.src);

0 commit comments

Comments
 (0)