Pop goes the...population count?
10 points by LesleyLai
10 points by LesleyLai
The general name for this is idiom recognition. LLVM does similar things for count leading/trailimg zeroes. https://llvm.org/doxygen/LoopIdiomRecognize_8cpp.html
A simpler kind of idiom recognition turns combinations of shifts into rotate instructions, handy for random numbers and cryptography.
If you’re ever looking for popcount in TAOCP, Knuth peculiarly calls it “sideways add” instead.
I like popcount-packed arrays, which I use to great advantage in my qp-trie. I got the idea from Bagwell’s HAMT.