zstd-ruby 1.4.5.0 → 1.5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/ruby.yml +35 -0
- data/README.md +2 -2
- data/ext/zstdruby/extconf.rb +2 -1
- data/ext/zstdruby/libzstd/BUCK +5 -7
- data/ext/zstdruby/libzstd/Makefile +225 -222
- data/ext/zstdruby/libzstd/README.md +43 -5
- data/ext/zstdruby/libzstd/common/bitstream.h +46 -22
- data/ext/zstdruby/libzstd/common/compiler.h +182 -22
- data/ext/zstdruby/libzstd/common/cpu.h +1 -3
- data/ext/zstdruby/libzstd/common/debug.c +1 -1
- data/ext/zstdruby/libzstd/common/debug.h +12 -19
- data/ext/zstdruby/libzstd/common/entropy_common.c +196 -44
- data/ext/zstdruby/libzstd/common/error_private.c +2 -1
- data/ext/zstdruby/libzstd/common/error_private.h +82 -3
- data/ext/zstdruby/libzstd/common/fse.h +41 -12
- data/ext/zstdruby/libzstd/common/fse_decompress.c +139 -22
- data/ext/zstdruby/libzstd/common/huf.h +47 -23
- data/ext/zstdruby/libzstd/common/mem.h +87 -98
- data/ext/zstdruby/libzstd/common/pool.c +23 -17
- data/ext/zstdruby/libzstd/common/pool.h +2 -2
- data/ext/zstdruby/libzstd/common/portability_macros.h +131 -0
- data/ext/zstdruby/libzstd/common/threading.c +6 -5
- data/ext/zstdruby/libzstd/common/xxhash.c +6 -846
- data/ext/zstdruby/libzstd/common/xxhash.h +5568 -167
- 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_internal.h +189 -142
- data/ext/zstdruby/libzstd/common/zstd_trace.h +163 -0
- data/ext/zstdruby/libzstd/compress/clevels.h +134 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +89 -46
- data/ext/zstdruby/libzstd/compress/hist.c +27 -29
- data/ext/zstdruby/libzstd/compress/hist.h +2 -2
- data/ext/zstdruby/libzstd/compress/huf_compress.c +770 -198
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +2894 -863
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +390 -90
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +12 -11
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +4 -2
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +31 -8
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -297
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +206 -69
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +307 -132
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +322 -143
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +1136 -174
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +59 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +316 -213
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +9 -2
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +106 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +373 -150
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +152 -444
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +31 -113
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +1044 -403
- data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +571 -0
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +9 -9
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +450 -105
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +913 -273
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +14 -5
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +59 -12
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +24 -4
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +55 -38
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +7 -6
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +43 -34
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +128 -58
- data/ext/zstdruby/libzstd/dll/example/Makefile +1 -1
- data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +8 -8
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +9 -9
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +9 -9
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +10 -10
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +13 -13
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +13 -13
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +13 -13
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
- data/ext/zstdruby/libzstd/libzstd.mk +185 -0
- data/ext/zstdruby/libzstd/libzstd.pc.in +4 -3
- data/ext/zstdruby/libzstd/modulemap/module.modulemap +4 -0
- data/ext/zstdruby/libzstd/{dictBuilder/zdict.h → zdict.h} +154 -7
- data/ext/zstdruby/libzstd/zstd.h +699 -214
- data/ext/zstdruby/libzstd/{common/zstd_errors.h → zstd_errors.h} +2 -1
- data/ext/zstdruby/zstdruby.c +2 -2
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +15 -6
- data/.travis.yml +0 -14
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) 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
|
@@ -28,7 +28,6 @@
|
|
28
28
|
extern "C" {
|
29
29
|
#endif
|
30
30
|
|
31
|
-
|
32
31
|
/*-*************************************
|
33
32
|
* Constants
|
34
33
|
***************************************/
|
@@ -64,7 +63,7 @@ typedef struct {
|
|
64
63
|
} ZSTD_localDict;
|
65
64
|
|
66
65
|
typedef struct {
|
67
|
-
|
66
|
+
HUF_CElt CTable[HUF_CTABLE_SIZE_ST(255)];
|
68
67
|
HUF_repeat repeatMode;
|
69
68
|
} ZSTD_hufCTables_t;
|
70
69
|
|
@@ -82,11 +81,75 @@ typedef struct {
|
|
82
81
|
ZSTD_fseCTables_t fse;
|
83
82
|
} ZSTD_entropyCTables_t;
|
84
83
|
|
84
|
+
/***********************************************
|
85
|
+
* Entropy buffer statistics structs and funcs *
|
86
|
+
***********************************************/
|
87
|
+
/** ZSTD_hufCTablesMetadata_t :
|
88
|
+
* Stores Literals Block Type for a super-block in hType, and
|
89
|
+
* huffman tree description in hufDesBuffer.
|
90
|
+
* hufDesSize refers to the size of huffman tree description in bytes.
|
91
|
+
* This metadata is populated in ZSTD_buildBlockEntropyStats_literals() */
|
85
92
|
typedef struct {
|
86
|
-
|
87
|
-
|
93
|
+
symbolEncodingType_e hType;
|
94
|
+
BYTE hufDesBuffer[ZSTD_MAX_HUF_HEADER_SIZE];
|
95
|
+
size_t hufDesSize;
|
96
|
+
} ZSTD_hufCTablesMetadata_t;
|
97
|
+
|
98
|
+
/** ZSTD_fseCTablesMetadata_t :
|
99
|
+
* Stores symbol compression modes for a super-block in {ll, ol, ml}Type, and
|
100
|
+
* fse tables in fseTablesBuffer.
|
101
|
+
* fseTablesSize refers to the size of fse tables in bytes.
|
102
|
+
* This metadata is populated in ZSTD_buildBlockEntropyStats_sequences() */
|
103
|
+
typedef struct {
|
104
|
+
symbolEncodingType_e llType;
|
105
|
+
symbolEncodingType_e ofType;
|
106
|
+
symbolEncodingType_e mlType;
|
107
|
+
BYTE fseTablesBuffer[ZSTD_MAX_FSE_HEADERS_SIZE];
|
108
|
+
size_t fseTablesSize;
|
109
|
+
size_t lastCountSize; /* This is to account for bug in 1.3.4. More detail in ZSTD_entropyCompressSeqStore_internal() */
|
110
|
+
} ZSTD_fseCTablesMetadata_t;
|
111
|
+
|
112
|
+
typedef struct {
|
113
|
+
ZSTD_hufCTablesMetadata_t hufMetadata;
|
114
|
+
ZSTD_fseCTablesMetadata_t fseMetadata;
|
115
|
+
} ZSTD_entropyCTablesMetadata_t;
|
116
|
+
|
117
|
+
/** ZSTD_buildBlockEntropyStats() :
|
118
|
+
* Builds entropy for the block.
|
119
|
+
* @return : 0 on success or error code */
|
120
|
+
size_t ZSTD_buildBlockEntropyStats(seqStore_t* seqStorePtr,
|
121
|
+
const ZSTD_entropyCTables_t* prevEntropy,
|
122
|
+
ZSTD_entropyCTables_t* nextEntropy,
|
123
|
+
const ZSTD_CCtx_params* cctxParams,
|
124
|
+
ZSTD_entropyCTablesMetadata_t* entropyMetadata,
|
125
|
+
void* workspace, size_t wkspSize);
|
126
|
+
|
127
|
+
/*********************************
|
128
|
+
* Compression internals structs *
|
129
|
+
*********************************/
|
130
|
+
|
131
|
+
typedef struct {
|
132
|
+
U32 off; /* Offset code (offset + ZSTD_REP_MOVE) for the match */
|
133
|
+
U32 len; /* Raw length of match */
|
88
134
|
} ZSTD_match_t;
|
89
135
|
|
136
|
+
typedef struct {
|
137
|
+
U32 offset; /* Offset of sequence */
|
138
|
+
U32 litLength; /* Length of literals prior to match */
|
139
|
+
U32 matchLength; /* Raw length of match */
|
140
|
+
} rawSeq;
|
141
|
+
|
142
|
+
typedef struct {
|
143
|
+
rawSeq* seq; /* The start of the sequences */
|
144
|
+
size_t pos; /* The index in seq where reading stopped. pos <= size. */
|
145
|
+
size_t posInSequence; /* The position within the sequence at seq[pos] where reading
|
146
|
+
stopped. posInSequence <= seq[pos].litLength + seq[pos].matchLength */
|
147
|
+
size_t size; /* The number of sequences. <= capacity. */
|
148
|
+
size_t capacity; /* The capacity starting from `seq` pointer */
|
149
|
+
} rawSeqStore_t;
|
150
|
+
|
151
|
+
UNUSED_ATTR static const rawSeqStore_t kNullRawSeqStore = {NULL, 0, 0, 0, 0};
|
152
|
+
|
90
153
|
typedef struct {
|
91
154
|
int price;
|
92
155
|
U32 off;
|
@@ -116,7 +179,7 @@ typedef struct {
|
|
116
179
|
U32 offCodeSumBasePrice; /* to compare to log2(offreq) */
|
117
180
|
ZSTD_OptPrice_e priceType; /* prices can be determined dynamically, or follow a pre-defined cost structure */
|
118
181
|
const ZSTD_entropyCTables_t* symbolCosts; /* pre-calculated dictionary statistics */
|
119
|
-
|
182
|
+
ZSTD_paramSwitch_e literalCompressionMode;
|
120
183
|
} optState_t;
|
121
184
|
|
122
185
|
typedef struct {
|
@@ -125,14 +188,23 @@ typedef struct {
|
|
125
188
|
} ZSTD_compressedBlockState_t;
|
126
189
|
|
127
190
|
typedef struct {
|
128
|
-
BYTE const* nextSrc;
|
129
|
-
BYTE const* base;
|
130
|
-
BYTE const* dictBase;
|
131
|
-
U32 dictLimit;
|
132
|
-
U32 lowLimit;
|
191
|
+
BYTE const* nextSrc; /* next block here to continue on current prefix */
|
192
|
+
BYTE const* base; /* All regular indexes relative to this position */
|
193
|
+
BYTE const* dictBase; /* extDict indexes relative to this position */
|
194
|
+
U32 dictLimit; /* below that point, need extDict */
|
195
|
+
U32 lowLimit; /* below that point, no more valid data */
|
196
|
+
U32 nbOverflowCorrections; /* Number of times overflow correction has run since
|
197
|
+
* ZSTD_window_init(). Useful for debugging coredumps
|
198
|
+
* and for ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY.
|
199
|
+
*/
|
133
200
|
} ZSTD_window_t;
|
134
201
|
|
202
|
+
#define ZSTD_WINDOW_START_INDEX 2
|
203
|
+
|
135
204
|
typedef struct ZSTD_matchState_t ZSTD_matchState_t;
|
205
|
+
|
206
|
+
#define ZSTD_ROW_HASH_CACHE_SIZE 8 /* Size of prefetching hash cache for row-based matchfinder */
|
207
|
+
|
136
208
|
struct ZSTD_matchState_t {
|
137
209
|
ZSTD_window_t window; /* State for window round buffer management */
|
138
210
|
U32 loadedDictEnd; /* index of end of dictionary, within context's referential.
|
@@ -144,12 +216,24 @@ struct ZSTD_matchState_t {
|
|
144
216
|
*/
|
145
217
|
U32 nextToUpdate; /* index from which to continue table update */
|
146
218
|
U32 hashLog3; /* dispatch table for matches of len==3 : larger == faster, more memory */
|
219
|
+
|
220
|
+
U32 rowHashLog; /* For row-based matchfinder: Hashlog based on nb of rows in the hashTable.*/
|
221
|
+
U16* tagTable; /* For row-based matchFinder: A row-based table containing the hashes and head index. */
|
222
|
+
U32 hashCache[ZSTD_ROW_HASH_CACHE_SIZE]; /* For row-based matchFinder: a cache of hashes to improve speed */
|
223
|
+
|
147
224
|
U32* hashTable;
|
148
225
|
U32* hashTable3;
|
149
226
|
U32* chainTable;
|
227
|
+
|
228
|
+
U32 forceNonContiguous; /* Non-zero if we should force non-contiguous load for the next window update. */
|
229
|
+
|
230
|
+
int dedicatedDictSearch; /* Indicates whether this matchState is using the
|
231
|
+
* dedicated dictionary search structure.
|
232
|
+
*/
|
150
233
|
optState_t opt; /* optimal parser state */
|
151
234
|
const ZSTD_matchState_t* dictMatchState;
|
152
235
|
ZSTD_compressionParameters cParams;
|
236
|
+
const rawSeqStore_t* ldmSeqStore;
|
153
237
|
};
|
154
238
|
|
155
239
|
typedef struct {
|
@@ -163,17 +247,26 @@ typedef struct {
|
|
163
247
|
U32 checksum;
|
164
248
|
} ldmEntry_t;
|
165
249
|
|
250
|
+
typedef struct {
|
251
|
+
BYTE const* split;
|
252
|
+
U32 hash;
|
253
|
+
U32 checksum;
|
254
|
+
ldmEntry_t* bucket;
|
255
|
+
} ldmMatchCandidate_t;
|
256
|
+
|
257
|
+
#define LDM_BATCH_SIZE 64
|
258
|
+
|
166
259
|
typedef struct {
|
167
260
|
ZSTD_window_t window; /* State for the window round buffer management */
|
168
261
|
ldmEntry_t* hashTable;
|
169
262
|
U32 loadedDictEnd;
|
170
263
|
BYTE* bucketOffsets; /* Next position in bucket to insert entry */
|
171
|
-
|
172
|
-
|
264
|
+
size_t splitIndices[LDM_BATCH_SIZE];
|
265
|
+
ldmMatchCandidate_t matchCandidates[LDM_BATCH_SIZE];
|
173
266
|
} ldmState_t;
|
174
267
|
|
175
268
|
typedef struct {
|
176
|
-
|
269
|
+
ZSTD_paramSwitch_e enableLdm; /* ZSTD_ps_enable to enable LDM. ZSTD_ps_auto by default */
|
177
270
|
U32 hashLog; /* Log size of hashTable */
|
178
271
|
U32 bucketSizeLog; /* Log bucket size for collision resolution, at most 8 */
|
179
272
|
U32 minMatchLength; /* Minimum match length */
|
@@ -181,19 +274,6 @@ typedef struct {
|
|
181
274
|
U32 windowLog; /* Window log for the LDM */
|
182
275
|
} ldmParams_t;
|
183
276
|
|
184
|
-
typedef struct {
|
185
|
-
U32 offset;
|
186
|
-
U32 litLength;
|
187
|
-
U32 matchLength;
|
188
|
-
} rawSeq;
|
189
|
-
|
190
|
-
typedef struct {
|
191
|
-
rawSeq* seq; /* The start of the sequences */
|
192
|
-
size_t pos; /* The position where reading stopped. <= size. */
|
193
|
-
size_t size; /* The number of sequences. <= capacity. */
|
194
|
-
size_t capacity; /* The capacity starting from `seq` pointer */
|
195
|
-
} rawSeqStore_t;
|
196
|
-
|
197
277
|
typedef struct {
|
198
278
|
int collectSequences;
|
199
279
|
ZSTD_Sequence* seqStart;
|
@@ -217,7 +297,7 @@ struct ZSTD_CCtx_params_s {
|
|
217
297
|
* There is no guarantee that hint is close to actual source size */
|
218
298
|
|
219
299
|
ZSTD_dictAttachPref_e attachDictPref;
|
220
|
-
|
300
|
+
ZSTD_paramSwitch_e literalCompressionMode;
|
221
301
|
|
222
302
|
/* Multithreading: used to pass parameters to mtctx */
|
223
303
|
int nbWorkers;
|
@@ -228,17 +308,68 @@ struct ZSTD_CCtx_params_s {
|
|
228
308
|
/* Long distance matching parameters */
|
229
309
|
ldmParams_t ldmParams;
|
230
310
|
|
311
|
+
/* Dedicated dict search algorithm trigger */
|
312
|
+
int enableDedicatedDictSearch;
|
313
|
+
|
314
|
+
/* Input/output buffer modes */
|
315
|
+
ZSTD_bufferMode_e inBufferMode;
|
316
|
+
ZSTD_bufferMode_e outBufferMode;
|
317
|
+
|
318
|
+
/* Sequence compression API */
|
319
|
+
ZSTD_sequenceFormat_e blockDelimiters;
|
320
|
+
int validateSequences;
|
321
|
+
|
322
|
+
/* Block splitting */
|
323
|
+
ZSTD_paramSwitch_e useBlockSplitter;
|
324
|
+
|
325
|
+
/* Param for deciding whether to use row-based matchfinder */
|
326
|
+
ZSTD_paramSwitch_e useRowMatchFinder;
|
327
|
+
|
328
|
+
/* Always load a dictionary in ext-dict mode (not prefix mode)? */
|
329
|
+
int deterministicRefPrefix;
|
330
|
+
|
231
331
|
/* Internal use, for createCCtxParams() and freeCCtxParams() only */
|
232
332
|
ZSTD_customMem customMem;
|
233
333
|
}; /* typedef'd to ZSTD_CCtx_params within "zstd.h" */
|
234
334
|
|
335
|
+
#define COMPRESS_SEQUENCES_WORKSPACE_SIZE (sizeof(unsigned) * (MaxSeq + 2))
|
336
|
+
#define ENTROPY_WORKSPACE_SIZE (HUF_WORKSPACE_SIZE + COMPRESS_SEQUENCES_WORKSPACE_SIZE)
|
337
|
+
|
338
|
+
/**
|
339
|
+
* Indicates whether this compression proceeds directly from user-provided
|
340
|
+
* source buffer to user-provided destination buffer (ZSTDb_not_buffered), or
|
341
|
+
* whether the context needs to buffer the input/output (ZSTDb_buffered).
|
342
|
+
*/
|
343
|
+
typedef enum {
|
344
|
+
ZSTDb_not_buffered,
|
345
|
+
ZSTDb_buffered
|
346
|
+
} ZSTD_buffered_policy_e;
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Struct that contains all elements of block splitter that should be allocated
|
350
|
+
* in a wksp.
|
351
|
+
*/
|
352
|
+
#define ZSTD_MAX_NB_BLOCK_SPLITS 196
|
353
|
+
typedef struct {
|
354
|
+
seqStore_t fullSeqStoreChunk;
|
355
|
+
seqStore_t firstHalfSeqStore;
|
356
|
+
seqStore_t secondHalfSeqStore;
|
357
|
+
seqStore_t currSeqStore;
|
358
|
+
seqStore_t nextSeqStore;
|
359
|
+
|
360
|
+
U32 partitions[ZSTD_MAX_NB_BLOCK_SPLITS];
|
361
|
+
ZSTD_entropyCTablesMetadata_t entropyMetadata;
|
362
|
+
} ZSTD_blockSplitCtx;
|
363
|
+
|
235
364
|
struct ZSTD_CCtx_s {
|
236
365
|
ZSTD_compressionStage_e stage;
|
237
366
|
int cParamsChanged; /* == 1 if cParams(except wlog) or compression level are changed in requestedParams. Triggers transmission of new params to ZSTDMT (if available) then reset to 0. */
|
238
367
|
int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
|
239
368
|
ZSTD_CCtx_params requestedParams;
|
240
369
|
ZSTD_CCtx_params appliedParams;
|
370
|
+
ZSTD_CCtx_params simpleApiParams; /* Param storage used by the simple API - not sticky. Must only be used in top-level simple API functions for storage. */
|
241
371
|
U32 dictID;
|
372
|
+
size_t dictContentSize;
|
242
373
|
|
243
374
|
ZSTD_cwksp workspace; /* manages buffer for dynamic allocations */
|
244
375
|
size_t blockSize;
|
@@ -247,6 +378,7 @@ struct ZSTD_CCtx_s {
|
|
247
378
|
unsigned long long producedCSize;
|
248
379
|
XXH64_state_t xxhState;
|
249
380
|
ZSTD_customMem customMem;
|
381
|
+
ZSTD_threadPool* pool;
|
250
382
|
size_t staticSize;
|
251
383
|
SeqCollector seqCollector;
|
252
384
|
int isFirstBlock;
|
@@ -258,7 +390,10 @@ struct ZSTD_CCtx_s {
|
|
258
390
|
size_t maxNbLdmSequences;
|
259
391
|
rawSeqStore_t externSeqStore; /* Mutable reference to external sequences */
|
260
392
|
ZSTD_blockState_t blockState;
|
261
|
-
U32* entropyWorkspace; /* entropy workspace of
|
393
|
+
U32* entropyWorkspace; /* entropy workspace of ENTROPY_WORKSPACE_SIZE bytes */
|
394
|
+
|
395
|
+
/* Whether we are streaming or not */
|
396
|
+
ZSTD_buffered_policy_e bufferedPolicy;
|
262
397
|
|
263
398
|
/* streaming */
|
264
399
|
char* inBuff;
|
@@ -273,6 +408,10 @@ struct ZSTD_CCtx_s {
|
|
273
408
|
ZSTD_cStreamStage streamStage;
|
274
409
|
U32 frameEnded;
|
275
410
|
|
411
|
+
/* Stable in/out buffer verification */
|
412
|
+
ZSTD_inBuffer expectedInBuffer;
|
413
|
+
size_t expectedOutBufferSize;
|
414
|
+
|
276
415
|
/* Dictionary */
|
277
416
|
ZSTD_localDict localDict;
|
278
417
|
const ZSTD_CDict* cdict;
|
@@ -282,17 +421,49 @@ struct ZSTD_CCtx_s {
|
|
282
421
|
#ifdef ZSTD_MULTITHREAD
|
283
422
|
ZSTDMT_CCtx* mtctx;
|
284
423
|
#endif
|
424
|
+
|
425
|
+
/* Tracing */
|
426
|
+
#if ZSTD_TRACE
|
427
|
+
ZSTD_TraceCtx traceCtx;
|
428
|
+
#endif
|
429
|
+
|
430
|
+
/* Workspace for block splitter */
|
431
|
+
ZSTD_blockSplitCtx blockSplitCtx;
|
285
432
|
};
|
286
433
|
|
287
434
|
typedef enum { ZSTD_dtlm_fast, ZSTD_dtlm_full } ZSTD_dictTableLoadMethod_e;
|
288
435
|
|
289
|
-
typedef enum {
|
290
|
-
|
436
|
+
typedef enum {
|
437
|
+
ZSTD_noDict = 0,
|
438
|
+
ZSTD_extDict = 1,
|
439
|
+
ZSTD_dictMatchState = 2,
|
440
|
+
ZSTD_dedicatedDictSearch = 3
|
441
|
+
} ZSTD_dictMode_e;
|
442
|
+
|
443
|
+
typedef enum {
|
444
|
+
ZSTD_cpm_noAttachDict = 0, /* Compression with ZSTD_noDict or ZSTD_extDict.
|
445
|
+
* In this mode we use both the srcSize and the dictSize
|
446
|
+
* when selecting and adjusting parameters.
|
447
|
+
*/
|
448
|
+
ZSTD_cpm_attachDict = 1, /* Compression with ZSTD_dictMatchState or ZSTD_dedicatedDictSearch.
|
449
|
+
* In this mode we only take the srcSize into account when selecting
|
450
|
+
* and adjusting parameters.
|
451
|
+
*/
|
452
|
+
ZSTD_cpm_createCDict = 2, /* Creating a CDict.
|
453
|
+
* In this mode we take both the source size and the dictionary size
|
454
|
+
* into account when selecting and adjusting the parameters.
|
455
|
+
*/
|
456
|
+
ZSTD_cpm_unknown = 3, /* ZSTD_getCParams, ZSTD_getParams, ZSTD_adjustParams.
|
457
|
+
* We don't know what these parameters are for. We default to the legacy
|
458
|
+
* behavior of taking both the source size and the dict size into account
|
459
|
+
* when selecting and adjusting parameters.
|
460
|
+
*/
|
461
|
+
} ZSTD_cParamMode_e;
|
291
462
|
|
292
463
|
typedef size_t (*ZSTD_blockCompressor) (
|
293
464
|
ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
294
465
|
void const* src, size_t srcSize);
|
295
|
-
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMode_e dictMode);
|
466
|
+
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e rowMatchfinderMode, ZSTD_dictMode_e dictMode);
|
296
467
|
|
297
468
|
|
298
469
|
MEM_STATIC U32 ZSTD_LLcode(U32 litLength)
|
@@ -345,7 +516,7 @@ MEM_STATIC repcodes_t ZSTD_updateRep(U32 const rep[3], U32 const offset, U32 con
|
|
345
516
|
newReps.rep[1] = rep[0];
|
346
517
|
newReps.rep[0] = currentOffset;
|
347
518
|
} else { /* repCode == 0 */
|
348
|
-
|
519
|
+
ZSTD_memcpy(&newReps, rep, sizeof(newReps));
|
349
520
|
}
|
350
521
|
}
|
351
522
|
return newReps;
|
@@ -372,7 +543,7 @@ MEM_STATIC size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const voi
|
|
372
543
|
RETURN_ERROR_IF(srcSize + ZSTD_blockHeaderSize > dstCapacity,
|
373
544
|
dstSize_tooSmall, "dst buf too small for uncompressed block");
|
374
545
|
MEM_writeLE24(dst, cBlockHeader24);
|
375
|
-
|
546
|
+
ZSTD_memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize);
|
376
547
|
return ZSTD_blockHeaderSize + srcSize;
|
377
548
|
}
|
378
549
|
|
@@ -399,17 +570,17 @@ MEM_STATIC size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
|
|
399
570
|
return (srcSize >> minlog) + 2;
|
400
571
|
}
|
401
572
|
|
402
|
-
MEM_STATIC int
|
573
|
+
MEM_STATIC int ZSTD_literalsCompressionIsDisabled(const ZSTD_CCtx_params* cctxParams)
|
403
574
|
{
|
404
575
|
switch (cctxParams->literalCompressionMode) {
|
405
|
-
case
|
576
|
+
case ZSTD_ps_enable:
|
406
577
|
return 0;
|
407
|
-
case
|
578
|
+
case ZSTD_ps_disable:
|
408
579
|
return 1;
|
409
580
|
default:
|
410
581
|
assert(0 /* impossible: pre-validated */);
|
411
|
-
|
412
|
-
case
|
582
|
+
ZSTD_FALLTHROUGH;
|
583
|
+
case ZSTD_ps_auto:
|
413
584
|
return (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0);
|
414
585
|
}
|
415
586
|
}
|
@@ -469,8 +640,8 @@ void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const BYTE* litera
|
|
469
640
|
|
470
641
|
/* literal Length */
|
471
642
|
if (litLength>0xFFFF) {
|
472
|
-
assert(seqStorePtr->
|
473
|
-
seqStorePtr->
|
643
|
+
assert(seqStorePtr->longLengthType == ZSTD_llt_none); /* there can only be a single long length */
|
644
|
+
seqStorePtr->longLengthType = ZSTD_llt_literalLength;
|
474
645
|
seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart);
|
475
646
|
}
|
476
647
|
seqStorePtr->sequences[0].litLength = (U16)litLength;
|
@@ -480,8 +651,8 @@ void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const BYTE* litera
|
|
480
651
|
|
481
652
|
/* match Length */
|
482
653
|
if (mlBase>0xFFFF) {
|
483
|
-
assert(seqStorePtr->
|
484
|
-
seqStorePtr->
|
654
|
+
assert(seqStorePtr->longLengthType == ZSTD_llt_none); /* there can only be a single long length */
|
655
|
+
seqStorePtr->longLengthType = ZSTD_llt_matchLength;
|
485
656
|
seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart);
|
486
657
|
}
|
487
658
|
seqStorePtr->sequences[0].matchLength = (U16)mlBase;
|
@@ -498,8 +669,18 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|
498
669
|
if (MEM_isLittleEndian()) {
|
499
670
|
if (MEM_64bits()) {
|
500
671
|
# if defined(_MSC_VER) && defined(_WIN64)
|
501
|
-
|
502
|
-
|
672
|
+
# if STATIC_BMI2
|
673
|
+
return _tzcnt_u64(val) >> 3;
|
674
|
+
# else
|
675
|
+
if (val != 0) {
|
676
|
+
unsigned long r;
|
677
|
+
_BitScanForward64(&r, (U64)val);
|
678
|
+
return (unsigned)(r >> 3);
|
679
|
+
} else {
|
680
|
+
/* Should not reach this code path */
|
681
|
+
__assume(0);
|
682
|
+
}
|
683
|
+
# endif
|
503
684
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
504
685
|
return (__builtin_ctzll((U64)val) >> 3);
|
505
686
|
# else
|
@@ -515,8 +696,14 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|
515
696
|
# endif
|
516
697
|
} else { /* 32 bits */
|
517
698
|
# if defined(_MSC_VER)
|
518
|
-
|
519
|
-
|
699
|
+
if (val != 0) {
|
700
|
+
unsigned long r;
|
701
|
+
_BitScanForward(&r, (U32)val);
|
702
|
+
return (unsigned)(r >> 3);
|
703
|
+
} else {
|
704
|
+
/* Should not reach this code path */
|
705
|
+
__assume(0);
|
706
|
+
}
|
520
707
|
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
521
708
|
return (__builtin_ctz((U32)val) >> 3);
|
522
709
|
# else
|
@@ -530,8 +717,18 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|
530
717
|
} else { /* Big Endian CPU */
|
531
718
|
if (MEM_64bits()) {
|
532
719
|
# if defined(_MSC_VER) && defined(_WIN64)
|
533
|
-
|
534
|
-
|
720
|
+
# if STATIC_BMI2
|
721
|
+
return _lzcnt_u64(val) >> 3;
|
722
|
+
# else
|
723
|
+
if (val != 0) {
|
724
|
+
unsigned long r;
|
725
|
+
_BitScanReverse64(&r, (U64)val);
|
726
|
+
return (unsigned)(r >> 3);
|
727
|
+
} else {
|
728
|
+
/* Should not reach this code path */
|
729
|
+
__assume(0);
|
730
|
+
}
|
731
|
+
# endif
|
535
732
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
536
733
|
return (__builtin_clzll(val) >> 3);
|
537
734
|
# else
|
@@ -544,8 +741,14 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|
544
741
|
# endif
|
545
742
|
} else { /* 32 bits */
|
546
743
|
# if defined(_MSC_VER)
|
547
|
-
|
548
|
-
|
744
|
+
if (val != 0) {
|
745
|
+
unsigned long r;
|
746
|
+
_BitScanReverse(&r, (unsigned long)val);
|
747
|
+
return (unsigned)(r >> 3);
|
748
|
+
} else {
|
749
|
+
/* Should not reach this code path */
|
750
|
+
__assume(0);
|
751
|
+
}
|
549
752
|
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
550
753
|
return (__builtin_clz((U32)val) >> 3);
|
551
754
|
# else
|
@@ -626,7 +829,8 @@ static const U64 prime8bytes = 0xCF1BBCDCB7A56463ULL;
|
|
626
829
|
static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u) * prime8bytes) >> (64-h)) ; }
|
627
830
|
static size_t ZSTD_hash8Ptr(const void* p, U32 h) { return ZSTD_hash8(MEM_readLE64(p), h); }
|
628
831
|
|
629
|
-
MEM_STATIC
|
832
|
+
MEM_STATIC FORCE_INLINE_ATTR
|
833
|
+
size_t ZSTD_hashPtr(const void* p, U32 hBits, U32 mls)
|
630
834
|
{
|
631
835
|
switch(mls)
|
632
836
|
{
|
@@ -723,6 +927,13 @@ MEM_STATIC void ZSTD_window_clear(ZSTD_window_t* window)
|
|
723
927
|
window->dictLimit = end;
|
724
928
|
}
|
725
929
|
|
930
|
+
MEM_STATIC U32 ZSTD_window_isEmpty(ZSTD_window_t const window)
|
931
|
+
{
|
932
|
+
return window.dictLimit == ZSTD_WINDOW_START_INDEX &&
|
933
|
+
window.lowLimit == ZSTD_WINDOW_START_INDEX &&
|
934
|
+
(window.nextSrc - window.base) == ZSTD_WINDOW_START_INDEX;
|
935
|
+
}
|
936
|
+
|
726
937
|
/**
|
727
938
|
* ZSTD_window_hasExtDict():
|
728
939
|
* Returns non-zero if the window has a non-empty extDict.
|
@@ -742,20 +953,76 @@ MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms)
|
|
742
953
|
return ZSTD_window_hasExtDict(ms->window) ?
|
743
954
|
ZSTD_extDict :
|
744
955
|
ms->dictMatchState != NULL ?
|
745
|
-
ZSTD_dictMatchState :
|
956
|
+
(ms->dictMatchState->dedicatedDictSearch ? ZSTD_dedicatedDictSearch : ZSTD_dictMatchState) :
|
746
957
|
ZSTD_noDict;
|
747
958
|
}
|
748
959
|
|
960
|
+
/* Defining this macro to non-zero tells zstd to run the overflow correction
|
961
|
+
* code much more frequently. This is very inefficient, and should only be
|
962
|
+
* used for tests and fuzzers.
|
963
|
+
*/
|
964
|
+
#ifndef ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY
|
965
|
+
# ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
966
|
+
# define ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY 1
|
967
|
+
# else
|
968
|
+
# define ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY 0
|
969
|
+
# endif
|
970
|
+
#endif
|
971
|
+
|
972
|
+
/**
|
973
|
+
* ZSTD_window_canOverflowCorrect():
|
974
|
+
* Returns non-zero if the indices are large enough for overflow correction
|
975
|
+
* to work correctly without impacting compression ratio.
|
976
|
+
*/
|
977
|
+
MEM_STATIC U32 ZSTD_window_canOverflowCorrect(ZSTD_window_t const window,
|
978
|
+
U32 cycleLog,
|
979
|
+
U32 maxDist,
|
980
|
+
U32 loadedDictEnd,
|
981
|
+
void const* src)
|
982
|
+
{
|
983
|
+
U32 const cycleSize = 1u << cycleLog;
|
984
|
+
U32 const curr = (U32)((BYTE const*)src - window.base);
|
985
|
+
U32 const minIndexToOverflowCorrect = cycleSize
|
986
|
+
+ MAX(maxDist, cycleSize)
|
987
|
+
+ ZSTD_WINDOW_START_INDEX;
|
988
|
+
|
989
|
+
/* Adjust the min index to backoff the overflow correction frequency,
|
990
|
+
* so we don't waste too much CPU in overflow correction. If this
|
991
|
+
* computation overflows we don't really care, we just need to make
|
992
|
+
* sure it is at least minIndexToOverflowCorrect.
|
993
|
+
*/
|
994
|
+
U32 const adjustment = window.nbOverflowCorrections + 1;
|
995
|
+
U32 const adjustedIndex = MAX(minIndexToOverflowCorrect * adjustment,
|
996
|
+
minIndexToOverflowCorrect);
|
997
|
+
U32 const indexLargeEnough = curr > adjustedIndex;
|
998
|
+
|
999
|
+
/* Only overflow correct early if the dictionary is invalidated already,
|
1000
|
+
* so we don't hurt compression ratio.
|
1001
|
+
*/
|
1002
|
+
U32 const dictionaryInvalidated = curr > maxDist + loadedDictEnd;
|
1003
|
+
|
1004
|
+
return indexLargeEnough && dictionaryInvalidated;
|
1005
|
+
}
|
1006
|
+
|
749
1007
|
/**
|
750
1008
|
* ZSTD_window_needOverflowCorrection():
|
751
1009
|
* Returns non-zero if the indices are getting too large and need overflow
|
752
1010
|
* protection.
|
753
1011
|
*/
|
754
1012
|
MEM_STATIC U32 ZSTD_window_needOverflowCorrection(ZSTD_window_t const window,
|
1013
|
+
U32 cycleLog,
|
1014
|
+
U32 maxDist,
|
1015
|
+
U32 loadedDictEnd,
|
1016
|
+
void const* src,
|
755
1017
|
void const* srcEnd)
|
756
1018
|
{
|
757
|
-
U32 const
|
758
|
-
|
1019
|
+
U32 const curr = (U32)((BYTE const*)srcEnd - window.base);
|
1020
|
+
if (ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY) {
|
1021
|
+
if (ZSTD_window_canOverflowCorrect(window, cycleLog, maxDist, loadedDictEnd, src)) {
|
1022
|
+
return 1;
|
1023
|
+
}
|
1024
|
+
}
|
1025
|
+
return curr > ZSTD_CURRENT_MAX;
|
759
1026
|
}
|
760
1027
|
|
761
1028
|
/**
|
@@ -766,7 +1033,6 @@ MEM_STATIC U32 ZSTD_window_needOverflowCorrection(ZSTD_window_t const window,
|
|
766
1033
|
*
|
767
1034
|
* The least significant cycleLog bits of the indices must remain the same,
|
768
1035
|
* which may be 0. Every index up to maxDist in the past must be valid.
|
769
|
-
* NOTE: (maxDist & cycleMask) must be zero.
|
770
1036
|
*/
|
771
1037
|
MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
|
772
1038
|
U32 maxDist, void const* src)
|
@@ -790,32 +1056,52 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
|
|
790
1056
|
* 3. (cctx->lowLimit + 1<<windowLog) < 1<<32:
|
791
1057
|
* windowLog <= 31 ==> 3<<29 + 1<<windowLog < 7<<29 < 1<<32.
|
792
1058
|
*/
|
793
|
-
U32 const
|
794
|
-
U32 const
|
795
|
-
U32 const
|
796
|
-
|
797
|
-
|
798
|
-
U32 const
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
1059
|
+
U32 const cycleSize = 1u << cycleLog;
|
1060
|
+
U32 const cycleMask = cycleSize - 1;
|
1061
|
+
U32 const curr = (U32)((BYTE const*)src - window->base);
|
1062
|
+
U32 const currentCycle = curr & cycleMask;
|
1063
|
+
/* Ensure newCurrent - maxDist >= ZSTD_WINDOW_START_INDEX. */
|
1064
|
+
U32 const currentCycleCorrection = currentCycle < ZSTD_WINDOW_START_INDEX
|
1065
|
+
? MAX(cycleSize, ZSTD_WINDOW_START_INDEX)
|
1066
|
+
: 0;
|
1067
|
+
U32 const newCurrent = currentCycle
|
1068
|
+
+ currentCycleCorrection
|
1069
|
+
+ MAX(maxDist, cycleSize);
|
1070
|
+
U32 const correction = curr - newCurrent;
|
1071
|
+
/* maxDist must be a power of two so that:
|
1072
|
+
* (newCurrent & cycleMask) == (curr & cycleMask)
|
1073
|
+
* This is required to not corrupt the chains / binary tree.
|
1074
|
+
*/
|
1075
|
+
assert((maxDist & (maxDist - 1)) == 0);
|
1076
|
+
assert((curr & cycleMask) == (newCurrent & cycleMask));
|
1077
|
+
assert(curr > newCurrent);
|
1078
|
+
if (!ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY) {
|
1079
|
+
/* Loose bound, should be around 1<<29 (see above) */
|
1080
|
+
assert(correction > 1<<28);
|
1081
|
+
}
|
804
1082
|
|
805
1083
|
window->base += correction;
|
806
1084
|
window->dictBase += correction;
|
807
|
-
if (window->lowLimit
|
808
|
-
|
809
|
-
|
810
|
-
|
1085
|
+
if (window->lowLimit < correction + ZSTD_WINDOW_START_INDEX) {
|
1086
|
+
window->lowLimit = ZSTD_WINDOW_START_INDEX;
|
1087
|
+
} else {
|
1088
|
+
window->lowLimit -= correction;
|
1089
|
+
}
|
1090
|
+
if (window->dictLimit < correction + ZSTD_WINDOW_START_INDEX) {
|
1091
|
+
window->dictLimit = ZSTD_WINDOW_START_INDEX;
|
1092
|
+
} else {
|
1093
|
+
window->dictLimit -= correction;
|
1094
|
+
}
|
811
1095
|
|
812
1096
|
/* Ensure we can still reference the full window. */
|
813
1097
|
assert(newCurrent >= maxDist);
|
814
|
-
assert(newCurrent - maxDist >=
|
1098
|
+
assert(newCurrent - maxDist >= ZSTD_WINDOW_START_INDEX);
|
815
1099
|
/* Ensure that lowLimit and dictLimit didn't underflow. */
|
816
1100
|
assert(window->lowLimit <= newCurrent);
|
817
1101
|
assert(window->dictLimit <= newCurrent);
|
818
1102
|
|
1103
|
+
++window->nbOverflowCorrections;
|
1104
|
+
|
819
1105
|
DEBUGLOG(4, "Correction of 0x%x bytes to lowLimit=0x%x", correction,
|
820
1106
|
window->lowLimit);
|
821
1107
|
return correction;
|
@@ -919,12 +1205,14 @@ ZSTD_checkDictValidity(const ZSTD_window_t* window,
|
|
919
1205
|
}
|
920
1206
|
|
921
1207
|
MEM_STATIC void ZSTD_window_init(ZSTD_window_t* window) {
|
922
|
-
|
923
|
-
window->base = (BYTE const*)"";
|
924
|
-
window->dictBase = (BYTE const*)"";
|
925
|
-
|
926
|
-
window->
|
927
|
-
window->
|
1208
|
+
ZSTD_memset(window, 0, sizeof(*window));
|
1209
|
+
window->base = (BYTE const*)" ";
|
1210
|
+
window->dictBase = (BYTE const*)" ";
|
1211
|
+
ZSTD_STATIC_ASSERT(ZSTD_DUBT_UNSORTED_MARK < ZSTD_WINDOW_START_INDEX); /* Start above ZSTD_DUBT_UNSORTED_MARK */
|
1212
|
+
window->dictLimit = ZSTD_WINDOW_START_INDEX; /* start from >0, so that 1st position is valid */
|
1213
|
+
window->lowLimit = ZSTD_WINDOW_START_INDEX; /* it ensures first and later CCtx usages compress the same */
|
1214
|
+
window->nextSrc = window->base + ZSTD_WINDOW_START_INDEX; /* see issue #1241 */
|
1215
|
+
window->nbOverflowCorrections = 0;
|
928
1216
|
}
|
929
1217
|
|
930
1218
|
/**
|
@@ -935,7 +1223,8 @@ MEM_STATIC void ZSTD_window_init(ZSTD_window_t* window) {
|
|
935
1223
|
* Returns non-zero if the segment is contiguous.
|
936
1224
|
*/
|
937
1225
|
MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t* window,
|
938
|
-
void const* src, size_t srcSize
|
1226
|
+
void const* src, size_t srcSize,
|
1227
|
+
int forceNonContiguous)
|
939
1228
|
{
|
940
1229
|
BYTE const* const ip = (BYTE const*)src;
|
941
1230
|
U32 contiguous = 1;
|
@@ -945,7 +1234,7 @@ MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t* window,
|
|
945
1234
|
assert(window->base != NULL);
|
946
1235
|
assert(window->dictBase != NULL);
|
947
1236
|
/* Check if blocks follow each other */
|
948
|
-
if (src != window->nextSrc) {
|
1237
|
+
if (src != window->nextSrc || forceNonContiguous) {
|
949
1238
|
/* not contiguous */
|
950
1239
|
size_t const distanceFromBase = (size_t)(window->nextSrc - window->base);
|
951
1240
|
DEBUGLOG(5, "Non contiguous blocks, new segment starts at %u", window->dictLimit);
|
@@ -973,25 +1262,32 @@ MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t* window,
|
|
973
1262
|
/**
|
974
1263
|
* Returns the lowest allowed match index. It may either be in the ext-dict or the prefix.
|
975
1264
|
*/
|
976
|
-
MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32
|
1265
|
+
MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog)
|
977
1266
|
{
|
978
|
-
U32
|
979
|
-
U32
|
980
|
-
U32
|
981
|
-
U32
|
982
|
-
|
1267
|
+
U32 const maxDistance = 1U << windowLog;
|
1268
|
+
U32 const lowestValid = ms->window.lowLimit;
|
1269
|
+
U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
|
1270
|
+
U32 const isDictionary = (ms->loadedDictEnd != 0);
|
1271
|
+
/* When using a dictionary the entire dictionary is valid if a single byte of the dictionary
|
1272
|
+
* is within the window. We invalidate the dictionary (and set loadedDictEnd to 0) when it isn't
|
1273
|
+
* valid for the entire block. So this check is sufficient to find the lowest valid match index.
|
1274
|
+
*/
|
1275
|
+
U32 const matchLowest = isDictionary ? lowestValid : withinWindow;
|
983
1276
|
return matchLowest;
|
984
1277
|
}
|
985
1278
|
|
986
1279
|
/**
|
987
1280
|
* Returns the lowest allowed match index in the prefix.
|
988
1281
|
*/
|
989
|
-
MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32
|
1282
|
+
MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog)
|
990
1283
|
{
|
991
1284
|
U32 const maxDistance = 1U << windowLog;
|
992
1285
|
U32 const lowestValid = ms->window.dictLimit;
|
993
|
-
U32 const withinWindow = (
|
1286
|
+
U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
|
994
1287
|
U32 const isDictionary = (ms->loadedDictEnd != 0);
|
1288
|
+
/* When computing the lowest prefix index we need to take the dictionary into account to handle
|
1289
|
+
* the edge case where the dictionary and the source are contiguous in memory.
|
1290
|
+
*/
|
995
1291
|
U32 const matchLowest = isDictionary ? lowestValid : withinWindow;
|
996
1292
|
return matchLowest;
|
997
1293
|
}
|
@@ -1045,7 +1341,6 @@ MEM_STATIC void ZSTD_debugTable(const U32* table, U32 max)
|
|
1045
1341
|
* assumptions : magic number supposed already checked
|
1046
1342
|
* and dictSize >= 8 */
|
1047
1343
|
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
1048
|
-
short* offcodeNCount, unsigned* offcodeMaxValue,
|
1049
1344
|
const void* const dict, size_t dictSize);
|
1050
1345
|
|
1051
1346
|
void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs);
|
@@ -1061,7 +1356,7 @@ void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs);
|
|
1061
1356
|
* Note: srcSizeHint == 0 means 0!
|
1062
1357
|
*/
|
1063
1358
|
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
1064
|
-
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize);
|
1359
|
+
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode);
|
1065
1360
|
|
1066
1361
|
/*! ZSTD_initCStream_internal() :
|
1067
1362
|
* Private use only. Init streaming operation.
|
@@ -1122,4 +1417,9 @@ size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSe
|
|
1122
1417
|
* condition for correct operation : hashLog > 1 */
|
1123
1418
|
U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat);
|
1124
1419
|
|
1420
|
+
/** ZSTD_CCtx_trace() :
|
1421
|
+
* Trace the end of a compression call.
|
1422
|
+
*/
|
1423
|
+
void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize);
|
1424
|
+
|
1125
1425
|
#endif /* ZSTD_COMPRESS_H */
|