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:
parent
67262dff31
commit
d0c8fc16b3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue