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