diff options
| author | Connor Abbott <cwabbott0@gmail.com> | 2023-04-03 18:26:57 +0200 |
|---|---|---|
| committer | Marge Bot <emma+marge@anholt.net> | 2023-07-03 19:51:04 +0000 |
| commit | 282e73118d59ad1204ccc1aaff3aa8b267bc2ed2 (patch) | |
| tree | 91c2c386f05f9939adaec77d8d3240a65148b5f5 | |
| parent | 5be8f98f5ac5cbdb314bdd88d6b6f51642d7701c (diff) | |
util/bitset: Add some extra functions
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22301>
| -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, |