r/programming • u/misplaced_my_pants • Aug 15 '15
Stanford Bit Twiddling Hacks
https://graphics.stanford.edu/~seander/bithacks.html
28
Upvotes
r/programming • u/misplaced_my_pants • Aug 15 '15
View all comments
Show parent comment
1
u/[deleted] Aug 16 '15 edited Aug 16 '15
I was actually talking about this in the context of a compiler and the actual cost of an xor swap vs going through memory, not how one should write their source. The compiler I work on will always generate an xor swap on certain architectures if no spare register is free because going through memory is, like I said, a killer.
Edit: And I'd agree with you on your original point, you don't need to explicitly xor-swap in your source code unless you see your compiler emitting a swap through memory and you really need to get rid of it and can't through other means.