Skip to content

Commit

Permalink
Reduced Dataset size to 2 GiB with 8 memory accesses per block
Browse files Browse the repository at this point in the history
Disabled Dataset growth
  • Loading branch information
tevador committed Mar 22, 2019
1 parent 233af9f commit 107270d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 142 deletions.
1 change: 1 addition & 0 deletions src/InterpretedVirtualMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ namespace RandomX {
executeBytecode(r, f, e, a);

mem.mx ^= r[readReg2] ^ r[readReg3];
mem.mx &= CacheLineAlignMask;
Cache& cache = mem.ds.cache;
uint64_t datasetLine[CacheLineSize / sizeof(uint64_t)];
initBlock(cache, (uint8_t*)datasetLine, datasetBase + mem.ma / CacheLineSize, RANDOMX_CACHE_ACCESSES / 8);
Expand Down
4 changes: 4 additions & 0 deletions src/JitCompilerX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ namespace RandomX {
}

void JitCompilerX86::generateProgramLight(Program& prog) {
if (RANDOMX_CACHE_ACCESSES != 8)
throw std::runtime_error("JIT compiler: Unsupported value of RANDOMX_CACHE_ACCESSES");
if (RANDOMX_ARGON_GROWTH != 0)
throw std::runtime_error("JIT compiler: Unsupported value of RANDOMX_ARGON_GROWTH");
generateProgramPrologue(prog);
memcpy(code + codePos, codeReadDatasetLight, readDatasetLightSize);
codePos += readDatasetLightSize;
Expand Down
3 changes: 2 additions & 1 deletion src/asm/program_read_dataset.inc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
xor rbp, rax ;# modify "mx"
and rbp, -64 ;# align "mx" to the start of a cache line
mov edx, ebp ;# edx = mx
and edx, 2147483584 ;# align "mx" to the start of a cache line
prefetchnta byte ptr [rdi+rdx]
ror rbp, 32 ;# swap "ma" and "mx"
mov edx, ebp ;# edx = ma
and edx, 2147483584 ;# align "ma" to the start of a cache line
lea rcx, [rdi+rdx] ;# dataset cache line
xor r8, qword ptr [rcx+0]
xor r9, qword ptr [rcx+8]
Expand Down
1 change: 1 addition & 0 deletions src/asm/program_read_dataset_light.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
xor rbp, rax ;# modify "mx"
ror rbp, 32 ;# swap "ma" and "mx"
mov ecx, ebp ;# ecx = ma
and ecx, 2147483584 ;# align "ma" to the start of a cache line
shr ecx, 6 ;# ecx = Dataset block number
137 changes: 0 additions & 137 deletions src/asm/program_read_dataset_light_sub.inc
Original file line number Diff line number Diff line change
Expand Up @@ -156,143 +156,6 @@
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# iteration 1
;# c0
mov rbx, r8
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r8+r9]
call squareHashSub
mov r9, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c1
mov rbx, r9
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r9+r10]
call squareHashSub
mov r10, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c2
mov rbx, r10
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r10+r11]
call squareHashSub
mov r11, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c3
mov rbx, r11
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r11+r12]
call squareHashSub
mov r12, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c4
mov rbx, r12
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r12+r13]
call squareHashSub
mov r13, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c5
mov rbx, r13
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r13+r14]
call squareHashSub
mov r14, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c6
mov rbx, r14
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r14+r15]
call squareHashSub
mov r15, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# c7
mov rbx, r15
and rbx, 4194303
shl rbx, 6
add rbx, rdi
prefetchnta byte ptr [rbx]
lea rcx, [r15+r8]
call squareHashSub
mov r8, rax
xor r8, qword ptr [rbx+0]
xor r9, qword ptr [rbx+8]
xor r10, qword ptr [rbx+16]
xor r11, qword ptr [rbx+24]
xor r12, qword ptr [rbx+32]
xor r13, qword ptr [rbx+40]
xor r14, qword ptr [rbx+48]
xor r15, qword ptr [rbx+56]
;# --------------------------
mov rbx, qword ptr [rsp+64]
xor r8, qword ptr [rsp+56]
Expand Down
6 changes: 3 additions & 3 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#define RANDOMX_ARGON_SALT "RandomX\x03"

//Number of random Cache accesses per Dataset block. Minimum is 2.
#define RANDOMX_CACHE_ACCESSES 16
#define RANDOMX_CACHE_ACCESSES 8

//Dataset size in bytes. Must be a power of 2.
#define RANDOMX_DATASET_SIZE (4ULL * 1024 * 1024 * 1024)
#define RANDOMX_DATASET_SIZE (2ULL * 1024 * 1024 * 1024)

//Dataset growth per epoch in bytes. Must be divisible by 64.
#define RANDOMX_DS_GROWTH (2 * 1024 * 1024)
#define RANDOMX_DS_GROWTH 0

//Number of blocks per epoch
#define RANDOMX_EPOCH_BLOCKS 1024
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ int main(int argc, char** argv) {
std::cout << "Calculated result: ";
result.print(std::cout);
if(programCount == 1000)
std::cout << "Reference result: 9e636a04a2517f37d8ed40b67a7051e02a7577e878fbba5c4352996b2c653f90" << std::endl;
std::cout << "Reference result: 83875c55fb9ff4a75205a744b82926ebbe23219c6291889c9ee91603c845c597" << std::endl;
if (!miningMode) {
std::cout << "Performance: " << 1000 * elapsed / programCount << " ms per hash" << std::endl;
}
Expand Down

0 comments on commit 107270d

Please sign in to comment.