diff options
author | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2017-05-02 17:30:09 +0200 |
---|---|---|
committer | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2018-03-14 09:04:01 +0100 |
commit | 2044a221528b029c53a8228b3c426f3c8fbabfd4 (patch) | |
tree | fdcc945a964c74ca2ca81a7199dac535dd6dba40 | |
parent | 5e349757d5d9ebad3825ee826ce66cfb04e2a054 (diff) |
util/bitset: add BITSET_AND and BITSET_AND_NOT
-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)) |