5 comments

[ 3.3 ms ] story [ 32.5 ms ] thread
Anyone else always spend a huge amount of time understanding someone elses code when their doing bit twiddling? It's just not intuitive to me, and I always abstract it away as much as possible.
Has anybody done any benchmarking lately to see if these hacks really save time? Seems like most of them rely on the assumption that the cpu has a barrel shifter and can do something like x>>23 in 1 clock cycle. I understand that some of the later x86 chips did not have a barrel shifter, so its not obvious to me that x>>23 would execute any faster than 1/(2 ^ 23) would. Does anybody know for sure?
How many people use this stuff in their daily job coding? Does this really matters and matters what?
I think this should be regarded as "recreational computer science". It's intriguing to see how much is possible with some bit twiddling. It also gives insight into how things are handled internally.

But it's not for use in actual code, unless you're writing a video codec or other embedded system in which you want to shave off every cycle.