mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
add popcount32x4, popcount64x4 helper functions
This commit is contained in:
parent
c043730675
commit
43c053a069
@ -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]);
|
||||
|
@ -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_ */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user