X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fbitset.h;h=012764afc42a725fd8722d136117734a1e20dfaa;hb=HEAD;hp=7f116214b920c0b8431e76f8093d8829428dc80c;hpb=512a31a41299758f0f60d0452b8c9e8c02238189;p=mesa.git diff --git a/src/util/bitset.h b/src/util/bitset.h index 7f116214b92..012764afc42 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -95,7 +95,21 @@ __bitset_ffs(const BITSET_WORD *x, int n) return 0; } +/* Get the last bit set in a bitset. + */ +static inline int +__bitset_last_bit(const BITSET_WORD *x, int n) +{ + for (int i = n - 1; i >= 0; i--) { + if (x[i]) + return util_last_bit(x[i]) + BITSET_WORDBITS * i; + } + + return 0; +} + #define BITSET_FFS(x) __bitset_ffs(x, ARRAY_SIZE(x)) +#define BITSET_LAST_BIT(x, size) __bitset_last_bit(x, size) static inline unsigned __bitset_next_set(unsigned i, BITSET_WORD *tmp, @@ -129,9 +143,17 @@ __bitset_next_set(unsigned i, BITSET_WORD *tmp, return word * BITSET_WORDBITS + bit; } -#define BITSET_FOREACH_SET(__i, __tmp, __set, __size) \ - for (__tmp = *(__set), __i = 0; \ - (__i = __bitset_next_set(__i, &__tmp, __set, __size)) < __size;) +/** + * Iterates over each set bit in a set + * + * @param __i iteration variable, bit number + * @param __set the bitset to iterate (will not be modified) + * @param __size number of bits in the set to consider + */ +#define BITSET_FOREACH_SET(__i, __set, __size) \ + for (BITSET_WORD __tmp = *(__set), *__foo = &__tmp; __foo != NULL; __foo = NULL) \ + for (__i = 0; \ + (__i = __bitset_next_set(__i, &__tmp, __set, __size)) < __size;) #ifdef __cplusplus