Skip to content

Instantly share code, notes, and snippets.

@sunfishcode
Created November 10, 2017 04:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunfishcode/859d97e2758e02015728f70f7cde15c3 to your computer and use it in GitHub Desktop.
Save sunfishcode/859d97e2758e02015728f70f7cde15c3 to your computer and use it in GitHub Desktop.
Efficient x86 saturating float->int conversion
.globl bar
.p2align 4, 0x90
.type bar,@function
bar:
.cfi_startproc
cvttss2si %xmm0, %eax
cmpl $1, %eax
jo 0f
retq
0:
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jnp 0f
xorl %eax, %eax
0:
sbbl $0, %eax
retq
.cfi_endproc
.size bar, .-bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment