zstd-ruby 1.4.0.0 → 1.4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/README.md +2 -2
- data/ext/zstdruby/libzstd/Makefile +274 -107
- data/ext/zstdruby/libzstd/README.md +75 -16
- data/ext/zstdruby/libzstd/common/bitstream.h +59 -51
- data/ext/zstdruby/libzstd/common/compiler.h +154 -5
- data/ext/zstdruby/libzstd/common/cpu.h +1 -3
- data/ext/zstdruby/libzstd/common/debug.c +11 -31
- data/ext/zstdruby/libzstd/common/debug.h +22 -49
- data/ext/zstdruby/libzstd/common/entropy_common.c +201 -75
- data/ext/zstdruby/libzstd/common/error_private.c +3 -1
- data/ext/zstdruby/libzstd/common/error_private.h +7 -3
- data/ext/zstdruby/libzstd/common/fse.h +50 -42
- data/ext/zstdruby/libzstd/common/fse_decompress.c +134 -50
- data/ext/zstdruby/libzstd/common/huf.h +41 -38
- data/ext/zstdruby/libzstd/common/mem.h +68 -22
- data/ext/zstdruby/libzstd/common/pool.c +30 -20
- data/ext/zstdruby/libzstd/common/pool.h +3 -3
- data/ext/zstdruby/libzstd/common/threading.c +51 -4
- data/ext/zstdruby/libzstd/common/threading.h +36 -4
- data/ext/zstdruby/libzstd/common/xxhash.c +39 -89
- data/ext/zstdruby/libzstd/common/xxhash.h +12 -32
- data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
- data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
- data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +231 -72
- data/ext/zstdruby/libzstd/common/zstd_trace.c +42 -0
- data/ext/zstdruby/libzstd/common/zstd_trace.h +152 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +47 -63
- data/ext/zstdruby/libzstd/compress/hist.c +41 -63
- data/ext/zstdruby/libzstd/compress/hist.h +13 -33
- data/ext/zstdruby/libzstd/compress/huf_compress.c +288 -172
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +2504 -1626
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +446 -85
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +433 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +849 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +561 -0
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +82 -60
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +106 -80
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +411 -105
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +296 -207
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +14 -3
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +260 -148
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +153 -440
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +29 -110
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +356 -238
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +20 -16
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +3 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +641 -238
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +600 -371
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -5
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +40 -9
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +197 -78
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +52 -7
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +84 -66
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +58 -36
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +60 -31
- data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
- data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +8 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +115 -111
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +28 -14
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +28 -14
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +36 -19
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +122 -107
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +29 -23
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +34 -24
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
- data/ext/zstdruby/libzstd/libzstd.pc.in +2 -1
- data/ext/zstdruby/libzstd/zstd.h +655 -118
- data/lib/zstd-ruby/version.rb +1 -1
- data/zstd-ruby.gemspec +1 -1
- metadata +20 -10
- data/.travis.yml +0 -14
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -76,6 +76,8 @@ typedef enum {
|
|
76
76
|
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
77
77
|
ZSTD_error_frameIndex_tooLarge = 100,
|
78
78
|
ZSTD_error_seekableIO = 102,
|
79
|
+
ZSTD_error_dstBuffer_wrong = 104,
|
80
|
+
ZSTD_error_srcBuffer_wrong = 105,
|
79
81
|
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
80
82
|
} ZSTD_ErrorCode;
|
81
83
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -19,12 +19,15 @@
|
|
19
19
|
/*-*************************************
|
20
20
|
* Dependencies
|
21
21
|
***************************************/
|
22
|
+
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
23
|
+
#include <arm_neon.h>
|
24
|
+
#endif
|
22
25
|
#include "compiler.h"
|
23
26
|
#include "mem.h"
|
24
27
|
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
25
28
|
#include "error_private.h"
|
26
29
|
#define ZSTD_STATIC_LINKING_ONLY
|
27
|
-
#include "zstd.h"
|
30
|
+
#include "../zstd.h"
|
28
31
|
#define FSE_STATIC_LINKING_ONLY
|
29
32
|
#include "fse.h"
|
30
33
|
#define HUF_STATIC_LINKING_ONLY
|
@@ -34,7 +37,6 @@
|
|
34
37
|
#endif
|
35
38
|
#include "xxhash.h" /* XXH_reset, update, digest */
|
36
39
|
|
37
|
-
|
38
40
|
#if defined (__cplusplus)
|
39
41
|
extern "C" {
|
40
42
|
#endif
|
@@ -54,16 +56,43 @@ extern "C" {
|
|
54
56
|
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
55
57
|
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
56
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
|
+
|
57
84
|
/**
|
58
85
|
* Return the specified error if the condition evaluates to true.
|
59
86
|
*
|
60
|
-
* In debug modes, prints additional information.
|
61
|
-
* (particularly, printing the conditional that failed),
|
62
|
-
* RETURN_ERROR().
|
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().
|
63
90
|
*/
|
64
91
|
#define RETURN_ERROR_IF(cond, err, ...) \
|
65
92
|
if (cond) { \
|
66
|
-
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s",
|
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__); \
|
67
96
|
RAWLOG(3, ": " __VA_ARGS__); \
|
68
97
|
RAWLOG(3, "\n"); \
|
69
98
|
return ERROR(err); \
|
@@ -76,7 +105,9 @@ extern "C" {
|
|
76
105
|
*/
|
77
106
|
#define RETURN_ERROR(err, ...) \
|
78
107
|
do { \
|
79
|
-
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s",
|
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__); \
|
80
111
|
RAWLOG(3, ": " __VA_ARGS__); \
|
81
112
|
RAWLOG(3, "\n"); \
|
82
113
|
return ERROR(err); \
|
@@ -91,7 +122,9 @@ extern "C" {
|
|
91
122
|
do { \
|
92
123
|
size_t const err_code = (err); \
|
93
124
|
if (ERR_isError(err_code)) { \
|
94
|
-
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s",
|
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__); \
|
95
128
|
RAWLOG(3, ": " __VA_ARGS__); \
|
96
129
|
RAWLOG(3, "\n"); \
|
97
130
|
return err_code; \
|
@@ -106,7 +139,7 @@ extern "C" {
|
|
106
139
|
|
107
140
|
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
108
141
|
#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
|
109
|
-
static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
142
|
+
static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
110
143
|
|
111
144
|
#define KB *(1 <<10)
|
112
145
|
#define MB *(1 <<20)
|
@@ -120,15 +153,17 @@ static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
|
120
153
|
#define BIT0 1
|
121
154
|
|
122
155
|
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
|
123
|
-
static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
124
|
-
static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
156
|
+
static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
157
|
+
static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
125
158
|
|
126
159
|
#define ZSTD_FRAMEIDSIZE 4 /* magic number size */
|
127
160
|
|
128
161
|
#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
|
129
|
-
static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
162
|
+
static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
130
163
|
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
131
164
|
|
165
|
+
#define ZSTD_FRAMECHECKSUMSIZE 4
|
166
|
+
|
132
167
|
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
133
168
|
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
|
134
169
|
|
@@ -151,97 +186,216 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
|
|
151
186
|
#define OffFSELog 8
|
152
187
|
#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
|
153
188
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
189
|
+
#define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
|
190
|
+
/* Each table cannot take more than #symbols * FSELog bits */
|
191
|
+
#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
|
192
|
+
|
193
|
+
static UNUSED_ATTR const U32 LL_bits[MaxLL+1] = {
|
194
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
195
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
196
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
197
|
+
4, 6, 7, 8, 9,10,11,12,
|
198
|
+
13,14,15,16
|
199
|
+
};
|
200
|
+
static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
|
201
|
+
4, 3, 2, 2, 2, 2, 2, 2,
|
202
|
+
2, 2, 2, 2, 2, 1, 1, 1,
|
203
|
+
2, 2, 2, 2, 2, 2, 2, 2,
|
204
|
+
2, 3, 2, 1, 1, 1, 1, 1,
|
205
|
+
-1,-1,-1,-1
|
206
|
+
};
|
164
207
|
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
165
|
-
static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
166
|
-
|
167
|
-
static const U32 ML_bits[MaxML+1] = {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
208
|
+
static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
209
|
+
|
210
|
+
static UNUSED_ATTR const U32 ML_bits[MaxML+1] = {
|
211
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
212
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
213
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
214
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
215
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
216
|
+
4, 4, 5, 7, 8, 9,10,11,
|
217
|
+
12,13,14,15,16
|
218
|
+
};
|
219
|
+
static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = {
|
220
|
+
1, 4, 3, 2, 2, 2, 2, 2,
|
221
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
222
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
223
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
224
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
225
|
+
1, 1, 1, 1, 1, 1,-1,-1,
|
226
|
+
-1,-1,-1,-1,-1
|
227
|
+
};
|
181
228
|
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
|
182
|
-
static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
183
|
-
|
184
|
-
static const S16 OF_defaultNorm[DefaultMaxOff+1] = {
|
185
|
-
|
186
|
-
|
187
|
-
|
229
|
+
static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
230
|
+
|
231
|
+
static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = {
|
232
|
+
1, 1, 1, 1, 1, 1, 2, 2,
|
233
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
234
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
235
|
+
-1,-1,-1,-1,-1
|
236
|
+
};
|
188
237
|
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
|
189
|
-
static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
238
|
+
static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
190
239
|
|
191
240
|
|
192
241
|
/*-*******************************************
|
193
242
|
* Shared functions to include for inlining
|
194
243
|
*********************************************/
|
195
|
-
static void ZSTD_copy8(void* dst, const void* src) {
|
244
|
+
static void ZSTD_copy8(void* dst, const void* src) {
|
245
|
+
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
246
|
+
vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
|
247
|
+
#else
|
248
|
+
ZSTD_memcpy(dst, src, 8);
|
249
|
+
#endif
|
250
|
+
}
|
251
|
+
|
196
252
|
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
|
253
|
+
static void ZSTD_copy16(void* dst, const void* src) {
|
254
|
+
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
255
|
+
vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
|
256
|
+
#else
|
257
|
+
ZSTD_memcpy(dst, src, 16);
|
258
|
+
#endif
|
259
|
+
}
|
260
|
+
#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
|
261
|
+
|
262
|
+
#define WILDCOPY_OVERLENGTH 32
|
263
|
+
#define WILDCOPY_VECLEN 16
|
264
|
+
|
265
|
+
typedef enum {
|
266
|
+
ZSTD_no_overlap,
|
267
|
+
ZSTD_overlap_src_before_dst
|
268
|
+
/* ZSTD_overlap_dst_before_src, */
|
269
|
+
} ZSTD_overlap_e;
|
197
270
|
|
198
271
|
/*! ZSTD_wildcopy() :
|
199
|
-
*
|
200
|
-
|
201
|
-
|
272
|
+
* Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
|
273
|
+
* @param ovtype controls the overlap detection
|
274
|
+
* - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
|
275
|
+
* - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
|
276
|
+
* The src buffer must be before the dst buffer.
|
277
|
+
*/
|
278
|
+
MEM_STATIC FORCE_INLINE_ATTR
|
279
|
+
void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
|
202
280
|
{
|
281
|
+
ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
|
203
282
|
const BYTE* ip = (const BYTE*)src;
|
204
283
|
BYTE* op = (BYTE*)dst;
|
205
284
|
BYTE* const oend = op + length;
|
206
|
-
|
207
|
-
|
208
|
-
|
285
|
+
|
286
|
+
assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
|
287
|
+
|
288
|
+
if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
|
289
|
+
/* Handle short offset copies. */
|
290
|
+
do {
|
291
|
+
COPY8(op, ip)
|
292
|
+
} while (op < oend);
|
293
|
+
} else {
|
294
|
+
assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
|
295
|
+
/* Separate out the first COPY16() call because the copy length is
|
296
|
+
* almost certain to be short, so the branches have different
|
297
|
+
* probabilities. Since it is almost certain to be short, only do
|
298
|
+
* one COPY16() in the first call. Then, do two calls per loop since
|
299
|
+
* at that point it is more likely to have a high trip count.
|
300
|
+
*/
|
301
|
+
#ifdef __aarch64__
|
302
|
+
do {
|
303
|
+
COPY16(op, ip);
|
304
|
+
}
|
305
|
+
while (op < oend);
|
306
|
+
#else
|
307
|
+
ZSTD_copy16(op, ip);
|
308
|
+
if (16 >= length) return;
|
309
|
+
op += 16;
|
310
|
+
ip += 16;
|
311
|
+
do {
|
312
|
+
COPY16(op, ip);
|
313
|
+
COPY16(op, ip);
|
314
|
+
}
|
315
|
+
while (op < oend);
|
316
|
+
#endif
|
317
|
+
}
|
209
318
|
}
|
210
319
|
|
211
|
-
MEM_STATIC
|
320
|
+
MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
212
321
|
{
|
213
|
-
const
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
while (op < oend);
|
322
|
+
size_t const length = MIN(dstCapacity, srcSize);
|
323
|
+
if (length > 0) {
|
324
|
+
ZSTD_memcpy(dst, src, length);
|
325
|
+
}
|
326
|
+
return length;
|
219
327
|
}
|
220
328
|
|
329
|
+
/* define "workspace is too large" as this number of times larger than needed */
|
330
|
+
#define ZSTD_WORKSPACETOOLARGE_FACTOR 3
|
331
|
+
|
332
|
+
/* when workspace is continuously too large
|
333
|
+
* during at least this number of times,
|
334
|
+
* context's memory usage is considered wasteful,
|
335
|
+
* because it's sized to handle a worst case scenario which rarely happens.
|
336
|
+
* In which case, resize it down to free some memory */
|
337
|
+
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
|
338
|
+
|
339
|
+
/* Controls whether the input/output buffer is buffered or stable. */
|
340
|
+
typedef enum {
|
341
|
+
ZSTD_bm_buffered = 0, /* Buffer the input/output */
|
342
|
+
ZSTD_bm_stable = 1 /* ZSTD_inBuffer/ZSTD_outBuffer is stable */
|
343
|
+
} ZSTD_bufferMode_e;
|
344
|
+
|
221
345
|
|
222
346
|
/*-*******************************************
|
223
347
|
* Private declarations
|
224
348
|
*********************************************/
|
225
349
|
typedef struct seqDef_s {
|
226
|
-
U32 offset;
|
350
|
+
U32 offset; /* Offset code of the sequence */
|
227
351
|
U16 litLength;
|
228
352
|
U16 matchLength;
|
229
353
|
} seqDef;
|
230
354
|
|
231
355
|
typedef struct {
|
232
356
|
seqDef* sequencesStart;
|
233
|
-
seqDef* sequences;
|
357
|
+
seqDef* sequences; /* ptr to end of sequences */
|
234
358
|
BYTE* litStart;
|
235
|
-
BYTE* lit;
|
359
|
+
BYTE* lit; /* ptr to end of literals */
|
236
360
|
BYTE* llCode;
|
237
361
|
BYTE* mlCode;
|
238
362
|
BYTE* ofCode;
|
239
363
|
size_t maxNbSeq;
|
240
364
|
size_t maxNbLit;
|
241
|
-
|
242
|
-
|
365
|
+
|
366
|
+
/* longLengthPos and longLengthID to allow us to represent either a single litLength or matchLength
|
367
|
+
* 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.
|
369
|
+
*/
|
370
|
+
U32 longLengthID; /* 0 == no longLength; 1 == Represent the long literal; 2 == Represent the long match; */
|
371
|
+
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
243
372
|
} seqStore_t;
|
244
373
|
|
374
|
+
typedef struct {
|
375
|
+
U32 litLength;
|
376
|
+
U32 matchLength;
|
377
|
+
} ZSTD_sequenceLength;
|
378
|
+
|
379
|
+
/**
|
380
|
+
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
381
|
+
* indicated by longLengthPos and longLengthID, and adds MINMATCH back to matchLength.
|
382
|
+
*/
|
383
|
+
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
384
|
+
{
|
385
|
+
ZSTD_sequenceLength seqLen;
|
386
|
+
seqLen.litLength = seq->litLength;
|
387
|
+
seqLen.matchLength = seq->matchLength + MINMATCH;
|
388
|
+
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
389
|
+
if (seqStore->longLengthID == 1) {
|
390
|
+
seqLen.litLength += 0xFFFF;
|
391
|
+
}
|
392
|
+
if (seqStore->longLengthID == 2) {
|
393
|
+
seqLen.matchLength += 0xFFFF;
|
394
|
+
}
|
395
|
+
}
|
396
|
+
return seqLen;
|
397
|
+
}
|
398
|
+
|
245
399
|
/**
|
246
400
|
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
247
401
|
* Note: before using `compressedSize`, check for errors using ZSTD_isError().
|
@@ -257,9 +411,9 @@ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBu
|
|
257
411
|
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
258
412
|
|
259
413
|
/* custom memory allocation functions */
|
260
|
-
void*
|
261
|
-
void*
|
262
|
-
void
|
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);
|
263
417
|
|
264
418
|
|
265
419
|
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
@@ -267,11 +421,16 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
|
|
267
421
|
assert(val != 0);
|
268
422
|
{
|
269
423
|
# if defined(_MSC_VER) /* Visual */
|
270
|
-
|
271
|
-
|
272
|
-
|
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
|
273
430
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
274
|
-
return
|
431
|
+
return __builtin_clz (val) ^ 31;
|
432
|
+
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
433
|
+
return 31 - __CLZ(val);
|
275
434
|
# else /* Software version */
|
276
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 };
|
277
436
|
U32 v = val;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-2021, Facebook, Inc.
|
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
|
+
#include "zstd_trace.h"
|
12
|
+
#include "../zstd.h"
|
13
|
+
|
14
|
+
#include "compiler.h"
|
15
|
+
|
16
|
+
#if ZSTD_TRACE && ZSTD_HAVE_WEAK_SYMBOLS
|
17
|
+
|
18
|
+
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(ZSTD_CCtx const* cctx)
|
19
|
+
{
|
20
|
+
(void)cctx;
|
21
|
+
return 0;
|
22
|
+
}
|
23
|
+
|
24
|
+
ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(ZSTD_TraceCtx ctx, ZSTD_Trace const* trace)
|
25
|
+
{
|
26
|
+
(void)ctx;
|
27
|
+
(void)trace;
|
28
|
+
}
|
29
|
+
|
30
|
+
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(ZSTD_DCtx const* dctx)
|
31
|
+
{
|
32
|
+
(void)dctx;
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(ZSTD_TraceCtx ctx, ZSTD_Trace const* trace)
|
37
|
+
{
|
38
|
+
(void)ctx;
|
39
|
+
(void)trace;
|
40
|
+
}
|
41
|
+
|
42
|
+
#endif
|