Lines Matching defs:bs
226 static inline void bitstream_init(struct bitstream *bs, void *s, size_t len, unsigned int pad_bits)
228 bs->buf = s;
229 bs->buf_len = len;
230 bs->pad_bits = pad_bits;
231 bitstream_cursor_reset(&bs->cur, bs->buf);
234 static inline void bitstream_rewind(struct bitstream *bs)
236 bitstream_cursor_reset(&bs->cur, bs->buf);
237 memset(bs->buf, 0, bs->buf_len);
248 static inline int bitstream_put_bits(struct bitstream *bs, u64 val, const unsigned int bits)
250 unsigned char *b = bs->cur.b;
256 if ((bs->cur.b + ((bs->cur.bit + bits -1) >> 3)) - bs->buf >= bs->buf_len)
263 *b++ |= (val & 0xff) << bs->cur.bit;
265 for (tmp = 8 - bs->cur.bit; tmp < bits; tmp += 8)
268 bitstream_cursor_advance(&bs->cur, bits);
281 static inline int bitstream_get_bits(struct bitstream *bs, u64 *out, int bits)
289 if (bs->cur.b + ((bs->cur.bit + bs->pad_bits + bits -1) >> 3) - bs->buf >= bs->buf_len)
290 bits = ((bs->buf_len - (bs->cur.b - bs->buf)) << 3)
291 - bs->cur.bit - bs->pad_bits;
300 n = (bs->cur.bit + bits + 7) >> 3;
304 memcpy(&val, bs->cur.b+1, n - 1);
305 val = le64_to_cpu(val) << (8 - bs->cur.bit);
309 val |= bs->cur.b[0] >> bs->cur.bit;
314 bitstream_cursor_advance(&bs->cur, bits);
320 /* encodes @in as vli into @bs;
324 * -ENOBUFS @bs is full
328 static inline int vli_encode_bits(struct bitstream *bs, u64 in)
336 return bitstream_put_bits(bs, code, bits);