Coverage Report

Created: 2026-07-10 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/c-blosc2/_deps/zstd-src/lib/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
/*
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
710k
{
153
710k
    bitC->bitContainer = 0;
154
710k
    bitC->bitPos = 0;
155
710k
    bitC->startPtr = (char*)startPtr;
156
710k
    bitC->ptr = bitC->startPtr;
157
710k
    bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
158
710k
    if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
159
704k
    return 0;
160
710k
}
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
152
290k
{
153
290k
    bitC->bitContainer = 0;
154
290k
    bitC->bitPos = 0;
155
290k
    bitC->startPtr = (char*)startPtr;
156
290k
    bitC->ptr = bitC->startPtr;
157
290k
    bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
158
290k
    if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
159
285k
    return 0;
160
290k
}
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: zstd_ddict.c:BIT_initCStream
Unexecuted instantiation: zstd_decompress.c:BIT_initCStream
Unexecuted instantiation: zstd_decompress_block.c:BIT_initCStream
Unexecuted instantiation: zdict.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
152
419k
{
153
419k
    bitC->bitContainer = 0;
154
419k
    bitC->bitPos = 0;
155
419k
    bitC->startPtr = (char*)startPtr;
156
419k
    bitC->ptr = bitC->startPtr;
157
419k
    bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
158
419k
    if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
159
419k
    return 0;
160
419k
}
Unexecuted instantiation: huf_compress.c:BIT_initCStream
Unexecuted instantiation: huf_decompress.c:BIT_initCStream
Unexecuted instantiation: fastcover.c:BIT_initCStream
Unexecuted instantiation: cover.c:BIT_initCStream
161
162
FORCE_INLINE_TEMPLATE BitContainerType BIT_getLowerBits(BitContainerType bitContainer, U32 const nbBits)
163
333M
{
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
333M
    assert(nbBits < BIT_MASK_SIZE);
173
333M
    return bitContainer & BIT_mask[nbBits];
174
333M
#endif
175
333M
}
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
163
230M
{
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
230M
    assert(nbBits < BIT_MASK_SIZE);
173
230M
    return bitContainer & BIT_mask[nbBits];
174
230M
#endif
175
230M
}
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: zstd_ddict.c:BIT_getLowerBits
Unexecuted instantiation: zstd_decompress.c:BIT_getLowerBits
Unexecuted instantiation: zstd_decompress_block.c:BIT_getLowerBits
Unexecuted instantiation: zdict.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
163
102M
{
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
102M
    assert(nbBits < BIT_MASK_SIZE);
173
102M
    return bitContainer & BIT_mask[nbBits];
174
102M
#endif
175
102M
}
Unexecuted instantiation: huf_compress.c:BIT_getLowerBits
Unexecuted instantiation: huf_decompress.c:BIT_getLowerBits
Unexecuted instantiation: fastcover.c:BIT_getLowerBits
Unexecuted instantiation: cover.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
333M
{
183
333M
    DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
184
333M
    assert(nbBits < BIT_MASK_SIZE);
185
333M
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
186
333M
    bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
187
333M
    bitC->bitPos += nbBits;
188
333M
}
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
182
230M
{
183
230M
    DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
184
230M
    assert(nbBits < BIT_MASK_SIZE);
185
230M
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
186
230M
    bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
187
230M
    bitC->bitPos += nbBits;
188
230M
}
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: zstd_ddict.c:BIT_addBits
Unexecuted instantiation: zstd_decompress.c:BIT_addBits
Unexecuted instantiation: zstd_decompress_block.c:BIT_addBits
Unexecuted instantiation: zdict.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
182
102M
{
183
102M
    DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
184
102M
    assert(nbBits < BIT_MASK_SIZE);
185
102M
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
186
102M
    bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
187
102M
    bitC->bitPos += nbBits;
188
102M
}
Unexecuted instantiation: huf_compress.c:BIT_addBits
Unexecuted instantiation: huf_decompress.c:BIT_addBits
Unexecuted instantiation: fastcover.c:BIT_addBits
Unexecuted instantiation: cover.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
704k
{
196
704k
    assert((value>>nbBits) == 0);
197
704k
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
198
704k
    bitC->bitContainer |= value << bitC->bitPos;
199
704k
    bitC->bitPos += nbBits;
200
704k
}
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
195
285k
{
196
285k
    assert((value>>nbBits) == 0);
197
285k
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
198
285k
    bitC->bitContainer |= value << bitC->bitPos;
199
285k
    bitC->bitPos += nbBits;
200
285k
}
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: zstd_ddict.c:BIT_addBitsFast
Unexecuted instantiation: zstd_decompress.c:BIT_addBitsFast
Unexecuted instantiation: zstd_decompress_block.c:BIT_addBitsFast
Unexecuted instantiation: zdict.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
195
419k
{
196
419k
    assert((value>>nbBits) == 0);
197
419k
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
198
419k
    bitC->bitContainer |= value << bitC->bitPos;
199
419k
    bitC->bitPos += nbBits;
200
419k
}
Unexecuted instantiation: huf_compress.c:BIT_addBitsFast
Unexecuted instantiation: huf_decompress.c:BIT_addBitsFast
Unexecuted instantiation: fastcover.c:BIT_addBitsFast
Unexecuted instantiation: cover.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
25.7M
{
207
25.7M
    size_t const nbBytes = bitC->bitPos >> 3;
208
25.7M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
209
25.7M
    assert(bitC->ptr <= bitC->endPtr);
210
25.7M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
211
25.7M
    bitC->ptr += nbBytes;
212
25.7M
    bitC->bitPos &= 7;
213
25.7M
    bitC->bitContainer >>= nbBytes*8;
214
25.7M
}
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_preSplit.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: zdict.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
206
25.7M
{
207
25.7M
    size_t const nbBytes = bitC->bitPos >> 3;
208
25.7M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
209
25.7M
    assert(bitC->ptr <= bitC->endPtr);
210
25.7M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
211
25.7M
    bitC->ptr += nbBytes;
212
25.7M
    bitC->bitPos &= 7;
213
25.7M
    bitC->bitContainer >>= nbBytes*8;
214
25.7M
}
Unexecuted instantiation: huf_compress.c:BIT_flushBitsFast
Unexecuted instantiation: huf_decompress.c:BIT_flushBitsFast
Unexecuted instantiation: fastcover.c:BIT_flushBitsFast
Unexecuted instantiation: cover.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
40.8M
{
223
40.8M
    size_t const nbBytes = bitC->bitPos >> 3;
224
40.8M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
40.8M
    assert(bitC->ptr <= bitC->endPtr);
226
40.8M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
227
40.8M
    bitC->ptr += nbBytes;
228
40.8M
    if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
229
40.8M
    bitC->bitPos &= 7;
230
40.8M
    bitC->bitContainer >>= nbBytes*8;
231
40.8M
}
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
222
39.5M
{
223
39.5M
    size_t const nbBytes = bitC->bitPos >> 3;
224
39.5M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
39.5M
    assert(bitC->ptr <= bitC->endPtr);
226
39.5M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
227
39.5M
    bitC->ptr += nbBytes;
228
39.5M
    if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
229
39.5M
    bitC->bitPos &= 7;
230
39.5M
    bitC->bitContainer >>= nbBytes*8;
231
39.5M
}
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: zstd_ddict.c:BIT_flushBits
Unexecuted instantiation: zstd_decompress.c:BIT_flushBits
Unexecuted instantiation: zstd_decompress_block.c:BIT_flushBits
Unexecuted instantiation: zdict.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
222
1.33M
{
223
1.33M
    size_t const nbBytes = bitC->bitPos >> 3;
224
1.33M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
1.33M
    assert(bitC->ptr <= bitC->endPtr);
226
1.33M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
227
1.33M
    bitC->ptr += nbBytes;
228
1.33M
    if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
229
1.33M
    bitC->bitPos &= 7;
230
1.33M
    bitC->bitContainer >>= nbBytes*8;
231
1.33M
}
Unexecuted instantiation: huf_compress.c:BIT_flushBits
Unexecuted instantiation: huf_decompress.c:BIT_flushBits
Unexecuted instantiation: fastcover.c:BIT_flushBits
Unexecuted instantiation: cover.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
704k
{
238
704k
    BIT_addBitsFast(bitC, 1, 1);   /* endMark */
239
704k
    BIT_flushBits(bitC);
240
704k
    if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
241
692k
    return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
242
704k
}
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
237
285k
{
238
285k
    BIT_addBitsFast(bitC, 1, 1);   /* endMark */
239
285k
    BIT_flushBits(bitC);
240
285k
    if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
241
273k
    return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
242
285k
}
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: zstd_ddict.c:BIT_closeCStream
Unexecuted instantiation: zstd_decompress.c:BIT_closeCStream
Unexecuted instantiation: zstd_decompress_block.c:BIT_closeCStream
Unexecuted instantiation: zdict.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
237
419k
{
238
419k
    BIT_addBitsFast(bitC, 1, 1);   /* endMark */
239
419k
    BIT_flushBits(bitC);
240
419k
    if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
241
419k
    return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
242
419k
}
Unexecuted instantiation: huf_compress.c:BIT_closeCStream
Unexecuted instantiation: huf_decompress.c:BIT_closeCStream
Unexecuted instantiation: fastcover.c:BIT_closeCStream
Unexecuted instantiation: cover.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
35.2k
{
256
35.2k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
35.1k
    bitD->start = (const char*)srcBuffer;
259
35.1k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
35.1k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
29.0k
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
29.0k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
29.0k
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
29.0k
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
29.0k
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
29.0k
    } else {
268
6.11k
        bitD->ptr   = bitD->start;
269
6.11k
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
6.11k
        switch(srcSize)
271
6.11k
        {
272
376
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
376
                ZSTD_FALLTHROUGH;
274
275
728
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
728
                ZSTD_FALLTHROUGH;
277
278
1.59k
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
1.59k
                ZSTD_FALLTHROUGH;
280
281
2.30k
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
2.30k
                ZSTD_FALLTHROUGH;
283
284
3.59k
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
3.59k
                ZSTD_FALLTHROUGH;
286
287
4.43k
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
4.43k
                ZSTD_FALLTHROUGH;
289
290
6.11k
        default: break;
291
6.11k
        }
292
6.11k
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
6.11k
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
6.11k
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
6.11k
        }
296
6.06k
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
6.06k
    }
298
299
34.8k
    return srcSize;
300
35.1k
}
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_preSplit.c:BIT_initDStream
Unexecuted instantiation: zstd_ddict.c:BIT_initDStream
Unexecuted instantiation: zstd_decompress.c:BIT_initDStream
zstd_decompress_block.c:BIT_initDStream
Line
Count
Source
255
16.2k
{
256
16.2k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
16.2k
    bitD->start = (const char*)srcBuffer;
259
16.2k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
16.2k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
13.3k
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
13.3k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
13.3k
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
13.3k
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
13.3k
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
13.3k
    } else {
268
2.90k
        bitD->ptr   = bitD->start;
269
2.90k
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
2.90k
        switch(srcSize)
271
2.90k
        {
272
162
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
162
                ZSTD_FALLTHROUGH;
274
275
322
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
322
                ZSTD_FALLTHROUGH;
277
278
972
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
972
                ZSTD_FALLTHROUGH;
280
281
1.50k
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
1.50k
                ZSTD_FALLTHROUGH;
283
284
1.79k
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
1.79k
                ZSTD_FALLTHROUGH;
286
287
2.37k
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
2.37k
                ZSTD_FALLTHROUGH;
289
290
2.90k
        default: break;
291
2.90k
        }
292
2.90k
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
2.90k
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
2.90k
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
2.90k
        }
296
2.89k
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
2.89k
    }
298
299
16.0k
    return srcSize;
300
16.2k
}
Unexecuted instantiation: zdict.c:BIT_initDStream
Unexecuted instantiation: entropy_common.c:BIT_initDStream
fse_decompress.c:BIT_initDStream
Line
Count
Source
255
14.7k
{
256
14.7k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
14.6k
    bitD->start = (const char*)srcBuffer;
259
14.6k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
14.6k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
13.8k
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
13.8k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
13.8k
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
13.8k
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
13.8k
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
13.8k
    } else {
268
859
        bitD->ptr   = bitD->start;
269
859
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
859
        switch(srcSize)
271
859
        {
272
172
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
172
                ZSTD_FALLTHROUGH;
274
275
301
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
301
                ZSTD_FALLTHROUGH;
277
278
421
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
421
                ZSTD_FALLTHROUGH;
280
281
540
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
540
                ZSTD_FALLTHROUGH;
283
284
673
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
673
                ZSTD_FALLTHROUGH;
286
287
837
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
837
                ZSTD_FALLTHROUGH;
289
290
859
        default: break;
291
859
        }
292
859
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
859
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
859
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
859
        }
296
847
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
847
    }
298
299
14.5k
    return srcSize;
