> // Parallel bit count intermediates
> let a = v - ((v >> 1) & (u64::MAX / 3));
> let b = (a & (u64::MAX / 5)) + ((a >> 2) & (u64::MAX / 5));
> let c = (b + (b >> 4)) & (u64::MAX / 0x11);
> let d = (c + (c >> 8)) & (u64::MAX / 0x101);
That "parallel bit count" is almost certainly slower than using two POPCNT instructions on a modern cpu. Should just call __builtin_popcount() and let the compiler do it the most optimal way. Luckily, people do this sort of thing so often that many modern compilers will try (and often succeed) to detect you trying this insanity and convert it to a POPCOUNT (or a pair of POPCOUNTs as the case may be here) replies(2):