1 #ifndef _TURBOPFOR_COMMON_H
2 #define _TURBOPFOR_COMMON_H 1
4 // Common definitions and utilities between turbopfor.h (decode)
5 // and turbopfor-encode.h (encode).
16 // Does not properly account for overflow.
17 inline unsigned div_round_up(unsigned val, unsigned div)
19 return (val + div - 1) / div;
22 inline unsigned bytes_for_packed_bits(unsigned num, unsigned bit_width)
24 return div_round_up(num * bit_width, CHAR_BIT);
27 constexpr uint32_t mask_for_bits(unsigned bit_width)
29 if (bit_width == 32) {
32 return (1U << bit_width) - 1;
36 #endif // !defined(_TURBOPFOR_COMMON_H)