Coverage Report

Created: 2026-04-12 06:36

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