diff options
author | 2025-02-13 14:37:13 +0000 | |
---|---|---|
committer | 2025-02-13 23:32:46 +0100 | |
commit | 1ed6edcf96bde863efddb895ca460d688c71c1f9 (patch) | |
tree | 9c09dae8675c142ecb2e1fa648ca9abfa702ec80 | |
parent | c06242e5f0bbd56e2f9dc5fba699c01155fcb532 (diff) |
vppinfra: add few uword_bitmap_* functions
Change-Id: I592668a385489d0eaccd9e7693121ff25090e353
Type: improvement
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/vppinfra/bitops.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/vppinfra/bitops.h b/src/vppinfra/bitops.h index c1122f59ff6..bf73bd95a84 100644 --- a/src/vppinfra/bitops.h +++ b/src/vppinfra/bitops.h @@ -195,6 +195,13 @@ next_with_same_number_of_set_bits (uword x) return ripple | ones; } +static_always_inline void +uword_bitmap_clear (uword *bmp, uword n_uwords) +{ + while (n_uwords--) + bmp++[0] = 0; +} + #define foreach_set_bit_index(i, v) \ for (uword _tmp = (v) + 0 * (uword) (i = get_lowest_set_bit_index (v)); \ _tmp; \ @@ -273,6 +280,34 @@ uword_bitmap_find_first_set (uword *bmp) return (b - bmp) * uword_bits + get_lowest_set_bit_index (b[0]); } +always_inline uword +uword_bitmap_get_multiple (uword *bmp, uword i, uword n_bits) +{ + uword rv; + + bmp += i / uword_bits; + i %= uword_bits; + + rv = (bmp[0] >> i); + rv &= pow2_mask (n_bits); + + if (i + n_bits <= uword_bits) + return rv; + + n_bits -= uword_bits - i; + rv |= (bmp[1] & pow2_mask (n_bits)) << (uword_bits - i); + + return rv; +} + +always_inline uword +uword_bitmap_get_multiple_no_check (uword *bmp, uword i, uword n_bits) +{ + bmp += i / uword_bits; + i %= uword_bits; + return ((bmp[0] >> i) & pow2_mask (n_bits)); +} + static_always_inline u32 bit_extract_u32 (u32 v, u32 mask) { |