diff options
| author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2021-05-07 09:51:01 +0200 |
|---|---|---|
| committer | Marge Bot <eric+marge@anholt.net> | 2021-09-21 20:25:31 +0000 |
| commit | cfa8828c62b55dbefdd5f29bdd60007582d0ddac (patch) | |
| tree | a8d304a65099fea5432d47058c4aa218ca0d340f | |
| parent | f8ea9fa0f8238cdd3ac3dcc0f32e0305aac6ad9c (diff) | |
util/bitset: add bitwise AND, OR and NOT
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
| -rw-r--r-- | src/util/bitset.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h index 4807709edb3..dd6656e1f42 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -65,6 +65,46 @@ #define BITSET_MASK(b) (((b) % BITSET_WORDBITS == 0) ? ~0 : BITSET_BIT(b) - 1) #define BITSET_RANGE(b, e) ((BITSET_MASK((e) + 1)) & ~(BITSET_BIT(b) - 1)) +/* logic bit operations + */ +static inline void +__bitset_and(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]; +} + +static inline void +__bitset_or(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]; +} + +static inline void +__bitset_not(BITSET_WORD *x, unsigned n) +{ + for (unsigned i = 0; i < n; i++) + x[i] = ~x[i]; +} + +#define BITSET_AND(r, x, y) \ + do { \ + assert(ARRAY_SIZE(r) == ARRAY_SIZE(x)); \ + assert(ARRAY_SIZE(r) == ARRAY_SIZE(y)); \ + __bitset_and(r, x, y, ARRAY_SIZE(r)); \ + } while (0) + +#define BITSET_OR(r, x, y) \ + do { \ + assert(ARRAY_SIZE(r) == ARRAY_SIZE(x)); \ + assert(ARRAY_SIZE(r) == ARRAY_SIZE(y)); \ + __bitset_or(r, x, y, ARRAY_SIZE(r)); \ + } while (0) + +#define BITSET_NOT(x) \ + __bitset_not(x, ARRAY_SIZE(x)) + /* bit range operations */ #define BITSET_TEST_RANGE(x, b, e) \ |