X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fbitmap.h;h=92205bfc8e8428bf44ccf0f25e82ebb3bf2cee4f;hb=bf37bf6f79a4d6242b35361c04d559c6bd8e6b2e;hp=4441116397583d397199997e716b484b2f7244c1;hpb=37b445468e45b537621269fc1e375f26ca2100ee;p=vpp.git diff --git a/src/vppinfra/bitmap.h b/src/vppinfra/bitmap.h index 44411163975..92205bfc8e8 100644 --- a/src/vppinfra/bitmap.h +++ b/src/vppinfra/bitmap.h @@ -358,24 +358,11 @@ clib_bitmap_set_region (uword * bitmap, uword i, uword value, uword n_bits) @param ai - the bitmap @param body - the expression to evaluate for each set bit */ -#define clib_bitmap_foreach(i,ai,body) \ -do { \ - uword __bitmap_i, __bitmap_ai, __bitmap_len, __bitmap_first_set; \ - __bitmap_len = vec_len ((ai)); \ - for (__bitmap_i = 0; __bitmap_i < __bitmap_len; __bitmap_i++) \ - { \ - __bitmap_ai = (ai)[__bitmap_i]; \ - while (__bitmap_ai != 0) \ - { \ - __bitmap_first_set = first_set (__bitmap_ai); \ - (i) = (__bitmap_i * BITS ((ai)[0]) \ - + min_log2 (__bitmap_first_set)); \ - do { body; } while (0); \ - __bitmap_ai ^= __bitmap_first_set; \ - } \ - } \ -} while (0) - +#define clib_bitmap_foreach(i,ai) \ + if (ai) \ + for (i = clib_bitmap_first_set (ai); \ + i != ~0; \ + i = clib_bitmap_next_set (ai, i + 1)) /** Return the lowest numbered set bit in a bitmap @param ai - pointer to the bitmap @@ -735,127 +722,11 @@ clib_bitmap_next_clear (uword * ai, uword i) return i; } -/** unformat an any sized hexadecimal bitmask into a bitmap - - uword * bitmap; - rv = unformat ("%U", unformat_bitmap_mask, &bitmap); - - Standard unformat_function_t arguments - - @param input - pointer an unformat_input_t - @param va - varargs list comprising a single uword ** - @returns 1 on success, 0 on failure -*/ -static inline uword -unformat_bitmap_mask (unformat_input_t * input, va_list * va) -{ - u8 *v = 0; /* hexadecimal vector */ - uword **bitmap_return = va_arg (*va, uword **); - uword *bitmap = 0; - - if (unformat (input, "%U", unformat_hex_string, &v)) - { - int i, s = vec_len (v) - 1; /* 's' for significance or shift */ - - /* v[0] holds the most significant byte */ - for (i = 0; s >= 0; i++, s--) - bitmap = clib_bitmap_set_multiple (bitmap, - s * BITS (v[i]), v[i], - BITS (v[i])); - - vec_free (v); - *bitmap_return = bitmap; - return 1; - } - - return 0; -} - -/** unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" ) - - uword * bitmap; - rv = unformat ("%U", unformat_bitmap_list, &bitmap); - - Standard unformat_function_t arguments - - @param input - pointer an unformat_input_t - @param va - varargs list comprising a single uword ** - @returns 1 on success, 0 on failure -*/ -static inline uword -unformat_bitmap_list (unformat_input_t * input, va_list * va) -{ - uword **bitmap_return = va_arg (*va, uword **); - uword *bitmap = 0; - - u32 a, b; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - int i; - if (unformat (input, "%u-%u,", &a, &b)) - ; - else if (unformat (input, "%u,", &a)) - b = a; - else if (unformat (input, "%u-%u", &a, &b)) - ; - else if (unformat (input, "%u", &a)) - b = a; - else if (bitmap) - { - unformat_put_input (input); - break; - } - else - goto error; - - if (b < a) - goto error; - - for (i = a; i <= b; i++) - bitmap = clib_bitmap_set (bitmap, i, 1); - } - *bitmap_return = bitmap; - return 1; -error: - clib_bitmap_free (bitmap); - return 0; -} - -/** Format a bitmap as a string of hex bytes - - uword * bitmap; - s = format ("%U", format_bitmap_hex, bitmap); +uword unformat_bitmap_mask (unformat_input_t *input, va_list *va); +uword unformat_bitmap_list (unformat_input_t *input, va_list *va); +u8 *format_bitmap_hex (u8 *s, va_list *args); +u8 *format_bitmap_list (u8 *s, va_list *args); - Standard format_function_t arguments - - @param s - string under construction - @param args - varargs list comprising a single uword * - @returns string under construction -*/ -static inline u8 * -format_bitmap_hex (u8 * s, va_list * args) -{ - uword *bitmap = va_arg (*args, uword *); - int i, is_trailing_zero = 1; - - if (!bitmap) - return format (s, "0"); - - i = vec_bytes (bitmap) * 2; - - while (i > 0) - { - u8 x = clib_bitmap_get_multiple (bitmap, --i * 4, 4); - - if (x && is_trailing_zero) - is_trailing_zero = 0; - - if (x || !is_trailing_zero) - s = format (s, "%x", x); - } - return s; -} #endif /* included_clib_bitmap_h */ /*