Author: | Wojciech Muła |
---|---|
Added on: | 2008-06-08 |
Branch-less x86 code:
movl %eax, %ebx sarl $32, %ebx ; fill ebx with sign bit xorl %ebx, %eax ; negate eax (if negative) subl %ebx, %eax ; increment eax by 1 (if negative)
SSE2:
pshufd $0b11110101, %xmm0, %xmm1 ; populate dwords 3 and 1 psrad $32, %xmm1 ; fill quad words with sign bit pxor %xmm1, %xmm0 ; negate (if negative) psubq %xmm1, %xmm0 ; increment (if negative)