]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
add popcount32x4, popcount64x4 helper functions
authorKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Fri, 2 Sep 2022 12:12:56 +0000 (15:12 +0300)
committerKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Tue, 6 Sep 2022 13:55:56 +0000 (16:55 +0300)
src/util/bitfield.h
src/util/popcount.h

index a580da7b608f43424905dd7e0dd1ed9ff786a7ab..202232b621551cb089493c9235795c004eb3def8 100644 (file)
@@ -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]);
index c7a69d4670c1ce289d00c964fc7c29a7105127ec..d90a0d50d075f5c56dd72d8561201583dc0d8fba 100644 (file)
@@ -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_ */