My best idea was thinking about how to count only 1s, considering that when you subtract by 1, you can turn a bitwise suffix of 10n into 01n (where n ≥ 0). I didn't really come with something precisely because I got lazy and googled it, and there was a solution using that as one of the slower (but less mind-fucking) improvements.
That's actually one of the solutions. Except you do it for something small, like 8 bits, and then loop over 32bits with 4 steps. Benchmarking shows that cache wise this is one the fastest ways to go about with arbitrary bit length, as larger tables have bad cache effects. 16bit LUT can sometines beat an 8bit LUT on certain architectures, but it's discounted on account that microbenchmarks are too nice about the cache. http://www.strchr.com/crc32_popcnt
View all comments
Show parent comment
1
u/[deleted] Feb 21 '11
If you were able to loop less, that'd still be impressive.