zstdlib 0.10.0-arm64-darwin → 0.12.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +17 -0
- data/ext/zstdlib_c/extconf.rb +9 -4
- data/ext/zstdlib_c/ruby/zlib-3.2/zstdlib.c +5090 -0
- data/ext/zstdlib_c/ruby/zlib-3.3/zstdlib.c +5090 -0
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/adler32.c +5 -27
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/compress.c +5 -16
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/crc32.c +94 -161
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/deflate.c +362 -434
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/deflate.h +43 -12
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzclose.c +1 -3
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzguts.h +13 -18
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzlib.c +28 -85
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzread.c +23 -73
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzwrite.c +19 -65
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/infback.c +17 -30
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffast.c +1 -4
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffast.h +1 -1
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inflate.c +36 -102
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inftrees.c +6 -11
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inftrees.h +6 -6
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/trees.c +290 -355
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/uncompr.c +4 -12
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zconf.h +23 -14
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zlib.h +202 -199
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zutil.c +18 -44
- data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zutil.h +13 -33
- data/ext/zstdlib_c/zstd-1.5.5/lib/common/allocations.h +55 -0
- data/ext/zstdlib_c/zstd-1.5.5/lib/common/bits.h +200 -0
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/bitstream.h +19 -60
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/compiler.h +26 -3
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/cpu.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/debug.c +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/debug.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/entropy_common.c +12 -40
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/error_private.c +9 -2
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/error_private.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/fse.h +5 -83
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/fse_decompress.c +7 -99
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/huf.h +65 -156
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/mem.h +39 -46
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/pool.c +26 -10
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/pool.h +7 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/portability_macros.h +22 -3
- data/ext/zstdlib_c/zstd-1.5.5/lib/common/threading.c +176 -0
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/threading.h +5 -10
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/xxhash.c +2 -2
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/xxhash.h +8 -8
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/zstd_common.c +1 -36
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/zstd_deps.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/zstd_internal.h +17 -118
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/common/zstd_trace.h +3 -3
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/clevels.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/fse_compress.c +7 -124
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/hist.c +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/hist.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/huf_compress.c +234 -169
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress.c +1243 -538
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress_internal.h +225 -151
- data/ext/zstdlib_c/zstd-1.5.5/lib/compress/zstd_compress_literals.c +235 -0
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress_literals.h +16 -8
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress_sequences.c +3 -3
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress_sequences.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress_superblock.c +25 -21
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_compress_superblock.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_cwksp.h +128 -62
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_double_fast.c +95 -33
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_double_fast.h +3 -2
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_fast.c +433 -148
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_fast.h +3 -2
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_lazy.c +398 -345
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_lazy.h +4 -2
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_ldm.c +5 -5
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_ldm.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_ldm_geartab.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_opt.c +106 -80
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstd_opt.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstdmt_compress.c +17 -9
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/compress/zstdmt_compress.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/huf_decompress.c +434 -441
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/huf_decompress_amd64.S +30 -39
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/zstd_ddict.c +4 -4
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/zstd_ddict.h +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/zstd_decompress.c +205 -80
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/zstd_decompress_block.c +201 -81
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/zstd_decompress_block.h +6 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/decompress/zstd_decompress_internal.h +4 -2
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/zdict.h +53 -31
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/zstd.h +580 -135
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/lib/zstd_errors.h +27 -8
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/gzclose.c +1 -1
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/gzcompatibility.h +8 -8
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/gzguts.h +10 -10
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/gzlib.c +3 -3
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/gzread.c +10 -10
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/gzwrite.c +5 -5
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/zstd_zlibwrapper.c +46 -44
- data/ext/zstdlib_c/{zstd-1.5.2 → zstd-1.5.5}/zlibWrapper/zstd_zlibwrapper.h +4 -1
- data/lib/2.4/zstdlib_c.bundle +0 -0
- data/lib/2.5/zstdlib_c.bundle +0 -0
- data/lib/2.6/zstdlib_c.bundle +0 -0
- data/lib/2.7/zstdlib_c.bundle +0 -0
- data/lib/3.0/zstdlib_c.bundle +0 -0
- data/lib/3.1/zstdlib_c.bundle +0 -0
- data/lib/3.2/zstdlib_c.bundle +0 -0
- data/lib/3.3/zstdlib_c.bundle +0 -0
- metadata +111 -105
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/threading.c +0 -122
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_literals.c +0 -159
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/crc32.h +0 -0
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffixed.h +0 -0
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inflate.h +0 -0
- /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/trees.h +0 -0
@@ -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
|
@@ -11,8 +11,42 @@
|
|
11
11
|
#include "zstd_compress_internal.h" /* ZSTD_hashPtr, ZSTD_count, ZSTD_storeSeq */
|
12
12
|
#include "zstd_fast.h"
|
13
13
|
|
14
|
+
static void ZSTD_fillHashTableForCDict(ZSTD_matchState_t* ms,
|
15
|
+
const void* const end,
|
16
|
+
ZSTD_dictTableLoadMethod_e dtlm)
|
17
|
+
{
|
18
|
+
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
19
|
+
U32* const hashTable = ms->hashTable;
|
20
|
+
U32 const hBits = cParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
|
21
|
+
U32 const mls = cParams->minMatch;
|
22
|
+
const BYTE* const base = ms->window.base;
|
23
|
+
const BYTE* ip = base + ms->nextToUpdate;
|
24
|
+
const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
|
25
|
+
const U32 fastHashFillStep = 3;
|
14
26
|
|
15
|
-
|
27
|
+
/* Currently, we always use ZSTD_dtlm_full for filling CDict tables.
|
28
|
+
* Feel free to remove this assert if there's a good reason! */
|
29
|
+
assert(dtlm == ZSTD_dtlm_full);
|
30
|
+
|
31
|
+
/* Always insert every fastHashFillStep position into the hash table.
|
32
|
+
* Insert the other positions if their hash entry is empty.
|
33
|
+
*/
|
34
|
+
for ( ; ip + fastHashFillStep < iend + 2; ip += fastHashFillStep) {
|
35
|
+
U32 const curr = (U32)(ip - base);
|
36
|
+
{ size_t const hashAndTag = ZSTD_hashPtr(ip, hBits, mls);
|
37
|
+
ZSTD_writeTaggedIndex(hashTable, hashAndTag, curr); }
|
38
|
+
|
39
|
+
if (dtlm == ZSTD_dtlm_fast) continue;
|
40
|
+
/* Only load extra positions for ZSTD_dtlm_full */
|
41
|
+
{ U32 p;
|
42
|
+
for (p = 1; p < fastHashFillStep; ++p) {
|
43
|
+
size_t const hashAndTag = ZSTD_hashPtr(ip + p, hBits, mls);
|
44
|
+
if (hashTable[hashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS] == 0) { /* not yet filled */
|
45
|
+
ZSTD_writeTaggedIndex(hashTable, hashAndTag, curr + p);
|
46
|
+
} } } }
|
47
|
+
}
|
48
|
+
|
49
|
+
static void ZSTD_fillHashTableForCCtx(ZSTD_matchState_t* ms,
|
16
50
|
const void* const end,
|
17
51
|
ZSTD_dictTableLoadMethod_e dtlm)
|
18
52
|
{
|
@@ -25,6 +59,10 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
|
25
59
|
const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
|
26
60
|
const U32 fastHashFillStep = 3;
|
27
61
|
|
62
|
+
/* Currently, we always use ZSTD_dtlm_fast for filling CCtx tables.
|
63
|
+
* Feel free to remove this assert if there's a good reason! */
|
64
|
+
assert(dtlm == ZSTD_dtlm_fast);
|
65
|
+
|
28
66
|
/* Always insert every fastHashFillStep position into the hash table.
|
29
67
|
* Insert the other positions if their hash entry is empty.
|
30
68
|
*/
|
@@ -42,6 +80,18 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
|
42
80
|
} } } }
|
43
81
|
}
|
44
82
|
|
83
|
+
void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
84
|
+
const void* const end,
|
85
|
+
ZSTD_dictTableLoadMethod_e dtlm,
|
86
|
+
ZSTD_tableFillPurpose_e tfp)
|
87
|
+
{
|
88
|
+
if (tfp == ZSTD_tfp_forCDict) {
|
89
|
+
ZSTD_fillHashTableForCDict(ms, end, dtlm);
|
90
|
+
} else {
|
91
|
+
ZSTD_fillHashTableForCCtx(ms, end, dtlm);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
45
95
|
|
46
96
|
/**
|
47
97
|
* If you squint hard enough (and ignore repcodes), the search operation at any
|
@@ -117,7 +167,7 @@ ZSTD_compressBlock_fast_noDict_generic(
|
|
117
167
|
|
118
168
|
U32 rep_offset1 = rep[0];
|
119
169
|
U32 rep_offset2 = rep[1];
|
120
|
-
U32
|
170
|
+
U32 offsetSaved1 = 0, offsetSaved2 = 0;
|
121
171
|
|
122
172
|
size_t hash0; /* hash for ip0 */
|
123
173
|
size_t hash1; /* hash for ip1 */
|
@@ -141,8 +191,8 @@ ZSTD_compressBlock_fast_noDict_generic(
|
|
141
191
|
{ U32 const curr = (U32)(ip0 - base);
|
142
192
|
U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, curr, cParams->windowLog);
|
143
193
|
U32 const maxRep = curr - windowLow;
|
144
|
-
if (rep_offset2 > maxRep)
|
145
|
-
if (rep_offset1 > maxRep)
|
194
|
+
if (rep_offset2 > maxRep) offsetSaved2 = rep_offset2, rep_offset2 = 0;
|
195
|
+
if (rep_offset1 > maxRep) offsetSaved1 = rep_offset1, rep_offset1 = 0;
|
146
196
|
}
|
147
197
|
|
148
198
|
/* start each op */
|
@@ -180,8 +230,14 @@ _start: /* Requires: ip0 */
|
|
180
230
|
mLength = ip0[-1] == match0[-1];
|
181
231
|
ip0 -= mLength;
|
182
232
|
match0 -= mLength;
|
183
|
-
offcode =
|
233
|
+
offcode = REPCODE1_TO_OFFBASE;
|
184
234
|
mLength += 4;
|
235
|
+
|
236
|
+
/* First write next hash table entry; we've already calculated it.
|
237
|
+
* This write is known to be safe because the ip1 is before the
|
238
|
+
* repcode (ip2). */
|
239
|
+
hashTable[hash1] = (U32)(ip1 - base);
|
240
|
+
|
185
241
|
goto _match;
|
186
242
|
}
|
187
243
|
|
@@ -195,6 +251,12 @@ _start: /* Requires: ip0 */
|
|
195
251
|
/* check match at ip[0] */
|
196
252
|
if (MEM_read32(ip0) == mval) {
|
197
253
|
/* found a match! */
|
254
|
+
|
255
|
+
/* First write next hash table entry; we've already calculated it.
|
256
|
+
* This write is known to be safe because the ip1 == ip0 + 1, so
|
257
|
+
* we know we will resume searching after ip1 */
|
258
|
+
hashTable[hash1] = (U32)(ip1 - base);
|
259
|
+
|
198
260
|
goto _offset;
|
199
261
|
}
|
200
262
|
|
@@ -224,6 +286,21 @@ _start: /* Requires: ip0 */
|
|
224
286
|
/* check match at ip[0] */
|
225
287
|
if (MEM_read32(ip0) == mval) {
|
226
288
|
/* found a match! */
|
289
|
+
|
290
|
+
/* first write next hash table entry; we've already calculated it */
|
291
|
+
if (step <= 4) {
|
292
|
+
/* We need to avoid writing an index into the hash table >= the
|
293
|
+
* position at which we will pick up our searching after we've
|
294
|
+
* taken this match.
|
295
|
+
*
|
296
|
+
* The minimum possible match has length 4, so the earliest ip0
|
297
|
+
* can be after we take this match will be the current ip0 + 4.
|
298
|
+
* ip1 is ip0 + step - 1. If ip1 is >= ip0 + 4, we can't safely
|
299
|
+
* write this position.
|
300
|
+
*/
|
301
|
+
hashTable[hash1] = (U32)(ip1 - base);
|
302
|
+
}
|
303
|
+
|
227
304
|
goto _offset;
|
228
305
|
}
|
229
306
|
|
@@ -254,9 +331,24 @@ _cleanup:
|
|
254
331
|
* However, it seems to be a meaningful performance hit to try to search
|
255
332
|
* them. So let's not. */
|
256
333
|
|
334
|
+
/* When the repcodes are outside of the prefix, we set them to zero before the loop.
|
335
|
+
* When the offsets are still zero, we need to restore them after the block to have a correct
|
336
|
+
* repcode history. If only one offset was invalid, it is easy. The tricky case is when both
|
337
|
+
* offsets were invalid. We need to figure out which offset to refill with.
|
338
|
+
* - If both offsets are zero they are in the same order.
|
339
|
+
* - If both offsets are non-zero, we won't restore the offsets from `offsetSaved[12]`.
|
340
|
+
* - If only one is zero, we need to decide which offset to restore.
|
341
|
+
* - If rep_offset1 is non-zero, then rep_offset2 must be offsetSaved1.
|
342
|
+
* - It is impossible for rep_offset2 to be non-zero.
|
343
|
+
*
|
344
|
+
* So if rep_offset1 started invalid (offsetSaved1 != 0) and became valid (rep_offset1 != 0), then
|
345
|
+
* set rep[0] = rep_offset1 and rep[1] = offsetSaved1.
|
346
|
+
*/
|
347
|
+
offsetSaved2 = ((offsetSaved1 != 0) && (rep_offset1 != 0)) ? offsetSaved1 : offsetSaved2;
|
348
|
+
|
257
349
|
/* save reps for next block */
|
258
|
-
rep[0] = rep_offset1 ? rep_offset1 :
|
259
|
-
rep[1] = rep_offset2 ? rep_offset2 :
|
350
|
+
rep[0] = rep_offset1 ? rep_offset1 : offsetSaved1;
|
351
|
+
rep[1] = rep_offset2 ? rep_offset2 : offsetSaved2;
|
260
352
|
|
261
353
|
/* Return the last literals size */
|
262
354
|
return (size_t)(iend - anchor);
|
@@ -267,7 +359,7 @@ _offset: /* Requires: ip0, idx */
|
|
267
359
|
match0 = base + idx;
|
268
360
|
rep_offset2 = rep_offset1;
|
269
361
|
rep_offset1 = (U32)(ip0-match0);
|
270
|
-
offcode =
|
362
|
+
offcode = OFFSET_TO_OFFBASE(rep_offset1);
|
271
363
|
mLength = 4;
|
272
364
|
|
273
365
|
/* Count the backwards match length. */
|
@@ -287,11 +379,6 @@ _match: /* Requires: ip0, match0, offcode */
|
|
287
379
|
ip0 += mLength;
|
288
380
|
anchor = ip0;
|
289
381
|
|
290
|
-
/* write next hash table entry */
|
291
|
-
if (ip1 < ip0) {
|
292
|
-
hashTable[hash1] = (U32)(ip1 - base);
|
293
|
-
}
|
294
|
-
|
295
382
|
/* Fill table and check for immediate repcode. */
|
296
383
|
if (ip0 <= ilimit) {
|
297
384
|
/* Fill Table */
|
@@ -306,7 +393,7 @@ _match: /* Requires: ip0, match0, offcode */
|
|
306
393
|
{ U32 const tmpOff = rep_offset2; rep_offset2 = rep_offset1; rep_offset1 = tmpOff; } /* swap rep_offset2 <=> rep_offset1 */
|
307
394
|
hashTable[ZSTD_hashPtr(ip0, hlog, mls)] = (U32)(ip0-base);
|
308
395
|
ip0 += rLength;
|
309
|
-
ZSTD_storeSeq(seqStore, 0 /*litLen*/, anchor, iend,
|
396
|
+
ZSTD_storeSeq(seqStore, 0 /*litLen*/, anchor, iend, REPCODE1_TO_OFFBASE, rLength);
|
310
397
|
anchor = ip0;
|
311
398
|
continue; /* faster when present (confirmed on gcc-8) ... (?) */
|
312
399
|
} } }
|
@@ -380,14 +467,14 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
|
|
380
467
|
U32 const stepSize = cParams->targetLength + !(cParams->targetLength);
|
381
468
|
const BYTE* const base = ms->window.base;
|
382
469
|
const BYTE* const istart = (const BYTE*)src;
|
383
|
-
const BYTE*
|
470
|
+
const BYTE* ip0 = istart;
|
471
|
+
const BYTE* ip1 = ip0 + stepSize; /* we assert below that stepSize >= 1 */
|
384
472
|
const BYTE* anchor = istart;
|
385
473
|
const U32 prefixStartIndex = ms->window.dictLimit;
|
386
474
|
const BYTE* const prefixStart = base + prefixStartIndex;
|
387
475
|
const BYTE* const iend = istart + srcSize;
|
388
476
|
const BYTE* const ilimit = iend - HASH_READ_SIZE;
|
389
477
|
U32 offset_1=rep[0], offset_2=rep[1];
|
390
|
-
U32 offsetSaved = 0;
|
391
478
|
|
392
479
|
const ZSTD_matchState_t* const dms = ms->dictMatchState;
|
393
480
|
const ZSTD_compressionParameters* const dictCParams = &dms->cParams ;
|
@@ -397,13 +484,13 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
|
|
397
484
|
const BYTE* const dictStart = dictBase + dictStartIndex;
|
398
485
|
const BYTE* const dictEnd = dms->window.nextSrc;
|
399
486
|
const U32 dictIndexDelta = prefixStartIndex - (U32)(dictEnd - dictBase);
|
400
|
-
const U32 dictAndPrefixLength = (U32)(
|
401
|
-
const U32
|
487
|
+
const U32 dictAndPrefixLength = (U32)(istart - prefixStart + dictEnd - dictStart);
|
488
|
+
const U32 dictHBits = dictCParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
|
402
489
|
|
403
490
|
/* if a dictionary is still attached, it necessarily means that
|
404
491
|
* it is within window size. So we just check it. */
|
405
492
|
const U32 maxDistance = 1U << cParams->windowLog;
|
406
|
-
const U32 endIndex = (U32)((size_t)(
|
493
|
+
const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
|
407
494
|
assert(endIndex - prefixStartIndex <= maxDistance);
|
408
495
|
(void)maxDistance; (void)endIndex; /* these variables are not used when assert() is disabled */
|
409
496
|
|
@@ -413,106 +500,155 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
|
|
413
500
|
* when translating a dict index into a local index */
|
414
501
|
assert(prefixStartIndex >= (U32)(dictEnd - dictBase));
|
415
502
|
|
503
|
+
if (ms->prefetchCDictTables) {
|
504
|
+
size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) * sizeof(U32);
|
505
|
+
PREFETCH_AREA(dictHashTable, hashTableBytes)
|
506
|
+
}
|
507
|
+
|
416
508
|
/* init */
|
417
509
|
DEBUGLOG(5, "ZSTD_compressBlock_fast_dictMatchState_generic");
|
418
|
-
|
510
|
+
ip0 += (dictAndPrefixLength == 0);
|
419
511
|
/* dictMatchState repCode checks don't currently handle repCode == 0
|
420
512
|
* disabling. */
|
421
513
|
assert(offset_1 <= dictAndPrefixLength);
|
422
514
|
assert(offset_2 <= dictAndPrefixLength);
|
423
515
|
|
424
|
-
/*
|
425
|
-
|
516
|
+
/* Outer search loop */
|
517
|
+
assert(stepSize >= 1);
|
518
|
+
while (ip1 <= ilimit) { /* repcode check at (ip0 + 1) is safe because ip0 < ip1 */
|
426
519
|
size_t mLength;
|
427
|
-
size_t
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
const
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
520
|
+
size_t hash0 = ZSTD_hashPtr(ip0, hlog, mls);
|
521
|
+
|
522
|
+
size_t const dictHashAndTag0 = ZSTD_hashPtr(ip0, dictHBits, mls);
|
523
|
+
U32 dictMatchIndexAndTag = dictHashTable[dictHashAndTag0 >> ZSTD_SHORT_CACHE_TAG_BITS];
|
524
|
+
int dictTagsMatch = ZSTD_comparePackedTags(dictMatchIndexAndTag, dictHashAndTag0);
|
525
|
+
|
526
|
+
U32 matchIndex = hashTable[hash0];
|
527
|
+
U32 curr = (U32)(ip0 - base);
|
528
|
+
size_t step = stepSize;
|
529
|
+
const size_t kStepIncr = 1 << kSearchStrength;
|
530
|
+
const BYTE* nextStep = ip0 + kStepIncr;
|
531
|
+
|
532
|
+
/* Inner search loop */
|
533
|
+
while (1) {
|
534
|
+
const BYTE* match = base + matchIndex;
|
535
|
+
const U32 repIndex = curr + 1 - offset_1;
|
536
|
+
const BYTE* repMatch = (repIndex < prefixStartIndex) ?
|
537
|
+
dictBase + (repIndex - dictIndexDelta) :
|
538
|
+
base + repIndex;
|
539
|
+
const size_t hash1 = ZSTD_hashPtr(ip1, hlog, mls);
|
540
|
+
size_t const dictHashAndTag1 = ZSTD_hashPtr(ip1, dictHBits, mls);
|
541
|
+
hashTable[hash0] = curr; /* update hash table */
|
542
|
+
|
543
|
+
if (((U32) ((prefixStartIndex - 1) - repIndex) >=
|
544
|
+
3) /* intentional underflow : ensure repIndex isn't overlapping dict + prefix */
|
545
|
+
&& (MEM_read32(repMatch) == MEM_read32(ip0 + 1))) {
|
546
|
+
const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
|
547
|
+
mLength = ZSTD_count_2segments(ip0 + 1 + 4, repMatch + 4, iend, repMatchEnd, prefixStart) + 4;
|
548
|
+
ip0++;
|
549
|
+
ZSTD_storeSeq(seqStore, (size_t) (ip0 - anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
|
550
|
+
break;
|
551
|
+
}
|
552
|
+
|
553
|
+
if (dictTagsMatch) {
|
554
|
+
/* Found a possible dict match */
|
555
|
+
const U32 dictMatchIndex = dictMatchIndexAndTag >> ZSTD_SHORT_CACHE_TAG_BITS;
|
556
|
+
const BYTE* dictMatch = dictBase + dictMatchIndex;
|
557
|
+
if (dictMatchIndex > dictStartIndex &&
|
558
|
+
MEM_read32(dictMatch) == MEM_read32(ip0)) {
|
559
|
+
/* To replicate extDict parse behavior, we only use dict matches when the normal matchIndex is invalid */
|
560
|
+
if (matchIndex <= prefixStartIndex) {
|
561
|
+
U32 const offset = (U32) (curr - dictMatchIndex - dictIndexDelta);
|
562
|
+
mLength = ZSTD_count_2segments(ip0 + 4, dictMatch + 4, iend, dictEnd, prefixStart) + 4;
|
563
|
+
while (((ip0 > anchor) & (dictMatch > dictStart))
|
564
|
+
&& (ip0[-1] == dictMatch[-1])) {
|
565
|
+
ip0--;
|
566
|
+
dictMatch--;
|
567
|
+
mLength++;
|
568
|
+
} /* catch up */
|
569
|
+
offset_2 = offset_1;
|
570
|
+
offset_1 = offset;
|
571
|
+
ZSTD_storeSeq(seqStore, (size_t) (ip0 - anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
|
572
|
+
break;
|
573
|
+
}
|
574
|
+
}
|
575
|
+
}
|
576
|
+
|
577
|
+
if (matchIndex > prefixStartIndex && MEM_read32(match) == MEM_read32(ip0)) {
|
578
|
+
/* found a regular match */
|
579
|
+
U32 const offset = (U32) (ip0 - match);
|
580
|
+
mLength = ZSTD_count(ip0 + 4, match + 4, iend) + 4;
|
581
|
+
while (((ip0 > anchor) & (match > prefixStart))
|
582
|
+
&& (ip0[-1] == match[-1])) {
|
583
|
+
ip0--;
|
584
|
+
match--;
|
585
|
+
mLength++;
|
459
586
|
} /* catch up */
|
460
587
|
offset_2 = offset_1;
|
461
588
|
offset_1 = offset;
|
462
|
-
ZSTD_storeSeq(seqStore, (size_t)(
|
589
|
+
ZSTD_storeSeq(seqStore, (size_t) (ip0 - anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
|
590
|
+
break;
|
463
591
|
}
|
464
|
-
|
465
|
-
/*
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
592
|
+
|
593
|
+
/* Prepare for next iteration */
|
594
|
+
dictMatchIndexAndTag = dictHashTable[dictHashAndTag1 >> ZSTD_SHORT_CACHE_TAG_BITS];
|
595
|
+
dictTagsMatch = ZSTD_comparePackedTags(dictMatchIndexAndTag, dictHashAndTag1);
|
596
|
+
matchIndex = hashTable[hash1];
|
597
|
+
|
598
|
+
if (ip1 >= nextStep) {
|
599
|
+
step++;
|
600
|
+
nextStep += kStepIncr;
|
601
|
+
}
|
602
|
+
ip0 = ip1;
|
603
|
+
ip1 = ip1 + step;
|
604
|
+
if (ip1 > ilimit) goto _cleanup;
|
605
|
+
|
606
|
+
curr = (U32)(ip0 - base);
|
607
|
+
hash0 = hash1;
|
608
|
+
} /* end inner search loop */
|
479
609
|
|
480
610
|
/* match found */
|
481
|
-
|
482
|
-
|
611
|
+
assert(mLength);
|
612
|
+
ip0 += mLength;
|
613
|
+
anchor = ip0;
|
483
614
|
|
484
|
-
if (
|
615
|
+
if (ip0 <= ilimit) {
|
485
616
|
/* Fill Table */
|
486
617
|
assert(base+curr+2 > istart); /* check base overflow */
|
487
618
|
hashTable[ZSTD_hashPtr(base+curr+2, hlog, mls)] = curr+2; /* here because curr+2 could be > iend-8 */
|
488
|
-
hashTable[ZSTD_hashPtr(
|
619
|
+
hashTable[ZSTD_hashPtr(ip0-2, hlog, mls)] = (U32)(ip0-2-base);
|
489
620
|
|
490
621
|
/* check immediate repcode */
|
491
|
-
while (
|
492
|
-
U32 const current2 = (U32)(
|
622
|
+
while (ip0 <= ilimit) {
|
623
|
+
U32 const current2 = (U32)(ip0-base);
|
493
624
|
U32 const repIndex2 = current2 - offset_2;
|
494
625
|
const BYTE* repMatch2 = repIndex2 < prefixStartIndex ?
|
495
626
|
dictBase - dictIndexDelta + repIndex2 :
|
496
627
|
base + repIndex2;
|
497
628
|
if ( ((U32)((prefixStartIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
|
498
|
-
&& (MEM_read32(repMatch2) == MEM_read32(
|
629
|
+
&& (MEM_read32(repMatch2) == MEM_read32(ip0))) {
|
499
630
|
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
500
|
-
size_t const repLength2 = ZSTD_count_2segments(
|
631
|
+
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
501
632
|
U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
|
502
|
-
ZSTD_storeSeq(seqStore, 0, anchor, iend,
|
503
|
-
hashTable[ZSTD_hashPtr(
|
504
|
-
|
505
|
-
anchor =
|
633
|
+
ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
|
634
|
+
hashTable[ZSTD_hashPtr(ip0, hlog, mls)] = current2;
|
635
|
+
ip0 += repLength2;
|
636
|
+
anchor = ip0;
|
506
637
|
continue;
|
507
638
|
}
|
508
639
|
break;
|
509
640
|
}
|
510
641
|
}
|
642
|
+
|
643
|
+
/* Prepare for next iteration */
|
644
|
+
assert(ip0 == anchor);
|
645
|
+
ip1 = ip0 + stepSize;
|
511
646
|
}
|
512
647
|
|
648
|
+
_cleanup:
|
513
649
|
/* save reps for next block */
|
514
|
-
rep[0] = offset_1
|
515
|
-
rep[1] = offset_2
|
650
|
+
rep[0] = offset_1;
|
651
|
+
rep[1] = offset_2;
|
516
652
|
|
517
653
|
/* Return the last literals size */
|
518
654
|
return (size_t)(iend - anchor);
|
@@ -553,11 +689,10 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
|
|
553
689
|
U32* const hashTable = ms->hashTable;
|
554
690
|
U32 const hlog = cParams->hashLog;
|
555
691
|
/* support stepSize of 0 */
|
556
|
-
|
692
|
+
size_t const stepSize = cParams->targetLength + !(cParams->targetLength) + 1;
|
557
693
|
const BYTE* const base = ms->window.base;
|
558
694
|
const BYTE* const dictBase = ms->window.dictBase;
|
559
695
|
const BYTE* const istart = (const BYTE*)src;
|
560
|
-
const BYTE* ip = istart;
|
561
696
|
const BYTE* anchor = istart;
|
562
697
|
const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
|
563
698
|
const U32 lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, cParams->windowLog);
|
@@ -570,6 +705,28 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
|
|
570
705
|
const BYTE* const iend = istart + srcSize;
|
571
706
|
const BYTE* const ilimit = iend - 8;
|
572
707
|
U32 offset_1=rep[0], offset_2=rep[1];
|
708
|
+
U32 offsetSaved1 = 0, offsetSaved2 = 0;
|
709
|
+
|
710
|
+
const BYTE* ip0 = istart;
|
711
|
+
const BYTE* ip1;
|
712
|
+
const BYTE* ip2;
|
713
|
+
const BYTE* ip3;
|
714
|
+
U32 current0;
|
715
|
+
|
716
|
+
|
717
|
+
size_t hash0; /* hash for ip0 */
|
718
|
+
size_t hash1; /* hash for ip1 */
|
719
|
+
U32 idx; /* match idx for ip0 */
|
720
|
+
const BYTE* idxBase; /* base pointer for idx */
|
721
|
+
|
722
|
+
U32 offcode;
|
723
|
+
const BYTE* match0;
|
724
|
+
size_t mLength;
|
725
|
+
const BYTE* matchEnd = 0; /* initialize to avoid warning, assert != 0 later */
|
726
|
+
|
727
|
+
size_t step;
|
728
|
+
const BYTE* nextStep;
|
729
|
+
const size_t kStepIncr = (1 << (kSearchStrength - 1));
|
573
730
|
|
574
731
|
(void)hasStep; /* not currently specialized on whether it's accelerated */
|
575
732
|
|
@@ -579,75 +736,202 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
|
|
579
736
|
if (prefixStartIndex == dictStartIndex)
|
580
737
|
return ZSTD_compressBlock_fast(ms, seqStore, rep, src, srcSize);
|
581
738
|
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
739
|
+
{ U32 const curr = (U32)(ip0 - base);
|
740
|
+
U32 const maxRep = curr - dictStartIndex;
|
741
|
+
if (offset_2 >= maxRep) offsetSaved2 = offset_2, offset_2 = 0;
|
742
|
+
if (offset_1 >= maxRep) offsetSaved1 = offset_1, offset_1 = 0;
|
743
|
+
}
|
744
|
+
|
745
|
+
/* start each op */
|
746
|
+
_start: /* Requires: ip0 */
|
747
|
+
|
748
|
+
step = stepSize;
|
749
|
+
nextStep = ip0 + kStepIncr;
|
750
|
+
|
751
|
+
/* calculate positions, ip0 - anchor == 0, so we skip step calc */
|
752
|
+
ip1 = ip0 + 1;
|
753
|
+
ip2 = ip0 + step;
|
754
|
+
ip3 = ip2 + 1;
|
755
|
+
|
756
|
+
if (ip3 >= ilimit) {
|
757
|
+
goto _cleanup;
|
758
|
+
}
|
759
|
+
|
760
|
+
hash0 = ZSTD_hashPtr(ip0, hlog, mls);
|
761
|
+
hash1 = ZSTD_hashPtr(ip1, hlog, mls);
|
762
|
+
|
763
|
+
idx = hashTable[hash0];
|
764
|
+
idxBase = idx < prefixStartIndex ? dictBase : base;
|
765
|
+
|
766
|
+
do {
|
767
|
+
{ /* load repcode match for ip[2] */
|
768
|
+
U32 const current2 = (U32)(ip2 - base);
|
769
|
+
U32 const repIndex = current2 - offset_1;
|
770
|
+
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
771
|
+
U32 rval;
|
772
|
+
if ( ((U32)(prefixStartIndex - repIndex) >= 4) /* intentional underflow */
|
773
|
+
& (offset_1 > 0) ) {
|
774
|
+
rval = MEM_read32(repBase + repIndex);
|
775
|
+
} else {
|
776
|
+
rval = MEM_read32(ip2) ^ 1; /* guaranteed to not match. */
|
610
777
|
}
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
778
|
+
|
779
|
+
/* write back hash table entry */
|
780
|
+
current0 = (U32)(ip0 - base);
|
781
|
+
hashTable[hash0] = current0;
|
782
|
+
|
783
|
+
/* check repcode at ip[2] */
|
784
|
+
if (MEM_read32(ip2) == rval) {
|
785
|
+
ip0 = ip2;
|
786
|
+
match0 = repBase + repIndex;
|
787
|
+
matchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
|
788
|
+
assert((match0 != prefixStart) & (match0 != dictStart));
|
789
|
+
mLength = ip0[-1] == match0[-1];
|
790
|
+
ip0 -= mLength;
|
791
|
+
match0 -= mLength;
|
792
|
+
offcode = REPCODE1_TO_OFFBASE;
|
793
|
+
mLength += 4;
|
794
|
+
goto _match;
|
620
795
|
} }
|
621
796
|
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
797
|
+
{ /* load match for ip[0] */
|
798
|
+
U32 const mval = idx >= dictStartIndex ?
|
799
|
+
MEM_read32(idxBase + idx) :
|
800
|
+
MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
801
|
+
|
802
|
+
/* check match at ip[0] */
|
803
|
+
if (MEM_read32(ip0) == mval) {
|
804
|
+
/* found a match! */
|
805
|
+
goto _offset;
|
806
|
+
} }
|
807
|
+
|
808
|
+
/* lookup ip[1] */
|
809
|
+
idx = hashTable[hash1];
|
810
|
+
idxBase = idx < prefixStartIndex ? dictBase : base;
|
811
|
+
|
812
|
+
/* hash ip[2] */
|
813
|
+
hash0 = hash1;
|
814
|
+
hash1 = ZSTD_hashPtr(ip2, hlog, mls);
|
815
|
+
|
816
|
+
/* advance to next positions */
|
817
|
+
ip0 = ip1;
|
818
|
+
ip1 = ip2;
|
819
|
+
ip2 = ip3;
|
820
|
+
|
821
|
+
/* write back hash table entry */
|
822
|
+
current0 = (U32)(ip0 - base);
|
823
|
+
hashTable[hash0] = current0;
|
824
|
+
|
825
|
+
{ /* load match for ip[0] */
|
826
|
+
U32 const mval = idx >= dictStartIndex ?
|
827
|
+
MEM_read32(idxBase + idx) :
|
828
|
+
MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
829
|
+
|
830
|
+
/* check match at ip[0] */
|
831
|
+
if (MEM_read32(ip0) == mval) {
|
832
|
+
/* found a match! */
|
833
|
+
goto _offset;
|
834
|
+
} }
|
835
|
+
|
836
|
+
/* lookup ip[1] */
|
837
|
+
idx = hashTable[hash1];
|
838
|
+
idxBase = idx < prefixStartIndex ? dictBase : base;
|
839
|
+
|
840
|
+
/* hash ip[2] */
|
841
|
+
hash0 = hash1;
|
842
|
+
hash1 = ZSTD_hashPtr(ip2, hlog, mls);
|
843
|
+
|
844
|
+
/* advance to next positions */
|
845
|
+
ip0 = ip1;
|
846
|
+
ip1 = ip2;
|
847
|
+
ip2 = ip0 + step;
|
848
|
+
ip3 = ip1 + step;
|
849
|
+
|
850
|
+
/* calculate step */
|
851
|
+
if (ip2 >= nextStep) {
|
852
|
+
step++;
|
853
|
+
PREFETCH_L1(ip1 + 64);
|
854
|
+
PREFETCH_L1(ip1 + 128);
|
855
|
+
nextStep += kStepIncr;
|
856
|
+
}
|
857
|
+
} while (ip3 < ilimit);
|
858
|
+
|
859
|
+
_cleanup:
|
860
|
+
/* Note that there are probably still a couple positions we could search.
|
861
|
+
* However, it seems to be a meaningful performance hit to try to search
|
862
|
+
* them. So let's not. */
|
863
|
+
|
864
|
+
/* If offset_1 started invalid (offsetSaved1 != 0) and became valid (offset_1 != 0),
|
865
|
+
* rotate saved offsets. See comment in ZSTD_compressBlock_fast_noDict for more context. */
|
866
|
+
offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
|
644
867
|
|
645
868
|
/* save reps for next block */
|
646
|
-
rep[0] = offset_1;
|
647
|
-
rep[1] = offset_2;
|
869
|
+
rep[0] = offset_1 ? offset_1 : offsetSaved1;
|
870
|
+
rep[1] = offset_2 ? offset_2 : offsetSaved2;
|
648
871
|
|
649
872
|
/* Return the last literals size */
|
650
873
|
return (size_t)(iend - anchor);
|
874
|
+
|
875
|
+
_offset: /* Requires: ip0, idx, idxBase */
|
876
|
+
|
877
|
+
/* Compute the offset code. */
|
878
|
+
{ U32 const offset = current0 - idx;
|
879
|
+
const BYTE* const lowMatchPtr = idx < prefixStartIndex ? dictStart : prefixStart;
|
880
|
+
matchEnd = idx < prefixStartIndex ? dictEnd : iend;
|
881
|
+
match0 = idxBase + idx;
|
882
|
+
offset_2 = offset_1;
|
883
|
+
offset_1 = offset;
|
884
|
+
offcode = OFFSET_TO_OFFBASE(offset);
|
885
|
+
mLength = 4;
|
886
|
+
|
887
|
+
/* Count the backwards match length. */
|
888
|
+
while (((ip0>anchor) & (match0>lowMatchPtr)) && (ip0[-1] == match0[-1])) {
|
889
|
+
ip0--;
|
890
|
+
match0--;
|
891
|
+
mLength++;
|
892
|
+
} }
|
893
|
+
|
894
|
+
_match: /* Requires: ip0, match0, offcode, matchEnd */
|
895
|
+
|
896
|
+
/* Count the forward length. */
|
897
|
+
assert(matchEnd != 0);
|
898
|
+
mLength += ZSTD_count_2segments(ip0 + mLength, match0 + mLength, iend, matchEnd, prefixStart);
|
899
|
+
|
900
|
+
ZSTD_storeSeq(seqStore, (size_t)(ip0 - anchor), anchor, iend, offcode, mLength);
|
901
|
+
|
902
|
+
ip0 += mLength;
|
903
|
+
anchor = ip0;
|
904
|
+
|
905
|
+
/* write next hash table entry */
|
906
|
+
if (ip1 < ip0) {
|
907
|
+
hashTable[hash1] = (U32)(ip1 - base);
|
908
|
+
}
|
909
|
+
|
910
|
+
/* Fill table and check for immediate repcode. */
|
911
|
+
if (ip0 <= ilimit) {
|
912
|
+
/* Fill Table */
|
913
|
+
assert(base+current0+2 > istart); /* check base overflow */
|
914
|
+
hashTable[ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2; /* here because current+2 could be > iend-8 */
|
915
|
+
hashTable[ZSTD_hashPtr(ip0-2, hlog, mls)] = (U32)(ip0-2-base);
|
916
|
+
|
917
|
+
while (ip0 <= ilimit) {
|
918
|
+
U32 const repIndex2 = (U32)(ip0-base) - offset_2;
|
919
|
+
const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
920
|
+
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (offset_2 > 0)) /* intentional underflow */
|
921
|
+
&& (MEM_read32(repMatch2) == MEM_read32(ip0)) ) {
|
922
|
+
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
923
|
+
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
924
|
+
{ U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; } /* swap offset_2 <=> offset_1 */
|
925
|
+
ZSTD_storeSeq(seqStore, 0 /*litlen*/, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
|
926
|
+
hashTable[ZSTD_hashPtr(ip0, hlog, mls)] = (U32)(ip0-base);
|
927
|
+
ip0 += repLength2;
|
928
|
+
anchor = ip0;
|
929
|
+
continue;
|
930
|
+
}
|
931
|
+
break;
|
932
|
+
} }
|
933
|
+
|
934
|
+
goto _start;
|
651
935
|
}
|
652
936
|
|
653
937
|
ZSTD_GEN_FAST_FN(extDict, 4, 0)
|
@@ -660,6 +944,7 @@ size_t ZSTD_compressBlock_fast_extDict(
|
|
660
944
|
void const* src, size_t srcSize)
|
661
945
|
{
|
662
946
|
U32 const mls = ms->cParams.minMatch;
|
947
|
+
assert(ms->dictMatchState == NULL);
|
663
948
|
switch(mls)
|
664
949
|
{
|
665
950
|
default: /* includes case 3 */
|