Skip to content

Instantly share code, notes, and snippets.

@DuncanRuns

DuncanRuns/new.s Secret

Last active June 13, 2024 15:31
Show Gist options
  • Save DuncanRuns/908f4eee46975648d58150598bab689b to your computer and use it in GitHub Desktop.
Save DuncanRuns/908f4eee46975648d58150598bab689b to your computer and use it in GitHub Desktop.
nextInt assembly before and after (original.s/nextIntA is master cubiomes, new.s/nextIntB is PR stuff)
nextIntB:
pushq %rbp
.seh_pushreg %rbp
pushq %rbx
.seh_pushreg %rbx
subq $72, %rsp
.seh_stackalloc 72
leaq 64(%rsp), %rbp
.seh_setframe %rbp, 64
.seh_endprologue
movq %rcx, 32(%rbp)
movl %edx, 40(%rbp)
movl 40(%rbp), %eax
subl $1, %eax
movl %eax, -4(%rbp)
movl -4(%rbp), %eax
andl 40(%rbp), %eax
testl %eax, %eax
jne .L9
movl 40(%rbp), %eax
movslq %eax, %rbx
movq 32(%rbp), %rax
movl $31, %edx
movq %rax, %rcx
call next
cltq
imulq %rbx, %rax
movq %rax, -24(%rbp)
movq -24(%rbp), %rax
sarq $31, %rax
jmp .L10
.L9:
movq 32(%rbp), %rax
movl $31, %edx
movq %rax, %rcx
call next
movl %eax, -8(%rbp)
movl -8(%rbp), %eax
cltd
idivl 40(%rbp)
movl %edx, -12(%rbp)
movl -8(%rbp), %edx
movl -12(%rbp), %eax
subl %eax, %edx
movl -4(%rbp), %eax
addl %edx, %eax
testl %eax, %eax
js .L9
movl -12(%rbp), %eax
.L10:
addq $72, %rsp
popq %rbx
popq %rbp
ret
nextIntA:
pushq %rbp
.seh_pushreg %rbp
pushq %rbx
.seh_pushreg %rbx
subq $72, %rsp
.seh_stackalloc 72
leaq 64(%rsp), %rbp
.seh_setframe %rbp, 64
.seh_endprologue
movq %rcx, 32(%rbp)
movl %edx, 40(%rbp)
movl 40(%rbp), %eax
subl $1, %eax
movl %eax, -4(%rbp)
movl -4(%rbp), %eax
andl 40(%rbp), %eax
testl %eax, %eax
jne .L6
movl 40(%rbp), %eax
movslq %eax, %rbx
movq 32(%rbp), %rax
movl $31, %edx
movq %rax, %rcx
call next
cltq
imulq %rbx, %rax
movq %rax, -24(%rbp)
movq -24(%rbp), %rax
sarq $31, %rax
jmp .L7
.L6:
movq 32(%rbp), %rax
movl $31, %edx
movq %rax, %rcx
call next
movl %eax, -8(%rbp)
movl -8(%rbp), %eax
cltd
idivl 40(%rbp)
movl %edx, -12(%rbp)
movl -8(%rbp), %eax
subl -12(%rbp), %eax
movl %eax, %edx
movl -4(%rbp), %eax
addl %edx, %eax
testl %eax, %eax
js .L6
movl -12(%rbp), %eax
.L7:
addq $72, %rsp
popq %rbx
popq %rbp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment