diff options
| -rw-r--r-- | src/util/bitset.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h index 64d0d2212e2..d5b5d6dae2d 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -89,6 +89,13 @@ __bitset_not(BITSET_WORD *x, unsigned n) x[i] = ~x[i]; } +static inline void +__bitset_andnot(BITSET_WORD *r, const BITSET_WORD *x, const BITSET_WORD *y, unsigned n) +{ + for (unsigned i = 0; i < n; i++) + r[i] = x[i] & ~y[i]; +} + #define BITSET_AND(r, x, y) \ do { \ STATIC_ASSERT(ARRAY_SIZE(r) == ARRAY_SIZE(x)); \ @@ -106,6 +113,13 @@ __bitset_not(BITSET_WORD *x, unsigned n) #define BITSET_NOT(x) \ __bitset_not(x, ARRAY_SIZE(x)) +#define BITSET_ANDNOT(r, x, y) \ + do { \ + assert(ARRAY_SIZE(r) == ARRAY_SIZE(x)); \ + assert(ARRAY_SIZE(r) == ARRAY_SIZE(y)); \ + __bitset_andnot(r, x, y, ARRAY_SIZE(r)); \ + } while (0) + static inline void __bitset_rotate_right(BITSET_WORD *x, unsigned amount, unsigned n) { @@ -296,6 +310,19 @@ __bitset_count(const BITSET_WORD *x, unsigned n) #define BITSET_COUNT(x) \ __bitset_count(x, ARRAY_SIZE(x)) +/* Return true if the bitset has no bits set. + */ +static inline bool +__bitset_is_empty(const BITSET_WORD *x, int n) +{ + for (int i = 0; i < n; i++) { + if (x[i]) + return false; + } + + return true; +} + /* Get first bit set in a bitset. */ static inline int @@ -325,6 +352,7 @@ __bitset_last_bit(const BITSET_WORD *x, int n) #define BITSET_FFS(x) __bitset_ffs(x, ARRAY_SIZE(x)) #define BITSET_LAST_BIT(x) __bitset_last_bit(x, ARRAY_SIZE(x)) #define BITSET_LAST_BIT_SIZED(x, size) __bitset_last_bit(x, size) +#define BITSET_IS_EMPTY(x) __bitset_is_empty(x, ARRAY_SIZE(x)) static inline unsigned __bitset_next_set(unsigned i, BITSET_WORD *tmp, |