34#if __has_include(<bit>)
118 unsigned lz =
clz(buf);
119 unsigned length = lz + 1;
163 static unsigned clz(uint32_t v)
165#if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L
166 return std::countl_zero(v);
174 static constexpr std::array<int,32> MultiplyDeBruijnBitPosition =
176 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
177 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
186 return 31 - MultiplyDeBruijnBitPosition[
static_cast<uint32_t
>(v * 0x07C4ACDDU) >> 27];
201 return val >> (64 - bits);
229 unsigned lz =
clz(buf);
230 unsigned length = lz + 1;
231 unsigned size = lz + length;
235 if (length > max_length || length > 16)
262 m_cache |=
static_cast<uint64_t
>(*m_buffer) << (shift - bits);
269 m_cache |=
static_cast<uint64_t
>(*m_buffer) >> (bits - shift);
unsigned m_bitIndex
index for next bit read from the MSB
int get_ue_golomb_31()
read unsigned exp golomb code, constraint to a max of 31.
uint32_t show_bits(unsigned n)
int get_ue_golomb()
Read an unsigned Exp-Golomb code in the range 0 to 8190 (2^13 - 2).
BitReader(const uint8_t *buffer, uint64_t size)
static constexpr unsigned kCacheSizeMax
static constexpr uint64_t get_upper_bits(uint64_t val, unsigned bits)
static constexpr unsigned kBitsPerRead
static unsigned clz(uint32_t v)
uint64_t get_bits64(unsigned n)
Read 0-64 bits.
void refill_cache(unsigned min_bits)
const uint8_t *const m_bufferEnd
past the end pointer
const uint8_t * m_buffer
next memory location to read from
void skip_bits(unsigned n)
uint32_t get_ue_golomb_long()
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
int get_se_golomb()
read signed exp golomb code.
uint64_t m_cache
cache for reads.
uint64_t show_bits64(unsigned n)
uint32_t get_bits(unsigned n)
Read 0-32 bits.