mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +02:00
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>
This commit is contained in:
parent
5be8f98f5a
commit
282e73118d
1 changed files with 28 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue