Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomX v2 virtual machine changes #274

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/asm/program_epilogue_linux.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
;# restore callee-saved registers - System V AMD64 ABI
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
mov r15, qword ptr [rsp+280]
mov r14, qword ptr [rsp+272]
mov r13, qword ptr [rsp+264]
mov r12, qword ptr [rsp+256]
mov rbp, qword ptr [rsp+232]
mov rbx, qword ptr [rsp+224]

add rsp, 456

;# program finished
ret 0
ret
2 changes: 1 addition & 1 deletion src/asm/program_epilogue_store.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;# save VM register values
pop rcx
mov rcx, qword ptr [rsp+448]
mov qword ptr [rcx+0], r8
mov qword ptr [rcx+8], r9
mov qword ptr [rcx+16], r10
Expand Down
40 changes: 20 additions & 20 deletions src/asm/program_epilogue_win64.inc
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
;# restore callee-saved registers - Microsoft x64 calling convention
movdqu xmm15, xmmword ptr [rsp]
movdqu xmm14, xmmword ptr [rsp+16]
movdqu xmm13, xmmword ptr [rsp+32]
movdqu xmm12, xmmword ptr [rsp+48]
movdqu xmm11, xmmword ptr [rsp+64]
add rsp, 80
movdqu xmm10, xmmword ptr [rsp]
movdqu xmm9, xmmword ptr [rsp+16]
movdqu xmm8, xmmword ptr [rsp+32]
movdqu xmm7, xmmword ptr [rsp+48]
movdqu xmm6, xmmword ptr [rsp+64]
add rsp, 80
pop r15
pop r14
pop r13
pop r12
pop rsi
pop rdi
pop rbp
pop rbx
movdqa xmm15, xmmword ptr [rsp+432]
movdqa xmm14, xmmword ptr [rsp+416]
movdqa xmm13, xmmword ptr [rsp+400]
movdqa xmm12, xmmword ptr [rsp+384]
movdqa xmm11, xmmword ptr [rsp+368]
movdqa xmm10, xmmword ptr [rsp+352]
movdqa xmm9, xmmword ptr [rsp+336]
movdqa xmm8, xmmword ptr [rsp+320]
movdqa xmm7, xmmword ptr [rsp+304]
movdqa xmm6, xmmword ptr [rsp+288]
mov r15, qword ptr [rsp+280]
mov r14, qword ptr [rsp+272]
mov r13, qword ptr [rsp+264]
mov r12, qword ptr [rsp+256]
mov rdi, qword ptr [rsp+248]
mov rsi, qword ptr [rsp+240]
mov rbp, qword ptr [rsp+232]
mov rbx, qword ptr [rsp+224]

add rsp, 456

;# program finished
ret
4 changes: 2 additions & 2 deletions src/asm/program_loop_load.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lea rcx, [rsi+rax]
push rcx
mov qword ptr [rsp+8], rcx
xor r8, qword ptr [rcx+0]
xor r9, qword ptr [rcx+8]
xor r10, qword ptr [rcx+16]
Expand All @@ -9,7 +9,7 @@
xor r14, qword ptr [rcx+48]
xor r15, qword ptr [rcx+56]
lea rcx, [rsi+rdx]
push rcx
mov qword ptr [rsp+16], rcx
cvtdq2pd xmm0, qword ptr [rcx+0]
cvtdq2pd xmm1, qword ptr [rcx+8]
cvtdq2pd xmm2, qword ptr [rcx+16]
Expand Down
4 changes: 2 additions & 2 deletions src/asm/program_loop_store.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pop rcx
mov rcx, qword ptr [rsp+16]
mov qword ptr [rcx+0], r8
mov qword ptr [rcx+8], r9
mov qword ptr [rcx+16], r10
Expand All @@ -7,7 +7,7 @@
mov qword ptr [rcx+40], r13
mov qword ptr [rcx+48], r14
mov qword ptr [rcx+56], r15
pop rcx
mov rcx, qword ptr [rsp+8]
xorpd xmm0, xmm4
xorpd xmm1, xmm5
xorpd xmm2, xmm6
Expand Down
30 changes: 30 additions & 0 deletions src/asm/program_loop_store_hard_aes.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
mov rcx, qword ptr [rsp+16]
mov qword ptr [rcx+0], r8
mov qword ptr [rcx+8], r9
mov qword ptr [rcx+16], r10
mov qword ptr [rcx+24], r11
mov qword ptr [rcx+32], r12
mov qword ptr [rcx+40], r13
mov qword ptr [rcx+48], r14
mov qword ptr [rcx+56], r15
mov rcx, qword ptr [rsp+8]
aesenc xmm0, xmm4
aesdec xmm1, xmm4
aesenc xmm2, xmm4
aesdec xmm3, xmm4
aesenc xmm0, xmm5
aesdec xmm1, xmm5
aesenc xmm2, xmm5
aesdec xmm3, xmm5
aesenc xmm0, xmm6
aesdec xmm1, xmm6
aesenc xmm2, xmm6
aesdec xmm3, xmm6
aesenc xmm0, xmm7
aesdec xmm1, xmm7
aesenc xmm2, xmm7
aesdec xmm3, xmm7
movapd xmmword ptr [rcx+0], xmm0
movapd xmmword ptr [rcx+16], xmm1
movapd xmmword ptr [rcx+32], xmm2
movapd xmmword ptr [rcx+48], xmm3
97 changes: 97 additions & 0 deletions src/asm/program_loop_store_soft_aes.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
mov rcx, qword ptr [rsp+16]
mov qword ptr [rcx+0], r8
mov qword ptr [rcx+8], r9
mov qword ptr [rcx+16], r10
mov qword ptr [rcx+24], r11
mov qword ptr [rcx+32], r12
mov qword ptr [rcx+40], r13
mov qword ptr [rcx+48], r14
mov qword ptr [rcx+56], r15
mov rcx, qword ptr [rsp+8]

movapd xmmword ptr [rsp+96], xmm0
movapd xmmword ptr [rsp+112], xmm1
movapd xmmword ptr [rsp+128], xmm2
movapd xmmword ptr [rsp+144], xmm3
movapd xmmword ptr [rsp+160], xmm4
movapd xmmword ptr [rsp+176], xmm5
movapd xmmword ptr [rsp+192], xmm6
movapd xmmword ptr [rsp+208], xmm7

mov qword ptr [rsp+24], rax
mov qword ptr [rsp+40], rcx
mov qword ptr [rsp+48], rdx
mov qword ptr [rsp+56], rbp
mov qword ptr [rsp+72], rsi
mov qword ptr [rsp+80], rdi
mov qword ptr [rsp+88], rbx

lea rsi, [rsp+160]
lea rdi, [rsp+96]
call soft_aes_enc
lea rsi, [rsp+160]
lea rdi, [rsp+112]
call soft_aes_dec
lea rsi, [rsp+160]
lea rdi, [rsp+128]
call soft_aes_enc
lea rsi, [rsp+160]
lea rdi, [rsp+144]
call soft_aes_dec

lea rsi, [rsp+176]
lea rdi, [rsp+96]
call soft_aes_enc
lea rsi, [rsp+176]
lea rdi, [rsp+112]
call soft_aes_dec
lea rsi, [rsp+176]
lea rdi, [rsp+128]
call soft_aes_enc
lea rsi, [rsp+176]
lea rdi, [rsp+144]
call soft_aes_dec

lea rsi, [rsp+192]
lea rdi, [rsp+96]
call soft_aes_enc
lea rsi, [rsp+192]
lea rdi, [rsp+112]
call soft_aes_dec
lea rsi, [rsp+192]
lea rdi, [rsp+128]
call soft_aes_enc
lea rsi, [rsp+192]
lea rdi, [rsp+144]
call soft_aes_dec

lea rsi, [rsp+208]
lea rdi, [rsp+96]
call soft_aes_enc
lea rsi, [rsp+208]
lea rdi, [rsp+112]
call soft_aes_dec
lea rsi, [rsp+208]
lea rdi, [rsp+128]
call soft_aes_enc
lea rsi, [rsp+208]
lea rdi, [rsp+144]
call soft_aes_dec

mov rax, qword ptr [rsp+24]
mov rcx, qword ptr [rsp+40]
mov rdx, qword ptr [rsp+48]
mov rbp, qword ptr [rsp+56]
mov rsi, qword ptr [rsp+72]
mov rdi, qword ptr [rsp+80]
mov rbx, qword ptr [rsp+88]

movapd xmm0, xmmword ptr [rsp+96]
movapd xmm1, xmmword ptr [rsp+112]
movapd xmm2, xmmword ptr [rsp+128]
movapd xmm3, xmmword ptr [rsp+144]

movapd xmmword ptr [rcx+0], xmm0
movapd xmmword ptr [rcx+16], xmm1
movapd xmmword ptr [rcx+32], xmm2
movapd xmmword ptr [rcx+48], xmm3
23 changes: 12 additions & 11 deletions src/asm/program_prologue_linux.inc
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
;# callee-saved registers - System V AMD64 ABI
push rbx
push rbp
push r12
push r13
push r14
push r15
sub rsp, 456
mov qword ptr [rsp+224], rbx
mov qword ptr [rsp+232], rbp
mov qword ptr [rsp+256], r12
mov qword ptr [rsp+264], r13
mov qword ptr [rsp+272], r14
mov qword ptr [rsp+280], r15

