#include <vppinfra/error.h>
#include <vppinfra/bitops.h> /* for count_set_bits */
+typedef uword clib_bitmap_t;
+
/* Returns 1 if the entire bitmap is zero, 0 otherwise */
always_inline uword
clib_bitmap_is_zero (uword * ai)
return ~0;
}
+/* Return highest numbered set bit in bitmap.
+
+ Return infinity (~0) if bitmap is zero. */
+always_inline uword clib_bitmap_last_set (uword * ai)
+{
+ uword i;
+
+ for (i = vec_len (ai); i > 0 ; i--)
+ {
+ uword x = ai[i - 1];
+ if (x != 0)
+ {
+ uword first_bit;
+ count_leading_zeros (first_bit, x);
+ return (i) * BITS (ai[0]) - first_bit - 1;
+ }
+ }
+ return ~0;
+}
+
/* Return lowest numbered clear bit in bitmap. */
always_inline uword
clib_bitmap_first_clear (uword * ai)
else
goto error;
- if ((b < a) || (b > 63))
+ if (b < a)
goto error;
for (i = a; i <= b; i++)
return 0;
}
+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 */