Lines Matching defs:bs
238 static inline void bitstream_init(struct bitstream *bs, void *s, size_t len, unsigned int pad_bits)
240 bs->buf = s;
241 bs->buf_len = len;
242 bs->pad_bits = 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);
249 memset(bs->buf, 0, bs->buf_len);
260 static inline int bitstream_put_bits(struct bitstream *bs, u64 val, const unsigned int bits)
262 unsigned char *b = bs->cur.b;
268 if ((bs->cur.b + ((bs->cur.bit + bits -1) >> 3)) - bs->buf >= bs->buf_len)
275 *b++ |= (val & 0xff) << bs->cur.bit;
277 for (tmp = 8 - bs->cur.bit; tmp < bits; tmp += 8)
280 bitstream_cursor_advance(&bs->cur, bits);
293 static inline int bitstream_get_bits(struct bitstream *bs, u64 *out, int bits)
301 if (bs->cur.b + ((bs->cur.bit + bs->pad_bits + bits -1) >> 3) - bs->buf >= bs->buf_len)
302 bits = ((bs->buf_len - (bs->cur.b - bs->buf)) << 3)
303 - bs->cur.bit - bs->pad_bits;
312 n = (bs->cur.bit + bits + 7) >> 3;
316 memcpy(&val, bs->cur.b+1, n - 1);
317 val = le64_to_cpu(val) << (8 - bs->cur.bit);
321 val |= bs->cur.b[0] >> bs->cur.bit;
326 bitstream_cursor_advance(&bs->cur, bits);
332 /* encodes @in as vli into @bs;
336 * -ENOBUFS @bs is full
340 static inline int vli_encode_bits(struct bitstream *bs, u64 in)
348 return bitstream_put_bits(bs, code, bits);