diff options
author | Timothy Arceri <[email protected]> | 2020-04-29 14:15:12 +1000 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-06-03 10:34:22 +0000 |
commit | d6d78f9b7ff02354af3ac8a918bb5cec6c4718e8 (patch) | |
tree | d49b0c5de5b345f3373c96f7117c056df7a3e1ef /src/util | |
parent | f518508a817aa5af1eee988439f73ecf6279e9c5 (diff) |
util: add BITSET_LAST_BIT() helper
This is the reverse of BITSET_FFS()
Reviewed-by: Kenneth Graunke <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4910>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/bitset.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h index 0fdfe205f39..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, |