/src/c-blosc/internal-complibs/zstd-1.5.6/common/bitstream.h
Line | Count | Source |
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 | 268k | { |
157 | 268k | bitC->bitContainer = 0; |
158 | 268k | bitC->bitPos = 0; |
159 | 268k | bitC->startPtr = (char*)startPtr; |
160 | 268k | bitC->ptr = bitC->startPtr; |
161 | 268k | bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer); |
162 | 268k | if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall); |
163 | 265k | return 0; |
164 | 268k | } Unexecuted instantiation: zstd_common.c:BIT_initCStream Unexecuted instantiation: zstd_compress.c:BIT_initCStream Unexecuted instantiation: zstd_compress_literals.c:BIT_initCStream zstd_compress_sequences.c:BIT_initCStream Line | Count | Source | 156 | 106k | { | 157 | 106k | bitC->bitContainer = 0; | 158 | 106k | bitC->bitPos = 0; | 159 | 106k | bitC->startPtr = (char*)startPtr; | 160 | 106k | bitC->ptr = bitC->startPtr; | 161 | 106k | bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer); | 162 | 106k | if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall); | 163 | 103k | return 0; | 164 | 106k | } |
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: zstd_decompress.c:BIT_initCStream Unexecuted instantiation: zstd_decompress_block.c:BIT_initCStream Unexecuted instantiation: entropy_common.c:BIT_initCStream Unexecuted instantiation: fse_decompress.c:BIT_initCStream fse_compress.c:BIT_initCStream Line | Count | Source | 156 | 161k | { | 157 | 161k | bitC->bitContainer = 0; | 158 | 161k | bitC->bitPos = 0; | 159 | 161k | bitC->startPtr = (char*)startPtr; | 160 | 161k | bitC->ptr = bitC->startPtr; | 161 | 161k | bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer); | 162 | 161k | if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall); | 163 | 161k | return 0; | 164 | 161k | } |
Unexecuted instantiation: huf_compress.c:BIT_initCStream Unexecuted instantiation: huf_decompress.c:BIT_initCStream Unexecuted instantiation: zstd_ddict.c:BIT_initCStream |
165 | | |
166 | | FORCE_INLINE_TEMPLATE size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits) |
167 | 186M | { |
168 | | #if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS) |
169 | | return _bzhi_u64(bitContainer, nbBits); |
170 | | #else |
171 | 186M | assert(nbBits < BIT_MASK_SIZE); |
172 | 186M | return bitContainer & BIT_mask[nbBits]; |
173 | 186M | #endif |
174 | 186M | } Unexecuted instantiation: zstd_common.c:BIT_getLowerBits Unexecuted instantiation: zstd_compress.c:BIT_getLowerBits Unexecuted instantiation: zstd_compress_literals.c:BIT_getLowerBits zstd_compress_sequences.c:BIT_getLowerBits Line | Count | Source | 167 | 147M | { | 168 | | #if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS) | 169 | | return _bzhi_u64(bitContainer, nbBits); | 170 | | #else | 171 | 147M | assert(nbBits < BIT_MASK_SIZE); | 172 | 147M | return bitContainer & BIT_mask[nbBits]; | 173 | 147M | #endif | 174 | 147M | } |
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: zstd_decompress.c:BIT_getLowerBits Unexecuted instantiation: zstd_decompress_block.c:BIT_getLowerBits Unexecuted instantiation: entropy_common.c:BIT_getLowerBits Unexecuted instantiation: fse_decompress.c:BIT_getLowerBits fse_compress.c:BIT_getLowerBits Line | Count | Source | 167 | 38.8M | { | 168 | | #if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS) | 169 | | return _bzhi_u64(bitContainer, nbBits); | 170 | | #else | 171 | 38.8M | assert(nbBits < BIT_MASK_SIZE); | 172 | 38.8M | return bitContainer & BIT_mask[nbBits]; | 173 | 38.8M | #endif | 174 | 38.8M | } |
Unexecuted instantiation: huf_compress.c:BIT_getLowerBits Unexecuted instantiation: huf_decompress.c:BIT_getLowerBits Unexecuted instantiation: zstd_ddict.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 | 186M | { |
182 | 186M | DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32); |
183 | 186M | assert(nbBits < BIT_MASK_SIZE); |
184 | 186M | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
185 | 186M | bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos; |
186 | 186M | bitC->bitPos += nbBits; |
187 | 186M | } Unexecuted instantiation: zstd_common.c:BIT_addBits Unexecuted instantiation: zstd_compress.c:BIT_addBits Unexecuted instantiation: zstd_compress_literals.c:BIT_addBits zstd_compress_sequences.c:BIT_addBits Line | Count | Source | 181 | 147M | { | 182 | 147M | DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32); | 183 | 147M | assert(nbBits < BIT_MASK_SIZE); | 184 | 147M | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 185 | 147M | bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos; | 186 | 147M | bitC->bitPos += nbBits; | 187 | 147M | } |
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: zstd_decompress.c:BIT_addBits Unexecuted instantiation: zstd_decompress_block.c:BIT_addBits Unexecuted instantiation: entropy_common.c:BIT_addBits Unexecuted instantiation: fse_decompress.c:BIT_addBits fse_compress.c:BIT_addBits Line | Count | Source | 181 | 38.8M | { | 182 | 38.8M | DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32); | 183 | 38.8M | assert(nbBits < BIT_MASK_SIZE); | 184 | 38.8M | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 185 | 38.8M | bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos; | 186 | 38.8M | bitC->bitPos += nbBits; | 187 | 38.8M | } |
Unexecuted instantiation: huf_compress.c:BIT_addBits Unexecuted instantiation: huf_decompress.c:BIT_addBits Unexecuted instantiation: zstd_ddict.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 | 265k | { |
195 | 265k | assert((value>>nbBits) == 0); |
196 | 265k | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
197 | 265k | bitC->bitContainer |= value << bitC->bitPos; |
198 | 265k | bitC->bitPos += nbBits; |
199 | 265k | } Unexecuted instantiation: zstd_common.c:BIT_addBitsFast Unexecuted instantiation: zstd_compress.c:BIT_addBitsFast Unexecuted instantiation: zstd_compress_literals.c:BIT_addBitsFast zstd_compress_sequences.c:BIT_addBitsFast Line | Count | Source | 194 | 103k | { | 195 | 103k | assert((value>>nbBits) == 0); | 196 | 103k | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 197 | 103k | bitC->bitContainer |= value << bitC->bitPos; | 198 | 103k | bitC->bitPos += nbBits; | 199 | 103k | } |
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: zstd_decompress.c:BIT_addBitsFast Unexecuted instantiation: zstd_decompress_block.c:BIT_addBitsFast Unexecuted instantiation: entropy_common.c:BIT_addBitsFast Unexecuted instantiation: fse_decompress.c:BIT_addBitsFast fse_compress.c:BIT_addBitsFast Line | Count | Source | 194 | 161k | { | 195 | 161k | assert((value>>nbBits) == 0); | 196 | 161k | assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 197 | 161k | bitC->bitContainer |= value << bitC->bitPos; | 198 | 161k | bitC->bitPos += nbBits; | 199 | 161k | } |
Unexecuted instantiation: huf_compress.c:BIT_addBitsFast Unexecuted instantiation: huf_decompress.c:BIT_addBitsFast Unexecuted instantiation: zstd_ddict.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 | 9.64M | { |
206 | 9.64M | size_t const nbBytes = bitC->bitPos >> 3; |
207 | 9.64M | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
208 | 9.64M | assert(bitC->ptr <= bitC->endPtr); |
209 | 9.64M | MEM_writeLEST(bitC->ptr, bitC->bitContainer); |
210 | 9.64M | bitC->ptr += nbBytes; |
211 | 9.64M | bitC->bitPos &= 7; |
212 | 9.64M | bitC->bitContainer >>= nbBytes*8; |
213 | 9.64M | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_decompress_block.c:BIT_flushBitsFast Unexecuted instantiation: entropy_common.c:BIT_flushBitsFast Unexecuted instantiation: fse_decompress.c:BIT_flushBitsFast fse_compress.c:BIT_flushBitsFast Line | Count | Source | 205 | 9.64M | { | 206 | 9.64M | size_t const nbBytes = bitC->bitPos >> 3; | 207 | 9.64M | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 208 | 9.64M | assert(bitC->ptr <= bitC->endPtr); | 209 | 9.64M | MEM_writeLEST(bitC->ptr, bitC->bitContainer); | 210 | 9.64M | bitC->ptr += nbBytes; | 211 | 9.64M | bitC->bitPos &= 7; | 212 | 9.64M | bitC->bitContainer >>= nbBytes*8; | 213 | 9.64M | } |
Unexecuted instantiation: huf_compress.c:BIT_flushBitsFast Unexecuted instantiation: huf_decompress.c:BIT_flushBitsFast Unexecuted instantiation: zstd_ddict.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 | 25.5M | { |
222 | 25.5M | size_t const nbBytes = bitC->bitPos >> 3; |
223 | 25.5M | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); |
224 | 25.5M | assert(bitC->ptr <= bitC->endPtr); |
225 | 25.5M | MEM_writeLEST(bitC->ptr, bitC->bitContainer); |
226 | 25.5M | bitC->ptr += nbBytes; |
227 | 25.5M | if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr; |
228 | 25.5M | bitC->bitPos &= 7; |
229 | 25.5M | bitC->bitContainer >>= nbBytes*8; |
230 | 25.5M | } Unexecuted instantiation: zstd_common.c:BIT_flushBits Unexecuted instantiation: zstd_compress.c:BIT_flushBits Unexecuted instantiation: zstd_compress_literals.c:BIT_flushBits zstd_compress_sequences.c:BIT_flushBits Line | Count | Source | 221 | 24.9M | { | 222 | 24.9M | size_t const nbBytes = bitC->bitPos >> 3; | 223 | 24.9M | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 224 | 24.9M | assert(bitC->ptr <= bitC->endPtr); | 225 | 24.9M | MEM_writeLEST(bitC->ptr, bitC->bitContainer); | 226 | 24.9M | bitC->ptr += nbBytes; | 227 | 24.9M | if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr; | 228 | 24.9M | bitC->bitPos &= 7; | 229 | 24.9M | bitC->bitContainer >>= nbBytes*8; | 230 | 24.9M | } |
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: zstd_decompress.c:BIT_flushBits Unexecuted instantiation: zstd_decompress_block.c:BIT_flushBits Unexecuted instantiation: entropy_common.c:BIT_flushBits Unexecuted instantiation: fse_decompress.c:BIT_flushBits fse_compress.c:BIT_flushBits Line | Count | Source | 221 | 575k | { | 222 | 575k | size_t const nbBytes = bitC->bitPos >> 3; | 223 | 575k | assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 224 | 575k | assert(bitC->ptr <= bitC->endPtr); | 225 | 575k | MEM_writeLEST(bitC->ptr, bitC->bitContainer); | 226 | 575k | bitC->ptr += nbBytes; | 227 | 575k | if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr; | 228 | 575k | bitC->bitPos &= 7; | 229 | 575k | bitC->bitContainer >>= nbBytes*8; | 230 | 575k | } |
Unexecuted instantiation: huf_compress.c:BIT_flushBits Unexecuted instantiation: huf_decompress.c:BIT_flushBits Unexecuted instantiation: zstd_ddict.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 | 265k | { |
237 | 265k | BIT_addBitsFast(bitC, 1, 1); /* endMark */ |
238 | 265k | BIT_flushBits(bitC); |
239 | 265k | if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */ |
240 | 259k | return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0); |
241 | 265k | } Unexecuted instantiation: zstd_common.c:BIT_closeCStream Unexecuted instantiation: zstd_compress.c:BIT_closeCStream Unexecuted instantiation: zstd_compress_literals.c:BIT_closeCStream zstd_compress_sequences.c:BIT_closeCStream Line | Count | Source | 236 | 103k | { | 237 | 103k | BIT_addBitsFast(bitC, 1, 1); /* endMark */ | 238 | 103k | BIT_flushBits(bitC); | 239 | 103k | if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */ | 240 | 97.2k | return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0); | 241 | 103k | } |
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: zstd_decompress.c:BIT_closeCStream Unexecuted instantiation: zstd_decompress_block.c:BIT_closeCStream Unexecuted instantiation: entropy_common.c:BIT_closeCStream Unexecuted instantiation: fse_decompress.c:BIT_closeCStream fse_compress.c:BIT_closeCStream Line | Count | Source | 236 | 161k | { | 237 | 161k | BIT_addBitsFast(bitC, 1, 1); /* endMark */ | 238 | 161k | BIT_flushBits(bitC); | 239 | 161k | if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */ | 240 | 161k | return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0); | 241 | 161k | } |
Unexecuted instantiation: huf_compress.c:BIT_closeCStream Unexecuted instantiation: huf_decompress.c:BIT_closeCStream Unexecuted instantiation: zstd_ddict.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 | 5.48k | { |
255 | 5.48k | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } |
256 | | |
257 | 5.48k | bitD->start = (const char*)srcBuffer; |
258 | 5.48k | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); |
259 | | |
260 | 5.48k | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ |
261 | 5.36k | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); |
262 | 5.36k | bitD->bitContainer = MEM_readLEST(bitD->ptr); |
263 | 5.36k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; |
264 | 5.36k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ |
265 | 5.36k | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } |
266 | 5.36k | } else { |
267 | 119 | bitD->ptr = bitD->start; |
268 | 119 | bitD->bitContainer = *(const BYTE*)(bitD->start); |
269 | 119 | switch(srcSize) |
270 | 119 | { |
271 | 31 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); |
272 | 31 | ZSTD_FALLTHROUGH; |
273 | | |
274 | 69 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); |
275 | 69 | ZSTD_FALLTHROUGH; |
276 | | |
277 | 108 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); |
278 | 108 | ZSTD_FALLTHROUGH; |
279 | | |
280 | 118 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; |
281 | 118 | ZSTD_FALLTHROUGH; |
282 | | |
283 | 119 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; |
284 | 119 | ZSTD_FALLTHROUGH; |
285 | | |
286 | 119 | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; |
287 | 119 | ZSTD_FALLTHROUGH; |
288 | | |
289 | 119 | default: break; |
290 | 119 | } |
291 | 119 | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; |
292 | 119 | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; |
293 | 119 | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ |
294 | 119 | } |
295 | 119 | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; |
296 | 119 | } |
297 | | |
298 | 5.48k | return srcSize; |
299 | 5.48k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_initDStream zstd_decompress_block.c:BIT_initDStream Line | Count | Source | 254 | 3.45k | { | 255 | 3.45k | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } | 256 | | | 257 | 3.45k | bitD->start = (const char*)srcBuffer; | 258 | 3.45k | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); | 259 | | | 260 | 3.45k | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ | 261 | 3.33k | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); | 262 | 3.33k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 263 | 3.33k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 264 | 3.33k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ | 265 | 3.33k | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } | 266 | 3.33k | } else { | 267 | 119 | bitD->ptr = bitD->start; | 268 | 119 | bitD->bitContainer = *(const BYTE*)(bitD->start); | 269 | 119 | switch(srcSize) | 270 | 119 | { | 271 | 31 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); | 272 | 31 | ZSTD_FALLTHROUGH; | 273 | | | 274 | 69 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); | 275 | 69 | ZSTD_FALLTHROUGH; | 276 | | | 277 | 108 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); | 278 | 108 | ZSTD_FALLTHROUGH; | 279 | | | 280 | 118 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; | 281 | 118 | ZSTD_FALLTHROUGH; | 282 | | | 283 | 119 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; | 284 | 119 | ZSTD_FALLTHROUGH; | 285 | | | 286 | 119 | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; | 287 | 119 | ZSTD_FALLTHROUGH; | 288 | | | 289 | 119 | default: break; | 290 | 119 | } | 291 | 119 | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 292 | 119 | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; | 293 | 119 | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ | 294 | 119 | } | 295 | 119 | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; | 296 | 119 | } | 297 | | | 298 | 3.45k | return srcSize; | 299 | 3.45k | } |
Unexecuted instantiation: entropy_common.c:BIT_initDStream fse_decompress.c:BIT_initDStream Line | Count | Source | 254 | 2.03k | { | 255 | 2.03k | if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } | 256 | | | 257 | 2.03k | bitD->start = (const char*)srcBuffer; | 258 | 2.03k | bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); | 259 | | | 260 | 2.03k | if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ | 261 | 2.03k | bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); | 262 | 2.03k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 263 | 2.03k | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 264 | 2.03k | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ | 265 | 2.03k | if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } | 266 | 2.03k | } else { | 267 | 0 | bitD->ptr = bitD->start; | 268 | 0 | bitD->bitContainer = *(const BYTE*)(bitD->start); | 269 | 0 | switch(srcSize) | 270 | 0 | { | 271 | 0 | case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); | 272 | 0 | ZSTD_FALLTHROUGH; | 273 | |
| 274 | 0 | case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); | 275 | 0 | ZSTD_FALLTHROUGH; | 276 | |
| 277 | 0 | case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); | 278 | 0 | ZSTD_FALLTHROUGH; | 279 | |
| 280 | 0 | case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24; | 281 | 0 | ZSTD_FALLTHROUGH; | 282 | |
| 283 | 0 | case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16; | 284 | 0 | ZSTD_FALLTHROUGH; | 285 | |
| 286 | 0 | case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8; | 287 | 0 | ZSTD_FALLTHROUGH; | 288 | |
| 289 | 0 | default: break; | 290 | 0 | } | 291 | 0 | { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; | 292 | 0 | bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; | 293 | 0 | if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ | 294 | 0 | } | 295 | 0 | bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; | 296 | 0 | } | 297 | | | 298 | 2.03k | return srcSize; | 299 | 2.03k | } |
Unexecuted instantiation: fse_compress.c:BIT_initDStream Unexecuted instantiation: huf_compress.c:BIT_initDStream Unexecuted instantiation: huf_decompress.c:BIT_initDStream Unexecuted instantiation: zstd_ddict.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: zstd_common.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: zstd_decompress.c:BIT_getUpperBits Unexecuted instantiation: zstd_decompress_block.c:BIT_getUpperBits Unexecuted instantiation: entropy_common.c:BIT_getUpperBits Unexecuted instantiation: fse_decompress.c:BIT_getUpperBits Unexecuted instantiation: fse_compress.c:BIT_getUpperBits Unexecuted instantiation: huf_compress.c:BIT_getUpperBits Unexecuted instantiation: huf_decompress.c:BIT_getUpperBits Unexecuted instantiation: zstd_ddict.c:BIT_getUpperBits |
305 | | |
306 | | FORCE_INLINE_TEMPLATE size_t BIT_getMiddleBits(BitContainerType bitContainer, U32 const start, U32 const nbBits) |
307 | 289k | { |
308 | 289k | U32 const regMask = sizeof(bitContainer)*8 - 1; |
309 | | /* if start > regMask, bitstream is corrupted, and result is undefined */ |
310 | 289k | 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 | 289k | #if defined(__x86_64__) || defined(_M_X86) |
317 | 289k | return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1); |
318 | | #else |
319 | | return (bitContainer >> (start & regMask)) & BIT_mask[nbBits]; |
320 | | #endif |
321 | 289k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_getMiddleBits zstd_decompress_block.c:BIT_getMiddleBits Line | Count | Source | 307 | 138k | { | 308 | 138k | U32 const regMask = sizeof(bitContainer)*8 - 1; | 309 | | /* if start > regMask, bitstream is corrupted, and result is undefined */ | 310 | 138k | 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 | 138k | #if defined(__x86_64__) || defined(_M_X86) | 317 | 138k | return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1); | 318 | | #else | 319 | | return (bitContainer >> (start & regMask)) & BIT_mask[nbBits]; | 320 | | #endif | 321 | 138k | } |
Unexecuted instantiation: entropy_common.c:BIT_getMiddleBits fse_decompress.c:BIT_getMiddleBits Line | Count | Source | 307 | 150k | { | 308 | 150k | U32 const regMask = sizeof(bitContainer)*8 - 1; | 309 | | /* if start > regMask, bitstream is corrupted, and result is undefined */ | 310 | 150k | 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 | 150k | #if defined(__x86_64__) || defined(_M_X86) | 317 | 150k | return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1); | 318 | | #else | 319 | | return (bitContainer >> (start & regMask)) & BIT_mask[nbBits]; | 320 | | #endif | 321 | 150k | } |
Unexecuted instantiation: fse_compress.c:BIT_getMiddleBits Unexecuted instantiation: huf_compress.c:BIT_getMiddleBits Unexecuted instantiation: huf_decompress.c:BIT_getMiddleBits Unexecuted instantiation: zstd_ddict.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 | 289k | { |
331 | | /* arbitrate between double-shift and shift+mask */ |
332 | 289k | #if 1 |
333 | | /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8, |
334 | | * bitstream is likely corrupted, and result is undefined */ |
335 | 289k | 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 | 289k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_lookBits zstd_decompress_block.c:BIT_lookBits Line | Count | Source | 330 | 138k | { | 331 | | /* arbitrate between double-shift and shift+mask */ | 332 | 138k | #if 1 | 333 | | /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8, | 334 | | * bitstream is likely corrupted, and result is undefined */ | 335 | 138k | 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 | 138k | } |
Unexecuted instantiation: entropy_common.c:BIT_lookBits fse_decompress.c:BIT_lookBits Line | Count | Source | 330 | 150k | { | 331 | | /* arbitrate between double-shift and shift+mask */ | 332 | 150k | #if 1 | 333 | | /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8, | 334 | | * bitstream is likely corrupted, and result is undefined */ | 335 | 150k | 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 | 150k | } |
Unexecuted instantiation: fse_compress.c:BIT_lookBits Unexecuted instantiation: huf_compress.c:BIT_lookBits Unexecuted instantiation: huf_decompress.c:BIT_lookBits Unexecuted instantiation: zstd_ddict.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 | 481k | { |
347 | 481k | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; |
348 | 481k | assert(nbBits >= 1); |
349 | 481k | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); |
350 | 481k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_lookBitsFast zstd_decompress_block.c:BIT_lookBitsFast Line | Count | Source | 346 | 66.3k | { | 347 | 66.3k | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 348 | 66.3k | assert(nbBits >= 1); | 349 | 66.3k | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); | 350 | 66.3k | } |
Unexecuted instantiation: entropy_common.c:BIT_lookBitsFast fse_decompress.c:BIT_lookBitsFast Line | Count | Source | 346 | 372k | { | 347 | 372k | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 348 | 372k | assert(nbBits >= 1); | 349 | 372k | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); | 350 | 372k | } |
Unexecuted instantiation: fse_compress.c:BIT_lookBitsFast Unexecuted instantiation: huf_compress.c:BIT_lookBitsFast huf_decompress.c:BIT_lookBitsFast Line | Count | Source | 346 | 42.4k | { | 347 | 42.4k | U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; | 348 | 42.4k | assert(nbBits >= 1); | 349 | 42.4k | return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); | 350 | 42.4k | } |
Unexecuted instantiation: zstd_ddict.c:BIT_lookBitsFast |
351 | | |
352 | | FORCE_INLINE_TEMPLATE void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits) |
353 | 770k | { |
354 | 770k | bitD->bitsConsumed += nbBits; |
355 | 770k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_skipBits zstd_decompress_block.c:BIT_skipBits Line | Count | Source | 353 | 205k | { | 354 | 205k | bitD->bitsConsumed += nbBits; | 355 | 205k | } |
Unexecuted instantiation: entropy_common.c:BIT_skipBits fse_decompress.c:BIT_skipBits Line | Count | Source | 353 | 522k | { | 354 | 522k | bitD->bitsConsumed += nbBits; | 355 | 522k | } |
Unexecuted instantiation: fse_compress.c:BIT_skipBits Unexecuted instantiation: huf_compress.c:BIT_skipBits huf_decompress.c:BIT_skipBits Line | Count | Source | 353 | 42.4k | { | 354 | 42.4k | bitD->bitsConsumed += nbBits; | 355 | 42.4k | } |
Unexecuted instantiation: zstd_ddict.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 | 289k | { |
363 | 289k | size_t const value = BIT_lookBits(bitD, nbBits); |
364 | 289k | BIT_skipBits(bitD, nbBits); |
365 | 289k | return value; |
366 | 289k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_readBits zstd_decompress_block.c:BIT_readBits Line | Count | Source | 362 | 138k | { | 363 | 138k | size_t const value = BIT_lookBits(bitD, nbBits); | 364 | 138k | BIT_skipBits(bitD, nbBits); | 365 | 138k | return value; | 366 | 138k | } |
Unexecuted instantiation: entropy_common.c:BIT_readBits fse_decompress.c:BIT_readBits Line | Count | Source | 362 | 150k | { | 363 | 150k | size_t const value = BIT_lookBits(bitD, nbBits); | 364 | 150k | BIT_skipBits(bitD, nbBits); | 365 | 150k | return value; | 366 | 150k | } |
Unexecuted instantiation: fse_compress.c:BIT_readBits Unexecuted instantiation: huf_compress.c:BIT_readBits Unexecuted instantiation: huf_decompress.c:BIT_readBits Unexecuted instantiation: zstd_ddict.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 | 438k | { |
372 | 438k | size_t const value = BIT_lookBitsFast(bitD, nbBits); |
373 | 438k | assert(nbBits >= 1); |
374 | 438k | BIT_skipBits(bitD, nbBits); |
375 | 438k | return value; |
376 | 438k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_readBitsFast zstd_decompress_block.c:BIT_readBitsFast Line | Count | Source | 371 | 66.3k | { | 372 | 66.3k | size_t const value = BIT_lookBitsFast(bitD, nbBits); | 373 | 66.3k | assert(nbBits >= 1); | 374 | 66.3k | BIT_skipBits(bitD, nbBits); | 375 | 66.3k | return value; | 376 | 66.3k | } |
Unexecuted instantiation: entropy_common.c:BIT_readBitsFast fse_decompress.c:BIT_readBitsFast Line | Count | Source | 371 | 372k | { | 372 | 372k | size_t const value = BIT_lookBitsFast(bitD, nbBits); | 373 | 372k | assert(nbBits >= 1); | 374 | 372k | BIT_skipBits(bitD, nbBits); | 375 | 372k | return value; | 376 | 372k | } |
Unexecuted instantiation: fse_compress.c:BIT_readBitsFast Unexecuted instantiation: huf_compress.c:BIT_readBitsFast Unexecuted instantiation: huf_decompress.c:BIT_readBitsFast Unexecuted instantiation: zstd_ddict.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 | 142k | { |
385 | 142k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); |
386 | 142k | bitD->ptr -= bitD->bitsConsumed >> 3; |
387 | 142k | assert(bitD->ptr >= bitD->start); |
388 | 142k | bitD->bitsConsumed &= 7; |
389 | 142k | bitD->bitContainer = MEM_readLEST(bitD->ptr); |
390 | 142k | return BIT_DStream_unfinished; |
391 | 142k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_reloadDStream_internal zstd_decompress_block.c:BIT_reloadDStream_internal Line | Count | Source | 384 | 34.2k | { | 385 | 34.2k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); | 386 | 34.2k | bitD->ptr -= bitD->bitsConsumed >> 3; | 387 | 34.2k | assert(bitD->ptr >= bitD->start); | 388 | 34.2k | bitD->bitsConsumed &= 7; | 389 | 34.2k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 390 | 34.2k | return BIT_DStream_unfinished; | 391 | 34.2k | } |
Unexecuted instantiation: entropy_common.c:BIT_reloadDStream_internal fse_decompress.c:BIT_reloadDStream_internal Line | Count | Source | 384 | 96.7k | { | 385 | 96.7k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); | 386 | 96.7k | bitD->ptr -= bitD->bitsConsumed >> 3; | 387 | 96.7k | assert(bitD->ptr >= bitD->start); | 388 | 96.7k | bitD->bitsConsumed &= 7; | 389 | 96.7k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 390 | 96.7k | return BIT_DStream_unfinished; | 391 | 96.7k | } |
Unexecuted instantiation: fse_compress.c:BIT_reloadDStream_internal Unexecuted instantiation: huf_compress.c:BIT_reloadDStream_internal huf_decompress.c:BIT_reloadDStream_internal Line | Count | Source | 384 | 11.6k | { | 385 | 11.6k | assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8); | 386 | 11.6k | bitD->ptr -= bitD->bitsConsumed >> 3; | 387 | 11.6k | assert(bitD->ptr >= bitD->start); | 388 | 11.6k | bitD->bitsConsumed &= 7; | 389 | 11.6k | bitD->bitContainer = MEM_readLEST(bitD->ptr); | 390 | 11.6k | return BIT_DStream_unfinished; | 391 | 11.6k | } |
Unexecuted instantiation: zstd_ddict.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 | 0 | { |
401 | 0 | if (UNLIKELY(bitD->ptr < bitD->limitPtr)) |
402 | 0 | return BIT_DStream_overflow; |
403 | 0 | return BIT_reloadDStream_internal(bitD); |
404 | 0 | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_decompress_block.c:BIT_reloadDStreamFast Unexecuted instantiation: entropy_common.c:BIT_reloadDStreamFast Unexecuted instantiation: fse_decompress.c:BIT_reloadDStreamFast Unexecuted instantiation: fse_compress.c:BIT_reloadDStreamFast Unexecuted instantiation: huf_compress.c:BIT_reloadDStreamFast Unexecuted instantiation: huf_decompress.c:BIT_reloadDStreamFast Unexecuted instantiation: zstd_ddict.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 | 260k | { |
413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ |
414 | 260k | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { |
415 | 2.03k | static const BitContainerType zeroFilled = 0; |
416 | 2.03k | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ |
417 | | /* overflow detected, erroneous scenario or end of stream: no update */ |
418 | 2.03k | return BIT_DStream_overflow; |
419 | 2.03k | } |
420 | | |
421 | 258k | assert(bitD->ptr >= bitD->start); |
422 | | |
423 | 258k | if (bitD->ptr >= bitD->limitPtr) { |
424 | 142k | return BIT_reloadDStream_internal(bitD); |
425 | 142k | } |
426 | 115k | if (bitD->ptr == bitD->start) { |
427 | | /* reached end of bitStream => no update */ |
428 | 84.1k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; |
429 | 2.90k | return BIT_DStream_completed; |
430 | 84.1k | } |
431 | | /* start < ptr < limitPtr => cautious update */ |
432 | 31.6k | { U32 nbBytes = bitD->bitsConsumed >> 3; |
433 | 31.6k | BIT_DStream_status result = BIT_DStream_unfinished; |
434 | 31.6k | if (bitD->ptr - nbBytes < bitD->start) { |
435 | 2.78k | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ |
436 | 2.78k | result = BIT_DStream_endOfBuffer; |
437 | 2.78k | } |
438 | 31.6k | bitD->ptr -= nbBytes; |
439 | 31.6k | bitD->bitsConsumed -= nbBytes*8; |
440 | 31.6k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ |
441 | 31.6k | return result; |
442 | 115k | } |
443 | 115k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_reloadDStream zstd_decompress_block.c:BIT_reloadDStream Line | Count | Source | 412 | 53.1k | { | 413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ | 414 | 53.1k | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { | 415 | 0 | static const BitContainerType zeroFilled = 0; | 416 | 0 | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ | 417 | | /* overflow detected, erroneous scenario or end of stream: no update */ | 418 | 0 | return BIT_DStream_overflow; | 419 | 0 | } | 420 | | | 421 | 53.1k | assert(bitD->ptr >= bitD->start); | 422 | | | 423 | 53.1k | if (bitD->ptr >= bitD->limitPtr) { | 424 | 34.2k | return BIT_reloadDStream_internal(bitD); | 425 | 34.2k | } | 426 | 18.9k | if (bitD->ptr == bitD->start) { | 427 | | /* reached end of bitStream => no update */ | 428 | 9.25k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; | 429 | 838 | return BIT_DStream_completed; | 430 | 9.25k | } | 431 | | /* start < ptr < limitPtr => cautious update */ | 432 | 9.69k | { U32 nbBytes = bitD->bitsConsumed >> 3; | 433 | 9.69k | BIT_DStream_status result = BIT_DStream_unfinished; | 434 | 9.69k | if (bitD->ptr - nbBytes < bitD->start) { | 435 | 1.74k | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ | 436 | 1.74k | result = BIT_DStream_endOfBuffer; | 437 | 1.74k | } | 438 | 9.69k | bitD->ptr -= nbBytes; | 439 | 9.69k | bitD->bitsConsumed -= nbBytes*8; | 440 | 9.69k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ | 441 | 9.69k | return result; | 442 | 18.9k | } | 443 | 18.9k | } |
Unexecuted instantiation: entropy_common.c:BIT_reloadDStream fse_decompress.c:BIT_reloadDStream Line | Count | Source | 412 | 191k | { | 413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ | 414 | 191k | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { | 415 | 2.03k | static const BitContainerType zeroFilled = 0; | 416 | 2.03k | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ | 417 | | /* overflow detected, erroneous scenario or end of stream: no update */ | 418 | 2.03k | return BIT_DStream_overflow; | 419 | 2.03k | } | 420 | | | 421 | 189k | assert(bitD->ptr >= bitD->start); | 422 | | | 423 | 189k | if (bitD->ptr >= bitD->limitPtr) { | 424 | 96.7k | return BIT_reloadDStream_internal(bitD); | 425 | 96.7k | } | 426 | 92.7k | if (bitD->ptr == bitD->start) { | 427 | | /* reached end of bitStream => no update */ | 428 | 74.8k | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; | 429 | 2.06k | return BIT_DStream_completed; | 430 | 74.8k | } | 431 | | /* start < ptr < limitPtr => cautious update */ | 432 | 17.8k | { U32 nbBytes = bitD->bitsConsumed >> 3; | 433 | 17.8k | BIT_DStream_status result = BIT_DStream_unfinished; | 434 | 17.8k | if (bitD->ptr - nbBytes < bitD->start) { | 435 | 33 | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ | 436 | 33 | result = BIT_DStream_endOfBuffer; | 437 | 33 | } | 438 | 17.8k | bitD->ptr -= nbBytes; | 439 | 17.8k | bitD->bitsConsumed -= nbBytes*8; | 440 | 17.8k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ | 441 | 17.8k | return result; | 442 | 92.7k | } | 443 | 92.7k | } |
Unexecuted instantiation: fse_compress.c:BIT_reloadDStream Unexecuted instantiation: huf_compress.c:BIT_reloadDStream huf_decompress.c:BIT_reloadDStream Line | Count | Source | 412 | 15.7k | { | 413 | | /* note : once in overflow mode, a bitstream remains in this mode until it's reset */ | 414 | 15.7k | if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) { | 415 | 0 | static const BitContainerType zeroFilled = 0; | 416 | 0 | bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */ | 417 | | /* overflow detected, erroneous scenario or end of stream: no update */ | 418 | 0 | return BIT_DStream_overflow; | 419 | 0 | } | 420 | | | 421 | 15.7k | assert(bitD->ptr >= bitD->start); | 422 | | | 423 | 15.7k | if (bitD->ptr >= bitD->limitPtr) { | 424 | 11.6k | return BIT_reloadDStream_internal(bitD); | 425 | 11.6k | } | 426 | 4.17k | if (bitD->ptr == bitD->start) { | 427 | | /* reached end of bitStream => no update */ | 428 | 0 | if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; | 429 | 0 | return BIT_DStream_completed; | 430 | 0 | } | 431 | | /* start < ptr < limitPtr => cautious update */ | 432 | 4.17k | { U32 nbBytes = bitD->bitsConsumed >> 3; | 433 | 4.17k | BIT_DStream_status result = BIT_DStream_unfinished; | 434 | 4.17k | if (bitD->ptr - nbBytes < bitD->start) { | 435 | 1.00k | nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ | 436 | 1.00k | result = BIT_DStream_endOfBuffer; | 437 | 1.00k | } | 438 | 4.17k | bitD->ptr -= nbBytes; | 439 | 4.17k | bitD->bitsConsumed -= nbBytes*8; | 440 | 4.17k | bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ | 441 | 4.17k | return result; | 442 | 4.17k | } | 443 | 4.17k | } |
Unexecuted instantiation: zstd_ddict.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 | 3.45k | { |
450 | 3.45k | return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); |
451 | 3.45k | } Unexecuted instantiation: zstd_common.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: zstd_decompress.c:BIT_endOfDStream zstd_decompress_block.c:BIT_endOfDStream Line | Count | Source | 449 | 3.45k | { | 450 | 3.45k | return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); | 451 | 3.45k | } |
Unexecuted instantiation: entropy_common.c:BIT_endOfDStream Unexecuted instantiation: fse_decompress.c:BIT_endOfDStream Unexecuted instantiation: fse_compress.c:BIT_endOfDStream Unexecuted instantiation: huf_compress.c:BIT_endOfDStream Unexecuted instantiation: huf_decompress.c:BIT_endOfDStream Unexecuted instantiation: zstd_ddict.c:BIT_endOfDStream |
452 | | |
453 | | #if defined (__cplusplus) |
454 | | } |
455 | | #endif |
456 | | |
457 | | #endif /* BITSTREAM_H_MODULE */ |