/src/zstd/lib/common/bitstream.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* ****************************************************************** |
2 | | * bitstream |
3 | | * Part of FSE library |
4 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
5 | | * |
6 | | * You can contact the author at : |
7 | | * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy |
8 | | * |
9 | | * This source code is licensed under both the BSD-style license (found in the |
10 | | * LICENSE file in the root directory of this source tree) and the GPLv2 (found |
11 | | * in the COPYING file in the root directory of this source tree). |
12 | | * You may select, at your option, one of the above-listed licenses. |
13 | | ****************************************************************** */ |
14 | | #ifndef BITSTREAM_H_MODULE |
15 | | #define BITSTREAM_H_MODULE |
16 | | |
17 | | #if defined (__cplusplus) |
18 | | extern "C" { |
19 | | #endif |
20 | | /* |
21 | | * This API consists of small unitary functions, which must be inlined for best performance. |
22 | | * Since link-time-optimization is not available for all compilers, |
23 | | * these functions are defined into a .h to be included. |
24 | | */ |
25 | | |
26 | | /*-**************************************** |
27 | | * Dependencies |
28 | | ******************************************/ |
29 | | #include "mem.h" /* unaligned access routines */ |
30 | | #include "compiler.h" /* UNLIKELY() */ |
31 | | #include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */ |
32 | | #include "error_private.h" /* error codes and messages */ |
33 | | #include "bits.h" /* ZSTD_highbit32 */ |
34 | | |
35 | | |
36 | | /*========================================= |
37 | | * Target specific |
38 | | =========================================*/ |
39 | | #ifndef ZSTD_NO_INTRINSICS |
40 | | # if (defined(__BMI__) || defined(__BMI2__)) && defined(__GNUC__) |
41 | | # include <immintrin.h> /* support for bextr (experimental)/bzhi */ |
42 | | # elif defined(__ICCARM__) |
43 | | # include <intrinsics.h> |
44 | | # endif |
45 | | #endif |
46 | | |
47 | 0 | #define STREAM_ACCUMULATOR_MIN_32 25 |
48 | 0 | #define STREAM_ACCUMULATOR_MIN_64 57 |
49 | 0 | #define STREAM_ACCUMULATOR_MIN ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64)) |
50 | | |
51 | | |
52 | | /*-****************************************** |
53 | | * bitStream encoding API (write forward) |
54 | | ********************************************/ |
55 | | /* bitStream can mix input from multiple sources. |
56 | | * A critical property of these streams is that they encode and decode in **reverse** direction. |
57 | | * So the first bit sequence you add will be the last to be read, like a LIFO stack. |
58 | | */ |
59 | | typedef struct { |
60 | | size_t bitContainer; |
61 | | unsigned bitPos; |
62 | | char* startPtr; |
63 | | char* ptr; |
64 | | char* endPtr; |
65 | | } BIT_CStream_t; |
66 | | |
67 | | MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* dstBuffer, size_t dstCapacity); |
68 | | MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits); |
69 | | MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC); |
70 | | MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC); |
71 | | |
72 | | /* Start with initCStream, providing the size of buffer to write into. |
73 | | * bitStream will never write outside of this buffer. |
74 | | * `dstCapacity` must be >= sizeof(bitD->bitContainer), otherwise @return will be an error code. |
75 | | * |
76 | | * bits are first added to a local register. |
77 | | * Local register is size_t, hence 64-bits on 64-bits systems, or 32-bits on 32-bits systems. |
78 | | * Writing data into memory is an explicit operation, performed by the flushBits function. |
79 | | * Hence keep track how many bits are potentially stored into local register to avoid register overflow. |
80 | | * After a flushBits, a maximum of 7 bits might still be stored into local register. |
81 | | * |
82 | | * Avoid storing elements of more than 24 bits if you want compatibility with 32-bits bitstream readers. |
83 | | * |
84 | | * Last operation is to close the bitStream. |
85 | | * The function returns the final size of CStream in bytes. |
86 | | * If data couldn't fit into `dstBuffer`, it will return a 0 ( == not storable) |
87 | | */ |
88 | | |
89 | | |
90 | | /*-******************************************** |
91 | | * bitStream decoding API (read backward) |
92 | | **********************************************/ |
93 | | typedef size_t BitContainerType; |
94 | | typedef struct { |
95 | | BitContainerType bitContainer; |
96 | | unsigned bitsConsumed; |
97 | | const char* ptr; |
98 | | const char* start; |
99 | | const char* limitPtr; |
100 | | } BIT_DStream_t; |
101 | | |
102 | | typedef enum { BIT_DStream_unfinished = 0, /* fully refilled */ |
103 | | BIT_DStream_endOfBuffer = 1, /* still some bits left in bitstream */ |
104 | | BIT_DStream_completed = 2, /* bitstream entirely consumed, bit-exact */ |
105 | | BIT_DStream_overflow = 3 /* user requested more bits than present in bitstream */ |
106 | | } BIT_DStream_status; /* result of BIT_reloadDStream() */ |
107 | | |
108 | | MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize); |
109 | | MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits); |
110 | | MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD); |
111 | | MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD); |
112 | | |
113 | | |
114 | | /* Start by invoking BIT_initDStream(). |
115 | | * A chunk of the bitStream is then stored into a local register. |
116 | | * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (BitContainerType). |
117 | | * You can then retrieve bitFields stored into the local register, **in reverse order**. |
118 | | * Local register is explicitly reloaded from memory by the BIT_reloadDStream() method. |
119 | | * A reload guarantee a minimum of ((8*sizeof(bitD->bitContainer))-7) bits when its result is BIT_DStream_unfinished. |
120 | | * Otherwise, it can be less than that, so proceed accordingly. |
121 | | * Checking if DStream has reached its end can be performed with BIT_endOfDStream(). |
122 | | */ |
123 | | |
124 | | |
125 | | /*-**************************************** |
126 | | * unsafe API |
127 | | ******************************************/ |
128 | | MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, size_t value, unsigned nbBits); |
129 | | /* faster, but works only if value is "clean", meaning all high bits above nbBits are 0 */ |
130 | | |
131 | | MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC); |
132 | | /* unsafe version; does not check buffer overflow */ |
133 | | |
134 | | MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits); |
135 | | /* faster, but works only if nbBits >= 1 */ |
136 | | |
137 | | /*===== Local Constants =====*/ |
138 | | static const unsigned BIT_mask[] = { |
139 | | 0, 1, 3, 7, 0xF, 0x1F, |
140 | | 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, |
141 | | 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, |
142 | | 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, |
143 | | 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF, |
144 | | 0x3FFFFFFF, 0x7FFFFFFF}; /* up to 31 bits */ |
145 | | #define BIT_MASK_SIZE (sizeof(BIT_mask) / sizeof(BIT_mask[0])) |
146 | | |
147 | | /*-************************************************************** |
148 | | * bitStream encoding |
149 | | ****************************************************************/ |
150 | | /*! BIT_initCStream() : |
151 | | * `dstCapacity` must be > sizeof(size_t) |
152 | | * @return : 0 if success, |
153 | | * otherwise an error code (can be tested using ERR_isError()) */ |
154 | | MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, |
155 | | void* startPtr, size_t dstCapacity) |
156 | 0 | { |
157 | 0 | bitC->bitContainer = 0; |
158 | 0 | bitC->bitPos = 0; |
159 | 0 | bitC->startPtr = (char*)startPtr; |
160 | 0 | bitC->ptr = bitC->startPtr; |
161 | 0 | bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer); |
162 | 0 | if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall); |
163 | 0 | return 0; |
164 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_initCStream Unexecuted instantiation: entropy_common.c:BIT_initCStream Unexecuted instantiation: fse_decompress.c:BIT_initCStream Unexecuted instantiation: zstd_common.c:BIT_initCStream Unexecuted instantiation: fse_compress.c:BIT_initCStream Unexecuted instantiation: huf_compress.c:BIT_initCStream Unexecuted instantiation: zstd_compress.c:BIT_initCStream Unexecuted instantiation: zstd_compress_literals.c:BIT_initCStream Unexecuted instantiation: zstd_compress_sequences.c:BIT_initCStream Unexecuted instantiation: zstd_compress_superblock.c:BIT_initCStream Unexecuted instantiation: zstd_double_fast.c:BIT_initCStream Unexecuted instantiation: zstd_fast.c:BIT_initCStream Unexecuted instantiation: zstd_lazy.c:BIT_initCStream Unexecuted instantiation: zstd_ldm.c:BIT_initCStream Unexecuted instantiation: zstd_opt.c:BIT_initCStream Unexecuted instantiation: zstdmt_compress.c:BIT_initCStream Unexecuted instantiation: huf_decompress.c:BIT_initCStream Unexecuted instantiation: zstd_ddict.c:BIT_initCStream Unexecuted instantiation: zstd_decompress.c:BIT_initCStream Unexecuted instantiation: zstd_decompress_block.c:BIT_initCStream Unexecuted instantiation: cover.c:BIT_initCStream Unexecuted instantiation: fastcover.c:BIT_initCStream Unexecuted instantiation: zdict.c:BIT_initCStream |
165 | | |
166 | | FORCE_INLINE_TEMPLATE size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits) |
167 | 0 | { |
168 | | #if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS) |
169 | | return _bzhi_u64(bitContainer, nbBits); |
170 | | #else |
171 | 0 | assert(nbBits < BIT_MASK_SIZE); |
172 | 0 | return bitContainer & BIT_mask[nbBits]; |
173 | 0 | #endif |
174 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_getLowerBits Unexecuted instantiation: entropy_common.c:BIT_getLowerBits Unexecuted instantiation: fse_decompress.c:BIT_getLowerBits Unexecuted instantiation: zstd_common.c:BIT_getLowerBits Unexecuted instantiation: fse_compress.c:BIT_getLowerBits Unexecuted instantiation: huf_compress.c:BIT_getLowerBits Unexecuted instantiation: zstd_compress.c:BIT_getLowerBits Unexecuted instantiation: zstd_compress_literals.c:BIT_getLowerBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_getLowerBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_getLowerBits Unexecuted instantiation: zstd_double_fast.c:BIT_getLowerBits Unexecuted instantiation: zstd_fast.c:BIT_getLowerBits Unexecuted instantiation: zstd_lazy.c:BIT_getLowerBits Unexecuted instantiation: zstd_ldm.c:BIT_getLowerBits Unexecuted instantiation: zstd_opt.c:BIT_getLowerBits Unexecuted instantiation: zstdmt_compress.c:BIT_getLowerBits Unexecuted instantiation: huf_decompress.c:BIT_getLowerBits Unexecuted instantiation: zstd_ddict.c:BIT_getLowerBits Unexecuted instantiation: zstd_decompress.c:BIT_getLowerBits Unexecuted instantiation: zstd_decompress_block.c:BIT_getLowerBits Unexecuted instantiation: cover.c:BIT_getLowerBits Unexecuted instantiation: fastcover.c:BIT_getLowerBits Unexecuted instantiation: zdict.c:BIT_getLowerBits |
175 | | |
176 | | /*! BIT_addBits() : |
177 | | * can add up to 31 bits into `bitC`. |
178 | | * Note : does not check for register overflow ! */ |
179 | | MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, |
180 | | size_t value, unsigned nbBits) |
181 | 0 | { |
182 | 0 | DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32); |
183 | 0 | assert(nbBits < BIT_MASK_SIZE); |
184 | 0 | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
185 | 0 | bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos; |
186 | 0 | bitC->bitPos += nbBits; |
187 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_addBits Unexecuted instantiation: entropy_common.c:BIT_addBits Unexecuted instantiation: fse_decompress.c:BIT_addBits Unexecuted instantiation: zstd_common.c:BIT_addBits Unexecuted instantiation: fse_compress.c:BIT_addBits Unexecuted instantiation: huf_compress.c:BIT_addBits Unexecuted instantiation: zstd_compress.c:BIT_addBits Unexecuted instantiation: zstd_compress_literals.c:BIT_addBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_addBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_addBits Unexecuted instantiation: zstd_double_fast.c:BIT_addBits Unexecuted instantiation: zstd_fast.c:BIT_addBits Unexecuted instantiation: zstd_lazy.c:BIT_addBits Unexecuted instantiation: zstd_ldm.c:BIT_addBits Unexecuted instantiation: zstd_opt.c:BIT_addBits Unexecuted instantiation: zstdmt_compress.c:BIT_addBits Unexecuted instantiation: huf_decompress.c:BIT_addBits Unexecuted instantiation: zstd_ddict.c:BIT_addBits Unexecuted instantiation: zstd_decompress.c:BIT_addBits Unexecuted instantiation: zstd_decompress_block.c:BIT_addBits Unexecuted instantiation: cover.c:BIT_addBits Unexecuted instantiation: fastcover.c:BIT_addBits Unexecuted instantiation: zdict.c:BIT_addBits |
188 | | |
189 | | /*! BIT_addBitsFast() : |
190 | | * works only if `value` is _clean_, |
191 | | * meaning all high bits above nbBits are 0 */ |
192 | | MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, |
193 | | size_t value, unsigned nbBits) |
194 | 0 | { |
195 | 0 | assert((value>>nbBits) == 0); |
196 | 0 | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
197 | 0 | bitC->bitContainer |= value << bitC->bitPos; |
198 | 0 | bitC->bitPos += nbBits; |
199 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_addBitsFast Unexecuted instantiation: entropy_common.c:BIT_addBitsFast Unexecuted instantiation: fse_decompress.c:BIT_addBitsFast Unexecuted instantiation: zstd_common.c:BIT_addBitsFast Unexecuted instantiation: fse_compress.c:BIT_addBitsFast Unexecuted instantiation: huf_compress.c:BIT_addBitsFast Unexecuted instantiation: zstd_compress.c:BIT_addBitsFast Unexecuted instantiation: zstd_compress_literals.c:BIT_addBitsFast Unexecuted instantiation: zstd_compress_sequences.c:BIT_addBitsFast Unexecuted instantiation: zstd_compress_superblock.c:BIT_addBitsFast Unexecuted instantiation: zstd_double_fast.c:BIT_addBitsFast Unexecuted instantiation: zstd_fast.c:BIT_addBitsFast Unexecuted instantiation: zstd_lazy.c:BIT_addBitsFast Unexecuted instantiation: zstd_ldm.c:BIT_addBitsFast Unexecuted instantiation: zstd_opt.c:BIT_addBitsFast Unexecuted instantiation: zstdmt_compress.c:BIT_addBitsFast Unexecuted instantiation: huf_decompress.c:BIT_addBitsFast Unexecuted instantiation: zstd_ddict.c:BIT_addBitsFast Unexecuted instantiation: zstd_decompress.c:BIT_addBitsFast Unexecuted instantiation: zstd_decompress_block.c:BIT_addBitsFast Unexecuted instantiation: cover.c:BIT_addBitsFast Unexecuted instantiation: fastcover.c:BIT_addBitsFast Unexecuted instantiation: zdict.c:BIT_addBitsFast |
200 | | |
201 | | /*! BIT_flushBitsFast() : |
202 | | * assumption : bitContainer has not overflowed |
203 | | * unsafe version; does not check buffer overflow */ |
204 | | MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC) |
205 | 0 | { |
206 | 0 | size_t const nbBytes = bitC->bitPos >> 3; |
207 | 0 | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
208 | 0 | assert(bitC->ptr <= bitC->endPtr); |
209 | 0 | MEM_writeLEST(bitC->ptr, bitC->bitContainer); |
210 | 0 | bitC->ptr += nbBytes; |
211 | 0 | bitC->bitPos &= 7; |
212 | 0 | bitC->bitContainer >>= nbBytes*8; |
213 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_flushBitsFast Unexecuted instantiation: entropy_common.c:BIT_flushBitsFast Unexecuted instantiation: fse_decompress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_common.c:BIT_flushBitsFast Unexecuted instantiation: fse_compress.c:BIT_flushBitsFast Unexecuted instantiation: huf_compress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_compress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_compress_literals.c:BIT_flushBitsFast Unexecuted instantiation: zstd_compress_sequences.c:BIT_flushBitsFast Unexecuted instantiation: zstd_compress_superblock.c:BIT_flushBitsFast Unexecuted instantiation: zstd_double_fast.c:BIT_flushBitsFast Unexecuted instantiation: zstd_fast.c:BIT_flushBitsFast Unexecuted instantiation: zstd_lazy.c:BIT_flushBitsFast Unexecuted instantiation: zstd_ldm.c:BIT_flushBitsFast Unexecuted instantiation: zstd_opt.c:BIT_flushBitsFast Unexecuted instantiation: zstdmt_compress.c:BIT_flushBitsFast Unexecuted instantiation: huf_decompress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_ddict.c:BIT_flushBitsFast Unexecuted instantiation: zstd_decompress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_decompress_block.c:BIT_flushBitsFast Unexecuted instantiation: cover.c:BIT_flushBitsFast Unexecuted instantiation: fastcover.c:BIT_flushBitsFast Unexecuted instantiation: zdict.c:BIT_flushBitsFast |
214 | | |
215 | | /*! BIT_flushBits() : |
216 | | * assumption : bitContainer has not overflowed |
217 | | * safe version; check for buffer overflow, and prevents it. |
218 | | * note : does not signal buffer overflow. |
219 | | * overflow will be revealed later on using BIT_closeCStream() */ |
220 | | MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC) |
221 | 0 | { |
222 | 0 | size_t const nbBytes = bitC->bitPos >> 3; |
223 | 0 | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
224 | 0 | assert(bitC->ptr <= bitC->endPtr); |
225 | 0 | MEM_writeLEST(bitC->ptr, bitC->bitContainer); |
226 | 0 | bitC->ptr += nbBytes; |
227 | 0 | if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr; |
228 | 0 | bitC->bitPos &= 7; |
229 | 0 | bitC->bitContainer >>= nbBytes*8; |
230 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_flushBits Unexecuted instantiation: entropy_common.c:BIT_flushBits Unexecuted instantiation: fse_decompress.c:BIT_flushBits Unexecuted instantiation: zstd_common.c:BIT_flushBits Unexecuted instantiation: fse_compress.c:BIT_flushBits Unexecuted instantiation: huf_compress.c:BIT_flushBits Unexecuted instantiation: zstd_compress.c:BIT_flushBits Unexecuted instantiation: zstd_compress_literals.c:BIT_flushBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_flushBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_flushBits Unexecuted instantiation: zstd_double_fast.c:BIT_flushBits Unexecuted instantiation: zstd_fast.c:BIT_flushBits Unexecuted instantiation: zstd_lazy.c:BIT_flushBits Unexecuted instantiation: zstd_ldm.c:BIT_flushBits Unexecuted instantiation: zstd_opt.c:BIT_flushBits Unexecuted instantiation: zstdmt_compress.c:BIT_flushBits Unexecuted instantiation: huf_decompress.c:BIT_flushBits Unexecuted instantiation: zstd_ddict.c:BIT_flushBits Unexecuted instantiation: zstd_decompress.c:BIT_flushBits Unexecuted instantiation: zstd_decompress_block.c:BIT_flushBits Unexecuted instantiation: cover.c:BIT_flushBits Unexecuted instantiation: fastcover.c:BIT_flushBits Unexecuted instantiation: zdict.c:BIT_flushBits |
231 | | |
232 | | /*! BIT_closeCStream() : |
233 | | * @return : size of CStream, in bytes, |
234 | | * or 0 if it could not fit into dstBuffer */ |
235 | | MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC) |
236 | 0 | { |
237 | 0 | BIT_addBitsFast(bitC, 1, 1); /* endMark */ |
238 | 0 | BIT_flushBits(bitC); |
239 | 0 | if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */ |
240 | 0 | return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0); |
241 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_closeCStream Unexecuted instantiation: entropy_common.c:BIT_closeCStream Unexecuted instantiation: fse_decompress.c:BIT_closeCStream Unexecuted instantiation: zstd_common.c:BIT_closeCStream Unexecuted instantiation: fse_compress.c:BIT_closeCStream Unexecuted instantiation: huf_compress.c:BIT_closeCStream Unexecuted instantiation: zstd_compress.c:BIT_closeCStream Unexecuted instantiation: zstd_compress_literals.c:BIT_closeCStream Unexecuted instantiation: zstd_compress_sequences.c:BIT_closeCStream Unexecuted instantiation: zstd_compress_superblock.c:BIT_closeCStream Unexecuted instantiation: zstd_double_fast.c:BIT_closeCStream Unexecuted instantiation: zstd_fast.c:BIT_closeCStream Unexecuted instantiation: zstd_lazy.c:BIT_closeCStream Unexecuted instantiation: zstd_ldm.c:BIT_closeCStream Unexecuted instantiation: zstd_opt.c:BIT_closeCStream Unexecuted instantiation: zstdmt_compress.c:BIT_closeCStream Unexecuted instantiation: huf_decompress.c:BIT_closeCStream Unexecuted instantiation: zstd_ddict.c:BIT_closeCStream Unexecuted instantiation: zstd_decompress.c:BIT_closeCStream Unexecuted instantiation: zstd_decompress_block.c:BIT_closeCStream Unexecuted instantiation: cover.c:BIT_closeCStream Unexecuted instantiation: fastcover.c:BIT_closeCStream Unexecuted instantiation: zdict.c:BIT_closeCStream |
242 | | |
243 | | |
244 | | /*-******************************************************** |
245 | | * bitStream decoding |
246 | | **********************************************************/ |
247 | | /*! BIT_initDStream() : |
248 | | * Initialize a BIT_DStream_t. |
249 | | * `bitD` : a pointer to an already allocated BIT_DStream_t structure. |
250 | | * `srcSize` must be the *exact* size of the bitStream, in bytes. |
251 | | * @return : size of stream (== srcSize), or an errorCode if a problem is detected |
252 | | */ |
253 | | MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize) |
254 | 4.36k | { |
255 | 4.36k | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } |
256 | | |
257 | 4.17k | bitD->start = (const char*)srcBuffer; |
258 | 4.17k | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); |
259 | | |
260 | 4.17k | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ |
261 | 1.56k | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); |
262 | 1.56k | bitD->bitContainer = MEM_readLEST(bitD->ptr); |
263 | 1.56k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; |
264 | 1.56k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ |
265 | 1.56k | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } |
266 | 2.60k | } else { |
267 | 2.60k | bitD->ptr = bitD->start; |
268 | 2.60k | bitD->bitContainer = *(const BYTE*)(bitD->start); |
269 | 2.60k | switch(srcSize) |
270 | 2.60k | { |
271 | 89 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); |
272 | 89 | ZSTD_FALLTHROUGH; |
273 | | |
274 | 166 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); |
275 | 166 | ZSTD_FALLTHROUGH; |
276 | | |
277 | 321 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); |
278 | 321 | ZSTD_FALLTHROUGH; |
279 | | |
280 | 599 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; |
281 | 599 | ZSTD_FALLTHROUGH; |
282 | | |
283 | 815 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; |
284 | 815 | ZSTD_FALLTHROUGH; |
285 | | |
286 | 1.14k | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; |
287 | 1.14k | ZSTD_FALLTHROUGH; |
288 | | |
289 | 2.60k | default: break; |
290 | 2.60k | } |
291 | 2.60k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; |
292 | 2.60k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; |
293 | 2.60k | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ |
294 | 2.60k | } |
295 | 2.58k | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; |
296 | 2.58k | } |
297 | | |
298 | 4.09k | return srcSize; |
299 | 4.17k | } Unexecuted instantiation: sequence_producer.c:BIT_initDStream Unexecuted instantiation: entropy_common.c:BIT_initDStream fse_decompress.c:BIT_initDStream Line | Count | Source | 254 | 536 | { | 255 | 536 | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } | 256 | | | 257 | 492 | bitD->start = (const char*)srcBuffer; | 258 | 492 | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); | 259 | | | 260 | 492 | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ | 261 | 194 | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); | 262 | 194 | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 263 | 194 | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 264 | 194 | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ | 265 | 194 | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } | 266 | 298 | } else { | 267 | 298 | bitD->ptr = bitD->start; | 268 | 298 | bitD->bitContainer = *(const BYTE*)(bitD->start); | 269 | 298 | switch(srcSize) | 270 | 298 | { | 271 | 18 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); | 272 | 18 | ZSTD_FALLTHROUGH; | 273 | | | 274 | 34 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); | 275 | 34 | ZSTD_FALLTHROUGH; | 276 | | | 277 | 70 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); | 278 | 70 | ZSTD_FALLTHROUGH; | 279 | | | 280 | 175 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; | 281 | 175 | ZSTD_FALLTHROUGH; | 282 | | | 283 | 215 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; | 284 | 215 | ZSTD_FALLTHROUGH; | 285 | | | 286 | 276 | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; | 287 | 276 | ZSTD_FALLTHROUGH; | 288 | | | 289 | 298 | default: break; | 290 | 298 | } | 291 | 298 | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 292 | 298 | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; | 293 | 298 | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ | 294 | 298 | } | 295 | 294 | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; | 296 | 294 | } | 297 | | | 298 | 485 | return srcSize; | 299 | 492 | } |
Unexecuted instantiation: zstd_common.c:BIT_initDStream Unexecuted instantiation: fse_compress.c:BIT_initDStream Unexecuted instantiation: huf_compress.c:BIT_initDStream Unexecuted instantiation: zstd_compress.c:BIT_initDStream Unexecuted instantiation: zstd_compress_literals.c:BIT_initDStream Unexecuted instantiation: zstd_compress_sequences.c:BIT_initDStream Unexecuted instantiation: zstd_compress_superblock.c:BIT_initDStream Unexecuted instantiation: zstd_double_fast.c:BIT_initDStream Unexecuted instantiation: zstd_fast.c:BIT_initDStream Unexecuted instantiation: zstd_lazy.c:BIT_initDStream Unexecuted instantiation: zstd_ldm.c:BIT_initDStream Unexecuted instantiation: zstd_opt.c:BIT_initDStream Unexecuted instantiation: zstdmt_compress.c:BIT_initDStream huf_decompress.c:BIT_initDStream Line | Count | Source | 254 | 2.42k | { | 255 | 2.42k | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } | 256 | | | 257 | 2.34k | bitD->start = (const char*)srcBuffer; | 258 | 2.34k | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); | 259 | | | 260 | 2.34k | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ | 261 | 1.14k | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); | 262 | 1.14k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 263 | 1.14k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 264 | 1.14k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ | 265 | 1.14k | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } | 266 | 1.19k | } else { | 267 | 1.19k | bitD->ptr = bitD->start; | 268 | 1.19k | bitD->bitContainer = *(const BYTE*)(bitD->start); | 269 | 1.19k | switch(srcSize) | 270 | 1.19k | { | 271 | 44 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); | 272 | 44 | ZSTD_FALLTHROUGH; | 273 | | | 274 | 86 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); | 275 | 86 | ZSTD_FALLTHROUGH; | 276 | | | 277 | 133 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); | 278 | 133 | ZSTD_FALLTHROUGH; | 279 | | | 280 | 177 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; | 281 | 177 | ZSTD_FALLTHROUGH; | 282 | | | 283 | 255 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; | 284 | 255 | ZSTD_FALLTHROUGH; | 285 | | | 286 | 335 | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; | 287 | 335 | ZSTD_FALLTHROUGH; | 288 | | | 289 | 1.19k | default: break; | 290 | 1.19k | } | 291 | 1.19k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 292 | 1.19k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; | 293 | 1.19k | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ | 294 | 1.19k | } | 295 | 1.17k | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; | 296 | 1.17k | } | 297 | | | 298 | 2.29k | return srcSize; | 299 | 2.34k | } |
Unexecuted instantiation: zstd_ddict.c:BIT_initDStream Unexecuted instantiation: zstd_decompress.c:BIT_initDStream zstd_decompress_block.c:BIT_initDStream Line | Count | Source | 254 | 1.40k | { | 255 | 1.40k | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } | 256 | | | 257 | 1.33k | bitD->start = (const char*)srcBuffer; | 258 | 1.33k | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); | 259 | | | 260 | 1.33k | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ | 261 | 224 | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); | 262 | 224 | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 263 | 224 | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 264 | 224 | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ | 265 | 224 | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } | 266 | 1.11k | } else { | 267 | 1.11k | bitD->ptr = bitD->start; | 268 | 1.11k | bitD->bitContainer = *(const BYTE*)(bitD->start); | 269 | 1.11k | switch(srcSize) | 270 | 1.11k | { | 271 | 27 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); | 272 | 27 | ZSTD_FALLTHROUGH; | 273 | | | 274 | 46 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); | 275 | 46 | ZSTD_FALLTHROUGH; | 276 | | | 277 | 118 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); | 278 | 118 | ZSTD_FALLTHROUGH; | 279 | | | 280 | 247 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; | 281 | 247 | ZSTD_FALLTHROUGH; | 282 | | | 283 | 345 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; | 284 | 345 | ZSTD_FALLTHROUGH; | 285 | | | 286 | 531 | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; | 287 | 531 | ZSTD_FALLTHROUGH; | 288 | | | 289 | 1.11k | default: break; | 290 | 1.11k | } | 291 | 1.11k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 292 | 1.11k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; | 293 | 1.11k | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ | 294 | 1.11k | } | 295 | 1.11k | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; | 296 | 1.11k | } | 297 | | | 298 | 1.31k | return srcSize; | 299 | 1.33k | } |
Unexecuted instantiation: cover.c:BIT_initDStream Unexecuted instantiation: fastcover.c:BIT_initDStream Unexecuted instantiation: zdict.c:BIT_initDStream |
300 | | |
301 | | FORCE_INLINE_TEMPLATE size_t BIT_getUpperBits(BitContainerType bitContainer, U32 const start) |
302 | 0 | { |
303 | 0 | return bitContainer >> start; |
304 | 0 | } Unexecuted instantiation: sequence_producer.c:BIT_getUpperBits Unexecuted instantiation: entropy_common.c:BIT_getUpperBits Unexecuted instantiation: fse_decompress.c:BIT_getUpperBits Unexecuted instantiation: zstd_common.c:BIT_getUpperBits Unexecuted instantiation: fse_compress.c:BIT_getUpperBits Unexecuted instantiation: huf_compress.c:BIT_getUpperBits Unexecuted instantiation: zstd_compress.c:BIT_getUpperBits Unexecuted instantiation: zstd_compress_literals.c:BIT_getUpperBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_getUpperBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_getUpperBits Unexecuted instantiation: zstd_double_fast.c:BIT_getUpperBits Unexecuted instantiation: zstd_fast.c:BIT_getUpperBits Unexecuted instantiation: zstd_lazy.c:BIT_getUpperBits Unexecuted instantiation: zstd_ldm.c:BIT_getUpperBits Unexecuted instantiation: zstd_opt.c:BIT_getUpperBits Unexecuted instantiation: zstdmt_compress.c:BIT_getUpperBits Unexecuted instantiation: huf_decompress.c:BIT_getUpperBits Unexecuted instantiation: zstd_ddict.c:BIT_getUpperBits Unexecuted instantiation: zstd_decompress.c:BIT_getUpperBits Unexecuted instantiation: zstd_decompress_block.c:BIT_getUpperBits Unexecuted instantiation: cover.c:BIT_getUpperBits Unexecuted instantiation: fastcover.c:BIT_getUpperBits Unexecuted instantiation: zdict.c:BIT_getUpperBits |
305 | | |
306 | | FORCE_INLINE_TEMPLATE size_t BIT_getMiddleBits(BitContainerType bitContainer, U32 const start, U32 const nbBits) |
307 | 3.07M | { |
308 | 3.07M | U32 const regMask = sizeof(bitContainer)*8 - 1; |
309 | | /* if start > regMask, bitstream is corrupted, and result is undefined */ |
310 | 3.07M | assert(nbBits < BIT_MASK_SIZE); |
311 | | /* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better |
312 | | * than accessing memory. When bmi2 instruction is not present, we consider |
313 | | * such cpus old (pre-Haswell, 2013) and their performance is not of that |
314 | | * importance. |
315 | | */ |
316 | 3.07M | #if defined(__x86_64__) || defined(_M_X86) |
317 | 3.07M | return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1); |
318 | | #else |
319 | | return (bitContainer >> (start & regMask)) & BIT_mask[nbBits]; |
320 | | #endif |
321 | 3.07M | } Unexecuted instantiation: sequence_producer.c:BIT_getMiddleBits Unexecuted instantiation: entropy_common.c:BIT_getMiddleBits fse_decompress.c:BIT_getMiddleBits Line | Count | Source | 307 | 27.8k | { | 308 | 27.8k | U32 const regMask = sizeof(bitContainer)*8 - 1; | 309 | | /* if start > regMask, bitstream is corrupted, and result is undefined */ | 310 | 27.8k | assert(nbBits < BIT_MASK_SIZE); | 311 | | /* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better | 312 | | * than accessing memory. When bmi2 instruction is not present, we consider | 313 | | * such cpus old (pre-Haswell, 2013) and their performance is not of that | 314 | | * importance. | 315 | | */ | 316 | 27.8k | #if defined(__x86_64__) || defined(_M_X86) | 317 | 27.8k | return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1); | 318 | | #else | 319 | | return (bitContainer >> (start & regMask)) & BIT_mask[nbBits]; | 320 | | #endif | 321 | 27.8k | } |
Unexecuted instantiation: zstd_common.c:BIT_getMiddleBits Unexecuted instantiation: fse_compress.c:BIT_getMiddleBits Unexecuted instantiation: huf_compress.c:BIT_getMiddleBits Unexecuted instantiation: zstd_compress.c:BIT_getMiddleBits Unexecuted instantiation: zstd_compress_literals.c:BIT_getMiddleBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_getMiddleBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_getMiddleBits Unexecuted instantiation: zstd_double_fast.c:BIT_getMiddleBits Unexecuted instantiation: zstd_fast.c:BIT_getMiddleBits Unexecuted instantiation: zstd_lazy.c:BIT_getMiddleBits Unexecuted instantiation: zstd_ldm.c:BIT_getMiddleBits Unexecuted instantiation: zstd_opt.c:BIT_getMiddleBits Unexecuted instantiation: zstdmt_compress.c:BIT_getMiddleBits Unexecuted instantiation: huf_decompress.c:BIT_getMiddleBits Unexecuted instantiation: zstd_ddict.c:BIT_getMiddleBits Unexecuted instantiation: zstd_decompress.c:BIT_getMiddleBits zstd_decompress_block.c:BIT_getMiddleBits Line | Count | Source | 307 | 3.04M | { | 308 | 3.04M | U32 const regMask = sizeof(bitContainer)*8 - 1; | 309 | | /* if start > regMask, bitstream is corrupted, and result is undefined */ | 310 | 3.04M | assert(nbBits < BIT_MASK_SIZE); | 311 | | /* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better | 312 | | * than accessing memory. When bmi2 instruction is not present, we consider | 313 | | * such cpus old (pre-Haswell, 2013) and their performance is not of that | 314 | | * importance. | 315 | | */ | 316 | 3.04M | #if defined(__x86_64__) || defined(_M_X86) | 317 | 3.04M | return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1); | 318 | | #else | 319 | | return (bitContainer >> (start & regMask)) & BIT_mask[nbBits]; | 320 | | #endif | 321 | 3.04M | } |
Unexecuted instantiation: cover.c:BIT_getMiddleBits Unexecuted instantiation: fastcover.c:BIT_getMiddleBits Unexecuted instantiation: zdict.c:BIT_getMiddleBits |
322 | | |
323 | | /*! BIT_lookBits() : |
324 | | * Provides next n bits from local register. |
325 | | * local register is not modified. |
326 | | * On 32-bits, maxNbBits==24. |
327 | | * On 64-bits, maxNbBits==56. |
328 | | * @return : value extracted */ |
329 | | FORCE_INLINE_TEMPLATE size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits) |
330 | 3.07M | { |
331 | | /* arbitrate between double-shift and shift+mask */ |
332 | 3.07M | #if 1 |
333 | | /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8, |
334 | | * bitstream is likely corrupted, and result is undefined */ |
335 | 3.07M | return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits); |
336 | | #else |
337 | | /* this code path is slower on my os-x laptop */ |
338 | | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; |
339 | | return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask); |
340 | | #endif |
341 | 3.07M | } Unexecuted instantiation: sequence_producer.c:BIT_lookBits Unexecuted instantiation: entropy_common.c:BIT_lookBits fse_decompress.c:BIT_lookBits Line | Count | Source | 330 | 27.8k | { | 331 | | /* arbitrate between double-shift and shift+mask */ | 332 | 27.8k | #if 1 | 333 | | /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8, | 334 | | * bitstream is likely corrupted, and result is undefined */ | 335 | 27.8k | return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits); | 336 | | #else | 337 | | /* this code path is slower on my os-x laptop */ | 338 | | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 339 | | return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask); | 340 | | #endif | 341 | 27.8k | } |
Unexecuted instantiation: zstd_common.c:BIT_lookBits Unexecuted instantiation: fse_compress.c:BIT_lookBits Unexecuted instantiation: huf_compress.c:BIT_lookBits Unexecuted instantiation: zstd_compress.c:BIT_lookBits Unexecuted instantiation: zstd_compress_literals.c:BIT_lookBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_lookBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_lookBits Unexecuted instantiation: zstd_double_fast.c:BIT_lookBits Unexecuted instantiation: zstd_fast.c:BIT_lookBits Unexecuted instantiation: zstd_lazy.c:BIT_lookBits Unexecuted instantiation: zstd_ldm.c:BIT_lookBits Unexecuted instantiation: zstd_opt.c:BIT_lookBits Unexecuted instantiation: zstdmt_compress.c:BIT_lookBits Unexecuted instantiation: huf_decompress.c:BIT_lookBits Unexecuted instantiation: zstd_ddict.c:BIT_lookBits Unexecuted instantiation: zstd_decompress.c:BIT_lookBits zstd_decompress_block.c:BIT_lookBits Line | Count | Source | 330 | 3.04M | { | 331 | | /* arbitrate between double-shift and shift+mask */ | 332 | 3.04M | #if 1 | 333 | | /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8, | 334 | | * bitstream is likely corrupted, and result is undefined */ | 335 | 3.04M | return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits); | 336 | | #else | 337 | | /* this code path is slower on my os-x laptop */ | 338 | | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 339 | | return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask); | 340 | | #endif | 341 | 3.04M | } |
Unexecuted instantiation: cover.c:BIT_lookBits Unexecuted instantiation: fastcover.c:BIT_lookBits Unexecuted instantiation: zdict.c:BIT_lookBits |
342 | | |
343 | | /*! BIT_lookBitsFast() : |
344 | | * unsafe version; only works if nbBits >= 1 */ |
345 | | MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits) |
346 | 7.09M | { |
347 | 7.09M | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; |
348 | 7.09M | assert(nbBits >= 1); |
349 | 7.09M | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); |
350 | 7.09M | } Unexecuted instantiation: sequence_producer.c:BIT_lookBitsFast Unexecuted instantiation: entropy_common.c:BIT_lookBitsFast fse_decompress.c:BIT_lookBitsFast Line | Count | Source | 346 | 11.4k | { | 347 | 11.4k | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 348 | 11.4k | assert(nbBits >= 1); | 349 | 11.4k | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); | 350 | 11.4k | } |
Unexecuted instantiation: zstd_common.c:BIT_lookBitsFast Unexecuted instantiation: fse_compress.c:BIT_lookBitsFast Unexecuted instantiation: huf_compress.c:BIT_lookBitsFast Unexecuted instantiation: zstd_compress.c:BIT_lookBitsFast Unexecuted instantiation: zstd_compress_literals.c:BIT_lookBitsFast Unexecuted instantiation: zstd_compress_sequences.c:BIT_lookBitsFast Unexecuted instantiation: zstd_compress_superblock.c:BIT_lookBitsFast Unexecuted instantiation: zstd_double_fast.c:BIT_lookBitsFast Unexecuted instantiation: zstd_fast.c:BIT_lookBitsFast Unexecuted instantiation: zstd_lazy.c:BIT_lookBitsFast Unexecuted instantiation: zstd_ldm.c:BIT_lookBitsFast Unexecuted instantiation: zstd_opt.c:BIT_lookBitsFast Unexecuted instantiation: zstdmt_compress.c:BIT_lookBitsFast huf_decompress.c:BIT_lookBitsFast Line | Count | Source | 346 | 6.46M | { | 347 | 6.46M | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 348 | 6.46M | assert(nbBits >= 1); | 349 | 6.46M | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); | 350 | 6.46M | } |
Unexecuted instantiation: zstd_ddict.c:BIT_lookBitsFast Unexecuted instantiation: zstd_decompress.c:BIT_lookBitsFast zstd_decompress_block.c:BIT_lookBitsFast Line | Count | Source | 346 | 615k | { | 347 | 615k | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 348 | 615k | assert(nbBits >= 1); | 349 | 615k | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); | 350 | 615k | } |
Unexecuted instantiation: cover.c:BIT_lookBitsFast Unexecuted instantiation: fastcover.c:BIT_lookBitsFast Unexecuted instantiation: zdict.c:BIT_lookBitsFast |
351 | | |
352 | | FORCE_INLINE_TEMPLATE void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits) |
353 | 10.1M | { |
354 | 10.1M | bitD->bitsConsumed += nbBits; |
355 | 10.1M | } Unexecuted instantiation: sequence_producer.c:BIT_skipBits Unexecuted instantiation: entropy_common.c:BIT_skipBits fse_decompress.c:BIT_skipBits Line | Count | Source | 353 | 39.3k | { | 354 | 39.3k | bitD->bitsConsumed += nbBits; | 355 | 39.3k | } |
Unexecuted instantiation: zstd_common.c:BIT_skipBits Unexecuted instantiation: fse_compress.c:BIT_skipBits Unexecuted instantiation: huf_compress.c:BIT_skipBits Unexecuted instantiation: zstd_compress.c:BIT_skipBits Unexecuted instantiation: zstd_compress_literals.c:BIT_skipBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_skipBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_skipBits Unexecuted instantiation: zstd_double_fast.c:BIT_skipBits Unexecuted instantiation: zstd_fast.c:BIT_skipBits Unexecuted instantiation: zstd_lazy.c:BIT_skipBits Unexecuted instantiation: zstd_ldm.c:BIT_skipBits Unexecuted instantiation: zstd_opt.c:BIT_skipBits Unexecuted instantiation: zstdmt_compress.c:BIT_skipBits huf_decompress.c:BIT_skipBits Line | Count | Source | 353 | 6.46M | { | 354 | 6.46M | bitD->bitsConsumed += nbBits; | 355 | 6.46M | } |
Unexecuted instantiation: zstd_ddict.c:BIT_skipBits Unexecuted instantiation: zstd_decompress.c:BIT_skipBits zstd_decompress_block.c:BIT_skipBits Line | Count | Source | 353 | 3.66M | { | 354 | 3.66M | bitD->bitsConsumed += nbBits; | 355 | 3.66M | } |
Unexecuted instantiation: cover.c:BIT_skipBits Unexecuted instantiation: fastcover.c:BIT_skipBits Unexecuted instantiation: zdict.c:BIT_skipBits |
356 | | |
357 | | /*! BIT_readBits() : |
358 | | * Read (consume) next n bits from local register and update. |
359 | | * Pay attention to not read more than nbBits contained into local register. |
360 | | * @return : extracted value. */ |
361 | | FORCE_INLINE_TEMPLATE size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits) |
362 | 3.07M | { |
363 | 3.07M | size_t const value = BIT_lookBits(bitD, nbBits); |
364 | 3.07M | BIT_skipBits(bitD, nbBits); |
365 | 3.07M | return value; |
366 | 3.07M | } Unexecuted instantiation: sequence_producer.c:BIT_readBits Unexecuted instantiation: entropy_common.c:BIT_readBits fse_decompress.c:BIT_readBits Line | Count | Source | 362 | 27.8k | { | 363 | 27.8k | size_t const value = BIT_lookBits(bitD, nbBits); | 364 | 27.8k | BIT_skipBits(bitD, nbBits); | 365 | 27.8k | return value; | 366 | 27.8k | } |
Unexecuted instantiation: zstd_common.c:BIT_readBits Unexecuted instantiation: fse_compress.c:BIT_readBits Unexecuted instantiation: huf_compress.c:BIT_readBits Unexecuted instantiation: zstd_compress.c:BIT_readBits Unexecuted instantiation: zstd_compress_literals.c:BIT_readBits Unexecuted instantiation: zstd_compress_sequences.c:BIT_readBits Unexecuted instantiation: zstd_compress_superblock.c:BIT_readBits Unexecuted instantiation: zstd_double_fast.c:BIT_readBits Unexecuted instantiation: zstd_fast.c:BIT_readBits Unexecuted instantiation: zstd_lazy.c:BIT_readBits Unexecuted instantiation: zstd_ldm.c:BIT_readBits Unexecuted instantiation: zstd_opt.c:BIT_readBits Unexecuted instantiation: zstdmt_compress.c:BIT_readBits Unexecuted instantiation: huf_decompress.c:BIT_readBits Unexecuted instantiation: zstd_ddict.c:BIT_readBits Unexecuted instantiation: zstd_decompress.c:BIT_readBits zstd_decompress_block.c:BIT_readBits Line | Count | Source | 362 | 3.04M | { | 363 | 3.04M | size_t const value = BIT_lookBits(bitD, nbBits); | 364 | 3.04M | BIT_skipBits(bitD, nbBits); | 365 | 3.04M | return value; | 366 | 3.04M | } |
Unexecuted instantiation: cover.c:BIT_readBits Unexecuted instantiation: fastcover.c:BIT_readBits Unexecuted instantiation: zdict.c:BIT_readBits |
367 | | |
368 | | /*! BIT_readBitsFast() : |
369 | | * unsafe version; only works if nbBits >= 1 */ |
370 | | MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits) |
371 | 627k | { |
372 | 627k | size_t const value = BIT_lookBitsFast(bitD, nbBits); |
373 | 627k | assert(nbBits >= 1); |
374 | 627k | BIT_skipBits(bitD, nbBits); |
375 | 627k | return value; |
376 | 627k | } Unexecuted instantiation: sequence_producer.c:BIT_readBitsFast Unexecuted instantiation: entropy_common.c:BIT_readBitsFast fse_decompress.c:BIT_readBitsFast Line | Count | Source | 371 | 11.4k | { | 372 | 11.4k | size_t const value = BIT_lookBitsFast(bitD, nbBits); | 373 | 11.4k | assert(nbBits >= 1); | 374 | 11.4k | BIT_skipBits(bitD, nbBits); | 375 | 11.4k | return value; | 376 | 11.4k | } |
Unexecuted instantiation: zstd_common.c:BIT_readBitsFast Unexecuted instantiation: fse_compress.c:BIT_readBitsFast Unexecuted instantiation: huf_compress.c:BIT_readBitsFast Unexecuted instantiation: zstd_compress.c:BIT_readBitsFast Unexecuted instantiation: zstd_compress_literals.c:BIT_readBitsFast Unexecuted instantiation: zstd_compress_sequences.c:BIT_readBitsFast Unexecuted instantiation: zstd_compress_superblock.c:BIT_readBitsFast Unexecuted instantiation: zstd_double_fast.c:BIT_readBitsFast Unexecuted instantiation: zstd_fast.c:BIT_readBitsFast Unexecuted instantiation: zstd_lazy.c:BIT_readBitsFast Unexecuted instantiation: zstd_ldm.c:BIT_readBitsFast Unexecuted instantiation: zstd_opt.c:BIT_readBitsFast Unexecuted instantiation: zstdmt_compress.c:BIT_readBitsFast Unexecuted instantiation: huf_decompress.c:BIT_readBitsFast Unexecuted instantiation: zstd_ddict.c:BIT_readBitsFast Unexecuted instantiation: zstd_decompress.c:BIT_readBitsFast zstd_decompress_block.c:BIT_readBitsFast Line | Count | Source | 371 | 615k | { | 372 | 615k | size_t const value = BIT_lookBitsFast(bitD, nbBits); | 373 | 615k | assert(nbBits >= 1); | 374 | 615k | BIT_skipBits(bitD, nbBits); | 375 | 615k | return value; | 376 | 615k | } |
Unexecuted instantiation: cover.c:BIT_readBitsFast Unexecuted instantiation: fastcover.c:BIT_readBitsFast Unexecuted instantiation: zdict.c:BIT_readBitsFast |
377 | | |
378 | | /*! BIT_reloadDStream_internal() : |
379 | | * Simple variant of BIT_reloadDStream(), with two conditions: |
380 | | * 1. bitstream is valid : bitsConsumed <= sizeof(bitD->bitContainer)*8 |
381 | | * 2. look window is valid after shifted down : bitD->ptr >= bitD->start |
382 | | */ |
383 | | MEM_STATIC BIT_DStream_status BIT_reloadDStream_internal(BIT_DStream_t* bitD) |
384 | 217k | { |
385 | 217k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); |
386 | 217k | bitD->ptr -= bitD->bitsConsumed >> 3; |
387 | 217k | assert(bitD->ptr >= bitD->start); |
388 | 217k | bitD->bitsConsumed &= 7; |
389 | 217k | bitD->bitContainer = MEM_readLEST(bitD->ptr); |
390 | 217k | return BIT_DStream_unfinished; |
391 | 217k | } Unexecuted instantiation: sequence_producer.c:BIT_reloadDStream_internal Unexecuted instantiation: entropy_common.c:BIT_reloadDStream_internal fse_decompress.c:BIT_reloadDStream_internal Line | Count | Source | 384 | 3.00k | { | 385 | 3.00k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); | 386 | 3.00k | bitD->ptr -= bitD->bitsConsumed >> 3; | 387 | 3.00k | assert(bitD->ptr >= bitD->start); | 388 | 3.00k | bitD->bitsConsumed &= 7; | 389 | 3.00k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 390 | 3.00k | return BIT_DStream_unfinished; | 391 | 3.00k | } |
Unexecuted instantiation: zstd_common.c:BIT_reloadDStream_internal Unexecuted instantiation: fse_compress.c:BIT_reloadDStream_internal Unexecuted instantiation: huf_compress.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_compress.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_compress_literals.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_compress_sequences.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_compress_superblock.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_double_fast.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_fast.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_lazy.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_ldm.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_opt.c:BIT_reloadDStream_internal Unexecuted instantiation: zstdmt_compress.c:BIT_reloadDStream_internal huf_decompress.c:BIT_reloadDStream_internal Line | Count | Source | 384 | 198k | { | 385 | 198k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); | 386 | 198k | bitD->ptr -= bitD->bitsConsumed >> 3; | 387 | 198k | assert(bitD->ptr >= bitD->start); | 388 | 198k | bitD->bitsConsumed &= 7; | 389 | 198k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 390 | 198k | return BIT_DStream_unfinished; | 391 | 198k | } |
Unexecuted instantiation: zstd_ddict.c:BIT_reloadDStream_internal Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStream_internal zstd_decompress_block.c:BIT_reloadDStream_internal Line | Count | Source | 384 | 15.7k | { | 385 | 15.7k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); | 386 | 15.7k | bitD->ptr -= bitD->bitsConsumed >> 3; | 387 | 15.7k | assert(bitD->ptr >= bitD->start); | 388 | 15.7k | bitD->bitsConsumed &= 7; | 389 | 15.7k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 390 | 15.7k | return BIT_DStream_unfinished; | 391 | 15.7k | } |
Unexecuted instantiation: cover.c:BIT_reloadDStream_internal Unexecuted instantiation: fastcover.c:BIT_reloadDStream_internal Unexecuted instantiation: zdict.c:BIT_reloadDStream_internal |
392 | | |
393 | | /*! BIT_reloadDStreamFast() : |
394 | | * Similar to BIT_reloadDStream(), but with two differences: |
395 | | * 1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold! |
396 | | * 2. Returns BIT_DStream_overflow when bitD->ptr < bitD->limitPtr, at this |
397 | | * point you must use BIT_reloadDStream() to reload. |
398 | | */ |
399 | | MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD) |
400 | 6.62k | { |
401 | 6.62k | if (UNLIKELY(bitD->ptr < bitD->limitPtr)) |
402 | 1.08k | return BIT_DStream_overflow; |
403 | 5.53k | return BIT_reloadDStream_internal(bitD); |
404 | 6.62k | } Unexecuted instantiation: sequence_producer.c:BIT_reloadDStreamFast Unexecuted instantiation: entropy_common.c:BIT_reloadDStreamFast Unexecuted instantiation: fse_decompress.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_common.c:BIT_reloadDStreamFast Unexecuted instantiation: fse_compress.c:BIT_reloadDStreamFast Unexecuted instantiation: huf_compress.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_compress.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_compress_literals.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_compress_sequences.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_compress_superblock.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_double_fast.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_fast.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_lazy.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_ldm.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_opt.c:BIT_reloadDStreamFast Unexecuted instantiation: zstdmt_compress.c:BIT_reloadDStreamFast huf_decompress.c:BIT_reloadDStreamFast Line | Count | Source | 400 | 6.62k | { | 401 | 6.62k | if (UNLIKELY(bitD->ptr < bitD->limitPtr)) | 402 | 1.08k | return BIT_DStream_overflow; | 403 | 5.53k | return BIT_reloadDStream_internal(bitD); | 404 | 6.62k | } |
Unexecuted instantiation: zstd_ddict.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_decompress_block.c:BIT_reloadDStreamFast Unexecuted instantiation: cover.c:BIT_reloadDStreamFast Unexecuted instantiation: fastcover.c:BIT_reloadDStreamFast Unexecuted instantiation: zdict.c:BIT_reloadDStreamFast |
405 | | |
406 | | /*! BIT_reloadDStream() : |
407 | | * Refill `bitD` from buffer previously set in BIT_initDStream() . |
408 | | * This function is safe, it guarantees it will not never beyond src buffer. |
409 | | * @return : status of `BIT_DStream_t` internal register. |
410 | | * when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */ |
411 | | FORCE_INLINE_TEMPLATE BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD) |
412 | 1.24M | { |
413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ |
414 | 1.24M | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { |
415 | 894k | static const BitContainerType zeroFilled = 0; |
416 | 894k | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ |
417 | | /* overflow detected, erroneous scenario or end of stream: no update */ |
418 | 894k | return BIT_DStream_overflow; |
419 | 894k | } |
420 | | |
421 | 355k | assert(bitD->ptr >= bitD->start); |
422 | | |
423 | 355k | if (bitD->ptr >= bitD->limitPtr) { |
424 | 211k | return BIT_reloadDStream_internal(bitD); |
425 | 211k | } |
426 | 143k | if (bitD->ptr == bitD->start) { |
427 | | /* reached end of bitStream => no update */ |
428 | 128k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; |
429 | 77.5k | return BIT_DStream_completed; |
430 | 128k | } |
431 | | /* start < ptr < limitPtr => cautious update */ |
432 | 15.2k | { U32 nbBytes = bitD->bitsConsumed >> 3; |
433 | 15.2k | BIT_DStream_status result = BIT_DStream_unfinished; |
434 | 15.2k | if (bitD->ptr - nbBytes < bitD->start) { |
435 | 486 | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ |
436 | 486 | result = BIT_DStream_endOfBuffer; |
437 | 486 | } |
438 | 15.2k | bitD->ptr -= nbBytes; |
439 | 15.2k | bitD->bitsConsumed -= nbBytes*8; |
440 | 15.2k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ |
441 | 15.2k | return result; |
442 | 143k | } |
443 | 143k | } Unexecuted instantiation: sequence_producer.c:BIT_reloadDStream Unexecuted instantiation: entropy_common.c:BIT_reloadDStream fse_decompress.c:BIT_reloadDStream Line | Count | Source | 412 | 27.4k | { | 413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ | 414 | 27.4k | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { | 415 | 483 | static const BitContainerType zeroFilled = 0; | 416 | 483 | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ | 417 | | /* overflow detected, erroneous scenario or end of stream: no update */ | 418 | 483 | return BIT_DStream_overflow; | 419 | 483 | } | 420 | | | 421 | 26.9k | assert(bitD->ptr >= bitD->start); | 422 | | | 423 | 26.9k | if (bitD->ptr >= bitD->limitPtr) { | 424 | 3.00k | return BIT_reloadDStream_internal(bitD); | 425 | 3.00k | } | 426 | 23.9k | if (bitD->ptr == bitD->start) { | 427 | | /* reached end of bitStream => no update */ | 428 | 22.2k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; | 429 | 918 | return BIT_DStream_completed; | 430 | 22.2k | } | 431 | | /* start < ptr < limitPtr => cautious update */ | 432 | 1.68k | { U32 nbBytes = bitD->bitsConsumed >> 3; | 433 | 1.68k | BIT_DStream_status result = BIT_DStream_unfinished; | 434 | 1.68k | if (bitD->ptr - nbBytes < bitD->start) { | 435 | 19 | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ | 436 | 19 | result = BIT_DStream_endOfBuffer; | 437 | 19 | } | 438 | 1.68k | bitD->ptr -= nbBytes; | 439 | 1.68k | bitD->bitsConsumed -= nbBytes*8; | 440 | 1.68k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ | 441 | 1.68k | return result; | 442 | 23.9k | } | 443 | 23.9k | } |
Unexecuted instantiation: zstd_common.c:BIT_reloadDStream Unexecuted instantiation: fse_compress.c:BIT_reloadDStream Unexecuted instantiation: huf_compress.c:BIT_reloadDStream Unexecuted instantiation: zstd_compress.c:BIT_reloadDStream Unexecuted instantiation: zstd_compress_literals.c:BIT_reloadDStream Unexecuted instantiation: zstd_compress_sequences.c:BIT_reloadDStream Unexecuted instantiation: zstd_compress_superblock.c:BIT_reloadDStream Unexecuted instantiation: zstd_double_fast.c:BIT_reloadDStream Unexecuted instantiation: zstd_fast.c:BIT_reloadDStream Unexecuted instantiation: zstd_lazy.c:BIT_reloadDStream Unexecuted instantiation: zstd_ldm.c:BIT_reloadDStream Unexecuted instantiation: zstd_opt.c:BIT_reloadDStream Unexecuted instantiation: zstdmt_compress.c:BIT_reloadDStream huf_decompress.c:BIT_reloadDStream Line | Count | Source | 412 | 201k | { | 413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ | 414 | 201k | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { | 415 | 420 | static const BitContainerType zeroFilled = 0; | 416 | 420 | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ | 417 | | /* overflow detected, erroneous scenario or end of stream: no update */ | 418 | 420 | return BIT_DStream_overflow; | 419 | 420 | } | 420 | | | 421 | 201k | assert(bitD->ptr >= bitD->start); | 422 | | | 423 | 201k | if (bitD->ptr >= bitD->limitPtr) { | 424 | 192k | return BIT_reloadDStream_internal(bitD); | 425 | 192k | } | 426 | 8.50k | if (bitD->ptr == bitD->start) { | 427 | | /* reached end of bitStream => no update */ | 428 | 2.28k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; | 429 | 124 | return BIT_DStream_completed; | 430 | 2.28k | } | 431 | | /* start < ptr < limitPtr => cautious update */ | 432 | 6.21k | { U32 nbBytes = bitD->bitsConsumed >> 3; | 433 | 6.21k | BIT_DStream_status result = BIT_DStream_unfinished; | 434 | 6.21k | if (bitD->ptr - nbBytes < bitD->start) { | 435 | 449 | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ | 436 | 449 | result = BIT_DStream_endOfBuffer; | 437 | 449 | } | 438 | 6.21k | bitD->ptr -= nbBytes; | 439 | 6.21k | bitD->bitsConsumed -= nbBytes*8; | 440 | 6.21k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ | 441 | 6.21k | return result; | 442 | 8.50k | } | 443 | 8.50k | } |
Unexecuted instantiation: zstd_ddict.c:BIT_reloadDStream Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStream zstd_decompress_block.c:BIT_reloadDStream Line | Count | Source | 412 | 1.01M | { | 413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ | 414 | 1.01M | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { | 415 | 893k | static const BitContainerType zeroFilled = 0; | 416 | 893k | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ | 417 | | /* overflow detected, erroneous scenario or end of stream: no update */ | 418 | 893k | return BIT_DStream_overflow; | 419 | 893k | } | 420 | | | 421 | 126k | assert(bitD->ptr >= bitD->start); | 422 | | | 423 | 126k | if (bitD->ptr >= bitD->limitPtr) { | 424 | 15.7k | return BIT_reloadDStream_internal(bitD); | 425 | 15.7k | } | 426 | 110k | if (bitD->ptr == bitD->start) { | 427 | | /* reached end of bitStream => no update */ | 428 | 103k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; | 429 | 76.4k | return BIT_DStream_completed; | 430 | 103k | } | 431 | | /* start < ptr < limitPtr => cautious update */ | 432 | 7.29k | { U32 nbBytes = bitD->bitsConsumed >> 3; | 433 | 7.29k | BIT_DStream_status result = BIT_DStream_unfinished; | 434 | 7.29k | if (bitD->ptr - nbBytes < bitD->start) { | 435 | 18 | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ | 436 | 18 | result = BIT_DStream_endOfBuffer; | 437 | 18 | } | 438 | 7.29k | bitD->ptr -= nbBytes; | 439 | 7.29k | bitD->bitsConsumed -= nbBytes*8; | 440 | 7.29k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ | 441 | 7.29k | return result; | 442 | 110k | } | 443 | 110k | } |
Unexecuted instantiation: cover.c:BIT_reloadDStream Unexecuted instantiation: fastcover.c:BIT_reloadDStream Unexecuted instantiation: zdict.c:BIT_reloadDStream |
444 | | |
445 | | /*! BIT_endOfDStream() : |
446 | | * @return : 1 if DStream has _exactly_ reached its end (all bits consumed). |
447 | | */ |
448 | | MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream) |
449 | 2.29k | { |
450 | 2.29k | return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); |
451 | 2.29k | } Unexecuted instantiation: sequence_producer.c:BIT_endOfDStream Unexecuted instantiation: entropy_common.c:BIT_endOfDStream Unexecuted instantiation: fse_decompress.c:BIT_endOfDStream Unexecuted instantiation: zstd_common.c:BIT_endOfDStream Unexecuted instantiation: fse_compress.c:BIT_endOfDStream Unexecuted instantiation: huf_compress.c:BIT_endOfDStream Unexecuted instantiation: zstd_compress.c:BIT_endOfDStream Unexecuted instantiation: zstd_compress_literals.c:BIT_endOfDStream Unexecuted instantiation: zstd_compress_sequences.c:BIT_endOfDStream Unexecuted instantiation: zstd_compress_superblock.c:BIT_endOfDStream Unexecuted instantiation: zstd_double_fast.c:BIT_endOfDStream Unexecuted instantiation: zstd_fast.c:BIT_endOfDStream Unexecuted instantiation: zstd_lazy.c:BIT_endOfDStream Unexecuted instantiation: zstd_ldm.c:BIT_endOfDStream Unexecuted instantiation: zstd_opt.c:BIT_endOfDStream Unexecuted instantiation: zstdmt_compress.c:BIT_endOfDStream huf_decompress.c:BIT_endOfDStream Line | Count | Source | 449 | 2.04k | { | 450 | 2.04k | return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); | 451 | 2.04k | } |
Unexecuted instantiation: zstd_ddict.c:BIT_endOfDStream Unexecuted instantiation: zstd_decompress.c:BIT_endOfDStream zstd_decompress_block.c:BIT_endOfDStream Line | Count | Source | 449 | 249 | { | 450 | 249 | return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); | 451 | 249 | } |
Unexecuted instantiation: cover.c:BIT_endOfDStream Unexecuted instantiation: fastcover.c:BIT_endOfDStream Unexecuted instantiation: zdict.c:BIT_endOfDStream |
452 | | |
453 | | #if defined (__cplusplus) |
454 | | } |
455 | | #endif |
456 | | |
457 | | #endif /* BITSTREAM_H_MODULE */ |