/src/duckdb/third_party/brotli/dec/bit_reader.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2013 Google Inc. All Rights Reserved. |
2 | | |
3 | | Distributed under MIT license. |
4 | | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
5 | | */ |
6 | | |
7 | | /* Bit reading helpers */ |
8 | | |
9 | | #ifndef BROTLI_DEC_BIT_READER_H_ |
10 | | #define BROTLI_DEC_BIT_READER_H_ |
11 | | |
12 | | #include <string.h> /* memcpy */ |
13 | | |
14 | | #include <brotli/types.h> |
15 | | |
16 | | #include "../common/brotli_constants.h" |
17 | | #include "../common/brotli_platform.h" |
18 | | |
19 | | namespace duckdb_brotli { |
20 | | |
21 | 0 | #define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1) |
22 | | |
23 | | /* 162 bits + 7 bytes */ |
24 | 0 | #define BROTLI_FAST_INPUT_SLACK 28 |
25 | | |
26 | | BROTLI_INTERNAL extern const brotli_reg_t kBrotliBitMask[33]; |
27 | | |
28 | 0 | static BROTLI_INLINE brotli_reg_t BitMask(brotli_reg_t n) { |
29 | 0 | if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) { |
30 | | /* Masking with this expression turns to a single |
31 | | "Unsigned Bit Field Extract" UBFX instruction on ARM. */ |
32 | 0 | return ~(~((brotli_reg_t)0) << n); |
33 | 0 | } else { |
34 | 0 | return kBrotliBitMask[n]; |
35 | 0 | } |
36 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BitMask(unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BitMask(unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BitMask(unsigned long) |
37 | | |
38 | | typedef struct { |
39 | | brotli_reg_t val_; /* pre-fetched bits */ |
40 | | brotli_reg_t bit_pos_; /* current bit-reading position in val_ */ |
41 | | const uint8_t* next_in; /* the byte we're reading from */ |
42 | | const uint8_t* guard_in; /* position from which "fast-path" is prohibited */ |
43 | | const uint8_t* last_in; /* == next_in + avail_in */ |
44 | | } BrotliBitReader; |
45 | | |
46 | | typedef struct { |
47 | | brotli_reg_t val_; |
48 | | brotli_reg_t bit_pos_; |
49 | | const uint8_t* next_in; |
50 | | size_t avail_in; |
51 | | } BrotliBitReaderState; |
52 | | |
53 | | /* Initializes the BrotliBitReader fields. */ |
54 | | BROTLI_INTERNAL void BrotliInitBitReader(BrotliBitReader* br); |
55 | | |
56 | | /* Ensures that accumulator is not empty. |
57 | | May consume up to sizeof(brotli_reg_t) - 1 bytes of input. |
58 | | Returns BROTLI_FALSE if data is required but there is no input available. |
59 | | For !BROTLI_UNALIGNED_READ_FAST this function also prepares bit reader for |
60 | | aligned reading. */ |
61 | | BROTLI_INTERNAL BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* br); |
62 | | |
63 | | /* Fallback for BrotliSafeReadBits32. Extracted as noninlined method to unburden |
64 | | the main code-path. Never called for RFC brotli streams, required only for |
65 | | "large-window" mode and other extensions. */ |
66 | | BROTLI_INTERNAL BROTLI_NOINLINE BROTLI_BOOL BrotliSafeReadBits32Slow( |
67 | | BrotliBitReader* br, brotli_reg_t n_bits, brotli_reg_t* val); |
68 | | |
69 | | static BROTLI_INLINE size_t |
70 | 0 | BrotliBitReaderGetAvailIn(BrotliBitReader* const br) { |
71 | 0 | return (size_t)(br->last_in - br->next_in); |
72 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderGetAvailIn(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderGetAvailIn(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderGetAvailIn(duckdb_brotli::BrotliBitReader*) |
73 | | |
74 | | static BROTLI_INLINE void BrotliBitReaderSaveState( |
75 | 0 | BrotliBitReader* const from, BrotliBitReaderState* to) { |
76 | 0 | to->val_ = from->val_; |
77 | 0 | to->bit_pos_ = from->bit_pos_; |
78 | 0 | to->next_in = from->next_in; |
79 | 0 | to->avail_in = BrotliBitReaderGetAvailIn(from); |
80 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderSaveState(duckdb_brotli::BrotliBitReader*, duckdb_brotli::BrotliBitReaderState*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderSaveState(duckdb_brotli::BrotliBitReader*, duckdb_brotli::BrotliBitReaderState*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderSaveState(duckdb_brotli::BrotliBitReader*, duckdb_brotli::BrotliBitReaderState*) |
81 | | |
82 | | static BROTLI_INLINE void BrotliBitReaderSetInput( |
83 | 0 | BrotliBitReader* const br, const uint8_t* next_in, size_t avail_in) { |
84 | 0 | br->next_in = next_in; |
85 | 0 | br->last_in = (avail_in == 0) ? next_in : (next_in + avail_in); |
86 | 0 | if (avail_in + 1 > BROTLI_FAST_INPUT_SLACK) { |
87 | 0 | br->guard_in = next_in + (avail_in + 1 - BROTLI_FAST_INPUT_SLACK); |
88 | 0 | } else { |
89 | 0 | br->guard_in = next_in; |
90 | 0 | } |
91 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderSetInput(duckdb_brotli::BrotliBitReader*, unsigned char const*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderSetInput(duckdb_brotli::BrotliBitReader*, unsigned char const*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderSetInput(duckdb_brotli::BrotliBitReader*, unsigned char const*, unsigned long) |
92 | | |
93 | | static BROTLI_INLINE void BrotliBitReaderRestoreState( |
94 | 0 | BrotliBitReader* const to, BrotliBitReaderState* from) { |
95 | 0 | to->val_ = from->val_; |
96 | 0 | to->bit_pos_ = from->bit_pos_; |
97 | 0 | to->next_in = from->next_in; |
98 | 0 | BrotliBitReaderSetInput(to, from->next_in, from->avail_in); |
99 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderRestoreState(duckdb_brotli::BrotliBitReader*, duckdb_brotli::BrotliBitReaderState*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderRestoreState(duckdb_brotli::BrotliBitReader*, duckdb_brotli::BrotliBitReaderState*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderRestoreState(duckdb_brotli::BrotliBitReader*, duckdb_brotli::BrotliBitReaderState*) |
100 | | |
101 | | static BROTLI_INLINE brotli_reg_t BrotliGetAvailableBits( |
102 | 0 | const BrotliBitReader* br) { |
103 | 0 | return br->bit_pos_; |
104 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliGetAvailableBits(duckdb_brotli::BrotliBitReader const*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliGetAvailableBits(duckdb_brotli::BrotliBitReader const*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliGetAvailableBits(duckdb_brotli::BrotliBitReader const*) |
105 | | |
106 | | /* Returns amount of unread bytes the bit reader still has buffered from the |
107 | | BrotliInput, including whole bytes in br->val_. Result is capped with |
108 | | maximal ring-buffer size (larger number won't be utilized anyway). */ |
109 | 0 | static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) { |
110 | 0 | static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS; |
111 | 0 | size_t avail_in = BrotliBitReaderGetAvailIn(br); |
112 | 0 | if (avail_in > kCap) return kCap; |
113 | 0 | return avail_in + (BrotliGetAvailableBits(br) >> 3); |
114 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliGetRemainingBytes(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliGetRemainingBytes(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliGetRemainingBytes(duckdb_brotli::BrotliBitReader*) |
115 | | |
116 | | /* Checks if there is at least |num| bytes left in the input ring-buffer |
117 | | (excluding the bits remaining in br->val_). */ |
118 | | static BROTLI_INLINE BROTLI_BOOL BrotliCheckInputAmount( |
119 | 0 | BrotliBitReader* const br) { |
120 | 0 | return TO_BROTLI_BOOL(br->next_in < br->guard_in); |
121 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliCheckInputAmount(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliCheckInputAmount(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliCheckInputAmount(duckdb_brotli::BrotliBitReader*) |
122 | | |
123 | | /* Load more bits into accumulator. */ |
124 | | static BROTLI_INLINE brotli_reg_t BrotliBitReaderLoadBits(brotli_reg_t val, |
125 | | brotli_reg_t new_bits, |
126 | | brotli_reg_t count, |
127 | 0 | brotli_reg_t offset) { |
128 | 0 | BROTLI_DCHECK( |
129 | 0 | !((val >> offset) & ~new_bits & ~(~((brotli_reg_t)0) << count))); |
130 | 0 | (void)count; |
131 | 0 | return val | (new_bits << offset); |
132 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderLoadBits(unsigned long, unsigned long, unsigned long, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderLoadBits(unsigned long, unsigned long, unsigned long, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderLoadBits(unsigned long, unsigned long, unsigned long, unsigned long) |
133 | | |
134 | | /* Guarantees that there are at least |n_bits| + 1 bits in accumulator. |
135 | | Precondition: accumulator contains at least 1 bit. |
136 | | |n_bits| should be in the range [1..24] for regular build. For portable |
137 | | non-64-bit little-endian build only 16 bits are safe to request. */ |
138 | | static BROTLI_INLINE void BrotliFillBitWindow( |
139 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits) { |
140 | 0 | #if (BROTLI_64_BITS) |
141 | 0 | if (BROTLI_UNALIGNED_READ_FAST && BROTLI_IS_CONSTANT(n_bits) && |
142 | 0 | (n_bits <= 8)) { |
143 | 0 | brotli_reg_t bit_pos = br->bit_pos_; |
144 | 0 | if (bit_pos <= 8) { |
145 | 0 | br->val_ = BrotliBitReaderLoadBits(br->val_, |
146 | 0 | BROTLI_UNALIGNED_LOAD64LE(br->next_in), 56, bit_pos); |
147 | 0 | br->bit_pos_ = bit_pos + 56; |
148 | 0 | br->next_in += 7; |
149 | 0 | } |
150 | 0 | } else if (BROTLI_UNALIGNED_READ_FAST && BROTLI_IS_CONSTANT(n_bits) && |
151 | 0 | (n_bits <= 16)) { |
152 | 0 | brotli_reg_t bit_pos = br->bit_pos_; |
153 | 0 | if (bit_pos <= 16) { |
154 | 0 | br->val_ = BrotliBitReaderLoadBits(br->val_, |
155 | 0 | BROTLI_UNALIGNED_LOAD64LE(br->next_in), 48, bit_pos); |
156 | 0 | br->bit_pos_ = bit_pos + 48; |
157 | 0 | br->next_in += 6; |
158 | 0 | } |
159 | 0 | } else { |
160 | 0 | brotli_reg_t bit_pos = br->bit_pos_; |
161 | 0 | if (bit_pos <= 32) { |
162 | 0 | br->val_ = BrotliBitReaderLoadBits(br->val_, |
163 | 0 | (uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in), 32, bit_pos); |
164 | 0 | br->bit_pos_ = bit_pos + 32; |
165 | 0 | br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ; |
166 | 0 | } |
167 | 0 | } |
168 | | #else |
169 | | if (BROTLI_UNALIGNED_READ_FAST && BROTLI_IS_CONSTANT(n_bits) && |
170 | | (n_bits <= 8)) { |
171 | | brotli_reg_t bit_pos = br->bit_pos_; |
172 | | if (bit_pos <= 8) { |
173 | | br->val_ = BrotliBitReaderLoadBits(br->val_, |
174 | | BROTLI_UNALIGNED_LOAD32LE(br->next_in), 24, bit_pos); |
175 | | br->bit_pos_ = bit_pos + 24; |
176 | | br->next_in += 3; |
177 | | } |
178 | | } else { |
179 | | brotli_reg_t bit_pos = br->bit_pos_; |
180 | | if (bit_pos <= 16) { |
181 | | br->val_ = BrotliBitReaderLoadBits(br->val_, |
182 | | (uint32_t)BROTLI_UNALIGNED_LOAD16LE(br->next_in), 16, bit_pos); |
183 | | br->bit_pos_ = bit_pos + 16; |
184 | | br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ; |
185 | | } |
186 | | } |
187 | | #endif |
188 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliFillBitWindow(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliFillBitWindow(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliFillBitWindow(duckdb_brotli::BrotliBitReader*, unsigned long) |
189 | | |
190 | | /* Mostly like BrotliFillBitWindow, but guarantees only 16 bits and reads no |
191 | | more than BROTLI_SHORT_FILL_BIT_WINDOW_READ bytes of input. */ |
192 | 0 | static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) { |
193 | 0 | BrotliFillBitWindow(br, 17); |
194 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliFillBitWindow16(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliFillBitWindow16(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliFillBitWindow16(duckdb_brotli::BrotliBitReader*) |
195 | | |
196 | | /* Tries to pull one byte of input to accumulator. |
197 | | Returns BROTLI_FALSE if there is no input available. */ |
198 | 0 | static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) { |
199 | 0 | if (br->next_in == br->last_in) { |
200 | 0 | return BROTLI_FALSE; |
201 | 0 | } |
202 | 0 | br->val_ = BrotliBitReaderLoadBits(br->val_, |
203 | 0 | (brotli_reg_t)*br->next_in, 8, br->bit_pos_); |
204 | 0 | br->bit_pos_ += 8; |
205 | 0 | ++br->next_in; |
206 | 0 | return BROTLI_TRUE; |
207 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliPullByte(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliPullByte(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliPullByte(duckdb_brotli::BrotliBitReader*) |
208 | | |
209 | | /* Returns currently available bits. |
210 | | The number of valid bits could be calculated by BrotliGetAvailableBits. */ |
211 | | static BROTLI_INLINE brotli_reg_t BrotliGetBitsUnmasked( |
212 | 0 | BrotliBitReader* const br) { |
213 | 0 | return br->val_; |
214 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliGetBitsUnmasked(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliGetBitsUnmasked(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliGetBitsUnmasked(duckdb_brotli::BrotliBitReader*) |
215 | | |
216 | | /* Like BrotliGetBits, but does not mask the result. |
217 | | The result contains at least 16 valid bits. */ |
218 | | static BROTLI_INLINE brotli_reg_t BrotliGet16BitsUnmasked( |
219 | 0 | BrotliBitReader* const br) { |
220 | 0 | BrotliFillBitWindow(br, 16); |
221 | 0 | return (brotli_reg_t)BrotliGetBitsUnmasked(br); |
222 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliGet16BitsUnmasked(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliGet16BitsUnmasked(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliGet16BitsUnmasked(duckdb_brotli::BrotliBitReader*) |
223 | | |
224 | | /* Returns the specified number of bits from |br| without advancing bit |
225 | | position. */ |
226 | | static BROTLI_INLINE brotli_reg_t BrotliGetBits( |
227 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits) { |
228 | 0 | BrotliFillBitWindow(br, n_bits); |
229 | 0 | return BrotliGetBitsUnmasked(br) & BitMask(n_bits); |
230 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliGetBits(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliGetBits(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliGetBits(duckdb_brotli::BrotliBitReader*, unsigned long) |
231 | | |
232 | | /* Tries to peek the specified amount of bits. Returns BROTLI_FALSE, if there |
233 | | is not enough input. */ |
234 | | static BROTLI_INLINE BROTLI_BOOL BrotliSafeGetBits( |
235 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits, brotli_reg_t* val) { |
236 | 0 | while (BrotliGetAvailableBits(br) < n_bits) { |
237 | 0 | if (!BrotliPullByte(br)) { |
238 | 0 | return BROTLI_FALSE; |
239 | 0 | } |
240 | 0 | } |
241 | 0 | *val = BrotliGetBitsUnmasked(br) & BitMask(n_bits); |
242 | 0 | return BROTLI_TRUE; |
243 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliSafeGetBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliSafeGetBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliSafeGetBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) |
244 | | |
245 | | /* Advances the bit pos by |n_bits|. */ |
246 | | static BROTLI_INLINE void BrotliDropBits( |
247 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits) { |
248 | 0 | br->bit_pos_ -= n_bits; |
249 | 0 | br->val_ >>= n_bits; |
250 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliDropBits(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliDropBits(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliDropBits(duckdb_brotli::BrotliBitReader*, unsigned long) |
251 | | |
252 | | /* Make sure that there are no spectre bits in accumulator. |
253 | | This is important for the cases when some bytes are skipped |
254 | | (i.e. never placed into accumulator). */ |
255 | 0 | static BROTLI_INLINE void BrotliBitReaderNormalize(BrotliBitReader* br) { |
256 | | /* Actually, it is enough to normalize when br->bit_pos_ == 0 */ |
257 | 0 | if (br->bit_pos_ < (sizeof(brotli_reg_t) << 3u)) { |
258 | 0 | br->val_ &= (((brotli_reg_t)1) << br->bit_pos_) - 1; |
259 | 0 | } |
260 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderNormalize(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderNormalize(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderNormalize(duckdb_brotli::BrotliBitReader*) |
261 | | |
262 | 0 | static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) { |
263 | 0 | brotli_reg_t unused_bytes = BrotliGetAvailableBits(br) >> 3; |
264 | 0 | brotli_reg_t unused_bits = unused_bytes << 3; |
265 | 0 | br->next_in = |
266 | 0 | (unused_bytes == 0) ? br->next_in : (br->next_in - unused_bytes); |
267 | 0 | br->bit_pos_ -= unused_bits; |
268 | 0 | BrotliBitReaderNormalize(br); |
269 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderUnload(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderUnload(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderUnload(duckdb_brotli::BrotliBitReader*) |
270 | | |
271 | | /* Reads the specified number of bits from |br| and advances the bit pos. |
272 | | Precondition: accumulator MUST contain at least |n_bits|. */ |
273 | | static BROTLI_INLINE void BrotliTakeBits(BrotliBitReader* const br, |
274 | | brotli_reg_t n_bits, |
275 | 0 | brotli_reg_t* val) { |
276 | 0 | *val = BrotliGetBitsUnmasked(br) & BitMask(n_bits); |
277 | 0 | BROTLI_LOG(("[BrotliTakeBits] %d %d %d val: %6x\n", |
278 | 0 | (int)BrotliBitReaderGetAvailIn(br), (int)br->bit_pos_, |
279 | 0 | (int)n_bits, (int)*val)); |
280 | 0 | BrotliDropBits(br, n_bits); |
281 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliTakeBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliTakeBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliTakeBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) |
282 | | |
283 | | /* Reads the specified number of bits from |br| and advances the bit pos. |
284 | | Assumes that there is enough input to perform BrotliFillBitWindow. |
285 | | Up to 24 bits are allowed to be requested from this method. */ |
286 | | static BROTLI_INLINE brotli_reg_t BrotliReadBits24( |
287 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits) { |
288 | 0 | BROTLI_DCHECK(n_bits <= 24); |
289 | 0 | if (BROTLI_64_BITS || (n_bits <= 16)) { |
290 | 0 | brotli_reg_t val; |
291 | 0 | BrotliFillBitWindow(br, n_bits); |
292 | 0 | BrotliTakeBits(br, n_bits, &val); |
293 | 0 | return val; |
294 | 0 | } else { |
295 | 0 | brotli_reg_t low_val; |
296 | 0 | brotli_reg_t high_val; |
297 | 0 | BrotliFillBitWindow(br, 16); |
298 | 0 | BrotliTakeBits(br, 16, &low_val); |
299 | 0 | BrotliFillBitWindow(br, 8); |
300 | 0 | BrotliTakeBits(br, n_bits - 16, &high_val); |
301 | 0 | return low_val | (high_val << 16); |
302 | 0 | } |
303 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliReadBits24(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliReadBits24(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliReadBits24(duckdb_brotli::BrotliBitReader*, unsigned long) |
304 | | |
305 | | /* Same as BrotliReadBits24, but allows reading up to 32 bits. */ |
306 | | static BROTLI_INLINE brotli_reg_t BrotliReadBits32( |
307 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits) { |
308 | 0 | BROTLI_DCHECK(n_bits <= 32); |
309 | 0 | if (BROTLI_64_BITS || (n_bits <= 16)) { |
310 | 0 | brotli_reg_t val; |
311 | 0 | BrotliFillBitWindow(br, n_bits); |
312 | 0 | BrotliTakeBits(br, n_bits, &val); |
313 | 0 | return val; |
314 | 0 | } else { |
315 | 0 | brotli_reg_t low_val; |
316 | 0 | brotli_reg_t high_val; |
317 | 0 | BrotliFillBitWindow(br, 16); |
318 | 0 | BrotliTakeBits(br, 16, &low_val); |
319 | 0 | BrotliFillBitWindow(br, 16); |
320 | 0 | BrotliTakeBits(br, n_bits - 16, &high_val); |
321 | 0 | return low_val | (high_val << 16); |
322 | 0 | } |
323 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliReadBits32(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliReadBits32(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliReadBits32(duckdb_brotli::BrotliBitReader*, unsigned long) |
324 | | |
325 | | /* Tries to read the specified amount of bits. Returns BROTLI_FALSE, if there |
326 | | is not enough input. |n_bits| MUST be positive. |
327 | | Up to 24 bits are allowed to be requested from this method. */ |
328 | | static BROTLI_INLINE BROTLI_BOOL BrotliSafeReadBits( |
329 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits, brotli_reg_t* val) { |
330 | 0 | BROTLI_DCHECK(n_bits <= 24); |
331 | 0 | while (BrotliGetAvailableBits(br) < n_bits) { |
332 | 0 | if (!BrotliPullByte(br)) { |
333 | 0 | return BROTLI_FALSE; |
334 | 0 | } |
335 | 0 | } |
336 | 0 | BrotliTakeBits(br, n_bits, val); |
337 | 0 | return BROTLI_TRUE; |
338 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliSafeReadBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliSafeReadBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliSafeReadBits(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) |
339 | | |
340 | | /* Same as BrotliSafeReadBits, but allows reading up to 32 bits. */ |
341 | | static BROTLI_INLINE BROTLI_BOOL BrotliSafeReadBits32( |
342 | 0 | BrotliBitReader* const br, brotli_reg_t n_bits, brotli_reg_t* val) { |
343 | 0 | BROTLI_DCHECK(n_bits <= 32); |
344 | 0 | if (BROTLI_64_BITS || (n_bits <= 24)) { |
345 | 0 | while (BrotliGetAvailableBits(br) < n_bits) { |
346 | 0 | if (!BrotliPullByte(br)) { |
347 | 0 | return BROTLI_FALSE; |
348 | 0 | } |
349 | 0 | } |
350 | 0 | BrotliTakeBits(br, n_bits, val); |
351 | 0 | return BROTLI_TRUE; |
352 | 0 | } else { |
353 | 0 | return BrotliSafeReadBits32Slow(br, n_bits, val); |
354 | 0 | } |
355 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliSafeReadBits32(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliSafeReadBits32(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliSafeReadBits32(duckdb_brotli::BrotliBitReader*, unsigned long, unsigned long*) |
356 | | |
357 | | /* Advances the bit reader position to the next byte boundary and verifies |
358 | | that any skipped bits are set to zero. */ |
359 | 0 | static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) { |
360 | 0 | brotli_reg_t pad_bits_count = BrotliGetAvailableBits(br) & 0x7; |
361 | 0 | brotli_reg_t pad_bits = 0; |
362 | 0 | if (pad_bits_count != 0) { |
363 | 0 | BrotliTakeBits(br, pad_bits_count, &pad_bits); |
364 | 0 | } |
365 | 0 | BrotliBitReaderNormalize(br); |
366 | 0 | return TO_BROTLI_BOOL(pad_bits == 0); |
367 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliJumpToByteBoundary(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliJumpToByteBoundary(duckdb_brotli::BrotliBitReader*) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliJumpToByteBoundary(duckdb_brotli::BrotliBitReader*) |
368 | | |
369 | 0 | static BROTLI_INLINE void BrotliDropBytes(BrotliBitReader* br, size_t num) { |
370 | | /* Check detour is legal: accumulator must to be empty. */ |
371 | 0 | BROTLI_DCHECK(br->bit_pos_ == 0); |
372 | 0 | BROTLI_DCHECK(br->val_ == 0); |
373 | 0 | br->next_in += num; |
374 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliDropBytes(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliDropBytes(duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliDropBytes(duckdb_brotli::BrotliBitReader*, unsigned long) |
375 | | |
376 | | /* Copies remaining input bytes stored in the bit reader to the output. Value |
377 | | |num| may not be larger than BrotliGetRemainingBytes. The bit reader must be |
378 | | warmed up again after this. */ |
379 | | static BROTLI_INLINE void BrotliCopyBytes(uint8_t* dest, |
380 | 0 | BrotliBitReader* br, size_t num) { |
381 | 0 | while (BrotliGetAvailableBits(br) >= 8 && num > 0) { |
382 | 0 | *dest = (uint8_t)BrotliGetBitsUnmasked(br); |
383 | 0 | BrotliDropBits(br, 8); |
384 | 0 | ++dest; |
385 | 0 | --num; |
386 | 0 | } |
387 | 0 | BrotliBitReaderNormalize(br); |
388 | 0 | if (num > 0) { |
389 | 0 | memcpy(dest, br->next_in, num); |
390 | 0 | BrotliDropBytes(br, num); |
391 | 0 | } |
392 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliCopyBytes(unsigned char*, duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliCopyBytes(unsigned char*, duckdb_brotli::BrotliBitReader*, unsigned long) Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliCopyBytes(unsigned char*, duckdb_brotli::BrotliBitReader*, unsigned long) |
393 | | |
394 | 0 | BROTLI_UNUSED_FUNCTION void BrotliBitReaderSuppressUnusedFunctions(void) { |
395 | 0 | BROTLI_UNUSED(&BrotliBitReaderSuppressUnusedFunctions); |
396 | 0 |
|
397 | 0 | BROTLI_UNUSED(&BrotliBitReaderGetAvailIn); |
398 | 0 | BROTLI_UNUSED(&BrotliBitReaderLoadBits); |
399 | 0 | BROTLI_UNUSED(&BrotliBitReaderRestoreState); |
400 | 0 | BROTLI_UNUSED(&BrotliBitReaderSaveState); |
401 | 0 | BROTLI_UNUSED(&BrotliBitReaderSetInput); |
402 | 0 | BROTLI_UNUSED(&BrotliBitReaderUnload); |
403 | 0 | BROTLI_UNUSED(&BrotliCheckInputAmount); |
404 | 0 | BROTLI_UNUSED(&BrotliCopyBytes); |
405 | 0 | BROTLI_UNUSED(&BrotliFillBitWindow16); |
406 | 0 | BROTLI_UNUSED(&BrotliGet16BitsUnmasked); |
407 | 0 | BROTLI_UNUSED(&BrotliGetBits); |
408 | 0 | BROTLI_UNUSED(&BrotliGetRemainingBytes); |
409 | 0 | BROTLI_UNUSED(&BrotliJumpToByteBoundary); |
410 | 0 | BROTLI_UNUSED(&BrotliReadBits24); |
411 | 0 | BROTLI_UNUSED(&BrotliReadBits32); |
412 | 0 | BROTLI_UNUSED(&BrotliSafeGetBits); |
413 | 0 | BROTLI_UNUSED(&BrotliSafeReadBits); |
414 | 0 | BROTLI_UNUSED(&BrotliSafeReadBits32); |
415 | 0 | } Unexecuted instantiation: decode.cpp:duckdb_brotli::BrotliBitReaderSuppressUnusedFunctions() Unexecuted instantiation: bit_reader.cpp:duckdb_brotli::BrotliBitReaderSuppressUnusedFunctions() Unexecuted instantiation: state.cpp:duckdb_brotli::BrotliBitReaderSuppressUnusedFunctions() |
416 | | |
417 | | } |
418 | | |
419 | | #endif /* BROTLI_DEC_BIT_READER_H_ */ |