300
14.6k
}
Unexecuted instantiation: fse_compress.c:BIT_initDStream
Unexecuted instantiation: huf_compress.c:BIT_initDStream
huf_decompress.c:BIT_initDStream
Line
Count
Source
255
4.22k
{
256
4.22k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
4.20k
    bitD->start = (const char*)srcBuffer;
259
4.20k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
4.20k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
1.85k
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
1.85k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
1.85k
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
1.85k
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
1.85k
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
2.35k
    } else {
268
2.35k
        bitD->ptr   = bitD->start;
269
2.35k
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
2.35k
        switch(srcSize)
271
2.35k
        {
272
42
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
42
                ZSTD_FALLTHROUGH;
274
275
105
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
105
                ZSTD_FALLTHROUGH;
277
278
200
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
200
                ZSTD_FALLTHROUGH;
280
281
266
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
266
                ZSTD_FALLTHROUGH;
283
284
1.12k
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
1.12k
                ZSTD_FALLTHROUGH;
286
287
1.22k
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
1.22k
                ZSTD_FALLTHROUGH;
289
290
2.35k
        default: break;
291
2.35k
        }
292
2.35k
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
2.35k
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
2.35k
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
2.35k
        }
296
2.32k
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
2.32k
    }
298
299
4.15k
    return srcSize;
300
4.20k
}
Unexecuted instantiation: fastcover.c:BIT_initDStream
Unexecuted instantiation: cover.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: 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_preSplit.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: zdict.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: fastcover.c:BIT_getUpperBits
Unexecuted instantiation: cover.c:BIT_getUpperBits
306
307
FORCE_INLINE_TEMPLATE BitContainerType BIT_getMiddleBits(BitContainerType bitContainer, U32 const start, U32 const nbBits)
308
20.9M
{
309
20.9M
    U32 const regMask = sizeof(bitContainer)*8 - 1;
310
    /* if start > regMask, bitstream is corrupted, and result is undefined */
311
20.9M
    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
20.9M
#if defined(__x86_64__) || defined(_M_X64)
318
20.9M
    return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
319
#else
320
    return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
321
#endif
322
20.9M
}
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_preSplit.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
20.2M
{
309
20.2M
    U32 const regMask = sizeof(bitContainer)*8 - 1;
310
    /* if start > regMask, bitstream is corrupted, and result is undefined */
311
20.2M
    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
20.2M
#if defined(__x86_64__) || defined(_M_X64)
318
20.2M
    return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
319
#else
320
    return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
321
#endif
322
20.2M
}
Unexecuted instantiation: zdict.c:BIT_getMiddleBits
Unexecuted instantiation: entropy_common.c:BIT_getMiddleBits
fse_decompress.c:BIT_getMiddleBits
Line
Count
Source
308
766k
{
309
766k
    U32 const regMask = sizeof(bitContainer)*8 - 1;
310
    /* if start > regMask, bitstream is corrupted, and result is undefined */
311
766k
    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
766k
#if defined(__x86_64__) || defined(_M_X64)
318
766k
    return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
319
#else
320
    return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
321
#endif
322
766k
}
Unexecuted instantiation: fse_compress.c:BIT_getMiddleBits
Unexecuted instantiation: huf_compress.c:BIT_getMiddleBits
Unexecuted instantiation: huf_decompress.c:BIT_getMiddleBits
Unexecuted instantiation: fastcover.c:BIT_getMiddleBits
Unexecuted instantiation: cover.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
20.9M
{
332
    /* arbitrate between double-shift and shift+mask */
333
20.9M
#if 1
334
    /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
335
     * bitstream is likely corrupted, and result is undefined */
336
20.9M
    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
20.9M
}
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_preSplit.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
20.2M
{
332
    /* arbitrate between double-shift and shift+mask */
333
20.2M
#if 1
334
    /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
335
     * bitstream is likely corrupted, and result is undefined */
336
20.2M
    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
20.2M
}
Unexecuted instantiation: zdict.c:BIT_lookBits
Unexecuted instantiation: entropy_common.c:BIT_lookBits
fse_decompress.c:BIT_lookBits
Line
Count
Source
331
766k
{
332
    /* arbitrate between double-shift and shift+mask */
333
766k
#if 1
334
    /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
335
     * bitstream is likely corrupted, and result is undefined */
336
766k
    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
766k
}
Unexecuted instantiation: fse_compress.c:BIT_lookBits
Unexecuted instantiation: huf_compress.c:BIT_lookBits
Unexecuted instantiation: huf_decompress.c:BIT_lookBits
Unexecuted instantiation: fastcover.c:BIT_lookBits
Unexecuted instantiation: cover.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
13.2M
{
348
13.2M
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
13.2M
    assert(nbBits >= 1);
350
13.2M
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
13.2M
}
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_preSplit.c:BIT_lookBitsFast
Unexecuted instantiation: zstd_ddict.c:BIT_lookBitsFast
Unexecuted instantiation: zstd_decompress.c:BIT_lookBitsFast
zstd_decompress_block.c:BIT_lookBitsFast
Line
Count
Source
347
6.02M
{
348
6.02M
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
6.02M
    assert(nbBits >= 1);
350
6.02M
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
6.02M
}
Unexecuted instantiation: zdict.c:BIT_lookBitsFast
Unexecuted instantiation: entropy_common.c:BIT_lookBitsFast
fse_decompress.c:BIT_lookBitsFast
Line
Count
Source
347
2.05M
{
348
2.05M
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
2.05M
    assert(nbBits >= 1);
350
2.05M
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
2.05M
}
Unexecuted instantiation: fse_compress.c:BIT_lookBitsFast
Unexecuted instantiation: huf_compress.c:BIT_lookBitsFast
huf_decompress.c:BIT_lookBitsFast
Line
Count
Source
347
5.15M
{
348
5.15M
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
5.15M
    assert(nbBits >= 1);
350
5.15M
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
5.15M
}
Unexecuted instantiation: fastcover.c:BIT_lookBitsFast
Unexecuted instantiation: cover.c:BIT_lookBitsFast
352
353
FORCE_INLINE_TEMPLATE void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
354
34.1M
{
355
34.1M
    bitD->bitsConsumed += nbBits;
356
34.1M
}
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_preSplit.c:BIT_skipBits
Unexecuted instantiation: zstd_ddict.c:BIT_skipBits
Unexecuted instantiation: zstd_decompress.c:BIT_skipBits
zstd_decompress_block.c:BIT_skipBits
Line
Count
Source
354
26.2M
{
355
26.2M
    bitD->bitsConsumed += nbBits;
356
26.2M
}
Unexecuted instantiation: zdict.c:BIT_skipBits
Unexecuted instantiation: entropy_common.c:BIT_skipBits
fse_decompress.c:BIT_skipBits
Line
Count
Source
354
2.81M
{
355
2.81M
    bitD->bitsConsumed += nbBits;
356
2.81M
}
Unexecuted instantiation: fse_compress.c:BIT_skipBits
Unexecuted instantiation: huf_compress.c:BIT_skipBits
huf_decompress.c:BIT_skipBits
Line
Count
Source
354
5.15M
{
355
5.15M
    bitD->bitsConsumed += nbBits;
356
5.15M
}
Unexecuted instantiation: fastcover.c:BIT_skipBits
Unexecuted instantiation: cover.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
20.9M
{
364
20.9M
    BitContainerType const value = BIT_lookBits(bitD, nbBits);
365
20.9M
    BIT_skipBits(bitD, nbBits);
366
20.9M
    return value;
367
20.9M
}
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_preSplit.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
20.2M
{
364
20.2M
    BitContainerType const value = BIT_lookBits(bitD, nbBits);
365
20.2M
    BIT_skipBits(bitD, nbBits);
366
20.2M
    return value;
367
20.2M
}
Unexecuted instantiation: zdict.c:BIT_readBits
Unexecuted instantiation: entropy_common.c:BIT_readBits
fse_decompress.c:BIT_readBits
Line
Count
Source
363
766k
{
364
766k
    BitContainerType const value = BIT_lookBits(bitD, nbBits);
365
766k
    BIT_skipBits(bitD, nbBits);
366
766k
    return value;
367
766k
}
Unexecuted instantiation: fse_compress.c:BIT_readBits
Unexecuted instantiation: huf_compress.c:BIT_readBits
Unexecuted instantiation: huf_decompress.c:BIT_readBits
Unexecuted instantiation: fastcover.c:BIT_readBits
Unexecuted instantiation: cover.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
8.07M
{
373
8.07M
    BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
374
8.07M
    assert(nbBits >= 1);
375
8.07M
    BIT_skipBits(bitD, nbBits);
376
8.07M
    return value;
377
8.07M
}
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_preSplit.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
6.02M
{
373
6.02M
    BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
374
6.02M
    assert(nbBits >= 1);
375
6.02M
    BIT_skipBits(bitD, nbBits);
376
6.02M
    return value;
377
6.02M
}
Unexecuted instantiation: zdict.c:BIT_readBitsFast
Unexecuted instantiation: entropy_common.c:BIT_readBitsFast
fse_decompress.c:BIT_readBitsFast
Line
Count
Source
372
2.05M
{
373
2.05M
    BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
374
2.05M
    assert(nbBits >= 1);
375
2.05M
    BIT_skipBits(bitD, nbBits);
376
2.05M
    return value;
377
2.05M
}
Unexecuted instantiation: fse_compress.c:BIT_readBitsFast
Unexecuted instantiation: huf_compress.c:BIT_readBitsFast
Unexecuted instantiation: huf_decompress.c:BIT_readBitsFast
Unexecuted instantiation: fastcover.c:BIT_readBitsFast
Unexecuted instantiation: cover.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
6.64M
{
386
6.64M
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
6.64M
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
6.64M
    assert(bitD->ptr >= bitD->start);
389
6.64M
    bitD->bitsConsumed &= 7;
390
6.64M
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
6.64M
    return BIT_DStream_unfinished;
392
6.64M
}
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_preSplit.c:BIT_reloadDStream_internal
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
5.63M
{
386
5.63M
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
5.63M
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
5.63M
    assert(bitD->ptr >= bitD->start);
389
5.63M
    bitD->bitsConsumed &= 7;
390
5.63M
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
5.63M
    return BIT_DStream_unfinished;
392
5.63M
}
Unexecuted instantiation: zdict.c:BIT_reloadDStream_internal
Unexecuted instantiation: entropy_common.c:BIT_reloadDStream_internal
fse_decompress.c:BIT_reloadDStream_internal
Line
Count
Source
385
447k
{
386
447k
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
447k
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
447k
    assert(bitD->ptr >= bitD->start);
389
447k
    bitD->bitsConsumed &= 7;
390
447k
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
447k
    return BIT_DStream_unfinished;
392
447k
}
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
385
560k
{
386
560k
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
560k
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
560k
    assert(bitD->ptr >= bitD->start);
389
560k
    bitD->bitsConsumed &= 7;
390
560k
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
560k
    return BIT_DStream_unfinished;
392
560k
}
Unexecuted instantiation: fastcover.c:BIT_reloadDStream_internal
Unexecuted instantiation: cover.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
128k
{
402
128k
    if (UNLIKELY(bitD->ptr < bitD->limitPtr))
403
742
        return BIT_DStream_overflow;
404
127k
    return BIT_reloadDStream_internal(bitD);
405
128k
}
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_preSplit.c:BIT_reloadDStreamFast
Unexecuted instantiation: zstd_ddict.c:BIT_reloadDStreamFast
Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStreamFast
Unexecuted instantiation: zstd_decompress_block.c:BIT_reloadDStreamFast
Unexecuted instantiation: zdict.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
huf_decompress.c:BIT_reloadDStreamFast
Line
Count
Source
401
128k
{
402
128k
    if (UNLIKELY(bitD->ptr < bitD->limitPtr))
403
742
        return BIT_DStream_overflow;
404
127k
    return BIT_reloadDStream_internal(bitD);
405
128k
}
Unexecuted instantiation: fastcover.c:BIT_reloadDStreamFast
Unexecuted instantiation: cover.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
8.45M
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
8.45M
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
1.06M
        static const BitContainerType zeroFilled = 0;
417
1.06M
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
1.06M
        return BIT_DStream_overflow;
420
1.06M
    }
421
422
7.38M
    assert(bitD->ptr >= bitD->start);
423
424
7.38M
    if (bitD->ptr >= bitD->limitPtr) {
425
6.51M
        return BIT_reloadDStream_internal(bitD);
426
6.51M
    }
427
872k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
667k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
17.5k
        return BIT_DStream_completed;
431
667k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
204k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
204k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
204k
        if (bitD->ptr - nbBytes < bitD->start) {
436
12.8k
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
12.8k
            result = BIT_DStream_endOfBuffer;
438
12.8k
        }
439
204k
        bitD->ptr -= nbBytes;
440
204k
        bitD->bitsConsumed -= nbBytes*8;
441
204k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
204k
        return result;
443
872k
    }
444
872k
}
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_preSplit.c:BIT_reloadDStream
Unexecuted instantiation: zstd_ddict.c:BIT_reloadDStream
Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStream
zstd_decompress_block.c:BIT_reloadDStream
Line
Count
Source
413
6.76M
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
6.76M
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
1.05M
        static const BitContainerType zeroFilled = 0;
417
1.05M
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
1.05M
        return BIT_DStream_overflow;
420
1.05M
    }
421
422
5.71M
    assert(bitD->ptr >= bitD->start);
423
424
5.71M
    if (bitD->ptr >= bitD->limitPtr) {
425
5.63M
        return BIT_reloadDStream_internal(bitD);
426
5.63M
    }
427
81.8k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
43.7k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
866
        return BIT_DStream_completed;
431
43.7k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
38.0k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
38.0k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
38.0k
        if (bitD->ptr - nbBytes < bitD->start) {
436
5.55k
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
5.55k
            result = BIT_DStream_endOfBuffer;
438
5.55k
        }
439
38.0k
        bitD->ptr -= nbBytes;
440
38.0k
        bitD->bitsConsumed -= nbBytes*8;
441
38.0k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
38.0k
        return result;
443
81.8k
    }
444
81.8k
}
Unexecuted instantiation: zdict.c:BIT_reloadDStream
Unexecuted instantiation: entropy_common.c:BIT_reloadDStream
fse_decompress.c:BIT_reloadDStream
Line
Count
Source
413
1.21M
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
1.21M
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
14.5k
        static const BitContainerType zeroFilled = 0;
417
14.5k
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
14.5k
        return BIT_DStream_overflow;
420
14.5k
    }
421
422
1.20M
    assert(bitD->ptr >= bitD->start);
423
424
1.20M
    if (bitD->ptr >= bitD->limitPtr) {
425
447k
        return BIT_reloadDStream_internal(bitD);
426
447k
    }
427
752k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
619k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
15.7k
        return BIT_DStream_completed;
431
619k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
133k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
133k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
133k
        if (bitD->ptr - nbBytes < bitD->start) {
436
633
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
633
            result = BIT_DStream_endOfBuffer;
438
633
        }
439
133k
        bitD->ptr -= nbBytes;
440
133k
        bitD->bitsConsumed -= nbBytes*8;
441
133k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
133k
        return result;
443
752k
    }
444
752k
}
Unexecuted instantiation: fse_compress.c:BIT_reloadDStream
Unexecuted instantiation: huf_compress.c:BIT_reloadDStream
huf_decompress.c:BIT_reloadDStream
Line
Count
Source
413
470k
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
470k
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
280
        static const BitContainerType zeroFilled = 0;
417
280
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
280
        return BIT_DStream_overflow;
420
280
    }
421
422
470k
    assert(bitD->ptr >= bitD->start);
423
424
470k
    if (bitD->ptr >= bitD->limitPtr) {
425
432k
        return BIT_reloadDStream_internal(bitD);
426
432k
    }
427
37.6k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
4.60k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
921
        return BIT_DStream_completed;
431
4.60k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
33.0k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
33.0k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
33.0k
        if (bitD->ptr - nbBytes < bitD->start) {
436
6.64k
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
6.64k
            result = BIT_DStream_endOfBuffer;
438
6.64k
        }
439
33.0k
        bitD->ptr -= nbBytes;
440
33.0k
        bitD->bitsConsumed -= nbBytes*8;
441
33.0k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
33.0k
        return result;
443
37.6k
    }
444
37.6k
}
Unexecuted instantiation: fastcover.c:BIT_reloadDStream
Unexecuted instantiation: cover.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
17.7k
{
451
17.7k
    return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
452
17.7k
}
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_preSplit.c:BIT_endOfDStream
Unexecuted instantiation: zstd_ddict.c:BIT_endOfDStream
Unexecuted instantiation: zstd_decompress.c:BIT_endOfDStream
zstd_decompress_block.c:BIT_endOfDStream
Line
Count
Source
450
13.7k
{
451
13.7k
    return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
452
13.7k
}
Unexecuted instantiation: zdict.c:BIT_endOfDStream
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
huf_decompress.c:BIT_endOfDStream
Line
Count
Source
450
4.07k
{
451
4.07k
    return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
452
4.07k
}
Unexecuted instantiation: fastcover.c:BIT_endOfDStream
Unexecuted instantiation: cover.c:BIT_endOfDStream
453
454
#endif /* BITSTREAM_H_MODULE */