mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 18:18:06 +02:00
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>
This commit is contained in:
parent
79067c4744
commit
7b62fb4558
1 changed files with 41 additions and 0 deletions
|
|
@ -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) \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue