diff options
| -rw-r--r-- | src/util/bitset.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util/bitset.h b/src/util/bitset.h index f0b16ea9964..279ad553e79 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -205,6 +205,25 @@ __bitset_shl(BITSET_WORD *x, unsigned amount, unsigned n) ((x)[BITSET_BITWORD(b)] &= ~BITSET_RANGE(b, e)) : \ (assert (!"BITSET_CLEAR_RANGE: bit range crosses word boundary"), 0)) +static inline void +__bitset_set_range(BITSET_WORD *r, unsigned start, unsigned end) +{ + const unsigned size = end - start; + const unsigned start_mod = start % BITSET_WORDBITS; + + if (start_mod + size <= BITSET_WORDBITS) { + BITSET_SET_RANGE_INSIDE_WORD(r, start, end); + } else { + const unsigned first_size = BITSET_WORDBITS - start_mod; + + __bitset_set_range(r, start, start + first_size - 1); + __bitset_set_range(r, start + first_size, end); + } +} + +#define BITSET_SET_RANGE(x, b, e) \ + __bitset_set_range(x, b, e) + static inline unsigned __bitset_prefix_sum(const BITSET_WORD *x, unsigned b, unsigned n) { |