About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2021-05-12 19:46:12 +0200
committerMarge Bot <eric+marge@anholt.net>2021-09-21 20:25:31 +0000
commitb3b03e33c9f11adb0c4d84311a651ea6016a0885 (patch)
tree609f2606e698277a55f231e0b7c1da350dc2519c
parent3d65cea6ee56c2192d333632bf28460d2857af0a (diff)
util/bitset: add BITSET_SET_RANGE(..)
This version works across word boundary. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11321>
-rw-r--r--src/util/bitset.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h
index f0b16ea9964..279ad553e79 100644
--- a/src/util/bitset.h
+++ b/src/util/bitset.h
@@ -205,6 +205,25 @@ __bitset_shl(BITSET_WORD *x, unsigned amount, unsigned n)
((x)[BITSET_BITWORD(b)] &= ~BITSET_RANGE(b, e)) : \
(assert (!"BITSET_CLEAR_RANGE: bit range crosses word boundary"), 0))
+static inline void
+__bitset_set_range(BITSET_WORD *r, unsigned start, unsigned end)
+{
+ const unsigned size = end - start;
+ const unsigned start_mod = start % BITSET_WORDBITS;
+
+ if (start_mod + size <= BITSET_WORDBITS) {
+ BITSET_SET_RANGE_INSIDE_WORD(r, start, end);
+ } else {
+ const unsigned first_size = BITSET_WORDBITS - start_mod;
+
+ __bitset_set_range(r, start, start + first_size - 1);
+ __bitset_set_range(r, start + first_size, end);
+ }
+}
+
+#define BITSET_SET_RANGE(x, b, e) \
+ __bitset_set_range(x, b, e)
+
static inline unsigned
__bitset_prefix_sum(const BITSET_WORD *x, unsigned b, unsigned n)
{