top | item 25301005

(no title)

stfwn | 5 years ago

I once had to count the number of set bits (the Hamming weight) for an assignment. It had to be done in under 40 bitwise ops, without loops and with constants of up to 8 bits. The naive approach took way too many ops! I was stumped until I found the linked page, in particular 'Counting bits set, in parallel'[1]. Parallelism at the bit level?! That is when I realized low level programming was completely badass.

[1]: https://graphics.stanford.edu/~seander/bithacks.html#CountBi...

discuss

order

ncmncm|5 years ago

Again, the POPCNT instruction reveals its importance.