util: add BITSET_LAST_BIT_BEFORE
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32145>
This commit is contained in:
@@ -350,9 +350,25 @@ __bitset_last_bit(const BITSET_WORD *x, int n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get the last bit set in a bitset before last_bit.
|
||||
*/
|
||||
static inline int
|
||||
__bitset_last_bit_before(const BITSET_WORD *x, int last_bit)
|
||||
{
|
||||
int n = last_bit / BITSET_WORDBITS;
|
||||
int reminder = last_bit % BITSET_WORDBITS;
|
||||
if (reminder) {
|
||||
BITSET_WORD last = x[n] & BITFIELD_MASK(reminder);
|
||||
if (last)
|
||||
return util_last_bit(last) + n * BITSET_WORDBITS;
|
||||
}
|
||||
return __bitset_last_bit(x, 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_LAST_BIT_BEFORE(x, last_bit) __bitset_last_bit_before(x, last_bit)
|
||||
#define BITSET_IS_EMPTY(x) __bitset_is_empty(x, ARRAY_SIZE(x))
|
||||
|
||||
static inline unsigned
|
||||
|
||||
Reference in New Issue
Block a user