|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
38 #ifndef included_clib_bitmap_h
39 #define included_clib_bitmap_h
87 #define clib_bitmap_dup(v) vec_dup(v)
92 #define clib_bitmap_free(v) vec_free(v)
97 #define clib_bitmap_bytes(v) vec_bytes(v)
102 #define clib_bitmap_zero(v) vec_zero(v)
109 #define clib_bitmap_alloc(v,n_bits) \
110 v = vec_new (uword, ((n_bits) + BITS (uword) - 1) / BITS (uword))
112 #define clib_bitmap_vec_validate(v,i) vec_validate_aligned((v),(i),sizeof(uword))
115 #define clib_bitmap_validate(v,n_bits) \
116 clib_bitmap_vec_validate ((v), ((n_bits) - 1) / BITS (uword))
120 _clib_bitmap_remove_trailing_zeros (
uword *
a)
125 for (
i = _vec_len (
a) - 1;
i >= 0;
i--)
128 _vec_len (
a) =
i + 1;
152 old_value = (ai & bit) != 0;
154 ai |= ((
uword) (new_value != 0)) << i1;
186 ai = _clib_bitmap_remove_trailing_zeros (ai);
201 return i0 <
vec_len (ai) && 0 != ((ai[i0] >> i1) & 1);
216 return 0 != ((ai[i0] >> i1) & 1);
225 return 0 != ((ai[i0] >> i1) &
pow2_mask (n_bits));
237 uword i0, i1, result;
242 i0 =
i /
BITS (bitmap[0]);
243 i1 =
i %
BITS (bitmap[0]);
249 result |= (bitmap[i0] >> i1);
250 if (n_bits <
BITS (bitmap[0]))
251 result &= (((
uword) 1 << n_bits) - 1);
256 if (i1 + n_bits >
BITS (bitmap[0]) && i0 < l)
258 n_bits -=
BITS (bitmap[0]) - i1;
260 (bitmap[i0] & (((
uword) 1 << n_bits) - 1)) << (
BITS (bitmap[0]) - i1);
277 uword i0, i1, l, t, m;
281 i0 =
i /
BITS (bitmap[0]);
282 i1 =
i %
BITS (bitmap[0]);
290 m = (((
uword) 1 << n_bits) - 1);
301 if (i1 + n_bits >
BITS (bitmap[0]) && i0 < l)
303 t =
BITS (bitmap[0]) - i1;
307 m = ((
uword) 1 << n_bits) - 1;
322 a0 =
i /
BITS (bitmap[0]);
323 a1 =
i %
BITS (bitmap[0]);
326 b0 = i_end /
BITS (bitmap[0]);
339 for (a0++; a0 < b0; a0++)
340 bitmap[a0] =
value ? ~0 : 0;
344 word n_bits_left = n_bits - (
BITS (bitmap[0]) - a1);
361 #define clib_bitmap_foreach(i,ai) \
363 for (i = clib_bitmap_first_set (ai); \
365 i = clib_bitmap_next_set (ai, i + 1))
376 #if defined(CLIB_HAVE_VEC256)
380 v = u64x4_load_unaligned (ai +
i) | u64x4_load_unaligned (ai +
i + 4);
381 if (!u64x4_is_all_zero (v))
385 #elif defined(CLIB_HAVE_VEC128) && defined(CLIB_HAVE_VEC128_UNALIGNED_LOAD_STORE)
389 v = u64x2_load_unaligned (ai +
i) | u64x2_load_unaligned (ai +
i + 2);
390 if (!u64x2_is_all_zero (v))
421 return (
i) *
BITS (ai[0]) - first_bit - 1;
441 return i *
BITS (ai[0]);
498 #define _(name, body, check_zero) \
499 always_inline uword * \
500 clib_bitmap_##name (uword * ai, uword * bi) \
502 uword i, a, b, bi_len, n_trailing_zeros; \
504 n_trailing_zeros = 0; \
505 bi_len = vec_len (bi); \
507 clib_bitmap_vec_validate (ai, bi_len - 1); \
508 for (i = 0; i < vec_len (ai); i++) \
511 b = i < bi_len ? bi[i] : 0; \
512 do { body; } while (0); \
515 n_trailing_zeros = a ? 0 : (n_trailing_zeros + 1); \
518 _vec_len (ai) -= n_trailing_zeros; \
563 always_inline uword * \
564 clib_bitmap_dup_##name (uword * ai, uword * bi) \
565 { return clib_bitmap_##name (clib_bitmap_dup (ai), bi); }
577 #define _(name, body, check_zero) \
578 always_inline uword * \
579 clib_bitmap_##name (uword * ai, uword i) \
581 uword i0 = i / BITS (ai[0]); \
582 uword i1 = i % BITS (ai[0]); \
584 clib_bitmap_vec_validate (ai, i0); \
586 b = (uword) 1 << i1; \
587 do { body; } while (0); \
589 if (check_zero && a == 0) \
590 ai = _clib_bitmap_remove_trailing_zeros (ai); \
596 _(andi,
a =
a &
b, 1)
597 _(andnoti,
a =
a & ~
b, 1)
599 _(xori,
a =
a ^
b, 1)
605 #define _(name, body) \
606 always_inline uword * \
607 clib_bitmap_##name##_notrim (uword * ai, uword i) \
609 uword i0 = i / BITS (ai[0]); \
610 uword i1 = i % BITS (ai[0]); \
612 clib_bitmap_vec_validate (ai, i0); \
614 b = (uword) 1 << i1; \
615 do { body; } while (0); \
623 _(andnoti,
a =
a & ~
b)
648 i0 =
i /
BITS (ai[0]);
649 i1 =
i %
BITS (ai[0]);
652 for (
i = 0;
i <= i0;
i++)
655 for (n = 0; n <
BITS (ai[
i]); n += log2_rand_max)
658 if (i1 + 1 <
BITS (ai[0]))
659 ai[i0] &= (((
uword) 1 << (i1 + 1)) - 1);
679 t = (ai[i0] >> i1) << i1;
683 for (i0++; i0 <
vec_len (ai); i0++)
708 t = (~ai[i0] >> i1) << i1;
712 for (i0++; i0 <
vec_len (ai); i0++)
720 return (i0 *
BITS (ai[0])) + 1;
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static uword clib_bitmap_is_equal(uword *a, uword *b)
predicate function; are two bitmaps equal?
static uword * clib_bitmap_dup_and(uword *ai, uword *bi)
Logical operator across two bitmaps which duplicates the first bitmap.
static uword pow2_mask(uword x)
#define count_leading_zeros(x)
static uword * clib_bitmap_dup_andnot(uword *ai, uword *bi)
Logical operator across two bitmaps which duplicates the first bitmap.
static uword clib_bitmap_first_set(uword *ai)
Return the lowest numbered set bit in a bitmap.
epu8_epi32 epu16_epi32 u64x2
static uword * clib_bitmap_andnot(uword *ai, uword *bi)
Logical operator across two bitmaps.
static uword clib_bitmap_first_clear(uword *ai)
Return the lowest numbered clear bit in a bitmap.
static uword * clib_bitmap_dup_xor(uword *ai, uword *bi)
Logical operator across two bitmaps which duplicates the first bitmap.
static u32 random_u32_max(void)
Maximum value returned by random_u32()
static u32 random_u32(u32 *seed)
32-bit random number generator
u8 * format_bitmap_hex(u8 *s, va_list *args)
Format a bitmap as a string of hex bytes.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
static uword * clib_bitmap_or(uword *ai, uword *bi)
Logical operator across two bitmaps.
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
static uword * clib_bitmap_set_region(uword *bitmap, uword i, uword value, uword n_bits)
__clib_export uword unformat_bitmap_mask(unformat_input_t *input, va_list *va)
unformat an any sized hexadecimal bitmask into a bitmap
static uword clib_bitmap_get_multiple_no_check(uword *ai, uword i, uword n_bits)
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap.
static uword * clib_bitmap_and(uword *ai, uword *bi)
Logical operator across two bitmaps.
uword unformat_bitmap_list(unformat_input_t *input, va_list *va)
unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
static uword clib_bitmap_get_no_check(uword *ai, uword i)
Gets the ith bit value from a bitmap Does not sanity-check the bit position.
static uword count_set_bits(uword x)
u8 * format_bitmap_list(u8 *s, va_list *args)
Format a bitmap as a list.
static uword log2_first_set(uword x)
static uword clib_bitmap_last_set(uword *ai)
Return the higest numbered set bit in a bitmap.
static uword * clib_bitmap_xor(uword *ai, uword *bi)
Logical operator across two bitmaps.
static uword clib_bitmap_get_multiple(uword *bitmap, uword i, uword n_bits)
Gets the ith through ith + n_bits bit values from a bitmap.
static uword min_log2(uword x)
static uword clib_bitmap_set_no_check(uword *a, uword i, uword new_value)
Sets the ith bit of a bitmap to new_value.
#define clib_bitmap_vec_validate(v, i)
static uword * clib_bitmap_dup_or(uword *ai, uword *bi)
Logical operator across two bitmaps which duplicates the first bitmap.
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
static uword * clib_bitmap_set_multiple(uword *bitmap, uword i, uword value, uword n_bits)
sets the ith through ith + n_bits bits in a bitmap