diff options
-rw-r--r-- | src/util/bitset.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h index b4c2152023..32c8b43954 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -55,6 +55,38 @@ #define BITSET_BITWORD(b) ((b) / BITSET_WORDBITS) #define BITSET_BIT(b) (1 << ((b) % BITSET_WORDBITS)) +static inline void +__bitset_and(BITSET_WORD *dst, const BITSET_WORD *x, const BITSET_WORD *y, + int n) +{ + for (int i = 0; i < n; ++i) + dst[i] = x[i] & y[i]; +} + +/* Bit-wise "and": dst = x & y */ +#define BITSET_AND(dst, x, y) \ + do { \ + STATIC_ASSERT(ARRAY_SIZE((dst)) == ARRAY_SIZE((x))); \ + STATIC_ASSERT(ARRAY_SIZE((dst)) == ARRAY_SIZE((y))); \ + __bitset_and((dst), (x), (y), ARRAY_SIZE((dst))); \ + } while (0) + +static inline void +__bitset_and_not(BITSET_WORD *dst, const BITSET_WORD *x, const BITSET_WORD *y, + int n) +{ + for (int i = 0; i < n; ++i) + dst[i] = x[i] & ~y[i]; +} + +/* Bit-wise "and not": dst = x & ~y */ +#define BITSET_AND_NOT(dst, x, y) \ + do { \ + STATIC_ASSERT(ARRAY_SIZE((dst)) == ARRAY_SIZE((x))); \ + STATIC_ASSERT(ARRAY_SIZE((dst)) == ARRAY_SIZE((y))); \ + __bitset_and_not((dst), (x), (y), ARRAY_SIZE((dst))); \ + } while (0) + /* single bit operations */ #define BITSET_TEST(x, b) ((x)[BITSET_BITWORD(b)] & BITSET_BIT(b)) |