Skip to content

Instantly share code, notes, and snippets.

@gofer
Created December 16, 2014 14:28
Show Gist options
  • Save gofer/d6169c4907c25bde4f20 to your computer and use it in GitHub Desktop.
Save gofer/d6169c4907c25bde4f20 to your computer and use it in GitHub Desktop.
.align 8
.text
.globl linux_fast_abs64
linux_fast_abs64:
movq %rdi, %rax # rax <- x
sarq $63, %rax # rax <- rax >> 63
xorq %rax, %rdi # rdi <- rdi ^ rax
subq %rax, %rdi # rdi <- rdi - rax
movq %rdi, %rax # rax <- rdi
retq
.globl windows_fast_abs64
windows_fast_abs64:
movq %rcx, %rax # rax <- x
sarq $63, %rax # rax <- rax >> 63
xorq %rax, %rcx # rcx <- rcx ^ rax
subq %rax, %rcx # rcx <- rcx - rax
movq %rcx, %rax # rax <- rcx
retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment