Skip to main content

libzstd_rs_sys/lib/compress/
zstd_lazy.rs

1use core::arch::asm;
2#[repr(C)]
3pub struct optState_t {
4    pub litFreq: *mut core::ffi::c_uint,
5    pub litLengthFreq: *mut core::ffi::c_uint,
6    pub matchLengthFreq: *mut core::ffi::c_uint,
7    pub offCodeFreq: *mut core::ffi::c_uint,
8    pub matchTable: *mut ZSTD_match_t,
9    pub priceTable: *mut ZSTD_optimal_t,
10    pub litSum: u32,
11    pub litLengthSum: u32,
12    pub matchLengthSum: u32,
13    pub offCodeSum: u32,
14    pub litSumBasePrice: u32,
15    pub litLengthSumBasePrice: u32,
16    pub matchLengthSumBasePrice: u32,
17    pub offCodeSumBasePrice: u32,
18    pub priceType: ZSTD_OptPrice_e,
19    pub symbolCosts: *const ZSTD_entropyCTables_t,
20    pub literalCompressionMode: ZSTD_ParamSwitch_e,
21}
22#[repr(C)]
23pub struct ZSTD_entropyCTables_t {
24    pub huf: ZSTD_hufCTables_t,
25    pub fse: ZSTD_fseCTables_t,
26}
27#[repr(C)]
28pub struct ZSTD_fseCTables_t {
29    pub offcodeCTable: [FSE_CTable; 193],
30    pub matchlengthCTable: [FSE_CTable; 363],
31    pub litlengthCTable: [FSE_CTable; 329],
32    pub offcode_repeatMode: FSE_repeat,
33    pub matchlength_repeatMode: FSE_repeat,
34    pub litlength_repeatMode: FSE_repeat,
35}
36#[repr(C)]
37pub struct ZSTD_hufCTables_t {
38    pub CTable: [HUF_CElt; 257],
39    pub repeatMode: HUF_repeat,
40}
41#[repr(C)]
42pub struct ZSTD_match_t {
43    pub off: u32,
44    pub len: u32,
45}
46
47pub type ZSTD_dictMode_e = core::ffi::c_uint;
48pub const ZSTD_dedicatedDictSearch: ZSTD_dictMode_e = 3;
49pub const ZSTD_dictMatchState: ZSTD_dictMode_e = 2;
50pub const ZSTD_extDict: ZSTD_dictMode_e = 1;
51pub const ZSTD_noDict: ZSTD_dictMode_e = 0;
52pub type searchMethod_e = core::ffi::c_uint;
53pub const search_rowHash: searchMethod_e = 2;
54pub const search_binaryTree: searchMethod_e = 1;
55pub const search_hashChain: searchMethod_e = 0;
56pub type ZSTD_VecMask = u64;
57
58use libc::size_t;
59
60use crate::lib::common::bits::ZSTD_highbit32;
61use crate::lib::common::fse::{FSE_CTable, FSE_repeat};
62use crate::lib::common::huf::{HUF_CElt, HUF_repeat};
63use crate::lib::common::mem::MEM_read32;
64use crate::lib::common::zstd_internal::ZSTD_REP_NUM;
65use crate::lib::compress::zstd_compress::{SeqStore_t, ZSTD_MatchState_t, ZSTD_optimal_t};
66use crate::lib::compress::zstd_compress_internal::{
67    ZSTD_OptPrice_e, ZSTD_count, ZSTD_count_2segments, ZSTD_getLowestMatchIndex,
68    ZSTD_getLowestPrefixIndex, ZSTD_hashPtr, ZSTD_hashPtrSalted, ZSTD_index_overlap_check,
69    ZSTD_storeSeq,
70};
71use crate::lib::polyfill::{prefetch_read_data, Locality};
72use crate::lib::zstd::{ZSTD_ParamSwitch_e, ZSTD_compressionParameters};
73pub const kSearchStrength: core::ffi::c_int = 8;
74pub const ZSTD_DUBT_UNSORTED_MARK: core::ffi::c_int = 1;
75pub const ZSTD_ROW_HASH_CACHE_SIZE: core::ffi::c_int = 8;
76
77pub const REPCODE1_TO_OFFBASE: core::ffi::c_int = 1;
78
79pub const ZSTD_LAZY_DDSS_BUCKET_LOG: core::ffi::c_int = 2;
80pub const ZSTD_ROW_HASH_TAG_BITS: core::ffi::c_int = 8;
81pub const kLazySkippingStep: core::ffi::c_int = 8;
82unsafe fn ZSTD_updateDUBT(ms: &mut ZSTD_MatchState_t, ip: *const u8, iend: *const u8, mls: u32) {
83    let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
84    let hashTable = ms.hashTable;
85    let hashLog = (*cParams).hashLog;
86    let bt = ms.chainTable;
87    let btLog = ((*cParams).chainLog).wrapping_sub(1);
88    let btMask = (((1) << btLog) - 1) as u32;
89    let base = ms.window.base;
90    let target = ip.offset_from(base) as core::ffi::c_long as u32;
91    let mut idx = ms.nextToUpdate;
92
93    assert!(ip.wrapping_add(8) <= iend); /* condition for ZSTD_hashPtr */
94
95    while idx < target {
96        let h = ZSTD_hashPtr(
97            base.offset(idx as isize) as *const core::ffi::c_void,
98            hashLog,
99            mls,
100        );
101        let matchIndex = *hashTable.add(h);
102        let nextCandidatePtr = bt.offset((2 * (idx & btMask)) as isize);
103        let sortMarkPtr = nextCandidatePtr.add(1);
104        *hashTable.add(h) = idx;
105        *nextCandidatePtr = matchIndex;
106        *sortMarkPtr = ZSTD_DUBT_UNSORTED_MARK as u32;
107        idx = idx.wrapping_add(1);
108    }
109    ms.nextToUpdate = target;
110}
111unsafe fn ZSTD_insertDUBT1(
112    ms: *const ZSTD_MatchState_t,
113    curr: u32,
114    inputEnd: *const u8,
115    mut nbCompares: u32,
116    btLow: u32,
117    dictMode: ZSTD_dictMode_e,
118) {
119    let cParams: *const ZSTD_compressionParameters = &(*ms).cParams;
120    let bt = (*ms).chainTable;
121    let btLog = ((*cParams).chainLog).wrapping_sub(1);
122    let btMask = (((1) << btLog) - 1) as u32;
123    let mut commonLengthSmaller = 0;
124    let mut commonLengthLarger = 0;
125    let base = (*ms).window.base;
126    let dictBase = (*ms).window.dictBase;
127    let dictLimit = (*ms).window.dictLimit;
128    let ip = if curr >= dictLimit {
129        base.offset(curr as isize)
130    } else {
131        dictBase.offset(curr as isize)
132    };
133    let iend = if curr >= dictLimit {
134        inputEnd
135    } else {
136        dictBase.offset(dictLimit as isize)
137    };
138    let dictEnd = dictBase.offset(dictLimit as isize);
139    let prefixStart = base.offset(dictLimit as isize);
140    let mut match_0 = core::ptr::null::<u8>();
141    let mut smallerPtr = bt.offset((2 * (curr & btMask)) as isize);
142    let mut largerPtr = smallerPtr.add(1);
143    let mut matchIndex = *smallerPtr;
144    let mut dummy32: u32 = 0;
145    let windowValid = (*ms).window.lowLimit;
146    let maxDistance = (1) << (*cParams).windowLog;
147    let windowLow = if curr.wrapping_sub(windowValid) > maxDistance {
148        curr.wrapping_sub(maxDistance)
149    } else {
150        windowValid
151    };
152    while nbCompares != 0 && matchIndex > windowLow {
153        let nextPtr = bt.offset((2 * (matchIndex & btMask)) as isize);
154        let mut matchLength = if commonLengthSmaller < commonLengthLarger {
155            commonLengthSmaller
156        } else {
157            commonLengthLarger
158        };
159        if dictMode as core::ffi::c_uint != ZSTD_extDict as core::ffi::c_int as core::ffi::c_uint
160            || (matchIndex as size_t).wrapping_add(matchLength) >= dictLimit as size_t
161            || curr < dictLimit
162        {
163            let mBase = if dictMode as core::ffi::c_uint
164                != ZSTD_extDict as core::ffi::c_int as core::ffi::c_uint
165                || (matchIndex as size_t).wrapping_add(matchLength) >= dictLimit as size_t
166            {
167                base
168            } else {
169                dictBase
170            };
171            match_0 = mBase.offset(matchIndex as isize);
172            matchLength = matchLength.wrapping_add(ZSTD_count(
173                ip.add(matchLength),
174                match_0.add(matchLength),
175                iend,
176            ));
177        } else {
178            match_0 = dictBase.offset(matchIndex as isize);
179            matchLength = matchLength.wrapping_add(ZSTD_count_2segments(
180                ip.add(matchLength),
181                match_0.add(matchLength),
182                iend,
183                dictEnd,
184                prefixStart,
185            ));
186            if (matchIndex as size_t).wrapping_add(matchLength) >= dictLimit as size_t {
187                match_0 = base.offset(matchIndex as isize);
188            }
189        }
190        if ip.add(matchLength) == iend {
191            break;
192        } else {
193            if (*match_0.add(matchLength) as core::ffi::c_int)
194                < *ip.add(matchLength) as core::ffi::c_int
195            {
196                *smallerPtr = matchIndex;
197                commonLengthSmaller = matchLength;
198                if matchIndex <= btLow {
199                    smallerPtr = &mut dummy32;
200                    break;
201                } else {
202                    smallerPtr = nextPtr.add(1);
203                    matchIndex = *nextPtr.add(1);
204                }
205            } else {
206                *largerPtr = matchIndex;
207                commonLengthLarger = matchLength;
208                if matchIndex <= btLow {
209                    largerPtr = &mut dummy32;
210                    break;
211                } else {
212                    largerPtr = nextPtr;
213                    matchIndex = *nextPtr;
214                }
215            }
216            nbCompares = nbCompares.wrapping_sub(1);
217        }
218    }
219    *largerPtr = 0;
220    *smallerPtr = *largerPtr;
221}
222unsafe fn ZSTD_DUBT_findBetterDictMatch(
223    ms: *const ZSTD_MatchState_t,
224    ip: *const u8,
225    iend: *const u8,
226    offsetPtr: *mut size_t,
227    mut bestLength: size_t,
228    mut nbCompares: u32,
229    mls: u32,
230    dictMode: ZSTD_dictMode_e,
231) -> size_t {
232    let dms = (*ms).dictMatchState;
233    let dmsCParams: *const ZSTD_compressionParameters = &(*dms).cParams;
234    let dictHashTable: *const u32 = (*dms).hashTable;
235    let hashLog = (*dmsCParams).hashLog;
236    let h = ZSTD_hashPtr(ip as *const core::ffi::c_void, hashLog, mls);
237    let mut dictMatchIndex = *dictHashTable.add(h);
238    let base = (*ms).window.base;
239    let prefixStart = base.offset((*ms).window.dictLimit as isize);
240    let curr = ip.offset_from(base) as core::ffi::c_long as u32;
241    let dictBase = (*dms).window.base;
242    let dictEnd = (*dms).window.nextSrc;
243    let dictHighLimit =
244        ((*dms).window.nextSrc).offset_from((*dms).window.base) as core::ffi::c_long as u32;
245    let dictLowLimit = (*dms).window.lowLimit;
246    let dictIndexDelta = ((*ms).window.lowLimit).wrapping_sub(dictHighLimit);
247    let dictBt = (*dms).chainTable;
248    let btLog = ((*dmsCParams).chainLog).wrapping_sub(1);
249    let btMask = (((1) << btLog) - 1) as u32;
250    let btLow = if btMask >= dictHighLimit.wrapping_sub(dictLowLimit) {
251        dictLowLimit
252    } else {
253        dictHighLimit.wrapping_sub(btMask)
254    };
255    let mut commonLengthSmaller = 0 as size_t;
256    let mut commonLengthLarger = 0 as size_t;
257
258    assert_eq!(dictMode, ZSTD_dictMatchState);
259
260    while nbCompares != 0 && dictMatchIndex > dictLowLimit {
261        let nextPtr = dictBt.offset((2 * (dictMatchIndex & btMask)) as isize);
262        let mut matchLength = if commonLengthSmaller < commonLengthLarger {
263            commonLengthSmaller
264        } else {
265            commonLengthLarger
266        };
267        let mut match_0 = dictBase.offset(dictMatchIndex as isize);
268        matchLength = matchLength.wrapping_add(ZSTD_count_2segments(
269            ip.add(matchLength),
270            match_0.add(matchLength),
271            iend,
272            dictEnd,
273            prefixStart,
274        ));
275        if (dictMatchIndex as size_t).wrapping_add(matchLength) >= dictHighLimit as size_t {
276            match_0 = base
277                .offset(dictMatchIndex as isize)
278                .offset(dictIndexDelta as isize);
279        }
280        if matchLength > bestLength {
281            let matchIndex = dictMatchIndex.wrapping_add(dictIndexDelta);
282            if 4 * matchLength.wrapping_sub(bestLength) as core::ffi::c_int
283                > (ZSTD_highbit32(curr.wrapping_sub(matchIndex).wrapping_add(1)))
284                    .wrapping_sub(ZSTD_highbit32((*offsetPtr as u32).wrapping_add(1)))
285                    as core::ffi::c_int
286            {
287                bestLength = matchLength;
288                *offsetPtr = curr
289                    .wrapping_sub(matchIndex)
290                    .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
291            }
292            if ip.add(matchLength) == iend {
293                break;
294            }
295        }
296        if (*match_0.add(matchLength) as core::ffi::c_int)
297            < *ip.add(matchLength) as core::ffi::c_int
298        {
299            if dictMatchIndex <= btLow {
300                break;
301            }
302            commonLengthSmaller = matchLength;
303            dictMatchIndex = *nextPtr.add(1);
304        } else {
305            if dictMatchIndex <= btLow {
306                break;
307            }
308            commonLengthLarger = matchLength;
309            dictMatchIndex = *nextPtr;
310        }
311        nbCompares = nbCompares.wrapping_sub(1);
312    }
313
314    bestLength
315}
316unsafe fn ZSTD_DUBT_findBestMatch(
317    ms: &mut ZSTD_MatchState_t,
318    ip: *const u8,
319    iend: *const u8,
320    offBasePtr: *mut size_t,
321    mls: u32,
322    dictMode: ZSTD_dictMode_e,
323) -> size_t {
324    let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
325    let hashTable = ms.hashTable;
326    let hashLog = (*cParams).hashLog;
327    let h = ZSTD_hashPtr(ip as *const core::ffi::c_void, hashLog, mls);
328    let mut matchIndex = *hashTable.add(h);
329    let base = ms.window.base;
330    let curr = ip.offset_from(base) as core::ffi::c_long as u32;
331    let windowLow = ZSTD_getLowestMatchIndex(ms, curr, (*cParams).windowLog);
332    let bt = ms.chainTable;
333    let btLog = ((*cParams).chainLog).wrapping_sub(1);
334    let btMask = (((1) << btLog) - 1) as u32;
335    let btLow = if btMask >= curr {
336        0
337    } else {
338        curr.wrapping_sub(btMask)
339    };
340    let unsortLimit = if btLow > windowLow { btLow } else { windowLow };
341    let mut nextCandidate = bt.offset((2 * (matchIndex & btMask)) as isize);
342    let mut unsortedMark = bt.offset((2 * (matchIndex & btMask)) as isize).add(1);
343    let mut nbCompares = (1 as core::ffi::c_uint) << (*cParams).searchLog;
344    let mut nbCandidates = nbCompares;
345    let mut previousCandidate = 0;
346    while matchIndex > unsortLimit
347        && *unsortedMark == ZSTD_DUBT_UNSORTED_MARK as u32
348        && nbCandidates > 1
349    {
350        *unsortedMark = previousCandidate;
351        previousCandidate = matchIndex;
352        matchIndex = *nextCandidate;
353        nextCandidate = bt.offset((2 * (matchIndex & btMask)) as isize);
354        unsortedMark = bt.offset((2 * (matchIndex & btMask)) as isize).add(1);
355        nbCandidates = nbCandidates.wrapping_sub(1);
356    }
357    if matchIndex > unsortLimit && *unsortedMark == ZSTD_DUBT_UNSORTED_MARK as u32 {
358        *unsortedMark = 0;
359        *nextCandidate = *unsortedMark;
360    }
361    matchIndex = previousCandidate;
362    while matchIndex != 0 {
363        let nextCandidateIdxPtr = bt.offset((2 * (matchIndex & btMask)) as isize).add(1);
364        let nextCandidateIdx = *nextCandidateIdxPtr;
365        ZSTD_insertDUBT1(ms, matchIndex, iend, nbCandidates, unsortLimit, dictMode);
366        matchIndex = nextCandidateIdx;
367        nbCandidates = nbCandidates.wrapping_add(1);
368    }
369    let mut commonLengthSmaller = 0;
370    let mut commonLengthLarger = 0;
371    let dictBase = ms.window.dictBase;
372    let dictLimit = ms.window.dictLimit;
373    let dictEnd = dictBase.offset(dictLimit as isize);
374    let prefixStart = base.offset(dictLimit as isize);
375    let mut smallerPtr = bt.offset((2 * (curr & btMask)) as isize);
376    let mut largerPtr = bt.offset((2 * (curr & btMask)) as isize).add(1);
377    let mut matchEndIdx = curr.wrapping_add(8).wrapping_add(1);
378    let mut dummy32: u32 = 0;
379    let mut bestLength = 0;
380    matchIndex = *hashTable.add(h);
381    *hashTable.add(h) = curr;
382    while nbCompares != 0 && matchIndex > windowLow {
383        let nextPtr = bt.offset((2 * (matchIndex & btMask)) as isize);
384        let mut matchLength = if commonLengthSmaller < commonLengthLarger {
385            commonLengthSmaller
386        } else {
387            commonLengthLarger
388        };
389        let mut match_0 = core::ptr::null::<u8>();
390        if dictMode as core::ffi::c_uint != ZSTD_extDict as core::ffi::c_int as core::ffi::c_uint
391            || (matchIndex as size_t).wrapping_add(matchLength) >= dictLimit as size_t
392        {
393            match_0 = base.offset(matchIndex as isize);
394            matchLength = matchLength.wrapping_add(ZSTD_count(
395                ip.add(matchLength),
396                match_0.add(matchLength),
397                iend,
398            ));
399        } else {
400            match_0 = dictBase.offset(matchIndex as isize);
401            matchLength = matchLength.wrapping_add(ZSTD_count_2segments(
402                ip.add(matchLength),
403                match_0.add(matchLength),
404                iend,
405                dictEnd,
406                prefixStart,
407            ));
408            if (matchIndex as size_t).wrapping_add(matchLength) >= dictLimit as size_t {
409                match_0 = base.offset(matchIndex as isize);
410            }
411        }
412        if matchLength > bestLength {
413            if matchLength > matchEndIdx.wrapping_sub(matchIndex) as size_t {
414                matchEndIdx = matchIndex.wrapping_add(matchLength as u32);
415            }
416            if 4 * matchLength.wrapping_sub(bestLength) as core::ffi::c_int
417                > (ZSTD_highbit32(curr.wrapping_sub(matchIndex).wrapping_add(1)))
418                    .wrapping_sub(ZSTD_highbit32(*offBasePtr as u32))
419                    as core::ffi::c_int
420            {
421                bestLength = matchLength;
422                *offBasePtr = curr
423                    .wrapping_sub(matchIndex)
424                    .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
425            }
426            if ip.add(matchLength) == iend {
427                if dictMode as core::ffi::c_uint
428                    == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
429                {
430                    nbCompares = 0;
431                }
432                break;
433            }
434        }
435        if (*match_0.add(matchLength) as core::ffi::c_int)
436            < *ip.add(matchLength) as core::ffi::c_int
437        {
438            *smallerPtr = matchIndex;
439            commonLengthSmaller = matchLength;
440            if matchIndex <= btLow {
441                smallerPtr = &mut dummy32;
442                break;
443            } else {
444                smallerPtr = nextPtr.add(1);
445                matchIndex = *nextPtr.add(1);
446            }
447        } else {
448            *largerPtr = matchIndex;
449            commonLengthLarger = matchLength;
450            if matchIndex <= btLow {
451                largerPtr = &mut dummy32;
452                break;
453            } else {
454                largerPtr = nextPtr;
455                matchIndex = *nextPtr;
456            }
457        }
458        nbCompares = nbCompares.wrapping_sub(1);
459    }
460    *largerPtr = 0;
461    *smallerPtr = *largerPtr;
462    if dictMode as core::ffi::c_uint == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
463        && nbCompares != 0
464    {
465        bestLength = ZSTD_DUBT_findBetterDictMatch(
466            ms, ip, iend, offBasePtr, bestLength, nbCompares, mls, dictMode,
467        );
468    }
469    ms.nextToUpdate = matchEndIdx.wrapping_sub(8);
470
471    bestLength
472}
473#[inline(always)]
474unsafe fn ZSTD_BtFindBestMatch(
475    ms: &mut ZSTD_MatchState_t,
476    ip: *const u8,
477    iLimit: *const u8,
478    offBasePtr: *mut size_t,
479    mls: u32,
480    dictMode: ZSTD_dictMode_e,
481) -> size_t {
482    if ip < (ms.window.base).offset(ms.nextToUpdate as isize) {
483        return 0;
484    }
485    ZSTD_updateDUBT(ms, ip, iLimit, mls);
486    ZSTD_DUBT_findBestMatch(ms, ip, iLimit, offBasePtr, mls, dictMode)
487}
488pub unsafe fn ZSTD_dedicatedDictSearch_lazy_loadDictionary(
489    ms: &mut ZSTD_MatchState_t,
490    ip: *const u8,
491) {
492    let base = ms.window.base;
493    let target = ip.offset_from(base) as core::ffi::c_long as u32;
494    let hashTable = ms.hashTable;
495    let chainTable = ms.chainTable;
496    let chainSize = ((1) << ms.cParams.chainLog) as u32;
497    let mut idx = ms.nextToUpdate;
498    let minChain = if chainSize < target.wrapping_sub(idx) {
499        target.wrapping_sub(chainSize)
500    } else {
501        idx
502    };
503    let bucketSize = ((1) << ZSTD_LAZY_DDSS_BUCKET_LOG) as u32;
504    let cacheSize = bucketSize.wrapping_sub(1);
505    let chainAttempts = (((1) << ms.cParams.searchLog) as u32).wrapping_sub(cacheSize);
506    let chainLimit = if chainAttempts > 255 {
507        255
508    } else {
509        chainAttempts
510    };
511    let hashLog = (ms.cParams.hashLog).wrapping_sub(ZSTD_LAZY_DDSS_BUCKET_LOG as core::ffi::c_uint);
512    let tmpHashTable = hashTable;
513    let tmpChainTable = hashTable.offset(((1) << hashLog) as isize);
514    let tmpChainSize = ((((1) << ZSTD_LAZY_DDSS_BUCKET_LOG) - 1) as u32) << hashLog;
515    let tmpMinChain = if tmpChainSize < target {
516        target.wrapping_sub(tmpChainSize)
517    } else {
518        idx
519    };
520    let mut hashIdx: u32 = 0;
521    while idx < target {
522        let h = ZSTD_hashPtr(
523            base.offset(idx as isize) as *const core::ffi::c_void,
524            hashLog,
525            ms.cParams.minMatch,
526        ) as u32;
527        if idx >= tmpMinChain {
528            *tmpChainTable.offset(idx.wrapping_sub(tmpMinChain) as isize) =
529                *hashTable.offset(h as isize);
530        }
531        *tmpHashTable.offset(h as isize) = idx;
532        idx = idx.wrapping_add(1);
533    }
534    let mut chainPos = 0u32;
535    hashIdx = 0;
536    while hashIdx < (1) << hashLog {
537        let mut count: u32 = 0;
538        let mut countBeyondMinChain = 0u32;
539        let mut i = *tmpHashTable.offset(hashIdx as isize);
540        count = 0;
541        while i >= tmpMinChain && count < cacheSize {
542            if i < minChain {
543                countBeyondMinChain = countBeyondMinChain.wrapping_add(1);
544            }
545            i = *tmpChainTable.offset(i.wrapping_sub(tmpMinChain) as isize);
546            count = count.wrapping_add(1);
547        }
548        if count == cacheSize {
549            count = 0;
550            while count < chainLimit {
551                if i < minChain
552                    && (i == 0 || {
553                        countBeyondMinChain = countBeyondMinChain.wrapping_add(1);
554                        countBeyondMinChain > cacheSize
555                    })
556                {
557                    break;
558                }
559                let fresh2 = chainPos;
560                chainPos = chainPos.wrapping_add(1);
561                *chainTable.offset(fresh2 as isize) = i;
562                count = count.wrapping_add(1);
563                if i < tmpMinChain {
564                    break;
565                }
566                i = *tmpChainTable.offset(i.wrapping_sub(tmpMinChain) as isize);
567            }
568        } else {
569            count = 0;
570        }
571        if count != 0 {
572            *tmpHashTable.offset(hashIdx as isize) =
573                (chainPos.wrapping_sub(count) << 8).wrapping_add(count);
574        } else {
575            *tmpHashTable.offset(hashIdx as isize) = 0;
576        }
577        hashIdx = hashIdx.wrapping_add(1);
578    }
579    hashIdx = ((1) << hashLog) as u32;
580    while hashIdx != 0 {
581        hashIdx = hashIdx.wrapping_sub(1);
582        let bucketIdx = hashIdx << ZSTD_LAZY_DDSS_BUCKET_LOG;
583        let chainPackedPointer = *tmpHashTable.offset(hashIdx as isize);
584        let mut i_0: u32 = 0;
585        i_0 = 0;
586        while i_0 < cacheSize {
587            *hashTable.offset(bucketIdx.wrapping_add(i_0) as isize) = 0;
588            i_0 = i_0.wrapping_add(1);
589        }
590        *hashTable.offset(bucketIdx.wrapping_add(bucketSize).wrapping_sub(1) as isize) =
591            chainPackedPointer;
592    }
593    idx = ms.nextToUpdate;
594    while idx < target {
595        let h_0 = (ZSTD_hashPtr(
596            base.offset(idx as isize) as *const core::ffi::c_void,
597            hashLog,
598            ms.cParams.minMatch,
599        ) as u32)
600            << ZSTD_LAZY_DDSS_BUCKET_LOG;
601        let mut i_1: u32 = 0;
602        i_1 = cacheSize.wrapping_sub(1);
603        while i_1 != 0 {
604            *hashTable.offset(h_0.wrapping_add(i_1) as isize) =
605                *hashTable.offset(h_0.wrapping_add(i_1).wrapping_sub(1) as isize);
606            i_1 = i_1.wrapping_sub(1);
607        }
608        *hashTable.offset(h_0 as isize) = idx;
609        idx = idx.wrapping_add(1);
610    }
611    ms.nextToUpdate = target;
612}
613#[inline(always)]
614unsafe fn ZSTD_dedicatedDictSearch_lazy_search(
615    offsetPtr: *mut size_t,
616    mut ml: size_t,
617    nbAttempts: u32,
618    dms: *const ZSTD_MatchState_t,
619    ip: *const u8,
620    iLimit: *const u8,
621    prefixStart: *const u8,
622    curr: u32,
623    dictLimit: u32,
624    ddsIdx: size_t,
625) -> size_t {
626    let ddsLowestIndex = (*dms).window.dictLimit;
627    let ddsBase = (*dms).window.base;
628    let ddsEnd = (*dms).window.nextSrc;
629    let ddsSize = ddsEnd.offset_from(ddsBase) as core::ffi::c_long as u32;
630    let ddsIndexDelta = dictLimit.wrapping_sub(ddsSize);
631    let bucketSize = ((1) << ZSTD_LAZY_DDSS_BUCKET_LOG) as u32;
632    let bucketLimit = if nbAttempts < bucketSize.wrapping_sub(1) {
633        nbAttempts
634    } else {
635        bucketSize.wrapping_sub(1)
636    };
637    let mut ddsAttempt: u32 = 0;
638    let mut matchIndex: u32 = 0;
639    ddsAttempt = 0;
640    while ddsAttempt < bucketSize.wrapping_sub(1) {
641        ddsAttempt = ddsAttempt.wrapping_add(1);
642
643        prefetch_read_data(
644            ddsBase.add(*((*dms).hashTable).add(ddsIdx + ddsAttempt as usize) as usize),
645            Locality::L1,
646        );
647    }
648
649    {
650        let chainPackedPointer =
651            *((*dms).hashTable).add(ddsIdx.wrapping_add(bucketSize as size_t).wrapping_sub(1));
652        let chainIndex = chainPackedPointer >> 8;
653
654        prefetch_read_data(
655            ((*dms).chainTable).offset(chainIndex as isize),
656            Locality::L1,
657        );
658    }
659
660    ddsAttempt = 0;
661    while ddsAttempt < bucketLimit {
662        let mut currentMl = 0;
663        let mut match_0 = core::ptr::null::<u8>();
664        matchIndex = *((*dms).hashTable).add(ddsIdx.wrapping_add(ddsAttempt as size_t));
665        match_0 = ddsBase.offset(matchIndex as isize);
666        if matchIndex == 0 {
667            return ml;
668        }
669
670        /* guaranteed by table construction */
671        assert!(matchIndex >= ddsLowestIndex);
672        assert!(match_0.wrapping_add(4) <= ddsEnd);
673        if MEM_read32(match_0 as *const core::ffi::c_void)
674            == MEM_read32(ip as *const core::ffi::c_void)
675        {
676            /* assumption : matchIndex <= dictLimit-4 (by table construction) */
677            currentMl =
678                (ZSTD_count_2segments(ip.add(4), match_0.add(4), iLimit, ddsEnd, prefixStart))
679                    .wrapping_add(4);
680        }
681        if currentMl > ml {
682            ml = currentMl;
683            *offsetPtr = curr
684                .wrapping_sub(matchIndex.wrapping_add(ddsIndexDelta))
685                .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
686            if ip.add(currentMl) == iLimit {
687                return ml;
688            }
689        }
690        ddsAttempt = ddsAttempt.wrapping_add(1);
691    }
692    let chainPackedPointer_0 =
693        *((*dms).hashTable).add(ddsIdx.wrapping_add(bucketSize as size_t).wrapping_sub(1));
694    let mut chainIndex_0 = chainPackedPointer_0 >> 8;
695    let chainLength = chainPackedPointer_0 & 0xff as core::ffi::c_int as u32;
696    let chainAttempts = nbAttempts.wrapping_sub(ddsAttempt);
697    let chainLimit = if chainAttempts > chainLength {
698        chainLength
699    } else {
700        chainAttempts
701    };
702    let mut chainAttempt: u32 = 0;
703    chainAttempt = 0;
704    while chainAttempt < chainLimit {
705        chainAttempt = chainAttempt.wrapping_add(1);
706    }
707    chainAttempt = 0;
708    while chainAttempt < chainLimit {
709        let mut currentMl_0 = 0;
710        let mut match_1 = core::ptr::null::<u8>();
711        matchIndex = *((*dms).chainTable).offset(chainIndex_0 as isize);
712        match_1 = ddsBase.offset(matchIndex as isize);
713        if MEM_read32(match_1 as *const core::ffi::c_void)
714            == MEM_read32(ip as *const core::ffi::c_void)
715        {
716            currentMl_0 =
717                (ZSTD_count_2segments(ip.add(4), match_1.add(4), iLimit, ddsEnd, prefixStart))
718                    .wrapping_add(4);
719        }
720        if currentMl_0 > ml {
721            ml = currentMl_0;
722            *offsetPtr = curr
723                .wrapping_sub(matchIndex.wrapping_add(ddsIndexDelta))
724                .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
725            if ip.add(currentMl_0) == iLimit {
726                break;
727            }
728        }
729        chainAttempt = chainAttempt.wrapping_add(1);
730        chainIndex_0 = chainIndex_0.wrapping_add(1);
731    }
732    ml
733}
734#[inline(always)]
735unsafe fn ZSTD_insertAndFindFirstIndex_internal(
736    ms: &mut ZSTD_MatchState_t,
737    cParams: *const ZSTD_compressionParameters,
738    ip: *const u8,
739    mls: u32,
740    lazySkipping: u32,
741) -> u32 {
742    let hashTable = ms.hashTable;
743    let hashLog = (*cParams).hashLog;
744    let chainTable = ms.chainTable;
745    let chainMask = (((1) << (*cParams).chainLog) - 1) as u32;
746    let base = ms.window.base;
747    let target = ip.offset_from(base) as core::ffi::c_long as u32;
748    let mut idx = ms.nextToUpdate;
749    while idx < target {
750        let h = ZSTD_hashPtr(
751            base.offset(idx as isize) as *const core::ffi::c_void,
752            hashLog,
753            mls,
754        );
755        *chainTable.offset((idx & chainMask) as isize) = *hashTable.add(h);
756        *hashTable.add(h) = idx;
757        idx = idx.wrapping_add(1);
758        if lazySkipping != 0 {
759            break;
760        }
761    }
762    ms.nextToUpdate = target;
763    *hashTable.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hashLog, mls))
764}
765pub unsafe fn ZSTD_insertAndFindFirstIndex(ms: &mut ZSTD_MatchState_t, ip: *const u8) -> u32 {
766    let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
767    ZSTD_insertAndFindFirstIndex_internal(ms, cParams, ip, ms.cParams.minMatch, 0)
768}
769#[inline(always)]
770unsafe fn ZSTD_HcFindBestMatch(
771    ms: &mut ZSTD_MatchState_t,
772    ip: *const u8,
773    iLimit: *const u8,
774    offsetPtr: *mut size_t,
775    mls: u32,
776    dictMode: ZSTD_dictMode_e,
777) -> size_t {
778    let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
779    let chainTable = ms.chainTable;
780    let chainSize = ((1) << (*cParams).chainLog) as u32;
781    let chainMask = chainSize.wrapping_sub(1);
782    let base = ms.window.base;
783    let dictBase = ms.window.dictBase;
784    let dictLimit = ms.window.dictLimit;
785    let prefixStart = base.offset(dictLimit as isize);
786    let dictEnd = dictBase.offset(dictLimit as isize);
787    let curr = ip.offset_from(base) as core::ffi::c_long as u32;
788    let maxDistance = (1) << (*cParams).windowLog;
789    let lowestValid = ms.window.lowLimit;
790    let withinMaxDistance = if curr.wrapping_sub(lowestValid) > maxDistance {
791        curr.wrapping_sub(maxDistance)
792    } else {
793        lowestValid
794    };
795    let isDictionary = (ms.loadedDictEnd != 0) as core::ffi::c_int as u32;
796    let lowLimit = if isDictionary != 0 {
797        lowestValid
798    } else {
799        withinMaxDistance
800    };
801    let minChain = if curr > chainSize {
802        curr.wrapping_sub(chainSize)
803    } else {
804        0
805    };
806    let mut nbAttempts = (1 as core::ffi::c_uint) << (*cParams).searchLog;
807    let mut ml = (4 - 1) as size_t;
808    let dms = ms.dictMatchState;
809    let ddsHashLog = if dictMode as core::ffi::c_uint
810        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
811    {
812        ((*dms).cParams.hashLog).wrapping_sub(ZSTD_LAZY_DDSS_BUCKET_LOG as core::ffi::c_uint)
813    } else {
814        0
815    };
816    let ddsIdx = if dictMode as core::ffi::c_uint
817        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
818    {
819        ZSTD_hashPtr(ip as *const core::ffi::c_void, ddsHashLog, mls) << ZSTD_LAZY_DDSS_BUCKET_LOG
820    } else {
821        0
822    };
823    let mut matchIndex: u32 = 0;
824    if dictMode as core::ffi::c_uint
825        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
826    {
827        let entry: *const u32 = &mut *((*dms).hashTable).add(ddsIdx) as *mut u32;
828        prefetch_read_data(entry, Locality::L1);
829    }
830    matchIndex =
831        ZSTD_insertAndFindFirstIndex_internal(ms, cParams, ip, mls, ms.lazySkipping as u32);
832    while (matchIndex >= lowLimit) as core::ffi::c_int & (nbAttempts > 0) as core::ffi::c_int != 0 {
833        let mut currentMl = 0;
834        if dictMode as core::ffi::c_uint != ZSTD_extDict as core::ffi::c_int as core::ffi::c_uint
835            || matchIndex >= dictLimit
836        {
837            let match_0 = base.offset(matchIndex as isize);
838            if MEM_read32(match_0.add(ml).sub(3) as *const core::ffi::c_void)
839                == MEM_read32(ip.add(ml).sub(3) as *const core::ffi::c_void)
840            {
841                currentMl = ZSTD_count(ip, match_0, iLimit);
842            }
843        } else {
844            let match_1 = dictBase.offset(matchIndex as isize);
845            if MEM_read32(match_1 as *const core::ffi::c_void)
846                == MEM_read32(ip as *const core::ffi::c_void)
847            {
848                currentMl =
849                    (ZSTD_count_2segments(ip.add(4), match_1.add(4), iLimit, dictEnd, prefixStart))
850                        .wrapping_add(4);
851            }
852        }
853        if currentMl > ml {
854            ml = currentMl;
855            *offsetPtr = curr
856                .wrapping_sub(matchIndex)
857                .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
858            if ip.add(currentMl) == iLimit {
859                break;
860            }
861        }
862        if matchIndex <= minChain {
863            break;
864        }
865        matchIndex = *chainTable.offset((matchIndex & chainMask) as isize);
866        nbAttempts = nbAttempts.wrapping_sub(1);
867    }
868    if dictMode as core::ffi::c_uint
869        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
870    {
871        ml = ZSTD_dedicatedDictSearch_lazy_search(
872            offsetPtr,
873            ml,
874            nbAttempts,
875            dms,
876            ip,
877            iLimit,
878            prefixStart,
879            curr,
880            dictLimit,
881            ddsIdx,
882        );
883    } else if dictMode as core::ffi::c_uint
884        == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
885    {
886        let dmsChainTable: *const u32 = (*dms).chainTable;
887        let dmsChainSize = ((1) << (*dms).cParams.chainLog) as u32;
888        let dmsChainMask = dmsChainSize.wrapping_sub(1);
889        let dmsLowestIndex = (*dms).window.dictLimit;
890        let dmsBase = (*dms).window.base;
891        let dmsEnd = (*dms).window.nextSrc;
892        let dmsSize = dmsEnd.offset_from(dmsBase) as core::ffi::c_long as u32;
893        let dmsIndexDelta = dictLimit.wrapping_sub(dmsSize);
894        let dmsMinChain = if dmsSize > dmsChainSize {
895            dmsSize.wrapping_sub(dmsChainSize)
896        } else {
897            0
898        };
899        matchIndex = *((*dms).hashTable).add(ZSTD_hashPtr(
900            ip as *const core::ffi::c_void,
901            (*dms).cParams.hashLog,
902            mls,
903        ));
904        while (matchIndex >= dmsLowestIndex) as core::ffi::c_int
905            & (nbAttempts > 0) as core::ffi::c_int
906            != 0
907        {
908            let mut currentMl_0 = 0;
909            let match_2 = dmsBase.offset(matchIndex as isize);
910            if MEM_read32(match_2 as *const core::ffi::c_void)
911                == MEM_read32(ip as *const core::ffi::c_void)
912            {
913                currentMl_0 =
914                    (ZSTD_count_2segments(ip.add(4), match_2.add(4), iLimit, dmsEnd, prefixStart))
915                        .wrapping_add(4);
916            }
917            if currentMl_0 > ml {
918                ml = currentMl_0;
919                *offsetPtr = curr
920                    .wrapping_sub(matchIndex.wrapping_add(dmsIndexDelta))
921                    .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
922                if ip.add(currentMl_0) == iLimit {
923                    break;
924                }
925            }
926            if matchIndex <= dmsMinChain {
927                break;
928            }
929            matchIndex = *dmsChainTable.offset((matchIndex & dmsChainMask) as isize);
930            nbAttempts = nbAttempts.wrapping_sub(1);
931        }
932    }
933    ml
934}
935pub const ZSTD_ROW_HASH_TAG_MASK: core::ffi::c_uint =
936    ((1 as core::ffi::c_uint) << ZSTD_ROW_HASH_TAG_BITS).wrapping_sub(1);
937pub const ZSTD_ROW_HASH_CACHE_MASK: core::ffi::c_int = ZSTD_ROW_HASH_CACHE_SIZE - 1;
938#[inline]
939unsafe fn ZSTD_VecMask_next(val: ZSTD_VecMask) -> u32 {
940    val.trailing_zeros()
941}
942#[inline(always)]
943unsafe fn ZSTD_row_nextIndex(tagRow: *mut u8, rowMask: u32) -> u32 {
944    let mut next = (*tagRow as core::ffi::c_int - 1) as u32 & rowMask;
945    next = next.wrapping_add(if next == 0 { rowMask } else { 0 });
946    *tagRow = next as u8;
947    next
948}
949
950/// Performs prefetching for the hashTable and tagTable at a given row.
951#[inline(always)]
952unsafe fn ZSTD_row_prefetch(hashTable: *const u32, tagTable: *const u8, relRow: u32, rowLog: u32) {
953    prefetch_read_data(hashTable.add(relRow as usize), Locality::L1);
954
955    if rowLog >= 5 {
956        // Note: prefetching more of the hash table does not appear to be beneficial for 128-entry rows.
957        prefetch_read_data(hashTable.add(relRow as usize + 16), Locality::L1);
958    }
959    prefetch_read_data(tagTable.add(relRow as usize), Locality::L1);
960    if rowLog == 6 {
961        prefetch_read_data(tagTable.add(relRow as usize + 32), Locality::L1);
962    }
963
964    assert!(rowLog == 4 || rowLog == 5 || rowLog == 6);
965    // Prefetched hash row always 64-byte aligned.
966    assert!((hashTable.wrapping_add(relRow as usize) as usize).is_multiple_of(64));
967    // Prefetched tagRow sits on correct multiple of bytes (32,64,128).
968    assert!((tagTable.wrapping_add(relRow as usize) as usize).is_multiple_of(1 << rowLog));
969}
970#[inline(always)]
971unsafe fn ZSTD_row_fillHashCache(
972    ms: &mut ZSTD_MatchState_t,
973    base: *const u8,
974    rowLog: u32,
975    mls: u32,
976    mut idx: u32,
977    iLimit: *const u8,
978) {
979    let hashTable: *const u32 = ms.hashTable;
980    let tagTable: *const u8 = ms.tagTable;
981    let hashLog = ms.rowHashLog;
982    let maxElemsToPrefetch = if base.offset(idx as isize) > iLimit {
983        0
984    } else {
985        (iLimit.offset_from(base.offset(idx as isize)) as core::ffi::c_long + 1) as u32
986    };
987    let lim = idx.wrapping_add(if (8) < maxElemsToPrefetch {
988        8
989    } else {
990        maxElemsToPrefetch
991    });
992    while idx < lim {
993        let hash = ZSTD_hashPtrSalted(
994            base.offset(idx as isize) as *const core::ffi::c_void,
995            hashLog.wrapping_add(ZSTD_ROW_HASH_TAG_BITS as u32),
996            mls,
997            ms.hashSalt,
998        ) as u32;
999        let row = hash >> ZSTD_ROW_HASH_TAG_BITS << rowLog;
1000        ZSTD_row_prefetch(hashTable, tagTable, row, rowLog);
1001        *(ms.hashCache)
1002            .as_mut_ptr()
1003            .offset((idx & ZSTD_ROW_HASH_CACHE_MASK as u32) as isize) = hash;
1004        idx = idx.wrapping_add(1);
1005    }
1006}
1007#[inline(always)]
1008unsafe fn ZSTD_row_nextCachedHash(
1009    cache: *mut u32,
1010    hashTable: *const u32,
1011    tagTable: *const u8,
1012    base: *const u8,
1013    idx: u32,
1014    hashLog: u32,
1015    rowLog: u32,
1016    mls: u32,
1017    hashSalt: u64,
1018) -> u32 {
1019    let newHash = ZSTD_hashPtrSalted(
1020        base.offset(idx as isize)
1021            .offset(ZSTD_ROW_HASH_CACHE_SIZE as isize) as *const core::ffi::c_void,
1022        hashLog.wrapping_add(ZSTD_ROW_HASH_TAG_BITS as u32),
1023        mls,
1024        hashSalt,
1025    ) as u32;
1026    let row = newHash >> ZSTD_ROW_HASH_TAG_BITS << rowLog;
1027    ZSTD_row_prefetch(hashTable, tagTable, row, rowLog);
1028    let hash = *cache.offset((idx & ZSTD_ROW_HASH_CACHE_MASK as u32) as isize);
1029    *cache.offset((idx & ZSTD_ROW_HASH_CACHE_MASK as u32) as isize) = newHash;
1030    hash
1031}
1032#[inline(always)]
1033unsafe fn ZSTD_row_update_internalImpl(
1034    ms: &mut ZSTD_MatchState_t,
1035    mut updateStartIdx: u32,
1036    updateEndIdx: u32,
1037    mls: u32,
1038    rowLog: u32,
1039    rowMask: u32,
1040    useCache: u32,
1041) {
1042    let hashTable = ms.hashTable;
1043    let tagTable = ms.tagTable;
1044    let hashLog = ms.rowHashLog;
1045    let base = ms.window.base;
1046    while updateStartIdx < updateEndIdx {
1047        let hash = if useCache != 0 {
1048            ZSTD_row_nextCachedHash(
1049                (ms.hashCache).as_mut_ptr(),
1050                hashTable,
1051                tagTable,
1052                base,
1053                updateStartIdx,
1054                hashLog,
1055                rowLog,
1056                mls,
1057                ms.hashSalt,
1058            )
1059        } else {
1060            ZSTD_hashPtrSalted(
1061                base.offset(updateStartIdx as isize) as *const core::ffi::c_void,
1062                hashLog.wrapping_add(ZSTD_ROW_HASH_TAG_BITS as u32),
1063                mls,
1064                ms.hashSalt,
1065            ) as u32
1066        };
1067        let relRow = hash >> ZSTD_ROW_HASH_TAG_BITS << rowLog;
1068        let row = hashTable.offset(relRow as isize);
1069        let tagRow = tagTable.offset(relRow as isize);
1070        let pos = ZSTD_row_nextIndex(tagRow, rowMask);
1071        *tagRow.offset(pos as isize) = (hash & ZSTD_ROW_HASH_TAG_MASK) as u8;
1072        *row.offset(pos as isize) = updateStartIdx;
1073        updateStartIdx = updateStartIdx.wrapping_add(1);
1074    }
1075}
1076#[inline(always)]
1077unsafe fn ZSTD_row_update_internal(
1078    ms: &mut ZSTD_MatchState_t,
1079    ip: *const u8,
1080    mls: u32,
1081    rowLog: u32,
1082    rowMask: u32,
1083    useCache: u32,
1084) {
1085    let mut idx = ms.nextToUpdate;
1086    let base = ms.window.base;
1087    let target = ip.offset_from(base) as core::ffi::c_long as u32;
1088    let kSkipThreshold = 384;
1089    let kMaxMatchStartPositionsToUpdate = 96;
1090    let kMaxMatchEndPositionsToUpdate = 32;
1091    if useCache != 0 && target.wrapping_sub(idx) > kSkipThreshold {
1092        let bound = idx.wrapping_add(kMaxMatchStartPositionsToUpdate);
1093        ZSTD_row_update_internalImpl(ms, idx, bound, mls, rowLog, rowMask, useCache);
1094        idx = target.wrapping_sub(kMaxMatchEndPositionsToUpdate);
1095        ZSTD_row_fillHashCache(ms, base, rowLog, mls, idx, ip.add(1));
1096    }
1097    ZSTD_row_update_internalImpl(ms, idx, target, mls, rowLog, rowMask, useCache);
1098    ms.nextToUpdate = target;
1099}
1100pub unsafe fn ZSTD_row_update(ms: &mut ZSTD_MatchState_t, ip: *const u8) {
1101    let rowLog = if 4
1102        > (if ms.cParams.searchLog < 6 {
1103            ms.cParams.searchLog
1104        } else {
1105            6
1106        }) {
1107        4
1108    } else if ms.cParams.searchLog < 6 {
1109        ms.cParams.searchLog
1110    } else {
1111        6
1112    };
1113    let rowMask = ((1 as core::ffi::c_uint) << rowLog).wrapping_sub(1);
1114    let mls = if ms.cParams.minMatch < 6 as core::ffi::c_uint {
1115        ms.cParams.minMatch
1116    } else {
1117        6
1118    };
1119    ZSTD_row_update_internal(ms, ip, mls, rowLog, rowMask, 0);
1120}
1121#[inline(always)]
1122unsafe fn ZSTD_row_matchMaskGroupWidth(_rowEntries: u32) -> u32 {
1123    // FIXME: add a more optimal implementation for aarch64.
1124    1
1125}
1126#[inline(always)]
1127#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1128unsafe fn ZSTD_row_getSSEMask(
1129    nbChunks: core::ffi::c_int,
1130    src: *const u8,
1131    tag: u8,
1132    head: u32,
1133) -> ZSTD_VecMask {
1134    #[cfg(target_arch = "x86")]
1135    use core::arch::x86::{
1136        __m128i, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_movemask_epi8, _mm_set1_epi8,
1137    };
1138    #[cfg(target_arch = "x86_64")]
1139    use core::arch::x86_64::{
1140        __m128i, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_movemask_epi8, _mm_set1_epi8,
1141    };
1142
1143    let comparisonMask = _mm_set1_epi8(tag as core::ffi::c_char);
1144    let mut matches: [core::ffi::c_int; 4] = [0; 4];
1145    let mut i: core::ffi::c_int = 0;
1146    while i < nbChunks {
1147        let chunk = _mm_loadu_si128(
1148            src.offset((16 * i) as isize) as *const core::ffi::c_void as *const __m128i
1149        );
1150        let equalMask = _mm_cmpeq_epi8(chunk, comparisonMask);
1151        *matches.as_mut_ptr().offset(i as isize) = _mm_movemask_epi8(equalMask);
1152        i += 1;
1153    }
1154    if nbChunks == 1 {
1155        return (matches[0] as u16).rotate_right(head) as ZSTD_VecMask;
1156    }
1157    if nbChunks == 2 {
1158        return ((matches[1] as u32) << 16 | matches[0] as u32).rotate_right(head) as ZSTD_VecMask;
1159    }
1160    ((matches[3] as u64) << 48
1161        | (matches[2] as u64) << 32
1162        | (matches[1] as u64) << 16
1163        | matches[0] as u64)
1164        .rotate_right(head)
1165}
1166#[inline(always)]
1167unsafe fn ZSTD_row_getMatchMask(
1168    tagRow: *const u8,
1169    tag: u8,
1170    headGrouped: u32,
1171    rowEntries: u32,
1172) -> ZSTD_VecMask {
1173    let src = tagRow;
1174
1175    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1176    if true {
1177        return ZSTD_row_getSSEMask((rowEntries / 16) as core::ffi::c_int, src, tag, headGrouped);
1178    }
1179
1180    // FIXME: Evaluate if the custom SIMD implementation is worth it on x86, and if so also add an
1181    // aarch64 implementation.
1182
1183    // Fallback using Simd Within A Register (SWAR).
1184
1185    let chunkSize = size_of::<usize>();
1186    let shiftAmount = (chunkSize * 8) - chunkSize;
1187    let xFF = usize::MAX;
1188    let x01 = xFF / 0xFF;
1189    let x80 = x01 << 7;
1190    let splatChar = usize::from(tag) * x01;
1191
1192    let mut matches: ZSTD_VecMask = 0;
1193    let mut i = rowEntries as isize - chunkSize as isize;
1194    assert!((size_of::<usize>() == 4) || (size_of::<usize>() == 8));
1195
1196    if cfg!(target_endian = "little") {
1197        let extractMagic = (xFF / 0x7F) >> chunkSize;
1198
1199        loop {
1200            let mut chunk = src.offset(i).cast::<usize>().read_unaligned();
1201            chunk ^= splatChar;
1202            chunk = (((chunk | x80) - x01) | chunk) & x80;
1203            matches <<= chunkSize;
1204            matches |= ((chunk.wrapping_mul(extractMagic)) >> shiftAmount) as ZSTD_VecMask;
1205            i -= chunkSize as isize;
1206
1207            if i < 0 {
1208                break;
1209            }
1210        }
1211    } else {
1212        // big endian: reverse bits during extraction.
1213        let msb = xFF ^ (xFF >> 1);
1214        let extractMagic = (msb / 0x1FF) | msb;
1215
1216        loop {
1217            let mut chunk = src.offset(i).cast::<usize>().read_unaligned();
1218            chunk ^= splatChar;
1219            chunk = (((chunk | x80) - x01) | chunk) & x80;
1220            matches <<= chunkSize;
1221            matches |= (((chunk >> 7) * extractMagic) >> shiftAmount) as ZSTD_VecMask;
1222            i -= chunkSize as isize;
1223
1224            if i < 0 {
1225                break;
1226            }
1227        }
1228    }
1229
1230    matches = !matches;
1231    match rowEntries {
1232        16 => (matches as u16).rotate_right(headGrouped) as ZSTD_VecMask,
1233        32 => (matches as u32).rotate_right(headGrouped) as ZSTD_VecMask,
1234        64 => (matches as u64).rotate_right(headGrouped) as ZSTD_VecMask,
1235        _ => unreachable!(),
1236    }
1237}
1238
1239#[inline(always)]
1240unsafe fn ZSTD_RowFindBestMatch(
1241    ms: &mut ZSTD_MatchState_t,
1242    ip: *const u8,
1243    iLimit: *const u8,
1244    offsetPtr: *mut size_t,
1245    mls: u32,
1246    dictMode: ZSTD_dictMode_e,
1247    rowLog: u32,
1248) -> size_t {
1249    let hashTable = ms.hashTable;
1250    let tagTable = ms.tagTable;
1251    let hashCache = (ms.hashCache).as_mut_ptr();
1252    let hashLog = ms.rowHashLog;
1253    let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
1254    let base = ms.window.base;
1255    let dictBase = ms.window.dictBase;
1256    let dictLimit = ms.window.dictLimit;
1257    let prefixStart = base.offset(dictLimit as isize);
1258    let dictEnd = dictBase.offset(dictLimit as isize);
1259    let curr = ip.offset_from(base) as core::ffi::c_long as u32;
1260    let maxDistance = (1) << (*cParams).windowLog;
1261    let lowestValid = ms.window.lowLimit;
1262    let withinMaxDistance = if curr.wrapping_sub(lowestValid) > maxDistance {
1263        curr.wrapping_sub(maxDistance)
1264    } else {
1265        lowestValid
1266    };
1267    let isDictionary = (ms.loadedDictEnd != 0) as core::ffi::c_int as u32;
1268    let lowLimit = if isDictionary != 0 {
1269        lowestValid
1270    } else {
1271        withinMaxDistance
1272    };
1273    let rowEntries = (1 as core::ffi::c_uint) << rowLog;
1274    let rowMask = rowEntries.wrapping_sub(1);
1275    let cappedSearchLog = if (*cParams).searchLog < rowLog {
1276        (*cParams).searchLog
1277    } else {
1278        rowLog
1279    };
1280    let groupWidth = ZSTD_row_matchMaskGroupWidth(rowEntries);
1281    let hashSalt = ms.hashSalt;
1282    let mut nbAttempts = (1 as core::ffi::c_uint) << cappedSearchLog;
1283    let mut ml = (4 - 1) as size_t;
1284    let mut hash: u32 = 0;
1285    let dms = ms.dictMatchState;
1286    let mut ddsIdx = 0;
1287    let mut ddsExtraAttempts = 0;
1288    let mut dmsTag = 0;
1289    let mut dmsRow = core::ptr::null_mut();
1290    let mut dmsTagRow = core::ptr::null_mut();
1291    if dictMode as core::ffi::c_uint
1292        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
1293    {
1294        let ddsHashLog =
1295            ((*dms).cParams.hashLog).wrapping_sub(ZSTD_LAZY_DDSS_BUCKET_LOG as core::ffi::c_uint);
1296        {
1297            /* Prefetch DDS hashtable entry */
1298            ddsIdx = ZSTD_hashPtr(ip as *const core::ffi::c_void, ddsHashLog, mls)
1299                << ZSTD_LAZY_DDSS_BUCKET_LOG;
1300            prefetch_read_data(((*dms).hashTable).add(ddsIdx), Locality::L1);
1301        }
1302        ddsExtraAttempts = if (*cParams).searchLog > rowLog {
1303            (1) << ((*cParams).searchLog).wrapping_sub(rowLog)
1304        } else {
1305            0
1306        };
1307    }
1308    if dictMode as core::ffi::c_uint == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
1309    {
1310        let dmsHashTable = (*dms).hashTable;
1311        let dmsTagTable = (*dms).tagTable;
1312        let dmsHash = ZSTD_hashPtr(
1313            ip as *const core::ffi::c_void,
1314            ((*dms).rowHashLog).wrapping_add(ZSTD_ROW_HASH_TAG_BITS as u32),
1315            mls,
1316        ) as u32;
1317        let dmsRelRow = dmsHash >> ZSTD_ROW_HASH_TAG_BITS << rowLog;
1318        dmsTag = dmsHash & ZSTD_ROW_HASH_TAG_MASK;
1319        dmsTagRow = dmsTagTable.offset(dmsRelRow as isize);
1320        dmsRow = dmsHashTable.offset(dmsRelRow as isize);
1321        ZSTD_row_prefetch(dmsHashTable, dmsTagTable, dmsRelRow, rowLog);
1322    }
1323    if ms.lazySkipping == 0 {
1324        ZSTD_row_update_internal(ms, ip, mls, rowLog, rowMask, 1);
1325        hash = ZSTD_row_nextCachedHash(
1326            hashCache, hashTable, tagTable, base, curr, hashLog, rowLog, mls, hashSalt,
1327        );
1328    } else {
1329        hash = ZSTD_hashPtrSalted(
1330            ip as *const core::ffi::c_void,
1331            hashLog.wrapping_add(ZSTD_ROW_HASH_TAG_BITS as u32),
1332            mls,
1333            hashSalt,
1334        ) as u32;
1335        ms.nextToUpdate = curr;
1336    }
1337    ms.hashSaltEntropy = (ms.hashSaltEntropy).wrapping_add(hash);
1338    let relRow = hash >> ZSTD_ROW_HASH_TAG_BITS << rowLog;
1339    let tag = hash & ZSTD_ROW_HASH_TAG_MASK;
1340    let row = hashTable.offset(relRow as isize);
1341    let tagRow = tagTable.offset(relRow as isize);
1342    let headGrouped = (*tagRow as u32 & rowMask) * groupWidth;
1343    let mut matchBuffer: [u32; 64] = [0; 64];
1344    let mut numMatches = 0 as size_t;
1345    let mut currMatch = 0;
1346    let mut matches = ZSTD_row_getMatchMask(tagRow, tag as u8, headGrouped, rowEntries);
1347    while matches > 0 && nbAttempts > 0 {
1348        let matchPos =
1349            (headGrouped.wrapping_add(ZSTD_VecMask_next(matches)) / groupWidth) & rowMask;
1350        let matchIndex = *row.offset(matchPos as isize);
1351        if matchPos != 0 {
1352            if matchIndex < lowLimit {
1353                break;
1354            }
1355
1356            if dictMode != ZSTD_extDict || matchIndex >= dictLimit {
1357                prefetch_read_data(base.add(matchIndex as usize), Locality::L1);
1358            } else {
1359                prefetch_read_data(dictBase.add(matchIndex as usize), Locality::L1);
1360            }
1361
1362            let fresh3 = numMatches;
1363            numMatches = numMatches.wrapping_add(1);
1364            *matchBuffer.as_mut_ptr().add(fresh3) = matchIndex;
1365            nbAttempts = nbAttempts.wrapping_sub(1);
1366        }
1367        matches &= matches.wrapping_sub(1);
1368    }
1369    let pos = ZSTD_row_nextIndex(tagRow, rowMask);
1370    *tagRow.offset(pos as isize) = tag as u8;
1371    let fresh4 = ms.nextToUpdate;
1372    ms.nextToUpdate = (ms.nextToUpdate).wrapping_add(1);
1373    *row.offset(pos as isize) = fresh4;
1374    while currMatch < numMatches {
1375        let matchIndex_0 = *matchBuffer.as_mut_ptr().add(currMatch);
1376        let mut currentMl = 0;
1377        if dictMode as core::ffi::c_uint != ZSTD_extDict as core::ffi::c_int as core::ffi::c_uint
1378            || matchIndex_0 >= dictLimit
1379        {
1380            let match_0 = base.offset(matchIndex_0 as isize);
1381            if MEM_read32(match_0.add(ml).sub(3) as *const core::ffi::c_void)
1382                == MEM_read32(ip.add(ml).sub(3) as *const core::ffi::c_void)
1383            {
1384                currentMl = ZSTD_count(ip, match_0, iLimit);
1385            }
1386        } else {
1387            let match_1 = dictBase.offset(matchIndex_0 as isize);
1388            if MEM_read32(match_1 as *const core::ffi::c_void)
1389                == MEM_read32(ip as *const core::ffi::c_void)
1390            {
1391                currentMl =
1392                    (ZSTD_count_2segments(ip.add(4), match_1.add(4), iLimit, dictEnd, prefixStart))
1393                        .wrapping_add(4);
1394            }
1395        }
1396        if currentMl > ml {
1397            ml = currentMl;
1398            *offsetPtr = curr
1399                .wrapping_sub(matchIndex_0)
1400                .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
1401            if ip.add(currentMl) == iLimit {
1402                break;
1403            }
1404        }
1405        currMatch = currMatch.wrapping_add(1);
1406    }
1407    if dictMode as core::ffi::c_uint
1408        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
1409    {
1410        ml = ZSTD_dedicatedDictSearch_lazy_search(
1411            offsetPtr,
1412            ml,
1413            nbAttempts.wrapping_add(ddsExtraAttempts),
1414            dms,
1415            ip,
1416            iLimit,
1417            prefixStart,
1418            curr,
1419            dictLimit,
1420            ddsIdx,
1421        );
1422    } else if dictMode as core::ffi::c_uint
1423        == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
1424    {
1425        let dmsLowestIndex = (*dms).window.dictLimit;
1426        let dmsBase = (*dms).window.base;
1427        let dmsEnd = (*dms).window.nextSrc;
1428        let dmsSize = dmsEnd.offset_from(dmsBase) as core::ffi::c_long as u32;
1429        let dmsIndexDelta = dictLimit.wrapping_sub(dmsSize);
1430        let headGrouped_0 = (*dmsTagRow as u32 & rowMask) * groupWidth;
1431        let mut matchBuffer_0: [u32; 64] = [0; 64];
1432        let mut numMatches_0 = 0 as size_t;
1433        let mut currMatch_0 = 0;
1434        let mut matches_0 =
1435            ZSTD_row_getMatchMask(dmsTagRow, dmsTag as u8, headGrouped_0, rowEntries);
1436        while matches_0 > 0 && nbAttempts > 0 {
1437            let matchPos_0 =
1438                (headGrouped_0.wrapping_add(ZSTD_VecMask_next(matches_0)) / groupWidth) & rowMask;
1439            let matchIndex_1 = *dmsRow.offset(matchPos_0 as isize);
1440            if matchPos_0 != 0 {
1441                if matchIndex_1 < dmsLowestIndex {
1442                    break;
1443                }
1444                let fresh5 = numMatches_0;
1445                numMatches_0 = numMatches_0.wrapping_add(1);
1446                *matchBuffer_0.as_mut_ptr().add(fresh5) = matchIndex_1;
1447                nbAttempts = nbAttempts.wrapping_sub(1);
1448            }
1449            matches_0 &= matches_0.wrapping_sub(1);
1450        }
1451        while currMatch_0 < numMatches_0 {
1452            let matchIndex_2 = *matchBuffer_0.as_mut_ptr().add(currMatch_0);
1453            let mut currentMl_0 = 0;
1454            let match_2 = dmsBase.offset(matchIndex_2 as isize);
1455            if MEM_read32(match_2 as *const core::ffi::c_void)
1456                == MEM_read32(ip as *const core::ffi::c_void)
1457            {
1458                currentMl_0 =
1459                    (ZSTD_count_2segments(ip.add(4), match_2.add(4), iLimit, dmsEnd, prefixStart))
1460                        .wrapping_add(4);
1461            }
1462            if currentMl_0 > ml {
1463                ml = currentMl_0;
1464                *offsetPtr = curr
1465                    .wrapping_sub(matchIndex_2.wrapping_add(dmsIndexDelta))
1466                    .wrapping_add(ZSTD_REP_NUM as u32) as size_t;
1467                if ip.add(currentMl_0) == iLimit {
1468                    break;
1469                }
1470            }
1471            currMatch_0 = currMatch_0.wrapping_add(1);
1472        }
1473    }
1474    ml
1475}
1476#[inline(never)]
1477unsafe fn ZSTD_RowFindBestMatch_dictMatchState_6_6(
1478    ms: &mut ZSTD_MatchState_t,
1479    ip: *const u8,
1480    iLimit: *const u8,
1481    offsetPtr: *mut size_t,
1482) -> size_t {
1483    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMatchState, 6)
1484}
1485#[inline(never)]
1486unsafe fn ZSTD_RowFindBestMatch_extDict_4_6(
1487    ms: &mut ZSTD_MatchState_t,
1488    ip: *const u8,
1489    iLimit: *const u8,
1490    offsetPtr: *mut size_t,
1491) -> size_t {
1492    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_extDict, 6)
1493}
1494#[inline(never)]
1495unsafe fn ZSTD_RowFindBestMatch_dictMatchState_4_4(
1496    ms: &mut ZSTD_MatchState_t,
1497    ip: *const u8,
1498    iLimit: *const u8,
1499    offsetPtr: *mut size_t,
1500) -> size_t {
1501    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMatchState, 4)
1502}
1503#[inline(never)]
1504unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_6_6(
1505    ms: &mut ZSTD_MatchState_t,
1506    ip: *const u8,
1507    iLimit: *const u8,
1508    offsetPtr: *mut size_t,
1509) -> size_t {
1510    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dedicatedDictSearch, 6)
1511}
1512#[inline(never)]
1513unsafe fn ZSTD_RowFindBestMatch_extDict_6_6(
1514    ms: &mut ZSTD_MatchState_t,
1515    ip: *const u8,
1516    iLimit: *const u8,
1517    offsetPtr: *mut size_t,
1518) -> size_t {
1519    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_extDict, 6)
1520}
1521#[inline(never)]
1522unsafe fn ZSTD_RowFindBestMatch_extDict_6_5(
1523    ms: &mut ZSTD_MatchState_t,
1524    ip: *const u8,
1525    iLimit: *const u8,
1526    offsetPtr: *mut size_t,
1527) -> size_t {
1528    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_extDict, 5)
1529}
1530#[inline(never)]
1531unsafe fn ZSTD_RowFindBestMatch_extDict_6_4(
1532    ms: &mut ZSTD_MatchState_t,
1533    ip: *const u8,
1534    iLimit: *const u8,
1535    offsetPtr: *mut size_t,
1536) -> size_t {
1537    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_extDict, 4)
1538}
1539#[inline(never)]
1540unsafe fn ZSTD_RowFindBestMatch_extDict_5_6(
1541    ms: &mut ZSTD_MatchState_t,
1542    ip: *const u8,
1543    iLimit: *const u8,
1544    offsetPtr: *mut size_t,
1545) -> size_t {
1546    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_extDict, 6)
1547}
1548#[inline(never)]
1549unsafe fn ZSTD_RowFindBestMatch_extDict_5_5(
1550    ms: &mut ZSTD_MatchState_t,
1551    ip: *const u8,
1552    iLimit: *const u8,
1553    offsetPtr: *mut size_t,
1554) -> size_t {
1555    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_extDict, 5)
1556}
1557#[inline(never)]
1558unsafe fn ZSTD_RowFindBestMatch_extDict_5_4(
1559    ms: &mut ZSTD_MatchState_t,
1560    ip: *const u8,
1561    iLimit: *const u8,
1562    offsetPtr: *mut size_t,
1563) -> size_t {
1564    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_extDict, 4)
1565}
1566#[inline(never)]
1567unsafe fn ZSTD_RowFindBestMatch_dictMatchState_4_5(
1568    ms: &mut ZSTD_MatchState_t,
1569    ip: *const u8,
1570    iLimit: *const u8,
1571    offsetPtr: *mut size_t,
1572) -> size_t {
1573    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMatchState, 5)
1574}
1575#[inline(never)]
1576unsafe fn ZSTD_RowFindBestMatch_extDict_4_5(
1577    ms: &mut ZSTD_MatchState_t,
1578    ip: *const u8,
1579    iLimit: *const u8,
1580    offsetPtr: *mut size_t,
1581) -> size_t {
1582    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_extDict, 5)
1583}
1584#[inline(never)]
1585unsafe fn ZSTD_RowFindBestMatch_extDict_4_4(
1586    ms: &mut ZSTD_MatchState_t,
1587    ip: *const u8,
1588    iLimit: *const u8,
1589    offsetPtr: *mut size_t,
1590) -> size_t {
1591    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_extDict, 4)
1592}
1593#[inline(never)]
1594unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_6_5(
1595    ms: &mut ZSTD_MatchState_t,
1596    ip: *const u8,
1597    iLimit: *const u8,
1598    offsetPtr: *mut size_t,
1599) -> size_t {
1600    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dedicatedDictSearch, 5)
1601}
1602#[inline(never)]
1603unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_6_4(
1604    ms: &mut ZSTD_MatchState_t,
1605    ip: *const u8,
1606    iLimit: *const u8,
1607    offsetPtr: *mut size_t,
1608) -> size_t {
1609    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dedicatedDictSearch, 4)
1610}
1611#[inline(never)]
1612unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_5_6(
1613    ms: &mut ZSTD_MatchState_t,
1614    ip: *const u8,
1615    iLimit: *const u8,
1616    offsetPtr: *mut size_t,
1617) -> size_t {
1618    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dedicatedDictSearch, 6)
1619}
1620#[inline(never)]
1621unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_5_5(
1622    ms: &mut ZSTD_MatchState_t,
1623    ip: *const u8,
1624    iLimit: *const u8,
1625    offsetPtr: *mut size_t,
1626) -> size_t {
1627    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dedicatedDictSearch, 5)
1628}
1629#[inline(never)]
1630unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_5_4(
1631    ms: &mut ZSTD_MatchState_t,
1632    ip: *const u8,
1633    iLimit: *const u8,
1634    offsetPtr: *mut size_t,
1635) -> size_t {
1636    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dedicatedDictSearch, 4)
1637}
1638#[inline(never)]
1639unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_4_6(
1640    ms: &mut ZSTD_MatchState_t,
1641    ip: *const u8,
1642    iLimit: *const u8,
1643    offsetPtr: *mut size_t,
1644) -> size_t {
1645    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dedicatedDictSearch, 6)
1646}
1647#[inline(never)]
1648unsafe fn ZSTD_RowFindBestMatch_noDict_6_6(
1649    ms: &mut ZSTD_MatchState_t,
1650    ip: *const u8,
1651    iLimit: *const u8,
1652    offsetPtr: *mut size_t,
1653) -> size_t {
1654    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_noDict, 6)
1655}
1656#[inline(never)]
1657unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_4_5(
1658    ms: &mut ZSTD_MatchState_t,
1659    ip: *const u8,
1660    iLimit: *const u8,
1661    offsetPtr: *mut size_t,
1662) -> size_t {
1663    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dedicatedDictSearch, 5)
1664}
1665#[inline(never)]
1666unsafe fn ZSTD_RowFindBestMatch_noDict_6_4(
1667    ms: &mut ZSTD_MatchState_t,
1668    ip: *const u8,
1669    iLimit: *const u8,
1670    offsetPtr: *mut size_t,
1671) -> size_t {
1672    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_noDict, 4)
1673}
1674#[inline(never)]
1675unsafe fn ZSTD_RowFindBestMatch_noDict_5_6(
1676    ms: &mut ZSTD_MatchState_t,
1677    ip: *const u8,
1678    iLimit: *const u8,
1679    offsetPtr: *mut size_t,
1680) -> size_t {
1681    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_noDict, 6)
1682}
1683#[inline(never)]
1684unsafe fn ZSTD_RowFindBestMatch_noDict_5_5(
1685    ms: &mut ZSTD_MatchState_t,
1686    ip: *const u8,
1687    iLimit: *const u8,
1688    offsetPtr: *mut size_t,
1689) -> size_t {
1690    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_noDict, 5)
1691}
1692#[inline(never)]
1693unsafe fn ZSTD_RowFindBestMatch_noDict_5_4(
1694    ms: &mut ZSTD_MatchState_t,
1695    ip: *const u8,
1696    iLimit: *const u8,
1697    offsetPtr: *mut size_t,
1698) -> size_t {
1699    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_noDict, 4)
1700}
1701#[inline(never)]
1702unsafe fn ZSTD_RowFindBestMatch_noDict_4_6(
1703    ms: &mut ZSTD_MatchState_t,
1704    ip: *const u8,
1705    iLimit: *const u8,
1706    offsetPtr: *mut size_t,
1707) -> size_t {
1708    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_noDict, 6)
1709}
1710#[inline(never)]
1711unsafe fn ZSTD_RowFindBestMatch_noDict_4_5(
1712    ms: &mut ZSTD_MatchState_t,
1713    ip: *const u8,
1714    iLimit: *const u8,
1715    offsetPtr: *mut size_t,
1716) -> size_t {
1717    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_noDict, 5)
1718}
1719#[inline(never)]
1720unsafe fn ZSTD_RowFindBestMatch_noDict_4_4(
1721    ms: &mut ZSTD_MatchState_t,
1722    ip: *const u8,
1723    iLimit: *const u8,
1724    offsetPtr: *mut size_t,
1725) -> size_t {
1726    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_noDict, 4)
1727}
1728#[inline(never)]
1729unsafe fn ZSTD_RowFindBestMatch_dedicatedDictSearch_4_4(
1730    ms: &mut ZSTD_MatchState_t,
1731    ip: *const u8,
1732    iLimit: *const u8,
1733    offsetPtr: *mut size_t,
1734) -> size_t {
1735    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dedicatedDictSearch, 4)
1736}
1737#[inline(never)]
1738unsafe fn ZSTD_RowFindBestMatch_dictMatchState_4_6(
1739    ms: &mut ZSTD_MatchState_t,
1740    ip: *const u8,
1741    iLimit: *const u8,
1742    offsetPtr: *mut size_t,
1743) -> size_t {
1744    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMatchState, 6)
1745}
1746#[inline(never)]
1747unsafe fn ZSTD_RowFindBestMatch_dictMatchState_6_5(
1748    ms: &mut ZSTD_MatchState_t,
1749    ip: *const u8,
1750    iLimit: *const u8,
1751    offsetPtr: *mut size_t,
1752) -> size_t {
1753    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMatchState, 5)
1754}
1755#[inline(never)]
1756unsafe fn ZSTD_RowFindBestMatch_dictMatchState_6_4(
1757    ms: &mut ZSTD_MatchState_t,
1758    ip: *const u8,
1759    iLimit: *const u8,
1760    offsetPtr: *mut size_t,
1761) -> size_t {
1762    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMatchState, 4)
1763}
1764#[inline(never)]
1765unsafe fn ZSTD_RowFindBestMatch_dictMatchState_5_6(
1766    ms: &mut ZSTD_MatchState_t,
1767    ip: *const u8,
1768    iLimit: *const u8,
1769    offsetPtr: *mut size_t,
1770) -> size_t {
1771    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMatchState, 6)
1772}
1773#[inline(never)]
1774unsafe fn ZSTD_RowFindBestMatch_dictMatchState_5_5(
1775    ms: &mut ZSTD_MatchState_t,
1776    ip: *const u8,
1777    iLimit: *const u8,
1778    offsetPtr: *mut size_t,
1779) -> size_t {
1780    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMatchState, 5)
1781}
1782#[inline(never)]
1783unsafe fn ZSTD_RowFindBestMatch_dictMatchState_5_4(
1784    ms: &mut ZSTD_MatchState_t,
1785    ip: *const u8,
1786    iLimit: *const u8,
1787    offsetPtr: *mut size_t,
1788) -> size_t {
1789    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMatchState, 4)
1790}
1791#[inline(never)]
1792unsafe fn ZSTD_RowFindBestMatch_noDict_6_5(
1793    ms: &mut ZSTD_MatchState_t,
1794    ip: *const u8,
1795    iLimit: *const u8,
1796    offsetPtr: *mut size_t,
1797) -> size_t {
1798    ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_noDict, 5)
1799}
1800#[inline(never)]
1801unsafe fn ZSTD_BtFindBestMatch_noDict_6(
1802    ms: &mut ZSTD_MatchState_t,
1803    ip: *const u8,
1804    iLimit: *const u8,
1805    offBasePtr: *mut size_t,
1806) -> size_t {
1807    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 6, ZSTD_noDict)
1808}
1809#[inline(never)]
1810unsafe fn ZSTD_BtFindBestMatch_dictMatchState_6(
1811    ms: &mut ZSTD_MatchState_t,
1812    ip: *const u8,
1813    iLimit: *const u8,
1814    offBasePtr: *mut size_t,
1815) -> size_t {
1816    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 6, ZSTD_dictMatchState)
1817}
1818#[inline(never)]
1819unsafe fn ZSTD_BtFindBestMatch_noDict_5(
1820    ms: &mut ZSTD_MatchState_t,
1821    ip: *const u8,
1822    iLimit: *const u8,
1823    offBasePtr: *mut size_t,
1824) -> size_t {
1825    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 5, ZSTD_noDict)
1826}
1827#[inline(never)]
1828unsafe fn ZSTD_BtFindBestMatch_dedicatedDictSearch_5(
1829    ms: &mut ZSTD_MatchState_t,
1830    ip: *const u8,
1831    iLimit: *const u8,
1832    offBasePtr: *mut size_t,
1833) -> size_t {
1834    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 5, ZSTD_dedicatedDictSearch)
1835}
1836#[inline(never)]
1837unsafe fn ZSTD_BtFindBestMatch_dedicatedDictSearch_6(
1838    ms: &mut ZSTD_MatchState_t,
1839    ip: *const u8,
1840    iLimit: *const u8,
1841    offBasePtr: *mut size_t,
1842) -> size_t {
1843    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 6, ZSTD_dedicatedDictSearch)
1844}
1845#[inline(never)]
1846unsafe fn ZSTD_BtFindBestMatch_dedicatedDictSearch_4(
1847    ms: &mut ZSTD_MatchState_t,
1848    ip: *const u8,
1849    iLimit: *const u8,
1850    offBasePtr: *mut size_t,
1851) -> size_t {
1852    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 4, ZSTD_dedicatedDictSearch)
1853}
1854#[inline(never)]
1855unsafe fn ZSTD_BtFindBestMatch_extDict_4(
1856    ms: &mut ZSTD_MatchState_t,
1857    ip: *const u8,
1858    iLimit: *const u8,
1859    offBasePtr: *mut size_t,
1860) -> size_t {
1861    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 4, ZSTD_extDict)
1862}
1863#[inline(never)]
1864unsafe fn ZSTD_BtFindBestMatch_dictMatchState_4(
1865    ms: &mut ZSTD_MatchState_t,
1866    ip: *const u8,
1867    iLimit: *const u8,
1868    offBasePtr: *mut size_t,
1869) -> size_t {
1870    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 4, ZSTD_dictMatchState)
1871}
1872#[inline(never)]
1873unsafe fn ZSTD_BtFindBestMatch_extDict_6(
1874    ms: &mut ZSTD_MatchState_t,
1875    ip: *const u8,
1876    iLimit: *const u8,
1877    offBasePtr: *mut size_t,
1878) -> size_t {
1879    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 6, ZSTD_extDict)
1880}
1881#[inline(never)]
1882unsafe fn ZSTD_BtFindBestMatch_noDict_4(
1883    ms: &mut ZSTD_MatchState_t,
1884    ip: *const u8,
1885    iLimit: *const u8,
1886    offBasePtr: *mut size_t,
1887) -> size_t {
1888    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 4, ZSTD_noDict)
1889}
1890#[inline(never)]
1891unsafe fn ZSTD_BtFindBestMatch_extDict_5(
1892    ms: &mut ZSTD_MatchState_t,
1893    ip: *const u8,
1894    iLimit: *const u8,
1895    offBasePtr: *mut size_t,
1896) -> size_t {
1897    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 5, ZSTD_extDict)
1898}
1899#[inline(never)]
1900unsafe fn ZSTD_BtFindBestMatch_dictMatchState_5(
1901    ms: &mut ZSTD_MatchState_t,
1902    ip: *const u8,
1903    iLimit: *const u8,
1904    offBasePtr: *mut size_t,
1905) -> size_t {
1906    ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 5, ZSTD_dictMatchState)
1907}
1908#[inline(never)]
1909unsafe fn ZSTD_HcFindBestMatch_noDict_6(
1910    ms: &mut ZSTD_MatchState_t,
1911    ip: *const u8,
1912    iLimit: *const u8,
1913    offsetPtr: *mut size_t,
1914) -> size_t {
1915    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_noDict)
1916}
1917#[inline(never)]
1918unsafe fn ZSTD_HcFindBestMatch_dictMatchState_5(
1919    ms: &mut ZSTD_MatchState_t,
1920    ip: *const u8,
1921    iLimit: *const u8,
1922    offsetPtr: *mut size_t,
1923) -> size_t {
1924    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMatchState)
1925}
1926#[inline(never)]
1927unsafe fn ZSTD_HcFindBestMatch_dedicatedDictSearch_6(
1928    ms: &mut ZSTD_MatchState_t,
1929    ip: *const u8,
1930    iLimit: *const u8,
1931    offsetPtr: *mut size_t,
1932) -> size_t {
1933    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dedicatedDictSearch)
1934}
1935#[inline(never)]
1936unsafe fn ZSTD_HcFindBestMatch_dictMatchState_4(
1937    ms: &mut ZSTD_MatchState_t,
1938    ip: *const u8,
1939    iLimit: *const u8,
1940    offsetPtr: *mut size_t,
1941) -> size_t {
1942    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMatchState)
1943}
1944#[inline(never)]
1945unsafe fn ZSTD_HcFindBestMatch_dedicatedDictSearch_5(
1946    ms: &mut ZSTD_MatchState_t,
1947    ip: *const u8,
1948    iLimit: *const u8,
1949    offsetPtr: *mut size_t,
1950) -> size_t {
1951    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dedicatedDictSearch)
1952}
1953#[inline(never)]
1954unsafe fn ZSTD_HcFindBestMatch_dedicatedDictSearch_4(
1955    ms: &mut ZSTD_MatchState_t,
1956    ip: *const u8,
1957    iLimit: *const u8,
1958    offsetPtr: *mut size_t,
1959) -> size_t {
1960    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dedicatedDictSearch)
1961}
1962#[inline(never)]
1963unsafe fn ZSTD_HcFindBestMatch_noDict_5(
1964    ms: &mut ZSTD_MatchState_t,
1965    ip: *const u8,
1966    iLimit: *const u8,
1967    offsetPtr: *mut size_t,
1968) -> size_t {
1969    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_noDict)
1970}
1971#[inline(never)]
1972unsafe fn ZSTD_HcFindBestMatch_dictMatchState_6(
1973    ms: &mut ZSTD_MatchState_t,
1974    ip: *const u8,
1975    iLimit: *const u8,
1976    offsetPtr: *mut size_t,
1977) -> size_t {
1978    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMatchState)
1979}
1980#[inline(never)]
1981unsafe fn ZSTD_HcFindBestMatch_noDict_4(
1982    ms: &mut ZSTD_MatchState_t,
1983    ip: *const u8,
1984    iLimit: *const u8,
1985    offsetPtr: *mut size_t,
1986) -> size_t {
1987    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_noDict)
1988}
1989#[inline(never)]
1990unsafe fn ZSTD_HcFindBestMatch_extDict_6(
1991    ms: &mut ZSTD_MatchState_t,
1992    ip: *const u8,
1993    iLimit: *const u8,
1994    offsetPtr: *mut size_t,
1995) -> size_t {
1996    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_extDict)
1997}
1998#[inline(never)]
1999unsafe fn ZSTD_HcFindBestMatch_extDict_5(
2000    ms: &mut ZSTD_MatchState_t,
2001    ip: *const u8,
2002    iLimit: *const u8,
2003    offsetPtr: *mut size_t,
2004) -> size_t {
2005    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_extDict)
2006}
2007#[inline(never)]
2008unsafe fn ZSTD_HcFindBestMatch_extDict_4(
2009    ms: &mut ZSTD_MatchState_t,
2010    ip: *const u8,
2011    iLimit: *const u8,
2012    offsetPtr: *mut size_t,
2013) -> size_t {
2014    ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_extDict)
2015}
2016#[inline(always)]
2017unsafe fn ZSTD_searchMax(
2018    ms: &mut ZSTD_MatchState_t,
2019    ip: *const u8,
2020    iend: *const u8,
2021    offsetPtr: *mut size_t,
2022    mls: u32,
2023    rowLog: u32,
2024    searchMethod: searchMethod_e,
2025    dictMode: ZSTD_dictMode_e,
2026) -> size_t {
2027    if dictMode as core::ffi::c_uint == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint {
2028        match searchMethod as core::ffi::c_uint {
2029            0 => match mls {
2030                4 => return ZSTD_HcFindBestMatch_noDict_4(ms, ip, iend, offsetPtr),
2031                5 => return ZSTD_HcFindBestMatch_noDict_5(ms, ip, iend, offsetPtr),
2032                6 => return ZSTD_HcFindBestMatch_noDict_6(ms, ip, iend, offsetPtr),
2033                _ => {}
2034            },
2035            1 => match mls {
2036                4 => return ZSTD_BtFindBestMatch_noDict_4(ms, ip, iend, offsetPtr),
2037                5 => return ZSTD_BtFindBestMatch_noDict_5(ms, ip, iend, offsetPtr),
2038                6 => return ZSTD_BtFindBestMatch_noDict_6(ms, ip, iend, offsetPtr),
2039                _ => {}
2040            },
2041            2 => match mls {
2042                4 => {
2043                    match rowLog {
2044                        4 => {
2045                            return ZSTD_RowFindBestMatch_noDict_4_4(ms, ip, iend, offsetPtr);
2046                        }
2047                        5 => {
2048                            return ZSTD_RowFindBestMatch_noDict_4_5(ms, ip, iend, offsetPtr);
2049                        }
2050                        6 => {
2051                            return ZSTD_RowFindBestMatch_noDict_4_6(ms, ip, iend, offsetPtr);
2052                        }
2053                        _ => {}
2054                    }
2055                    unreachable!();
2056                }
2057                5 => {
2058                    match rowLog {
2059                        4 => {
2060                            return ZSTD_RowFindBestMatch_noDict_5_4(ms, ip, iend, offsetPtr);
2061                        }
2062                        5 => {
2063                            return ZSTD_RowFindBestMatch_noDict_5_5(ms, ip, iend, offsetPtr);
2064                        }
2065                        6 => {
2066                            return ZSTD_RowFindBestMatch_noDict_5_6(ms, ip, iend, offsetPtr);
2067                        }
2068                        _ => {}
2069                    }
2070                    unreachable!();
2071                }
2072                6 => {
2073                    match rowLog {
2074                        4 => {
2075                            return ZSTD_RowFindBestMatch_noDict_6_4(ms, ip, iend, offsetPtr);
2076                        }
2077                        5 => {
2078                            return ZSTD_RowFindBestMatch_noDict_6_5(ms, ip, iend, offsetPtr);
2079                        }
2080                        6 => {
2081                            return ZSTD_RowFindBestMatch_noDict_6_6(ms, ip, iend, offsetPtr);
2082                        }
2083                        _ => {}
2084                    }
2085                    unreachable!();
2086                }
2087                _ => {}
2088            },
2089            _ => {}
2090        }
2091        unreachable!();
2092    } else if dictMode as core::ffi::c_uint == ZSTD_extDict as core::ffi::c_int as core::ffi::c_uint
2093    {
2094        match searchMethod as core::ffi::c_uint {
2095            0 => match mls {
2096                4 => return ZSTD_HcFindBestMatch_extDict_4(ms, ip, iend, offsetPtr),
2097                5 => return ZSTD_HcFindBestMatch_extDict_5(ms, ip, iend, offsetPtr),
2098                6 => return ZSTD_HcFindBestMatch_extDict_6(ms, ip, iend, offsetPtr),
2099                _ => {}
2100            },
2101            1 => match mls {
2102                4 => return ZSTD_BtFindBestMatch_extDict_4(ms, ip, iend, offsetPtr),
2103                5 => return ZSTD_BtFindBestMatch_extDict_5(ms, ip, iend, offsetPtr),
2104                6 => return ZSTD_BtFindBestMatch_extDict_6(ms, ip, iend, offsetPtr),
2105                _ => {}
2106            },
2107            2 => match mls {
2108                4 => {
2109                    match rowLog {
2110                        4 => {
2111                            return ZSTD_RowFindBestMatch_extDict_4_4(ms, ip, iend, offsetPtr);
2112                        }
2113                        5 => {
2114                            return ZSTD_RowFindBestMatch_extDict_4_5(ms, ip, iend, offsetPtr);
2115                        }
2116                        6 => {
2117                            return ZSTD_RowFindBestMatch_extDict_4_6(ms, ip, iend, offsetPtr);
2118                        }
2119                        _ => {}
2120                    }
2121                    unreachable!();
2122                }
2123                5 => {
2124                    match rowLog {
2125                        4 => {
2126                            return ZSTD_RowFindBestMatch_extDict_5_4(ms, ip, iend, offsetPtr);
2127                        }
2128                        5 => {
2129                            return ZSTD_RowFindBestMatch_extDict_5_5(ms, ip, iend, offsetPtr);
2130                        }
2131                        6 => {
2132                            return ZSTD_RowFindBestMatch_extDict_5_6(ms, ip, iend, offsetPtr);
2133                        }
2134                        _ => {}
2135                    }
2136                    unreachable!();
2137                }
2138                6 => {
2139                    match rowLog {
2140                        4 => {
2141                            return ZSTD_RowFindBestMatch_extDict_6_4(ms, ip, iend, offsetPtr);
2142                        }
2143                        5 => {
2144                            return ZSTD_RowFindBestMatch_extDict_6_5(ms, ip, iend, offsetPtr);
2145                        }
2146                        6 => {
2147                            return ZSTD_RowFindBestMatch_extDict_6_6(ms, ip, iend, offsetPtr);
2148                        }
2149                        _ => {}
2150                    }
2151                    unreachable!();
2152                }
2153                _ => {}
2154            },
2155            _ => {}
2156        }
2157        unreachable!();
2158    } else if dictMode as core::ffi::c_uint
2159        == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
2160    {
2161        match searchMethod as core::ffi::c_uint {
2162            0 => match mls {
2163                4 => {
2164                    return ZSTD_HcFindBestMatch_dictMatchState_4(ms, ip, iend, offsetPtr);
2165                }
2166                5 => {
2167                    return ZSTD_HcFindBestMatch_dictMatchState_5(ms, ip, iend, offsetPtr);
2168                }
2169                6 => {
2170                    return ZSTD_HcFindBestMatch_dictMatchState_6(ms, ip, iend, offsetPtr);
2171                }
2172                _ => {}
2173            },
2174            1 => match mls {
2175                4 => {
2176                    return ZSTD_BtFindBestMatch_dictMatchState_4(ms, ip, iend, offsetPtr);
2177                }
2178                5 => {
2179                    return ZSTD_BtFindBestMatch_dictMatchState_5(ms, ip, iend, offsetPtr);
2180                }
2181                6 => {
2182                    return ZSTD_BtFindBestMatch_dictMatchState_6(ms, ip, iend, offsetPtr);
2183                }
2184                _ => {}
2185            },
2186            2 => match mls {
2187                4 => {
2188                    match rowLog {
2189                        4 => {
2190                            return ZSTD_RowFindBestMatch_dictMatchState_4_4(
2191                                ms, ip, iend, offsetPtr,
2192                            );
2193                        }
2194                        5 => {
2195                            return ZSTD_RowFindBestMatch_dictMatchState_4_5(
2196                                ms, ip, iend, offsetPtr,
2197                            );
2198                        }
2199                        6 => {
2200                            return ZSTD_RowFindBestMatch_dictMatchState_4_6(
2201                                ms, ip, iend, offsetPtr,
2202                            );
2203                        }
2204                        _ => {}
2205                    }
2206                    unreachable!();
2207                }
2208                5 => {
2209                    match rowLog {
2210                        4 => {
2211                            return ZSTD_RowFindBestMatch_dictMatchState_5_4(
2212                                ms, ip, iend, offsetPtr,
2213                            );
2214                        }
2215                        5 => {
2216                            return ZSTD_RowFindBestMatch_dictMatchState_5_5(
2217                                ms, ip, iend, offsetPtr,
2218                            );
2219                        }
2220                        6 => {
2221                            return ZSTD_RowFindBestMatch_dictMatchState_5_6(
2222                                ms, ip, iend, offsetPtr,
2223                            );
2224                        }
2225                        _ => {}
2226                    }
2227                    unreachable!();
2228                }
2229                6 => {
2230                    match rowLog {
2231                        4 => {
2232                            return ZSTD_RowFindBestMatch_dictMatchState_6_4(
2233                                ms, ip, iend, offsetPtr,
2234                            );
2235                        }
2236                        5 => {
2237                            return ZSTD_RowFindBestMatch_dictMatchState_6_5(
2238                                ms, ip, iend, offsetPtr,
2239                            );
2240                        }
2241                        6 => {
2242                            return ZSTD_RowFindBestMatch_dictMatchState_6_6(
2243                                ms, ip, iend, offsetPtr,
2244                            );
2245                        }
2246                        _ => {}
2247                    }
2248                    unreachable!();
2249                }
2250                _ => {}
2251            },
2252            _ => {}
2253        }
2254        unreachable!();
2255    } else if dictMode as core::ffi::c_uint
2256        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint
2257    {
2258        match searchMethod as core::ffi::c_uint {
2259            0 => match mls {
2260                4 => {
2261                    return ZSTD_HcFindBestMatch_dedicatedDictSearch_4(ms, ip, iend, offsetPtr);
2262                }
2263                5 => {
2264                    return ZSTD_HcFindBestMatch_dedicatedDictSearch_5(ms, ip, iend, offsetPtr);
2265                }
2266                6 => {
2267                    return ZSTD_HcFindBestMatch_dedicatedDictSearch_6(ms, ip, iend, offsetPtr);
2268                }
2269                _ => {}
2270            },
2271            1 => match mls {
2272                4 => {
2273                    return ZSTD_BtFindBestMatch_dedicatedDictSearch_4(ms, ip, iend, offsetPtr);
2274                }
2275                5 => {
2276                    return ZSTD_BtFindBestMatch_dedicatedDictSearch_5(ms, ip, iend, offsetPtr);
2277                }
2278                6 => {
2279                    return ZSTD_BtFindBestMatch_dedicatedDictSearch_6(ms, ip, iend, offsetPtr);
2280                }
2281                _ => {}
2282            },
2283            2 => match mls {
2284                4 => {
2285                    match rowLog {
2286                        4 => {
2287                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_4(
2288                                ms, ip, iend, offsetPtr,
2289                            );
2290                        }
2291                        5 => {
2292                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_5(
2293                                ms, ip, iend, offsetPtr,
2294                            );
2295                        }
2296                        6 => {
2297                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_6(
2298                                ms, ip, iend, offsetPtr,
2299                            );
2300                        }
2301                        _ => {}
2302                    }
2303                    unreachable!();
2304                }
2305                5 => {
2306                    match rowLog {
2307                        4 => {
2308                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_4(
2309                                ms, ip, iend, offsetPtr,
2310                            );
2311                        }
2312                        5 => {
2313                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_5(
2314                                ms, ip, iend, offsetPtr,
2315                            );
2316                        }
2317                        6 => {
2318                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_6(
2319                                ms, ip, iend, offsetPtr,
2320                            );
2321                        }
2322                        _ => {}
2323                    }
2324                    unreachable!();
2325                }
2326                6 => {
2327                    match rowLog {
2328                        4 => {
2329                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_4(
2330                                ms, ip, iend, offsetPtr,
2331                            );
2332                        }
2333                        5 => {
2334                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_5(
2335                                ms, ip, iend, offsetPtr,
2336                            );
2337                        }
2338                        6 => {
2339                            return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_6(
2340                                ms, ip, iend, offsetPtr,
2341                            );
2342                        }
2343                        _ => {}
2344                    }
2345                    unreachable!();
2346                }
2347                _ => {}
2348            },
2349            _ => {}
2350        }
2351        unreachable!();
2352    }
2353    unreachable!();
2354}
2355#[inline(always)]
2356unsafe fn ZSTD_compressBlock_lazy_generic(
2357    ms: &mut ZSTD_MatchState_t,
2358    seqStore: &mut SeqStore_t,
2359    rep: *mut u32,
2360    src: *const core::ffi::c_void,
2361    srcSize: size_t,
2362    searchMethod: searchMethod_e,
2363    depth: u32,
2364    dictMode: ZSTD_dictMode_e,
2365) -> size_t {
2366    let mut current_block: u64;
2367    let istart = src as *const u8;
2368    let mut ip = istart;
2369    let mut anchor = istart;
2370    let iend = istart.add(srcSize);
2371    let ilimit = if searchMethod as core::ffi::c_uint
2372        == search_rowHash as core::ffi::c_int as core::ffi::c_uint
2373    {
2374        iend.sub(8).offset(-(ZSTD_ROW_HASH_CACHE_SIZE as isize))
2375    } else {
2376        iend.sub(8)
2377    };
2378    let base = ms.window.base;
2379    let prefixLowestIndex = ms.window.dictLimit;
2380    let prefixLowest = base.offset(prefixLowestIndex as isize);
2381    let mls = if 4
2382        > (if ms.cParams.minMatch < 6 {
2383            ms.cParams.minMatch
2384        } else {
2385            6
2386        }) {
2387        4
2388    } else if ms.cParams.minMatch < 6 {
2389        ms.cParams.minMatch
2390    } else {
2391        6
2392    };
2393    let rowLog = if 4
2394        > (if ms.cParams.searchLog < 6 {
2395            ms.cParams.searchLog
2396        } else {
2397            6
2398        }) {
2399        4
2400    } else if ms.cParams.searchLog < 6 {
2401        ms.cParams.searchLog
2402    } else {
2403        6
2404    };
2405    let mut offset_1 = *rep;
2406    let mut offset_2 = *rep.add(1);
2407    let mut offsetSaved1 = 0;
2408    let mut offsetSaved2 = 0;
2409    let isDMS = (dictMode as core::ffi::c_uint
2410        == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint)
2411        as core::ffi::c_int;
2412    let isDDS = (dictMode as core::ffi::c_uint
2413        == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint)
2414        as core::ffi::c_int;
2415    let isDxS = (isDMS != 0 || isDDS != 0) as core::ffi::c_int;
2416    let dms = ms.dictMatchState;
2417    let dictLowestIndex = if isDxS != 0 {
2418        (*dms).window.dictLimit
2419    } else {
2420        0
2421    };
2422    let dictBase = if isDxS != 0 {
2423        (*dms).window.base
2424    } else {
2425        core::ptr::null()
2426    };
2427    let dictLowest = if isDxS != 0 {
2428        dictBase.offset(dictLowestIndex as isize)
2429    } else {
2430        core::ptr::null()
2431    };
2432    let dictEnd = if isDxS != 0 {
2433        (*dms).window.nextSrc
2434    } else {
2435        core::ptr::null()
2436    };
2437    let dictIndexDelta = if isDxS != 0 {
2438        prefixLowestIndex.wrapping_sub(dictEnd.offset_from(dictBase) as core::ffi::c_long as u32)
2439    } else {
2440        0
2441    };
2442    let dictAndPrefixLength = (ip.offset_from(prefixLowest) as core::ffi::c_long
2443        + dictEnd.offset_from(dictLowest) as core::ffi::c_long)
2444        as u32;
2445    ip = ip.offset((dictAndPrefixLength == 0) as core::ffi::c_int as isize);
2446    if dictMode as core::ffi::c_uint == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint {
2447        let curr = ip.offset_from(base) as core::ffi::c_long as u32;
2448        let windowLow = ZSTD_getLowestPrefixIndex(ms, curr, ms.cParams.windowLog);
2449        let maxRep = curr.wrapping_sub(windowLow);
2450        if offset_2 > maxRep {
2451            offsetSaved2 = offset_2;
2452            offset_2 = 0;
2453        }
2454        if offset_1 > maxRep {
2455            offsetSaved1 = offset_1;
2456            offset_1 = 0;
2457        }
2458    }
2459
2460    if isDxS != 0 {
2461        // dictMatchState repCode checks don't currently handle repCode == 0 disabling.
2462        assert!(offset_1 <= dictAndPrefixLength);
2463        assert!(offset_2 <= dictAndPrefixLength);
2464    }
2465
2466    /* Reset the lazy skipping state */
2467    ms.lazySkipping = 0;
2468
2469    if searchMethod == search_rowHash {
2470        ZSTD_row_fillHashCache(ms, base, rowLog, mls, ms.nextToUpdate, ilimit);
2471    }
2472
2473    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
2474    asm!(".p2align 5", options(preserves_flags));
2475
2476    while ip < ilimit {
2477        let mut matchLength = 0;
2478        let mut offBase = REPCODE1_TO_OFFBASE as size_t;
2479        let mut start = ip.add(1);
2480        if isDxS != 0 {
2481            let repIndex = (ip.offset_from(base) as core::ffi::c_long as u32)
2482                .wrapping_add(1)
2483                .wrapping_sub(offset_1);
2484            let repMatch = if (dictMode as core::ffi::c_uint
2485                == ZSTD_dictMatchState as core::ffi::c_int as core::ffi::c_uint
2486                || dictMode as core::ffi::c_uint
2487                    == ZSTD_dedicatedDictSearch as core::ffi::c_int as core::ffi::c_uint)
2488                && repIndex < prefixLowestIndex
2489            {
2490                dictBase.offset(repIndex.wrapping_sub(dictIndexDelta) as isize)
2491            } else {
2492                base.offset(repIndex as isize)
2493            };
2494            if ZSTD_index_overlap_check(prefixLowestIndex, repIndex) != 0
2495                && MEM_read32(repMatch as *const core::ffi::c_void)
2496                    == MEM_read32(ip.add(1) as *const core::ffi::c_void)
2497            {
2498                let repMatchEnd = if repIndex < prefixLowestIndex {
2499                    dictEnd
2500                } else {
2501                    iend
2502                };
2503                matchLength = (ZSTD_count_2segments(
2504                    ip.add(1).add(4),
2505                    repMatch.add(4),
2506                    iend,
2507                    repMatchEnd,
2508                    prefixLowest,
2509                ))
2510                .wrapping_add(4);
2511                if depth == 0 {
2512                    current_block = 9173645608424642017;
2513                } else {
2514                    current_block = 14136749492126903395;
2515                }
2516            } else {
2517                current_block = 14136749492126903395;
2518            }
2519        } else {
2520            current_block = 14136749492126903395;
2521        }
2522        if current_block == 14136749492126903395 {
2523            if dictMode as core::ffi::c_uint == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint
2524                && (offset_1 > 0) as core::ffi::c_int
2525                    & (MEM_read32(
2526                        ip.add(1).offset(-(offset_1 as isize)) as *const core::ffi::c_void
2527                    ) == MEM_read32(ip.add(1) as *const core::ffi::c_void))
2528                        as core::ffi::c_int
2529                    != 0
2530            {
2531                matchLength = (ZSTD_count(
2532                    ip.add(1).add(4),
2533                    ip.add(1).add(4).offset(-(offset_1 as isize)),
2534                    iend,
2535                ))
2536                .wrapping_add(4);
2537                if depth == 0 {
2538                    current_block = 9173645608424642017;
2539                } else {
2540                    current_block = 6450636197030046351;
2541                }
2542            } else {
2543                current_block = 6450636197030046351;
2544            }
2545            match current_block {
2546                9173645608424642017 => {}
2547                _ => {
2548                    let mut offbaseFound = 999999999;
2549                    let ml2 = ZSTD_searchMax(
2550                        ms,
2551                        ip,
2552                        iend,
2553                        &mut offbaseFound,
2554                        mls,
2555                        rowLog,
2556                        searchMethod,
2557                        dictMode,
2558                    );
2559                    if ml2 > matchLength {
2560                        matchLength = ml2;
2561                        start = ip;
2562                        offBase = offbaseFound;
2563                    }
2564                    if matchLength < 4 {
2565                        let step =
2566                            (ip.offset_from_unsigned(anchor) >> kSearchStrength).wrapping_add(1);
2567                        ip = ip.add(step);
2568                        ms.lazySkipping = (step > kLazySkippingStep as size_t) as core::ffi::c_int;
2569                        continue;
2570                    } else {
2571                        if depth >= 1 {
2572                            while ip < ilimit {
2573                                ip = ip.add(1);
2574                                if dictMode as core::ffi::c_uint
2575                                    == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint
2576                                    && offBase != 0
2577                                    && (offset_1 > 0) as core::ffi::c_int
2578                                        & (MEM_read32(ip as *const core::ffi::c_void)
2579                                            == MEM_read32(ip.offset(-(offset_1 as isize))
2580                                                as *const core::ffi::c_void))
2581                                            as core::ffi::c_int
2582                                        != 0
2583                                {
2584                                    let mlRep = (ZSTD_count(
2585                                        ip.add(4),
2586                                        ip.add(4).offset(-(offset_1 as isize)),
2587                                        iend,
2588                                    ))
2589                                    .wrapping_add(4);
2590                                    let gain2 = (mlRep * 3) as core::ffi::c_int;
2591                                    let gain1 = (matchLength * 3)
2592                                        .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
2593                                        .wrapping_add(1)
2594                                        as core::ffi::c_int;
2595                                    if mlRep >= 4 && gain2 > gain1 {
2596                                        matchLength = mlRep;
2597                                        offBase = REPCODE1_TO_OFFBASE as size_t;
2598                                        start = ip;
2599                                    }
2600                                }
2601                                if isDxS != 0 {
2602                                    let repIndex_0 = (ip.offset_from(base) as core::ffi::c_long
2603                                        as u32)
2604                                        .wrapping_sub(offset_1);
2605                                    let repMatch_0 = if repIndex_0 < prefixLowestIndex {
2606                                        dictBase
2607                                            .offset(repIndex_0.wrapping_sub(dictIndexDelta)
2608                                                as isize)
2609                                    } else {
2610                                        base.offset(repIndex_0 as isize)
2611                                    };
2612                                    if ZSTD_index_overlap_check(prefixLowestIndex, repIndex_0) != 0
2613                                        && MEM_read32(repMatch_0 as *const core::ffi::c_void)
2614                                            == MEM_read32(ip as *const core::ffi::c_void)
2615                                    {
2616                                        let repMatchEnd_0 = if repIndex_0 < prefixLowestIndex {
2617                                            dictEnd
2618                                        } else {
2619                                            iend
2620                                        };
2621                                        let mlRep_0 = (ZSTD_count_2segments(
2622                                            ip.add(4),
2623                                            repMatch_0.add(4),
2624                                            iend,
2625                                            repMatchEnd_0,
2626                                            prefixLowest,
2627                                        ))
2628                                        .wrapping_add(4);
2629                                        let gain2_0 = (mlRep_0 * 3) as core::ffi::c_int;
2630                                        let gain1_0 = (matchLength * 3)
2631                                            .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
2632                                            .wrapping_add(1)
2633                                            as core::ffi::c_int;
2634                                        if mlRep_0 >= 4 && gain2_0 > gain1_0 {
2635                                            matchLength = mlRep_0;
2636                                            offBase = REPCODE1_TO_OFFBASE as size_t;
2637                                            start = ip;
2638                                        }
2639                                    }
2640                                }
2641                                let mut ofbCandidate = 999999999;
2642                                let ml2_0 = ZSTD_searchMax(
2643                                    ms,
2644                                    ip,
2645                                    iend,
2646                                    &mut ofbCandidate,
2647                                    mls,
2648                                    rowLog,
2649                                    searchMethod,
2650                                    dictMode,
2651                                );
2652                                let gain2_1 = (ml2_0 * 4)
2653                                    .wrapping_sub(ZSTD_highbit32(ofbCandidate as u32) as size_t)
2654                                    as core::ffi::c_int;
2655                                let gain1_1 = (matchLength * 4)
2656                                    .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
2657                                    .wrapping_add(4)
2658                                    as core::ffi::c_int;
2659                                if ml2_0 >= 4 && gain2_1 > gain1_1 {
2660                                    matchLength = ml2_0;
2661                                    offBase = ofbCandidate;
2662                                    start = ip;
2663                                } else {
2664                                    if !(depth == 2 && ip < ilimit) {
2665                                        break;
2666                                    }
2667                                    ip = ip.add(1);
2668                                    if dictMode as core::ffi::c_uint
2669                                        == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint
2670                                        && offBase != 0
2671                                        && (offset_1 > 0) as core::ffi::c_int
2672                                            & (MEM_read32(ip as *const core::ffi::c_void)
2673                                                == MEM_read32(ip.offset(-(offset_1 as isize))
2674                                                    as *const core::ffi::c_void))
2675                                                as core::ffi::c_int
2676                                            != 0
2677                                    {
2678                                        let mlRep_1 = (ZSTD_count(
2679                                            ip.add(4),
2680                                            ip.add(4).offset(-(offset_1 as isize)),
2681                                            iend,
2682                                        ))
2683                                        .wrapping_add(4);
2684                                        let gain2_2 = (mlRep_1 * 4) as core::ffi::c_int;
2685                                        let gain1_2 = (matchLength * 4)
2686                                            .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
2687                                            .wrapping_add(1)
2688                                            as core::ffi::c_int;
2689                                        if mlRep_1 >= 4 && gain2_2 > gain1_2 {
2690                                            matchLength = mlRep_1;
2691                                            offBase = REPCODE1_TO_OFFBASE as size_t;
2692                                            start = ip;
2693                                        }
2694                                    }
2695                                    if isDxS != 0 {
2696                                        let repIndex_1 = (ip.offset_from(base) as core::ffi::c_long
2697                                            as u32)
2698                                            .wrapping_sub(offset_1);
2699                                        let repMatch_1 = if repIndex_1 < prefixLowestIndex {
2700                                            dictBase
2701                                                .offset(repIndex_1.wrapping_sub(dictIndexDelta)
2702                                                    as isize)
2703                                        } else {
2704                                            base.offset(repIndex_1 as isize)
2705                                        };
2706                                        if ZSTD_index_overlap_check(prefixLowestIndex, repIndex_1)
2707                                            != 0
2708                                            && MEM_read32(repMatch_1 as *const core::ffi::c_void)
2709                                                == MEM_read32(ip as *const core::ffi::c_void)
2710                                        {
2711                                            let repMatchEnd_1 = if repIndex_1 < prefixLowestIndex {
2712                                                dictEnd
2713                                            } else {
2714                                                iend
2715                                            };
2716                                            let mlRep_2 = (ZSTD_count_2segments(
2717                                                ip.add(4),
2718                                                repMatch_1.add(4),
2719                                                iend,
2720                                                repMatchEnd_1,
2721                                                prefixLowest,
2722                                            ))
2723                                            .wrapping_add(4);
2724                                            let gain2_3 = (mlRep_2 * 4) as core::ffi::c_int;
2725                                            let gain1_3 = (matchLength * 4)
2726                                                .wrapping_sub(
2727                                                    ZSTD_highbit32(offBase as u32) as size_t
2728                                                )
2729                                                .wrapping_add(1)
2730                                                as core::ffi::c_int;
2731                                            if mlRep_2 >= 4 && gain2_3 > gain1_3 {
2732                                                matchLength = mlRep_2;
2733                                                offBase = REPCODE1_TO_OFFBASE as size_t;
2734                                                start = ip;
2735                                            }
2736                                        }
2737                                    }
2738                                    let mut ofbCandidate_0 = 999999999;
2739                                    let ml2_1 = ZSTD_searchMax(
2740                                        ms,
2741                                        ip,
2742                                        iend,
2743                                        &mut ofbCandidate_0,
2744                                        mls,
2745                                        rowLog,
2746                                        searchMethod,
2747                                        dictMode,
2748                                    );
2749                                    let gain2_4 = (ml2_1 * 4)
2750                                        .wrapping_sub(
2751                                            ZSTD_highbit32(ofbCandidate_0 as u32) as size_t
2752                                        )
2753                                        as core::ffi::c_int;
2754                                    let gain1_4 = (matchLength * 4)
2755                                        .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
2756                                        .wrapping_add(7)
2757                                        as core::ffi::c_int;
2758                                    if !(ml2_1 >= 4 && gain2_4 > gain1_4) {
2759                                        break;
2760                                    }
2761                                    matchLength = ml2_1;
2762                                    offBase = ofbCandidate_0;
2763                                    start = ip;
2764                                }
2765                            }
2766                        }
2767                        if offBase > ZSTD_REP_NUM as size_t {
2768                            if dictMode as core::ffi::c_uint
2769                                == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint
2770                            {
2771                                while (start > anchor) as core::ffi::c_int
2772                                    & (start.offset(
2773                                        -(offBase.wrapping_sub(ZSTD_REP_NUM as size_t) as isize),
2774                                    ) > prefixLowest)
2775                                        as core::ffi::c_int
2776                                    != 0
2777                                    && *start.sub(1) as core::ffi::c_int
2778                                        == *start
2779                                            .offset(
2780                                                -(offBase.wrapping_sub(ZSTD_REP_NUM as size_t)
2781                                                    as isize),
2782                                            )
2783                                            .sub(1)
2784                                            as core::ffi::c_int
2785                                {
2786                                    start = start.sub(1);
2787                                    matchLength = matchLength.wrapping_add(1);
2788                                }
2789                            }
2790                            if isDxS != 0 {
2791                                let matchIndex = (start.offset_from(base) as core::ffi::c_long
2792                                    as size_t)
2793                                    .wrapping_sub(offBase.wrapping_sub(ZSTD_REP_NUM as size_t))
2794                                    as u32;
2795                                let mut match_0 = if matchIndex < prefixLowestIndex {
2796                                    dictBase
2797                                        .offset(matchIndex as isize)
2798                                        .offset(-(dictIndexDelta as isize))
2799                                } else {
2800                                    base.offset(matchIndex as isize)
2801                                };
2802                                let mStart = if matchIndex < prefixLowestIndex {
2803                                    dictLowest
2804                                } else {
2805                                    prefixLowest
2806                                };
2807                                while start > anchor
2808                                    && match_0 > mStart
2809                                    && *start.sub(1) as core::ffi::c_int
2810                                        == *match_0.sub(1) as core::ffi::c_int
2811                                {
2812                                    start = start.sub(1);
2813                                    match_0 = match_0.sub(1);
2814                                    matchLength = matchLength.wrapping_add(1);
2815                                }
2816                            }
2817                            offset_2 = offset_1;
2818                            offset_1 = offBase.wrapping_sub(ZSTD_REP_NUM as size_t) as u32;
2819                        }
2820                    }
2821                }
2822            }
2823        }
2824        let litLength = start.offset_from_unsigned(anchor);
2825        ZSTD_storeSeq(
2826            seqStore,
2827            litLength,
2828            anchor,
2829            iend,
2830            offBase as u32,
2831            matchLength,
2832        );
2833        ip = start.add(matchLength);
2834        anchor = ip;
2835        if ms.lazySkipping != 0 {
2836            if searchMethod as core::ffi::c_uint
2837                == search_rowHash as core::ffi::c_int as core::ffi::c_uint
2838            {
2839                ZSTD_row_fillHashCache(ms, base, rowLog, mls, ms.nextToUpdate, ilimit);
2840            }
2841            ms.lazySkipping = 0;
2842        }
2843        if isDxS != 0 {
2844            while ip <= ilimit {
2845                let current2 = ip.offset_from(base) as core::ffi::c_long as u32;
2846                let repIndex_2 = current2.wrapping_sub(offset_2);
2847                let repMatch_2 = if repIndex_2 < prefixLowestIndex {
2848                    dictBase
2849                        .offset(-(dictIndexDelta as isize))
2850                        .offset(repIndex_2 as isize)
2851                } else {
2852                    base.offset(repIndex_2 as isize)
2853                };
2854                if !(ZSTD_index_overlap_check(prefixLowestIndex, repIndex_2) != 0
2855                    && MEM_read32(repMatch_2 as *const core::ffi::c_void)
2856                        == MEM_read32(ip as *const core::ffi::c_void))
2857                {
2858                    break;
2859                }
2860                let repEnd2 = if repIndex_2 < prefixLowestIndex {
2861                    dictEnd
2862                } else {
2863                    iend
2864                };
2865                matchLength = (ZSTD_count_2segments(
2866                    ip.add(4),
2867                    repMatch_2.add(4),
2868                    iend,
2869                    repEnd2,
2870                    prefixLowest,
2871                ))
2872                .wrapping_add(4);
2873                offBase = offset_2 as size_t;
2874                offset_2 = offset_1;
2875                offset_1 = offBase as u32;
2876                ZSTD_storeSeq(
2877                    seqStore,
2878                    0,
2879                    anchor,
2880                    iend,
2881                    REPCODE1_TO_OFFBASE as u32,
2882                    matchLength,
2883                );
2884                ip = ip.add(matchLength);
2885                anchor = ip;
2886            }
2887        }
2888        if dictMode as core::ffi::c_uint == ZSTD_noDict as core::ffi::c_int as core::ffi::c_uint {
2889            while (ip <= ilimit) as core::ffi::c_int & (offset_2 > 0) as core::ffi::c_int != 0
2890                && MEM_read32(ip as *const core::ffi::c_void)
2891                    == MEM_read32(ip.offset(-(offset_2 as isize)) as *const core::ffi::c_void)
2892            {
2893                matchLength = (ZSTD_count(ip.add(4), ip.add(4).offset(-(offset_2 as isize)), iend))
2894                    .wrapping_add(4);
2895                offBase = offset_2 as size_t;
2896                offset_2 = offset_1;
2897                offset_1 = offBase as u32;
2898                ZSTD_storeSeq(
2899                    seqStore,
2900                    0,
2901                    anchor,
2902                    iend,
2903                    REPCODE1_TO_OFFBASE as u32,
2904                    matchLength,
2905                );
2906                ip = ip.add(matchLength);
2907                anchor = ip;
2908            }
2909        }
2910    }
2911    offsetSaved2 = if offsetSaved1 != 0 && offset_1 != 0 {
2912        offsetSaved1
2913    } else {
2914        offsetSaved2
2915    };
2916    *rep = if offset_1 != 0 {
2917        offset_1
2918    } else {
2919        offsetSaved1
2920    };
2921    *rep.add(1) = if offset_2 != 0 {
2922        offset_2
2923    } else {
2924        offsetSaved2
2925    };
2926    iend.offset_from_unsigned(anchor)
2927}
2928pub unsafe fn ZSTD_compressBlock_greedy(
2929    ms: &mut ZSTD_MatchState_t,
2930    seqStore: &mut SeqStore_t,
2931    rep: *mut u32,
2932    src: *const core::ffi::c_void,
2933    srcSize: size_t,
2934) -> size_t {
2935    ZSTD_compressBlock_lazy_generic(
2936        ms,
2937        seqStore,
2938        rep,
2939        src,
2940        srcSize,
2941        search_hashChain,
2942        0,
2943        ZSTD_noDict,
2944    )
2945}
2946pub unsafe fn ZSTD_compressBlock_greedy_dictMatchState(
2947    ms: &mut ZSTD_MatchState_t,
2948    seqStore: &mut SeqStore_t,
2949    rep: *mut u32,
2950    src: *const core::ffi::c_void,
2951    srcSize: size_t,
2952) -> size_t {
2953    ZSTD_compressBlock_lazy_generic(
2954        ms,
2955        seqStore,
2956        rep,
2957        src,
2958        srcSize,
2959        search_hashChain,
2960        0,
2961        ZSTD_dictMatchState,
2962    )
2963}
2964pub unsafe fn ZSTD_compressBlock_greedy_dedicatedDictSearch(
2965    ms: &mut ZSTD_MatchState_t,
2966    seqStore: &mut SeqStore_t,
2967    rep: *mut u32,
2968    src: *const core::ffi::c_void,
2969    srcSize: size_t,
2970) -> size_t {
2971    ZSTD_compressBlock_lazy_generic(
2972        ms,
2973        seqStore,
2974        rep,
2975        src,
2976        srcSize,
2977        search_hashChain,
2978        0,
2979        ZSTD_dedicatedDictSearch,
2980    )
2981}
2982pub unsafe fn ZSTD_compressBlock_greedy_row(
2983    ms: &mut ZSTD_MatchState_t,
2984    seqStore: &mut SeqStore_t,
2985    rep: *mut u32,
2986    src: *const core::ffi::c_void,
2987    srcSize: size_t,
2988) -> size_t {
2989    ZSTD_compressBlock_lazy_generic(
2990        ms,
2991        seqStore,
2992        rep,
2993        src,
2994        srcSize,
2995        search_rowHash,
2996        0,
2997        ZSTD_noDict,
2998    )
2999}
3000pub unsafe fn ZSTD_compressBlock_greedy_dictMatchState_row(
3001    ms: &mut ZSTD_MatchState_t,
3002    seqStore: &mut SeqStore_t,
3003    rep: *mut u32,
3004    src: *const core::ffi::c_void,
3005    srcSize: size_t,
3006) -> size_t {
3007    ZSTD_compressBlock_lazy_generic(
3008        ms,
3009        seqStore,
3010        rep,
3011        src,
3012        srcSize,
3013        search_rowHash,
3014        0,
3015        ZSTD_dictMatchState,
3016    )
3017}
3018pub unsafe fn ZSTD_compressBlock_greedy_dedicatedDictSearch_row(
3019    ms: &mut ZSTD_MatchState_t,
3020    seqStore: &mut SeqStore_t,
3021    rep: *mut u32,
3022    src: *const core::ffi::c_void,
3023    srcSize: size_t,
3024) -> size_t {
3025    ZSTD_compressBlock_lazy_generic(
3026        ms,
3027        seqStore,
3028        rep,
3029        src,
3030        srcSize,
3031        search_rowHash,
3032        0,
3033        ZSTD_dedicatedDictSearch,
3034    )
3035}
3036pub unsafe fn ZSTD_compressBlock_lazy(
3037    ms: &mut ZSTD_MatchState_t,
3038    seqStore: &mut SeqStore_t,
3039    rep: *mut u32,
3040    src: *const core::ffi::c_void,
3041    srcSize: size_t,
3042) -> size_t {
3043    ZSTD_compressBlock_lazy_generic(
3044        ms,
3045        seqStore,
3046        rep,
3047        src,
3048        srcSize,
3049        search_hashChain,
3050        1,
3051        ZSTD_noDict,
3052    )
3053}
3054pub unsafe fn ZSTD_compressBlock_lazy_dictMatchState(
3055    ms: &mut ZSTD_MatchState_t,
3056    seqStore: &mut SeqStore_t,
3057    rep: *mut u32,
3058    src: *const core::ffi::c_void,
3059    srcSize: size_t,
3060) -> size_t {
3061    ZSTD_compressBlock_lazy_generic(
3062        ms,
3063        seqStore,
3064        rep,
3065        src,
3066        srcSize,
3067        search_hashChain,
3068        1,
3069        ZSTD_dictMatchState,
3070    )
3071}
3072pub unsafe fn ZSTD_compressBlock_lazy_dedicatedDictSearch(
3073    ms: &mut ZSTD_MatchState_t,
3074    seqStore: &mut SeqStore_t,
3075    rep: *mut u32,
3076    src: *const core::ffi::c_void,
3077    srcSize: size_t,
3078) -> size_t {
3079    ZSTD_compressBlock_lazy_generic(
3080        ms,
3081        seqStore,
3082        rep,
3083        src,
3084        srcSize,
3085        search_hashChain,
3086        1,
3087        ZSTD_dedicatedDictSearch,
3088    )
3089}
3090pub unsafe fn ZSTD_compressBlock_lazy_row(
3091    ms: &mut ZSTD_MatchState_t,
3092    seqStore: &mut SeqStore_t,
3093    rep: *mut u32,
3094    src: *const core::ffi::c_void,
3095    srcSize: size_t,
3096) -> size_t {
3097    ZSTD_compressBlock_lazy_generic(
3098        ms,
3099        seqStore,
3100        rep,
3101        src,
3102        srcSize,
3103        search_rowHash,
3104        1,
3105        ZSTD_noDict,
3106    )
3107}
3108pub unsafe fn ZSTD_compressBlock_lazy_dictMatchState_row(
3109    ms: &mut ZSTD_MatchState_t,
3110    seqStore: &mut SeqStore_t,
3111    rep: *mut u32,
3112    src: *const core::ffi::c_void,
3113    srcSize: size_t,
3114) -> size_t {
3115    ZSTD_compressBlock_lazy_generic(
3116        ms,
3117        seqStore,
3118        rep,
3119        src,
3120        srcSize,
3121        search_rowHash,
3122        1,
3123        ZSTD_dictMatchState,
3124    )
3125}
3126pub unsafe fn ZSTD_compressBlock_lazy_dedicatedDictSearch_row(
3127    ms: &mut ZSTD_MatchState_t,
3128    seqStore: &mut SeqStore_t,
3129    rep: *mut u32,
3130    src: *const core::ffi::c_void,
3131    srcSize: size_t,
3132) -> size_t {
3133    ZSTD_compressBlock_lazy_generic(
3134        ms,
3135        seqStore,
3136        rep,
3137        src,
3138        srcSize,
3139        search_rowHash,
3140        1,
3141        ZSTD_dedicatedDictSearch,
3142    )
3143}
3144pub unsafe fn ZSTD_compressBlock_lazy2(
3145    ms: &mut ZSTD_MatchState_t,
3146    seqStore: &mut SeqStore_t,
3147    rep: *mut u32,
3148    src: *const core::ffi::c_void,
3149    srcSize: size_t,
3150) -> size_t {
3151    ZSTD_compressBlock_lazy_generic(
3152        ms,
3153        seqStore,
3154        rep,
3155        src,
3156        srcSize,
3157        search_hashChain,
3158        2,
3159        ZSTD_noDict,
3160    )
3161}
3162pub unsafe fn ZSTD_compressBlock_lazy2_dictMatchState(
3163    ms: &mut ZSTD_MatchState_t,
3164    seqStore: &mut SeqStore_t,
3165    rep: *mut u32,
3166    src: *const core::ffi::c_void,
3167    srcSize: size_t,
3168) -> size_t {
3169    ZSTD_compressBlock_lazy_generic(
3170        ms,
3171        seqStore,
3172        rep,
3173        src,
3174        srcSize,
3175        search_hashChain,
3176        2,
3177        ZSTD_dictMatchState,
3178    )
3179}
3180pub unsafe fn ZSTD_compressBlock_lazy2_dedicatedDictSearch(
3181    ms: &mut ZSTD_MatchState_t,
3182    seqStore: &mut SeqStore_t,
3183    rep: *mut u32,
3184    src: *const core::ffi::c_void,
3185    srcSize: size_t,
3186) -> size_t {
3187    ZSTD_compressBlock_lazy_generic(
3188        ms,
3189        seqStore,
3190        rep,
3191        src,
3192        srcSize,
3193        search_hashChain,
3194        2,
3195        ZSTD_dedicatedDictSearch,
3196    )
3197}
3198pub unsafe fn ZSTD_compressBlock_lazy2_row(
3199    ms: &mut ZSTD_MatchState_t,
3200    seqStore: &mut SeqStore_t,
3201    rep: *mut u32,
3202    src: *const core::ffi::c_void,
3203    srcSize: size_t,
3204) -> size_t {
3205    ZSTD_compressBlock_lazy_generic(
3206        ms,
3207        seqStore,
3208        rep,
3209        src,
3210        srcSize,
3211        search_rowHash,
3212        2,
3213        ZSTD_noDict,
3214    )
3215}
3216pub unsafe fn ZSTD_compressBlock_lazy2_dictMatchState_row(
3217    ms: &mut ZSTD_MatchState_t,
3218    seqStore: &mut SeqStore_t,
3219    rep: *mut u32,
3220    src: *const core::ffi::c_void,
3221    srcSize: size_t,
3222) -> size_t {
3223    ZSTD_compressBlock_lazy_generic(
3224        ms,
3225        seqStore,
3226        rep,
3227        src,
3228        srcSize,
3229        search_rowHash,
3230        2,
3231        ZSTD_dictMatchState,
3232    )
3233}
3234pub unsafe fn ZSTD_compressBlock_lazy2_dedicatedDictSearch_row(
3235    ms: &mut ZSTD_MatchState_t,
3236    seqStore: &mut SeqStore_t,
3237    rep: *mut u32,
3238    src: *const core::ffi::c_void,
3239    srcSize: size_t,
3240) -> size_t {
3241    ZSTD_compressBlock_lazy_generic(
3242        ms,
3243        seqStore,
3244        rep,
3245        src,
3246        srcSize,
3247        search_rowHash,
3248        2,
3249        ZSTD_dedicatedDictSearch,
3250    )
3251}
3252pub unsafe fn ZSTD_compressBlock_btlazy2(
3253    ms: &mut ZSTD_MatchState_t,
3254    seqStore: &mut SeqStore_t,
3255    rep: *mut u32,
3256    src: *const core::ffi::c_void,
3257    srcSize: size_t,
3258) -> size_t {
3259    ZSTD_compressBlock_lazy_generic(
3260        ms,
3261        seqStore,
3262        rep,
3263        src,
3264        srcSize,
3265        search_binaryTree,
3266        2,
3267        ZSTD_noDict,
3268    )
3269}
3270pub unsafe fn ZSTD_compressBlock_btlazy2_dictMatchState(
3271    ms: &mut ZSTD_MatchState_t,
3272    seqStore: &mut SeqStore_t,
3273    rep: *mut u32,
3274    src: *const core::ffi::c_void,
3275    srcSize: size_t,
3276) -> size_t {
3277    ZSTD_compressBlock_lazy_generic(
3278        ms,
3279        seqStore,
3280        rep,
3281        src,
3282        srcSize,
3283        search_binaryTree,
3284        2,
3285        ZSTD_dictMatchState,
3286    )
3287}
3288#[inline(always)]
3289unsafe fn ZSTD_compressBlock_lazy_extDict_generic(
3290    ms: &mut ZSTD_MatchState_t,
3291    seqStore: &mut SeqStore_t,
3292    rep: *mut u32,
3293    src: *const core::ffi::c_void,
3294    srcSize: size_t,
3295    searchMethod: searchMethod_e,
3296    depth: u32,
3297) -> size_t {
3298    let istart = src as *const u8;
3299    let mut ip = istart;
3300    let mut anchor = istart;
3301    let iend = istart.add(srcSize);
3302    let ilimit = if searchMethod as core::ffi::c_uint
3303        == search_rowHash as core::ffi::c_int as core::ffi::c_uint
3304    {
3305        iend.sub(8).offset(-(ZSTD_ROW_HASH_CACHE_SIZE as isize))
3306    } else {
3307        iend.sub(8)
3308    };
3309    let base = ms.window.base;
3310    let dictLimit = ms.window.dictLimit;
3311    let prefixStart = base.offset(dictLimit as isize);
3312    let dictBase = ms.window.dictBase;
3313    let dictEnd = dictBase.offset(dictLimit as isize);
3314    let dictStart = dictBase.offset(ms.window.lowLimit as isize);
3315    let windowLog = ms.cParams.windowLog;
3316    let mls = if 4
3317        > (if ms.cParams.minMatch < 6 {
3318            ms.cParams.minMatch
3319        } else {
3320            6
3321        }) {
3322        4
3323    } else if ms.cParams.minMatch < 6 {
3324        ms.cParams.minMatch
3325    } else {
3326        6
3327    };
3328    let rowLog = if 4
3329        > (if ms.cParams.searchLog < 6 {
3330            ms.cParams.searchLog
3331        } else {
3332            6
3333        }) {
3334        4
3335    } else if ms.cParams.searchLog < 6 {
3336        ms.cParams.searchLog
3337    } else {
3338        6
3339    };
3340    let mut offset_1 = *rep;
3341    let mut offset_2 = *rep.add(1);
3342    ms.lazySkipping = 0;
3343    ip = ip.offset((ip == prefixStart) as core::ffi::c_int as isize);
3344    if searchMethod as core::ffi::c_uint == search_rowHash as core::ffi::c_int as core::ffi::c_uint
3345    {
3346        ZSTD_row_fillHashCache(ms, base, rowLog, mls, ms.nextToUpdate, ilimit);
3347    }
3348
3349    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3350    asm!(".p2align 5", options(preserves_flags, att_syntax));
3351
3352    let mut current_block_61: u64;
3353    while ip < ilimit {
3354        let mut matchLength = 0;
3355        let mut offBase = REPCODE1_TO_OFFBASE as size_t;
3356        let mut start = ip.add(1);
3357        let mut curr = ip.offset_from(base) as core::ffi::c_long as u32;
3358        let windowLow = ZSTD_getLowestMatchIndex(ms, curr.wrapping_add(1), windowLog);
3359        let repIndex = curr.wrapping_add(1).wrapping_sub(offset_1);
3360        let repBase = if repIndex < dictLimit { dictBase } else { base };
3361        let repMatch = repBase.offset(repIndex as isize);
3362        if ZSTD_index_overlap_check(dictLimit, repIndex)
3363            & (offset_1 <= curr.wrapping_add(1).wrapping_sub(windowLow)) as core::ffi::c_int
3364            != 0
3365        {
3366            if MEM_read32(ip.add(1) as *const core::ffi::c_void)
3367                == MEM_read32(repMatch as *const core::ffi::c_void)
3368            {
3369                let repEnd = if repIndex < dictLimit { dictEnd } else { iend };
3370                matchLength = (ZSTD_count_2segments(
3371                    ip.add(1).add(4),
3372                    repMatch.add(4),
3373                    iend,
3374                    repEnd,
3375                    prefixStart,
3376                ))
3377                .wrapping_add(4);
3378                if depth == 0 {
3379                    current_block_61 = 10962704168502628720;
3380                } else {
3381                    current_block_61 = 12147880666119273379;
3382                }
3383            } else {
3384                current_block_61 = 12147880666119273379;
3385            }
3386        } else {
3387            current_block_61 = 12147880666119273379;
3388        }
3389        if current_block_61 == 12147880666119273379 {
3390            let mut ofbCandidate = 999999999;
3391            let ml2 = ZSTD_searchMax(
3392                ms,
3393                ip,
3394                iend,
3395                &mut ofbCandidate,
3396                mls,
3397                rowLog,
3398                searchMethod,
3399                ZSTD_extDict,
3400            );
3401            if ml2 > matchLength {
3402                matchLength = ml2;
3403                start = ip;
3404                offBase = ofbCandidate;
3405            }
3406            if matchLength < 4 {
3407                let step = ip.offset_from_unsigned(anchor) >> kSearchStrength;
3408                ip = ip.add(step.wrapping_add(1));
3409                ms.lazySkipping = (step > kLazySkippingStep as size_t) as core::ffi::c_int;
3410                continue;
3411            } else {
3412                if depth >= 1 {
3413                    while ip < ilimit {
3414                        ip = ip.add(1);
3415                        curr = curr.wrapping_add(1);
3416                        if offBase != 0 {
3417                            let windowLow_0 = ZSTD_getLowestMatchIndex(ms, curr, windowLog);
3418                            let repIndex_0 = curr.wrapping_sub(offset_1);
3419                            let repBase_0 = if repIndex_0 < dictLimit {
3420                                dictBase
3421                            } else {
3422                                base
3423                            };
3424                            let repMatch_0 = repBase_0.offset(repIndex_0 as isize);
3425                            if ZSTD_index_overlap_check(dictLimit, repIndex_0)
3426                                & (offset_1 <= curr.wrapping_sub(windowLow_0)) as core::ffi::c_int
3427                                != 0
3428                                && MEM_read32(ip as *const core::ffi::c_void)
3429                                    == MEM_read32(repMatch_0 as *const core::ffi::c_void)
3430                            {
3431                                let repEnd_0 = if repIndex_0 < dictLimit {
3432                                    dictEnd
3433                                } else {
3434                                    iend
3435                                };
3436                                let repLength = (ZSTD_count_2segments(
3437                                    ip.add(4),
3438                                    repMatch_0.add(4),
3439                                    iend,
3440                                    repEnd_0,
3441                                    prefixStart,
3442                                ))
3443                                .wrapping_add(4);
3444                                let gain2 = (repLength * 3) as core::ffi::c_int;
3445                                let gain1 = (matchLength * 3)
3446                                    .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
3447                                    .wrapping_add(1)
3448                                    as core::ffi::c_int;
3449                                if repLength >= 4 && gain2 > gain1 {
3450                                    matchLength = repLength;
3451                                    offBase = REPCODE1_TO_OFFBASE as size_t;
3452                                    start = ip;
3453                                }
3454                            }
3455                        }
3456                        let mut ofbCandidate_0 = 999999999;
3457                        let ml2_0 = ZSTD_searchMax(
3458                            ms,
3459                            ip,
3460                            iend,
3461                            &mut ofbCandidate_0,
3462                            mls,
3463                            rowLog,
3464                            searchMethod,
3465                            ZSTD_extDict,
3466                        );
3467                        let gain2_0 = (ml2_0 * 4)
3468                            .wrapping_sub(ZSTD_highbit32(ofbCandidate_0 as u32) as size_t)
3469                            as core::ffi::c_int;
3470                        let gain1_0 = (matchLength * 4)
3471                            .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
3472                            .wrapping_add(4)
3473                            as core::ffi::c_int;
3474                        if ml2_0 >= 4 && gain2_0 > gain1_0 {
3475                            matchLength = ml2_0;
3476                            offBase = ofbCandidate_0;
3477                            start = ip;
3478                        } else {
3479                            if !(depth == 2 && ip < ilimit) {
3480                                break;
3481                            }
3482                            ip = ip.add(1);
3483                            curr = curr.wrapping_add(1);
3484                            if offBase != 0 {
3485                                let windowLow_1 = ZSTD_getLowestMatchIndex(ms, curr, windowLog);
3486                                let repIndex_1 = curr.wrapping_sub(offset_1);
3487                                let repBase_1 = if repIndex_1 < dictLimit {
3488                                    dictBase
3489                                } else {
3490                                    base
3491                                };
3492                                let repMatch_1 = repBase_1.offset(repIndex_1 as isize);
3493                                if ZSTD_index_overlap_check(dictLimit, repIndex_1)
3494                                    & (offset_1 <= curr.wrapping_sub(windowLow_1))
3495                                        as core::ffi::c_int
3496                                    != 0
3497                                    && MEM_read32(ip as *const core::ffi::c_void)
3498                                        == MEM_read32(repMatch_1 as *const core::ffi::c_void)
3499                                {
3500                                    let repEnd_1 = if repIndex_1 < dictLimit {
3501                                        dictEnd
3502                                    } else {
3503                                        iend
3504                                    };
3505                                    let repLength_0 = (ZSTD_count_2segments(
3506                                        ip.add(4),
3507                                        repMatch_1.add(4),
3508                                        iend,
3509                                        repEnd_1,
3510                                        prefixStart,
3511                                    ))
3512                                    .wrapping_add(4);
3513                                    let gain2_1 = (repLength_0 * 4) as core::ffi::c_int;
3514                                    let gain1_1 = (matchLength * 4)
3515                                        .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
3516                                        .wrapping_add(1)
3517                                        as core::ffi::c_int;
3518                                    if repLength_0 >= 4 && gain2_1 > gain1_1 {
3519                                        matchLength = repLength_0;
3520                                        offBase = REPCODE1_TO_OFFBASE as size_t;
3521                                        start = ip;
3522                                    }
3523                                }
3524                            }
3525                            let mut ofbCandidate_1 = 999999999;
3526                            let ml2_1 = ZSTD_searchMax(
3527                                ms,
3528                                ip,
3529                                iend,
3530                                &mut ofbCandidate_1,
3531                                mls,
3532                                rowLog,
3533                                searchMethod,
3534                                ZSTD_extDict,
3535                            );
3536                            let gain2_2 = (ml2_1 * 4)
3537                                .wrapping_sub(ZSTD_highbit32(ofbCandidate_1 as u32) as size_t)
3538                                as core::ffi::c_int;
3539                            let gain1_2 = (matchLength * 4)
3540                                .wrapping_sub(ZSTD_highbit32(offBase as u32) as size_t)
3541                                .wrapping_add(7)
3542                                as core::ffi::c_int;
3543                            if !(ml2_1 >= 4 && gain2_2 > gain1_2) {
3544                                break;
3545                            }
3546                            matchLength = ml2_1;
3547                            offBase = ofbCandidate_1;
3548                            start = ip;
3549                        }
3550                    }
3551                }
3552                if offBase > ZSTD_REP_NUM as size_t {
3553                    let matchIndex = (start.offset_from_unsigned(base))
3554                        .wrapping_sub(offBase.wrapping_sub(ZSTD_REP_NUM as size_t))
3555                        as u32;
3556                    let mut match_0 = if matchIndex < dictLimit {
3557                        dictBase.offset(matchIndex as isize)
3558                    } else {
3559                        base.offset(matchIndex as isize)
3560                    };
3561                    let mStart = if matchIndex < dictLimit {
3562                        dictStart
3563                    } else {
3564                        prefixStart
3565                    };
3566                    while start > anchor
3567                        && match_0 > mStart
3568                        && *start.sub(1) as core::ffi::c_int == *match_0.sub(1) as core::ffi::c_int
3569                    {
3570                        start = start.sub(1);
3571                        match_0 = match_0.sub(1);
3572                        matchLength = matchLength.wrapping_add(1);
3573                    }
3574                    offset_2 = offset_1;
3575                    offset_1 = offBase.wrapping_sub(ZSTD_REP_NUM as size_t) as u32;
3576                }
3577            }
3578        }
3579        let litLength = start.offset_from_unsigned(anchor);
3580        ZSTD_storeSeq(
3581            seqStore,
3582            litLength,
3583            anchor,
3584            iend,
3585            offBase as u32,
3586            matchLength,
3587        );
3588        ip = start.add(matchLength);
3589        anchor = ip;
3590        if ms.lazySkipping != 0 {
3591            if searchMethod as core::ffi::c_uint
3592                == search_rowHash as core::ffi::c_int as core::ffi::c_uint
3593            {
3594                ZSTD_row_fillHashCache(ms, base, rowLog, mls, ms.nextToUpdate, ilimit);
3595            }
3596            ms.lazySkipping = 0;
3597        }
3598        while ip <= ilimit {
3599            let repCurrent = ip.offset_from(base) as core::ffi::c_long as u32;
3600            let windowLow_2 = ZSTD_getLowestMatchIndex(ms, repCurrent, windowLog);
3601            let repIndex_2 = repCurrent.wrapping_sub(offset_2);
3602            let repBase_2 = if repIndex_2 < dictLimit {
3603                dictBase
3604            } else {
3605                base
3606            };
3607            let repMatch_2 = repBase_2.offset(repIndex_2 as isize);
3608            if ZSTD_index_overlap_check(dictLimit, repIndex_2)
3609                & (offset_2 <= repCurrent.wrapping_sub(windowLow_2)) as core::ffi::c_int
3610                == 0
3611            {
3612                break;
3613            }
3614            if MEM_read32(ip as *const core::ffi::c_void)
3615                != MEM_read32(repMatch_2 as *const core::ffi::c_void)
3616            {
3617                break;
3618            }
3619            let repEnd_2 = if repIndex_2 < dictLimit {
3620                dictEnd
3621            } else {
3622                iend
3623            };
3624            matchLength =
3625                (ZSTD_count_2segments(ip.add(4), repMatch_2.add(4), iend, repEnd_2, prefixStart))
3626                    .wrapping_add(4);
3627            offBase = offset_2 as size_t;
3628            offset_2 = offset_1;
3629            offset_1 = offBase as u32;
3630            ZSTD_storeSeq(
3631                seqStore,
3632                0,
3633                anchor,
3634                iend,
3635                REPCODE1_TO_OFFBASE as u32,
3636                matchLength,
3637            );
3638            ip = ip.add(matchLength);
3639            anchor = ip;
3640        }
3641    }
3642    *rep = offset_1;
3643    *rep.add(1) = offset_2;
3644    iend.offset_from_unsigned(anchor)
3645}
3646pub unsafe fn ZSTD_compressBlock_greedy_extDict(
3647    ms: &mut ZSTD_MatchState_t,
3648    seqStore: &mut SeqStore_t,
3649    rep: *mut u32,
3650    src: *const core::ffi::c_void,
3651    srcSize: size_t,
3652) -> size_t {
3653    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_hashChain, 0)
3654}
3655pub unsafe fn ZSTD_compressBlock_greedy_extDict_row(
3656    ms: &mut ZSTD_MatchState_t,
3657    seqStore: &mut SeqStore_t,
3658    rep: *mut u32,
3659    src: *const core::ffi::c_void,
3660    srcSize: size_t,
3661) -> size_t {
3662    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_rowHash, 0)
3663}
3664pub unsafe fn ZSTD_compressBlock_lazy_extDict(
3665    ms: &mut ZSTD_MatchState_t,
3666    seqStore: &mut SeqStore_t,
3667    rep: *mut u32,
3668    src: *const core::ffi::c_void,
3669    srcSize: size_t,
3670) -> size_t {
3671    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_hashChain, 1)
3672}
3673pub unsafe fn ZSTD_compressBlock_lazy_extDict_row(
3674    ms: &mut ZSTD_MatchState_t,
3675    seqStore: &mut SeqStore_t,
3676    rep: *mut u32,
3677    src: *const core::ffi::c_void,
3678    srcSize: size_t,
3679) -> size_t {
3680    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_rowHash, 1)
3681}
3682pub unsafe fn ZSTD_compressBlock_lazy2_extDict(
3683    ms: &mut ZSTD_MatchState_t,
3684    seqStore: &mut SeqStore_t,
3685    rep: *mut u32,
3686    src: *const core::ffi::c_void,
3687    srcSize: size_t,
3688) -> size_t {
3689    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_hashChain, 2)
3690}
3691pub unsafe fn ZSTD_compressBlock_lazy2_extDict_row(
3692    ms: &mut ZSTD_MatchState_t,
3693    seqStore: &mut SeqStore_t,
3694    rep: *mut u32,
3695    src: *const core::ffi::c_void,
3696    srcSize: size_t,
3697) -> size_t {
3698    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_rowHash, 2)
3699}
3700pub unsafe fn ZSTD_compressBlock_btlazy2_extDict(
3701    ms: &mut ZSTD_MatchState_t,
3702    seqStore: &mut SeqStore_t,
3703    rep: *mut u32,
3704    src: *const core::ffi::c_void,
3705    srcSize: size_t,
3706) -> size_t {
3707    ZSTD_compressBlock_lazy_extDict_generic(ms, seqStore, rep, src, srcSize, search_binaryTree, 2)
3708}