129 #define VLI_L_1_1() do { \
130 LEVEL( 2, 1, 0x00); \
131 LEVEL( 3, 2, 0x01); \
132 LEVEL( 5, 3, 0x03); \
133 LEVEL( 7, 4, 0x07); \
134 LEVEL(10, 5, 0x0f); \
135 LEVEL(14, 6, 0x1f); \
136 LEVEL(21, 8, 0x3f); \
137 LEVEL(29, 8, 0x7f); \
138 LEVEL(42, 8, 0xbf); \
139 LEVEL(64, 8, 0xff); \
146 static inline int vli_decode_bits(
u64 *
out,
const u64 in)
150 #define LEVEL(t,b,v) \
152 if ((in & ((1 << b) -1)) == v) { \
153 *out = ((in & ((~0ULL) >> (64-t))) >> b) + adj; \
156 adj += 1ULL << (t - b); \
168 static inline int __vli_encode_bits(
u64 *
out,
const u64 in)
176 #define LEVEL(t,b,v) do { \
177 max += 1ULL << (t - b); \
180 *out = ((in - adj) << b) | v; \
222 cur->
b = cur->
b + (bits >> 3);
238 static inline void bitstream_init(
struct bitstream *bs,
void *
s,
size_t len,
unsigned int pad_bits)
243 bitstream_cursor_reset(&bs->
cur, bs->
buf);
246 static inline void bitstream_rewind(
struct bitstream *bs)
248 bitstream_cursor_reset(&bs->
cur, bs->
buf);
260 static inline int bitstream_put_bits(
struct bitstream *bs,
u64 val,
const unsigned int bits)
262 unsigned char *
b = bs->
cur.b;
273 val &= ~0ULL >> (64 -
bits);
275 *b++ |= (val & 0xff) << bs->
cur.bit;
277 for (tmp = 8 - bs->
cur.bit; tmp < bits; tmp += 8)
278 *b++ |= (val >>
tmp) & 0xff;
280 bitstream_cursor_advance(&bs->
cur, bits);
293 static inline int bitstream_get_bits(
struct bitstream *bs,
u64 *out,
int bits)
312 n = (bs->
cur.bit + bits + 7) >> 3;
321 val |= bs->
cur.b[0] >> bs->
cur.bit;
324 val &= ~0ULL >> (64 -
bits);
326 bitstream_cursor_advance(&bs->
cur, bits);
340 static inline int vli_encode_bits(
struct bitstream *bs,
u64 in)
343 int bits = __vli_encode_bits(&code, in);
348 return bitstream_put_bits(bs, code, bits);