Coverage Report

Created: 2025-12-14 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zstd/lib/common/zstd_internal.h
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under both the BSD-style license (found in the
6
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
 * in the COPYING file in the root directory of this source tree).
8
 * You may select, at your option, one of the above-listed licenses.
9
 */
10
11
#ifndef ZSTD_CCOMMON_H_MODULE
12
#define ZSTD_CCOMMON_H_MODULE
13
14
/* this module contains definitions which must be identical
15
 * across compression, decompression and dictBuilder.
16
 * It also contains a few functions useful to at least 2 of them
17
 * and which benefit from being inlined */
18
19
/*-*************************************
20
*  Dependencies
21
***************************************/
22
#include "compiler.h"
23
#include "cpu.h"
24
#include "mem.h"
25
#include "debug.h"                 /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
26
#include "error_private.h"
27
#define ZSTD_STATIC_LINKING_ONLY
28
#include "../zstd.h"
29
#define FSE_STATIC_LINKING_ONLY
30
#include "fse.h"
31
#include "huf.h"
32
#ifndef XXH_STATIC_LINKING_ONLY
33
#  define XXH_STATIC_LINKING_ONLY  /* XXH64_state_t */
34
#endif
35
#include "xxhash.h"                /* XXH_reset, update, digest */
36
#ifndef ZSTD_NO_TRACE
37
#  include "zstd_trace.h"
38
#else
39
#  define ZSTD_TRACE 0
40
#endif
41
42
/* ---- static assert (debug) --- */
43
1.38G
#define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
44
362M
#define ZSTD_isError ERR_isError   /* for inlining */
45
365k
#define FSE_isError  ERR_isError
46
121k
#define HUF_isError  ERR_isError
47
48
49
/*-*************************************
50
*  shared macros
51
***************************************/
52
#undef MIN
53
#undef MAX
54
5.17G
#define MIN(a,b) ((a)<(b) ? (a) : (b))
55
489M
#define MAX(a,b) ((a)>(b) ? (a) : (b))
56
63.4M
#define BOUNDED(min,val,max) (MAX(min,MIN(val,max)))
57
58
59
/*-*************************************
60
*  Common constants
61
***************************************/
62
565M
#define ZSTD_OPT_NUM    (1<<12)
63
64
4.91G
#define ZSTD_REP_NUM      3                 /* number of repcodes */
65
static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
66
67
114M
#define KB *(1 <<10)
68
64.4M
#define MB *(1 <<20)
69
0
#define GB *(1U<<30)
70
71
#define BIT7 128
72
#define BIT6  64
73
#define BIT5  32
74
#define BIT4  16
75
#define BIT1   2
76
#define BIT0   1
77
78
7.25M
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
79
static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
80
static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
81
82
54.4k
#define ZSTD_FRAMEIDSIZE 4   /* magic number size */
83
84
23.1k
#define ZSTD_BLOCKHEADERSIZE 3   /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
85
static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
86
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
87
88
#define ZSTD_FRAMECHECKSUMSIZE 4
89
90
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
91
52.2M
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */)   /* for a non-null block */
92
#define MIN_LITERALS_FOR_4_STREAMS 6
93
94
typedef enum { set_basic, set_rle, set_compressed, set_repeat } SymbolEncodingType_e;
95
96
544k
#define LONGNBSEQ 0x7F00
97
98
5.43G
#define MINMATCH 3
99
100
10.0M
#define Litbits  8
101
2.74M
#define LitHufLog 11
102
4.69M
#define MaxLit ((1<<Litbits) - 1)
103
30.6M
#define MaxML   52
104
24.8M
#define MaxLL   35
105
9.47M
#define DefaultMaxOff 28
106
14.7M
#define MaxOff  31
107
11.4M
#define MaxSeq MAX(MaxLL, MaxML)   /* Assumption : MaxOff < MaxLL,MaxML */
108
222M
#define MLFSELog    9
109
222M
#define LLFSELog    9
110
222M
#define OffFSELog   8
111
#define MaxFSELog  MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
112
#define MaxMLBits 16
113
#define MaxLLBits 16
114
115
#define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
116
/* Each table cannot take more than #symbols * FSELog bits */
117
#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
118
119
static UNUSED_ATTR const U8 LL_bits[MaxLL+1] = {
120
     0, 0, 0, 0, 0, 0, 0, 0,
121
     0, 0, 0, 0, 0, 0, 0, 0,
122
     1, 1, 1, 1, 2, 2, 3, 3,
123
     4, 6, 7, 8, 9,10,11,12,
124
    13,14,15,16
125
};
126
static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
127
     4, 3, 2, 2, 2, 2, 2, 2,
128
     2, 2, 2, 2, 2, 1, 1, 1,
129
     2, 2, 2, 2, 2, 2, 2, 2,
130
     2, 3, 2, 1, 1, 1, 1, 1,
131
    -1,-1,-1,-1
132
};
133
#define LL_DEFAULTNORMLOG 6  /* for static allocation */
134
static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
135
136
static UNUSED_ATTR const U8 ML_bits[MaxML+1] = {
137
     0, 0, 0, 0, 0, 0, 0, 0,
138
     0, 0, 0, 0, 0, 0, 0, 0,
139
     0, 0, 0, 0, 0, 0, 0, 0,
140
     0, 0, 0, 0, 0, 0, 0, 0,
141
     1, 1, 1, 1, 2, 2, 3, 3,
142
     4, 4, 5, 7, 8, 9,10,11,
143
    12,13,14,15,16
144
};
145
static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = {
146
     1, 4, 3, 2, 2, 2, 2, 2,
147
     2, 1, 1, 1, 1, 1, 1, 1,
148
     1, 1, 1, 1, 1, 1, 1, 1,
149
     1, 1, 1, 1, 1, 1, 1, 1,
150
     1, 1, 1, 1, 1, 1, 1, 1,
151
     1, 1, 1, 1, 1, 1,-1,-1,
152
    -1,-1,-1,-1,-1
153
};
154
#define ML_DEFAULTNORMLOG 6  /* for static allocation */
155
static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
156
157
static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = {
158
     1, 1, 1, 1, 1, 1, 2, 2,
159
     2, 1, 1, 1, 1, 1, 1, 1,
160
     1, 1, 1, 1, 1, 1, 1, 1,
161
    -1,-1,-1,-1,-1
162
};
163
#define OF_DEFAULTNORMLOG 5  /* for static allocation */
164
static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
165
166
167
/*-*******************************************
168
*  Shared functions to include for inlining
169
*********************************************/
170
528M
static void ZSTD_copy8(void* dst, const void* src) {
171
#if defined(ZSTD_ARCH_ARM_NEON) && !defined(__aarch64__)
172
    vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
173
#else
174
528M
    ZSTD_memcpy(dst, src, 8);
175
528M
#endif
176
528M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_copy8
Unexecuted instantiation: zstd_common.c:ZSTD_copy8
Unexecuted instantiation: zstd_compress.c:ZSTD_copy8
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_copy8
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_copy8
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_copy8
Unexecuted instantiation: zstd_double_fast.c:ZSTD_copy8
Unexecuted instantiation: zstd_fast.c:ZSTD_copy8
Unexecuted instantiation: zstd_lazy.c:ZSTD_copy8
Unexecuted instantiation: zstd_ldm.c:ZSTD_copy8
Unexecuted instantiation: zstd_opt.c:ZSTD_copy8
Unexecuted instantiation: zstd_preSplit.c:ZSTD_copy8
Unexecuted instantiation: zstdmt_compress.c:ZSTD_copy8
Unexecuted instantiation: huf_decompress.c:ZSTD_copy8
Unexecuted instantiation: zstd_ddict.c:ZSTD_copy8
Unexecuted instantiation: zstd_decompress.c:ZSTD_copy8
zstd_decompress_block.c:ZSTD_copy8
Line
Count
Source
170
528M
static void ZSTD_copy8(void* dst, const void* src) {
171
#if defined(ZSTD_ARCH_ARM_NEON) && !defined(__aarch64__)
172
    vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
173
#else
174
528M
    ZSTD_memcpy(dst, src, 8);
175
528M
#endif
176
528M
}
Unexecuted instantiation: cover.c:ZSTD_copy8
Unexecuted instantiation: fastcover.c:ZSTD_copy8
Unexecuted instantiation: zdict.c:ZSTD_copy8
177
515M
#define COPY8(d,s) do { ZSTD_copy8(d,s); d+=8; s+=8; } while (0)
178
179
/* Need to use memmove here since the literal buffer can now be located within
180
   the dst buffer. In circumstances where the op "catches up" to where the
181
   literal buffer is, there can be partial overlaps in this call on the final
182
   copy if the literal is being shifted by less than 16 bytes. */
183
1.29G
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
1.29G
}
Unexecuted instantiation: sequence_producer.c:ZSTD_copy16
Unexecuted instantiation: zstd_common.c:ZSTD_copy16
zstd_compress.c:ZSTD_copy16
Line
Count
Source
183
57.2M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
57.2M
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_copy16
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_copy16
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_copy16
zstd_double_fast.c:ZSTD_copy16
Line
Count
Source
183
43.3M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
43.3M
}
zstd_fast.c:ZSTD_copy16
Line
Count
Source
183
80.7M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
80.7M
}
zstd_lazy.c:ZSTD_copy16
Line
Count
Source
183
70.6M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
70.6M
}
zstd_ldm.c:ZSTD_copy16
Line
Count
Source
183
8.80M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
8.80M
}
zstd_opt.c:ZSTD_copy16
Line
Count
Source
183
78.6M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
78.6M
}
Unexecuted instantiation: zstd_preSplit.c:ZSTD_copy16
Unexecuted instantiation: zstdmt_compress.c:ZSTD_copy16
Unexecuted instantiation: huf_decompress.c:ZSTD_copy16
Unexecuted instantiation: zstd_ddict.c:ZSTD_copy16
Unexecuted instantiation: zstd_decompress.c:ZSTD_copy16
zstd_decompress_block.c:ZSTD_copy16
Line
Count
Source
183
950M
static void ZSTD_copy16(void* dst, const void* src) {
184
#if defined(ZSTD_ARCH_ARM_NEON)
185
    vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
186
#elif defined(ZSTD_ARCH_X86_SSE2)
187
    _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
188
#elif defined(ZSTD_ARCH_RISCV_RVV)
189
    __riscv_vse8_v_u8m1((uint8_t*)dst, __riscv_vle8_v_u8m1((const uint8_t*)src, 16), 16);
190
#elif defined(__clang__)
191
    ZSTD_memmove(dst, src, 16);
192
#else
193
    /* ZSTD_memmove is not inlined properly by gcc */
194
    BYTE copy16_buf[16];
195
    ZSTD_memcpy(copy16_buf, src, 16);
196
    ZSTD_memcpy(dst, copy16_buf, 16);
197
#endif
198
950M
}
Unexecuted instantiation: cover.c:ZSTD_copy16
Unexecuted instantiation: fastcover.c:ZSTD_copy16
Unexecuted instantiation: zdict.c:ZSTD_copy16
199
743M
#define COPY16(d,s) do { ZSTD_copy16(d,s); d+=16; s+=16; } while (0)
200
201
426M
#define WILDCOPY_OVERLENGTH 32
202
14.1M
#define WILDCOPY_VECLEN 16
203
204
typedef enum {
205
    ZSTD_no_overlap,
206
    ZSTD_overlap_src_before_dst
207
    /*  ZSTD_overlap_dst_before_src, */
208
} ZSTD_overlap_e;
209
210
/*! ZSTD_wildcopy() :
211
 *  Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
212
 *  @param ovtype controls the overlap detection
213
 *         - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
214
 *         - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
215
 *           The src buffer must be before the dst buffer.
216
 */
217
MEM_STATIC FORCE_INLINE_ATTR
218
void ZSTD_wildcopy(void* dst, const void* src, size_t length, ZSTD_overlap_e const ovtype)
219
161M
{
220
161M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
161M
    const BYTE* ip = (const BYTE*)src;
222
161M
    BYTE* op = (BYTE*)dst;
223
161M
    BYTE* const oend = op + length;
224
225
161M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
515M
        do {
228
515M
            COPY8(op, ip);
229
515M
        } while (op < oend);
230
147M
    } else {
231
147M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
147M
        ZSTD_copy16(op, ip);
239
147M
        if (16 >= length) return;
240
35.9M
        op += 16;
241
35.9M
        ip += 16;
242
371M
        do {
243
371M
            COPY16(op, ip);
244
371M
            COPY16(op, ip);
245
371M
        }
246
371M
        while (op < oend);
247
35.9M
    }
248
161M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_wildcopy
Unexecuted instantiation: zstd_common.c:ZSTD_wildcopy
zstd_compress.c:ZSTD_wildcopy
Line
Count
Source
219
1.49M
{
220
1.49M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
1.49M
    const BYTE* ip = (const BYTE*)src;
222
1.49M
    BYTE* op = (BYTE*)dst;
223
1.49M
    BYTE* const oend = op + length;
224
225
1.49M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
0
        do {
228
0
            COPY8(op, ip);
229
0
        } while (op < oend);
230
1.49M
    } else {
231
1.49M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
1.49M
        ZSTD_copy16(op, ip);
239
1.49M
        if (16 >= length) return;
240
820k
        op += 16;
241
820k
        ip += 16;
242
12.7M
        do {
243
12.7M
            COPY16(op, ip);
244
12.7M
            COPY16(op, ip);
245
12.7M
        }
246
12.7M
        while (op < oend);
247
820k
    }
248
1.49M
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_wildcopy
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_wildcopy
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_wildcopy
zstd_double_fast.c:ZSTD_wildcopy
Line
Count
Source
219
1.97M
{
220
1.97M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
1.97M
    const BYTE* ip = (const BYTE*)src;
222
1.97M
    BYTE* op = (BYTE*)dst;
223
1.97M
    BYTE* const oend = op + length;
224
225
1.97M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
0
        do {
228
0
            COPY8(op, ip);
229
0
        } while (op < oend);
230
1.97M
    } else {
231
1.97M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
1.97M
        ZSTD_copy16(op, ip);
239
1.97M
        if (16 >= length) return;
240
1.01M
        op += 16;
241
1.01M
        ip += 16;
242
6.77M
        do {
243
6.77M
            COPY16(op, ip);
244
6.77M
            COPY16(op, ip);
245
6.77M
        }
246
6.77M
        while (op < oend);
247
1.01M
    }
248
1.97M
}
zstd_fast.c:ZSTD_wildcopy
Line
Count
Source
219
2.91M
{
220
2.91M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
2.91M
    const BYTE* ip = (const BYTE*)src;
222
2.91M
    BYTE* op = (BYTE*)dst;
223
2.91M
    BYTE* const oend = op + length;
224
225
2.91M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
0
        do {
228
0
            COPY8(op, ip);
229
0
        } while (op < oend);
230
2.91M
    } else {
231
2.91M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
2.91M
        ZSTD_copy16(op, ip);
239
2.91M
        if (16 >= length) return;
240
1.74M
        op += 16;
241
1.74M
        ip += 16;
242
16.2M
        do {
243
16.2M
            COPY16(op, ip);
244
16.2M
            COPY16(op, ip);
245
16.2M
        }
246
16.2M
        while (op < oend);
247
1.74M
    }
248
2.91M
}
zstd_lazy.c:ZSTD_wildcopy
Line
Count
Source
219
3.43M
{
220
3.43M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
3.43M
    const BYTE* ip = (const BYTE*)src;
222
3.43M
    BYTE* op = (BYTE*)dst;
223
3.43M
    BYTE* const oend = op + length;
224
225
3.43M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
0
        do {
228
0
            COPY8(op, ip);
229
0
        } while (op < oend);
230
3.43M
    } else {
231
3.43M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
3.43M
        ZSTD_copy16(op, ip);
239
3.43M
        if (16 >= length) return;
240
1.68M
        op += 16;
241
1.68M
        ip += 16;
242
9.08M
        do {
243
9.08M
            COPY16(op, ip);
244
9.08M
            COPY16(op, ip);
245
9.08M
        }
246
9.08M
        while (op < oend);
247
1.68M
    }
248
3.43M
}
zstd_ldm.c:ZSTD_wildcopy
Line
Count
Source
219
463k
{
220
463k
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
463k
    const BYTE* ip = (const BYTE*)src;
222
463k
    BYTE* op = (BYTE*)dst;
223
463k
    BYTE* const oend = op + length;
224
225
463k
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
0
        do {
228
0
            COPY8(op, ip);
229
0
        } while (op < oend);
230
463k
    } else {
231
463k
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
463k
        ZSTD_copy16(op, ip);
239
463k
        if (16 >= length) return;
240
192k
        op += 16;
241
192k
        ip += 16;
242
599k
        do {
243
599k
            COPY16(op, ip);
244
599k
            COPY16(op, ip);
245
599k
        }
246
599k
        while (op < oend);
247
192k
    }
248
463k
}
zstd_opt.c:ZSTD_wildcopy
Line
Count
Source
219
2.30M
{
220
2.30M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
2.30M
    const BYTE* ip = (const BYTE*)src;
222
2.30M
    BYTE* op = (BYTE*)dst;
223
2.30M
    BYTE* const oend = op + length;
224
225
2.30M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
0
        do {
228
0
            COPY8(op, ip);
229
0
        } while (op < oend);
230
2.30M
    } else {
231
2.30M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
2.30M
        ZSTD_copy16(op, ip);
239
2.30M
        if (16 >= length) return;
240
1.26M
        op += 16;
241
1.26M
        ip += 16;
242
6.82M
        do {
243
6.82M
            COPY16(op, ip);
244
6.82M
            COPY16(op, ip);
245
6.82M
        }
246
6.82M
        while (op < oend);
247
1.26M
    }
248
2.30M
}
Unexecuted instantiation: zstd_preSplit.c:ZSTD_wildcopy
Unexecuted instantiation: zstdmt_compress.c:ZSTD_wildcopy
Unexecuted instantiation: huf_decompress.c:ZSTD_wildcopy
Unexecuted instantiation: zstd_ddict.c:ZSTD_wildcopy
Unexecuted instantiation: zstd_decompress.c:ZSTD_wildcopy
zstd_decompress_block.c:ZSTD_wildcopy
Line
Count
Source
219
149M
{
220
149M
    ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
221
149M
    const BYTE* ip = (const BYTE*)src;
222
149M
    BYTE* op = (BYTE*)dst;
223
149M
    BYTE* const oend = op + length;
224
225
149M
    if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
        /* Handle short offset copies. */
227
515M
        do {
228
515M
            COPY8(op, ip);
229
515M
        } while (op < oend);
230
135M
    } else {
231
135M
        assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
232
        /* Separate out the first COPY16() call because the copy length is
233
         * almost certain to be short, so the branches have different
234
         * probabilities. Since it is almost certain to be short, only do
235
         * one COPY16() in the first call. Then, do two calls per loop since
236
         * at that point it is more likely to have a high trip count.
237
         */
238
135M
        ZSTD_copy16(op, ip);
239
135M
        if (16 >= length) return;
240
29.2M
        op += 16;
241
29.2M
        ip += 16;
242
319M
        do {
243
319M
            COPY16(op, ip);
244
319M
            COPY16(op, ip);
245
319M
        }
246
319M
        while (op < oend);
247
29.2M
    }
248
149M
}
Unexecuted instantiation: cover.c:ZSTD_wildcopy
Unexecuted instantiation: fastcover.c:ZSTD_wildcopy
Unexecuted instantiation: zdict.c:ZSTD_wildcopy
249
250
MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
251
291M
{
252
291M
    size_t const length = MIN(dstCapacity, srcSize);
253
291M
    if (length > 0) {
254
247M
        ZSTD_memcpy(dst, src, length);
255
247M
    }
256
291M
    return length;
257
291M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_common.c:ZSTD_limitCopy
zstd_compress.c:ZSTD_limitCopy
Line
Count
Source
251
266M
{
252
266M
    size_t const length = MIN(dstCapacity, srcSize);
253
266M
    if (length > 0) {
254
222M
        ZSTD_memcpy(dst, src, length);
255
222M
    }
256
266M
    return length;
257
266M
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_double_fast.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_fast.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_lazy.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_ldm.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_opt.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_preSplit.c:ZSTD_limitCopy
Unexecuted instantiation: zstdmt_compress.c:ZSTD_limitCopy
Unexecuted instantiation: huf_decompress.c:ZSTD_limitCopy
Unexecuted instantiation: zstd_ddict.c:ZSTD_limitCopy
zstd_decompress.c:ZSTD_limitCopy
Line
Count
Source
251
25.1M
{
252
25.1M
    size_t const length = MIN(dstCapacity, srcSize);
253
25.1M
    if (length > 0) {
254
25.1M
        ZSTD_memcpy(dst, src, length);
255
25.1M
    }
256
25.1M
    return length;
257
25.1M
}
Unexecuted instantiation: zstd_decompress_block.c:ZSTD_limitCopy
Unexecuted instantiation: cover.c:ZSTD_limitCopy
Unexecuted instantiation: fastcover.c:ZSTD_limitCopy
Unexecuted instantiation: zdict.c:ZSTD_limitCopy
258
259
/* define "workspace is too large" as this number of times larger than needed */
260
8.19M
#define ZSTD_WORKSPACETOOLARGE_FACTOR 3
261
262
/* when workspace is continuously too large
263
 * during at least this number of times,
264
 * context's memory usage is considered wasteful,
265
 * because it's sized to handle a worst case scenario which rarely happens.
266
 * In which case, resize it down to free some memory */
267
88.6k
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
268
269
/* Controls whether the input/output buffer is buffered or stable. */
270
typedef enum {
271
    ZSTD_bm_buffered = 0,  /* Buffer the input/output */
272
    ZSTD_bm_stable = 1     /* ZSTD_inBuffer/ZSTD_outBuffer is stable */
273
} ZSTD_bufferMode_e;
274
275
276
/*-*******************************************
277
*  Private declarations
278
*********************************************/
279
280
/**
281
 * Contains the compressed frame size and an upper-bound for the decompressed frame size.
282
 * Note: before using `compressedSize`, check for errors using ZSTD_isError().
283
 *       similarly, before using `decompressedBound`, check for errors using:
284
 *          `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
285
 */
286
typedef struct {
287
    size_t nbBlocks;
288
    size_t compressedSize;
289
    unsigned long long decompressedBound;
290
} ZSTD_frameSizeInfo;   /* decompress & legacy */
291
292
/* ZSTD_invalidateRepCodes() :
293
 * ensures next compression will not use repcodes from previous block.
294
 * Note : only works with regular variant;
295
 *        do not use with extDict variant ! */
296
void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx);   /* zstdmt, adaptive_compression (shouldn't get this definition from here) */
297
298
299
typedef struct {
300
    blockType_e blockType;
301
    U32 lastBlock;
302
    U32 origSize;
303
} blockProperties_t;   /* declared here for decompress and fullbench */
304
305
/*! ZSTD_getcBlockSize() :
306
 *  Provides the size of compressed block from block header `src` */
307
/*  Used by: decompress, fullbench */
308
size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
309
                          blockProperties_t* bpPtr);
310
311
/*! ZSTD_decodeSeqHeaders() :
312
 *  decode sequence header from src */
313
/*  Used by: zstd_decompress_block, fullbench */
314
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
315
                       const void* src, size_t srcSize);
316
317
/**
318
 * @returns true iff the CPU supports dynamic BMI2 dispatch.
319
 */
320
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
321
536k
{
322
536k
    ZSTD_cpuid_t cpuid = ZSTD_cpuid();
323
536k
    return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
324
536k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_common.c:ZSTD_cpuSupportsBmi2
zstd_compress.c:ZSTD_cpuSupportsBmi2
Line
Count
Source
321
277k
{
322
277k
    ZSTD_cpuid_t cpuid = ZSTD_cpuid();
323
277k
    return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
324
277k
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_double_fast.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_fast.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_lazy.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_ldm.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_opt.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_preSplit.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstdmt_compress.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: huf_decompress.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zstd_ddict.c:ZSTD_cpuSupportsBmi2
zstd_decompress.c:ZSTD_cpuSupportsBmi2
Line
Count
Source
321
258k
{
322
258k
    ZSTD_cpuid_t cpuid = ZSTD_cpuid();
323
258k
    return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
324
258k
}
Unexecuted instantiation: zstd_decompress_block.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: cover.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: fastcover.c:ZSTD_cpuSupportsBmi2
Unexecuted instantiation: zdict.c:ZSTD_cpuSupportsBmi2
325
326
#endif   /* ZSTD_CCOMMON_H_MODULE */