Reduced x86 code size by 512 bytes (and ecx -> and eax)

This commit is contained in:
tevador
2019-01-12 20:27:35 +01:00
parent 1426fcbab5
commit 67e741ff22
8 changed files with 1841 additions and 1842 deletions
+26 -26
View File
@@ -222,42 +222,42 @@ TransformAddress MACRO reg32, reg64
ENDM
ReadMemoryRandom MACRO spmask
;# IN ecx = random 32-bit address
;# IN eax = random 32-bit address
;# GLOBAL rdi = address of the dataset address
;# GLOBAL rsi = address of the scratchpad
;# GLOBAL rbp = low 32 bits = "mx", high 32 bits = "ma"
;# MODIFY rcx, rdx
push rcx ;# preserve ecx
TransformAddress ecx, rcx ;# TransformAddress function
mov rax, qword ptr [rdi] ;# load the dataset address
xor rbp, rcx ;# modify "mx"
push rax ;# preserve eax
TransformAddress eax, rax ;# TransformAddress function
mov rcx, qword ptr [rdi] ;# load the dataset address
xor rbp, rax ;# modify "mx"
; prefetch cacheline "mx"
and rbp, -64 ;# align "mx" to the start of a cache line
mov edx, ebp ;# edx = mx
prefetchnta byte ptr [rax+rdx]
prefetchnta byte ptr [rcx+rdx]
; read cacheline "ma"
ror rbp, 32 ;# swap "ma" and "mx"
mov edx, ebp ;# edx = ma
and ecx, spmask-7 ;# limit address to the specified scratchpad size aligned to multiple of 8
lea rcx, [rsi+rcx*8] ;# scratchpad cache line
lea rax, [rax+rdx] ;# dataset cache line
mov rdx, qword ptr [rax+0] ;# load first dataset quadword (prefetched into the cache by now)
xor qword ptr [rcx+0], rdx ;# XOR the dataset item with a scratchpad item, repeat for the rest of the cacheline
mov rdx, qword ptr [rax+8]
xor qword ptr [rcx+8], rdx
mov rdx, qword ptr [rax+16]
xor qword ptr [rcx+16], rdx
mov rdx, qword ptr [rax+24]
xor qword ptr [rcx+24], rdx
mov rdx, qword ptr [rax+32]
xor qword ptr [rcx+32], rdx
mov rdx, qword ptr [rax+40]
xor qword ptr [rcx+40], rdx
mov rdx, qword ptr [rax+48]
xor qword ptr [rcx+48], rdx
mov rdx, qword ptr [rax+56]
xor qword ptr [rcx+56], rdx
pop rcx ;# restore ecx
and eax, spmask-7 ;# limit address to the specified scratchpad size aligned to multiple of 8
lea rax, [rsi+rax*8] ;# scratchpad cache line
lea rcx, [rcx+rdx] ;# dataset cache line
mov rdx, qword ptr [rcx+0] ;# load first dataset quadword (prefetched into the cache by now)
xor qword ptr [rax+0], rdx ;# XOR the dataset item with a scratchpad item, repeat for the rest of the cacheline
mov rdx, qword ptr [rcx+8]
xor qword ptr [rax+8], rdx
mov rdx, qword ptr [rcx+16]
xor qword ptr [rax+16], rdx
mov rdx, qword ptr [rcx+24]
xor qword ptr [rax+24], rdx
mov rdx, qword ptr [rcx+32]
xor qword ptr [rax+32], rdx
mov rdx, qword ptr [rcx+40]
xor qword ptr [rax+40], rdx
mov rdx, qword ptr [rcx+48]
xor qword ptr [rax+48], rdx
mov rdx, qword ptr [rcx+56]
xor qword ptr [rax+56], rdx
pop rax ;# restore eax
ret
ENDM