;# function arguments
mov rbx, rcx ;# loop counter
push rdi ;# RegisterFile& registerFile
mov rbx, rcx ;# loop counter
mov qword ptr [rsp+448], rdi ;# RegisterFile& registerFile
mov rcx, rdi
mov rbp, qword ptr [rsi] ;# "mx", "ma"
mov rdi, qword ptr [rsi+8] ;# uint8_t* dataset
mov rsi, rdx ;# uint8_t* scratchpad
mov rbp, qword ptr [rsi] ;# "mx", "ma"
mov rdi, qword ptr [rsi+8] ;# uint8_t* dataset
mov rsi, rdx ;# uint8_t* scratchpad

mov rax, rbp
ror rbp, 32
Expand Down
49 changes: 24 additions & 25 deletions src/asm/program_prologue_win64.inc
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
;# callee-saved registers - Microsoft x64 calling convention
push rbx
push rbp
push rdi
push rsi
push r12
push r13
push r14
push r15
sub rsp, 80
movdqu xmmword ptr [rsp+64], xmm6
movdqu xmmword ptr [rsp+48], xmm7
movdqu xmmword ptr [rsp+32], xmm8
movdqu xmmword ptr [rsp+16], xmm9
movdqu xmmword ptr [rsp+0], xmm10
sub rsp, 80
movdqu xmmword ptr [rsp+64], xmm11
movdqu xmmword ptr [rsp+48], xmm12
movdqu xmmword ptr [rsp+32], xmm13
movdqu xmmword ptr [rsp+16], xmm14
movdqu xmmword ptr [rsp+0], xmm15
sub rsp, 456
mov qword ptr [rsp+224], rbx
mov qword ptr [rsp+232], rbp
mov qword ptr [rsp+240], rsi
mov qword ptr [rsp+248], rdi
mov qword ptr [rsp+256], r12
mov qword ptr [rsp+264], r13
mov qword ptr [rsp+272], r14
mov qword ptr [rsp+280], r15
movdqa xmmword ptr [rsp+288], xmm6
movdqa xmmword ptr [rsp+304], xmm7
movdqa xmmword ptr [rsp+320], xmm8
movdqa xmmword ptr [rsp+336], xmm9
movdqa xmmword ptr [rsp+352], xmm10
movdqa xmmword ptr [rsp+368], xmm11
movdqa xmmword ptr [rsp+384], xmm12
movdqa xmmword ptr [rsp+400], xmm13
movdqa xmmword ptr [rsp+416], xmm14
movdqa xmmword ptr [rsp+432], xmm15

;# function arguments
push rcx ;# RegisterFile& registerFile
mov rbp, qword ptr [rdx] ;# "mx", "ma"
mov rdi, qword ptr [rdx+8] ;# uint8_t* dataset
mov rsi, r8 ;# uint8_t* scratchpad
mov rbx, r9 ;# loop counter
mov qword ptr [rsp+448], rcx ;# RegisterFile& registerFile
mov rbp, qword ptr [rdx] ;# "mx", "ma"
mov rdi, qword ptr [rdx+8] ;# uint8_t* dataset
mov rsi, r8 ;# uint8_t* scratchpad
mov rbx, r9 ;# loop counter

mov rax, rbp
ror rbp, 32
Expand Down
17 changes: 8 additions & 9 deletions src/asm/program_read_dataset_sshash_fin.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
mov rbx, qword ptr [rsp+64]
xor r8, qword ptr [rsp+56]
xor r9, qword ptr [rsp+48]
xor r8, qword ptr [rsp+24]
xor r9, qword ptr [rsp+32]
xor r10, qword ptr [rsp+40]
xor r11, qword ptr [rsp+32]
xor r12, qword ptr [rsp+24]
xor r13, qword ptr [rsp+16]
xor r14, qword ptr [rsp+8]
xor r15, qword ptr [rsp+0]
add rsp, 72
xor r11, qword ptr [rsp+48]
xor r12, qword ptr [rsp+56]
xor r13, qword ptr [rsp+64]
xor r14, qword ptr [rsp+72]
xor r15, qword ptr [rsp+80]
mov rbx, qword ptr [rsp+88]
17 changes: 8 additions & 9 deletions src/asm/program_read_dataset_sshash_init.inc
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
sub rsp, 72
mov qword ptr [rsp+64], rbx
mov qword ptr [rsp+56], r8
mov qword ptr [rsp+48], r9
mov qword ptr [rsp+24], r8
mov qword ptr [rsp+32], r9
mov qword ptr [rsp+40], r10
mov qword ptr [rsp+32], r11
mov qword ptr [rsp+24], r12
mov qword ptr [rsp+16], r13
mov qword ptr [rsp+8], r14
mov qword ptr [rsp+0], r15
mov qword ptr [rsp+48], r11
mov qword ptr [rsp+56], r12
mov qword ptr [rsp+64], r13
mov qword ptr [rsp+72], r14
mov qword ptr [rsp+80], r15
mov qword ptr [rsp+88], rbx
ror rbp, 32 ;# swap "ma" and "mx"
xor rbp, rax ;# modify "mx"
mov rbx, rbp ;# ebx = ma
Expand Down
Loading