extzstd 0.3.2 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/contrib/zstd/CHANGELOG +225 -1
- data/contrib/zstd/CONTRIBUTING.md +158 -75
- data/contrib/zstd/LICENSE +4 -4
- data/contrib/zstd/Makefile +106 -69
- data/contrib/zstd/Package.swift +36 -0
- data/contrib/zstd/README.md +64 -36
- data/contrib/zstd/SECURITY.md +15 -0
- data/contrib/zstd/TESTING.md +2 -3
- data/contrib/zstd/lib/BUCK +5 -7
- data/contrib/zstd/lib/Makefile +117 -199
- data/contrib/zstd/lib/README.md +37 -7
- data/contrib/zstd/lib/common/allocations.h +55 -0
- data/contrib/zstd/lib/common/bits.h +200 -0
- data/contrib/zstd/lib/common/bitstream.h +80 -86
- data/contrib/zstd/lib/common/compiler.h +225 -63
- data/contrib/zstd/lib/common/cpu.h +37 -1
- data/contrib/zstd/lib/common/debug.c +7 -1
- data/contrib/zstd/lib/common/debug.h +21 -12
- data/contrib/zstd/lib/common/entropy_common.c +15 -37
- data/contrib/zstd/lib/common/error_private.c +9 -2
- data/contrib/zstd/lib/common/error_private.h +93 -5
- data/contrib/zstd/lib/common/fse.h +12 -87
- data/contrib/zstd/lib/common/fse_decompress.c +37 -117
- data/contrib/zstd/lib/common/huf.h +97 -172
- data/contrib/zstd/lib/common/mem.h +58 -58
- data/contrib/zstd/lib/common/pool.c +38 -17
- data/contrib/zstd/lib/common/pool.h +10 -4
- data/contrib/zstd/lib/common/portability_macros.h +158 -0
- data/contrib/zstd/lib/common/threading.c +74 -14
- data/contrib/zstd/lib/common/threading.h +5 -10
- data/contrib/zstd/lib/common/xxhash.c +6 -814
- data/contrib/zstd/lib/common/xxhash.h +6930 -195
- data/contrib/zstd/lib/common/zstd_common.c +1 -36
- data/contrib/zstd/lib/common/zstd_deps.h +1 -1
- data/contrib/zstd/lib/common/zstd_internal.h +68 -154
- data/contrib/zstd/lib/common/zstd_trace.h +163 -0
- data/contrib/zstd/lib/compress/clevels.h +134 -0
- data/contrib/zstd/lib/compress/fse_compress.c +75 -155
- data/contrib/zstd/lib/compress/hist.c +1 -1
- data/contrib/zstd/lib/compress/hist.h +1 -1
- data/contrib/zstd/lib/compress/huf_compress.c +810 -259
- data/contrib/zstd/lib/compress/zstd_compress.c +2864 -919
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +523 -192
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +251 -412
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/contrib/zstd/lib/compress/zstd_cwksp.h +284 -97
- data/contrib/zstd/lib/compress/zstd_double_fast.c +382 -133
- data/contrib/zstd/lib/compress/zstd_double_fast.h +14 -2
- data/contrib/zstd/lib/compress/zstd_fast.c +732 -260
- data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
- data/contrib/zstd/lib/compress/zstd_lazy.c +1177 -390
- data/contrib/zstd/lib/compress/zstd_lazy.h +129 -14
- data/contrib/zstd/lib/compress/zstd_ldm.c +280 -210
- data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
- data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +516 -285
- data/contrib/zstd/lib/compress/zstd_opt.h +32 -8
- data/contrib/zstd/lib/compress/zstdmt_compress.c +202 -131
- data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
- data/contrib/zstd/lib/decompress/huf_decompress.c +1149 -555
- data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/contrib/zstd/lib/decompress/zstd_decompress.c +583 -106
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1054 -379
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +56 -6
- data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/contrib/zstd/lib/dictBuilder/cover.c +60 -44
- data/contrib/zstd/lib/dictBuilder/cover.h +6 -11
- data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
- data/contrib/zstd/lib/dictBuilder/fastcover.c +26 -18
- data/contrib/zstd/lib/dictBuilder/zdict.c +100 -101
- data/contrib/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/contrib/zstd/lib/legacy/zstd_v01.c +18 -53
- data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +28 -85
- data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +29 -88
- data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +27 -80
- data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v05.c +36 -85
- data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v06.c +44 -96
- data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +37 -92
- data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
- data/contrib/zstd/lib/libzstd.mk +237 -0
- data/contrib/zstd/lib/libzstd.pc.in +4 -3
- data/contrib/zstd/lib/module.modulemap +35 -0
- data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
- data/contrib/zstd/lib/zstd.h +1030 -332
- data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
- data/ext/extconf.rb +26 -7
- data/ext/extzstd.c +51 -24
- data/ext/extzstd.h +33 -6
- data/ext/extzstd_stream.c +74 -31
- data/ext/libzstd_conf.h +0 -1
- data/ext/zstd_decompress_asm.S +1 -0
- metadata +17 -7
- data/contrib/zstd/appveyor.yml +0 -292
- data/ext/depend +0 -2
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -14,7 +14,6 @@
|
|
14
14
|
* Dependencies
|
15
15
|
***************************************/
|
16
16
|
#define ZSTD_DEPS_NEED_MALLOC
|
17
|
-
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
|
18
17
|
#include "error_private.h"
|
19
18
|
#include "zstd_internal.h"
|
20
19
|
|
@@ -47,37 +46,3 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
|
|
47
46
|
/*! ZSTD_getErrorString() :
|
48
47
|
* provides error code string from enum */
|
49
48
|
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
/*=**************************************************************
|
54
|
-
* Custom allocator
|
55
|
-
****************************************************************/
|
56
|
-
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
57
|
-
{
|
58
|
-
if (customMem.customAlloc)
|
59
|
-
return customMem.customAlloc(customMem.opaque, size);
|
60
|
-
return ZSTD_malloc(size);
|
61
|
-
}
|
62
|
-
|
63
|
-
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
64
|
-
{
|
65
|
-
if (customMem.customAlloc) {
|
66
|
-
/* calloc implemented as malloc+memset;
|
67
|
-
* not as efficient as calloc, but next best guess for custom malloc */
|
68
|
-
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
69
|
-
ZSTD_memset(ptr, 0, size);
|
70
|
-
return ptr;
|
71
|
-
}
|
72
|
-
return ZSTD_calloc(1, size);
|
73
|
-
}
|
74
|
-
|
75
|
-
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
|
76
|
-
{
|
77
|
-
if (ptr!=NULL) {
|
78
|
-
if (customMem.customFree)
|
79
|
-
customMem.customFree(customMem.opaque, ptr);
|
80
|
-
else
|
81
|
-
ZSTD_free(ptr);
|
82
|
-
}
|
83
|
-
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -19,10 +19,8 @@
|
|
19
19
|
/*-*************************************
|
20
20
|
* Dependencies
|
21
21
|
***************************************/
|
22
|
-
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
23
|
-
#include <arm_neon.h>
|
24
|
-
#endif
|
25
22
|
#include "compiler.h"
|
23
|
+
#include "cpu.h"
|
26
24
|
#include "mem.h"
|
27
25
|
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
28
26
|
#include "error_private.h"
|
@@ -30,12 +28,16 @@
|
|
30
28
|
#include "../zstd.h"
|
31
29
|
#define FSE_STATIC_LINKING_ONLY
|
32
30
|
#include "fse.h"
|
33
|
-
#define HUF_STATIC_LINKING_ONLY
|
34
31
|
#include "huf.h"
|
35
32
|
#ifndef XXH_STATIC_LINKING_ONLY
|
36
33
|
# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
|
37
34
|
#endif
|
38
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
|
39
41
|
|
40
42
|
#if defined (__cplusplus)
|
41
43
|
extern "C" {
|
@@ -55,81 +57,7 @@ extern "C" {
|
|
55
57
|
#undef MAX
|
56
58
|
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
57
59
|
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Ignore: this is an internal helper.
|
61
|
-
*
|
62
|
-
* This is a helper function to help force C99-correctness during compilation.
|
63
|
-
* Under strict compilation modes, variadic macro arguments can't be empty.
|
64
|
-
* However, variadic function arguments can be. Using a function therefore lets
|
65
|
-
* us statically check that at least one (string) argument was passed,
|
66
|
-
* independent of the compilation flags.
|
67
|
-
*/
|
68
|
-
static INLINE_KEYWORD UNUSED_ATTR
|
69
|
-
void _force_has_format_string(const char *format, ...) {
|
70
|
-
(void)format;
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Ignore: this is an internal helper.
|
75
|
-
*
|
76
|
-
* We want to force this function invocation to be syntactically correct, but
|
77
|
-
* we don't want to force runtime evaluation of its arguments.
|
78
|
-
*/
|
79
|
-
#define _FORCE_HAS_FORMAT_STRING(...) \
|
80
|
-
if (0) { \
|
81
|
-
_force_has_format_string(__VA_ARGS__); \
|
82
|
-
}
|
83
|
-
|
84
|
-
/**
|
85
|
-
* Return the specified error if the condition evaluates to true.
|
86
|
-
*
|
87
|
-
* In debug modes, prints additional information.
|
88
|
-
* In order to do that (particularly, printing the conditional that failed),
|
89
|
-
* this can't just wrap RETURN_ERROR().
|
90
|
-
*/
|
91
|
-
#define RETURN_ERROR_IF(cond, err, ...) \
|
92
|
-
if (cond) { \
|
93
|
-
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
|
94
|
-
__FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
|
95
|
-
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
96
|
-
RAWLOG(3, ": " __VA_ARGS__); \
|
97
|
-
RAWLOG(3, "\n"); \
|
98
|
-
return ERROR(err); \
|
99
|
-
}
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Unconditionally return the specified error.
|
103
|
-
*
|
104
|
-
* In debug modes, prints additional information.
|
105
|
-
*/
|
106
|
-
#define RETURN_ERROR(err, ...) \
|
107
|
-
do { \
|
108
|
-
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
|
109
|
-
__FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
|
110
|
-
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
111
|
-
RAWLOG(3, ": " __VA_ARGS__); \
|
112
|
-
RAWLOG(3, "\n"); \
|
113
|
-
return ERROR(err); \
|
114
|
-
} while(0);
|
115
|
-
|
116
|
-
/**
|
117
|
-
* If the provided expression evaluates to an error code, returns that error code.
|
118
|
-
*
|
119
|
-
* In debug modes, prints additional information.
|
120
|
-
*/
|
121
|
-
#define FORWARD_IF_ERROR(err, ...) \
|
122
|
-
do { \
|
123
|
-
size_t const err_code = (err); \
|
124
|
-
if (ERR_isError(err_code)) { \
|
125
|
-
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
|
126
|
-
__FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
|
127
|
-
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
128
|
-
RAWLOG(3, ": " __VA_ARGS__); \
|
129
|
-
RAWLOG(3, "\n"); \
|
130
|
-
return err_code; \
|
131
|
-
} \
|
132
|
-
} while(0);
|
60
|
+
#define BOUNDED(min,val,max) (MAX(min,MIN(val,max)))
|
133
61
|
|
134
62
|
|
135
63
|
/*-*************************************
|
@@ -138,7 +66,6 @@ void _force_has_format_string(const char *format, ...) {
|
|
138
66
|
#define ZSTD_OPT_NUM (1<<12)
|
139
67
|
|
140
68
|
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
141
|
-
#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
|
142
69
|
static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
143
70
|
|
144
71
|
#define KB *(1 <<10)
|
@@ -165,9 +92,9 @@ typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
|
165
92
|
#define ZSTD_FRAMECHECKSUMSIZE 4
|
166
93
|
|
167
94
|
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
168
|
-
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */
|
95
|
+
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */) /* for a non-null block */
|
96
|
+
#define MIN_LITERALS_FOR_4_STREAMS 6
|
169
97
|
|
170
|
-
#define HufLog 12
|
171
98
|
typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
|
172
99
|
|
173
100
|
#define LONGNBSEQ 0x7F00
|
@@ -175,6 +102,7 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
|
|
175
102
|
#define MINMATCH 3
|
176
103
|
|
177
104
|
#define Litbits 8
|
105
|
+
#define LitHufLog 11
|
178
106
|
#define MaxLit ((1<<Litbits) - 1)
|
179
107
|
#define MaxML 52
|
180
108
|
#define MaxLL 35
|
@@ -185,12 +113,14 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
|
|
185
113
|
#define LLFSELog 9
|
186
114
|
#define OffFSELog 8
|
187
115
|
#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
|
116
|
+
#define MaxMLBits 16
|
117
|
+
#define MaxLLBits 16
|
188
118
|
|
189
119
|
#define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
|
190
120
|
/* Each table cannot take more than #symbols * FSELog bits */
|
191
121
|
#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
|
192
122
|
|
193
|
-
static UNUSED_ATTR const
|
123
|
+
static UNUSED_ATTR const U8 LL_bits[MaxLL+1] = {
|
194
124
|
0, 0, 0, 0, 0, 0, 0, 0,
|
195
125
|
0, 0, 0, 0, 0, 0, 0, 0,
|
196
126
|
1, 1, 1, 1, 2, 2, 3, 3,
|
@@ -207,7 +137,7 @@ static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
|
|
207
137
|
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
208
138
|
static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
209
139
|
|
210
|
-
static UNUSED_ATTR const
|
140
|
+
static UNUSED_ATTR const U8 ML_bits[MaxML+1] = {
|
211
141
|
0, 0, 0, 0, 0, 0, 0, 0,
|
212
142
|
0, 0, 0, 0, 0, 0, 0, 0,
|
213
143
|
0, 0, 0, 0, 0, 0, 0, 0,
|
@@ -242,22 +172,33 @@ static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
|
242
172
|
* Shared functions to include for inlining
|
243
173
|
*********************************************/
|
244
174
|
static void ZSTD_copy8(void* dst, const void* src) {
|
245
|
-
#if
|
175
|
+
#if defined(ZSTD_ARCH_ARM_NEON)
|
246
176
|
vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
|
247
177
|
#else
|
248
178
|
ZSTD_memcpy(dst, src, 8);
|
249
179
|
#endif
|
250
180
|
}
|
181
|
+
#define COPY8(d,s) do { ZSTD_copy8(d,s); d+=8; s+=8; } while (0)
|
251
182
|
|
252
|
-
|
183
|
+
/* Need to use memmove here since the literal buffer can now be located within
|
184
|
+
the dst buffer. In circumstances where the op "catches up" to where the
|
185
|
+
literal buffer is, there can be partial overlaps in this call on the final
|
186
|
+
copy if the literal is being shifted by less than 16 bytes. */
|
253
187
|
static void ZSTD_copy16(void* dst, const void* src) {
|
254
|
-
#if
|
188
|
+
#if defined(ZSTD_ARCH_ARM_NEON)
|
255
189
|
vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
|
190
|
+
#elif defined(ZSTD_ARCH_X86_SSE2)
|
191
|
+
_mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
|
192
|
+
#elif defined(__clang__)
|
193
|
+
ZSTD_memmove(dst, src, 16);
|
256
194
|
#else
|
257
|
-
|
195
|
+
/* ZSTD_memmove is not inlined properly by gcc */
|
196
|
+
BYTE copy16_buf[16];
|
197
|
+
ZSTD_memcpy(copy16_buf, src, 16);
|
198
|
+
ZSTD_memcpy(dst, copy16_buf, 16);
|
258
199
|
#endif
|
259
200
|
}
|
260
|
-
#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
|
201
|
+
#define COPY16(d,s) do { ZSTD_copy16(d,s); d+=16; s+=16; } while (0)
|
261
202
|
|
262
203
|
#define WILDCOPY_OVERLENGTH 32
|
263
204
|
#define WILDCOPY_VECLEN 16
|
@@ -283,12 +224,10 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|
283
224
|
BYTE* op = (BYTE*)dst;
|
284
225
|
BYTE* const oend = op + length;
|
285
226
|
|
286
|
-
assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
|
287
|
-
|
288
227
|
if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
|
289
228
|
/* Handle short offset copies. */
|
290
229
|
do {
|
291
|
-
COPY8(op, ip)
|
230
|
+
COPY8(op, ip);
|
292
231
|
} while (op < oend);
|
293
232
|
} else {
|
294
233
|
assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
|
@@ -298,12 +237,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|
298
237
|
* one COPY16() in the first call. Then, do two calls per loop since
|
299
238
|
* at that point it is more likely to have a high trip count.
|
300
239
|
*/
|
301
|
-
#ifdef __aarch64__
|
302
|
-
do {
|
303
|
-
COPY16(op, ip);
|
304
|
-
}
|
305
|
-
while (op < oend);
|
306
|
-
#else
|
307
240
|
ZSTD_copy16(op, ip);
|
308
241
|
if (16 >= length) return;
|
309
242
|
op += 16;
|
@@ -313,7 +246,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|
313
246
|
COPY16(op, ip);
|
314
247
|
}
|
315
248
|
while (op < oend);
|
316
|
-
#endif
|
317
249
|
}
|
318
250
|
}
|
319
251
|
|
@@ -347,28 +279,35 @@ typedef enum {
|
|
347
279
|
* Private declarations
|
348
280
|
*********************************************/
|
349
281
|
typedef struct seqDef_s {
|
350
|
-
U32
|
282
|
+
U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
|
351
283
|
U16 litLength;
|
352
|
-
U16 matchLength
|
284
|
+
U16 mlBase; /* mlBase == matchLength - MINMATCH */
|
353
285
|
} seqDef;
|
354
286
|
|
287
|
+
/* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
|
288
|
+
typedef enum {
|
289
|
+
ZSTD_llt_none = 0, /* no longLengthType */
|
290
|
+
ZSTD_llt_literalLength = 1, /* represents a long literal */
|
291
|
+
ZSTD_llt_matchLength = 2 /* represents a long match */
|
292
|
+
} ZSTD_longLengthType_e;
|
293
|
+
|
355
294
|
typedef struct {
|
356
295
|
seqDef* sequencesStart;
|
357
296
|
seqDef* sequences; /* ptr to end of sequences */
|
358
|
-
BYTE*
|
359
|
-
BYTE*
|
360
|
-
BYTE*
|
361
|
-
BYTE*
|
362
|
-
BYTE*
|
297
|
+
BYTE* litStart;
|
298
|
+
BYTE* lit; /* ptr to end of literals */
|
299
|
+
BYTE* llCode;
|
300
|
+
BYTE* mlCode;
|
301
|
+
BYTE* ofCode;
|
363
302
|
size_t maxNbSeq;
|
364
303
|
size_t maxNbLit;
|
365
304
|
|
366
|
-
/* longLengthPos and
|
305
|
+
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
367
306
|
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
368
|
-
* the existing value of the litLength or matchLength by 0x10000.
|
307
|
+
* the existing value of the litLength or matchLength by 0x10000.
|
369
308
|
*/
|
370
|
-
|
371
|
-
U32
|
309
|
+
ZSTD_longLengthType_e longLengthType;
|
310
|
+
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
372
311
|
} seqStore_t;
|
373
312
|
|
374
313
|
typedef struct {
|
@@ -378,19 +317,19 @@ typedef struct {
|
|
378
317
|
|
379
318
|
/**
|
380
319
|
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
381
|
-
* indicated by longLengthPos and
|
320
|
+
* indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
|
382
321
|
*/
|
383
322
|
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
384
323
|
{
|
385
324
|
ZSTD_sequenceLength seqLen;
|
386
325
|
seqLen.litLength = seq->litLength;
|
387
|
-
seqLen.matchLength = seq->
|
326
|
+
seqLen.matchLength = seq->mlBase + MINMATCH;
|
388
327
|
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
389
|
-
if (seqStore->
|
390
|
-
seqLen.litLength +=
|
328
|
+
if (seqStore->longLengthType == ZSTD_llt_literalLength) {
|
329
|
+
seqLen.litLength += 0x10000;
|
391
330
|
}
|
392
|
-
if (seqStore->
|
393
|
-
seqLen.matchLength +=
|
331
|
+
if (seqStore->longLengthType == ZSTD_llt_matchLength) {
|
332
|
+
seqLen.matchLength += 0x10000;
|
394
333
|
}
|
395
334
|
}
|
396
335
|
return seqLen;
|
@@ -403,46 +342,13 @@ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore
|
|
403
342
|
* `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
|
404
343
|
*/
|
405
344
|
typedef struct {
|
345
|
+
size_t nbBlocks;
|
406
346
|
size_t compressedSize;
|
407
347
|
unsigned long long decompressedBound;
|
408
348
|
} ZSTD_frameSizeInfo; /* decompress & legacy */
|
409
349
|
|
410
350
|
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
411
|
-
|
412
|
-
|
413
|
-
/* custom memory allocation functions */
|
414
|
-
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
|
415
|
-
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
|
416
|
-
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
|
417
|
-
|
418
|
-
|
419
|
-
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
420
|
-
{
|
421
|
-
assert(val != 0);
|
422
|
-
{
|
423
|
-
# if defined(_MSC_VER) /* Visual */
|
424
|
-
# if STATIC_BMI2 == 1
|
425
|
-
return _lzcnt_u32(val)^31;
|
426
|
-
# else
|
427
|
-
unsigned long r=0;
|
428
|
-
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
429
|
-
# endif
|
430
|
-
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
431
|
-
return __builtin_clz (val) ^ 31;
|
432
|
-
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
433
|
-
return 31 - __CLZ(val);
|
434
|
-
# else /* Software version */
|
435
|
-
static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
|
436
|
-
U32 v = val;
|
437
|
-
v |= v >> 1;
|
438
|
-
v |= v >> 2;
|
439
|
-
v |= v >> 4;
|
440
|
-
v |= v >> 8;
|
441
|
-
v |= v >> 16;
|
442
|
-
return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
|
443
|
-
# endif
|
444
|
-
}
|
445
|
-
}
|
351
|
+
int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
446
352
|
|
447
353
|
|
448
354
|
/* ZSTD_invalidateRepCodes() :
|
@@ -460,16 +366,24 @@ typedef struct {
|
|
460
366
|
|
461
367
|
/*! ZSTD_getcBlockSize() :
|
462
368
|
* Provides the size of compressed block from block header `src` */
|
463
|
-
/*
|
369
|
+
/* Used by: decompress, fullbench */
|
464
370
|
size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
|
465
371
|
blockProperties_t* bpPtr);
|
466
372
|
|
467
373
|
/*! ZSTD_decodeSeqHeaders() :
|
468
374
|
* decode sequence header from src */
|
469
|
-
/*
|
375
|
+
/* Used by: zstd_decompress_block, fullbench */
|
470
376
|
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
471
377
|
const void* src, size_t srcSize);
|
472
378
|
|
379
|
+
/**
|
380
|
+
* @returns true iff the CPU supports dynamic BMI2 dispatch.
|
381
|
+
*/
|
382
|
+
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
|
383
|
+
{
|
384
|
+
ZSTD_cpuid_t cpuid = ZSTD_cpuid();
|
385
|
+
return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
|
386
|
+
}
|
473
387
|
|
474
388
|
#if defined (__cplusplus)
|
475
389
|
}
|
@@ -0,0 +1,163 @@
|
|
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_TRACE_H
|
12
|
+
#define ZSTD_TRACE_H
|
13
|
+
|
14
|
+
#if defined (__cplusplus)
|
15
|
+
extern "C" {
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#include <stddef.h>
|
19
|
+
|
20
|
+
/* weak symbol support
|
21
|
+
* For now, enable conservatively:
|
22
|
+
* - Only GNUC
|
23
|
+
* - Only ELF
|
24
|
+
* - Only x86-64, i386 and aarch64
|
25
|
+
* Also, explicitly disable on platforms known not to work so they aren't
|
26
|
+
* forgotten in the future.
|
27
|
+
*/
|
28
|
+
#if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \
|
29
|
+
defined(__GNUC__) && defined(__ELF__) && \
|
30
|
+
(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(__aarch64__)) && \
|
31
|
+
!defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \
|
32
|
+
!defined(__CYGWIN__) && !defined(_AIX)
|
33
|
+
# define ZSTD_HAVE_WEAK_SYMBOLS 1
|
34
|
+
#else
|
35
|
+
# define ZSTD_HAVE_WEAK_SYMBOLS 0
|
36
|
+
#endif
|
37
|
+
#if ZSTD_HAVE_WEAK_SYMBOLS
|
38
|
+
# define ZSTD_WEAK_ATTR __attribute__((__weak__))
|
39
|
+
#else
|
40
|
+
# define ZSTD_WEAK_ATTR
|
41
|
+
#endif
|
42
|
+
|
43
|
+
/* Only enable tracing when weak symbols are available. */
|
44
|
+
#ifndef ZSTD_TRACE
|
45
|
+
# define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#if ZSTD_TRACE
|
49
|
+
|
50
|
+
struct ZSTD_CCtx_s;
|
51
|
+
struct ZSTD_DCtx_s;
|
52
|
+
struct ZSTD_CCtx_params_s;
|
53
|
+
|
54
|
+
typedef struct {
|
55
|
+
/**
|
56
|
+
* ZSTD_VERSION_NUMBER
|
57
|
+
*
|
58
|
+
* This is guaranteed to be the first member of ZSTD_trace.
|
59
|
+
* Otherwise, this struct is not stable between versions. If
|
60
|
+
* the version number does not match your expectation, you
|
61
|
+
* should not interpret the rest of the struct.
|
62
|
+
*/
|
63
|
+
unsigned version;
|
64
|
+
/**
|
65
|
+
* Non-zero if streaming (de)compression is used.
|
66
|
+
*/
|
67
|
+
unsigned streaming;
|
68
|
+
/**
|
69
|
+
* The dictionary ID.
|
70
|
+
*/
|
71
|
+
unsigned dictionaryID;
|
72
|
+
/**
|
73
|
+
* Is the dictionary cold?
|
74
|
+
* Only set on decompression.
|
75
|
+
*/
|
76
|
+
unsigned dictionaryIsCold;
|
77
|
+
/**
|
78
|
+
* The dictionary size or zero if no dictionary.
|
79
|
+
*/
|
80
|
+
size_t dictionarySize;
|
81
|
+
/**
|
82
|
+
* The uncompressed size of the data.
|
83
|
+
*/
|
84
|
+
size_t uncompressedSize;
|
85
|
+
/**
|
86
|
+
* The compressed size of the data.
|
87
|
+
*/
|
88
|
+
size_t compressedSize;
|
89
|
+
/**
|
90
|
+
* The fully resolved CCtx parameters (NULL on decompression).
|
91
|
+
*/
|
92
|
+
struct ZSTD_CCtx_params_s const* params;
|
93
|
+
/**
|
94
|
+
* The ZSTD_CCtx pointer (NULL on decompression).
|
95
|
+
*/
|
96
|
+
struct ZSTD_CCtx_s const* cctx;
|
97
|
+
/**
|
98
|
+
* The ZSTD_DCtx pointer (NULL on compression).
|
99
|
+
*/
|
100
|
+
struct ZSTD_DCtx_s const* dctx;
|
101
|
+
} ZSTD_Trace;
|
102
|
+
|
103
|
+
/**
|
104
|
+
* A tracing context. It must be 0 when tracing is disabled.
|
105
|
+
* Otherwise, any non-zero value returned by a tracing begin()
|
106
|
+
* function is presented to any subsequent calls to end().
|
107
|
+
*
|
108
|
+
* Any non-zero value is treated as tracing is enabled and not
|
109
|
+
* interpreted by the library.
|
110
|
+
*
|
111
|
+
* Two possible uses are:
|
112
|
+
* * A timestamp for when the begin() function was called.
|
113
|
+
* * A unique key identifying the (de)compression, like the
|
114
|
+
* address of the [dc]ctx pointer if you need to track
|
115
|
+
* more information than just a timestamp.
|
116
|
+
*/
|
117
|
+
typedef unsigned long long ZSTD_TraceCtx;
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Trace the beginning of a compression call.
|
121
|
+
* @param cctx The dctx pointer for the compression.
|
122
|
+
* It can be used as a key to map begin() to end().
|
123
|
+
* @returns Non-zero if tracing is enabled. The return value is
|
124
|
+
* passed to ZSTD_trace_compress_end().
|
125
|
+
*/
|
126
|
+
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(
|
127
|
+
struct ZSTD_CCtx_s const* cctx);
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Trace the end of a compression call.
|
131
|
+
* @param ctx The return value of ZSTD_trace_compress_begin().
|
132
|
+
* @param trace The zstd tracing info.
|
133
|
+
*/
|
134
|
+
ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(
|
135
|
+
ZSTD_TraceCtx ctx,
|
136
|
+
ZSTD_Trace const* trace);
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Trace the beginning of a decompression call.
|
140
|
+
* @param dctx The dctx pointer for the decompression.
|
141
|
+
* It can be used as a key to map begin() to end().
|
142
|
+
* @returns Non-zero if tracing is enabled. The return value is
|
143
|
+
* passed to ZSTD_trace_compress_end().
|
144
|
+
*/
|
145
|
+
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(
|
146
|
+
struct ZSTD_DCtx_s const* dctx);
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Trace the end of a decompression call.
|
150
|
+
* @param ctx The return value of ZSTD_trace_decompress_begin().
|
151
|
+
* @param trace The zstd tracing info.
|
152
|
+
*/
|
153
|
+
ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(
|
154
|
+
ZSTD_TraceCtx ctx,
|
155
|
+
ZSTD_Trace const* trace);
|
156
|
+
|
157
|
+
#endif /* ZSTD_TRACE */
|
158
|
+
|
159
|
+
#if defined (__cplusplus)
|
160
|
+
}
|
161
|
+
#endif
|
162
|
+
|
163
|
+
#endif /* ZSTD_TRACE_H */
|