1
0
Fork 0
mirror of https://github.com/BLAKE3-team/BLAKE3 synced 2024-05-18 03:56:08 +02:00

use a better popcnt fallback algorithm

This one loops once for every set bit, rather than once for each bit
position to the right of the highest set bit.

https://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation
This commit is contained in:
Jack O'Connor 2020-01-21 10:45:37 -05:00
parent 67262dff31
commit d0c8fc16b3

View File

@ -50,8 +50,8 @@ INLINE uint8_t popcnt(uint64_t x) {
#else
uint8_t count = 0;
while (x > 0) {
count += ((uint8_t)x) & 1;
x >>= 1;
count += 1;
x &= x - 1;
}
return count;
#endif