Coverage Report

Created: 2024-05-21 06:17

/src/zstd/lib/compress/zstd_double_fast.c
Line
Count
Source (jump to first uncovered line)
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
18.6k
{
21
18.6k
    const ZSTD_compressionParameters* const cParams = &ms->cParams;
22
18.6k
    U32* const hashLarge = ms->hashTable;
23
18.6k
    U32  const hBitsL = cParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
24
18.6k
    U32  const mls = cParams->minMatch;
25
18.6k
    U32* const hashSmall = ms->chainTable;
26
18.6k
    U32  const hBitsS = cParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
27
18.6k
    const BYTE* const base = ms->window.base;
28
18.6k
    const BYTE* ip = base + ms->nextToUpdate;
29
18.6k
    const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
30
18.6k
    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
181M
    for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
37
181M
        U32 const curr = (U32)(ip - base);
38
181M
        U32 i;
39
726M
        for (i = 0; i < fastHashFillStep; ++i) {
40
544M
            size_t const smHashAndTag = ZSTD_hashPtr(ip + i, hBitsS, mls);
41
544M
            size_t const lgHashAndTag = ZSTD_hashPtr(ip + i, hBitsL, 8);
42
544M
            if (i == 0) {
43
181M
                ZSTD_writeTaggedIndex(hashSmall, smHashAndTag, curr + i);
44
181M
            }
45
544M
            if (i == 0 || hashLarge[lgHashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS] == 0) {
46
227M
                ZSTD_writeTaggedIndex(hashLarge, lgHashAndTag, curr + i);
47
227M
            }
48
            /* Only load extra positions for ZSTD_dtlm_full */
49
544M
            if (dtlm == ZSTD_dtlm_fast)
50
0
                break;
51
544M
    }   }
52
18.6k
}
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
5.36M
{
59
5.36M
    const ZSTD_compressionParameters* const cParams = &ms->cParams;
60
5.36M
    U32* const hashLarge = ms->hashTable;
61
5.36M
    U32  const hBitsL = cParams->hashLog;
62
5.36M
    U32  const mls = cParams->minMatch;
63
5.36M
    U32* const hashSmall = ms->chainTable;
64
5.36M
    U32  const hBitsS = cParams->chainLog;
65
5.36M
    const BYTE* const base = ms->window.base;
66
5.36M
    const BYTE* ip = base + ms->nextToUpdate;
67
5.36M
    const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
68
5.36M
    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
1.07G
    for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
75
1.07G
        U32 const curr = (U32)(ip - base);
76
1.07G
        U32 i;
77
1.07G
        for (i = 0; i < fastHashFillStep; ++i) {
78
1.07G
            size_t const smHash = ZSTD_hashPtr(ip + i, hBitsS, mls);
79
1.07G
            size_t const lgHash = ZSTD_hashPtr(ip + i, hBitsL, 8);
80
1.07G
            if (i == 0)
81
1.07G
                hashSmall[smHash] = curr + i;
82
1.07G
            if (i == 0 || hashLarge[lgHash] == 0)
83
1.07G
                hashLarge[lgHash] = curr + i;
84
            /* Only load extra positions for ZSTD_dtlm_full */
85
1.07G
            if (dtlm == ZSTD_dtlm_fast)
86
1.07G
                break;
87
1.07G
        }   }
88
5.36M
}
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
5.38M
{
95
5.38M
    if (tfp == ZSTD_tfp_forCDict) {
96
18.6k
        ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
97
5.36M
    } else {
98
5.36M
        ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
99
5.36M
    }
100
5.38M
}
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
4.43M
{
109
4.43M
    ZSTD_compressionParameters const* cParams = &ms->cParams;
110
4.43M
    U32* const hashLong = ms->hashTable;
111
4.43M
    const U32 hBitsL = cParams->hashLog;
112
4.43M
    U32* const hashSmall = ms->chainTable;
113
4.43M
    const U32 hBitsS = cParams->chainLog;
114
4.43M
    const BYTE* const base = ms->window.base;
115
4.43M
    const BYTE* const istart = (const BYTE*)src;
116
4.43M
    const BYTE* anchor = istart;
117
4.43M
    const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
118
    /* presumes that, if there is a dictionary, it must be using Attach mode */
119
4.43M
    const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
120
4.43M
    const BYTE* const prefixLowest = base + prefixLowestIndex;
121
4.43M
    const BYTE* const iend = istart + srcSize;
122
4.43M
    const BYTE* const ilimit = iend - HASH_READ_SIZE;
123
4.43M
    U32 offset_1=rep[0], offset_2=rep[1];
124
4.43M
    U32 offsetSaved1 = 0, offsetSaved2 = 0;
125
126
4.43M
    size_t mLength;
127
4.43M
    U32 offset;
128
4.43M
    U32 curr;
129
130
    /* how many positions to search before increasing step size */
131
4.43M
    const size_t kStepIncr = 1 << kSearchStrength;
132
    /* the position at which to increment the step size if no match is found */
133
4.43M
    const BYTE* nextStep;
134
4.43M
    size_t step; /* the current step size */
135
136
4.43M
    size_t hl0; /* the long hash at ip */
137
4.43M
    size_t hl1; /* the long hash at ip1 */
138
139
4.43M
    U32 idxl0; /* the long match index for ip */
140
4.43M
    U32 idxl1; /* the long match index for ip1 */
141
142
4.43M
    const BYTE* matchl0; /* the long match for ip */
143
4.43M
    const BYTE* matchs0; /* the short match for ip */
144
4.43M
    const BYTE* matchl1; /* the long match for ip1 */
145
146
4.43M
    const BYTE* ip = istart; /* the current position */
147
4.43M
    const BYTE* ip1; /* the next position */
148
149
4.43M
    DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_noDict_generic");
150
151
    /* init */
152
4.43M
    ip += ((ip - prefixLowest) == 0);
153
4.43M
    {
154
4.43M
        U32 const current = (U32)(ip - base);
155
4.43M
        U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
156
4.43M
        U32 const maxRep = current - windowLow;
157
4.43M
        if (offset_2 > maxRep) offsetSaved2 = offset_2, offset_2 = 0;
158
4.43M
        if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
159
4.43M
    }
160
161
    /* Outer Loop: one iteration per match found and stored */
162
30.3M
    while (1) {
163
30.2M
        step = 1;
164
30.2M
        nextStep = ip + kStepIncr;
165
30.2M
        ip1 = ip + step;
166
167
30.2M
        if (ip1 > ilimit) {
168
3.90M
            goto _cleanup;
169
3.90M
        }
170
171
26.3M
        hl0 = ZSTD_hashPtr(ip, hBitsL, 8);
172
26.3M
        idxl0 = hashLong[hl0];
173
26.3M
        matchl0 = base + idxl0;
174
175
        /* Inner Loop: one iteration per search / position */
176
216M
        do {
177
216M
            const size_t hs0 = ZSTD_hashPtr(ip, hBitsS, mls);
178
216M
            const U32 idxs0 = hashSmall[hs0];
179
216M
            curr = (U32)(ip-base);
180
216M
            matchs0 = base + idxs0;
181
182
216M
            hashLong[hl0] = hashSmall[hs0] = curr;   /* update hash tables */
183
184
            /* check noDict repcode */
185
216M
            if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) {
186
9.90M
                mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
187
9.90M
                ip++;
188
9.90M
                ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
189
0
                goto _match_stored;
190
9.90M
            }
191
192
206M
            hl1 = ZSTD_hashPtr(ip1, hBitsL, 8);
193
194
206M
            if (idxl0 > prefixLowestIndex) {
195
                /* check prefix long match */
196
102M
                if (MEM_read64(matchl0) == MEM_read64(ip)) {
197
6.79M
                    mLength = ZSTD_count(ip+8, matchl0+8, iend) + 8;
198
6.79M
                    offset = (U32)(ip-matchl0);
199
9.04M
                    while (((ip>anchor) & (matchl0>prefixLowest)) && (ip[-1] == matchl0[-1])) { ip--; matchl0--; mLength++; } /* catch up */
200
6.79M
                    goto _match_found;
201
6.79M
                }
202
102M
            }
203
204
199M
            idxl1 = hashLong[hl1];
205
199M
            matchl1 = base + idxl1;
206
207
199M
            if (idxs0 > prefixLowestIndex) {
208
                /* check prefix short match */
209
103M
                if (MEM_read32(matchs0) == MEM_read32(ip)) {
210
9.19M
                    goto _search_next_long;
211
9.19M
                }
212
103M
            }
213
214
190M
            if (ip1 >= nextStep) {
215
1.43M
                PREFETCH_L1(ip1 + 64);
216
1.43M
                PREFETCH_L1(ip1 + 128);
217
1.43M
                step++;
218
1.43M
                nextStep += kStepIncr;
219
1.43M
            }
220
190M
            ip = ip1;
221
190M
            ip1 += step;
222
223
190M
            hl0 = hl1;
224
190M
            idxl0 = idxl1;
225
190M
            matchl0 = matchl1;
226
    #if defined(__aarch64__)
227
            PREFETCH_L1(ip+256);
228
    #endif
229
190M
        } while (ip1 <= ilimit);
230
231
4.43M
_cleanup:
232
        /* If offset_1 started invalid (offsetSaved1 != 0) and became valid (offset_1 != 0),
233
         * rotate saved offsets. See comment in ZSTD_compressBlock_fast_noDict for more context. */
234
4.43M
        offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
235
236
        /* save reps for next block */
237
4.43M
        rep[0] = offset_1 ? offset_1 : offsetSaved1;
238
4.43M
        rep[1] = offset_2 ? offset_2 : offsetSaved2;
239
240
        /* Return the last literals size */
241
4.43M
        return (size_t)(iend - anchor);
242
243
9.19M
_search_next_long:
244
245
        /* check prefix long +1 match */
246
9.19M
        if (idxl1 > prefixLowestIndex) {
247
5.89M
            if (MEM_read64(matchl1) == MEM_read64(ip1)) {
248
908k
                ip = ip1;
249
908k
                mLength = ZSTD_count(ip+8, matchl1+8, iend) + 8;
250
908k
                offset = (U32)(ip-matchl1);
251
1.44M
                while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; } /* catch up */
252
908k
                goto _match_found;
253
908k
            }
254
5.89M
        }
