diff --git a/src/util/bitfield.h b/src/util/bitfield.h index a580da7b..202232b6 100644 --- a/src/util/bitfield.h +++ b/src/util/bitfield.h @@ -189,10 +189,7 @@ public: size_t sum = 0; size_t i = 0; for (; i + 4 <= num_blocks; i += 4) { - sum += popcount64(bits[i]); - sum += popcount64(bits[i + 1]); - sum += popcount64(bits[i + 2]); - sum += popcount64(bits[i + 3]); + sum += popcount64x4(&bits[i]); } for (; i < num_blocks; i++) { sum += popcount64(bits[i]); diff --git a/src/util/popcount.h b/src/util/popcount.h index c7a69d46..d90a0d50 100644 --- a/src/util/popcount.h +++ b/src/util/popcount.h @@ -52,6 +52,15 @@ u32 popcount32(u32 x) { // #endif } +static really_inline +u32 popcount32x4(u32 const *x) { + u32 sum = popcount32(x[0]); + sum += popcount32(x[1]); + sum += popcount32(x[2]); + sum += popcount32(x[3]); + return sum; +} + static really_inline u32 popcount64(u64a x) { return __builtin_popcountll(x); @@ -73,5 +82,14 @@ u32 popcount64(u64a x) { // #endif } +static really_inline +u32 popcount64x4(u64a const *x) { + volatile u32 sum = popcount64(x[0]); + sum += popcount64(x[1]); + sum += popcount64(x[2]); + sum += popcount64(x[3]); + return sum; +} + #endif /* UTIL_POPCOUNT_H_ */