1use crate::lib::polyfill::PointerExt;
2
3#[repr(C)]
4pub struct optState_t {
5 pub litFreq: *mut core::ffi::c_uint,
6 pub litLengthFreq: *mut core::ffi::c_uint,
7 pub matchLengthFreq: *mut core::ffi::c_uint,
8 pub offCodeFreq: *mut core::ffi::c_uint,
9 pub matchTable: *mut ZSTD_match_t,
10 pub priceTable: *mut ZSTD_optimal_t,
11 pub litSum: u32,
12 pub litLengthSum: u32,
13 pub matchLengthSum: u32,
14 pub offCodeSum: u32,
15 pub litSumBasePrice: u32,
16 pub litLengthSumBasePrice: u32,
17 pub matchLengthSumBasePrice: u32,
18 pub offCodeSumBasePrice: u32,
19 pub priceType: ZSTD_OptPrice_e,
20 pub symbolCosts: *const ZSTD_entropyCTables_t,
21 pub literalCompressionMode: ZSTD_ParamSwitch_e,
22}
23#[repr(C)]
24pub struct ZSTD_entropyCTables_t {
25 pub huf: ZSTD_hufCTables_t,
26 pub fse: ZSTD_fseCTables_t,
27}
28#[repr(C)]
29pub struct ZSTD_fseCTables_t {
30 pub offcodeCTable: [FSE_CTable; 193],
31 pub matchlengthCTable: [FSE_CTable; 363],
32 pub litlengthCTable: [FSE_CTable; 329],
33 pub offcode_repeatMode: FSE_repeat,
34 pub matchlength_repeatMode: FSE_repeat,
35 pub litlength_repeatMode: FSE_repeat,
36}
37#[repr(C)]
38pub struct ZSTD_hufCTables_t {
39 pub CTable: [HUF_CElt; 257],
40 pub repeatMode: HUF_repeat,
41}
42
43pub type ZSTD_dictTableLoadMethod_e = core::ffi::c_uint;
44pub const ZSTD_dtlm_full: ZSTD_dictTableLoadMethod_e = 1;
45pub const ZSTD_dtlm_fast: ZSTD_dictTableLoadMethod_e = 0;
46pub type ZSTD_tableFillPurpose_e = core::ffi::c_uint;
47pub const ZSTD_tfp_forCDict: ZSTD_tableFillPurpose_e = 1;
48pub const ZSTD_tfp_forCCtx: ZSTD_tableFillPurpose_e = 0;
49pub const CACHELINE_SIZE: core::ffi::c_int = 64;
50
51use libc::size_t;
52
53use crate::lib::common::fse::{FSE_CTable, FSE_repeat};
54use crate::lib::common::huf::{HUF_CElt, HUF_repeat};
55use crate::lib::common::mem::{MEM_read32, MEM_read64};
56use crate::lib::common::zstd_internal::ZSTD_REP_NUM;
57use crate::lib::compress::zstd_compress::{
58 SeqStore_t, ZSTD_MatchState_t, ZSTD_match_t, ZSTD_optimal_t,
59};
60use crate::lib::compress::zstd_compress_internal::{
61 ZSTD_OptPrice_e, ZSTD_count, ZSTD_count_2segments, ZSTD_getLowestMatchIndex,
62 ZSTD_getLowestPrefixIndex, ZSTD_hashPtr, ZSTD_index_overlap_check, ZSTD_storeSeq,
63};
64use crate::lib::zstd::{ZSTD_ParamSwitch_e, ZSTD_compressionParameters};
65pub const kSearchStrength: core::ffi::c_int = 8;
66pub const HASH_READ_SIZE: core::ffi::c_int = 8;
67pub const REPCODE1_TO_OFFBASE: core::ffi::c_int = 1;
68
69pub const ZSTD_SHORT_CACHE_TAG_BITS: core::ffi::c_int = 8;
70pub const ZSTD_SHORT_CACHE_TAG_MASK: core::ffi::c_uint =
71 ((1 as core::ffi::c_uint) << ZSTD_SHORT_CACHE_TAG_BITS).wrapping_sub(1);
72#[inline]
73unsafe fn ZSTD_writeTaggedIndex(hashTable: *mut u32, hashAndTag: size_t, index: u32) {
74 let hash = hashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS;
75 let tag = (hashAndTag & ZSTD_SHORT_CACHE_TAG_MASK as size_t) as u32;
76 *hashTable.add(hash) = index << ZSTD_SHORT_CACHE_TAG_BITS | tag;
77}
78#[inline]
79unsafe fn ZSTD_comparePackedTags(packedTag1: size_t, packedTag2: size_t) -> core::ffi::c_int {
80 let tag1 = (packedTag1 & ZSTD_SHORT_CACHE_TAG_MASK as size_t) as u32;
81 let tag2 = (packedTag2 & ZSTD_SHORT_CACHE_TAG_MASK as size_t) as u32;
82 (tag1 == tag2) as core::ffi::c_int
83}
84unsafe fn ZSTD_fillDoubleHashTableForCDict(
85 ms: &mut ZSTD_MatchState_t,
86 end: *const core::ffi::c_void,
87 dtlm: ZSTD_dictTableLoadMethod_e,
88) {
89 let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
90 let hashLarge = ms.hashTable;
91 let hBitsL = ((*cParams).hashLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
92 let mls = (*cParams).minMatch;
93 let hashSmall = ms.chainTable;
94 let hBitsS = ((*cParams).chainLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
95 let base = ms.window.base;
96 let mut ip = base.offset(ms.nextToUpdate as isize);
97 let iend = (end as *const u8).offset(-(HASH_READ_SIZE as isize));
98 let fastHashFillStep = 3;
99 while ip.offset(fastHashFillStep as isize).sub(1) <= iend {
100 let curr = ip.offset_from(base) as core::ffi::c_long as u32;
101 let mut i: u32 = 0;
102 i = 0;
103 while i < fastHashFillStep {
104 let smHashAndTag = ZSTD_hashPtr(
105 ip.offset(i as isize) as *const core::ffi::c_void,
106 hBitsS,
107 mls,
108 );
109 let lgHashAndTag =
110 ZSTD_hashPtr(ip.offset(i as isize) as *const core::ffi::c_void, hBitsL, 8);
111 if i == 0 {
112 ZSTD_writeTaggedIndex(hashSmall, smHashAndTag, curr.wrapping_add(i));
113 }
114 if i == 0 || *hashLarge.add(lgHashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS) == 0 {
115 ZSTD_writeTaggedIndex(hashLarge, lgHashAndTag, curr.wrapping_add(i));
116 }
117 if dtlm as core::ffi::c_uint == ZSTD_dtlm_fast as core::ffi::c_int as core::ffi::c_uint
118 {
119 break;
120 }
121 i = i.wrapping_add(1);
122 }
123 ip = ip.offset(fastHashFillStep as isize);
124 }
125}
126unsafe fn ZSTD_fillDoubleHashTableForCCtx(
127 ms: &mut ZSTD_MatchState_t,
128 end: *const core::ffi::c_void,
129 dtlm: ZSTD_dictTableLoadMethod_e,
130) {
131 let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
132 let hashLarge = ms.hashTable;
133 let hBitsL = (*cParams).hashLog;
134 let mls = (*cParams).minMatch;
135 let hashSmall = ms.chainTable;
136 let hBitsS = (*cParams).chainLog;
137 let base = ms.window.base;
138 let mut ip = base.offset(ms.nextToUpdate as isize);
139 let iend = (end as *const u8).offset(-(HASH_READ_SIZE as isize));
140 let fastHashFillStep = 3;
141 while ip.offset(fastHashFillStep as isize).sub(1) <= iend {
142 let curr = ip.offset_from(base) as core::ffi::c_long as u32;
143 let mut i: u32 = 0;
144 i = 0;
145 while i < fastHashFillStep {
146 let smHash = ZSTD_hashPtr(
147 ip.offset(i as isize) as *const core::ffi::c_void,
148 hBitsS,
149 mls,
150 );
151 let lgHash = ZSTD_hashPtr(ip.offset(i as isize) as *const core::ffi::c_void, hBitsL, 8);
152 if i == 0 {
153 *hashSmall.add(smHash) = curr.wrapping_add(i);
154 }
155 if i == 0 || *hashLarge.add(lgHash) == 0 {
156 *hashLarge.add(lgHash) = curr.wrapping_add(i);
157 }
158 if dtlm as core::ffi::c_uint == ZSTD_dtlm_fast as core::ffi::c_int as core::ffi::c_uint
159 {
160 break;
161 }
162 i = i.wrapping_add(1);
163 }
164 ip = ip.offset(fastHashFillStep as isize);
165 }
166}
167pub unsafe fn ZSTD_fillDoubleHashTable(
168 ms: &mut ZSTD_MatchState_t,
169 end: *const core::ffi::c_void,
170 dtlm: ZSTD_dictTableLoadMethod_e,
171 tfp: ZSTD_tableFillPurpose_e,
172) {
173 if tfp as core::ffi::c_uint == ZSTD_tfp_forCDict as core::ffi::c_int as core::ffi::c_uint {
174 ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
175 } else {
176 ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
177 }
178}
179#[inline(always)]
180unsafe fn ZSTD_compressBlock_doubleFast_noDict_generic(
181 ms: &mut ZSTD_MatchState_t,
182 seqStore: &mut SeqStore_t,
183 rep: *mut u32,
184 src: *const core::ffi::c_void,
185 srcSize: size_t,
186 mls: u32,
187) -> size_t {
188 let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
189 let hashLong = ms.hashTable;
190 let hBitsL = (*cParams).hashLog;
191 let hashSmall = ms.chainTable;
192 let hBitsS = (*cParams).chainLog;
193 let base = ms.window.base;
194 let istart = src as *const u8;
195 let mut anchor = istart;
196 let endIndex = (istart.offset_from_unsigned(base)).wrapping_add(srcSize) as u32;
197 let prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, (*cParams).windowLog);
198 let prefixLowest = base.offset(prefixLowestIndex as isize);
199 let iend = istart.add(srcSize);
200 let ilimit = iend.offset(-(HASH_READ_SIZE as isize));
201 let mut offset_1 = *rep;
202 let mut offset_2 = *rep.add(1);
203 let mut offsetSaved1 = 0;
204 let mut offsetSaved2 = 0;
205 let mut mLength: size_t = 0;
206 let mut offset: u32 = 0;
207 let mut curr: u32 = 0;
208 let kStepIncr = ((1) << kSearchStrength) as size_t;
209 let mut nextStep = core::ptr::null::<u8>();
210 let mut step: size_t = 0;
211 let mut hl0: size_t = 0;
212 let mut hl1: size_t = 0;
213 let mut idxl0: u32 = 0;
214 let mut idxl1: u32 = 0;
215 let mut matchl0 = core::ptr::null::<u8>();
216 let mut matchs0 = core::ptr::null::<u8>();
217 let mut matchl1 = core::ptr::null::<u8>();
218 let mut matchs0_safe = core::ptr::null::<u8>();
219 let mut ip = istart;
220 let mut ip1 = core::ptr::null::<u8>();
221 let dummy: [u8; 10] = [
222 0x12 as core::ffi::c_int as u8,
223 0x34 as core::ffi::c_int as u8,
224 0x56 as core::ffi::c_int as u8,
225 0x78 as core::ffi::c_int as u8,
226 0x9a as core::ffi::c_int as u8,
227 0xbc as core::ffi::c_int as u8,
228 0xde as core::ffi::c_int as u8,
229 0xf0 as core::ffi::c_int as u8,
230 0xe2 as core::ffi::c_int as u8,
231 0xb4 as core::ffi::c_int as u8,
232 ];
233 ip = ip.offset(
234 (ip.offset_from(prefixLowest) as core::ffi::c_long == 0) as core::ffi::c_int as isize,
235 );
236 let current = ip.offset_from(base) as core::ffi::c_long as u32;
237 let windowLow = ZSTD_getLowestPrefixIndex(ms, current, (*cParams).windowLog);
238 let maxRep = current.wrapping_sub(windowLow);
239 if offset_2 > maxRep {
240 offsetSaved2 = offset_2;
241 offset_2 = 0;
242 }
243 if offset_1 > maxRep {
244 offsetSaved1 = offset_1;
245 offset_1 = 0;
246 }
247 loop {
248 's_428: {
249 let mut current_block_83: u64;
250 step = 1;
251 nextStep = ip.add(kStepIncr);
252 ip1 = ip.add(step);
253 if ip1 <= ilimit {
254 hl0 = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8);
255 idxl0 = *hashLong.add(hl0);
256 matchl0 = base.offset(idxl0 as isize);
257 loop {
258 let hs0 = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls);
259 let idxs0 = *hashSmall.add(hs0);
260 curr = ip.offset_from(base) as core::ffi::c_long as u32;
261 matchs0 = base.offset(idxs0 as isize);
262 let fresh2 = &mut (*hashSmall.add(hs0));
263 *fresh2 = curr;
264 *hashLong.add(hl0) = *fresh2;
265 if (offset_1 > 0) as core::ffi::c_int
266 & (MEM_read32(
267 ip.add(1).offset(-(offset_1 as isize)) as *const core::ffi::c_void
268 ) == MEM_read32(ip.add(1) as *const core::ffi::c_void))
269 as core::ffi::c_int
270 != 0
271 {
272 mLength = (ZSTD_count(
273 ip.add(1).add(4),
274 ip.add(1).add(4).offset(-(offset_1 as isize)),
275 iend,
276 ))
277 .wrapping_add(4);
278 ip = ip.add(1);
279 ZSTD_storeSeq(
280 seqStore,
281 ip.offset_from_unsigned(anchor),
282 anchor,
283 iend,
284 REPCODE1_TO_OFFBASE as u32,
285 mLength,
286 );
287 current_block_83 = 18341544293284149774;
288 break;
289 } else {
290 hl1 = ZSTD_hashPtr(ip1 as *const core::ffi::c_void, hBitsL, 8);
291 let matchl0_safe = {
292 core::hint::select_unpredictable(
293 idxl0 >= prefixLowestIndex,
294 matchl0,
295 dummy.as_ptr(),
296 )
297 };
298 if MEM_read64(matchl0_safe as *const core::ffi::c_void)
299 == MEM_read64(ip as *const core::ffi::c_void)
300 && matchl0_safe == matchl0
301 {
302 mLength = (ZSTD_count(ip.add(8), matchl0.add(8), iend)).wrapping_add(8);
303 offset = ip.offset_from(matchl0) as core::ffi::c_long as u32;
304 while (ip > anchor) as core::ffi::c_int
305 & (matchl0 > prefixLowest) as core::ffi::c_int
306 != 0
307 && *ip.sub(1) as core::ffi::c_int
308 == *matchl0.sub(1) as core::ffi::c_int
309 {
310 ip = ip.sub(1);
311 matchl0 = matchl0.sub(1);
312 mLength = mLength.wrapping_add(1);
313 }
314 current_block_83 = 14716613436827065636;
315 break;
316 } else {
317 idxl1 = *hashLong.add(hl1);
318 matchl1 = base.offset(idxl1 as isize);
319 matchs0_safe = {
320 core::hint::select_unpredictable(
321 idxs0 >= prefixLowestIndex,
322 matchs0,
323 dummy.as_ptr(),
324 )
325 };
326 if MEM_read32(matchs0_safe as *const core::ffi::c_void)
327 == MEM_read32(ip as *const core::ffi::c_void)
328 && matchs0_safe == matchs0
329 {
330 current_block_83 = 6142208486753608565;
331 break;
332 }
333 if ip1 >= nextStep {
334 step = step.wrapping_add(1);
335 nextStep = nextStep.add(kStepIncr);
336 }
337 ip = ip1;
338 ip1 = ip1.add(step);
339 hl0 = hl1;
340 idxl0 = idxl1;
341 matchl0 = matchl1;
342 if ip1 > ilimit {
343 current_block_83 = 14575735148454673654;
344 break;
345 }
346 }
347 }
348 }
349 match current_block_83 {
350 14575735148454673654 => {}
351 _ => {
352 if current_block_83 == 6142208486753608565 {
353 mLength = (ZSTD_count(ip.add(4), matchs0.add(4), iend)).wrapping_add(4);
354 offset = ip.offset_from(matchs0) as core::ffi::c_long as u32;
355 if idxl1 > prefixLowestIndex
356 && MEM_read64(matchl1 as *const core::ffi::c_void)
357 == MEM_read64(ip1 as *const core::ffi::c_void)
358 {
359 let l1len =
360 (ZSTD_count(ip1.add(8), matchl1.add(8), iend)).wrapping_add(8);
361 if l1len > mLength {
362 ip = ip1;
363 mLength = l1len;
364 offset = ip.offset_from(matchl1) as core::ffi::c_long as u32;
365 matchs0 = matchl1;
366 }
367 }
368 while (ip > anchor) as core::ffi::c_int
369 & (matchs0 > prefixLowest) as core::ffi::c_int
370 != 0
371 && *ip.sub(1) as core::ffi::c_int
372 == *matchs0.sub(1) as core::ffi::c_int
373 {
374 ip = ip.sub(1);
375 matchs0 = matchs0.sub(1);
376 mLength = mLength.wrapping_add(1);
377 }
378 current_block_83 = 14716613436827065636;
379 }
380 if current_block_83 == 14716613436827065636 {
381 offset_2 = offset_1;
382 offset_1 = offset;
383 if step < 4 {
384 *hashLong.add(hl1) =
385 ip1.offset_from(base) as core::ffi::c_long as u32;
386 }
387 ZSTD_storeSeq(
388 seqStore,
389 ip.offset_from_unsigned(anchor),
390 anchor,
391 iend,
392 offset.wrapping_add(ZSTD_REP_NUM as u32),
393 mLength,
394 );
395 }
396 ip = ip.add(mLength);
397 anchor = ip;
398 if ip <= ilimit {
399 let indexToInsert = curr.wrapping_add(2);
400 *hashLong.add(ZSTD_hashPtr(
401 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
402 hBitsL,
403 8,
404 )) = indexToInsert;
405 *hashLong.add(ZSTD_hashPtr(
406 ip.sub(2) as *const core::ffi::c_void,
407 hBitsL,
408 8,
409 )) = ip.sub(2).offset_from(base) as core::ffi::c_long as u32;
410 *hashSmall.add(ZSTD_hashPtr(
411 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
412 hBitsS,
413 mls,
414 )) = indexToInsert;
415 *hashSmall.add(ZSTD_hashPtr(
416 ip.sub(1) as *const core::ffi::c_void,
417 hBitsS,
418 mls,
419 )) = ip.sub(1).offset_from(base) as core::ffi::c_long as u32;
420 while ip <= ilimit
421 && (offset_2 > 0) as core::ffi::c_int
422 & (MEM_read32(ip as *const core::ffi::c_void)
423 == MEM_read32(ip.offset(-(offset_2 as isize))
424 as *const core::ffi::c_void))
425 as core::ffi::c_int
426 != 0
427 {
428 let rLength = (ZSTD_count(
429 ip.add(4),
430 ip.add(4).offset(-(offset_2 as isize)),
431 iend,
432 ))
433 .wrapping_add(4);
434 core::mem::swap(&mut offset_2, &mut offset_1);
435 *hashSmall.add(ZSTD_hashPtr(
436 ip as *const core::ffi::c_void,
437 hBitsS,
438 mls,
439 )) = ip.offset_from(base) as core::ffi::c_long as u32;
440 *hashLong.add(ZSTD_hashPtr(
441 ip as *const core::ffi::c_void,
442 hBitsL,
443 8,
444 )) = ip.offset_from(base) as core::ffi::c_long as u32;
445 ZSTD_storeSeq(
446 seqStore,
447 0,
448 anchor,
449 iend,
450 REPCODE1_TO_OFFBASE as u32,
451 rLength,
452 );
453 ip = ip.add(rLength);
454 anchor = ip;
455 }
456 }
457 break 's_428;
458 }
459 }
460 }
461 offsetSaved2 = if offsetSaved1 != 0 && offset_1 != 0 {
462 offsetSaved1
463 } else {
464 offsetSaved2
465 };
466 *rep = if offset_1 != 0 {
467 offset_1
468 } else {
469 offsetSaved1
470 };
471 *rep.add(1) = if offset_2 != 0 {
472 offset_2
473 } else {
474 offsetSaved2
475 };
476 return iend.offset_from_unsigned(anchor);
477 }
478 }
479}
480#[inline(always)]
481unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_generic(
482 ms: &mut ZSTD_MatchState_t,
483 seqStore: &mut SeqStore_t,
484 rep: *mut u32,
485 src: *const core::ffi::c_void,
486 srcSize: size_t,
487 mls: u32,
488) -> size_t {
489 let mut current_block: u64;
490 let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
491 let hashLong = ms.hashTable;
492 let hBitsL = (*cParams).hashLog;
493 let hashSmall = ms.chainTable;
494 let hBitsS = (*cParams).chainLog;
495 let base = ms.window.base;
496 let istart = src as *const u8;
497 let mut ip = istart;
498 let mut anchor = istart;
499 let endIndex = (istart.wrapping_offset_from(base) as size_t).wrapping_add(srcSize) as u32;
500 let prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, (*cParams).windowLog);
501 let prefixLowest = base.wrapping_offset(prefixLowestIndex as isize);
502 let iend = istart.add(srcSize);
503 let ilimit = iend.offset(-(HASH_READ_SIZE as isize));
504 let mut offset_1 = *rep;
505 let mut offset_2 = *rep.add(1);
506 let dms = ms.dictMatchState;
507 let dictCParams: *const ZSTD_compressionParameters = &(*dms).cParams;
508 let dictHashLong: *const u32 = (*dms).hashTable;
509 let dictHashSmall: *const u32 = (*dms).chainTable;
510 let dictStartIndex = (*dms).window.dictLimit;
511 let dictBase = (*dms).window.base;
512 let dictStart = dictBase.offset(dictStartIndex as isize);
513 let dictEnd = (*dms).window.nextSrc;
514 let dictIndexDelta =
515 prefixLowestIndex.wrapping_sub(dictEnd.offset_from(dictBase) as core::ffi::c_long as u32);
516 let dictHBitsL =
517 ((*dictCParams).hashLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
518 let dictHBitsS =
519 ((*dictCParams).chainLog).wrapping_add(ZSTD_SHORT_CACHE_TAG_BITS as core::ffi::c_uint);
520 let dictAndPrefixLength = (ip.offset_from(prefixLowest) as core::ffi::c_long
521 + dictEnd.offset_from(dictStart) as core::ffi::c_long) as u32;
522 if ms.prefetchCDictTables != 0 {
523 let hashTableBytes =
524 ((1 as size_t) << (*dictCParams).hashLog).wrapping_mul(::core::mem::size_of::<u32>());
525 let chainTableBytes =
526 ((1 as size_t) << (*dictCParams).chainLog).wrapping_mul(::core::mem::size_of::<u32>());
527 let _ptr = dictHashLong as *const core::ffi::c_char;
528 let _size = hashTableBytes;
529 let mut _pos: size_t = 0;
530 _pos = 0;
531 while _pos < _size {
532 _pos = _pos.wrapping_add(CACHELINE_SIZE as size_t);
533 }
534 let _ptr_0 = dictHashSmall as *const core::ffi::c_char;
535 let _size_0 = chainTableBytes;
536 let mut _pos_0: size_t = 0;
537 _pos_0 = 0;
538 while _pos_0 < _size_0 {
539 _pos_0 = _pos_0.wrapping_add(CACHELINE_SIZE as size_t);
540 }
541 }
542 ip = ip.offset((dictAndPrefixLength == 0) as core::ffi::c_int as isize);
543 while ip < ilimit {
544 let mut mLength: size_t = 0;
545 let mut offset: u32 = 0;
546 let h2 = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8);
547 let h = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls);
548 let dictHashAndTagL = ZSTD_hashPtr(ip as *const core::ffi::c_void, dictHBitsL, 8);
549 let dictHashAndTagS = ZSTD_hashPtr(ip as *const core::ffi::c_void, dictHBitsS, mls);
550 let dictMatchIndexAndTagL = *dictHashLong.add(dictHashAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS);
551 let dictMatchIndexAndTagS =
552 *dictHashSmall.add(dictHashAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS);
553 let dictTagsMatchL =
554 ZSTD_comparePackedTags(dictMatchIndexAndTagL as size_t, dictHashAndTagL);
555 let dictTagsMatchS =
556 ZSTD_comparePackedTags(dictMatchIndexAndTagS as size_t, dictHashAndTagS);
557 let curr = ip.wrapping_offset_from(base) as core::ffi::c_long as u32;
558 let matchIndexL = *hashLong.add(h2);
559 let mut matchIndexS = *hashSmall.add(h);
560 let mut matchLong = base.wrapping_offset(matchIndexL as isize);
561 let mut match_0 = base.wrapping_offset(matchIndexS as isize);
562 let repIndex = curr.wrapping_add(1).wrapping_sub(offset_1);
563 let repMatch = if repIndex < prefixLowestIndex {
564 dictBase.offset(repIndex.wrapping_sub(dictIndexDelta) as isize)
565 } else {
566 base.wrapping_offset(repIndex as isize)
567 };
568 let fresh3 = &mut (*hashSmall.add(h));
569 *fresh3 = curr;
570 *hashLong.add(h2) = *fresh3;
571 if ZSTD_index_overlap_check(prefixLowestIndex, repIndex) != 0
572 && MEM_read32(repMatch as *const core::ffi::c_void)
573 == MEM_read32(ip.add(1) as *const core::ffi::c_void)
574 {
575 let repMatchEnd = if repIndex < prefixLowestIndex {
576 dictEnd
577 } else {
578 iend
579 };
580 mLength = (ZSTD_count_2segments(
581 ip.add(1).add(4),
582 repMatch.add(4),
583 iend,
584 repMatchEnd,
585 prefixLowest,
586 ))
587 .wrapping_add(4);
588 ip = ip.add(1);
589 ZSTD_storeSeq(
590 seqStore,
591 ip.offset_from_unsigned(anchor),
592 anchor,
593 iend,
594 REPCODE1_TO_OFFBASE as u32,
595 mLength,
596 );
597 } else {
598 if matchIndexL >= prefixLowestIndex
599 && MEM_read64(matchLong as *const core::ffi::c_void)
600 == MEM_read64(ip as *const core::ffi::c_void)
601 {
602 mLength = (ZSTD_count(ip.add(8), matchLong.add(8), iend)).wrapping_add(8);
603 offset = ip.offset_from(matchLong) as core::ffi::c_long as u32;
604 while (ip > anchor) as core::ffi::c_int
605 & (matchLong > prefixLowest) as core::ffi::c_int
606 != 0
607 && *ip.sub(1) as core::ffi::c_int == *matchLong.sub(1) as core::ffi::c_int
608 {
609 ip = ip.sub(1);
610 matchLong = matchLong.sub(1);
611 mLength = mLength.wrapping_add(1);
612 }
613 } else {
614 if dictTagsMatchL != 0 {
615 let dictMatchIndexL = dictMatchIndexAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS;
616 let mut dictMatchL = dictBase.offset(dictMatchIndexL as isize);
617 if dictMatchL > dictStart
618 && MEM_read64(dictMatchL as *const core::ffi::c_void)
619 == MEM_read64(ip as *const core::ffi::c_void)
620 {
621 mLength = (ZSTD_count_2segments(
622 ip.add(8),
623 dictMatchL.add(8),
624 iend,
625 dictEnd,
626 prefixLowest,
627 ))
628 .wrapping_add(8);
629 offset = curr
630 .wrapping_sub(dictMatchIndexL)
631 .wrapping_sub(dictIndexDelta);
632 while (ip > anchor) as core::ffi::c_int
633 & (dictMatchL > dictStart) as core::ffi::c_int
634 != 0
635 && *ip.sub(1) as core::ffi::c_int
636 == *dictMatchL.sub(1) as core::ffi::c_int
637 {
638 ip = ip.sub(1);
639 dictMatchL = dictMatchL.sub(1);
640 mLength = mLength.wrapping_add(1);
641 }
642 current_block = 17830677668754335218;
643 } else {
644 current_block = 6721012065216013753;
645 }
646 } else {
647 current_block = 6721012065216013753;
648 }
649 match current_block {
650 17830677668754335218 => {}
651 _ => {
652 if matchIndexS > prefixLowestIndex {
653 if MEM_read32(match_0 as *const core::ffi::c_void)
654 == MEM_read32(ip as *const core::ffi::c_void)
655 {
656 current_block = 2631791190359682872;
657 } else {
658 current_block = 5372832139739605200;
659 }
660 } else if dictTagsMatchS != 0 {
661 let dictMatchIndexS =
662 dictMatchIndexAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS;
663 match_0 = dictBase.offset(dictMatchIndexS as isize);
664 matchIndexS = dictMatchIndexS.wrapping_add(dictIndexDelta);
665 if match_0 > dictStart
666 && MEM_read32(match_0 as *const core::ffi::c_void)
667 == MEM_read32(ip as *const core::ffi::c_void)
668 {
669 current_block = 2631791190359682872;
670 } else {
671 current_block = 5372832139739605200;
672 }
673 } else {
674 current_block = 5372832139739605200;
675 }
676 match current_block {
677 5372832139739605200 => {
678 ip = ip.offset(
679 ((ip.offset_from(anchor) as core::ffi::c_long
680 >> kSearchStrength)
681 + 1) as isize,
682 );
683 continue;
684 }
685 _ => {
686 let hl3 =
687 ZSTD_hashPtr(ip.add(1) as *const core::ffi::c_void, hBitsL, 8);
688 let dictHashAndTagL3 = ZSTD_hashPtr(
689 ip.add(1) as *const core::ffi::c_void,
690 dictHBitsL,
691 8,
692 );
693 let matchIndexL3 = *hashLong.add(hl3);
694 let dictMatchIndexAndTagL3 = *dictHashLong
695 .add(dictHashAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS);
696 let dictTagsMatchL3 = ZSTD_comparePackedTags(
697 dictMatchIndexAndTagL3 as size_t,
698 dictHashAndTagL3,
699 );
700 let mut matchL3 = base.wrapping_offset(matchIndexL3 as isize);
701 *hashLong.add(hl3) = curr.wrapping_add(1);
702 if matchIndexL3 >= prefixLowestIndex
703 && MEM_read64(matchL3 as *const core::ffi::c_void)
704 == MEM_read64(ip.add(1) as *const core::ffi::c_void)
705 {
706 mLength = (ZSTD_count(ip.add(9), matchL3.add(8), iend))
707 .wrapping_add(8);
708 ip = ip.add(1);
709 offset = ip.offset_from(matchL3) as core::ffi::c_long as u32;
710 while (ip > anchor) as core::ffi::c_int
711 & (matchL3 > prefixLowest) as core::ffi::c_int
712 != 0
713 && *ip.sub(1) as core::ffi::c_int
714 == *matchL3.sub(1) as core::ffi::c_int
715 {
716 ip = ip.sub(1);
717 matchL3 = matchL3.sub(1);
718 mLength = mLength.wrapping_add(1);
719 }
720 } else {
721 if dictTagsMatchL3 != 0 {
722 let dictMatchIndexL3 =
723 dictMatchIndexAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS;
724 let mut dictMatchL3 =
725 dictBase.offset(dictMatchIndexL3 as isize);
726 if dictMatchL3 > dictStart
727 && MEM_read64(dictMatchL3 as *const core::ffi::c_void)
728 == MEM_read64(ip.add(1) as *const core::ffi::c_void)
729 {
730 mLength = (ZSTD_count_2segments(
731 ip.add(1).add(8),
732 dictMatchL3.add(8),
733 iend,
734 dictEnd,
735 prefixLowest,
736 ))
737 .wrapping_add(8);
738 ip = ip.add(1);
739 offset = curr
740 .wrapping_add(1)
741 .wrapping_sub(dictMatchIndexL3)
742 .wrapping_sub(dictIndexDelta);
743 while (ip > anchor) as core::ffi::c_int
744 & (dictMatchL3 > dictStart) as core::ffi::c_int
745 != 0
746 && *ip.sub(1) as core::ffi::c_int
747 == *dictMatchL3.sub(1) as core::ffi::c_int
748 {
749 ip = ip.sub(1);
750 dictMatchL3 = dictMatchL3.sub(1);
751 mLength = mLength.wrapping_add(1);
752 }
753 current_block = 17830677668754335218;
754 } else {
755 current_block = 1209030638129645089;
756 }
757 } else {
758 current_block = 1209030638129645089;
759 }
760 match current_block {
761 17830677668754335218 => {}
762 _ => {
763 if matchIndexS < prefixLowestIndex {
764 mLength = (ZSTD_count_2segments(
765 ip.add(4),
766 match_0.add(4),
767 iend,
768 dictEnd,
769 prefixLowest,
770 ))
771 .wrapping_add(4);
772 offset = curr.wrapping_sub(matchIndexS);
773 while (ip > anchor) as core::ffi::c_int
774 & (match_0 > dictStart) as core::ffi::c_int
775 != 0
776 && *ip.sub(1) as core::ffi::c_int
777 == *match_0.sub(1) as core::ffi::c_int
778 {
779 ip = ip.sub(1);
780 match_0 = match_0.sub(1);
781 mLength = mLength.wrapping_add(1);
782 }
783 } else {
784 mLength =
785 (ZSTD_count(ip.add(4), match_0.add(4), iend))
786 .wrapping_add(4);
787 offset = ip.offset_from(match_0)
788 as core::ffi::c_long
789 as u32;
790 while (ip > anchor) as core::ffi::c_int
791 & (match_0 > prefixLowest) as core::ffi::c_int
792 != 0
793 && *ip.sub(1) as core::ffi::c_int
794 == *match_0.sub(1) as core::ffi::c_int
795 {
796 ip = ip.sub(1);
797 match_0 = match_0.sub(1);
798 mLength = mLength.wrapping_add(1);
799 }
800 }
801 }
802 }
803 }
804 }
805 }
806 }
807 }
808 }
809 offset_2 = offset_1;
810 offset_1 = offset;
811 ZSTD_storeSeq(
812 seqStore,
813 ip.offset_from_unsigned(anchor),
814 anchor,
815 iend,
816 offset.wrapping_add(ZSTD_REP_NUM as u32),
817 mLength,
818 );
819 }
820 ip = ip.add(mLength);
821 anchor = ip;
822 if ip <= ilimit {
823 let indexToInsert = curr.wrapping_add(2);
824 *hashLong.add(ZSTD_hashPtr(
825 base.wrapping_add(indexToInsert as usize) as *const core::ffi::c_void,
826 hBitsL,
827 8,
828 )) = indexToInsert;
829 *hashLong.add(ZSTD_hashPtr(
830 ip.sub(2) as *const core::ffi::c_void,
831 hBitsL,
832 8,
833 )) = ip.sub(2).wrapping_offset_from(base) as core::ffi::c_long as u32;
834 *hashSmall.add(ZSTD_hashPtr(
835 base.wrapping_offset(indexToInsert as isize) as *const core::ffi::c_void,
836 hBitsS,
837 mls,
838 )) = indexToInsert;
839 *hashSmall.add(ZSTD_hashPtr(
840 ip.sub(1) as *const core::ffi::c_void,
841 hBitsS,
842 mls,
843 )) = ip.sub(1).wrapping_offset_from(base) as core::ffi::c_long as u32;
844 while ip <= ilimit {
845 let current2 = ip.wrapping_offset_from(base) as core::ffi::c_long as u32;
846 let repIndex2 = current2.wrapping_sub(offset_2);
847 let repMatch2 = if repIndex2 < prefixLowestIndex {
848 dictBase
849 .offset(repIndex2 as isize)
850 .offset(-(dictIndexDelta as isize))
851 } else {
852 base.wrapping_offset(repIndex2 as isize)
853 };
854 if !(ZSTD_index_overlap_check(prefixLowestIndex, repIndex2) != 0
855 && MEM_read32(repMatch2 as *const core::ffi::c_void)
856 == MEM_read32(ip as *const core::ffi::c_void))
857 {
858 break;
859 }
860 let repEnd2 = if repIndex2 < prefixLowestIndex {
861 dictEnd
862 } else {
863 iend
864 };
865 let repLength2 = (ZSTD_count_2segments(
866 ip.add(4),
867 repMatch2.add(4),
868 iend,
869 repEnd2,
870 prefixLowest,
871 ))
872 .wrapping_add(4);
873 core::mem::swap(&mut offset_2, &mut offset_1);
874 ZSTD_storeSeq(
875 seqStore,
876 0,
877 anchor,
878 iend,
879 REPCODE1_TO_OFFBASE as u32,
880 repLength2,
881 );
882 *hashSmall.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls)) =
883 current2;
884 *hashLong.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8)) = current2;
885 ip = ip.add(repLength2);
886 anchor = ip;
887 }
888 }
889 }
890 *rep = offset_1;
891 *rep.add(1) = offset_2;
892 iend.offset_from_unsigned(anchor)
893}
894unsafe fn ZSTD_compressBlock_doubleFast_noDict_4(
895 ms: &mut ZSTD_MatchState_t,
896 seqStore: &mut SeqStore_t,
897 rep: *mut u32,
898 src: *const core::ffi::c_void,
899 srcSize: size_t,
900) -> size_t {
901 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 4)
902}
903unsafe fn ZSTD_compressBlock_doubleFast_noDict_5(
904 ms: &mut ZSTD_MatchState_t,
905 seqStore: &mut SeqStore_t,
906 rep: *mut u32,
907 src: *const core::ffi::c_void,
908 srcSize: size_t,
909) -> size_t {
910 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 5)
911}
912unsafe fn ZSTD_compressBlock_doubleFast_noDict_6(
913 ms: &mut ZSTD_MatchState_t,
914 seqStore: &mut SeqStore_t,
915 rep: *mut u32,
916 src: *const core::ffi::c_void,
917 srcSize: size_t,
918) -> size_t {
919 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 6)
920}
921unsafe fn ZSTD_compressBlock_doubleFast_noDict_7(
922 ms: &mut ZSTD_MatchState_t,
923 seqStore: &mut SeqStore_t,
924 rep: *mut u32,
925 src: *const core::ffi::c_void,
926 srcSize: size_t,
927) -> size_t {
928 ZSTD_compressBlock_doubleFast_noDict_generic(ms, seqStore, rep, src, srcSize, 7)
929}
930unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_4(
931 ms: &mut ZSTD_MatchState_t,
932 seqStore: &mut SeqStore_t,
933 rep: *mut u32,
934 src: *const core::ffi::c_void,
935 srcSize: size_t,
936) -> size_t {
937 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 4)
938}
939unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_5(
940 ms: &mut ZSTD_MatchState_t,
941 seqStore: &mut SeqStore_t,
942 rep: *mut u32,
943 src: *const core::ffi::c_void,
944 srcSize: size_t,
945) -> size_t {
946 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 5)
947}
948unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_6(
949 ms: &mut ZSTD_MatchState_t,
950 seqStore: &mut SeqStore_t,
951 rep: *mut u32,
952 src: *const core::ffi::c_void,
953 srcSize: size_t,
954) -> size_t {
955 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 6)
956}
957unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState_7(
958 ms: &mut ZSTD_MatchState_t,
959 seqStore: &mut SeqStore_t,
960 rep: *mut u32,
961 src: *const core::ffi::c_void,
962 srcSize: size_t,
963) -> size_t {
964 ZSTD_compressBlock_doubleFast_dictMatchState_generic(ms, seqStore, rep, src, srcSize, 7)
965}
966pub unsafe fn ZSTD_compressBlock_doubleFast(
967 ms: &mut ZSTD_MatchState_t,
968 seqStore: &mut SeqStore_t,
969 rep: *mut u32,
970 src: *const core::ffi::c_void,
971 srcSize: size_t,
972) -> size_t {
973 let mls = ms.cParams.minMatch;
974 match mls {
975 5 => ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize),
976 6 => ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize),
977 7 => ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize),
978 _ => ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize),
979 }
980}
981pub unsafe fn ZSTD_compressBlock_doubleFast_dictMatchState(
982 ms: &mut ZSTD_MatchState_t,
983 seqStore: &mut SeqStore_t,
984 rep: *mut u32,
985 src: *const core::ffi::c_void,
986 srcSize: size_t,
987) -> size_t {
988 let mls = ms.cParams.minMatch;
989 match mls {
990 5 => ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize),
991 6 => ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize),
992 7 => ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize),
993 _ => ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize),
994 }
995}
996unsafe fn ZSTD_compressBlock_doubleFast_extDict_generic(
997 ms: &mut ZSTD_MatchState_t,
998 seqStore: &mut SeqStore_t,
999 rep: *mut u32,
1000 src: *const core::ffi::c_void,
1001 srcSize: size_t,
1002 mls: u32,
1003) -> size_t {
1004 let cParams: *const ZSTD_compressionParameters = &mut ms.cParams;
1005 let hashLong = ms.hashTable;
1006 let hBitsL = (*cParams).hashLog;
1007 let hashSmall = ms.chainTable;
1008 let hBitsS = (*cParams).chainLog;
1009 let istart = src as *const u8;
1010 let mut ip = istart;
1011 let mut anchor = istart;
1012 let iend = istart.add(srcSize);
1013 let ilimit = iend.sub(8);
1014 let base = ms.window.base;
1015 let endIndex = (istart.wrapping_offset_from(base) as size_t).wrapping_add(srcSize) as u32;
1016 let lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, (*cParams).windowLog);
1017 let dictStartIndex = lowLimit;
1018 let dictLimit = ms.window.dictLimit;
1019 let prefixStartIndex = if dictLimit > lowLimit {
1020 dictLimit
1021 } else {
1022 lowLimit
1023 };
1024 let prefixStart = base.wrapping_offset(prefixStartIndex as isize);
1025 let dictBase = ms.window.dictBase;
1026 let dictStart = dictBase.wrapping_offset(dictStartIndex as isize);
1027 let dictEnd = dictBase.wrapping_offset(prefixStartIndex as isize);
1028 let mut offset_1 = *rep;
1029 let mut offset_2 = *rep.add(1);
1030 if prefixStartIndex == dictStartIndex {
1031 return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize);
1032 }
1033 while ip < ilimit {
1034 let hSmall = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls);
1035 let matchIndex = *hashSmall.add(hSmall);
1036 let matchBase = if matchIndex < prefixStartIndex {
1037 dictBase
1038 } else {
1039 base
1040 };
1041 let mut match_0 = matchBase.offset(matchIndex as isize);
1042 let hLong = ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8);
1043 let matchLongIndex = *hashLong.add(hLong);
1044 let matchLongBase = if matchLongIndex < prefixStartIndex {
1045 dictBase
1046 } else {
1047 base
1048 };
1049 let mut matchLong = matchLongBase.offset(matchLongIndex as isize);
1050 let curr = ip.wrapping_offset_from(base) as core::ffi::c_long as u32;
1051 let repIndex = curr.wrapping_add(1).wrapping_sub(offset_1);
1052 let repBase = if repIndex < prefixStartIndex {
1053 dictBase
1054 } else {
1055 base
1056 };
1057 let repMatch = repBase.wrapping_offset(repIndex as isize);
1058 let mut mLength: size_t = 0;
1059 let fresh4 = &mut (*hashLong.add(hLong));
1060 *fresh4 = curr;
1061 *hashSmall.add(hSmall) = *fresh4;
1062 if ZSTD_index_overlap_check(prefixStartIndex, repIndex)
1063 & (offset_1 <= curr.wrapping_add(1).wrapping_sub(dictStartIndex)) as core::ffi::c_int
1064 != 0
1065 && MEM_read32(repMatch as *const core::ffi::c_void)
1066 == MEM_read32(ip.add(1) as *const core::ffi::c_void)
1067 {
1068 let repMatchEnd = if repIndex < prefixStartIndex {
1069 dictEnd
1070 } else {
1071 iend
1072 };
1073 mLength = (ZSTD_count_2segments(
1074 ip.add(1).add(4),
1075 repMatch.add(4),
1076 iend,
1077 repMatchEnd,
1078 prefixStart,
1079 ))
1080 .wrapping_add(4);
1081 ip = ip.add(1);
1082 ZSTD_storeSeq(
1083 seqStore,
1084 ip.offset_from_unsigned(anchor),
1085 anchor,
1086 iend,
1087 REPCODE1_TO_OFFBASE as u32,
1088 mLength,
1089 );
1090 } else if matchLongIndex > dictStartIndex
1091 && MEM_read64(matchLong as *const core::ffi::c_void)
1092 == MEM_read64(ip as *const core::ffi::c_void)
1093 {
1094 let matchEnd = if matchLongIndex < prefixStartIndex {
1095 dictEnd
1096 } else {
1097 iend
1098 };
1099 let lowMatchPtr = if matchLongIndex < prefixStartIndex {
1100 dictStart
1101 } else {
1102 prefixStart
1103 };
1104 let mut offset: u32 = 0;
1105 mLength =
1106 (ZSTD_count_2segments(ip.add(8), matchLong.add(8), iend, matchEnd, prefixStart))
1107 .wrapping_add(8);
1108 offset = curr.wrapping_sub(matchLongIndex);
1109 while (ip > anchor) as core::ffi::c_int & (matchLong > lowMatchPtr) as core::ffi::c_int
1110 != 0
1111 && *ip.sub(1) as core::ffi::c_int == *matchLong.sub(1) as core::ffi::c_int
1112 {
1113 ip = ip.sub(1);
1114 matchLong = matchLong.sub(1);
1115 mLength = mLength.wrapping_add(1);
1116 }
1117 offset_2 = offset_1;
1118 offset_1 = offset;
1119 ZSTD_storeSeq(
1120 seqStore,
1121 ip.offset_from_unsigned(anchor),
1122 anchor,
1123 iend,
1124 offset.wrapping_add(ZSTD_REP_NUM as u32),
1125 mLength,
1126 );
1127 } else if matchIndex > dictStartIndex
1128 && MEM_read32(match_0 as *const core::ffi::c_void)
1129 == MEM_read32(ip as *const core::ffi::c_void)
1130 {
1131 let h3 = ZSTD_hashPtr(ip.add(1) as *const core::ffi::c_void, hBitsL, 8);
1132 let matchIndex3 = *hashLong.add(h3);
1133 let match3Base = if matchIndex3 < prefixStartIndex {
1134 dictBase
1135 } else {
1136 base
1137 };
1138 let mut match3 = match3Base.offset(matchIndex3 as isize);
1139 let mut offset_0: u32 = 0;
1140 *hashLong.add(h3) = curr.wrapping_add(1);
1141 if matchIndex3 > dictStartIndex
1142 && MEM_read64(match3 as *const core::ffi::c_void)
1143 == MEM_read64(ip.add(1) as *const core::ffi::c_void)
1144 {
1145 let matchEnd_0 = if matchIndex3 < prefixStartIndex {
1146 dictEnd
1147 } else {
1148 iend
1149 };
1150 let lowMatchPtr_0 = if matchIndex3 < prefixStartIndex {
1151 dictStart
1152 } else {
1153 prefixStart
1154 };
1155 mLength =
1156 (ZSTD_count_2segments(ip.add(9), match3.add(8), iend, matchEnd_0, prefixStart))
1157 .wrapping_add(8);
1158 ip = ip.add(1);
1159 offset_0 = curr.wrapping_add(1).wrapping_sub(matchIndex3);
1160 while (ip > anchor) as core::ffi::c_int
1161 & (match3 > lowMatchPtr_0) as core::ffi::c_int
1162 != 0
1163 && *ip.sub(1) as core::ffi::c_int == *match3.sub(1) as core::ffi::c_int
1164 {
1165 ip = ip.sub(1);
1166 match3 = match3.sub(1);
1167 mLength = mLength.wrapping_add(1);
1168 }
1169 } else {
1170 let matchEnd_1 = if matchIndex < prefixStartIndex {
1171 dictEnd
1172 } else {
1173 iend
1174 };
1175 let lowMatchPtr_1 = if matchIndex < prefixStartIndex {
1176 dictStart
1177 } else {
1178 prefixStart
1179 };
1180 mLength = (ZSTD_count_2segments(
1181 ip.add(4),
1182 match_0.add(4),
1183 iend,
1184 matchEnd_1,
1185 prefixStart,
1186 ))
1187 .wrapping_add(4);
1188 offset_0 = curr.wrapping_sub(matchIndex);
1189 while (ip > anchor) as core::ffi::c_int
1190 & (match_0 > lowMatchPtr_1) as core::ffi::c_int
1191 != 0
1192 && *ip.sub(1) as core::ffi::c_int == *match_0.sub(1) as core::ffi::c_int
1193 {
1194 ip = ip.sub(1);
1195 match_0 = match_0.sub(1);
1196 mLength = mLength.wrapping_add(1);
1197 }
1198 }
1199 offset_2 = offset_1;
1200 offset_1 = offset_0;
1201 ZSTD_storeSeq(
1202 seqStore,
1203 ip.offset_from_unsigned(anchor),
1204 anchor,
1205 iend,
1206 offset_0.wrapping_add(ZSTD_REP_NUM as u32),
1207 mLength,
1208 );
1209 } else {
1210 ip = ip.offset(
1211 ((ip.offset_from(anchor) as core::ffi::c_long >> kSearchStrength) + 1) as isize,
1212 );
1213 continue;
1214 }
1215 ip = ip.add(mLength);
1216 anchor = ip;
1217 if ip <= ilimit {
1218 let indexToInsert = curr.wrapping_add(2);
1219 *hashLong.add(ZSTD_hashPtr(
1220 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
1221 hBitsL,
1222 8,
1223 )) = indexToInsert;
1224 *hashLong.add(ZSTD_hashPtr(
1225 ip.sub(2) as *const core::ffi::c_void,
1226 hBitsL,
1227 8,
1228 )) = ip.sub(2).offset_from(base) as core::ffi::c_long as u32;
1229 *hashSmall.add(ZSTD_hashPtr(
1230 base.offset(indexToInsert as isize) as *const core::ffi::c_void,
1231 hBitsS,
1232 mls,
1233 )) = indexToInsert;
1234 *hashSmall.add(ZSTD_hashPtr(
1235 ip.sub(1) as *const core::ffi::c_void,
1236 hBitsS,
1237 mls,
1238 )) = ip.sub(1).offset_from(base) as core::ffi::c_long as u32;
1239 while ip <= ilimit {
1240 let current2 = ip.offset_from(base) as core::ffi::c_long as u32;
1241 let repIndex2 = current2.wrapping_sub(offset_2);
1242 let repMatch2 = if repIndex2 < prefixStartIndex {
1243 dictBase.offset(repIndex2 as isize)
1244 } else {
1245 base.offset(repIndex2 as isize)
1246 };
1247 if !(ZSTD_index_overlap_check(prefixStartIndex, repIndex2)
1248 & (offset_2 <= current2.wrapping_sub(dictStartIndex)) as core::ffi::c_int
1249 != 0
1250 && MEM_read32(repMatch2 as *const core::ffi::c_void)
1251 == MEM_read32(ip as *const core::ffi::c_void))
1252 {
1253 break;
1254 }
1255 let repEnd2 = if repIndex2 < prefixStartIndex {
1256 dictEnd
1257 } else {
1258 iend
1259 };
1260 let repLength2 =
1261 (ZSTD_count_2segments(ip.add(4), repMatch2.add(4), iend, repEnd2, prefixStart))
1262 .wrapping_add(4);
1263 core::mem::swap(&mut offset_2, &mut offset_1);
1264 ZSTD_storeSeq(
1265 seqStore,
1266 0,
1267 anchor,
1268 iend,
1269 REPCODE1_TO_OFFBASE as u32,
1270 repLength2,
1271 );
1272 *hashSmall.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsS, mls)) =
1273 current2;
1274 *hashLong.add(ZSTD_hashPtr(ip as *const core::ffi::c_void, hBitsL, 8)) = current2;
1275 ip = ip.add(repLength2);
1276 anchor = ip;
1277 }
1278 }
1279 }
1280 *rep = offset_1;
1281 *rep.add(1) = offset_2;
1282 iend.offset_from_unsigned(anchor)
1283}
1284unsafe fn ZSTD_compressBlock_doubleFast_extDict_4(
1285 ms: &mut ZSTD_MatchState_t,
1286 seqStore: &mut SeqStore_t,
1287 rep: *mut u32,
1288 src: *const core::ffi::c_void,
1289 srcSize: size_t,
1290) -> size_t {
1291 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 4)
1292}
1293unsafe fn ZSTD_compressBlock_doubleFast_extDict_5(
1294 ms: &mut ZSTD_MatchState_t,
1295 seqStore: &mut SeqStore_t,
1296 rep: *mut u32,
1297 src: *const core::ffi::c_void,
1298 srcSize: size_t,
1299) -> size_t {
1300 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 5)
1301}
1302unsafe fn ZSTD_compressBlock_doubleFast_extDict_6(
1303 ms: &mut ZSTD_MatchState_t,
1304 seqStore: &mut SeqStore_t,
1305 rep: *mut u32,
1306 src: *const core::ffi::c_void,
1307 srcSize: size_t,
1308) -> size_t {
1309 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 6)
1310}
1311unsafe fn ZSTD_compressBlock_doubleFast_extDict_7(
1312 ms: &mut ZSTD_MatchState_t,
1313 seqStore: &mut SeqStore_t,
1314 rep: *mut u32,
1315 src: *const core::ffi::c_void,
1316 srcSize: size_t,
1317) -> size_t {
1318 ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 7)
1319}
1320pub unsafe fn ZSTD_compressBlock_doubleFast_extDict(
1321 ms: &mut ZSTD_MatchState_t,
1322 seqStore: &mut SeqStore_t,
1323 rep: *mut u32,
1324 src: *const core::ffi::c_void,
1325 srcSize: size_t,
1326) -> size_t {
1327 let mls = ms.cParams.minMatch;
1328 match mls {
1329 5 => ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize),
1330 6 => ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize),
1331 7 => ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize),
1332 _ => ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize),
1333 }
1334}