Coverage Report

Created: 2025-07-23 08:18

/src/zstd/lib/common/bitstream.h
Line
Count
Source (jump to first uncovered line)
1
/* ******************************************************************
2
 * bitstream
3
 * Part of FSE library
4
 * Copyright (c) Meta Platforms, Inc. and affiliates.
5
 *
6
 * You can contact the author at :
7
 * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8
 *
9
 * This source code is licensed under both the BSD-style license (found in the
10
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
 * in the COPYING file in the root directory of this source tree).
12
 * You may select, at your option, one of the above-listed licenses.
13
****************************************************************** */
14
#ifndef BITSTREAM_H_MODULE
15
#define BITSTREAM_H_MODULE
16
17
/*
18
*  This API consists of small unitary functions, which must be inlined for best performance.
19
*  Since link-time-optimization is not available for all compilers,
20
*  these functions are defined into a .h to be included.
21
*/
22
23
/*-****************************************
24
*  Dependencies
25
******************************************/
26
#include "mem.h"            /* unaligned access routines */
27
#include "compiler.h"       /* UNLIKELY() */
28
#include "debug.h"          /* assert(), DEBUGLOG(), RAWLOG() */
29
#include "error_private.h"  /* error codes and messages */
30
#include "bits.h"           /* ZSTD_highbit32 */
31
32
/*=========================================
33
*  Target specific
34
=========================================*/
35
#ifndef ZSTD_NO_INTRINSICS
36
#  if (defined(__BMI__) || defined(__BMI2__)) && defined(__GNUC__)
37
#    include <immintrin.h>   /* support for bextr (experimental)/bzhi */
38
#  elif defined(__ICCARM__)
39
#    include <intrinsics.h>
40
#  endif
41
#endif
42
43
0
#define STREAM_ACCUMULATOR_MIN_32  25
44
0
#define STREAM_ACCUMULATOR_MIN_64  57
45
0
#define STREAM_ACCUMULATOR_MIN    ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))
46
47
48
/*-******************************************
49
*  bitStream encoding API (write forward)
50
********************************************/
51
typedef size_t BitContainerType;
52
/* bitStream can mix input from multiple sources.
53
 * A critical property of these streams is that they encode and decode in **reverse** direction.
54
 * So the first bit sequence you add will be the last to be read, like a LIFO stack.
55
 */
56
typedef struct {
57
    BitContainerType bitContainer;
58
    unsigned bitPos;
59
    char*  startPtr;
60
    char*  ptr;
61
    char*  endPtr;
62
} BIT_CStream_t;
63
64
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* dstBuffer, size_t dstCapacity);
65
MEM_STATIC void   BIT_addBits(BIT_CStream_t* bitC, BitContainerType value, unsigned nbBits);
66
MEM_STATIC void   BIT_flushBits(BIT_CStream_t* bitC);
67
MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
68
69
/* Start with initCStream, providing the size of buffer to write into.
70
*  bitStream will never write outside of this buffer.
71
*  `dstCapacity` must be >= sizeof(bitD->bitContainer), otherwise @return will be an error code.
72
*
73
*  bits are first added to a local register.
74
*  Local register is BitContainerType, 64-bits on 64-bits systems, or 32-bits on 32-bits systems.
75
*  Writing data into memory is an explicit operation, performed by the flushBits function.
76
*  Hence keep track how many bits are potentially stored into local register to avoid register overflow.
77
*  After a flushBits, a maximum of 7 bits might still be stored into local register.
78
*
79
*  Avoid storing elements of more than 24 bits if you want compatibility with 32-bits bitstream readers.
80
*
81
*  Last operation is to close the bitStream.
82
*  The function returns the final size of CStream in bytes.
83
*  If data couldn't fit into `dstBuffer`, it will return a 0 ( == not storable)
84
*/
85
86
87
/*-********************************************
88
*  bitStream decoding API (read backward)
89
**********************************************/
90
typedef struct {
91
    BitContainerType bitContainer;
92
    unsigned bitsConsumed;
93
    const char* ptr;
94
    const char* start;
95
    const char* limitPtr;
96
} BIT_DStream_t;
97
98
typedef enum { BIT_DStream_unfinished = 0,  /* fully refilled */
99
               BIT_DStream_endOfBuffer = 1, /* still some bits left in bitstream */
100
               BIT_DStream_completed = 2,   /* bitstream entirely consumed, bit-exact */
101
               BIT_DStream_overflow = 3     /* user requested more bits than present in bitstream */
102
    } BIT_DStream_status;  /* result of BIT_reloadDStream() */
103
104
MEM_STATIC size_t   BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize);
105
MEM_STATIC BitContainerType BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits);
106
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
107
MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
108
109
110
/* Start by invoking BIT_initDStream().
111
*  A chunk of the bitStream is then stored into a local register.
112
*  Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (BitContainerType).
113
*  You can then retrieve bitFields stored into the local register, **in reverse order**.
114
*  Local register is explicitly reloaded from memory by the BIT_reloadDStream() method.
115
*  A reload guarantee a minimum of ((8*sizeof(bitD->bitContainer))-7) bits when its result is BIT_DStream_unfinished.
116
*  Otherwise, it can be less than that, so proceed accordingly.
117
*  Checking if DStream has reached its end can be performed with BIT_endOfDStream().
118
*/
119
120
121
/*-****************************************
122
*  unsafe API
123
******************************************/
124
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, BitContainerType value, unsigned nbBits);
125
/* faster, but works only if value is "clean", meaning all high bits above nbBits are 0 */
126
127
MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC);
128
/* unsafe version; does not check buffer overflow */
129
130
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
131
/* faster, but works only if nbBits >= 1 */
132
133
/*=====    Local Constants   =====*/
134
static const unsigned BIT_mask[] = {
135
    0,          1,         3,         7,         0xF,       0x1F,
136
    0x3F,       0x7F,      0xFF,      0x1FF,     0x3FF,     0x7FF,
137
    0xFFF,      0x1FFF,    0x3FFF,    0x7FFF,    0xFFFF,    0x1FFFF,
138
    0x3FFFF,    0x7FFFF,   0xFFFFF,   0x1FFFFF,  0x3FFFFF,  0x7FFFFF,
139
    0xFFFFFF,   0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF,
140
    0x3FFFFFFF, 0x7FFFFFFF}; /* up to 31 bits */
141
#define BIT_MASK_SIZE (sizeof(BIT_mask) / sizeof(BIT_mask[0]))
142
143
/*-**************************************************************
144
*  bitStream encoding
145
****************************************************************/
146
/*! BIT_initCStream() :
147
 *  `dstCapacity` must be > sizeof(size_t)
148
 *  @return : 0 if success,
149
 *            otherwise an error code (can be tested using ERR_isError()) */
150
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
151
                                  void* startPtr, size_t dstCapacity)
152
73.4k
{
153
73.4k
    bitC->bitContainer = 0;
154
73.4k
    bitC->bitPos = 0;
155
73.4k
    bitC->startPtr = (char*)startPtr;
156
73.4k
    bitC->ptr = bitC->startPtr;
157
73.4k
    bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
158
73.4k
    if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
159
73.4k
    return 0;
160
73.4k
}
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
53.5k
{
153
53.5k
    bitC->bitContainer = 0;
154
53.5k
    bitC->bitPos = 0;
155
53.5k
    bitC->startPtr = (char*)startPtr;
156
53.5k
    bitC->ptr = bitC->startPtr;
157
53.5k
    bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
158
53.5k
    if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
159
53.5k
    return 0;
160
53.5k
}
Unexecuted instantiation: zstd_compress_superblock.c:BIT_initCStream
Unexecuted instantiation: zstd_double_fast.c:BIT_initCStream
Unexecuted instantiation: zstd_fast.c:BIT_initCStream
Unexecuted instantiation: zstd_lazy.c:BIT_initCStream
Unexecuted instantiation: zstd_ldm.c:BIT_initCStream
Unexecuted instantiation: zstd_opt.c:BIT_initCStream
Unexecuted instantiation: zstd_preSplit.c:BIT_initCStream
Unexecuted instantiation: zstdmt_compress.c:BIT_initCStream
Unexecuted instantiation: 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
152
19.9k
{
153
19.9k
    bitC->bitContainer = 0;
154
19.9k
    bitC->bitPos = 0;
155
19.9k
    bitC->startPtr = (char*)startPtr;
156
19.9k
    bitC->ptr = bitC->startPtr;
157
19.9k
    bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
158
19.9k
    if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
159
19.9k
    return 0;
160
19.9k
}
Unexecuted instantiation: huf_compress.c:BIT_initCStream
Unexecuted instantiation: huf_decompress.c:BIT_initCStream
Unexecuted instantiation: zstd_ddict.c:BIT_initCStream
161
162
FORCE_INLINE_TEMPLATE BitContainerType BIT_getLowerBits(BitContainerType bitContainer, U32 const nbBits)
163
204M
{
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
204M
    assert(nbBits < BIT_MASK_SIZE);
173
204M
    return bitContainer & BIT_mask[nbBits];
174
204M
#endif
175
204M
}
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
199M
{
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
199M
    assert(nbBits < BIT_MASK_SIZE);
173
199M
    return bitContainer & BIT_mask[nbBits];
174
199M
#endif
175
199M
}
Unexecuted instantiation: zstd_compress_superblock.c:BIT_getLowerBits
Unexecuted instantiation: zstd_double_fast.c:BIT_getLowerBits
Unexecuted instantiation: zstd_fast.c:BIT_getLowerBits
Unexecuted instantiation: zstd_lazy.c:BIT_getLowerBits
Unexecuted instantiation: zstd_ldm.c:BIT_getLowerBits
Unexecuted instantiation: zstd_opt.c:BIT_getLowerBits
Unexecuted instantiation: zstd_preSplit.c:BIT_getLowerBits
Unexecuted instantiation: zstdmt_compress.c:BIT_getLowerBits
Unexecuted instantiation: 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
163
5.06M
{
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
5.06M
    assert(nbBits < BIT_MASK_SIZE);
173
5.06M
    return bitContainer & BIT_mask[nbBits];
174
5.06M
#endif
175
5.06M
}
Unexecuted instantiation: huf_compress.c:BIT_getLowerBits
Unexecuted instantiation: huf_decompress.c:BIT_getLowerBits
Unexecuted instantiation: zstd_ddict.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
204M
{
183
204M
    DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
184
204M
    assert(nbBits < BIT_MASK_SIZE);
185
204M
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
186
204M
    bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
187
204M
    bitC->bitPos += nbBits;
188
204M
}
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
199M
{
183
199M
    DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
184
199M
    assert(nbBits < BIT_MASK_SIZE);
185
199M
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
186
199M
    bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
187
199M
    bitC->bitPos += nbBits;
188
199M
}
Unexecuted instantiation: zstd_compress_superblock.c:BIT_addBits
Unexecuted instantiation: zstd_double_fast.c:BIT_addBits
Unexecuted instantiation: zstd_fast.c:BIT_addBits
Unexecuted instantiation: zstd_lazy.c:BIT_addBits
Unexecuted instantiation: zstd_ldm.c:BIT_addBits
Unexecuted instantiation: zstd_opt.c:BIT_addBits
Unexecuted instantiation: zstd_preSplit.c:BIT_addBits
Unexecuted instantiation: zstdmt_compress.c:BIT_addBits
Unexecuted instantiation: 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
182
5.06M
{
183
5.06M
    DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
184
5.06M
    assert(nbBits < BIT_MASK_SIZE);
185
5.06M
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
186
5.06M
    bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
187
5.06M
    bitC->bitPos += nbBits;
188
5.06M
}
Unexecuted instantiation: huf_compress.c:BIT_addBits
Unexecuted instantiation: huf_decompress.c:BIT_addBits
Unexecuted instantiation: zstd_ddict.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
73.4k
{
196
73.4k
    assert((value>>nbBits) == 0);
197
73.4k
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
198
73.4k
    bitC->bitContainer |= value << bitC->bitPos;
199
73.4k
    bitC->bitPos += nbBits;
200
73.4k
}
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
53.5k
{
196
53.5k
    assert((value>>nbBits) == 0);
197
53.5k
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
198
53.5k
    bitC->bitContainer |= value << bitC->bitPos;
199
53.5k
    bitC->bitPos += nbBits;
200
53.5k
}
Unexecuted instantiation: zstd_compress_superblock.c:BIT_addBitsFast
Unexecuted instantiation: zstd_double_fast.c:BIT_addBitsFast
Unexecuted instantiation: zstd_fast.c:BIT_addBitsFast
Unexecuted instantiation: zstd_lazy.c:BIT_addBitsFast
Unexecuted instantiation: zstd_ldm.c:BIT_addBitsFast
Unexecuted instantiation: zstd_opt.c:BIT_addBitsFast
Unexecuted instantiation: zstd_preSplit.c:BIT_addBitsFast
Unexecuted instantiation: zstdmt_compress.c:BIT_addBitsFast
Unexecuted instantiation: 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
195
19.9k
{
196
19.9k
    assert((value>>nbBits) == 0);
197
19.9k
    assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
198
19.9k
    bitC->bitContainer |= value << bitC->bitPos;
199
19.9k
    bitC->bitPos += nbBits;
200
19.9k
}
Unexecuted instantiation: huf_compress.c:BIT_addBitsFast
Unexecuted instantiation: huf_decompress.c:BIT_addBitsFast
Unexecuted instantiation: zstd_ddict.c:BIT_addBitsFast
201
202
/*! BIT_flushBitsFast() :
203
 *  assumption : bitContainer has not overflowed
204
 *  unsafe version; does not check buffer overflow */
