xref: /openbmc/linux/drivers/block/drbd/drbd_vli.h (revision 25985edcedea6396277003854657b5f3cb31a628)
1b411b363SPhilipp Reisner /*
2b411b363SPhilipp Reisner -*- linux-c -*-
3b411b363SPhilipp Reisner    drbd_receiver.c
4b411b363SPhilipp Reisner    This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
5b411b363SPhilipp Reisner 
6b411b363SPhilipp Reisner    Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
7b411b363SPhilipp Reisner    Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
8b411b363SPhilipp Reisner    Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
9b411b363SPhilipp Reisner 
10b411b363SPhilipp Reisner    drbd is free software; you can redistribute it and/or modify
11b411b363SPhilipp Reisner    it under the terms of the GNU General Public License as published by
12b411b363SPhilipp Reisner    the Free Software Foundation; either version 2, or (at your option)
13b411b363SPhilipp Reisner    any later version.
14b411b363SPhilipp Reisner 
15b411b363SPhilipp Reisner    drbd is distributed in the hope that it will be useful,
16b411b363SPhilipp Reisner    but WITHOUT ANY WARRANTY; without even the implied warranty of
17b411b363SPhilipp Reisner    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18b411b363SPhilipp Reisner    GNU General Public License for more details.
19b411b363SPhilipp Reisner 
20b411b363SPhilipp Reisner    You should have received a copy of the GNU General Public License
21b411b363SPhilipp Reisner    along with drbd; see the file COPYING.  If not, write to
22b411b363SPhilipp Reisner    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23b411b363SPhilipp Reisner  */
24b411b363SPhilipp Reisner 
25b411b363SPhilipp Reisner #ifndef _DRBD_VLI_H
26b411b363SPhilipp Reisner #define _DRBD_VLI_H
27b411b363SPhilipp Reisner 
28b411b363SPhilipp Reisner /*
29b411b363SPhilipp Reisner  * At a granularity of 4KiB storage represented per bit,
30b411b363SPhilipp Reisner  * and stroage sizes of several TiB,
31b411b363SPhilipp Reisner  * and possibly small-bandwidth replication,
32b411b363SPhilipp Reisner  * the bitmap transfer time can take much too long,
33b411b363SPhilipp Reisner  * if transmitted in plain text.
34b411b363SPhilipp Reisner  *
35*25985edcSLucas De Marchi  * We try to reduce the transferred bitmap information
36b411b363SPhilipp Reisner  * by encoding runlengths of bit polarity.
37b411b363SPhilipp Reisner  *
38b411b363SPhilipp Reisner  * We never actually need to encode a "zero" (runlengths are positive).
39b411b363SPhilipp Reisner  * But then we have to store the value of the first bit.
40b411b363SPhilipp Reisner  * The first bit of information thus shall encode if the first runlength
41b411b363SPhilipp Reisner  * gives the number of set or unset bits.
42b411b363SPhilipp Reisner  *
43b411b363SPhilipp Reisner  * We assume that large areas are either completely set or unset,
44b411b363SPhilipp Reisner  * which gives good compression with any runlength method,
45b411b363SPhilipp Reisner  * even when encoding the runlength as fixed size 32bit/64bit integers.
46b411b363SPhilipp Reisner  *
47b411b363SPhilipp Reisner  * Still, there may be areas where the polarity flips every few bits,
48b411b363SPhilipp Reisner  * and encoding the runlength sequence of those areas with fix size
49b411b363SPhilipp Reisner  * integers would be much worse than plaintext.
50b411b363SPhilipp Reisner  *
51b411b363SPhilipp Reisner  * We want to encode small runlength values with minimum code length,
52b411b363SPhilipp Reisner  * while still being able to encode a Huge run of all zeros.
53b411b363SPhilipp Reisner  *
54b411b363SPhilipp Reisner  * Thus we need a Variable Length Integer encoding, VLI.
55b411b363SPhilipp Reisner  *
56b411b363SPhilipp Reisner  * For some cases, we produce more code bits than plaintext input.
57b411b363SPhilipp Reisner  * We need to send incompressible chunks as plaintext, skip over them
58b411b363SPhilipp Reisner  * and then see if the next chunk compresses better.
59b411b363SPhilipp Reisner  *
60b411b363SPhilipp Reisner  * We don't care too much about "excellent" compression ratio for large
61b411b363SPhilipp Reisner  * runlengths (all set/all clear): whether we achieve a factor of 100
62b411b363SPhilipp Reisner  * or 1000 is not that much of an issue.
63b411b363SPhilipp Reisner  * We do not want to waste too much on short runlengths in the "noisy"
64b411b363SPhilipp Reisner  * parts of the bitmap, though.
65b411b363SPhilipp Reisner  *
66b411b363SPhilipp Reisner  * There are endless variants of VLI, we experimented with:
67b411b363SPhilipp Reisner  *  * simple byte-based
68b411b363SPhilipp Reisner  *  * various bit based with different code word length.
69b411b363SPhilipp Reisner  *
70b411b363SPhilipp Reisner  * To avoid yet an other configuration parameter (choice of bitmap compression
71b411b363SPhilipp Reisner  * algorithm) which was difficult to explain and tune, we just chose the one
72b411b363SPhilipp Reisner  * variant that turned out best in all test cases.
73b411b363SPhilipp Reisner  * Based on real world usage patterns, with device sizes ranging from a few GiB
74b411b363SPhilipp Reisner  * to several TiB, file server/mailserver/webserver/mysql/postgress,
75b411b363SPhilipp Reisner  * mostly idle to really busy, the all time winner (though sometimes only
76b411b363SPhilipp Reisner  * marginally better) is:
77b411b363SPhilipp Reisner  */
78b411b363SPhilipp Reisner 
79b411b363SPhilipp Reisner /*
80b411b363SPhilipp Reisner  * encoding is "visualised" as
81b411b363SPhilipp Reisner  * __little endian__ bitstream, least significant bit first (left most)
82b411b363SPhilipp Reisner  *
83b411b363SPhilipp Reisner  * this particular encoding is chosen so that the prefix code
84b411b363SPhilipp Reisner  * starts as unary encoding the level, then modified so that
85b411b363SPhilipp Reisner  * 10 levels can be described in 8bit, with minimal overhead
86b411b363SPhilipp Reisner  * for the smaller levels.
87b411b363SPhilipp Reisner  *
88b411b363SPhilipp Reisner  * Number of data bits follow fibonacci sequence, with the exception of the
89b411b363SPhilipp Reisner  * last level (+1 data bit, so it makes 64bit total).  The only worse code when
90b411b363SPhilipp Reisner  * encoding bit polarity runlength is 1 plain bits => 2 code bits.
91b411b363SPhilipp Reisner prefix    data bits                                    max val  Nº data bits
92b411b363SPhilipp Reisner 0 x                                                         0x2            1
93b411b363SPhilipp Reisner 10 x                                                        0x4            1
94b411b363SPhilipp Reisner 110 xx                                                      0x8            2
95b411b363SPhilipp Reisner 1110 xxx                                                   0x10            3
96b411b363SPhilipp Reisner 11110 xxx xx                                               0x30            5
97b411b363SPhilipp Reisner 111110 xx xxxxxx                                          0x130            8
98b411b363SPhilipp Reisner 11111100  xxxxxxxx xxxxx                                 0x2130           13
99b411b363SPhilipp Reisner 11111110  xxxxxxxx xxxxxxxx xxxxx                      0x202130           21
100b411b363SPhilipp Reisner 11111101  xxxxxxxx xxxxxxxx xxxxxxxx  xxxxxxxx xx   0x400202130           34
101b411b363SPhilipp Reisner 11111111  xxxxxxxx xxxxxxxx xxxxxxxx  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 56
102b411b363SPhilipp Reisner  * maximum encodable value: 0x100000400202130 == 2**56 + some */
103b411b363SPhilipp Reisner 
104b411b363SPhilipp Reisner /* compression "table":
105b411b363SPhilipp Reisner  transmitted   x                                0.29
106b411b363SPhilipp Reisner  as plaintext x                                  ........................
107b411b363SPhilipp Reisner              x                                   ........................
108b411b363SPhilipp Reisner             x                                    ........................
109b411b363SPhilipp Reisner            x    0.59                         0.21........................
110b411b363SPhilipp Reisner           x      ........................................................
111b411b363SPhilipp Reisner          x       .. c ...................................................
112b411b363SPhilipp Reisner         x    0.44.. o ...................................................
113b411b363SPhilipp Reisner        x .......... d ...................................................
114b411b363SPhilipp Reisner       x  .......... e ...................................................
115b411b363SPhilipp Reisner      X.............   ...................................................
116b411b363SPhilipp Reisner     x.............. b ...................................................
117b411b363SPhilipp Reisner 2.0x............... i ...................................................
118b411b363SPhilipp Reisner  #X................ t ...................................................
119b411b363SPhilipp Reisner  #................. s ...........................  plain bits  ..........
120b411b363SPhilipp Reisner -+-----------------------------------------------------------------------
121b411b363SPhilipp Reisner  1             16              32                              64
122b411b363SPhilipp Reisner */
123b411b363SPhilipp Reisner 
124b411b363SPhilipp Reisner /* LEVEL: (total bits, prefix bits, prefix value),
125b411b363SPhilipp Reisner  * sorted ascending by number of total bits.
126b411b363SPhilipp Reisner  * The rest of the code table is calculated at compiletime from this. */
127b411b363SPhilipp Reisner 
128b411b363SPhilipp Reisner /* fibonacci data 1, 1, ... */
129b411b363SPhilipp Reisner #define VLI_L_1_1() do { \
130b411b363SPhilipp Reisner 	LEVEL( 2, 1, 0x00); \
131b411b363SPhilipp Reisner 	LEVEL( 3, 2, 0x01); \
132b411b363SPhilipp Reisner 	LEVEL( 5, 3, 0x03); \
133b411b363SPhilipp Reisner 	LEVEL( 7, 4, 0x07); \
134b411b363SPhilipp Reisner 	LEVEL(10, 5, 0x0f); \
135b411b363SPhilipp Reisner 	LEVEL(14, 6, 0x1f); \
136b411b363SPhilipp Reisner 	LEVEL(21, 8, 0x3f); \
137b411b363SPhilipp Reisner 	LEVEL(29, 8, 0x7f); \
138b411b363SPhilipp Reisner 	LEVEL(42, 8, 0xbf); \
139b411b363SPhilipp Reisner 	LEVEL(64, 8, 0xff); \
140b411b363SPhilipp Reisner 	} while (0)
141b411b363SPhilipp Reisner 
142b411b363SPhilipp Reisner /* finds a suitable level to decode the least significant part of in.
143b411b363SPhilipp Reisner  * returns number of bits consumed.
144b411b363SPhilipp Reisner  *
145b411b363SPhilipp Reisner  * BUG() for bad input, as that would mean a buggy code table. */
146b411b363SPhilipp Reisner static inline int vli_decode_bits(u64 *out, const u64 in)
147b411b363SPhilipp Reisner {
148b411b363SPhilipp Reisner 	u64 adj = 1;
149b411b363SPhilipp Reisner 
150b411b363SPhilipp Reisner #define LEVEL(t,b,v)					\
151b411b363SPhilipp Reisner 	do {						\
152b411b363SPhilipp Reisner 		if ((in & ((1 << b) -1)) == v) {	\
153b411b363SPhilipp Reisner 			*out = ((in & ((~0ULL) >> (64-t))) >> b) + adj;	\
154b411b363SPhilipp Reisner 			return t;			\
155b411b363SPhilipp Reisner 		}					\
156b411b363SPhilipp Reisner 		adj += 1ULL << (t - b);			\
157b411b363SPhilipp Reisner 	} while (0)
158b411b363SPhilipp Reisner 
159b411b363SPhilipp Reisner 	VLI_L_1_1();
160b411b363SPhilipp Reisner 
161b411b363SPhilipp Reisner 	/* NOT REACHED, if VLI_LEVELS code table is defined properly */
162b411b363SPhilipp Reisner 	BUG();
163b411b363SPhilipp Reisner #undef LEVEL
164b411b363SPhilipp Reisner }
165b411b363SPhilipp Reisner 
166b411b363SPhilipp Reisner /* return number of code bits needed,
167b411b363SPhilipp Reisner  * or negative error number */
168b411b363SPhilipp Reisner static inline int __vli_encode_bits(u64 *out, const u64 in)
169b411b363SPhilipp Reisner {
170b411b363SPhilipp Reisner 	u64 max = 0;
171b411b363SPhilipp Reisner 	u64 adj = 1;
172b411b363SPhilipp Reisner 
173b411b363SPhilipp Reisner 	if (in == 0)
174b411b363SPhilipp Reisner 		return -EINVAL;
175b411b363SPhilipp Reisner 
176b411b363SPhilipp Reisner #define LEVEL(t,b,v) do {		\
177b411b363SPhilipp Reisner 		max += 1ULL << (t - b);	\
178b411b363SPhilipp Reisner 		if (in <= max) {	\
179b411b363SPhilipp Reisner 			if (out)	\
180b411b363SPhilipp Reisner 				*out = ((in - adj) << b) | v;	\
181b411b363SPhilipp Reisner 			return t;	\
182b411b363SPhilipp Reisner 		}			\
183b411b363SPhilipp Reisner 		adj = max + 1;		\
184b411b363SPhilipp Reisner 	} while (0)
185b411b363SPhilipp Reisner 
186b411b363SPhilipp Reisner 	VLI_L_1_1();
187b411b363SPhilipp Reisner 
188b411b363SPhilipp Reisner 	return -EOVERFLOW;
189b411b363SPhilipp Reisner #undef LEVEL
190b411b363SPhilipp Reisner }
191b411b363SPhilipp Reisner 
192b411b363SPhilipp Reisner #undef VLI_L_1_1
193b411b363SPhilipp Reisner 
194b411b363SPhilipp Reisner /* code from here down is independend of actually used bit code */
195b411b363SPhilipp Reisner 
196b411b363SPhilipp Reisner /*
197b411b363SPhilipp Reisner  * Code length is determined by some unique (e.g. unary) prefix.
198b411b363SPhilipp Reisner  * This encodes arbitrary bit length, not whole bytes: we have a bit-stream,
199b411b363SPhilipp Reisner  * not a byte stream.
200b411b363SPhilipp Reisner  */
201b411b363SPhilipp Reisner 
202b411b363SPhilipp Reisner /* for the bitstream, we need a cursor */
203b411b363SPhilipp Reisner struct bitstream_cursor {
204b411b363SPhilipp Reisner 	/* the current byte */
205b411b363SPhilipp Reisner 	u8 *b;
206b411b363SPhilipp Reisner 	/* the current bit within *b, nomalized: 0..7 */
207b411b363SPhilipp Reisner 	unsigned int bit;
208b411b363SPhilipp Reisner };
209b411b363SPhilipp Reisner 
210b411b363SPhilipp Reisner /* initialize cursor to point to first bit of stream */
211b411b363SPhilipp Reisner static inline void bitstream_cursor_reset(struct bitstream_cursor *cur, void *s)
212b411b363SPhilipp Reisner {
213b411b363SPhilipp Reisner 	cur->b = s;
214b411b363SPhilipp Reisner 	cur->bit = 0;
215b411b363SPhilipp Reisner }
216b411b363SPhilipp Reisner 
217b411b363SPhilipp Reisner /* advance cursor by that many bits; maximum expected input value: 64,
218b411b363SPhilipp Reisner  * but depending on VLI implementation, it may be more. */
219b411b363SPhilipp Reisner static inline void bitstream_cursor_advance(struct bitstream_cursor *cur, unsigned int bits)
220b411b363SPhilipp Reisner {
221b411b363SPhilipp Reisner 	bits += cur->bit;
222b411b363SPhilipp Reisner 	cur->b = cur->b + (bits >> 3);
223b411b363SPhilipp Reisner 	cur->bit = bits & 7;
224b411b363SPhilipp Reisner }
225b411b363SPhilipp Reisner 
226b411b363SPhilipp Reisner /* the bitstream itself knows its length */
227b411b363SPhilipp Reisner struct bitstream {
228b411b363SPhilipp Reisner 	struct bitstream_cursor cur;
229b411b363SPhilipp Reisner 	unsigned char *buf;
230b411b363SPhilipp Reisner 	size_t buf_len;		/* in bytes */
231b411b363SPhilipp Reisner 
232b411b363SPhilipp Reisner 	/* for input stream:
233b411b363SPhilipp Reisner 	 * number of trailing 0 bits for padding
234b411b363SPhilipp Reisner 	 * total number of valid bits in stream: buf_len * 8 - pad_bits */
235b411b363SPhilipp Reisner 	unsigned int pad_bits;
236b411b363SPhilipp Reisner };
237b411b363SPhilipp Reisner 
238b411b363SPhilipp Reisner static inline void bitstream_init(struct bitstream *bs, void *s, size_t len, unsigned int pad_bits)
239b411b363SPhilipp Reisner {
240b411b363SPhilipp Reisner 	bs->buf = s;
241b411b363SPhilipp Reisner 	bs->buf_len = len;
242b411b363SPhilipp Reisner 	bs->pad_bits = pad_bits;
243b411b363SPhilipp Reisner 	bitstream_cursor_reset(&bs->cur, bs->buf);
244b411b363SPhilipp Reisner }
245b411b363SPhilipp Reisner 
246b411b363SPhilipp Reisner static inline void bitstream_rewind(struct bitstream *bs)
247b411b363SPhilipp Reisner {
248b411b363SPhilipp Reisner 	bitstream_cursor_reset(&bs->cur, bs->buf);
249b411b363SPhilipp Reisner 	memset(bs->buf, 0, bs->buf_len);
250b411b363SPhilipp Reisner }
251b411b363SPhilipp Reisner 
252b411b363SPhilipp Reisner /* Put (at most 64) least significant bits of val into bitstream, and advance cursor.
253b411b363SPhilipp Reisner  * Ignores "pad_bits".
254b411b363SPhilipp Reisner  * Returns zero if bits == 0 (nothing to do).
255b411b363SPhilipp Reisner  * Returns number of bits used if successful.
256b411b363SPhilipp Reisner  *
257b411b363SPhilipp Reisner  * If there is not enough room left in bitstream,
258b411b363SPhilipp Reisner  * leaves bitstream unchanged and returns -ENOBUFS.
259b411b363SPhilipp Reisner  */
260b411b363SPhilipp Reisner static inline int bitstream_put_bits(struct bitstream *bs, u64 val, const unsigned int bits)
261b411b363SPhilipp Reisner {
262b411b363SPhilipp Reisner 	unsigned char *b = bs->cur.b;
263b411b363SPhilipp Reisner 	unsigned int tmp;
264b411b363SPhilipp Reisner 
265b411b363SPhilipp Reisner 	if (bits == 0)
266b411b363SPhilipp Reisner 		return 0;
267b411b363SPhilipp Reisner 
268b411b363SPhilipp Reisner 	if ((bs->cur.b + ((bs->cur.bit + bits -1) >> 3)) - bs->buf >= bs->buf_len)
269b411b363SPhilipp Reisner 		return -ENOBUFS;
270b411b363SPhilipp Reisner 
271b411b363SPhilipp Reisner 	/* paranoia: strip off hi bits; they should not be set anyways. */
272b411b363SPhilipp Reisner 	if (bits < 64)
273b411b363SPhilipp Reisner 		val &= ~0ULL >> (64 - bits);
274b411b363SPhilipp Reisner 
275b411b363SPhilipp Reisner 	*b++ |= (val & 0xff) << bs->cur.bit;
276b411b363SPhilipp Reisner 
277b411b363SPhilipp Reisner 	for (tmp = 8 - bs->cur.bit; tmp < bits; tmp += 8)
278b411b363SPhilipp Reisner 		*b++ |= (val >> tmp) & 0xff;
279b411b363SPhilipp Reisner 
280b411b363SPhilipp Reisner 	bitstream_cursor_advance(&bs->cur, bits);
281b411b363SPhilipp Reisner 	return bits;
282b411b363SPhilipp Reisner }
283b411b363SPhilipp Reisner 
284b411b363SPhilipp Reisner /* Fetch (at most 64) bits from bitstream into *out, and advance cursor.
285b411b363SPhilipp Reisner  *
286b411b363SPhilipp Reisner  * If more than 64 bits are requested, returns -EINVAL and leave *out unchanged.
287b411b363SPhilipp Reisner  *
288b411b363SPhilipp Reisner  * If there are less than the requested number of valid bits left in the
289b411b363SPhilipp Reisner  * bitstream, still fetches all available bits.
290b411b363SPhilipp Reisner  *
291b411b363SPhilipp Reisner  * Returns number of actually fetched bits.
292b411b363SPhilipp Reisner  */
293b411b363SPhilipp Reisner static inline int bitstream_get_bits(struct bitstream *bs, u64 *out, int bits)
294b411b363SPhilipp Reisner {
295b411b363SPhilipp Reisner 	u64 val;
296b411b363SPhilipp Reisner 	unsigned int n;
297b411b363SPhilipp Reisner 
298b411b363SPhilipp Reisner 	if (bits > 64)
299b411b363SPhilipp Reisner 		return -EINVAL;
300b411b363SPhilipp Reisner 
301b411b363SPhilipp Reisner 	if (bs->cur.b + ((bs->cur.bit + bs->pad_bits + bits -1) >> 3) - bs->buf >= bs->buf_len)
302b411b363SPhilipp Reisner 		bits = ((bs->buf_len - (bs->cur.b - bs->buf)) << 3)
303b411b363SPhilipp Reisner 			- bs->cur.bit - bs->pad_bits;
304b411b363SPhilipp Reisner 
305b411b363SPhilipp Reisner 	if (bits == 0) {
306b411b363SPhilipp Reisner 		*out = 0;
307b411b363SPhilipp Reisner 		return 0;
308b411b363SPhilipp Reisner 	}
309b411b363SPhilipp Reisner 
310b411b363SPhilipp Reisner 	/* get the high bits */
311b411b363SPhilipp Reisner 	val = 0;
312b411b363SPhilipp Reisner 	n = (bs->cur.bit + bits + 7) >> 3;
313b411b363SPhilipp Reisner 	/* n may be at most 9, if cur.bit + bits > 64 */
314b411b363SPhilipp Reisner 	/* which means this copies at most 8 byte */
315b411b363SPhilipp Reisner 	if (n) {
316b411b363SPhilipp Reisner 		memcpy(&val, bs->cur.b+1, n - 1);
317b411b363SPhilipp Reisner 		val = le64_to_cpu(val) << (8 - bs->cur.bit);
318b411b363SPhilipp Reisner 	}
319b411b363SPhilipp Reisner 
320b411b363SPhilipp Reisner 	/* we still need the low bits */
321b411b363SPhilipp Reisner 	val |= bs->cur.b[0] >> bs->cur.bit;
322b411b363SPhilipp Reisner 
323b411b363SPhilipp Reisner 	/* and mask out bits we don't want */
324b411b363SPhilipp Reisner 	val &= ~0ULL >> (64 - bits);
325b411b363SPhilipp Reisner 
326b411b363SPhilipp Reisner 	bitstream_cursor_advance(&bs->cur, bits);
327b411b363SPhilipp Reisner 	*out = val;
328b411b363SPhilipp Reisner 
329b411b363SPhilipp Reisner 	return bits;
330b411b363SPhilipp Reisner }
331b411b363SPhilipp Reisner 
332b411b363SPhilipp Reisner /* encodes @in as vli into @bs;
333b411b363SPhilipp Reisner 
334b411b363SPhilipp Reisner  * return values
335b411b363SPhilipp Reisner  *  > 0: number of bits successfully stored in bitstream
336b411b363SPhilipp Reisner  * -ENOBUFS @bs is full
337b411b363SPhilipp Reisner  * -EINVAL input zero (invalid)
338b411b363SPhilipp Reisner  * -EOVERFLOW input too large for this vli code (invalid)
339b411b363SPhilipp Reisner  */
340b411b363SPhilipp Reisner static inline int vli_encode_bits(struct bitstream *bs, u64 in)
341b411b363SPhilipp Reisner {
342b411b363SPhilipp Reisner 	u64 code = code;
343b411b363SPhilipp Reisner 	int bits = __vli_encode_bits(&code, in);
344b411b363SPhilipp Reisner 
345b411b363SPhilipp Reisner 	if (bits <= 0)
346b411b363SPhilipp Reisner 		return bits;
347b411b363SPhilipp Reisner 
348b411b363SPhilipp Reisner 	return bitstream_put_bits(bs, code, bits);
349b411b363SPhilipp Reisner }
350b411b363SPhilipp Reisner 
351b411b363SPhilipp Reisner #endif
352