Hacker News new | ask | show | jobs
by freshbob 2244 days ago
x >> 2 resulting in SAR is quite logical. I'm more concerned about

x / 2 resulting in the off-by-one error mentioned in the paper, if x is LLONG_MIN. LLONG_MIN / 2 = 0 in with their optimization.

https://godbolt.org/z/EtyNsR

2 comments

> x / 2 resulting in the off-by-one error mentioned in the paper, if x is LLONG_MIN. LLONG_MIN / 2 = 0 in with their optimization.

Are you saying clang is leading to an off-by-one error? The code seems to behave correctly to me.

Doh. Sorry about that.

https://godbolt.org/z/xWmjpP

return x / 2

baz: # @baz mov rax, rdi shr rax, 63 add rax, rdi sar rax ret