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]);
// #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);
// #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_ */