14#ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
21 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
24 U32 const mls = cParams->minMatch;
30 const U32 fastHashFillStep = 3;
36 for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
39 for (i = 0; i < fastHashFillStep; ++i) {
40 size_t const smHashAndTag =
ZSTD_hashPtr(ip + i, hBitsS, mls);
41 size_t const lgHashAndTag =
ZSTD_hashPtr(ip + i, hBitsL, 8);
59 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
61 U32 const hBitsL = cParams->hashLog;
62 U32 const mls = cParams->minMatch;
64 U32 const hBitsS = cParams->chainLog;
68 const U32 fastHashFillStep = 3;
74 for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
77 for (i = 0; i < fastHashFillStep; ++i) {
81 hashSmall[smHash] =
curr + i;
82 if (i == 0 || hashLarge[lgHash] == 0)
83 hashLarge[lgHash] =
curr + i;
91 const void*
const end,
96 ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
98 ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
107 void const* src,
size_t srcSize,
U32 const mls )
109 ZSTD_compressionParameters
const* cParams = &ms->
cParams;
111 const U32 hBitsL = cParams->hashLog;
113 const U32 hBitsS = cParams->chainLog;
115 const BYTE*
const istart = (
const BYTE*)src;
116 const BYTE* anchor = istart;
117 const U32 endIndex = (
U32)((
size_t)(istart - base) + srcSize);
120 const BYTE*
const prefixLowest = base + prefixLowestIndex;
121 const BYTE*
const iend = istart + srcSize;
123 U32 offset_1=rep[0], offset_2=rep[1];
124 U32 offsetSaved1 = 0, offsetSaved2 = 0;
133 const BYTE* nextStep;
146 const BYTE* ip = istart;
149 DEBUGLOG(5,
"ZSTD_compressBlock_doubleFast_noDict_generic");
152 ip += ((ip - prefixLowest) == 0);
154 U32 const current = (
U32)(ip - base);
156 U32 const maxRep = current - windowLow;
157 if (offset_2 > maxRep) offsetSaved2 = offset_2, offset_2 = 0;
158 if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
164 nextStep = ip + kStepIncr;
172 idxl0 = hashLong[hl0];
173 matchl0 = base + idxl0;
178 const U32 idxs0 = hashSmall[hs0];
179 curr = (
U32)(ip-base);
180 matchs0 = base + idxs0;
182 hashLong[hl0] = hashSmall[hs0] = curr;
186 mLength =
ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
194 if (idxl0 > prefixLowestIndex) {
197 mLength =
ZSTD_count(ip+8, matchl0+8, iend) + 8;
198 offset = (
U32)(ip-matchl0);
199 while (((ip>anchor) & (matchl0>prefixLowest)) && (ip[-1] == matchl0[-1])) { ip--; matchl0--; mLength++; }
204 idxl1 = hashLong[hl1];
205 matchl1 = base + idxl1;
207 if (idxs0 > prefixLowestIndex) {
210 goto _search_next_long;
214 if (ip1 >= nextStep) {
218 nextStep += kStepIncr;
226 #if defined(__aarch64__)
229 }
while (ip1 <= ilimit);
234 offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
237 rep[0] = offset_1 ? offset_1 : offsetSaved1;
238 rep[1] = offset_2 ? offset_2 : offsetSaved2;
241 return (
size_t)(iend - anchor);
246 if (idxl1 > prefixLowestIndex) {
249 mLength =
ZSTD_count(ip+8, matchl1+8, iend) + 8;
250 offset = (
U32)(ip-matchl1);
251 while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; }
257 mLength =
ZSTD_count(ip+4, matchs0+4, iend) + 4;
258 offset = (
U32)(ip - matchs0);
259 while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; }
275 hashLong[hl1] = (
U32)(ip1 - base);
288 {
U32 const indexToInsert = curr+2;
289 hashLong[
ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
291 hashSmall[
ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
296 while ( (ip <= ilimit)
300 size_t const rLength =
ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
301 U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff;
318 void const* src,
size_t srcSize,
321 ZSTD_compressionParameters
const* cParams = &ms->
cParams;
323 const U32 hBitsL = cParams->hashLog;
325 const U32 hBitsS = cParams->chainLog;
327 const BYTE*
const istart = (
const BYTE*)src;
328 const BYTE* ip = istart;
329 const BYTE* anchor = istart;
330 const U32 endIndex = (
U32)((
size_t)(istart - base) + srcSize);
333 const BYTE*
const prefixLowest = base + prefixLowestIndex;
334 const BYTE*
const iend = istart + srcSize;
336 U32 offset_1=rep[0], offset_2=rep[1];
339 const ZSTD_compressionParameters*
const dictCParams = &dms->
cParams;
344 const BYTE*
const dictStart = dictBase + dictStartIndex;
346 const U32 dictIndexDelta = prefixLowestIndex - (
U32)(dictEnd - dictBase);
349 const U32 dictAndPrefixLength = (
U32)((ip - prefixLowest) + (dictEnd - dictStart));
351 DEBUGLOG(5,
"ZSTD_compressBlock_doubleFast_dictMatchState_generic");
357 size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) *
sizeof(
U32);
358 size_t const chainTableBytes = (((size_t)1) << dictCParams->chainLog) *
sizeof(
U32);
364 ip += (dictAndPrefixLength == 0);
368 assert(offset_1 <= dictAndPrefixLength);
369 assert(offset_2 <= dictAndPrefixLength);
372 while (ip < ilimit) {
377 size_t const dictHashAndTagL =
ZSTD_hashPtr(ip, dictHBitsL, 8);
378 size_t const dictHashAndTagS =
ZSTD_hashPtr(ip, dictHBitsS, mls);
383 U32 const curr = (
U32)(ip-base);
384 U32 const matchIndexL = hashLong[h2];
385 U32 matchIndexS = hashSmall[h];
386 const BYTE* matchLong = base + matchIndexL;
387 const BYTE* match = base + matchIndexS;
388 const U32 repIndex = curr + 1 - offset_1;
389 const BYTE* repMatch = (repIndex < prefixLowestIndex) ?
390 dictBase + (repIndex - dictIndexDelta) :
392 hashLong[h2] = hashSmall[h] = curr;
395 if (((
U32)((prefixLowestIndex-1) - repIndex) >= 3 )
397 const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
404 if (matchIndexL > prefixLowestIndex) {
407 mLength =
ZSTD_count(ip+8, matchLong+8, iend) + 8;
408 offset = (
U32)(ip-matchLong);
409 while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; }
412 }
else if (dictTagsMatchL) {
415 const BYTE* dictMatchL = dictBase + dictMatchIndexL;
416 assert(dictMatchL < dictEnd);
420 offset = (
U32)(curr - dictMatchIndexL - dictIndexDelta);
421 while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; }
425 if (matchIndexS > prefixLowestIndex) {
428 goto _search_next_long;
430 }
else if (dictTagsMatchS) {
433 match = dictBase + dictMatchIndexS;
434 matchIndexS = dictMatchIndexS + dictIndexDelta;
437 goto _search_next_long;
441#if defined(__aarch64__)
448 size_t const dictHashAndTagL3 =
ZSTD_hashPtr(ip+1, dictHBitsL, 8);
449 U32 const matchIndexL3 = hashLong[hl3];
452 const BYTE* matchL3 = base + matchIndexL3;
453 hashLong[hl3] = curr + 1;
456 if (matchIndexL3 > prefixLowestIndex) {
458 mLength =
ZSTD_count(ip+9, matchL3+8, iend) + 8;
460 offset = (
U32)(ip-matchL3);
461 while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; }
464 }
else if (dictTagsMatchL3) {
467 const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
468 assert(dictMatchL3 < dictEnd);
472 offset = (
U32)(curr + 1 - dictMatchIndexL3 - dictIndexDelta);
473 while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; }
478 if (matchIndexS < prefixLowestIndex) {
480 offset = (
U32)(curr - matchIndexS);
481 while (((ip>anchor) & (match>dictStart)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; }
483 mLength =
ZSTD_count(ip+4, match+4, iend) + 4;
484 offset = (
U32)(ip - match);
485 while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; }
502 {
U32 const indexToInsert = curr+2;
503 hashLong[
ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
505 hashSmall[
ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
510 while (ip <= ilimit) {
511 U32 const current2 = (
U32)(ip-base);
512 U32 const repIndex2 = current2 - offset_2;
513 const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
514 dictBase + repIndex2 - dictIndexDelta :
516 if ( ((
U32)((prefixLowestIndex-1) - (
U32)repIndex2) >= 3 )
518 const BYTE*
const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
519 size_t const repLength2 =
ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
520 U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;
538 return (
size_t)(iend - anchor);
541#define ZSTD_GEN_DFAST_FN(dictMode, mls) \
542 static size_t ZSTD_compressBlock_doubleFast_##dictMode##_##mls( \
543 ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], \
544 void const* src, size_t srcSize) \
546 return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
562 void const* src,
size_t srcSize)
564 const U32 mls = ms->cParams.minMatch;
569 return ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize);
571 return ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize);
573 return ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize);
575 return ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize);
582 void const* src,
size_t srcSize)
589 return ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize);
591 return ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize);
593 return ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize);
595 return ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize);
602size_t ZSTD_compressBlock_doubleFast_extDict_generic(
604 void const* src,
size_t srcSize,
607 ZSTD_compressionParameters
const* cParams = &ms->
cParams;
609 U32 const hBitsL = cParams->hashLog;
611 U32 const hBitsS = cParams->chainLog;
612 const BYTE*
const istart = (
const BYTE*)src;
613 const BYTE* ip = istart;
614 const BYTE* anchor = istart;
615 const BYTE*
const iend = istart + srcSize;
616 const BYTE*
const ilimit = iend - 8;
618 const U32 endIndex = (
U32)((
size_t)(istart -
base) + srcSize);
620 const U32 dictStartIndex = lowLimit;
622 const U32 prefixStartIndex = (dictLimit > lowLimit) ? dictLimit : lowLimit;
623 const BYTE*
const prefixStart =
base + prefixStartIndex;
625 const BYTE*
const dictStart = dictBase + dictStartIndex;
626 const BYTE*
const dictEnd = dictBase + prefixStartIndex;
627 U32 offset_1=rep[0], offset_2=rep[1];
629 DEBUGLOG(5,
"ZSTD_compressBlock_doubleFast_extDict_generic (srcSize=%zu)", srcSize);
632 if (prefixStartIndex == dictStartIndex)
636 while (ip < ilimit) {
638 const U32 matchIndex = hashSmall[hSmall];
639 const BYTE*
const matchBase = matchIndex < prefixStartIndex ? dictBase :
base;
640 const BYTE* match = matchBase + matchIndex;
643 const U32 matchLongIndex = hashLong[hLong];
644 const BYTE*
const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase :
base;
645 const BYTE* matchLong = matchLongBase + matchLongIndex;
648 const U32 repIndex =
curr + 1 - offset_1;
649 const BYTE*
const repBase = repIndex < prefixStartIndex ? dictBase :
base;
650 const BYTE*
const repMatch = repBase + repIndex;
652 hashSmall[hSmall] = hashLong[hLong] =
curr;
654 if ((((
U32)((prefixStartIndex-1) - repIndex) >= 3)
655 & (offset_1 <= curr+1 - dictStartIndex))
657 const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
663 const BYTE*
const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
664 const BYTE*
const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
667 offset =
curr - matchLongIndex;
668 while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; }
675 U32 const matchIndex3 = hashLong[h3];
676 const BYTE*
const match3Base = matchIndex3 < prefixStartIndex ? dictBase :
base;
677 const BYTE* match3 = match3Base + matchIndex3;
679 hashLong[h3] =
curr + 1;
681 const BYTE*
const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
682 const BYTE*
const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
685 offset =
curr+1 - matchIndex3;
686 while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; }
688 const BYTE*
const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
689 const BYTE*
const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
691 offset =
curr - matchIndex;
692 while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; }
710 {
U32 const indexToInsert =
curr+2;
711 hashLong[
ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
713 hashSmall[
ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
718 while (ip <= ilimit) {
719 U32 const current2 = (
U32)(ip-base);
720 U32 const repIndex2 = current2 - offset_2;
721 const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 :
base + repIndex2;
722 if ( (((
U32)((prefixStartIndex-1) - repIndex2) >= 3)
723 & (offset_2 <= current2 - dictStartIndex))
725 const BYTE*
const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
726 size_t const repLength2 =
ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
727 U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;
743 return (
size_t)(iend - anchor);
753 void const* src,
size_t srcSize)
755 U32 const mls = ms->cParams.minMatch;
760 return ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize);
762 return ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize);
764 return ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize);
766 return ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize);
#define PREFETCH_AREA(p, s)
#define FORCE_INLINE_TEMPLATE
#define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
#define assert(condition)
MEM_STATIC U32 MEM_read32(const void *memPtr)
MEM_STATIC U64 MEM_read64(const void *memPtr)
ZSTD_compressionParameters cParams
const ZSTD_matchState_t * dictMatchState
#define ZSTD_SHORT_CACHE_TAG_BITS
MEM_STATIC size_t ZSTD_count_2segments(const BYTE *ip, const BYTE *match, const BYTE *iEnd, const BYTE *mEnd, const BYTE *iStart)
#define OFFSET_TO_OFFBASE(o)
MEM_STATIC void ZSTD_writeTaggedIndex(U32 *const hashTable, size_t hashAndTag, U32 index)
MEM_STATIC int ZSTD_comparePackedTags(size_t packedTag1, size_t packedTag2)
MEM_STATIC FORCE_INLINE_ATTR size_t ZSTD_hashPtr(const void *p, U32 hBits, U32 mls)
MEM_STATIC size_t ZSTD_count(const BYTE *pIn, const BYTE *pMatch, const BYTE *const pInLimit)
HINT_INLINE UNUSED_ATTR void ZSTD_storeSeq(seqStore_t *seqStorePtr, size_t litLength, const BYTE *literals, const BYTE *litLimit, U32 offBase, size_t matchLength)
MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t *ms, U32 curr, unsigned windowLog)
MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t *ms, U32 curr, unsigned windowLog)
#define REPCODE1_TO_OFFBASE
ZSTD_dictTableLoadMethod_e
size_t ZSTD_compressBlock_doubleFast(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_doubleFast_extDict(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
void ZSTD_fillDoubleHashTable(ZSTD_matchState_t *ms, const void *const end, ZSTD_dictTableLoadMethod_e dtlm, ZSTD_tableFillPurpose_e tfp)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize, U32 const mls)
size_t ZSTD_compressBlock_doubleFast_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_compressBlock_doubleFast_noDict_generic(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize, U32 const mls)
#define ZSTD_GEN_DFAST_FN(dictMode, mls)