Skip to content

Instantly share code, notes, and snippets.

@fulmicoton
Last active May 22, 2017 02:39
Show Gist options
  • Save fulmicoton/a4f066646d9097dbdacf6dfe5206ed5d to your computer and use it in GitHub Desktop.
Save fulmicoton/a4f066646d9097dbdacf6dfe5206ed5d to your computer and use it in GitHub Desktop.
branchless binary search
.type _ZN8rust_out13binary_search17hd76cf76916892235E,@function_ZN8rust_out13binary_search17hd76cf76916892235E:
.cfi_startproc
movl 256(%rdi), %ecx
movl $64, %edx
xorl %eax, %eax
cmpl %ecx, %esi
cmovgeq %rdx, %rax
movl 128(%rdi,%rax,4), %ecx
leaq 32(%rax), %rdx
cmpl %ecx, %esi
cmovgeq %rdx, %rax
movl 64(%rdi,%rax,4), %ecx
leaq 16(%rax), %rdx
cmpl %ecx, %esi
cmovgeq %rdx, %rax
movl 32(%rdi,%rax,4), %ecx
leaq 8(%rax), %rdx
cmpl %ecx, %esi
cmovgeq %rdx, %rax
movl 16(%rdi,%rax,4), %ecx
leaq 4(%rax), %rdx
cmpl %ecx, %esi
cmovgeq %rdx, %rax
movl 8(%rdi,%rax,4), %ecx
leaq 2(%rax), %rdx
cmpl %ecx, %esi
cmovgeq %rdx, %rax
movl 4(%rdi,%rax,4), %ecx
leaq 1(%rax), %rdx
cmpl %ecx, %esi
cmovgeq %rdx, %rax
retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment