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:
committed by
Marge Bot
parent
c37a468a8a
commit
0cc9443e9b
@@ -280,6 +280,20 @@ __bitclear_clear_range(BITSET_WORD *r, unsigned start, unsigned end)
|
|||||||
#define BITSET_CLEAR_RANGE(x, b, e) \
|
#define BITSET_CLEAR_RANGE(x, b, e) \
|
||||||
__bitclear_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
|
static inline unsigned
|
||||||
__bitset_prefix_sum(const BITSET_WORD *x, unsigned b, unsigned n)
|
__bitset_prefix_sum(const BITSET_WORD *x, unsigned b, unsigned n)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user