mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-10 01:40:14 +01:00
util: Add BITSET_EXTRACT
Extracts a <=32 bit range from a bitset. Reviewed-by: Natalie Vock <natalie.vock@gmx.de> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34273>
This commit is contained in:
parent
c37a468a8a
commit
0cc9443e9b
1 changed files with 14 additions and 0 deletions
|
|
@ -280,6 +280,20 @@ __bitclear_clear_range(BITSET_WORD *r, unsigned start, unsigned end)
|
|||
#define BITSET_CLEAR_RANGE(x, b, e) \
|
||||
__bitclear_clear_range(x, b, e)
|
||||
|
||||
static inline unsigned
|
||||
__bitset_extract(const BITSET_WORD *r, unsigned start, unsigned count)
|
||||
{
|
||||
unsigned shift = start % BITSET_WORDBITS;
|
||||
unsigned lower = r[BITSET_BITWORD(start)] >> shift;
|
||||
unsigned upper = shift ? r[BITSET_BITWORD(start) + 1] << (32 - shift) : 0;
|
||||
unsigned total = lower | upper;
|
||||
|
||||
return count != 32 ? total & ((1u << count) - 1u) : total;
|
||||
}
|
||||
|
||||
#define BITSET_EXTRACT(x, s, c) \
|
||||
__bitset_extract(x, s, c)
|
||||
|
||||
static inline unsigned
|
||||
__bitset_prefix_sum(const BITSET_WORD *x, unsigned b, unsigned n)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue