diff options
author | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2017-05-02 17:30:22 +0200 |
---|---|---|
committer | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2018-03-14 09:04:01 +0100 |
commit | 2ed6f03d3bf2fb5671776375a0a6132bba30c9f0 (patch) | |
tree | baa68348f0778bc8cde33572f5074e68beef3cd2 | |
parent | 2044a221528b029c53a8228b3c426f3c8fbabfd4 (diff) |
util/bitset: add BITSET_LAST_BIT
-rw-r--r-- | src/util/bitset.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h index 32c8b43954..b972e63adc 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -32,6 +32,7 @@ #define BITSET_H #include "util/u_math.h" +#include "util/bitscan.h" /**************************************************************************** * generic bitset implementation @@ -129,6 +130,26 @@ __bitset_ffs(const BITSET_WORD *x, int n) #define BITSET_FFS(x) __bitset_ffs(x, ARRAY_SIZE(x)) static inline unsigned +__bitset_last_bit(const BITSET_WORD *x, int n) +{ + STATIC_ASSERT(sizeof(BITSET_WORD) == sizeof(unsigned)); + + for (int i = n - 1; i >= 0; --i) { + unsigned bit = util_last_bit(x[i]); + if (bit > 1) + return bit + BITSET_WORDBITS * i; + } + + return 0; +} + +/** + * Find last bit set in a bitset. The least significant bit is 1. + * Return 0 if no bits are set. + */ +#define BITSET_LAST_BIT(x) __bitset_last_bit((x), ARRAY_SIZE((x))) + +static inline unsigned __bitset_next_set(unsigned i, BITSET_WORD *tmp, const BITSET_WORD *set, unsigned size) { |