255
256
        /* if no long +1 match, explore the short match we found */
257
8.28M
        mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
258
8.28M
        offset = (U32)(ip - matchs0);
259
9.19M
        while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
260
261
        /* fall-through */
262
263
15.9M
_match_found: /* requires ip, offset, mLength */
264
15.9M
        offset_2 = offset_1;
265
15.9M
        offset_1 = offset;
266
267
15.9M
        if (step < 4) {
268
            /* It is unsafe to write this value back to the hashtable when ip1 is
269
             * greater than or equal to the new ip we will have after we're done
270
             * processing this match. Rather than perform that test directly
271
             * (ip1 >= ip + mLength), which costs speed in practice, we do a simpler
272
             * more predictable test. The minmatch even if we take a short match is
273
             * 4 bytes, so as long as step, the distance between ip and ip1
274
             * (initially) is less than 4, we know ip1 < new ip. */
275
15.9M
            hashLong[hl1] = (U32)(ip1 - base);
276
15.9M
        }
277
278
15.9M
        ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
279
280
25.8M
_match_stored:
281
        /* match found */
282
25.8M
        ip += mLength;
283
25.8M
        anchor = ip;
284
285
25.8M
        if (ip <= ilimit) {
286
            /* Complementary insertion */
287
            /* done after iLimit test, as candidates could be > iend-8 */
288
24.2M
            {   U32 const indexToInsert = curr+2;
289
24.2M
                hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
290
24.2M
                hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
291
24.2M
                hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
292
24.2M
                hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
293
24.2M
            }
294
295
            /* check immediate repcode */
296
27.2M
            while ( (ip <= ilimit)
297
27.2M
                 && ( (offset_2>0)
298
27.0M
                    & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
299
                /* store sequence */
300
2.93M
                size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
301
2.93M
                U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff;  /* swap offset_2 <=> offset_1 */
302
2.93M
                hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
303
2.93M
                hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
304
2.93M
                ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, rLength);
305
0
                ip += rLength;
306
2.93M
                anchor = ip;
307
2.93M
                continue;   /* faster when present ... (?) */
308
2.93M
            }
309
24.2M
        }
310
25.8M
    }
311
4.43M
}
312
313
314
FORCE_INLINE_TEMPLATE
315
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
316
size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
317
        ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
318
        void const* src, size_t srcSize,
319
        U32 const mls /* template */)
