From: Ben Pfaff <b...@nicira.com> These will be used in an upcoming commit.
This is a backport of master commit c1a29506e854. Signed-off-by: Ben Pfaff <b...@nicira.com> Acked-by: Jarno Rajahalme <jrajaha...@nicira.com> Signed-off-by: Joe Stringer <joestrin...@nicira.com> --- lib/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/bitmap.h | 6 ++++++ 2 files changed, 50 insertions(+) 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)) -- 2.1.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev