PABSQ — absolute value of two singed 64-bit numbers
Branch-less x86 code:
text
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:
text
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)