About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/util/bitset.h
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2021-05-11 08:00:54 +0200
committerMarge Bot <eric+marge@anholt.net>2021-09-21 20:25:31 +0000
commit7b62fb45588030920b853526dd9f45953dae27e5 (patch)
tree26822ba3fb8c1d4bc8d8633fde9cf606731ddbf8 /src/util/bitset.h
parent79067c4744be6d9afd3e11053e48aaf35503278b (diff)
util/bitset: add right shift
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>
Diffstat (limited to 'src/util/bitset.h')
-rw-r--r--src/util/bitset.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h
index dd6656e1f42..edda9f3406f 100644
--- a/src/util/bitset.h
+++ b/src/util/bitset.h
@@ -105,6 +105,47 @@ __bitset_not(BITSET_WORD *x, unsigned n)
#define BITSET_NOT(x) \
__bitset_not(x, ARRAY_SIZE(x))
+static inline void
+__bitset_rotate_right(BITSET_WORD *x, unsigned amount, unsigned n)
+{
+ assert(amount < BITSET_WORDBITS);
+
+ if (amount == 0)
+ return;
+
+ for (unsigned i = 0; i < n - 1; i++) {
+ x[i] = (x[i] >> amount) | (x[i + 1] << (BITSET_WORDBITS - amount));
+ }
+
+ x[n - 1] = x[n - 1] >> amount;
+}
+
+static inline void
+__bitset_shr(BITSET_WORD *x, unsigned amount, unsigned n)
+{
+ const unsigned int words = amount / BITSET_WORDBITS;
+
+ if (amount == 0)
+ return;
+
+ if (words) {
+ unsigned i;
+
+ for (i = 0; i < n - words; i++)
+ x[i] = x[i + words];
+
+ while (i < n)
+ x[i++] = 0;
+
+ amount %= BITSET_WORDBITS;
+ }
+
+ __bitset_rotate_right(x, amount, n);
+}
+
+#define BITSET_SHR(x, n) \
+ __bitset_shr(x, n, ARRAY_SIZE(x));
+
/* bit range operations
*/
#define BITSET_TEST_RANGE(x, b, e) \