43#if __has_include(<bit>)
127 unsigned lz =
clz(buf);
128 unsigned length = lz + 1;
172 static unsigned clz(uint32_t v)
174#if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L
175 return std::countl_zero(v);
183 static constexpr std::array<int,32> MultiplyDeBruijnBitPosition =
185 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
186 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
195 return 31 - MultiplyDeBruijnBitPosition[
static_cast<uint32_t
>(v * 0x07C4ACDDU) >> 27];
210 return val >> (64 - bits);
238 unsigned lz =
clz(buf);
239 unsigned length = lz + 1;
240 unsigned size = lz + length;
244 if (length > max_length || length > 16)
271 m_cache |=
static_cast<uint64_t
>(*m_buffer) << (shift - bits);
278 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.