320
645k
{
321
645k
    ZSTD_compressionParameters const* cParams = &ms->cParams;
322
645k
    U32* const hashLong = ms->hashTable;
323
645k
    const U32 hBitsL = cParams->hashLog;
324
645k
    U32* const hashSmall = ms->chainTable;
325
645k
    const U32 hBitsS = cParams->chainLog;
326
645k
    const BYTE* const base = ms->window.base;
327
645k
    const BYTE* const istart = (const BYTE*)src;
328
645k
    const BYTE* ip = istart;
329
645k
    const BYTE* anchor = istart;
330
645k
    const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
331
    /* presumes that, if there is a dictionary, it must be using Attach mode */
332
645k
    const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
333
645k
    const BYTE* const prefixLowest = base + prefixLowestIndex;
334
645k
    const BYTE* const iend = istart + srcSize;
335
645k
    const BYTE* const ilimit = iend - HASH_READ_SIZE;
336
645k
    U32 offset_1=rep[0], offset_2=rep[1];
337
338
645k
    const ZSTD_matchState_t* const dms = ms->dictMatchState;
339
645k
    const ZSTD_compressionParameters* const dictCParams = &dms->cParams;
340
645k
    const U32* const dictHashLong  = dms->hashTable;
341
645k
    const U32* const dictHashSmall = dms->chainTable;
342
645k
    const U32 dictStartIndex       = dms->window.dictLimit;
343
645k
    const BYTE* const dictBase     = dms->window.base;
344
645k
    const BYTE* const dictStart    = dictBase + dictStartIndex;
345
645k
    const BYTE* const dictEnd      = dms->window.nextSrc;
346
645k
    const U32 dictIndexDelta       = prefixLowestIndex - (U32)(dictEnd - dictBase);
347
645k
    const U32 dictHBitsL           = dictCParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
348
645k
    const U32 dictHBitsS           = dictCParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
349
645k
    const U32 dictAndPrefixLength  = (U32)((ip - prefixLowest) + (dictEnd - dictStart));
350
351
645k
    DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_dictMatchState_generic");
352
353
    /* if a dictionary is attached, it must be within window range */
354
645k
    assert(ms->window.dictLimit + (1U << cParams->windowLog) >= endIndex);
355
356
645k
    if (ms->prefetchCDictTables) {
357
323k
        size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) * sizeof(U32);
358
323k
        size_t const chainTableBytes = (((size_t)1) << dictCParams->chainLog) * sizeof(U32);
359
323k
        PREFETCH_AREA(dictHashLong, hashTableBytes);
360
323k
        PREFETCH_AREA(dictHashSmall, chainTableBytes);
361
323k
    }
362
363
    /* init */
364
645k
    ip += (dictAndPrefixLength == 0);
365
366
    /* dictMatchState repCode checks don't currently handle repCode == 0
367
     * disabling. */
368
645k
    assert(offset_1 <= dictAndPrefixLength);
369
645k
    assert(offset_2 <= dictAndPrefixLength);
370
371
    /* Main Search Loop */
372
8.16M
    while (ip < ilimit) {   /* < instead of <=, because repcode check at (ip+1) */
373
7.51M
        size_t mLength;
374
7.51M
        U32 offset;
375
7.51M
        size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8);
376
7.51M
        size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
377
7.51M
        size_t const dictHashAndTagL = ZSTD_hashPtr(ip, dictHBitsL, 8);
378
7.51M
        size_t const dictHashAndTagS = ZSTD_hashPtr(ip, dictHBitsS, mls);
379
7.51M
        U32 const dictMatchIndexAndTagL = dictHashLong[dictHashAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS];
380
7.51M
        U32 const dictMatchIndexAndTagS = dictHashSmall[dictHashAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS];
381
7.51M
        int const dictTagsMatchL = ZSTD_comparePackedTags(dictMatchIndexAndTagL, dictHashAndTagL);
382
7.51M
        int const dictTagsMatchS = ZSTD_comparePackedTags(dictMatchIndexAndTagS, dictHashAndTagS);
383
7.51M
        U32 const curr = (U32)(ip-base);
384
7.51M
        U32 const matchIndexL = hashLong[h2];
385
7.51M
        U32 matchIndexS = hashSmall[h];
386
7.51M
        const BYTE* matchLong = base + matchIndexL;
387
7.51M
        const BYTE* match = base + matchIndexS;
388
7.51M
        const U32 repIndex = curr + 1 - offset_1;
389
7.51M
        const BYTE* repMatch = (repIndex < prefixLowestIndex) ?
390
1.28M
                               dictBase + (repIndex - dictIndexDelta) :
391
7.51M
                               base + repIndex;
392
7.51M
        hashLong[h2] = hashSmall[h] = curr;   /* update hash tables */
393
394
        /* check repcode */
395
7.51M
        if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
396
7.51M
            && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
397
338k
            const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
398
338k
            mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
399
338k
            ip++;
400
338k
            ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
401
0
            goto _match_stored;
402
338k
        }
403
404
7.17M
        if (matchIndexL > prefixLowestIndex) {
405
            /* check prefix long match */
406
5.31M
            if (MEM_read64(matchLong) == MEM_read64(ip)) {
407
277k
                mLength = ZSTD_count(ip+8, matchLong+8, iend) + 8;
408
277k
                offset = (U32)(ip-matchLong);
409
329k
                while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
410
277k
                goto _match_found;
411
277k
            }
412
5.31M
        } else if (dictTagsMatchL) {
413
            /* check dictMatchState long match */
414
146k
            U32 const dictMatchIndexL = dictMatchIndexAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS;
415
146k
            const BYTE* dictMatchL = dictBase + dictMatchIndexL;
416
146k
            assert(dictMatchL < dictEnd);
417
418
146k
            if (dictMatchL > dictStart && MEM_read64(dictMatchL) == MEM_read64(ip)) {
419
133k
                mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
420
133k
                offset = (U32)(curr - dictMatchIndexL - dictIndexDelta);
421
217k
                while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
422
133k
                goto _match_found;
423
133k
        }   }
424
425
6.76M
        if (matchIndexS > prefixLowestIndex) {
426
            /* check prefix short match */
427
4.45M
            if (MEM_read32(match) == MEM_read32(ip)) {
428
410k
                goto _search_next_long;
429
410k
            }
430
4.45M
        } else if (dictTagsMatchS) {
431
            /* check dictMatchState short match */
432
168k
            U32 const dictMatchIndexS = dictMatchIndexAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS;
433
168k
            match = dictBase + dictMatchIndexS;
434
168k
            matchIndexS = dictMatchIndexS + dictIndexDelta;
435
436
168k
            if (match > dictStart && MEM_read32(match) == MEM_read32(ip)) {
437
150k
                goto _search_next_long;
438
150k
        }   }
439
440
6.20M
        ip += ((ip-anchor) >> kSearchStrength) + 1;
441
#if defined(__aarch64__)
442
        PREFETCH_L1(ip+256);
443
#endif
444
6.20M
        continue;
445
446
560k
_search_next_long:
447
560k
        {   size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
448
560k
            size_t const dictHashAndTagL3 = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
449
560k
            U32 const matchIndexL3 = hashLong[hl3];
450
560k
            U32 const dictMatchIndexAndTagL3 = dictHashLong[dictHashAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS];
451
560k
            int const dictTagsMatchL3 = ZSTD_comparePackedTags(dictMatchIndexAndTagL3, dictHashAndTagL3);
452
560k
            const BYTE* matchL3 = base + matchIndexL3;
453
560k
            hashLong[hl3] = curr + 1;
454
455
            /* check prefix long +1 match */
456
560k
            if (matchIndexL3 > prefixLowestIndex) {
457
431k
                if (MEM_read64(matchL3) == MEM_read64(ip+1)) {
458
85.9k
                    mLength = ZSTD_count(ip+9, matchL3+8, iend) + 8;
459
85.9k
                    ip++;
460
85.9k
                    offset = (U32)(ip-matchL3);
461
144k
                    while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
462
85.9k
                    goto _match_found;
463
85.9k
                }
464
431k
            } else if (dictTagsMatchL3) {
465
                /* check dict long +1 match */
466
25.1k
                U32 const dictMatchIndexL3 = dictMatchIndexAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS;
467
25.1k
                const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
468
25.1k
                assert(dictMatchL3 < dictEnd);
469
25.1k
                if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
470
22.3k
                    mLength = ZSTD_count_2segments(ip+1+8, dictMatchL3+8, iend, dictEnd, prefixLowest) + 8;
471
22.3k
                    ip++;
472
22.3k
                    offset = (U32)(curr + 1 - dictMatchIndexL3 - dictIndexDelta);
473
47.5k
                    while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
474
22.3k
                    goto _match_found;
475
22.3k
        }   }   }
476
477
        /* if no long +1 match, explore the short match we found */
478
452k
        if (matchIndexS < prefixLowestIndex) {
479
121k
            mLength = ZSTD_count_2segments(ip+4, match+4, iend, dictEnd, prefixLowest) + 4;
480
121k
            offset = (U32)(curr - matchIndexS);
481
248k
            while (((ip>anchor) & (match>dictStart)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
482
330k
        } else {
483
330k
            mLength = ZSTD_count(ip+4, match+4, iend) + 4;
484
330k
            offset = (U32)(ip - match);
485
398k
            while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
486
330k
        }
487
488
972k
_match_found:
489
972k
        offset_2 = offset_1;
490
972k
        offset_1 = offset;
491
492
972k
        ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
493
494
1.31M
_match_stored:
495
        /* match found */
496
1.31M
        ip += mLength;
497
1.31M
        anchor = ip;
498
499
1.31M
        if (ip <= ilimit) {
500
            /* Complementary insertion */
501
            /* done after iLimit test, as candidates could be > iend-8 */
502
1.00M
            {   U32 const indexToInsert = curr+2;
503
1.00M
                hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
504
1.00M
                hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
505
1.00M
                hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
506
1.00M
                hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
507
1.00M
            }
508
509
            /* check immediate repcode */
510
1.17M
            while (ip <= ilimit) {
511
1.16M
                U32 const current2 = (U32)(ip-base);
512
1.16M
                U32 const repIndex2 = current2 - offset_2;
513
1.16M
                const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
514
251k
                        dictBase + repIndex2 - dictIndexDelta :
515
1.16M
                        base + repIndex2;
516
1.16M
                if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
517
1.16M
                   && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
518
177k
                    const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
519
177k
                    size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
520
177k
                    U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;   /* swap offset_2 <=> offset_1 */
521
177k
                    ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
522
0
                    hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
523
177k
                    hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
524
177k
                    ip += repLength2;
525
177k
                    anchor = ip;
526
177k
                    continue;
527
177k
                }
528
985k
                break;
529
1.16M
            }
530
1.00M
        }
531
1.31M
    }   /* while (ip < ilimit) */
532
533
    /* save reps for next block */
534
645k
    rep[0] = offset_1;
535
645k
    rep[1] = offset_2;
536
537
    /* Return the last literals size */
538
645k
    return (size_t)(iend - anchor);
539
645k
}
540
541
#define ZSTD_GEN_DFAST_FN(dictMode, mls)                                                                 \
542
    static size_t ZSTD_compressBlock_doubleFast_##dictMode##_##mls(                                      \
543
            ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],                          \
544
            void const* src, size_t srcSize)                                                             \
545
5.63M
    {                                                                                                    \
546
5.63M
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
5.63M
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_4
Line
Count
Source
545
1.23M
    {                                                                                                    \
546
1.23M
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
1.23M
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_5
Line
Count
Source
545
1.06M
    {                                                                                                    \
546
1.06M
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
1.06M
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_6
Line
Count
Source
545
935k
    {                                                                                                    \
546
935k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
935k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_noDict_7
Line
Count
Source
545
1.19M
    {                                                                                                    \
546
1.19M
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
1.19M
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_4
Line
Count
Source
545
162k
    {                                                                                                    \
546
162k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
162k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_5
Line
Count
Source
545
149k
    {                                                                                                    \
546
149k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
149k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_6
Line
Count
Source
545
141k
    {                                                                                                    \
546
141k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
141k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_dictMatchState_7
Line
Count
Source
545
192k
    {                                                                                                    \
546
192k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
192k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_4
Line
Count
Source
545
166k
    {                                                                                                    \
546
166k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
166k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_5
Line
Count
Source
545
209k
    {                                                                                                    \
546
209k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
209k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_6
Line
Count
Source
545
64.9k
    {                                                                                                    \
546
64.9k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
64.9k
    }
zstd_double_fast.c:ZSTD_compressBlock_doubleFast_extDict_7
Line
Count
Source
545
117k
    {                                                                                                    \
546
117k
        return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
547
117k
    }
548
549
ZSTD_GEN_DFAST_FN(noDict, 4)
550
ZSTD_GEN_DFAST_FN(noDict, 5)
551
ZSTD_GEN_DFAST_FN(noDict, 6)
552
ZSTD_GEN_DFAST_FN(noDict, 7)
553
554
ZSTD_GEN_DFAST_FN(dictMatchState, 4)
555
ZSTD_GEN_DFAST_FN(dictMatchState, 5)
556
ZSTD_GEN_DFAST_FN(dictMatchState, 6)
557
ZSTD_GEN_DFAST_FN(dictMatchState, 7)
558
559
560
size_t ZSTD_compressBlock_doubleFast(
561
        ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
562
        void const* src, size_t srcSize)
563
4.43M
{
564
4.43M
    const U32 mls = ms->cParams.minMatch;
565
4.43M
    switch(mls)
566
4.43M
    {
567
548k
    default: /* includes case 3 */
568
1.23M
    case 4 :
569
1.23M
        return ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize);
570
1.06M
    case 5 :
571
1.06M
        return ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize);
572
935k
    case 6 :
573
935k
        return ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize);
574
1.19M
    case 7 :
575
1.19M
        return ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize);
576
4.43M
    }
577
4.43M
}
578
579
580
size_t ZSTD_compressBlock_doubleFast_dictMatchState(
581
        ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
582
        void const* src, size_t srcSize)
583
645k
{
584
645k
    const U32 mls = ms->cParams.minMatch;
585
645k
    switch(mls)
586
645k
    {
587
76.2k
    default: /* includes case 3 */
588
162k
    case 4 :
589
162k
        return ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize);
590
149k
    case 5 :
591
149k
        return ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize);
592
141k
    case 6 :
593
141k
        return ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize);
594
192k
    case 7 :
595
192k
        return ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize);
596
645k
    }
597
645k
}
598
599
600
static
601
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
602
size_t ZSTD_compressBlock_doubleFast_extDict_generic(
603
        ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
604
        void const* src, size_t srcSize,
605
        U32 const mls /* template */)
606
559k
{
607
559k
    ZSTD_compressionParameters const* cParams = &ms->cParams;
608
559k
    U32* const hashLong = ms->hashTable;
609
559k
    U32  const hBitsL = cParams->hashLog;
610
559k
    U32* const hashSmall = ms->chainTable;
611
559k
    U32  const hBitsS = cParams->chainLog;
612
559k
    const BYTE* const istart = (const BYTE*)src;
613
559k
    const BYTE* ip = istart;
614
559k
    const BYTE* anchor = istart;
615
559k
    const BYTE* const iend = istart + srcSize;
616
559k
    const BYTE* const ilimit = iend - 8;
617
559k
    const BYTE* const base = ms->window.base;
618
559k
    const U32   endIndex = (U32)((size_t)(istart - base) + srcSize);
619
559k
    const U32   lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, cParams->windowLog);
620
559k
    const U32   dictStartIndex = lowLimit;
621
559k
    const U32   dictLimit = ms->window.dictLimit;
622
559k
    const U32   prefixStartIndex = (dictLimit > lowLimit) ? dictLimit : lowLimit;
623
559k
    const BYTE* const prefixStart = base + prefixStartIndex;
624
559k
    const BYTE* const dictBase = ms->window.dictBase;
625
559k
    const BYTE* const dictStart = dictBase + dictStartIndex;
626
559k
    const BYTE* const dictEnd = dictBase + prefixStartIndex;
627
559k
    U32 offset_1=rep[0], offset_2=rep[1];
628
629
559k
    DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_extDict_generic (srcSize=%zu)", srcSize);
630
631
    /* if extDict is invalidated due to maxDistance, switch to "regular" variant */
632
559k
    if (prefixStartIndex == dictStartIndex)
633
30.4k
        return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize);
634
635
    /* Search Loop */
636
18.1M
    while (ip < ilimit) {  /* < instead of <=, because (ip+1) */
637
17.6M
        const size_t hSmall = ZSTD_hashPtr(ip, hBitsS, mls);
638
17.6M
        const U32 matchIndex = hashSmall[hSmall];
639
17.6M
        const BYTE* const matchBase = matchIndex < prefixStartIndex ? dictBase : base;
640
17.6M
        const BYTE* match = matchBase + matchIndex;
641
642
17.6M
        const size_t hLong = ZSTD_hashPtr(ip, hBitsL, 8);
643
17.6M
        const U32 matchLongIndex = hashLong[hLong];
644
17.6M
        const BYTE* const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase : base;
645
17.6M
        const BYTE* matchLong = matchLongBase + matchLongIndex;
646
647
17.6M
        const U32 curr = (U32)(ip-base);
648
17.6M
        const U32 repIndex = curr + 1 - offset_1;   /* offset_1 expected <= curr +1 */
649
17.6M
        const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
650
17.6M
        const BYTE* const repMatch = repBase + repIndex;
651
17.6M
        size_t mLength;
652
17.6M
        hashSmall[hSmall] = hashLong[hLong] = curr;   /* update hash table */
653
654
17.6M
        if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
655
17.6M
            & (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */
656
17.6M
          && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
657
1.45M
            const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
658
1.45M
            mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
659
1.45M
            ip++;
660
2.91M
            ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
661
16.1M
        } else {
662
16.1M
            if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
663
1.12M
                const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
664
1.12M
                const BYTE* const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
665
1.12M
                U32 offset;
666
1.12M
                mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, prefixStart) + 8;
667
1.12M
                offset = curr - matchLongIndex;
668
1.36M
                while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; }   /* catch up */
669
1.12M
                offset_2 = offset_1;
670
1.12M
                offset_1 = offset;
671
1.12M
                ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
672
673
15.0M
            } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
674
586k
                size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
675
586k
                U32 const matchIndex3 = hashLong[h3];
676
586k
                const BYTE* const match3Base = matchIndex3 < prefixStartIndex ? dictBase : base;
677
586k
                const BYTE* match3 = match3Base + matchIndex3;
678
586k
                U32 offset;
679
586k
                hashLong[h3] = curr + 1;
680
586k
                if ( (matchIndex3 > dictStartIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) {
681
62.6k
                    const BYTE* const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
682
62.6k
                    const BYTE* const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
683
62.6k
                    mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, prefixStart) + 8;
684
62.6k
                    ip++;
685
62.6k
                    offset = curr+1 - matchIndex3;
686
100k
                    while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */
687
524k
                } else {
688
524k
                    const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
689
524k
                    const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
690
524k
                    mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
691
524k
                    offset = curr - matchIndex;
692
651k
                    while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; }   /* catch up */
693
524k
                }
