diff options
| author | Jack O'Connor <[email protected]> | 2020-01-21 10:45:37 -0500 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2020-01-21 10:47:00 -0500 |
| commit | d0c8fc16b3b79b82099855a67e148a29e605331e (patch) | |
| tree | 934b4733fa018ed933c7a7c0f7e76e35b830931c | |
| parent | 67262dff31461d3fb801f3fe01382abb77387735 (diff) | |
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
| -rw-r--r-- | c/blake3_impl.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/c/blake3_impl.h b/c/blake3_impl.h index 576ccf4..d345246 100644 --- a/c/blake3_impl.h +++ b/c/blake3_impl.h @@ -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 |
