Coverage Report

Created: 2026-10-17 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zstd/lib/compress/zstd_double_fast.c
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under both the BSD-style license (found in the
6
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
 * in the COPYING file in the root directory of this source tree).
8
 * You may select, at your option, one of the above-listed licenses.
9
 */
10
11
#include "zstd_compress_internal.h"
12
#include "zstd_double_fast.h"
13
14
#ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
15
16
static
17
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
18
void ZSTD_fillDoubleHashTableForCDict(ZSTD_MatchState_t* ms,
19
                              void const* end, ZSTD_dictTableLoadMethod_e dtlm)
20
16.9k
{
21
16.9k
    const ZSTD_compressionParameters* const cParams = &ms->cParams;
22
16.9k
    U32* const hashLarge = ms->hashTable;
23
16.9k
    U32  const hBitsL = cParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
24
16.9k
    U32  const mls = cParams->minMatch;
25
16.9k
    U32* const hashSmall = ms->chainTable;
26
16.9k
    U32  const hBitsS = cParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
27
16.9k
    const BYTE* const base = ms->window.base;
28
16.9k
    const BYTE* ip = base + ms->nextToUpdate;
29
16.9k
    const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
30
16.9k
    const U32 fastHashFillStep = 3;
31
32
    /* Always insert every fastHashFillStep position into the hash tables.
33
     * Insert the other positions into the large hash table if their entry
34
     * is empty.
35
     */
36
3.86M
    for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
37
3.84M
        U32 const curr = (U32)(ip - base);
38
3.84M
        U32 i;
39
15.3M
        for (i = 0; i < fastHashFillStep; ++i) {
40
11.5M
            size_t const smHashAndTag = ZSTD_hashPtr(ip + i, hBitsS, mls);
41
11.5M
            size_t const lgHashAndTag = ZSTD_hashPtr(ip + i, hBitsL, 8);
42
11.5M
            if (i == 0) {
43
3.84M
                ZSTD_writeTaggedIndex(hashSmall, smHashAndTag, curr + i);
44
3.84M
            }
45
11.5M
            if (i == 0 || hashLarge[lgHashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS] == 0) {
46
5.59M
                ZSTD_writeTaggedIndex(hashLarge, lgHashAndTag, curr + i);
47
5.59M
            }
48
            /* Only load extra positions for ZSTD_dtlm_full */
49
11.5M
            if (dtlm == ZSTD_dtlm_fast)
50
0
                break;
51
11.5M
    }   }
52
16.9k
}
53
54
static
55
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
56
void ZSTD_fillDoubleHashTableForCCtx(ZSTD_MatchState_t* ms,
57
                              void const* end, ZSTD_dictTableLoadMethod_e dtlm)
58
3.21M
{
59
3.21M
    const ZSTD_compressionParameters* const cParams = &ms->cParams;
60
3.21M
    U32* const hashLarge = ms->hashTable;
61
3.21M
    U32  const hBitsL = cParams->hashLog;
62
3.21M
    U32  const mls = cParams->minMatch;
63
3.21M
    U32* const hashSmall = ms->chainTable;
64
3.21M
    U32  const hBitsS = cParams->chainLog;
65
3.21M
    const BYTE* const base = ms->window.base;
66
3.21M
    const BYTE* ip = base + ms->nextToUpdate;
67
3.21M
    const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
68
3.21M
    const U32 fastHashFillStep = 3;
69
70
    /* Always insert every fastHashFillStep position into the hash tables.
71
     * Insert the other positions into the large hash table if their entry
72
     * is empty.
73
     */
74
515M
    for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
75
512M
        U32 const curr = (U32)(ip - base);
76
512M
        U32 i;
77
512M
        for (i = 0; i < fastHashFillStep; ++i) {
78
512M
            size_t const smHash = ZSTD_hashPtr(ip + i, hBitsS, mls);
79
512M
            size_t const lgHash = ZSTD_hashPtr(ip + i, hBitsL, 8);
80
512M
            if (i == 0)
81
512M
                hashSmall[smHash] = curr + i;
82
512M
            if (i == 0 || hashLarge[lgHash] == 0)
83
512M
                hashLarge[lgHash] = curr + i;
84
            /* Only load extra positions for ZSTD_dtlm_full */
85
512M
            if (dtlm == ZSTD_dtlm_fast)
86
512M
                break;
87
512M
        }   }
88
3.21M
}
89
90
void ZSTD_fillDoubleHashTable(ZSTD_MatchState_t* ms,
91
                        const void* const end,
92
                        ZSTD_dictTableLoadMethod_e dtlm,
93
                        ZSTD_tableFillPurpose_e tfp)
94
3.23M
{
95
3.23M
    if (tfp == ZSTD_tfp_forCDict) {
96
16.9k
        ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
97
3.21M
    } else {
98
3.21M
        ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
99
3.21M
    }
100
3.23M
}
101
102
103
FORCE_INLINE_TEMPLATE
104
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
105
size_t ZSTD_compressBlock_doubleFast_noDict_generic(
106
        ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
107
        void const* src, size_t srcSize, U32 const mls /* template */)
108
2.52M
{
109
2.52M
    ZSTD_compressionParameters const* cParams = &ms->cParams;
110
2.52M
    U32* const hashLong = ms->hashTable;
111
2.52M
    const U32 hBitsL = cParams->hashLog;
112
2.52M
    U32* const hashSmall = ms->chainTable;
113
2.52M
    const U32 hBitsS = cParams->chainLog;
114
2.52M
    const BYTE* const base = ms->window.base;
115
2.52M
    const BYTE* const istart = (const BYTE*)src;
116
2.52M
    const BYTE* anchor = istart;
117
2.52M
    const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
118
    /* presumes that, if there is a dictionary, it must be using Attach mode */
119
2.52M
    const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
120
2.52M
    const BYTE* const prefixLowest = base + prefixLowestIndex;
121
2.52M
    const BYTE* const iend = istart + srcSize;
122
2.52M
    const BYTE* const ilimit = iend - HASH_READ_SIZE;
123
2.52M
    U32 offset_1=rep[0], offset_2=rep[1];
124
2.52M
    U32 offsetSaved1 = 0, offsetSaved2 = 0;
125
126
2.52M
    size_t mLength;
127
2.52M
    U32 offset;
128
2.52M
    U32 curr;
129
130
    /* how many positions to search before increasing step size */
131
2.52M
    const size_t kStepIncr = 1 << kSearchStrength;
132
    /* the position at which to increment the step size if no match is found */
133
2.52M
    const BYTE* nextStep;
134
2.52M
    size_t step; /* the current step size */
135
136
2.52M
    size_t hl0; /* the long hash at ip */
137
2.52M
    size_t hl1; /* the long hash at ip1 */
138
139
2.52M
    U32 idxl0; /* the long match index for ip */
140
2.52M
    U32 idxl1; /* the long match index for ip1 */
141
142
2.52M
    const BYTE* matchl0; /* the long match for ip */
143
2.52M
    const BYTE* matchs0; /* the short match for ip */
144
2.52M
    const BYTE* matchl1; /* the long match for ip1 */
145
2.52M
    const BYTE* matchs0_safe; /* matchs0 or safe address */
146
147
2.52M
    const BYTE* ip = istart; /* the current position */
148
2.52M
    const BYTE* ip1; /* the next position */
149
    /* Array of ~random data, should have low probability of matching data
150
     * we load from here instead of from tables, if matchl0/matchl1 are
151
     * invalid indices. Used to avoid unpredictable branches. */
152
2.52M
    const BYTE dummy[] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0xe2,0xb4};
153
154
2.52M
    DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_noDict_generic");
155
156
    /* init */
157
2.52M
    ip += ((ip - prefixLowest) == 0);
158
2.52M
    {
159
2.52M
        U32 const current = (U32)(ip - base);
160
2.52M
        U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
161
2.52M
        U32 const maxRep = current - windowLow;
162
2.52M
        if (offset_2 > maxRep) offsetSaved2 = offset_2, offset_2 = 0;
163
2.52M
        if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
164
2.52M
    }
165
166
    /* Outer Loop: one iteration per match found and stored */
167
14.0M
    while (1) {
168
14.0M
        step = 1;
169
14.0M
        nextStep = ip + kStepIncr;
170
14.0M
        ip1 = ip + step;
171
172
14.0M
        if (ip1 > ilimit) {
173
2.23M
            goto _cleanup;
174
2.23M
        }
175
176
11.8M
        hl0 = ZSTD_hashPtr(ip, hBitsL, 8);
177
11.8M
        idxl0 = hashLong[hl0];
178
11.8M
        matchl0 = base + idxl0;
179
180
        /* Inner Loop: one iteration per search / position */
181
94.0M
        do {
182
94.0M
            const size_t hs0 = ZSTD_hashPtr(ip, hBitsS, mls);
183
94.0M
            const U32 idxs0 = hashSmall[hs0];
184
94.0M
            curr = (U32)(ip-base);
185
94.0M
            matchs0 = base + idxs0;
186
187
94.0M
            hashLong[hl0] = hashSmall[hs0] = curr;   /* update hash tables */
188
189
            /* check noDict repcode */
190
94.0M
            if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) {
191
4.48M
                mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
192
4.48M
                ip++;
193
4.48M
                ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
194
4.48M
                goto _match_stored;
195
4.48M
            }
196
197
89.5M
            hl1 = ZSTD_hashPtr(ip1, hBitsL, 8);
198
199
            /* idxl0 > prefixLowestIndex is a (somewhat) unpredictable branch.
200
             * However expression below complies into conditional move. Since
201
             * match is unlikely and we only *branch* on idxl0 > prefixLowestIndex
202
             * if there is a match, all branches become predictable. */
203
89.5M
            {   const BYTE*  const matchl0_safe = ZSTD_selectAddr(idxl0, prefixLowestIndex, matchl0, &dummy[0]);
204
205
                /* check prefix long match */
206
89.5M
                if (MEM_read64(matchl0_safe) == MEM_read64(ip) && matchl0_safe == matchl0) {
207
2.69M
                    mLength = ZSTD_count(ip+8, matchl0+8, iend) + 8;
208
2.69M
                    offset = (U32)(ip-matchl0);
209
3.08M
                    while (((ip>anchor) & (matchl0>prefixLowest)) && (ip[-1] == matchl0[-1])) { ip--; matchl0--; mLength++; } /* catch up */
210
2.69M
                    goto _match_found;
211
2.69M
            }   }
212
213
86.8M
            idxl1 = hashLong[hl1];
214
86.8M
            matchl1 = base + idxl1;
215
216
            /* Same optimization as matchl0 above */
217
86.8M
            matchs0_safe = ZSTD_selectAddr(idxs0, prefixLowestIndex, matchs0, &dummy[0]);
218
219
            /* check prefix short match */
220
86.8M
            if(MEM_read32(matchs0_safe) == MEM_read32(ip) && matchs0_safe == matchs0) {
221
4.34M
                  goto _search_next_long;
222
4.34M
            }
223
224
82.4M
            if (ip1 >= nextStep) {
225
309k
                PREFETCH_L1(ip1 + 64);
226
309k
                PREFETCH_L1(ip1 + 128);
227
309k
                step++;
228
309k
                nextStep += kStepIncr;
229
309k
            }
230
82.4M
            ip = ip1;
231
82.4M
            ip1 += step;
232
233
82.4M
            hl0 = hl1;
234
82.4M
            idxl0 = idxl1;
235
82.4M
            matchl0 = matchl1;
236
    #if defined(__aarch64__)
237
            PREFETCH_L1(ip+256);
238
    #endif
239
82.4M
        } while (ip1 <= ilimit);
240
241
2.52M
_cleanup:
242
        /* If offset_1 started invalid (offsetSaved1 != 0) and became valid (offset_1 != 0),
243
         * rotate saved offsets. See comment in ZSTD_compressBlock_fast_noDict for more context. */
244
2.52M
        offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
245
246
        /* save reps for next block */
247
2.52M
        rep[0] = offset_1 ? offset_1 : offsetSaved1;
248
2.52M
        rep[1] = offset_2 ? offset_2 : offsetSaved2;
249
250
        /* Return the last literals size */
251
2.52M
        return (size_t)(iend - anchor);
252
253
4.34M
_search_next_long:
254
255
        /* short match found: let's check for a longer one */
256
4.34M
        mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
257
4.34M
        offset = (U32)(ip - matchs0);
258
259
        /* check long match at +1 position */
260
4.34M
        if ((idxl1 > prefixLowestIndex) && (MEM_read64(matchl1) == MEM_read64(ip1))) {
261
484k
            size_t const l1len = ZSTD_count(ip1+8, matchl1+8, iend) + 8;
262
484k
            if (l1len > mLength) {
263
                /* use the long match instead */
264
277k
                ip = ip1;
265
277k
                mLength = l1len;
266
277k
                offset = (U32)(ip-matchl1);
267
277k
                matchs0 = matchl1;
268
277k
            }
269
484k
        }
270
271
5.00M
        while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* complete backward */
272
273
        /* fall-through */
274
275
7.04M
_match_found: /* requires ip, offset, mLength */
276
7.04M
        offset_2 = offset_1;
277
7.04M
        offset_1 = offset;
278
279
7.04M
        if (step < 4) {
280
            /* It is unsafe to write this value back to the hashtable when ip1 is
281
             * greater than or equal to the new ip we will have after we're done
282
             * processing this match. Rather than perform that test directly
283
             * (ip1 >= ip + mLength), which costs speed in practice, we do a simpler
284
             * more predictable test. The minmatch even if we take a short match is
285
             * 4 bytes, so as long as step, the distance between ip and ip1
286
             * (initially) is less than 4, we know ip1 < new ip. */
287
7.03M
            hashLong[hl1] = (U32)(ip1 - base);
288
7.03M
        }
289
290
7.04M
        ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
291
292
11.5M
_match_stored:
293
        /* match found */
294
11.5M
        ip += mLength;
295
11.5M
        anchor = ip;
296
297
11.5M
        if (ip <= ilimit) {
298
            /* Complementary insertion */
299
            /* done after iLimit test, as candidates could be > iend-8 */
300
10.6M
            {   U32 const indexToInsert = curr+2;
301
10.6M
                hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
302
10.6M
                hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
303
10.6M
                hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
304
10.6M
                hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
305
10.6M
            }
306
307
            /* check immediate repcode */
308
11.6M
            while ( (ip <= ilimit)
309
11.4M
                 && ( (offset_2>0)
310
11.4M
                    & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
311
                /* store sequence */
312
1.00M
                size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
313
1.00M
                U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff;  /* swap offset_2 <=> offset_1 */
314
1.00M
                hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
315
1.00M
                hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
316
1.00M
                ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, rLength);
317
1.00M
                ip += rLength;
318
1.00M
                anchor = ip;
319
1.00M
                continue;   /* faster when present ... (?) */
320
1.00M
            }
321
10.6M
        }
322
11.5M
    }
323
2.52M
}
324
325
326
FORCE_INLINE_TEMPLATE
327
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
328
size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
329
        ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
330
        void const* src, size_t srcSize,
331
        U32 const mls /* template */)
332
587k
{
333
587k
    ZSTD_compressionParameters const* cParams = &ms->cParams;
334
587k
    U32* const hashLong = ms->hashTable;
335
587k
    const U32 hBitsL = cParams->hashLog;
336
587k
    U32* const hashSmall = ms->chainTable;
337
587k
    const U32 hBitsS = cParams->chainLog;
338
587k
    const BYTE* const base = ms->window.base;
339
587k
    const BYTE* const istart = (const BYTE*)src;
340
587k
    const BYTE* ip = istart;
341
587k
    const BYTE* anchor = istart;
342
587k
    const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
343
    /* presumes that, if there is a dictionary, it must be using Attach mode */
344
587k
    const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
345
587k
    const BYTE* const prefixLowest = base + prefixLowestIndex;
346
587k
    const BYTE* const iend = istart + srcSize;
347
587k
    const BYTE* const ilimit = iend - HASH_READ_SIZE;
348
587k
    U32 offset_1=rep[0], offset_2=rep[1];
349
350
587k
    const ZSTD_MatchState_t* const dms = ms->dictMatchState;
351
587k
    const ZSTD_compressionParameters* const dictCParams = &dms->cParams;
352
587k
    const U32* const dictHashLong  = dms->hashTable;
353
587k
    const U32* const dictHashSmall = dms->chainTable;
354
587k
    const U32 dictStartIndex       = dms->window.dictLimit;
355
587k
    const BYTE* const dictBase     = dms->window.base;
356
587k
    const BYTE* const dictStart    = dictBase + dictStartIndex;
357
587k
    const BYTE* const dictEnd      = dms->window.nextSrc;
358
587k
    const U32 dictIndexDelta       = prefixLowestIndex - (U32)(dictEnd - dictBase);
359
587k
    const U32 dictHBitsL           = dictCParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
360
587k
    const U32 dictHBitsS           = dictCParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
361
587k
    const U32 dictAndPrefixLength  = (U32)((ip - prefixLowest) + (dictEnd - dictStart));
362
363
587k
    DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_dictMatchState_generic");
364
365
    /* if a dictionary is attached, it must be within window range */
366
587k
    assert(ms->window.dictLimit + (1U << cParams->windowLog) >= endIndex);
367
368
587k
    if (ms->prefetchCDictTables) {
369
226k
        size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) * sizeof(U32);
370
226k
        size_t const chainTableBytes = (((size_t)1) << dictCParams->chainLog) * sizeof(U32);
371
226k
        PREFETCH_AREA(dictHashLong, hashTableBytes);
372
226k
        PREFETCH_AREA(dictHashSmall, chainTableBytes);
373
226k
    }
374
375
    /* init */
376
587k
    ip += (dictAndPrefixLength == 0);
377
378
    /* dictMatchState repCode checks don't currently handle repCode == 0
379
     * disabling. */
380
587k
    assert(offset_1 <= dictAndPrefixLength);
381
587k
    assert(offset_2 <= dictAndPrefixLength);
382
383
    /* Main Search Loop */
384
7.65M
    while (ip < ilimit) {   /* < instead of <=, because repcode check at (ip+1) */
385
7.06M
        size_t mLength;
386
7.06M
        U32 offset;
387
7.06M
        size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8);
388
7.06M
        size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
389
7.06M
        size_t const dictHashAndTagL = ZSTD_hashPtr(ip, dictHBitsL, 8);
390
7.06M
        size_t const dictHashAndTagS = ZSTD_hashPtr(ip, dictHBitsS, mls);
391
7.06M
        U32 const dictMatchIndexAndTagL = dictHashLong[dictHashAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS];
392
7.06M
        U32 const dictMatchIndexAndTagS = dictHashSmall[dictHashAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS];
393
7.06M
        int const dictTagsMatchL = ZSTD_comparePackedTags(dictMatchIndexAndTagL, dictHashAndTagL);
394
7.06M
        int const dictTagsMatchS = ZSTD_comparePackedTags(dictMatchIndexAndTagS, dictHashAndTagS);
395
7.06M
        U32 const curr = (U32)(ip-base);
396
7.06M
        U32 const matchIndexL = hashLong[h2];
397
7.06M
        U32 matchIndexS = hashSmall[h];
398
7.06M
        const BYTE* matchLong = base + matchIndexL;
399
7.06M
        const BYTE* match = base + matchIndexS;
400
7.06M
        const U32 repIndex = curr + 1 - offset_1;
401
7.06M
        const BYTE* repMatch = (repIndex < prefixLowestIndex) ?
402
1.21M
                               dictBase + (repIndex - dictIndexDelta) :
403
7.06M
                               base + repIndex;
404
7.06M
        hashLong[h2] = hashSmall[h] = curr;   /* update hash tables */
405
406
        /* check repcode */
407
7.06M
        if ((ZSTD_index_overlap_check(prefixLowestIndex, repIndex))
408
7.05M
            && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
409
255k
            const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
410
255k
            mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
411
255k
            ip++;
412
255k
            ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
413
255k
            goto _match_stored;
414
255k
        }
415
416
6.81M
        if ((matchIndexL >= prefixLowestIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
417
            /* check prefix long match */
418
208k
            mLength = ZSTD_count(ip+8, matchLong+8, iend) + 8;
419
208k
            offset = (U32)(ip-matchLong);
420
236k
            while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
421
208k
            goto _match_found;
422
6.60M
        } else if (dictTagsMatchL) {
423
            /* check dictMatchState long match */
424
198k
            U32 const dictMatchIndexL = dictMatchIndexAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS;
425
198k
            const BYTE* dictMatchL = dictBase + dictMatchIndexL;
426
198k
            assert(dictMatchL < dictEnd);
427
428
198k
            if (dictMatchL > dictStart && MEM_read64(dictMatchL) == MEM_read64(ip)) {
429
163k
                mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
430
163k
                offset = (U32)(curr - dictMatchIndexL - dictIndexDelta);
431
277k
                while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
432
163k
                goto _match_found;
433
163k
        }   }
434
435
6.43M
        if (matchIndexS > prefixLowestIndex) {
436
            /* short match  candidate */
437
4.40M
            if (MEM_read32(match) == MEM_read32(ip)) {
438
341k
                goto _search_next_long;
439
341k
            }
440
4.40M
        } else if (dictTagsMatchS) {
441
            /* check dictMatchState short match */
442
143k
            U32 const dictMatchIndexS = dictMatchIndexAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS;
443
143k
            match = dictBase + dictMatchIndexS;
444
143k
            matchIndexS = dictMatchIndexS + dictIndexDelta;
445
446
143k
            if (match > dictStart && MEM_read32(match) == MEM_read32(ip)) {
447
126k
                goto _search_next_long;
448
126k
        }   }
449
450
5.97M
        ip += ((ip-anchor) >> kSearchStrength) + 1;
451
#if defined(__aarch64__)
452
        PREFETCH_L1(ip+256);
453
#endif
454
5.97M
        continue;
455
456
468k
_search_next_long:
457
468k
        {   size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
458
468k
            size_t const dictHashAndTagL3 = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
459
468k
            U32 const matchIndexL3 = hashLong[hl3];
460
468k
            U32 const dictMatchIndexAndTagL3 = dictHashLong[dictHashAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS];
461
468k
            int const dictTagsMatchL3 = ZSTD_comparePackedTags(dictMatchIndexAndTagL3, dictHashAndTagL3);
462
468k
            const BYTE* matchL3 = base + matchIndexL3;
463
468k
            hashLong[hl3] = curr + 1;
464
465
            /* check prefix long +1 match */
466
468k
            if ((matchIndexL3 >= prefixLowestIndex) && (MEM_read64(matchL3) == MEM_read64(ip+1))) {
467
64.0k
                mLength = ZSTD_count(ip+9, matchL3+8, iend) + 8;
468
64.0k
                ip++;
469
64.0k
                offset = (U32)(ip-matchL3);
470
107k
                while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
471
64.0k
                goto _match_found;
472
404k
            } else if (dictTagsMatchL3) {
473
                /* check dict long +1 match */
474
40.0k
                U32 const dictMatchIndexL3 = dictMatchIndexAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS;
475
40.0k
                const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
476
40.0k
                assert(dictMatchL3 < dictEnd);
477
40.0k
                if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
478
33.3k
                    mLength = ZSTD_count_2segments(ip+1+8, dictMatchL3+8, iend, dictEnd, prefixLowest) + 8;
479
33.3k
                    ip++;
480
33.3k
                    offset = (U32)(curr + 1 - dictMatchIndexL3 - dictIndexDelta);
481
68.1k
                    while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
482
33.3k
                    goto _match_found;
483
33.3k
        }   }   }
484
485
        /* if no long +1 match, explore the short match we found */
486
370k
        if (matchIndexS < prefixLowestIndex) {
487
97.2k
            mLength = ZSTD_count_2segments(ip+4, match+4, iend, dictEnd, prefixLowest) + 4;
488
97.2k
            offset = (U32)(curr - matchIndexS);
489
170k
            while (((ip>anchor) & (match>dictStart)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
490
273k
        } else {
491
273k
            mLength = ZSTD_count(ip+4, match+4, iend) + 4;
492
273k
            offset = (U32)(ip - match);
493
333k
            while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
494
273k
        }
495
496
839k
_match_found:
497
839k
        offset_2 = offset_1;
498
839k
        offset_1 = offset;
499
500
839k
        ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
501
502
1.09M
_match_stored:
503
        /* match found */
504
1.09M
        ip += mLength;
505
1.09M
        anchor = ip;
506
507
1.09M
        if (ip <= ilimit) {
508
            /* Complementary insertion */
509
            /* done after iLimit test, as candidates could be > iend-8 */
510
793k
            {   U32 const indexToInsert = curr+2;
511
793k
                hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
512
793k
                hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
513
793k
                hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
514
793k
                hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
515
793k
            }
516
517
            /* check immediate repcode */
518
857k
            while (ip <= ilimit) {
519
845k
                U32 const current2 = (U32)(ip-base);
520
845k
                U32 const repIndex2 = current2 - offset_2;
521
845k
                const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
522
176k
                        dictBase + repIndex2 - dictIndexDelta :
523
845k
                        base + repIndex2;
524
845k
                if ( (ZSTD_index_overlap_check(prefixLowestIndex, repIndex2))
525
840k
                   && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
526
64.8k
                    const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
527
64.8k
                    size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
528
64.8k
                    U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;   /* swap offset_2 <=> offset_1 */
529
64.8k
                    ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
530
64.8k
                    hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
531
64.8k
                    hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
532
64.8k
                    ip += repLength2;
533
64.8k
                    anchor = ip;
534
64.8k
                    continue;
535
64.8k
                }
536
780k
                break;
537
845k
            }
538
793k
        }
539
1.09M
    }   /* while (ip < ilimit) */
540
541
    /* save reps for next block */
542
587k
    rep[0] = offset_1;
543
587k
    rep[1] = offset_2;
544
545
    /* Return the last literals size */
546
587k
    return (size_t)(iend - anchor);
547
587k
}
548
549
#define ZSTD_GEN_DFAST_FN(dictMode, mls)                                                                 \
550
    static size_t ZSTD_compressBlock_doubleFast_##dictMode##_##mls(                                      \
551
            ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],                          \
552
            void const* src, size_t srcSize)                                                             \
553
3.48M
    {                                                                                                    \
554
3.48M
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
3.48M
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_4
Line
Count
Source
553
613k
    {                                                                                                    \
554
613k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
613k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_5
Line
Count
Source
553
685k
    {                                                                                                    \
554
685k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
685k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_6
Line
Count
Source
553
632k
    {                                                                                                    \
554
632k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
632k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_7
Line
Count
Source
553
594k
    {                                                                                                    \
554
594k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
594k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_4
Line
Count
Source
553
161k
    {                                                                                                    \
554
161k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
161k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_5
Line
Count
Source
553
140k
    {                                                                                                    \
554
140k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
140k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_6
Line
Count
Source
553
135k
    {                                                                                                    \
554
135k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
135k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_7
Line
Count
Source
553
150k
    {                                                                                                    \
554
150k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
150k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_4
Line
Count
Source
553
130k
    {                                                                                                    \
554
130k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
130k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_5
Line
Count
Source
553
84.0k
    {                                                                                                    \
554
84.0k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
84.0k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_6
Line
Count
Source
553
64.2k
    {                                                                                                    \
554
64.2k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
64.2k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_7
Line
Count
Source
553
93.4k
    {                                                                                                    \
554
93.4k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
555
93.4k
    }
556
557
ZSTD_GEN_DFAST_FN(noDict, 4)
558
ZSTD_GEN_DFAST_FN(noDict, 5)
559
ZSTD_GEN_DFAST_FN(noDict, 6)
560
ZSTD_GEN_DFAST_FN(noDict, 7)
561
562
ZSTD_GEN_DFAST_FN(dictMatchState, 4)
563
ZSTD_GEN_DFAST_FN(dictMatchState, 5)
564
ZSTD_GEN_DFAST_FN(dictMatchState, 6)
565
ZSTD_GEN_DFAST_FN(dictMatchState, 7)
566
567
568
size_t ZSTD_compressBlock_doubleFast(
569
        ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
570
        void const* src, size_t srcSize)
571
2.52M
{
572
2.52M
    const U32 mls = ms->cParams.minMatch;
573
2.52M
    switch(mls)
574
2.52M
    {
575
460k
    default: /* includes case 3 */
576
613k
    case 4 :
577
613k
        return ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize);
578
685k
    case 5 :
579
685k
        return ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize);
580
632k
    case 6 :
581
632k
        return ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize);
582
594k
    case 7 :
583
594k
        return ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize);
584
2.52M
    }
585
2.52M
}
586
587
588
size_t ZSTD_compressBlock_doubleFast_dictMatchState(
589
        ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
590
        void const* src, size_t srcSize)
591
587k
{
592
587k
    const U32 mls = ms->cParams.minMatch;
593
587k
    switch(mls)
594
587k
    {
595
104k
    default: /* includes case 3 */
596
161k
    case 4 :
597
161k
        return ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize);
598
140k
    case 5 :
599
140k
        return ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize);
600
135k
    case 6 :
601
135k
        return ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize);
602
150k
    case 7 :
603
150k
        return ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize);
604
587k
    }
605
587k
}
606
607
608
static
609
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
610
size_t ZSTD_compressBlock_doubleFast_extDict_generic(
611
        ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
612
        void const* src, size_t srcSize,
613
        U32 const mls /* template */)
614
371k
{
615
371k
    ZSTD_compressionParameters const* cParams = &ms->cParams;
616
371k
    U32* const hashLong = ms->hashTable;
617
371k
    U32  const hBitsL = cParams->hashLog;
618
371k
    U32* const hashSmall = ms->chainTable;
619
371k
    U32  const hBitsS = cParams->chainLog;
620
371k
    const BYTE* const istart = (const BYTE*)src;
621
371k
    const BYTE* ip = istart;
622
371k
    const BYTE* anchor = istart;
623
371k
    const BYTE* const iend = istart + srcSize;
624
371k
    const BYTE* const ilimit = iend - 8;
625
371k
    const BYTE* const base = ms->window.base;
626
371k
    const U32   endIndex = (U32)((size_t)(istart - base) + srcSize);
627
371k
    const U32   lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, cParams->windowLog);
628
371k
    const U32   dictStartIndex = lowLimit;
629
371k
    const U32   dictLimit = ms->window.dictLimit;
630
371k
    const U32   prefixStartIndex = (dictLimit > lowLimit) ? dictLimit : lowLimit;
631
371k
    const BYTE* const prefixStart = base + prefixStartIndex;
632
371k
    const BYTE* const dictBase = ms->window.dictBase;
633
371k
    const BYTE* const dictStart = dictBase + dictStartIndex;
634
371k
    const BYTE* const dictEnd = dictBase + prefixStartIndex;
635
371k
    U32 offset_1=rep[0], offset_2=rep[1];
636
637
371k
    DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_extDict_generic (srcSize=%zu)", srcSize);
638
639
    /* if extDict is invalidated due to maxDistance, switch to "regular" variant */
640
371k
    if (prefixStartIndex == dictStartIndex)
641
19.1k
        return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize);
642
643
    /* Search Loop */
644
13.4M
    while (ip < ilimit) {  /* < instead of <=, because (ip+1) */
645
13.1M
        const size_t hSmall = ZSTD_hashPtr(ip, hBitsS, mls);
646
13.1M
        const U32 matchIndex = hashSmall[hSmall];
647
13.1M
        const BYTE* const matchBase = matchIndex < prefixStartIndex ? dictBase : base;
648
13.1M
        const BYTE* match = matchBase + matchIndex;
649
650
13.1M
        const size_t hLong = ZSTD_hashPtr(ip, hBitsL, 8);
651
13.1M
        const U32 matchLongIndex = hashLong[hLong];
652
13.1M
        const BYTE* const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase : base;
653
13.1M
        const BYTE* matchLong = matchLongBase + matchLongIndex;
654
655
13.1M
        const U32 curr = (U32)(ip-base);
656
13.1M
        const U32 repIndex = curr + 1 - offset_1;   /* offset_1 expected <= curr +1 */
657
13.1M
        const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
658
13.1M
        const BYTE* const repMatch = repBase + repIndex;
659
13.1M
        size_t mLength;
660
13.1M
        hashSmall[hSmall] = hashLong[hLong] = curr;   /* update hash table */
661
662
13.1M
        if (((ZSTD_index_overlap_check(prefixStartIndex, repIndex))
663
13.1M
            & (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */
664
13.0M
          && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
665
274k
            const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
666
274k
            mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
667
274k
            ip++;
668
549k
            ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
669
12.8M
        } else {
670
12.8M
            if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
671
314k
                const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
672
314k
                const BYTE* const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
673
314k
                U32 offset;
674
314k
                mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, prefixStart) + 8;
675
314k
                offset = curr - matchLongIndex;
676
487k
                while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; }   /* catch up */
677
314k
                offset_2 = offset_1;
678
314k
                offset_1 = offset;
679
314k
                ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
680
681
12.5M
            } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
682
332k
                size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
683
332k
                U32 const matchIndex3 = hashLong[h3];
684
332k
                const BYTE* const match3Base = matchIndex3 < prefixStartIndex ? dictBase : base;
685
332k
                const BYTE* match3 = match3Base + matchIndex3;
686
332k
                U32 offset;
687
332k
                hashLong[h3] = curr + 1;
688
332k
                if ( (matchIndex3 > dictStartIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) {
689
47.6k
                    const BYTE* const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
690
47.6k
                    const BYTE* const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
691
47.6k
                    mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, prefixStart) + 8;
692
47.6k
                    ip++;
693
47.6k
                    offset = curr+1 - matchIndex3;
694
76.2k
                    while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */
695
285k
                } else {
696
285k
                    const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
697
285k
                    const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
698
285k
                    mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
699
285k
                    offset = curr - matchIndex;
700
365k
                    while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; }   /* catch up */
701
285k
                }
702
332k
                offset_2 = offset_1;
703
332k
                offset_1 = offset;
704
332k
                ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
705
706
12.2M
            } else {
707
12.2M
                ip += ((ip-anchor) >> kSearchStrength) + 1;
708
12.2M
                continue;
709
12.2M
        }   }
710
711
        /* move to next sequence start */
712
921k
        ip += mLength;
713
921k
        anchor = ip;
714
715
921k
        if (ip <= ilimit) {
716
            /* Complementary insertion */
717
            /* done after iLimit test, as candidates could be > iend-8 */
718
812k
            {   U32 const indexToInsert = curr+2;
719
812k
                hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
720
812k
                hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
721
812k
                hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
722
812k
                hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
723
812k
            }
724
725
            /* check immediate repcode */
726
895k
            while (ip <= ilimit) {
727
886k
                U32 const current2 = (U32)(ip-base);
728
886k
                U32 const repIndex2 = current2 - offset_2;
729
886k
                const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
730
886k
                if ( ((ZSTD_index_overlap_check(prefixStartIndex, repIndex2))
731
886k
                    & (offset_2 <= current2 - dictStartIndex))
732
883k
                  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
733
82.9k
                    const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
734
82.9k
                    size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
735
82.9k
                    U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;   /* swap offset_2 <=> offset_1 */
736
82.9k
                    ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
737
82.9k
                    hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
738
82.9k
                    hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
739
82.9k
                    ip += repLength2;
740
82.9k
                    anchor = ip;
741
82.9k
                    continue;
742
82.9k
                }
743
803k
                break;
744
886k
    }   }   }
745
746
    /* save reps for next block */
747
352k
    rep[0] = offset_1;
748
352k
    rep[1] = offset_2;
749
750
    /* Return the last literals size */
751
352k
    return (size_t)(iend - anchor);
752
352k
}
753
754
ZSTD_GEN_DFAST_FN(extDict, 4)
755
ZSTD_GEN_DFAST_FN(extDict, 5)
756
ZSTD_GEN_DFAST_FN(extDict, 6)
757
ZSTD_GEN_DFAST_FN(extDict, 7)
758
759
size_t ZSTD_compressBlock_doubleFast_extDict(
760
        ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
761
        void const* src, size_t srcSize)
762
371k
{
763
371k
    U32 const mls = ms->cParams.minMatch;
764
371k
    switch(mls)
765
371k
    {
766
95.1k
    default: /* includes case 3 */
767
130k
    case 4 :
768
130k
        return ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize);
769
84.0k
    case 5 :
770
84.0k
        return ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize);
771
64.2k
    case 6 :
772
64.2k
        return ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize);
773
93.4k
    case 7 :
774
93.4k
        return ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize);
775
371k
    }
776
371k
}
777
778
#endif /* ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR */