66 uword c, d, result, n_bits;
67 uword explicit_end, implicit_end;
74 implicit_end = c == coding;
75 explicit_end = (zdata & 1) & ~implicit_end;
76 d = (zdata >> explicit_end) & (c - 1);
77 if (explicit_end | implicit_end)
80 n_bits +=
min_log2 (c) + explicit_end;
92 *n_zdata_bits = n_bits;
100 uword explicit_end, implicit_end;
104 ASSERT (data <= coding - 1);
110 implicit_end = c == coding;
111 explicit_end = ((data & (c - 1)) == data);
112 if (explicit_end | implicit_end)
114 uword t = explicit_end & ~implicit_end;
115 result = ((data << t) | t) << shift;
136 else if (data_bytes == 2)
139 else if (data_bytes == 4)
142 else if (data_bytes == 8)
162 else if (data_bytes == 2)
169 else if (data_bytes == 4)
176 else if (data_bytes == 8)
204 d0 =
get_data (data + 0 * data_stride, data_bytes, is_signed);
205 data += 1 * data_stride;
217 #define _(TYPE,IS_SIGNED) \ 218 uword * zvec_encode_##TYPE (uword * zvec, \ 219 uword * zvec_n_bits, \ 225 return zvec_encode_inline (zvec, zvec_n_bits, \ 227 data, data_stride, n_data, \ 270 put_data (data + 0 * data_stride, data_bytes, is_signed, d0);
271 data += 1 * data_stride;
277 #define _(TYPE,IS_SIGNED) \ 278 void zvec_decode_##TYPE (uword * zvec, \ 279 uword * zvec_n_bits, \ 285 return zvec_decode_inline (zvec, zvec_n_bits, \ 287 data, data_stride, n_data, \ 307 uword n_type_bits, n_bits;
308 uword this_count, last_count, max_count_index;
314 max_count_index =
vec_len (histogram_counts) - 1;
317 if (coding <= max_count_index)
328 histogram_counts[i > max_count_index ? max_count_index : i - 1];
331 if (this_count == last_count)
338 n_bits += (this_count - last_count) * (n_type_bits + l);
341 if (n_bits >= min_bits)
344 last_count = this_count;
353 _zvec_coding_from_histogram (
void *histogram,
355 uword histogram_elt_count_offset,
356 uword histogram_elt_bytes,
357 uword max_value_to_encode,
360 uword coding, min_coding;
361 uword min_coding_bits, coding_bits;
362 uword i, n_bits_set, total_count;
366 if (histogram_len < 1)
368 coding_return->
coding = 0;
370 coding_return->
n_data = 0;
378 for (i = 0; i < histogram_len; i++)
381 total_count += this_count;
382 counts[
i] = total_count;
388 min_coding_bits = ~0;
392 max_value_to_encode !=
393 ~0 ? (1 + max_value_to_encode) :
vec_len (counts);
396 for (n_bits_set = 1; n_bits_set <= 8; n_bits_set++)
403 if (coding_bits >= min_coding_bits)
405 min_coding_bits = coding_bits;
413 coding_return->
coding = min_coding;
415 coding_return->
n_data = total_count;
418 (
f64) min_coding_bits / (
f64) total_count;
431 "zvec coding 0x%x, %d elts, %d codes, %d bits total, %.4f ave bits/code",
static void zvec_decode_inline(uword *zvec, uword *zvec_n_bits, uword coding, void *data, uword data_stride, uword n_data, uword data_bytes, uword is_signed)
static uword min_log2(uword x)
static uword pow2_mask(uword x)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
uword zvec_decode(uword coding, uword zdata, uword *n_zdata_bits)
uword zvec_encode(uword coding, uword data, uword *n_result_bits)
static void put_data(void *data, uword data_bytes, uword is_signed, uword x)
static uword zvec_signed_to_unsigned(word s)
static uword * zvec_encode_inline(uword *zvec, uword *zvec_n_bits, uword coding, void *data, uword data_stride, uword n_data, uword data_bytes, uword is_signed)
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.
u32 zvec_histogram_count_t
#define vec_free(V)
Free vector's memory (no header).
static uword max_pow2(uword x)
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
static uword first_set(uword x)
static uword coding_max_n_bits(uword coding)
static uword get_data(void *data, uword data_bytes, uword is_signed)
Bitmaps built as vectors of machine words.
static word zvec_unsigned_to_signed(uword u)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword zvec_coding_bits(uword coding, uword *histogram_counts, uword min_bits)
u8 * format_zvec_coding(u8 *s, va_list *args)
static uword next_with_same_number_of_set_bits(uword x)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".