v4.1:
  Update bitmap_count1 function: call count_1bits to improve
  performance.

v4:
  Add bitmap_count1 function to count all 1 bits.
---
 lib/bitmap.c |   15 +++++++++++++++
 lib/bitmap.h |    1 +
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index ac568e9..655b0a2 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -17,6 +17,7 @@
 #include <config.h>
 #include "bitmap.h"
 #include <string.h>
+#include "util.h"
 
 /* Allocates and returns a bitmap initialized to all-1-bits. */
 unsigned long *
@@ -92,3 +93,17 @@ bitmap_scan(const unsigned long int *bitmap, size_t start, 
size_t end)
     }
     return i;
 }
+
+size_t
+bitmap_count1(const unsigned long int *bitmap, size_t end)
+{
+    size_t i;
+    size_t count = 0;
+
+    BUILD_ASSERT(ULONG_MAX <= UINT64_MAX);
+    for (i = 0; i < BITMAP_N_LONGS(end); i++) {
+        count += count_1bits(bitmap[i]);
+    }
+
+    return count;
+}
diff --git a/lib/bitmap.h b/lib/bitmap.h
index 645f15f..5e6f8ed 100644
--- a/lib/bitmap.h
+++ b/lib/bitmap.h
@@ -101,6 +101,7 @@ void bitmap_set_multiple(unsigned long *, size_t start, 
size_t count,
                          bool value);
 bool bitmap_equal(const unsigned long *, const unsigned long *, size_t n);
 size_t bitmap_scan(const unsigned long int *, size_t start, size_t end);
+size_t bitmap_count1(const unsigned long *, size_t n);
 
 #define BITMAP_FOR_EACH_1(IDX, SIZE, BITMAP) \
     for ((IDX) = bitmap_scan(BITMAP, 0, SIZE); (IDX) < (SIZE); \
-- 
1.7.3.1.msysgit.0


_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to