1pub type ZSTD_longLengthType_e = core::ffi::c_uint;
2pub const ZSTD_llt_matchLength: ZSTD_longLengthType_e = 2;
3pub const ZSTD_llt_literalLength: ZSTD_longLengthType_e = 1;
4pub const ZSTD_llt_none: ZSTD_longLengthType_e = 0;
5#[repr(C)]
6pub struct optState_t {
7 pub litFreq: *mut core::ffi::c_uint,
8 pub litLengthFreq: *mut core::ffi::c_uint,
9 pub matchLengthFreq: *mut core::ffi::c_uint,
10 pub offCodeFreq: *mut core::ffi::c_uint,
11 pub matchTable: *mut ZSTD_match_t,
12 pub priceTable: *mut ZSTD_optimal_t,
13 pub litSum: u32,
14 pub litLengthSum: u32,
15 pub matchLengthSum: u32,
16 pub offCodeSum: u32,
17 pub litSumBasePrice: u32,
18 pub litLengthSumBasePrice: u32,
19 pub matchLengthSumBasePrice: u32,
20 pub offCodeSumBasePrice: u32,
21 pub priceType: ZSTD_OptPrice_e,
22 pub symbolCosts: *const ZSTD_entropyCTables_t,
23 pub literalCompressionMode: ZSTD_ParamSwitch_e,
24}
25pub type ZSTD_ParamSwitch_e = core::ffi::c_uint;
26pub const ZSTD_ps_disable: ZSTD_ParamSwitch_e = 2;
27pub const ZSTD_ps_enable: ZSTD_ParamSwitch_e = 1;
28pub const ZSTD_ps_auto: ZSTD_ParamSwitch_e = 0;
29#[repr(C)]
30pub struct ZSTD_entropyCTables_t {
31 pub huf: ZSTD_hufCTables_t,
32 pub fse: ZSTD_fseCTables_t,
33}
34#[repr(C)]
35pub struct ZSTD_fseCTables_t {
36 pub offcodeCTable: [FSE_CTable; 193],
37 pub matchlengthCTable: [FSE_CTable; 363],
38 pub litlengthCTable: [FSE_CTable; 329],
39 pub offcode_repeatMode: FSE_repeat,
40 pub matchlength_repeatMode: FSE_repeat,
41 pub litlength_repeatMode: FSE_repeat,
42}
43#[repr(C)]
44pub struct ZSTD_hufCTables_t {
45 pub CTable: [HUF_CElt; 257],
46 pub repeatMode: HUF_repeat,
47}
48pub type ZSTD_OptPrice_e = core::ffi::c_uint;
49pub const zop_predef: ZSTD_OptPrice_e = 1;
50pub const zop_dynamic: ZSTD_OptPrice_e = 0;
51#[repr(C)]
52pub struct ZSTD_window_t {
53 pub nextSrc: *const u8,
54 pub base: *const u8,
55 pub dictBase: *const u8,
56 pub dictLimit: u32,
57 pub lowLimit: u32,
58 pub nbOverflowCorrections: u32,
59}
60pub type ZSTD_dictTableLoadMethod_e = core::ffi::c_uint;
61pub const ZSTD_dtlm_full: ZSTD_dictTableLoadMethod_e = 1;
62pub const ZSTD_dtlm_fast: ZSTD_dictTableLoadMethod_e = 0;
63pub type ZSTD_tableFillPurpose_e = core::ffi::c_uint;
64pub const ZSTD_tfp_forCDict: ZSTD_tableFillPurpose_e = 1;
65pub const ZSTD_tfp_forCCtx: ZSTD_tableFillPurpose_e = 0;
66pub const CACHELINE_SIZE: core::ffi::c_int = 64;
67
68use libc::size_t;
69
70use crate::lib::common::fse::{FSE_CTable, FSE_repeat};
71use crate::lib::common::huf::{HUF_CElt, HUF_repeat};
72use crate::lib::common::mem::{
73 MEM_64bits, MEM_isLittleEndian, MEM_read16, MEM_read32, MEM_read64, MEM_readLE32, MEM_readLE64,
74 MEM_readST,
75};
76use crate::lib::common::zstd_internal::{
77 Overlap, ZSTD_copy16, ZSTD_wildcopy, MINMATCH, WILDCOPY_OVERLENGTH, ZSTD_REP_NUM,
78};
79use crate::lib::compress::zstd_compress::{
80 SeqStore_t, ZSTD_MatchState_t, ZSTD_match_t, ZSTD_optimal_t,
81};
82use crate::lib::zstd::*;
83pub const kSearchStrength: core::ffi::c_int = 8;
84pub const HASH_READ_SIZE: core::ffi::c_int = 8;
85unsafe fn ZSTD_safecopyLiterals(
86 mut op: *mut u8,
87 mut ip: *const u8,
88 iend: *const u8,
89 ilimit_w: *const u8,
90) {
91 if ip <= ilimit_w {
92 ZSTD_wildcopy(
93 op as *mut core::ffi::c_void,
94 ip as *const core::ffi::c_void,
95 ilimit_w.offset_from(ip) as size_t,
96 Overlap::NoOverlap,
97 );
98 op = op.offset(ilimit_w.offset_from(ip) as core::ffi::c_long as isize);
99 ip = ilimit_w;
100 }
101 while ip < iend {
102 let fresh0 = ip;
103 ip = ip.offset(1);
104 let fresh1 = op;
105 op = op.offset(1);
106 *fresh1 = *fresh0;
107 }
108}
109pub const REPCODE1_TO_OFFBASE: core::ffi::c_int = 1;
110#[inline(always)]
111unsafe fn ZSTD_storeSeqOnly(
112 seqStorePtr: *mut SeqStore_t,
113 litLength: size_t,
114 offBase: u32,
115 matchLength: size_t,
116) {
117 if (litLength > 0xffff as core::ffi::c_int as size_t) as core::ffi::c_int as core::ffi::c_long
118 != 0
119 {
120 (*seqStorePtr).longLengthType = ZSTD_llt_literalLength;
121 (*seqStorePtr).longLengthPos = ((*seqStorePtr).sequences)
122 .offset_from((*seqStorePtr).sequencesStart)
123 as core::ffi::c_long as u32;
124 }
125 (*((*seqStorePtr).sequences).offset(0)).litLength = litLength as u16;
126 (*((*seqStorePtr).sequences).offset(0)).offBase = offBase;
127 let mlBase = matchLength.wrapping_sub(MINMATCH as size_t);
128 if (mlBase > 0xffff as core::ffi::c_int as size_t) as core::ffi::c_int as core::ffi::c_long != 0
129 {
130 (*seqStorePtr).longLengthType = ZSTD_llt_matchLength;
131 (*seqStorePtr).longLengthPos = ((*seqStorePtr).sequences)
132 .offset_from((*seqStorePtr).sequencesStart)
133 as core::ffi::c_long as u32;
134 }
135 (*((*seqStorePtr).sequences).offset(0)).mlBase = mlBase as u16;
136 (*seqStorePtr).sequences = ((*seqStorePtr).sequences).offset(1);
137 (*seqStorePtr).sequences;
138}
139#[inline(always)]
140unsafe fn ZSTD_storeSeq(
141 seqStorePtr: *mut SeqStore_t,
142 litLength: size_t,
143 literals: *const u8,
144 litLimit: *const u8,
145 offBase: u32,
146 matchLength: size_t,
147) {
148 let litLimit_w = litLimit.sub(WILDCOPY_OVERLENGTH);
149 let litEnd = literals.add(litLength);
150 if litEnd <= litLimit_w {
151 ZSTD_copy16(
152 (*seqStorePtr).lit as *mut core::ffi::c_void,
153 literals as *const core::ffi::c_void,
154 );
155 if litLength > 16 {
156 ZSTD_wildcopy(
157 ((*seqStorePtr).lit).offset(16) as *mut core::ffi::c_void,
158 literals.offset(16) as *const core::ffi::c_void,
159 litLength.wrapping_sub(16),
160 Overlap::NoOverlap,
161 );
162 }
163 } else {
164 ZSTD_safecopyLiterals((*seqStorePtr).lit, literals, litEnd, litLimit_w);
165 }
166 (*seqStorePtr).lit = ((*seqStorePtr).lit).add(litLength);
167 ZSTD_storeSeqOnly(seqStorePtr, litLength, offBase, matchLength);
168}
169#[inline]
170unsafe fn ZSTD_count(mut pIn: *const u8, mut pMatch: *const u8, pInLimit: *const u8) -> size_t {
171 let pStart = pIn;
172 let pInLoopLimit = pInLimit.offset(
173 -((::core::mem::size_of::<size_t>() as core::ffi::c_ulong).wrapping_sub(1) as isize),
174 );
175 if pIn < pInLoopLimit {
176 let diff = MEM_readST(pMatch as *const core::ffi::c_void)
177 ^ MEM_readST(pIn as *const core::ffi::c_void);
178 if diff != 0 {
179 return ZSTD_NbCommonBytes(diff) as size_t;
180 }
181 pIn = pIn.offset(::core::mem::size_of::<size_t>() as core::ffi::c_ulong as isize);
182 pMatch = pMatch.offset(::core::mem::size_of::<size_t>() as core::ffi::c_ulong as isize);
183 while pIn < pInLoopLimit {
184 let diff_0 = MEM_readST(pMatch as *const core::ffi::c_void)
185 ^ MEM_readST(pIn as *const core::ffi::c_void);
186 if diff_0 == 0 {
187 pIn = pIn.offset(::core::mem::size_of::<size_t>() as core::ffi::c_ulong as isize);
188 pMatch =
189 pMatch.offset(::core::mem::size_of::<size_t>() as core::ffi::c_ulong as isize);
190 } else {
191 pIn = pIn.offset(ZSTD_NbCommonBytes(diff_0) as isize);
192 return pIn.offset_from(pStart) as size_t;
193 }
194 }
195 }
196 if MEM_64bits() != 0
197 && pIn < pInLimit.offset(-(3))
198 && MEM_read32(pMatch as *const core::ffi::c_void)
199 == MEM_read32(pIn as *const core::ffi::c_void)
200 {
201 pIn = pIn.offset(4);
202 pMatch = pMatch.offset(4);
203 }
204 if pIn < pInLimit.offset(-(1))
205 && MEM_read16(pMatch as *const core::ffi::c_void) as core::ffi::c_int
206 == MEM_read16(pIn as *const core::ffi::c_void) as core::ffi::c_int
207 {
208 pIn = pIn.offset(2);
209 pMatch = pMatch.offset(2);
210 }
211 if pIn < pInLimit && *pMatch as core::ffi::c_int == *pIn as core::ffi::c_int {
212 pIn = pIn.offset(1);
213 }
214 pIn.offset_from(pStart) as size_t
215}
216#[inline]
217unsafe fn ZSTD_count_2segments(
218 ip: *const u8,
219 match_0: *const u8,
220 iEnd: *const u8,
221 mEnd: *const u8,
222 iStart: *const u8,
223) -> size_t {
224 let vEnd = if ip.offset(mEnd.offset_from(match_0) as core::ffi::c_long as isize) < iEnd {
225 ip.offset(mEnd.offset_from(match_0) as core::ffi::c_long as isize)
226 } else {
227 iEnd
228 };
229 let matchLength = ZSTD_count(ip, match_0, vEnd);
230 if match_0.add(matchLength) != mEnd {
231 return matchLength;
232 }
233 matchLength.wrapping_add(ZSTD_count(ip.add(matchLength), iStart, iEnd))
234}
235static prime4bytes: u32 = 2654435761;
236unsafe fn ZSTD_hash4(u: u32, h: u32, s: u32) -> u32 {
237 ((u.wrapping_mul(prime4bytes)) ^ s) >> 32u32.wrapping_sub(h)
238}
239unsafe fn ZSTD_hash4Ptr(ptr: *const core::ffi::c_void, h: u32) -> size_t {
240 ZSTD_hash4(MEM_readLE32(ptr), h, 0) as size_t
241}
242static prime5bytes: u64 = 889523592379;
243unsafe fn ZSTD_hash5(u: u64, h: u32, s: u64) -> size_t {
244 ((((u << (64 - 40)) * prime5bytes) ^ s) >> 64u32.wrapping_sub(h)) as size_t
245}
246unsafe fn ZSTD_hash5Ptr(p: *const core::ffi::c_void, h: u32) -> size_t {
247 ZSTD_hash5(MEM_readLE64(p), h, 0)
248}
249static prime6bytes: u64 = 227718039650203;
250unsafe fn ZSTD_hash6(u: u64, h: u32, s: u64) -> size_t {
251 ((((u << (64 - 48)) * prime6bytes) ^ s) >> 64u32.wrapping_sub(h)) as size_t
252}
253unsafe fn ZSTD_hash6Ptr(p: *const core::ffi::c_void, h: u32) -> size_t {
254 ZSTD_hash6(MEM_readLE64(p), h, 0)
255}
256static prime7bytes: u64 = 58295818150454627;
257unsafe fn ZSTD_hash7(u: u64, h: u32, s: u64) -> size_t {
258 ((((u << (64 - 56)) * prime7bytes) ^ s) >> (64u32).wrapping_sub(h)) as size_t
259}
260unsafe fn ZSTD_hash7Ptr(p: *const core::ffi::c_void, h: u32) -> size_t {
261 ZSTD_hash7(MEM_readLE64(p), h, 0)
262}
263static prime8bytes: u64 = 0xcf1bbcdcb7a56463 as core::ffi::c_ulonglong;
264unsafe fn ZSTD_hash8(u: u64, h: u32, s: u64) -> size_t {
265 (((u.wrapping_mul(prime8bytes)) ^ s) >> 64u32.wrapping_sub(h)) as size_t
266}
267unsafe fn ZSTD_hash8Ptr(p: *const core::ffi::c_void, h: u32) -> size_t {
268 ZSTD_hash8(MEM_readLE64(p), h, 0)
269}
270#[inline(always)]
271unsafe fn ZSTD_hashPtr(p: *const core::ffi::c_void, hBits: u32, mls: u32) -> size_t {
272 match mls {
273 5 => ZSTD_hash5Ptr(p, hBits),
274 6 => ZSTD_hash6Ptr(p, hBits),
275 7 => ZSTD_hash7Ptr(p, hBits),
276 8 => ZSTD_hash8Ptr(p, hBits),
277 4 | _ => ZSTD_hash4Ptr(p, hBits),
278 }
279}
280#[inline]
281unsafe fn ZSTD_getLowestMatchIndex(
282 ms: *const ZSTD_MatchState_t,
283 curr: u32,
284 windowLog: core::ffi::c_uint,
285) -> u32 {
286 let maxDistance = (1) << windowLog;
287 let lowestValid = (*ms).window.lowLimit;
288 let withinWindow = if curr.wrapping_sub(lowestValid) > maxDistance {
289 curr.wrapping_sub(maxDistance)
290 } else {
291 lowestValid
292 };
293 let isDictionary = ((*ms).loadedDictEnd != 0) as core::ffi::c_int as u32;
294
295 if isDictionary != 0 {
296 lowestValid
297 } else {
298 withinWindow
299 }
300}
301#[inline]
302unsafe fn ZSTD_getLowestPrefixIndex(
303 ms: *const ZSTD_MatchState_t,
304 curr: u32,
305 windowLog: core::ffi::c_uint,
306) -> u32 {
307 let maxDistance = (1) << windowLog;
308 let lowestValid = (*ms).window.dictLimit;
309 let withinWindow = if curr.wrapping_sub(lowestValid) > maxDistance {
310 curr.wrapping_sub(maxDistance)
311 } else {
312 lowestValid
313 };
314 let isDictionary = ((*ms).loadedDictEnd != 0) as core::ffi::c_int as u32;
315
316 if isDictionary != 0 {
317 lowestValid
318 } else {
319 withinWindow
320 }
321}
322#[inline]
323unsafe fn ZSTD_index_overlap_check(prefixLowestIndex: u32, repIndex: u32) -> core::ffi::c_int {
324 (prefixLowestIndex.wrapping_sub(1).wrapping_sub(repIndex) >= 3) as core::ffi::c_int
325}
326pub const ZSTD_SHORT_CACHE_TAG_BITS: core::ffi::c_int = 8;
327pub const ZSTD_SHORT_CACHE_TAG_MASK: core::ffi::c_uint =
328 ((1 as core::ffi::c_uint) << ZSTD_SHORT_CACHE_TAG_BITS).wrapping_sub(1);
329#[inline]
330unsafe fn ZSTD_writeTaggedIndex(hashTable: *mut u32, hashAndTag: size_t, index: u32) {
331 let hash = hashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS;
332 let tag = (hashAndTag & ZSTD_SHORT_CACHE_TAG_MASK as size_t) as u32;
333 *hashTable.add(hash) = index << ZSTD_SHORT_CACHE_TAG_BITS | tag;
334}
335#[inline]
336unsafe fn ZSTD_comparePackedTags(packedTag1: size_t, packedTag2: size_t) -> core::ffi::c_int {
337 let tag1 = (packedTag1 & ZSTD_SHORT_CACHE_TAG_MASK as size_t) as u32;
338 let tag2 = (packedTag2 & ZSTD_SHORT_CACHE_TAG_MASK as size_t) as u32;
339 (tag1 == tag2) as core::ffi::c_int
340}
341#[inline]
342unsafe fn ZSTD_countTrailingZeros32(val: u32) -> core::ffi::c_uint {
343 val.trailing_zeros() as i32 as core::ffi::c_uint
344}
345#[inline]
346unsafe fn ZSTD_countLeadingZeros32(val: u32) -> core::ffi::c_uint {
347 val.leading_zeros() as i32 as core::ffi::c_uint
348}
349#[inline]
350unsafe fn ZSTD_countTrailingZeros64(val: u64) -> core::ffi::c_uint {
351 (val as core::ffi::c_ulonglong).trailing_zeros() as i32 as core::ffi::c_uint
352}
353#[inline]
354unsafe fn ZSTD_countLeadingZeros64(val: u64) -> core::ffi::c_uint {
355 (val as core::ffi::c_ulonglong).leading_zeros() as i32 as core::ffi::c_uint
356}
357#[inline]
358unsafe fn ZSTD_NbCommonBytes(val: size_t) -> core::ffi::c_uint {
359 if MEM_isLittleEndian() != 0 {
360 if MEM_64bits() != 0 {
361 ZSTD_countTrailingZeros64(val as u64) >> 3
362 } else {
363 ZSTD_countTrailingZeros32(val as u32) >> 3
364 }
365 } else if MEM_64bits() != 0 {
366 ZSTD_countLeadingZeros64(val as u64) >> 3
367 } else {
368 ZSTD_countLeadingZeros32(val as u32) >> 3
369 }
370}
371unsafe fn ZSTD_fillDoubleHashTableForCDict(
372 ms: *mut ZSTD_MatchState_t,
373 end: *const core::ffi::c_void,
374 dtlm: ZSTD_dictTableLoadMethod_e,
375) {
376 let cParams: *const ZSTD_compressionParameters = &mut (*ms).cParams;
377 let hashLarge = (*ms).hashTable;
378 let hBitsL = ((*cParams).hashLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
379 let mls = (*cParams).minMatch;
380 let hashSmall = (*ms).chainTable;
381 let hBitsS = ((*cParams).chainLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
382 let base = (*ms).window.base;
383 let mut ip = base.offset((*ms).nextToUpdate as isize);
384 let iend = (end as *const u8).offset(-(HASH_READ_SIZE as isize));
385 let fastHashFillStep = 3;
386 while ip.offset(fastHashFillStep as isize).offset(-(1)) <= iend {
387 let curr = ip.offset_from(base) as core::ffi::c_long as u32;
388 let mut i: u32 = 0;
389 i = 0;
390 while i < fastHashFillStep {
391 let smHashAndTag = ZSTD_hashPtr(
392 ip.offset(i as isize) as *const core::ffi::c_void,
393 hBitsS,
394 mls,
395 );
396 let lgHashAndTag =
397 ZSTD_hashPtr(ip.offset(i as isize) as *const core::ffi::c_void, hBitsL, 8);
398 if i == 0 {
399 ZSTD_writeTaggedIndex(hashSmall, smHashAndTag, curr.wrapping_add(i));
400 }
401 if i == 0 || *hashLarge.add(lgHashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS) == 0 {
402 ZSTD_writeTaggedIndex(hashLarge, lgHashAndTag, curr.wrapping_add(i));
403 }
404 if dtlm as core::ffi::c_uint == ZSTD_dtlm_fast as core::ffi::c_int as core::ffi::c_uint
405 {
406 break;
407 }
408 i = i.wrapping_add(1);
409 }
410 ip = ip.offset(fastHashFillStep as isize);
411 }
412}
413unsafe fn ZSTD_fillDoubleHashTableForCCtx(
414 ms: *mut ZSTD_MatchState_t,
415 end: *const core::ffi::c_void,
416 dtlm: ZSTD_dictTableLoadMethod_e,
417) {
418 let cParams: *const ZSTD_compressionParameters = &mut (*ms).cParams;
419 let hashLarge = (*ms).hashTable;
420 let hBitsL = (*cParams).hashLog;
421 let mls = (*cParams).minMatch;
422 let hashSmall = (*ms).chainTable;
423 let hBitsS = (*cParams).chainLog;
424 let base = (*ms).window.base;
425 let mut ip = base.offset((*ms).nextToUpdate as isize);
426 let iend = (end as *const u8).offset(-(HASH_READ_SIZE as isize));
427 let fastHashFillStep = 3;
428 while ip.offset(fastHashFillStep as isize).offset(-(1)) <= iend {
429 let curr = ip.offset_from(base) as core::ffi::c_long as u32;
430 let mut i: u32 = 0;
431 i = 0;
432 while i < fastHashFillStep {
433 let smHash = ZSTD_hashPtr(
434 ip.offset(i as isize) as *const core::ffi::c_void,
435 hBitsS,
436 mls,
437 );
438 let lgHash = ZSTD_hashPtr(ip.offset(i as isize) as *const core::ffi::c_void, hBitsL, 8);
439 if i == 0 {
440 *hashSmall.add(smHash) = curr.wrapping_add(i);
441 }
442 if i == 0 || *hashLarge.add(lgHash) == 0 {
443 *hashLarge.add(lgHash) = curr.wrapping_add(i);
444 }
445 if dtlm as core::ffi::c_uint == ZSTD_dtlm_fast as core::ffi::c_int as core::ffi::c_uint
446 {
447 break;
448 }
449 i = i.wrapping_add(1);
450 }
451 ip = ip.offset(fastHashFillStep as isize);
452 }
453}
454pub unsafe fn ZSTD_fillDoubleHashTable(
455 ms: *mut ZSTD_MatchState_t,
456 end: *const core::ffi::c_void,
457 dtlm: ZSTD_dictTableLoadMethod_e,
458 tfp: ZSTD_tableFillPurpose_e,
459) {
460 if tfp as core::ffi::c_uint == ZSTD_tfp_forCDict as core::ffi::c_int as core::ffi::c_uint {
461 ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
462 } else {
463 ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
464 };
465}
466#[inline(always)]
467unsafe fn ZSTD_compressBlock_doubleFast_noDict_generic(
468 ms: *mut ZSTD_MatchState_t,
469 seqStore: *mut SeqStore_t,
470 rep: *mut u32,
471 src: *const core::ffi::c_void,
472 srcSize: size_t,
473 mls: u32,
474) -> size_t {
475 let cParams: *const ZSTD_compressionParameters = &mut (*ms).cParams;
476 let hashLong = (*ms).hashTable;
477 let hBitsL = (*cParams).hashLog;
478 let hashSmall = (*ms).chainTable;
479 let hBitsS = (*cParams).chainLog;
480 let base = (*ms).window.base;
481 let istart = src as *const u8;
482 let mut anchor = istart;
483 let endIndex = (istart.offset_from(base) as size_t).wrapping_add(srcSize) as u32;
484 let prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, (*cParams).windowLog);
485 let prefixLowest = base.offset(prefixLowestIndex as isize);
486 let iend = istart.add(srcSize);
487 let ilimit = iend.offset(-(HASH_READ_SIZE as isize));
488 let mut offset_1 = *rep.offset(0);
489 let mut offset_2 = *rep.offset(1);
490 let mut offsetSaved1 = 0;
491 let mut offsetSaved2 = 0;
492 let mut mLength: size_t = 0;
493 let mut offset: u32 = 0;
494 let mut curr: u32 = 0;
495 let kStepIncr = ((1) << kSearchStrength) as size_t;
496 let mut nextStep = core::ptr::null::<u8>();
497 let mut step: size_t = 0;
498 let mut hl0: size_t = 0;
499 let mut hl1: size_t = 0;
500 let mut idxl0: u32 = 0;
501 let mut idxl1: u32 = 0;
502 let mut matchl0 = core::ptr::null::<u8>();
503 let mut matchs0 = core::ptr::null::<u8>();
504 let mut matchl1 = core::ptr::null::<u8>();
505 let mut matchs0_safe = core::ptr::null::<u8>();
506 let mut ip = istart;
507 let mut ip1 = core::ptr::null::<u8>();
508 let dummy: [u8; 10] = [
509 0x12 as core::ffi::c_int as u8,
510 0x34 as core::ffi::c_int as u8,
511 0x56 as core::ffi::c_int as u8,
512 0x78 as core::ffi::c_int as u8,
513 0x9a as core::ffi::c_int as u8,
514 0xbc as core::ffi::c_int as u8,
515 0xde as core::ffi::c_int as u8,
516 0xf0 as core::ffi::c_int as u8,
517 0xe2 as core::ffi::c_int as u8,
518 0xb4 as core::ffi::c_int as u8,
519 ];
520 ip = ip.offset(
521 (ip.offset_from(prefixLowest) as core::ffi::c_long == 0) as core::ffi::c_int as isize,
522 );
523 let current = ip.offset_from(base) as core::ffi::c_long as u32;
524 let windowLow = ZSTD_getLowestPrefixIndex(ms, current, (*cParams).windowLog);
525 let maxRep = current.wrapping_sub(windowLow);
526 if offset_2 > maxRep {
527 offsetSaved2 = offset_2;
528 offset_2 = 0;
529 }
530 if offset_1 > maxRep {
531 offsetSaved1 = offset_1;
532 offset_1 = 0;
533 }
534 loop {
535 's_428: {
536 let mut current_block_83: u64;
537 step = 1;
538 nextStep = ip.add(kStepIncr);
539 ip1 = ip.add(step);
540 if ip1 <= ilimit {
541 hl0 = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8);
542 idxl0 = *hashLong.add(hl0);
543 matchl0 = base.offset(idxl0 as isize);
544 loop {
545 let hs0 = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls);
546 let idxs0 = *hashSmall.add(hs0);
547 curr = ip.offset_from(base) as core::ffi::c_long as u32;
548 matchs0 = base.offset(idxs0 as isize);
549 let fresh2 = &mut (*hashSmall.add(hs0));
550 *fresh2 = curr;
551 *hashLong.add(hl0) = *fresh2;
552 if (offset_1 > 0) as core::ffi::c_int
553 & (MEM_read32(
554 ip.offset(1).offset(-(offset_1 as isize)) as *const core::ffi::c_void
555 ) == MEM_read32(ip.offset(1) as *const core::ffi::c_void))
556 as core::ffi::c_int
557 != 0
558 {
559 mLength = (ZSTD_count(
560 ip.offset(1).offset(4),
561 ip.offset(1).offset(4).offset(-(offset_1 as isize)),
562 iend,
563 ))
564 .wrapping_add(4);
565 ip = ip.offset(1);
566 ZSTD_storeSeq(
567 seqStore,
568 ip.offset_from(anchor) as size_t,
569 anchor,
570 iend,
571 REPCODE1_TO_OFFBASE as u32,
572 mLength,
573 );
574 current_block_83 = 18341544293284149774;
575 break;
576 } else {
577 hl1 = ZSTD_hashPtr(ip1 as *const core::ffi::c_void, hBitsL, 8);
578 let matchl0_safe = {
579 core::hint::select_unpredictable(
580 idxl0 >= prefixLowestIndex,
581 matchl0,
582 dummy.as_ptr(),
583 )
584 };
585 if MEM_read64(matchl0_safe as *const core::ffi::c_void)
586 == MEM_read64(ip as *const core::ffi::c_void)
587 && matchl0_safe == matchl0
588 {
589 mLength =
590 (ZSTD_count(ip.offset(8), matchl0.offset(8), iend)).wrapping_add(8);
591 offset = ip.offset_from(matchl0) as core::ffi::c_long as u32;
592 while (ip > anchor) as core::ffi::c_int
593 & (matchl0 > prefixLowest) as core::ffi::c_int
594 != 0
595 && *ip.offset(-1_isize) as core::ffi::c_int
596 == *matchl0.offset(-1_isize) as core::ffi::c_int
597 {
598 ip = ip.offset(-1);
599 matchl0 = matchl0.offset(-1);
600 mLength = mLength.wrapping_add(1);
601 }
602 current_block_83 = 14716613436827065636;
603 break;
604 } else {
605 idxl1 = *hashLong.add(hl1);
606 matchl1 = base.offset(idxl1 as isize);
607 matchs0_safe = {
608 core::hint::select_unpredictable(
609 idxs0 >= prefixLowestIndex,
610 matchs0,
611 dummy.as_ptr(),
612 )
613 };
614 if MEM_read32(matchs0_safe as *const core::ffi::c_void)
615 == MEM_read32(ip as *const core::ffi::c_void)
616 && matchs0_safe == matchs0
617 {
618 current_block_83 = 6142208486753608565;
619 break;
620 }
621 if ip1 >= nextStep {
622 step = step.wrapping_add(1);
623 nextStep = nextStep.add(kStepIncr);
624 }
625 ip = ip1;
626 ip1 = ip1.add(step);
627 hl0 = hl1;
628 idxl0 = idxl1;
629 matchl0 = matchl1;
630 if ip1 > ilimit {
631 current_block_83 = 14575735148454673654;
632 break;
633 }
634 }
635 }
636 }
637 match current_block_83 {
638 14575735148454673654 => {}
639 _ => {
640 if current_block_83 == 6142208486753608565 {
641 mLength =
642 (ZSTD_count(ip.offset(4), matchs0.offset(4), iend)).wrapping_add(4);
643 offset = ip.offset_from(matchs0) as core::ffi::c_long as u32;
644 if idxl1 > prefixLowestIndex
645 && MEM_read64(matchl1 as *const core::ffi::c_void)
646 == MEM_read64(ip1 as *const core::ffi::c_void)
647 {
648 let l1len = (ZSTD_count(ip1.offset(8), matchl1.offset(8), iend))
649 .wrapping_add(8);
650 if l1len > mLength {
651 ip = ip1;
652 mLength = l1len;
653 offset = ip.offset_from(matchl1) as core::ffi::c_long as u32;
654 matchs0 = matchl1;
655 }
656 }
657 while (ip > anchor) as core::ffi::c_int
658 & (matchs0 > prefixLowest) as core::ffi::c_int
659 != 0
660 && *ip.offset(-1_isize) as core::ffi::c_int
661 == *matchs0.offset(-1_isize) as core::ffi::c_int
662 {
663 ip = ip.offset(-1);
664 matchs0 = matchs0.offset(-1);
665 mLength = mLength.wrapping_add(1);
666 }
667 current_block_83 = 14716613436827065636;
668 }
669 if current_block_83 == 14716613436827065636 {
670 offset_2 = offset_1;
671 offset_1 = offset;
672 if step < 4 {
673 *hashLong.add(hl1) =
674 ip1.offset_from(base) as core::ffi::c_long as u32;
675 }
676 ZSTD_storeSeq(
677 seqStore,
678 ip.offset_from(anchor) as size_t,
679 anchor,
680 iend,
681 offset.wrapping_add(ZSTD_REP_NUM as u32),
682 mLength,
683 );
684 }
685 ip = ip.add(mLength);
686 anchor = ip;
687 if ip <= ilimit {
688 let indexToInsert = curr.wrapping_add(2);
689 *hashLong.add(ZSTD_hashPtr(
690 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
691 hBitsL,
692 8,
693 )) = indexToInsert;
694 *hashLong.add(ZSTD_hashPtr(
695 ip.offset(-(2)) as *const core::ffi::c_void,
696 hBitsL,
697 8,
698 )) = ip.offset(-(2)).offset_from(base) as core::ffi::c_long as u32;
699 *hashSmall.add(ZSTD_hashPtr(
700 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
701 hBitsS,
702 mls,
703 )) = indexToInsert;
704 *hashSmall.add(ZSTD_hashPtr(
705 ip.offset(-(1)) as *const core::ffi::c_void,
706 hBitsS,
707 mls,
708 )) = ip.offset(-(1)).offset_from(base) as core::ffi::c_long as u32;
709 while ip <= ilimit
710 && (offset_2 > 0) as core::ffi::c_int
711 & (MEM_read32(ip as *const core::ffi::c_void)
712 == MEM_read32(ip.offset(-(offset_2 as isize))
713 as *const core::ffi::c_void))
714 as core::ffi::c_int
715 != 0
716 {
717 let rLength = (ZSTD_count(
718 ip.offset(4),
719 ip.offset(4).offset(-(offset_2 as isize)),
720 iend,
721 ))
722 .wrapping_add(4);
723 core::mem::swap(&mut offset_2, &mut offset_1);
724 *hashSmall.add(ZSTD_hashPtr(
725 ip as *const core::ffi::c_void,
726 hBitsS,
727 mls,
728 )) = ip.offset_from(base) as core::ffi::c_long as u32;
729 *hashLong.add(ZSTD_hashPtr(
730 ip as *const core::ffi::c_void,
731 hBitsL,
732 8,
733 )) = ip.offset_from(base) as core::ffi::c_long as u32;
734 ZSTD_storeSeq(
735 seqStore,
736 0,
737 anchor,
738 iend,
739 REPCODE1_TO_OFFBASE as u32,
740 rLength,
741 );
742 ip = ip.add(rLength);
743 anchor = ip;
744 }
745 }
746 break 's_428;
747 }
748 }
749 }
750 offsetSaved2 = if offsetSaved1 != 0 && offset_1 != 0 {
751 offsetSaved1
752 } else {
753 offsetSaved2
754 };
755 *rep.offset(0) = if offset_1 != 0 {
756 offset_1
757 } else {
758 offsetSaved1
759 };
760 *rep.offset(1) = if offset_2 != 0 {
761 offset_2
762 } else {
763 offsetSaved2
764 };
765 return iend.offset_from(anchor) as size_t;
766 }
767 }
768}
769#[inline(always)]
770unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_generic(
771 ms: *mut ZSTD_MatchState_t,
772 seqStore: *mut SeqStore_t,
773 rep: *mut u32,
774 src: *const core::ffi::c_void,
775 srcSize: size_t,
776 mls: u32,
777) -> size_t {
778 let mut current_block: u64;
779 let cParams: *const ZSTD_compressionParameters = &mut (*ms).cParams;
780 let hashLong = (*ms).hashTable;
781 let hBitsL = (*cParams).hashLog;
782 let hashSmall = (*ms).chainTable;
783 let hBitsS = (*cParams).chainLog;
784 let base = (*ms).window.base;
785 let istart = src as *const u8;
786 let mut ip = istart;
787 let mut anchor = istart;
788 let endIndex = (istart.offset_from(base) as size_t).wrapping_add(srcSize) as u32;
789 let prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, (*cParams).windowLog);
790 let prefixLowest = base.offset(prefixLowestIndex as isize);
791 let iend = istart.add(srcSize);
792 let ilimit = iend.offset(-(HASH_READ_SIZE as isize));
793 let mut offset_1 = *rep.offset(0);
794 let mut offset_2 = *rep.offset(1);
795 let dms = (*ms).dictMatchState;
796 let dictCParams: *const ZSTD_compressionParameters = &(*dms).cParams;
797 let dictHashLong: *const u32 = (*dms).hashTable;
798 let dictHashSmall: *const u32 = (*dms).chainTable;
799 let dictStartIndex = (*dms).window.dictLimit;
800 let dictBase = (*dms).window.base;
801 let dictStart = dictBase.offset(dictStartIndex as isize);
802 let dictEnd = (*dms).window.nextSrc;
803 let dictIndexDelta =
804 prefixLowestIndex.wrapping_sub(dictEnd.offset_from(dictBase) as core::ffi::c_long as u32);
805 let dictHBitsL =
806 ((*dictCParams).hashLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
807 let dictHBitsS =
808 ((*dictCParams).chainLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
809 let dictAndPrefixLength = (ip.offset_from(prefixLowest) as core::ffi::c_long
810 + dictEnd.offset_from(dictStart) as core::ffi::c_long) as u32;
811 if (*ms).prefetchCDictTables != 0 {
812 let hashTableBytes =
813 ((1 as size_t) << (*dictCParams).hashLog).wrapping_mul(::core::mem::size_of::<u32>());
814 let chainTableBytes =
815 ((1 as size_t) << (*dictCParams).chainLog).wrapping_mul(::core::mem::size_of::<u32>());
816 let _ptr = dictHashLong as *const core::ffi::c_char;
817 let _size = hashTableBytes;
818 let mut _pos: size_t = 0;
819 _pos = 0;
820 while _pos < _size {
821 _pos = _pos.wrapping_add(CACHELINE_SIZE as size_t);
822 }
823 let _ptr_0 = dictHashSmall as *const core::ffi::c_char;
824 let _size_0 = chainTableBytes;
825 let mut _pos_0: size_t = 0;
826 _pos_0 = 0;
827 while _pos_0 < _size_0 {
828 _pos_0 = _pos_0.wrapping_add(CACHELINE_SIZE as size_t);
829 }
830 }
831 ip = ip.offset((dictAndPrefixLength == 0) as core::ffi::c_int as isize);
832 while ip < ilimit {
833 let mut mLength: size_t = 0;
834 let mut offset: u32 = 0;
835 let h2 = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8);
836 let h = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls);
837 let dictHashAndTagL = ZSTD_hashPtr(ip as *const core::ffi::c_void, dictHBitsL, 8);
838 let dictHashAndTagS = ZSTD_hashPtr(ip as *const core::ffi::c_void, dictHBitsS, mls);
839 let dictMatchIndexAndTagL = *dictHashLong.add(dictHashAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS);
840 let dictMatchIndexAndTagS =
841 *dictHashSmall.add(dictHashAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS);
842 let dictTagsMatchL =
843 ZSTD_comparePackedTags(dictMatchIndexAndTagL as size_t, dictHashAndTagL);
844 let dictTagsMatchS =
845 ZSTD_comparePackedTags(dictMatchIndexAndTagS as size_t, dictHashAndTagS);
846 let curr = ip.offset_from(base) as core::ffi::c_long as u32;
847 let matchIndexL = *hashLong.add(h2);
848 let mut matchIndexS = *hashSmall.add(h);
849 let mut matchLong = base.offset(matchIndexL as isize);
850 let mut match_0 = base.offset(matchIndexS as isize);
851 let repIndex = curr.wrapping_add(1).wrapping_sub(offset_1);
852 let repMatch = if repIndex < prefixLowestIndex {
853 dictBase.offset(repIndex.wrapping_sub(dictIndexDelta) as isize)
854 } else {
855 base.offset(repIndex as isize)
856 };
857 let fresh3 = &mut (*hashSmall.add(h));
858 *fresh3 = curr;
859 *hashLong.add(h2) = *fresh3;
860 if ZSTD_index_overlap_check(prefixLowestIndex, repIndex) != 0
861 && MEM_read32(repMatch as *const core::ffi::c_void)
862 == MEM_read32(ip.offset(1) as *const core::ffi::c_void)
863 {
864 let repMatchEnd = if repIndex < prefixLowestIndex {
865 dictEnd
866 } else {
867 iend
868 };
869 mLength = (ZSTD_count_2segments(
870 ip.offset(1).offset(4),
871 repMatch.offset(4),
872 iend,
873 repMatchEnd,
874 prefixLowest,
875 ))
876 .wrapping_add(4);
877 ip = ip.offset(1);
878 ZSTD_storeSeq(
879 seqStore,
880 ip.offset_from(anchor) as size_t,
881 anchor,
882 iend,
883 REPCODE1_TO_OFFBASE as u32,
884 mLength,
885 );
886 } else {
887 if matchIndexL >= prefixLowestIndex
888 && MEM_read64(matchLong as *const core::ffi::c_void)
889 == MEM_read64(ip as *const core::ffi::c_void)
890 {
891 mLength = (ZSTD_count(ip.offset(8), matchLong.offset(8), iend)).wrapping_add(8);
892 offset = ip.offset_from(matchLong) as core::ffi::c_long as u32;
893 while (ip > anchor) as core::ffi::c_int
894 & (matchLong > prefixLowest) as core::ffi::c_int
895 != 0
896 && *ip.offset(-1_isize) as core::ffi::c_int
897 == *matchLong.offset(-1_isize) as core::ffi::c_int
898 {
899 ip = ip.offset(-1);
900 matchLong = matchLong.offset(-1);
901 mLength = mLength.wrapping_add(1);
902 }
903 } else {
904 if dictTagsMatchL != 0 {
905 let dictMatchIndexL = dictMatchIndexAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS;
906 let mut dictMatchL = dictBase.offset(dictMatchIndexL as isize);
907 if dictMatchL > dictStart
908 && MEM_read64(dictMatchL as *const core::ffi::c_void)
909 == MEM_read64(ip as *const core::ffi::c_void)
910 {
911 mLength = (ZSTD_count_2segments(
912 ip.offset(8),
913 dictMatchL.offset(8),
914 iend,
915 dictEnd,
916 prefixLowest,
917 ))
918 .wrapping_add(8);
919 offset = curr
920 .wrapping_sub(dictMatchIndexL)
921 .wrapping_sub(dictIndexDelta);
922 while (ip > anchor) as core::ffi::c_int
923 & (dictMatchL > dictStart) as core::ffi::c_int
924 != 0
925 && *ip.offset(-1_isize) as core::ffi::c_int
926 == *dictMatchL.offset(-1_isize) as core::ffi::c_int
927 {
928 ip = ip.offset(-1);
929 dictMatchL = dictMatchL.offset(-1);
930 mLength = mLength.wrapping_add(1);
931 }
932 current_block = 17830677668754335218;
933 } else {
934 current_block = 6721012065216013753;
935 }
936 } else {
937 current_block = 6721012065216013753;
938 }
939 match current_block {
940 17830677668754335218 => {}
941 _ => {
942 if matchIndexS > prefixLowestIndex {
943 if MEM_read32(match_0 as *const core::ffi::c_void)
944 == MEM_read32(ip as *const core::ffi::c_void)
945 {
946 current_block = 2631791190359682872;
947 } else {
948 current_block = 5372832139739605200;
949 }
950 } else if dictTagsMatchS != 0 {
951 let dictMatchIndexS =
952 dictMatchIndexAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS;
953 match_0 = dictBase.offset(dictMatchIndexS as isize);
954 matchIndexS = dictMatchIndexS.wrapping_add(dictIndexDelta);
955 if match_0 > dictStart
956 && MEM_read32(match_0 as *const core::ffi::c_void)
957 == MEM_read32(ip as *const core::ffi::c_void)
958 {
959 current_block = 2631791190359682872;
960 } else {
961 current_block = 5372832139739605200;
962 }
963 } else {
964 current_block = 5372832139739605200;
965 }
966 match current_block {
967 5372832139739605200 => {
968 ip = ip.offset(
969 ((ip.offset_from(anchor) as core::ffi::c_long
970 >> kSearchStrength)
971 + 1) as isize,
972 );
973 continue;
974 }
975 _ => {
976 let hl3 = ZSTD_hashPtr(
977 ip.offset(1) as *const core::ffi::c_void,
978 hBitsL,
979 8,
980 );
981 let dictHashAndTagL3 = ZSTD_hashPtr(
982 ip.offset(1) as *const core::ffi::c_void,
983 dictHBitsL,
984 8,
985 );
986 let matchIndexL3 = *hashLong.add(hl3);
987 let dictMatchIndexAndTagL3 = *dictHashLong
988 .add(dictHashAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS);
989 let dictTagsMatchL3 = ZSTD_comparePackedTags(
990 dictMatchIndexAndTagL3 as size_t,
991 dictHashAndTagL3,
992 );
993 let mut matchL3 = base.offset(matchIndexL3 as isize);
994 *hashLong.add(hl3) = curr.wrapping_add(1);
995 if matchIndexL3 >= prefixLowestIndex
996 && MEM_read64(matchL3 as *const core::ffi::c_void)
997 == MEM_read64(ip.offset(1) as *const core::ffi::c_void)
998 {
999 mLength = (ZSTD_count(ip.offset(9), matchL3.offset(8), iend))
1000 .wrapping_add(8);
1001 ip = ip.offset(1);
1002 offset = ip.offset_from(matchL3) as core::ffi::c_long as u32;
1003 while (ip > anchor) as core::ffi::c_int
1004 & (matchL3 > prefixLowest) as core::ffi::c_int
1005 != 0
1006 && *ip.offset(-1_isize) as core::ffi::c_int
1007 == *matchL3.offset(-1_isize) as core::ffi::c_int
1008 {
1009 ip = ip.offset(-1);
1010 matchL3 = matchL3.offset(-1);
1011 mLength = mLength.wrapping_add(1);
1012 }
1013 } else {
1014 if dictTagsMatchL3 != 0 {
1015 let dictMatchIndexL3 =
1016 dictMatchIndexAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS;
1017 let mut dictMatchL3 =
1018 dictBase.offset(dictMatchIndexL3 as isize);
1019 if dictMatchL3 > dictStart
1020 && MEM_read64(dictMatchL3 as *const core::ffi::c_void)
1021 == MEM_read64(
1022 ip.offset(1) as *const core::ffi::c_void
1023 )
1024 {
1025 mLength = (ZSTD_count_2segments(
1026 ip.offset(1).offset(8),
1027 dictMatchL3.offset(8),
1028 iend,
1029 dictEnd,
1030 prefixLowest,
1031 ))
1032 .wrapping_add(8);
1033 ip = ip.offset(1);
1034 offset = curr
1035 .wrapping_add(1)
1036 .wrapping_sub(dictMatchIndexL3)
1037 .wrapping_sub(dictIndexDelta);
1038 while (ip > anchor) as core::ffi::c_int
1039 & (dictMatchL3 > dictStart) as core::ffi::c_int
1040 != 0
1041 && *ip.offset(-1_isize) as core::ffi::c_int
1042 == *dictMatchL3.offset(-1_isize)
1043 as core::ffi::c_int
1044 {
1045 ip = ip.offset(-1);
1046 dictMatchL3 = dictMatchL3.offset(-1);
1047 mLength = mLength.wrapping_add(1);
1048 }
1049 current_block = 17830677668754335218;
1050 } else {
1051 current_block = 1209030638129645089;
1052 }
1053 } else {
1054 current_block = 1209030638129645089;
1055 }
1056 match current_block {
1057 17830677668754335218 => {}
1058 _ => {
1059 if matchIndexS < prefixLowestIndex {
1060 mLength = (ZSTD_count_2segments(
1061 ip.offset(4),
1062 match_0.offset(4),
1063 iend,
1064 dictEnd,
1065 prefixLowest,
1066 ))
1067 .wrapping_add(4);
1068 offset = curr.wrapping_sub(matchIndexS);
1069 while (ip > anchor) as core::ffi::c_int
1070 & (match_0 > dictStart) as core::ffi::c_int
1071 != 0
1072 && *ip.offset(-1_isize) as core::ffi::c_int
1073 == *match_0.offset(-1_isize)
1074 as core::ffi::c_int
1075 {
1076 ip = ip.offset(-1);
1077 match_0 = match_0.offset(-1);
1078 mLength = mLength.wrapping_add(1);
1079 }
1080 } else {
1081 mLength = (ZSTD_count(
1082 ip.offset(4),
1083 match_0.offset(4),
1084 iend,
1085 ))
1086 .wrapping_add(4);
1087 offset = ip.offset_from(match_0)
1088 as core::ffi::c_long
1089 as u32;
1090 while (ip > anchor) as core::ffi::c_int
1091 & (match_0 > prefixLowest) as core::ffi::c_int
1092 != 0
1093 && *ip.offset(-1_isize) as core::ffi::c_int
1094 == *match_0.offset(-1_isize)
1095 as core::ffi::c_int
1096 {
1097 ip = ip.offset(-1);
1098 match_0 = match_0.offset(-1);
1099 mLength = mLength.wrapping_add(1);
1100 }
1101 }
1102 }
1103 }
1104 }
1105 }
1106 }
1107 }
1108 }
1109 }
1110 offset_2 = offset_1;
1111 offset_1 = offset;
1112 ZSTD_storeSeq(
1113 seqStore,
1114 ip.offset_from(anchor) as size_t,
1115 anchor,
1116 iend,
1117 offset.wrapping_add(ZSTD_REP_NUM as u32),
1118 mLength,
1119 );
1120 }
1121 ip = ip.add(mLength);
1122 anchor = ip;
1123 if ip <= ilimit {
1124 let indexToInsert = curr.wrapping_add(2);
1125 *hashLong.add(ZSTD_hashPtr(
1126 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
1127 hBitsL,
1128 8,
1129 )) = indexToInsert;
1130 *hashLong.add(ZSTD_hashPtr(
1131 ip.offset(-(2)) as *const core::ffi::c_void,
1132 hBitsL,
1133 8,
1134 )) = ip.offset(-(2)).offset_from(base) as core::ffi::c_long as u32;
1135 *hashSmall.add(ZSTD_hashPtr(
1136 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
1137 hBitsS,
1138 mls,
1139 )) = indexToInsert;
1140 *hashSmall.add(ZSTD_hashPtr(
1141 ip.offset(-(1)) as *const core::ffi::c_void,
1142 hBitsS,
1143 mls,
1144 )) = ip.offset(-(1)).offset_from(base) as core::ffi::c_long as u32;
1145 while ip <= ilimit {
1146 let current2 = ip.offset_from(base) as core::ffi::c_long as u32;
1147 let repIndex2 = current2.wrapping_sub(offset_2);
1148 let repMatch2 = if repIndex2 < prefixLowestIndex {
1149 dictBase
1150 .offset(repIndex2 as isize)
1151 .offset(-(dictIndexDelta as isize))
1152 } else {
1153 base.offset(repIndex2 as isize)
1154 };
1155 if !(ZSTD_index_overlap_check(prefixLowestIndex, repIndex2) != 0
1156 && MEM_read32(repMatch2 as *const core::ffi::c_void)
1157 == MEM_read32(ip as *const core::ffi::c_void))
1158 {
1159 break;
1160 }
1161 let repEnd2 = if repIndex2 < prefixLowestIndex {
1162 dictEnd
1163 } else {
1164 iend
1165 };
1166 let repLength2 = (ZSTD_count_2segments(
1167 ip.offset(4),
1168 repMatch2.offset(4),
1169 iend,
1170 repEnd2,
1171 prefixLowest,
1172 ))
1173 .wrapping_add(4);
1174 core::mem::swap(&mut offset_2, &mut offset_1);
1175 ZSTD_storeSeq(
1176 seqStore,
1177 0,
1178 anchor,
1179 iend,
1180 REPCODE1_TO_OFFBASE as u32,
1181 repLength2,
1182 );
1183 *hashSmall.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls)) =
1184 current2;
1185 *hashLong.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8)) = current2;
1186 ip = ip.add(repLength2);
1187 anchor = ip;
1188 }
1189 }
1190 }
1191 *rep.offset(0) = offset_1;
1192 *rep.offset(1) = offset_2;
1193 iend.offset_from(anchor) as size_t
1194}
1195unsafe fn ZSTD_compressBlock_doubleFast_noDict_4(
1196 ms: *mut ZSTD_MatchState_t,
1197 seqStore: *mut SeqStore_t,
1198 rep: *mut u32,
1199 src: *const core::ffi::c_void,
1200 srcSize: size_t,
1201) -> size_t {
1202 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 4)
1203}
1204unsafe fn ZSTD_compressBlock_doubleFast_noDict_5(
1205 ms: *mut ZSTD_MatchState_t,
1206 seqStore: *mut SeqStore_t,
1207 rep: *mut u32,
1208 src: *const core::ffi::c_void,
1209 srcSize: size_t,
1210) -> size_t {
1211 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 5)
1212}
1213unsafe fn ZSTD_compressBlock_doubleFast_noDict_6(
1214 ms: *mut ZSTD_MatchState_t,
1215 seqStore: *mut SeqStore_t,
1216 rep: *mut u32,
1217 src: *const core::ffi::c_void,
1218 srcSize: size_t,
1219) -> size_t {
1220 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 6)
1221}
1222unsafe fn ZSTD_compressBlock_doubleFast_noDict_7(
1223 ms: *mut ZSTD_MatchState_t,
1224 seqStore: *mut SeqStore_t,
1225 rep: *mut u32,
1226 src: *const core::ffi::c_void,
1227 srcSize: size_t,
1228) -> size_t {
1229 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 7)
1230}
1231unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_4(
1232 ms: *mut ZSTD_MatchState_t,
1233 seqStore: *mut SeqStore_t,
1234 rep: *mut u32,
1235 src: *const core::ffi::c_void,
1236 srcSize: size_t,
1237) -> size_t {
1238 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 4)
1239}
1240unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_5(
1241 ms: *mut ZSTD_MatchState_t,
1242 seqStore: *mut SeqStore_t,
1243 rep: *mut u32,
1244 src: *const core::ffi::c_void,
1245 srcSize: size_t,
1246) -> size_t {
1247 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 5)
1248}
1249unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_6(
1250 ms: *mut ZSTD_MatchState_t,
1251 seqStore: *mut SeqStore_t,
1252 rep: *mut u32,
1253 src: *const core::ffi::c_void,
1254 srcSize: size_t,
1255) -> size_t {
1256 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 6)
1257}
1258unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_7(
1259 ms: *mut ZSTD_MatchState_t,
1260 seqStore: *mut SeqStore_t,
1261 rep: *mut u32,
1262 src: *const core::ffi::c_void,
1263 srcSize: size_t,
1264) -> size_t {
1265 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 7)
1266}
1267pub unsafe fn ZSTD_compressBlock_doubleFast(
1268 ms: *mut ZSTD_MatchState_t,
1269 seqStore: *mut SeqStore_t,
1270 rep: *mut u32,
1271 src: *const core::ffi::c_void,
1272 srcSize: size_t,
1273) -> size_t {
1274 let mls = (*ms).cParams.minMatch;
1275 match mls {
1276 5 => ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize),
1277 6 => ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize),
1278 7 => ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize),
1279 4 | _ => ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize),
1280 }
1281}
1282pub unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState(
1283 ms: *mut ZSTD_MatchState_t,
1284 seqStore: *mut SeqStore_t,
1285 rep: *mut u32,
1286 src: *const core::ffi::c_void,
1287 srcSize: size_t,
1288) -> size_t {
1289 let mls = (*ms).cParams.minMatch;
1290 match mls {
1291 5 => ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize),
1292 6 => ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize),
1293 7 => ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize),
1294 4 | _ => ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize),
1295 }
1296}
1297unsafe fn ZSTD_compressBlock_doubleFast_extDict_generic(
1298 ms: *mut ZSTD_MatchState_t,
1299 seqStore: *mut SeqStore_t,
1300 rep: *mut u32,
1301 src: *const core::ffi::c_void,
1302 srcSize: size_t,
1303 mls: u32,
1304) -> size_t {
1305 let cParams: *const ZSTD_compressionParameters = &mut (*ms).cParams;
1306 let hashLong = (*ms).hashTable;
1307 let hBitsL = (*cParams).hashLog;
1308 let hashSmall = (*ms).chainTable;
1309 let hBitsS = (*cParams).chainLog;
1310 let istart = src as *const u8;
1311 let mut ip = istart;
1312 let mut anchor = istart;
1313 let iend = istart.add(srcSize);
1314 let ilimit = iend.offset(-(8));
1315 let base = (*ms).window.base;
1316 let endIndex = (istart.offset_from(base) as size_t).wrapping_add(srcSize) as u32;
1317 let lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, (*cParams).windowLog);
1318 let dictStartIndex = lowLimit;
1319 let dictLimit = (*ms).window.dictLimit;
1320 let prefixStartIndex = if dictLimit > lowLimit {
1321 dictLimit
1322 } else {
1323 lowLimit
1324 };
1325 let prefixStart = base.offset(prefixStartIndex as isize);
1326 let dictBase = (*ms).window.dictBase;
1327 let dictStart = dictBase.offset(dictStartIndex as isize);
1328 let dictEnd = dictBase.offset(prefixStartIndex as isize);
1329 let mut offset_1 = *rep.offset(0);
1330 let mut offset_2 = *rep.offset(1);
1331 if prefixStartIndex == dictStartIndex {
1332 return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize);
1333 }
1334 while ip < ilimit {
1335 let hSmall = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls);
1336 let matchIndex = *hashSmall.add(hSmall);
1337 let matchBase = if matchIndex < prefixStartIndex {
1338 dictBase
1339 } else {
1340 base
1341 };
1342 let mut match_0 = matchBase.offset(matchIndex as isize);
1343 let hLong = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8);
1344 let matchLongIndex = *hashLong.add(hLong);
1345 let matchLongBase = if matchLongIndex < prefixStartIndex {
1346 dictBase
1347 } else {
1348 base
1349 };
1350 let mut matchLong = matchLongBase.offset(matchLongIndex as isize);
1351 let curr = ip.offset_from(base) as core::ffi::c_long as u32;
1352 let repIndex = curr.wrapping_add(1).wrapping_sub(offset_1);
1353 let repBase = if repIndex < prefixStartIndex {
1354 dictBase
1355 } else {
1356 base
1357 };
1358 let repMatch = repBase.offset(repIndex as isize);
1359 let mut mLength: size_t = 0;
1360 let fresh4 = &mut (*hashLong.add(hLong));
1361 *fresh4 = curr;
1362 *hashSmall.add(hSmall) = *fresh4;
1363 if ZSTD_index_overlap_check(prefixStartIndex, repIndex)
1364 & (offset_1 <= curr.wrapping_add(1).wrapping_sub(dictStartIndex)) as core::ffi::c_int
1365 != 0
1366 && MEM_read32(repMatch as *const core::ffi::c_void)
1367 == MEM_read32(ip.offset(1) as *const core::ffi::c_void)
1368 {
1369 let repMatchEnd = if repIndex < prefixStartIndex {
1370 dictEnd
1371 } else {
1372 iend
1373 };
1374 mLength = (ZSTD_count_2segments(
1375 ip.offset(1).offset(4),
1376 repMatch.offset(4),
1377 iend,
1378 repMatchEnd,
1379 prefixStart,
1380 ))
1381 .wrapping_add(4);
1382 ip = ip.offset(1);
1383 ZSTD_storeSeq(
1384 seqStore,
1385 ip.offset_from(anchor) as size_t,
1386 anchor,
1387 iend,
1388 REPCODE1_TO_OFFBASE as u32,
1389 mLength,
1390 );
1391 } else if matchLongIndex > dictStartIndex
1392 && MEM_read64(matchLong as *const core::ffi::c_void)
1393 == MEM_read64(ip as *const core::ffi::c_void)
1394 {
1395 let matchEnd = if matchLongIndex < prefixStartIndex {
1396 dictEnd
1397 } else {
1398 iend
1399 };
1400 let lowMatchPtr = if matchLongIndex < prefixStartIndex {
1401 dictStart
1402 } else {
1403 prefixStart
1404 };
1405 let mut offset: u32 = 0;
1406 mLength = (ZSTD_count_2segments(
1407 ip.offset(8),
1408 matchLong.offset(8),
1409 iend,
1410 matchEnd,
1411 prefixStart,
1412 ))
1413 .wrapping_add(8);
1414 offset = curr.wrapping_sub(matchLongIndex);
1415 while (ip > anchor) as core::ffi::c_int & (matchLong > lowMatchPtr) as core::ffi::c_int
1416 != 0
1417 && *ip.offset(-1_isize) as core::ffi::c_int
1418 == *matchLong.offset(-1_isize) as core::ffi::c_int
1419 {
1420 ip = ip.offset(-1);
1421 matchLong = matchLong.offset(-1);
1422 mLength = mLength.wrapping_add(1);
1423 }
1424 offset_2 = offset_1;
1425 offset_1 = offset;
1426 ZSTD_storeSeq(
1427 seqStore,
1428 ip.offset_from(anchor) as size_t,
1429 anchor,
1430 iend,
1431 offset.wrapping_add(ZSTD_REP_NUM as u32),
1432 mLength,
1433 );
1434 } else if matchIndex > dictStartIndex
1435 && MEM_read32(match_0 as *const core::ffi::c_void)
1436 == MEM_read32(ip as *const core::ffi::c_void)
1437 {
1438 let h3 = ZSTD_hashPtr(ip.offset(1) as *const core::ffi::c_void, hBitsL, 8);
1439 let matchIndex3 = *hashLong.add(h3);
1440 let match3Base = if matchIndex3 < prefixStartIndex {
1441 dictBase
1442 } else {
1443 base
1444 };
1445 let mut match3 = match3Base.offset(matchIndex3 as isize);
1446 let mut offset_0: u32 = 0;
1447 *hashLong.add(h3) = curr.wrapping_add(1);
1448 if matchIndex3 > dictStartIndex
1449 && MEM_read64(match3 as *const core::ffi::c_void)
1450 == MEM_read64(ip.offset(1) as *const core::ffi::c_void)
1451 {
1452 let matchEnd_0 = if matchIndex3 < prefixStartIndex {
1453 dictEnd
1454 } else {
1455 iend
1456 };
1457 let lowMatchPtr_0 = if matchIndex3 < prefixStartIndex {
1458 dictStart
1459 } else {
1460 prefixStart
1461 };
1462 mLength = (ZSTD_count_2segments(
1463 ip.offset(9),
1464 match3.offset(8),
1465 iend,
1466 matchEnd_0,
1467 prefixStart,
1468 ))
1469 .wrapping_add(8);
1470 ip = ip.offset(1);
1471 offset_0 = curr.wrapping_add(1).wrapping_sub(matchIndex3);
1472 while (ip > anchor) as core::ffi::c_int
1473 & (match3 > lowMatchPtr_0) as core::ffi::c_int
1474 != 0
1475 && *ip.offset(-1_isize) as core::ffi::c_int
1476 == *match3.offset(-1_isize) as core::ffi::c_int
1477 {
1478 ip = ip.offset(-1);
1479 match3 = match3.offset(-1);
1480 mLength = mLength.wrapping_add(1);
1481 }
1482 } else {
1483 let matchEnd_1 = if matchIndex < prefixStartIndex {
1484 dictEnd
1485 } else {
1486 iend
1487 };
1488 let lowMatchPtr_1 = if matchIndex < prefixStartIndex {
1489 dictStart
1490 } else {
1491 prefixStart
1492 };
1493 mLength = (ZSTD_count_2segments(
1494 ip.offset(4),
1495 match_0.offset(4),
1496 iend,
1497 matchEnd_1,
1498 prefixStart,
1499 ))
1500 .wrapping_add(4);
1501 offset_0 = curr.wrapping_sub(matchIndex);
1502 while (ip > anchor) as core::ffi::c_int
1503 & (match_0 > lowMatchPtr_1) as core::ffi::c_int
1504 != 0
1505 && *ip.offset(-1_isize) as core::ffi::c_int
1506 == *match_0.offset(-1_isize) as core::ffi::c_int
1507 {
1508 ip = ip.offset(-1);
1509 match_0 = match_0.offset(-1);
1510 mLength = mLength.wrapping_add(1);
1511 }
1512 }
1513 offset_2 = offset_1;
1514 offset_1 = offset_0;
1515 ZSTD_storeSeq(
1516 seqStore,
1517 ip.offset_from(anchor) as size_t,
1518 anchor,
1519 iend,
1520 offset_0.wrapping_add(ZSTD_REP_NUM as u32),
1521 mLength,
1522 );
1523 } else {
1524 ip = ip.offset(
1525 ((ip.offset_from(anchor) as core::ffi::c_long >> kSearchStrength) + 1) as isize,
1526 );
1527 continue;
1528 }
1529 ip = ip.add(mLength);
1530 anchor = ip;
1531 if ip <= ilimit {
1532 let indexToInsert = curr.wrapping_add(2);
1533 *hashLong.add(ZSTD_hashPtr(
1534 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
1535 hBitsL,
1536 8,
1537 )) = indexToInsert;
1538 *hashLong.add(ZSTD_hashPtr(
1539 ip.offset(-(2)) as *const core::ffi::c_void,
1540 hBitsL,
1541 8,
1542 )) = ip.offset(-(2)).offset_from(base) as core::ffi::c_long as u32;
1543 *hashSmall.add(ZSTD_hashPtr(
1544 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
1545 hBitsS,
1546 mls,
1547 )) = indexToInsert;
1548 *hashSmall.add(ZSTD_hashPtr(
1549 ip.offset(-(1)) as *const core::ffi::c_void,
1550 hBitsS,
1551 mls,
1552 )) = ip.offset(-(1)).offset_from(base) as core::ffi::c_long as u32;
1553 while ip <= ilimit {
1554 let current2 = ip.offset_from(base) as core::ffi::c_long as u32;
1555 let repIndex2 = current2.wrapping_sub(offset_2);
1556 let repMatch2 = if repIndex2 < prefixStartIndex {
1557 dictBase.offset(repIndex2 as isize)
1558 } else {
1559 base.offset(repIndex2 as isize)
1560 };
1561 if !(ZSTD_index_overlap_check(prefixStartIndex, repIndex2)
1562 & (offset_2 <= current2.wrapping_sub(dictStartIndex)) as core::ffi::c_int
1563 != 0
1564 && MEM_read32(repMatch2 as *const core::ffi::c_void)
1565 == MEM_read32(ip as *const core::ffi::c_void))
1566 {
1567 break;
1568 }
1569 let repEnd2 = if repIndex2 < prefixStartIndex {
1570 dictEnd
1571 } else {
1572 iend
1573 };
1574 let repLength2 = (ZSTD_count_2segments(
1575 ip.offset(4),
1576 repMatch2.offset(4),
1577 iend,
1578 repEnd2,
1579 prefixStart,
1580 ))
1581 .wrapping_add(4);
1582 core::mem::swap(&mut offset_2, &mut offset_1);
1583 ZSTD_storeSeq(
1584 seqStore,
1585 0,
1586 anchor,
1587 iend,
1588 REPCODE1_TO_OFFBASE as u32,
1589 repLength2,
1590 );
1591 *hashSmall.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls)) =
1592 current2;
1593 *hashLong.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8)) = current2;
1594 ip = ip.add(repLength2);
1595 anchor = ip;
1596 }
1597 }
1598 }
1599 *rep.offset(0) = offset_1;
1600 *rep.offset(1) = offset_2;
1601 iend.offset_from(anchor) as size_t
1602}
1603unsafe fn ZSTD_compressBlock_doubleFast_extDict_4(
1604 ms: *mut ZSTD_MatchState_t,
1605 seqStore: *mut SeqStore_t,
1606 rep: *mut u32,
1607 src: *const core::ffi::c_void,
1608 srcSize: size_t,
1609) -> size_t {
1610 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 4)
1611}
1612unsafe fn ZSTD_compressBlock_doubleFast_extDict_5(
1613 ms: *mut ZSTD_MatchState_t,
1614 seqStore: *mut SeqStore_t,
1615 rep: *mut u32,
1616 src: *const core::ffi::c_void,
1617 srcSize: size_t,
1618) -> size_t {
1619 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 5)
1620}
1621unsafe fn ZSTD_compressBlock_doubleFast_extDict_6(
1622 ms: *mut ZSTD_MatchState_t,
1623 seqStore: *mut SeqStore_t,
1624 rep: *mut u32,
1625 src: *const core::ffi::c_void,
1626 srcSize: size_t,
1627) -> size_t {
1628 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 6)
1629}
1630unsafe fn ZSTD_compressBlock_doubleFast_extDict_7(
1631 ms: *mut ZSTD_MatchState_t,
1632 seqStore: *mut SeqStore_t,
1633 rep: *mut u32,
1634 src: *const core::ffi::c_void,
1635 srcSize: size_t,
1636) -> size_t {
1637 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 7)
1638}
1639pub unsafe fn ZSTD_compressBlock_doubleFast_extDict(
1640 ms: *mut ZSTD_MatchState_t,
1641 seqStore: *mut SeqStore_t,
1642 rep: *mut u32,
1643 src: *const core::ffi::c_void,
1644 srcSize: size_t,
1645) -> size_t {
1646 let mls = (*ms).cParams.minMatch;
1647 match mls {
1648 5 => ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize),
1649 6 => ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize),
1650 7 => ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize),
1651 4 | _ => ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize),
1652 }
1653}