205
MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC)
206
1.26M
{
207
1.26M
    size_t const nbBytes = bitC->bitPos >> 3;
208
1.26M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
209
1.26M
    assert(bitC->ptr <= bitC->endPtr);
210
1.26M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
211
1.26M
    bitC->ptr += nbBytes;
212
1.26M
    bitC->bitPos &= 7;
213
1.26M
    bitC->bitContainer >>= nbBytes*8;
214
1.26M
}
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: zstdmt_compress.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
206
1.26M
{
207
1.26M
    size_t const nbBytes = bitC->bitPos >> 3;
208
1.26M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
209
1.26M
    assert(bitC->ptr <= bitC->endPtr);
210
1.26M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
211
1.26M
    bitC->ptr += nbBytes;
212
1.26M
    bitC->bitPos &= 7;
213
1.26M
    bitC->bitContainer >>= nbBytes*8;
214
1.26M
}
Unexecuted instantiation: huf_compress.c:BIT_flushBitsFast
Unexecuted instantiation: huf_decompress.c:BIT_flushBitsFast
Unexecuted instantiation: zstd_ddict.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
33.5M
{
223
33.5M
    size_t const nbBytes = bitC->bitPos >> 3;
224
33.5M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
33.5M
    assert(bitC->ptr <= bitC->endPtr);
226
33.5M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
227
33.5M
    bitC->ptr += nbBytes;
228
33.5M
    if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
229
33.5M
    bitC->bitPos &= 7;
230
33.5M
    bitC->bitContainer >>= nbBytes*8;
231
33.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
222
33.4M
{
223
33.4M
    size_t const nbBytes = bitC->bitPos >> 3;
224
33.4M
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
33.4M
    assert(bitC->ptr <= bitC->endPtr);
226
33.4M
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
227
33.4M
    bitC->ptr += nbBytes;
228
33.4M
    if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
229
33.4M
    bitC->bitPos &= 7;
230
33.4M
    bitC->bitContainer >>= nbBytes*8;
231
33.4M
}
Unexecuted instantiation: zstd_compress_superblock.c:BIT_flushBits
Unexecuted instantiation: zstd_double_fast.c:BIT_flushBits
Unexecuted instantiation: zstd_fast.c:BIT_flushBits
Unexecuted instantiation: zstd_lazy.c:BIT_flushBits
Unexecuted instantiation: zstd_ldm.c:BIT_flushBits
Unexecuted instantiation: zstd_opt.c:BIT_flushBits
Unexecuted instantiation: zstd_preSplit.c:BIT_flushBits
Unexecuted instantiation: zstdmt_compress.c:BIT_flushBits
Unexecuted instantiation: 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
222
59.8k
{
223
59.8k
    size_t const nbBytes = bitC->bitPos >> 3;
224
59.8k
    assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
225
59.8k
    assert(bitC->ptr <= bitC->endPtr);
226
59.8k
    MEM_writeLEST(bitC->ptr, bitC->bitContainer);
227
59.8k
    bitC->ptr += nbBytes;
228
59.8k
    if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
229
59.8k
    bitC->bitPos &= 7;
230
59.8k
    bitC->bitContainer >>= nbBytes*8;
231
59.8k
}
Unexecuted instantiation: huf_compress.c:BIT_flushBits
Unexecuted instantiation: huf_decompress.c:BIT_flushBits
Unexecuted instantiation: zstd_ddict.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
73.4k
{
238
73.4k
    BIT_addBitsFast(bitC, 1, 1);   /* endMark */
239
73.4k
    BIT_flushBits(bitC);
240
73.4k
    if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
241
73.4k
    return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
242
73.4k
}
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
53.5k
{
238
53.5k
    BIT_addBitsFast(bitC, 1, 1);   /* endMark */
239
53.5k
    BIT_flushBits(bitC);
240
53.5k
    if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
241
53.5k
    return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
242
53.5k
}
Unexecuted instantiation: zstd_compress_superblock.c:BIT_closeCStream
Unexecuted instantiation: zstd_double_fast.c:BIT_closeCStream
Unexecuted instantiation: zstd_fast.c:BIT_closeCStream
Unexecuted instantiation: zstd_lazy.c:BIT_closeCStream
Unexecuted instantiation: zstd_ldm.c:BIT_closeCStream
Unexecuted instantiation: zstd_opt.c:BIT_closeCStream
Unexecuted instantiation: zstd_preSplit.c:BIT_closeCStream
Unexecuted instantiation: zstdmt_compress.c:BIT_closeCStream
Unexecuted instantiation: 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
237
19.9k
{
238
19.9k
    BIT_addBitsFast(bitC, 1, 1);   /* endMark */
239
19.9k
    BIT_flushBits(bitC);
240
19.9k
    if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
241
19.9k
    return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
242
19.9k
}
Unexecuted instantiation: huf_compress.c:BIT_closeCStream
Unexecuted instantiation: huf_decompress.c:BIT_closeCStream
Unexecuted instantiation: zstd_ddict.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
3.61k
{
256
3.61k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
3.57k
    bitD->start = (const char*)srcBuffer;
259
3.57k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
3.57k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
2.78k
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
2.78k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
2.78k
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
2.78k
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
2.78k
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
2.78k
    } else {
268
795
        bitD->ptr   = bitD->start;
269
795
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
795
        switch(srcSize)
271
795
        {
272
119
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
119
                ZSTD_FALLTHROUGH;
274
275
165
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
165
                ZSTD_FALLTHROUGH;
277
278
285
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
285
                ZSTD_FALLTHROUGH;
280
281
413
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
413
                ZSTD_FALLTHROUGH;
283
284
572
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
572
                ZSTD_FALLTHROUGH;
286
287
693
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
693
                ZSTD_FALLTHROUGH;
289
290
795
        default: break;
291
795
        }
292
795
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
795
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
795
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
795
        }
296
740
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
740
    }
298
299
3.45k
    return srcSize;
300
3.57k
}
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: zstdmt_compress.c:BIT_initDStream
Unexecuted instantiation: zstd_decompress.c:BIT_initDStream
zstd_decompress_block.c:BIT_initDStream
Line
Count
Source
255
1.02k
{
256
1.02k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
1.01k
    bitD->start = (const char*)srcBuffer;
259
1.01k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
1.01k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
921
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
921
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
921
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
921
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
921
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
921
    } else {
268
94
        bitD->ptr   = bitD->start;
269
94
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
94
        switch(srcSize)
271
94
        {
272
13
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
13
                ZSTD_FALLTHROUGH;
274
275
29
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
29
                ZSTD_FALLTHROUGH;
277
278
39
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
39
                ZSTD_FALLTHROUGH;
280
281
50
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
50
                ZSTD_FALLTHROUGH;
283
284
64
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
64
                ZSTD_FALLTHROUGH;
286
287
81
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
81
                ZSTD_FALLTHROUGH;
289
290
94
        default: break;
291
94
        }
292
94
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
94
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
94
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
94
        }
296
84
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
84
    }
298
299
989
    return srcSize;
300
1.01k
}
Unexecuted instantiation: entropy_common.c:BIT_initDStream
fse_decompress.c:BIT_initDStream
Line
Count
Source
255
797
{
256
797
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
789
    bitD->start = (const char*)srcBuffer;
259
789
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
789
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
610
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
610
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
610
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
610
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
610
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
610
    } else {
268
179
        bitD->ptr   = bitD->start;
269
179
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
179
        switch(srcSize)
271
179
        {
272
16
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
16
                ZSTD_FALLTHROUGH;
274
275
23
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
23
                ZSTD_FALLTHROUGH;
277
278
65
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
65
                ZSTD_FALLTHROUGH;
280
281
86
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
86
                ZSTD_FALLTHROUGH;
283
284
149
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
149
                ZSTD_FALLTHROUGH;
286
287
170
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
170
                ZSTD_FALLTHROUGH;
289
290
179
        default: break;
291
179
        }
292
179
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
179
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
179
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
179
        }
296
170
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
170
    }
298
299
768
    return srcSize;
300
789
}
Unexecuted instantiation: fse_compress.c:BIT_initDStream
Unexecuted instantiation: huf_compress.c:BIT_initDStream
huf_decompress.c:BIT_initDStream
Line
Count
Source
255
1.79k
{
256
1.79k
    if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
257
258
1.77k
    bitD->start = (const char*)srcBuffer;
259
1.77k
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
260
261
1.77k
    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
262
1.25k
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
263
1.25k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
264
1.25k
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
265
1.25k
          bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
266
1.25k
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
267
1.25k
    } else {
268
522
        bitD->ptr   = bitD->start;
269
522
        bitD->bitContainer = *(const BYTE*)(bitD->start);
270
522
        switch(srcSize)
271
522
        {
272
90
        case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
273
90
                ZSTD_FALLTHROUGH;
274
275
113
        case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
276
113
                ZSTD_FALLTHROUGH;
277
278
181
        case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
279
181
                ZSTD_FALLTHROUGH;
280
281
277
        case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
282
277
                ZSTD_FALLTHROUGH;
283
284
359
        case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
285
359
                ZSTD_FALLTHROUGH;
286
287
442
        case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) <<  8;
288
442
                ZSTD_FALLTHROUGH;
289
290
522
        default: break;
291
522
        }
292
522
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
293
522
            bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
294
522
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
295
522
        }
296
486
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
297
486
    }
298
299
1.70k
    return srcSize;
300
1.77k
}
Unexecuted instantiation: zstd_ddict.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: zstdmt_compress.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
306
307
FORCE_INLINE_TEMPLATE BitContainerType BIT_getMiddleBits(BitContainerType bitContainer, U32 const start, U32 const nbBits)
308
5.43M
{
309
5.43M
    U32 const regMask = sizeof(bitContainer)*8 - 1;
310
    /* if start > regMask, bitstream is corrupted, and result is undefined */
311
5.43M
    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
5.43M
#if defined(__x86_64__) || defined(_M_X64)
318
5.43M
    return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
319
#else
320
    return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
321
#endif
322
5.43M
}
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: zstdmt_compress.c:BIT_getMiddleBits
Unexecuted instantiation: zstd_decompress.c:BIT_getMiddleBits
zstd_decompress_block.c:BIT_getMiddleBits
Line
Count
Source
308
5.34M
{
309
5.34M
    U32 const regMask = sizeof(bitContainer)*8 - 1;
310
    /* if start > regMask, bitstream is corrupted, and result is undefined */
311
5.34M
    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
5.34M
#if defined(__x86_64__) || defined(_M_X64)
318
5.34M
    return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
319
#else
320
    return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
321
#endif
322
5.34M
}
Unexecuted instantiation: entropy_common.c:BIT_getMiddleBits
fse_decompress.c:BIT_getMiddleBits
Line
Count
Source
308
91.4k
{
309
91.4k
    U32 const regMask = sizeof(bitContainer)*8 - 1;
310
    /* if start > regMask, bitstream is corrupted, and result is undefined */
311
91.4k
    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
91.4k
#if defined(__x86_64__) || defined(_M_X64)
318
91.4k
    return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
319
#else
320
    return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
321
#endif
322
91.4k
}
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
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
5.43M
{
332
    /* arbitrate between double-shift and shift+mask */
333
5.43M
#if 1
334
    /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
335
     * bitstream is likely corrupted, and result is undefined */
336
5.43M
    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
5.43M
}
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: zstdmt_compress.c:BIT_lookBits
Unexecuted instantiation: zstd_decompress.c:BIT_lookBits
zstd_decompress_block.c:BIT_lookBits
Line
Count
Source
331
5.34M
{
332
    /* arbitrate between double-shift and shift+mask */
333
5.34M
#if 1
334
    /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
335
     * bitstream is likely corrupted, and result is undefined */
336
5.34M
    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
5.34M
}
Unexecuted instantiation: entropy_common.c:BIT_lookBits
fse_decompress.c:BIT_lookBits
Line
Count
Source
331
91.4k
{
332
    /* arbitrate between double-shift and shift+mask */
333
91.4k
#if 1
334
    /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
335
     * bitstream is likely corrupted, and result is undefined */
336
91.4k
    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
91.4k
}
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
343
344
/*! BIT_lookBitsFast() :
345
 *  unsafe version; only works if nbBits >= 1 */
346
MEM_STATIC BitContainerType BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits)
347
2.00M
{
348
2.00M
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
2.00M
    assert(nbBits >= 1);
350
2.00M
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
2.00M
}
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: zstdmt_compress.c:BIT_lookBitsFast
Unexecuted instantiation: zstd_decompress.c:BIT_lookBitsFast
zstd_decompress_block.c:BIT_lookBitsFast
Line
Count
Source
347
1.61M
{
348
1.61M
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
1.61M
    assert(nbBits >= 1);
350
1.61M
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
1.61M
}
Unexecuted instantiation: entropy_common.c:BIT_lookBitsFast
fse_decompress.c:BIT_lookBitsFast
Line
Count
Source
347
9.58k
{
348
9.58k
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
9.58k
    assert(nbBits >= 1);
350
9.58k
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
9.58k
}
Unexecuted instantiation: fse_compress.c:BIT_lookBitsFast
Unexecuted instantiation: huf_compress.c:BIT_lookBitsFast
huf_decompress.c:BIT_lookBitsFast
Line
Count
Source
347
385k
{
348
385k
    U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
349
385k
    assert(nbBits >= 1);
350
385k
    return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
351
385k
}
Unexecuted instantiation: zstd_ddict.c:BIT_lookBitsFast
352
353
FORCE_INLINE_TEMPLATE void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
354
7.44M
{
355
7.44M
    bitD->bitsConsumed += nbBits;
356
7.44M
}
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: zstdmt_compress.c:BIT_skipBits
Unexecuted instantiation: zstd_decompress.c:BIT_skipBits
zstd_decompress_block.c:BIT_skipBits
Line
Count
Source
354
6.95M
{
355
6.95M
    bitD->bitsConsumed += nbBits;
356
6.95M
}
Unexecuted instantiation: entropy_common.c:BIT_skipBits
fse_decompress.c:BIT_skipBits
Line
Count
Source
354
101k
{
355
101k
    bitD->bitsConsumed += nbBits;
356
101k
}
Unexecuted instantiation: fse_compress.c:BIT_skipBits
Unexecuted instantiation: huf_compress.c:BIT_skipBits
huf_decompress.c:BIT_skipBits
Line
Count
Source
354
385k
{
355
385k
    bitD->bitsConsumed += nbBits;
356
385k
}
Unexecuted instantiation: zstd_ddict.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
5.43M
{
364
5.43M
    BitContainerType const value = BIT_lookBits(bitD, nbBits);
365
5.43M
    BIT_skipBits(bitD, nbBits);
366
5.43M
    return value;
367
5.43M
}
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: zstdmt_compress.c:BIT_readBits
Unexecuted instantiation: zstd_decompress.c:BIT_readBits
zstd_decompress_block.c:BIT_readBits
Line
Count
Source
363
5.34M
{
364
5.34M
    BitContainerType const value = BIT_lookBits(bitD, nbBits);
365
5.34M
    BIT_skipBits(bitD, nbBits);
366
5.34M
    return value;
367
5.34M
}
Unexecuted instantiation: entropy_common.c:BIT_readBits
fse_decompress.c:BIT_readBits
Line
Count
Source
363
91.4k
{
364
91.4k
    BitContainerType const value = BIT_lookBits(bitD, nbBits);
365
91.4k
    BIT_skipBits(bitD, nbBits);
366
91.4k
    return value;
367
91.4k
}
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
368
369
/*! BIT_readBitsFast() :
370
 *  unsafe version; only works if nbBits >= 1 */
371
MEM_STATIC BitContainerType BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
372
1.62M
{
373
1.62M
    BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
374
1.62M
    assert(nbBits >= 1);
375
1.62M
    BIT_skipBits(bitD, nbBits);
376
1.62M
    return value;
377
1.62M
}
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: zstdmt_compress.c:BIT_readBitsFast
Unexecuted instantiation: zstd_decompress.c:BIT_readBitsFast
zstd_decompress_block.c:BIT_readBitsFast
Line
Count
Source
372
1.61M
{
373
1.61M
    BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
374
1.61M
    assert(nbBits >= 1);
375
1.61M
    BIT_skipBits(bitD, nbBits);
376
1.61M
    return value;
377
1.61M
}
Unexecuted instantiation: entropy_common.c:BIT_readBitsFast
fse_decompress.c:BIT_readBitsFast
Line
Count
Source
372
9.58k
{
373
9.58k
    BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
374
9.58k
    assert(nbBits >= 1);
375
9.58k
    BIT_skipBits(bitD, nbBits);
376
9.58k
    return value;
377
9.58k
}
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
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
93.7k
{
386
93.7k
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
93.7k
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
93.7k
    assert(bitD->ptr >= bitD->start);
389
93.7k
    bitD->bitsConsumed &= 7;
390
93.7k
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
93.7k
    return BIT_DStream_unfinished;
392
93.7k
}
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: zstdmt_compress.c:BIT_reloadDStream_internal
Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStream_internal
zstd_decompress_block.c:BIT_reloadDStream_internal
Line
Count
Source
385
50.3k
{
386
50.3k
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
50.3k
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
50.3k
    assert(bitD->ptr >= bitD->start);
389
50.3k
    bitD->bitsConsumed &= 7;
390
50.3k
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
50.3k
    return BIT_DStream_unfinished;
392
50.3k
}
Unexecuted instantiation: entropy_common.c:BIT_reloadDStream_internal
fse_decompress.c:BIT_reloadDStream_internal
Line
Count
Source
385
11.0k
{
386
11.0k
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
11.0k
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
11.0k
    assert(bitD->ptr >= bitD->start);
389
11.0k
    bitD->bitsConsumed &= 7;
390
11.0k
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
11.0k
    return BIT_DStream_unfinished;
392
11.0k
}
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
32.3k
{
386
32.3k
    assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
387
32.3k
    bitD->ptr -= bitD->bitsConsumed >> 3;
388
32.3k
    assert(bitD->ptr >= bitD->start);
389
32.3k
    bitD->bitsConsumed &= 7;
390
32.3k
    bitD->bitContainer = MEM_readLEST(bitD->ptr);
391
32.3k
    return BIT_DStream_unfinished;
392
32.3k
}
Unexecuted instantiation: zstd_ddict.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
2.77k
{
402
2.77k
    if (UNLIKELY(bitD->ptr < bitD->limitPtr))
403
553
        return BIT_DStream_overflow;
404
2.22k
    return BIT_reloadDStream_internal(bitD);
405
2.77k
}
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: zstdmt_compress.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
401
2.77k
{
402
2.77k
    if (UNLIKELY(bitD->ptr < bitD->limitPtr))
403
553
        return BIT_DStream_overflow;
404
2.22k
    return BIT_reloadDStream_internal(bitD);
405
2.77k
}
Unexecuted instantiation: zstd_ddict.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
1.87M
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
1.87M
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
1.73M
        static const BitContainerType zeroFilled = 0;
417
1.73M
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
1.73M
        return BIT_DStream_overflow;
420
1.73M
    }
421
422
145k
    assert(bitD->ptr >= bitD->start);
423
424
145k
    if (bitD->ptr >= bitD->limitPtr) {
425
91.5k
        return BIT_reloadDStream_internal(bitD);
426
91.5k
    }
427
53.5k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
39.1k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
781
        return BIT_DStream_completed;
431
39.1k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
14.3k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
14.3k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
14.3k
        if (bitD->ptr - nbBytes < bitD->start) {
436
992
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
992
            result = BIT_DStream_endOfBuffer;
438
992
        }
439
14.3k
        bitD->ptr -= nbBytes;
440
14.3k
        bitD->bitsConsumed -= nbBytes*8;
441
14.3k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
14.3k
        return result;
443
53.5k
    }
444
53.5k
}
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: zstdmt_compress.c:BIT_reloadDStream
Unexecuted instantiation: zstd_decompress.c:BIT_reloadDStream
zstd_decompress_block.c:BIT_reloadDStream
Line
Count
Source
413
1.78M
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
1.78M
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
1.72M
        static const BitContainerType zeroFilled = 0;
417
1.72M
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
1.72M
        return BIT_DStream_overflow;
420
1.72M
    }
421
422
55.3k
    assert(bitD->ptr >= bitD->start);
423
424
55.3k
    if (bitD->ptr >= bitD->limitPtr) {
425
50.3k
        return BIT_reloadDStream_internal(bitD);
426
50.3k
    }
427
5.06k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
2.60k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
49
        return BIT_DStream_completed;
431
2.60k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
2.45k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
2.45k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
2.45k
        if (bitD->ptr - nbBytes < bitD->start) {
436
233
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
233
            result = BIT_DStream_endOfBuffer;
438
233
        }
439
2.45k
        bitD->ptr -= nbBytes;
440
2.45k
        bitD->bitsConsumed -= nbBytes*8;
441
2.45k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
2.45k
        return result;
443
5.06k
    }
444
5.06k
}
Unexecuted instantiation: entropy_common.c:BIT_reloadDStream
fse_decompress.c:BIT_reloadDStream
Line
Count
Source
413
53.4k
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
53.4k
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
761
        static const BitContainerType zeroFilled = 0;
417
761
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
761
        return BIT_DStream_overflow;
420
761
    }
421
422
52.6k
    assert(bitD->ptr >= bitD->start);
423
424
52.6k
    if (bitD->ptr >= bitD->limitPtr) {
425
11.0k
        return BIT_reloadDStream_internal(bitD);
426
11.0k
    }
427
41.6k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
34.6k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
716
        return BIT_DStream_completed;
431
34.6k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
6.98k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
6.98k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
6.98k
        if (bitD->ptr - nbBytes < bitD->start) {
436
74
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
74
            result = BIT_DStream_endOfBuffer;
438
74
        }
439
6.98k
        bitD->ptr -= nbBytes;
440
6.98k
        bitD->bitsConsumed -= nbBytes*8;
441
6.98k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
6.98k
        return result;
443
41.6k
    }
444
41.6k
}
Unexecuted instantiation: fse_compress.c:BIT_reloadDStream
Unexecuted instantiation: huf_compress.c:BIT_reloadDStream
huf_decompress.c:BIT_reloadDStream
Line
Count
Source
413
37.2k
{
414
    /* note : once in overflow mode, a bitstream remains in this mode until it's reset */
415
37.2k
    if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
416
295
        static const BitContainerType zeroFilled = 0;
417
295
        bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
418
        /* overflow detected, erroneous scenario or end of stream: no update */
419
295
        return BIT_DStream_overflow;
420
295
    }
421
422
36.9k
    assert(bitD->ptr >= bitD->start);
423
424
36.9k
    if (bitD->ptr >= bitD->limitPtr) {
425
30.1k
        return BIT_reloadDStream_internal(bitD);
426
30.1k
    }
427
6.81k
    if (bitD->ptr == bitD->start) {
428
        /* reached end of bitStream => no update */
429
1.87k
        if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
430
16
        return BIT_DStream_completed;
431
1.87k
    }
432
    /* start < ptr < limitPtr => cautious update */
433
4.93k
    {   U32 nbBytes = bitD->bitsConsumed >> 3;
434
4.93k
        BIT_DStream_status result = BIT_DStream_unfinished;
435
4.93k
        if (bitD->ptr - nbBytes < bitD->start) {
436
685
            nbBytes = (U32)(bitD->ptr - bitD->start);  /* ptr > start */
437
685
            result = BIT_DStream_endOfBuffer;
438
685
        }
439
4.93k
        bitD->ptr -= nbBytes;
440
4.93k
        bitD->bitsConsumed -= nbBytes*8;
441
4.93k
        bitD->bitContainer = MEM_readLEST(bitD->ptr);   /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
442
4.93k
        return result;
443
6.81k
    }
444
6.81k
}
Unexecuted instantiation: zstd_ddict.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
1.73k
{
451
1.73k
    return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
452
1.73k
}
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: zstdmt_compress.c:BIT_endOfDStream
Unexecuted instantiation: zstd_decompress.c:BIT_endOfDStream
zstd_decompress_block.c:BIT_endOfDStream
Line
Count
Source
450
130
{
451
130
    return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
452
130
}
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
1.60k
{
451
1.60k
    return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
452
1.60k
}
Unexecuted instantiation: zstd_ddict.c:BIT_endOfDStream
453
454
#endif /* BITSTREAM_H_MODULE */