About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Seurer <konstantin.seurer@gmail.com>2025-03-28 18:38:36 +0100
committerMarge Bot <emma+marge@anholt.net>2025-04-17 20:20:40 +0000
commit0cc9443e9b5419f927a3f81d4ed9b7e9c1829907 (patch)
tree8c97f27962eedbe826210e88138d02922437fe80 /src
parentc37a468a8a109cbaece70760fd748fc838185b88 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/util/bitset.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h
index 4fc4dbb6f3e..cf9e59a01cf 100644
--- a/src/util/bitset.h
+++ b/src/util/bitset.h
@@ -281,6 +281,20 @@ __bitclear_clear_range(BITSET_WORD *r, unsigned start, unsigned end)
__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)
{
unsigned prefix = 0;