About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorGeorg Lehmann <dadschoorse@gmail.com>2024-11-19 19:11:03 +0100
committerMarge Bot <emma+marge@anholt.net>2024-11-21 14:50:45 +0000
commit12d026d679c6f6e55b96e20710e223c45de7c35b (patch)
tree6b0a14f3d36c82dca4b69a2b6bdad5baaa2b5ea4 /src/util
parent4c7d6e9437d98ce7c7f2de893fe1a23d6f47cff1 (diff)
util: add BITSET_LAST_BIT_BEFORE
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32145>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bitset.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h
index d5abb6c1f7c..8f6979881bd 100644
--- a/src/util/bitset.h
+++ b/src/util/bitset.h
@@ -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