694
586k
                offset_2 = offset_1;
695
586k
                offset_1 = offset;
696
586k
                ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
697
698
14.4M
            } else {
699
14.4M
                ip += ((ip-anchor) >> kSearchStrength) + 1;
700
14.4M
                continue;
701
14.4M
        }   }
702
703
        /* move to next sequence start */
704
3.17M
        ip += mLength;
705
3.17M
        anchor = ip;
706
707
3.17M
        if (ip <= ilimit) {
708
            /* Complementary insertion */
709
            /* done after iLimit test, as candidates could be > iend-8 */
710
3.00M
            {   U32 const indexToInsert = curr+2;
711
3.00M
                hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
712
3.00M
                hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
713
3.00M
                hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
714
3.00M
                hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
715
3.00M
            }
716
717
            /* check immediate repcode */
718
5.02M
            while (ip <= ilimit) {
719
5.00M
                U32 const current2 = (U32)(ip-base);
720
5.00M
                U32 const repIndex2 = current2 - offset_2;
721
5.00M
                const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
722
5.00M
                if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3)   /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
723
5.00M
                    & (offset_2 <= current2 - dictStartIndex))
724
5.00M
                  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
725
2.01M
                    const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
726
2.01M
                    size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
727
2.01M
                    U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;   /* swap offset_2 <=> offset_1 */
728
2.01M
                    ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
729
0
                    hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
730
2.01M
                    hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
731
2.01M
                    ip += repLength2;
732
2.01M
                    anchor = ip;
733
2.01M
                    continue;
734
2.01M
                }
735
2.98M
                break;
736
5.00M
    }   }   }
737
738
    /* save reps for next block */
739
528k
    rep[0] = offset_1;
740
528k
    rep[1] = offset_2;
741
742
    /* Return the last literals size */
743
528k
    return (size_t)(iend - anchor);
744
528k
}
745
746
ZSTD_GEN_DFAST_FN(extDict, 4)
747
ZSTD_GEN_DFAST_FN(extDict, 5)
748
ZSTD_GEN_DFAST_FN(extDict, 6)
749
ZSTD_GEN_DFAST_FN(extDict, 7)
750
751
size_t ZSTD_compressBlock_doubleFast_extDict(
752
        ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
753
        void const* src, size_t srcSize)
754
559k
{
755
559k
    U32 const mls = ms->cParams.minMatch;
756
559k
    switch(mls)
757
559k
    {
758
59.7k
    default: /* includes case 3 */
759
166k
    case 4 :
760
166k
        return ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize);
761
209k
    case 5 :
762
209k
        return ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize);
763
64.9k
    case 6 :
764
64.9k
        return ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize);
765
117k
    case 7 :
766
117k
        return ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize);
767
559k
    }
768
559k
}
769
770
#endif /* ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR */