diff mbox

[ovs-dev,branch-2.3,1/2] bitmap: Add new functions.

Message ID 1442011646-50005-1-git-send-email-joestringer@nicira.com
State Accepted
Headers show

Commit Message

Joe Stringer Sept. 11, 2015, 10:47 p.m. UTC
From: Ben Pfaff <blp@nicira.com>

These will be used in an upcoming commit.

This is a backport of master commit c1a29506e854.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Joe Stringer <joestringer@nicira.com>
---
 lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 lib/bitmap.h |  6 ++++++
 2 files changed, 50 insertions(+)

Comments

Ben Pfaff Sept. 12, 2015, 4:02 a.m. UTC | #1
On Fri, Sep 11, 2015 at 03:47:25PM -0700, Joe Stringer wrote:
> From: Ben Pfaff <blp@nicira.com>
> 
> These will be used in an upcoming commit.
> 
> This is a backport of master commit c1a29506e854.
> 
> Signed-off-by: Ben Pfaff <blp@nicira.com>
> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
> Signed-off-by: Joe Stringer <joestringer@nicira.com>

Thanks for the fixes.  They look correct to me.
Joe Stringer Sept. 14, 2015, 5:47 p.m. UTC | #2
On 11 September 2015 at 21:02, Ben Pfaff <blp@nicira.com> wrote:
> On Fri, Sep 11, 2015 at 03:47:25PM -0700, Joe Stringer wrote:
>> From: Ben Pfaff <blp@nicira.com>
>>
>> These will be used in an upcoming commit.
>>
>> This is a backport of master commit c1a29506e854.
>>
>> Signed-off-by: Ben Pfaff <blp@nicira.com>
>> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
>> Signed-off-by: Joe Stringer <joestringer@nicira.com>
>
> Thanks for the fixes.  They look correct to me.

Thanks, I updated the commit messages and pushed the series to branch-2.3.
diff mbox

Patch

diff --git a/lib/bitmap.c b/lib/bitmap.c
index 4b4e13e..7889aa1 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -109,3 +109,47 @@  bitmap_count1(const unsigned long int *bitmap, size_t n)
 
     return count;
 }
+
+/* "dst &= arg;" for n-bit dst and arg.  */
+void
+bitmap_and(unsigned long *dst, const unsigned long *arg, size_t n)
+{
+    size_t i;
+
+    for (i = 0; i < BITMAP_N_LONGS(n); i++) {
+        dst[i] &= arg[i];
+    }
+}
+
+/* "dst |= arg;" for n-bit dst and arg.  */
+void
+bitmap_or(unsigned long *dst, const unsigned long *arg, size_t n)
+{
+    size_t i;
+
+    for (i = 0; i < BITMAP_N_LONGS(n); i++) {
+        dst[i] |= arg[i];
+    }
+}
+
+/* "dst = ~dst;" for n-bit dst.  */
+void
+bitmap_not(unsigned long *dst, size_t n)
+{
+    size_t i;
+
+    for (i = 0; i < n / BITMAP_ULONG_BITS; i++) {
+        dst[i] = ~dst[i];
+    }
+    if (n % BITMAP_ULONG_BITS) {
+        dst[i] ^= (1u << (n % BITMAP_ULONG_BITS)) - 1;
+    }
+}
+
+/* Returns true if all of the 'n' bits in 'bitmap' are 0,
+ * false if at least one bit is a 1.*/
+bool
+bitmap_is_all_zeros(const unsigned long *bitmap, size_t n)
+{
+    return bitmap_scan(bitmap, true, 0, n) == n;
+}
diff --git a/lib/bitmap.h b/lib/bitmap.h
index afe6151..ace091f 100644
--- a/lib/bitmap.h
+++ b/lib/bitmap.h
@@ -104,6 +104,12 @@  size_t bitmap_scan(const unsigned long int *, bool target,
                    size_t start, size_t end);
 size_t bitmap_count1(const unsigned long *, size_t n);
 
+void bitmap_and(unsigned long *dst, const unsigned long *arg, size_t n);
+void bitmap_or(unsigned long *dst, const unsigned long *arg, size_t n);
+void bitmap_not(unsigned long *dst, size_t n);
+
+bool bitmap_is_all_zeros(const unsigned long *, size_t n);
+
 #define BITMAP_FOR_EACH_1(IDX, SIZE, BITMAP) \
     for ((IDX) = bitmap_scan(BITMAP, 1, 0, SIZE); (IDX) < (SIZE);    \
          (IDX) = bitmap_scan(BITMAP, 1, (IDX) + 1, SIZE))