17 const void*
const end,
20 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
23 U32 const mls = cParams->minMatch;
27 const U32 fastHashFillStep = 3;
36 for ( ; ip + fastHashFillStep < iend + 2; ip += fastHashFillStep) {
38 {
size_t const hashAndTag =
ZSTD_hashPtr(ip, hBits, mls);
44 for (p = 1; p < fastHashFillStep; ++p) {
45 size_t const hashAndTag =
ZSTD_hashPtr(ip + p, hBits, mls);
54 const void*
const end,
57 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
59 U32 const hBits = cParams->hashLog;
60 U32 const mls = cParams->minMatch;
64 const U32 fastHashFillStep = 3;
73 for ( ; ip + fastHashFillStep < iend + 2; ip += fastHashFillStep) {
76 hashTable[hash0] =
curr;
80 for (p = 1; p < fastHashFillStep; ++p) {
82 if (hashTable[hash] == 0) {
83 hashTable[hash] =
curr + p;
88 const void*
const end,
93 ZSTD_fillHashTableForCDict(ms, end, dtlm);
95 ZSTD_fillHashTableForCCtx(ms, end, dtlm);
150 void const* src,
size_t srcSize,
151 U32 const mls,
U32 const hasStep)
153 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
155 U32 const hlog = cParams->hashLog;
157 size_t const stepSize = hasStep ? (cParams->targetLength + !(cParams->targetLength) + 1) : 2;
159 const BYTE*
const istart = (
const BYTE*)src;
160 const U32 endIndex = (
U32)((
size_t)(istart - base) + srcSize);
162 const BYTE*
const prefixStart = base + prefixStartIndex;
163 const BYTE*
const iend = istart + srcSize;
166 const BYTE* anchor = istart;
167 const BYTE* ip0 = istart;
173 U32 rep_offset1 = rep[0];
174 U32 rep_offset2 = rep[1];
175 U32 offsetSaved1 = 0, offsetSaved2 = 0;
191 const BYTE* nextStep;
194 DEBUGLOG(5,
"ZSTD_compressBlock_fast_generic");
195 ip0 += (ip0 == prefixStart);
196 {
U32 const curr = (
U32)(ip0 - base);
198 U32 const maxRep = curr - windowLow;
199 if (rep_offset2 > maxRep) offsetSaved2 = rep_offset2, rep_offset2 = 0;
200 if (rep_offset1 > maxRep) offsetSaved1 = rep_offset1, rep_offset1 = 0;
207 nextStep = ip0 + kStepIncr;
221 idx = hashTable[hash0];
228 current0 = (
U32)(ip0 - base);
229 hashTable[hash0] = current0;
232 if ((
MEM_read32(ip2) == rval) & (rep_offset1 > 0)) {
234 match0 = ip0 - rep_offset1;
235 mLength = ip0[-1] == match0[-1];
244 hashTable[hash1] = (
U32)(ip1 - base);
250 if (idx >= prefixStartIndex) {
263 hashTable[hash1] = (
U32)(ip1 - base);
269 idx = hashTable[hash1];
281 current0 = (
U32)(ip0 - base);
282 hashTable[hash0] = current0;
285 if (idx >= prefixStartIndex) {
306 hashTable[hash1] = (
U32)(ip1 - base);
313 idx = hashTable[hash1];
326 if (ip2 >= nextStep) {
330 nextStep += kStepIncr;
332 }
while (ip3 < ilimit);
352 offsetSaved2 = ((offsetSaved1 != 0) && (rep_offset1 != 0)) ? offsetSaved1 : offsetSaved2;
355 rep[0] = rep_offset1 ? rep_offset1 : offsetSaved1;
356 rep[1] = rep_offset2 ? rep_offset2 : offsetSaved2;
359 return (
size_t)(iend - anchor);
365 rep_offset2 = rep_offset1;
366 rep_offset1 = (
U32)(ip0-match0);
371 while (((ip0>anchor) & (match0>prefixStart)) && (ip0[-1] == match0[-1])) {
380 mLength +=
ZSTD_count(ip0 + mLength, match0 + mLength, iend);
382 ZSTD_storeSeq(seqStore, (
size_t)(ip0 - anchor), anchor, iend, offcode, mLength);
390 assert(base+current0+2 > istart);
391 hashTable[
ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2;
394 if (rep_offset2 > 0) {
397 size_t const rLength =
ZSTD_count(ip0+4, ip0+4-rep_offset2, iend) + 4;
398 {
U32 const tmpOff = rep_offset2; rep_offset2 = rep_offset1; rep_offset1 = tmpOff; }
409#define ZSTD_GEN_FAST_FN(dictMode, mls, step) \
410 static size_t ZSTD_compressBlock_fast_##dictMode##_##mls##_##step( \
411 ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], \
412 void const* src, size_t srcSize) \
414 return ZSTD_compressBlock_fast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls, step); \
429 void const* src,
size_t srcSize)
431 U32 const mls = ms->cParams.minMatch;
432 assert(ms->dictMatchState == NULL);
433 if (ms->cParams.targetLength > 1) {
438 return ZSTD_compressBlock_fast_noDict_4_1(ms, seqStore, rep, src, srcSize);
440 return ZSTD_compressBlock_fast_noDict_5_1(ms, seqStore, rep, src, srcSize);
442 return ZSTD_compressBlock_fast_noDict_6_1(ms, seqStore, rep, src, srcSize);
444 return ZSTD_compressBlock_fast_noDict_7_1(ms, seqStore, rep, src, srcSize);
451 return ZSTD_compressBlock_fast_noDict_4_0(ms, seqStore, rep, src, srcSize);
453 return ZSTD_compressBlock_fast_noDict_5_0(ms, seqStore, rep, src, srcSize);
455 return ZSTD_compressBlock_fast_noDict_6_0(ms, seqStore, rep, src, srcSize);
457 return ZSTD_compressBlock_fast_noDict_7_0(ms, seqStore, rep, src, srcSize);
467 void const* src,
size_t srcSize,
U32 const mls,
U32 const hasStep)
469 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
471 U32 const hlog = cParams->hashLog;
473 U32 const stepSize = cParams->targetLength + !(cParams->targetLength);
475 const BYTE*
const istart = (
const BYTE*)src;
476 const BYTE* ip0 = istart;
477 const BYTE* ip1 = ip0 + stepSize;
478 const BYTE* anchor = istart;
480 const BYTE*
const prefixStart = base + prefixStartIndex;
481 const BYTE*
const iend = istart + srcSize;
483 U32 offset_1=rep[0], offset_2=rep[1];
486 const ZSTD_compressionParameters*
const dictCParams = &dms->
cParams ;
490 const BYTE*
const dictStart = dictBase + dictStartIndex;
492 const U32 dictIndexDelta = prefixStartIndex - (
U32)(dictEnd - dictBase);
493 const U32 dictAndPrefixLength = (
U32)(istart - prefixStart + dictEnd - dictStart);
498 const U32 maxDistance = 1U << cParams->windowLog;
499 const U32 endIndex = (
U32)((
size_t)(istart - base) + srcSize);
500 assert(endIndex - prefixStartIndex <= maxDistance);
501 (void)maxDistance; (void)endIndex;
507 assert(prefixStartIndex >= (
U32)(dictEnd - dictBase));
510 size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) *
sizeof(
U32);
515 DEBUGLOG(5,
"ZSTD_compressBlock_fast_dictMatchState_generic");
516 ip0 += (dictAndPrefixLength == 0);
519 assert(offset_1 <= dictAndPrefixLength);
520 assert(offset_2 <= dictAndPrefixLength);
524 while (ip1 <= ilimit) {
528 size_t const dictHashAndTag0 =
ZSTD_hashPtr(ip0, dictHBits, mls);
532 U32 matchIndex = hashTable[hash0];
533 U32 curr = (
U32)(ip0 - base);
534 size_t step = stepSize;
536 const BYTE* nextStep = ip0 + kStepIncr;
540 const BYTE* match = base + matchIndex;
541 const U32 repIndex = curr + 1 - offset_1;
542 const BYTE* repMatch = (repIndex < prefixStartIndex) ?
543 dictBase + (repIndex - dictIndexDelta) :
546 size_t const dictHashAndTag1 =
ZSTD_hashPtr(ip1, dictHBits, mls);
547 hashTable[hash0] = curr;
549 if (((
U32) ((prefixStartIndex - 1) - repIndex) >=
552 const BYTE*
const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
562 const BYTE* dictMatch = dictBase + dictMatchIndex;
563 if (dictMatchIndex > dictStartIndex &&
566 if (matchIndex <= prefixStartIndex) {
567 U32 const offset = (
U32) (curr - dictMatchIndex - dictIndexDelta);
569 while (((ip0 > anchor) & (dictMatch > dictStart))
570 && (ip0[-1] == dictMatch[-1])) {
585 U32 const offset = (
U32) (ip0 - match);
586 mLength =
ZSTD_count(ip0 + 4, match + 4, iend) + 4;
587 while (((ip0 > anchor) & (match > prefixStart))
588 && (ip0[-1] == match[-1])) {
602 matchIndex = hashTable[hash1];
604 if (ip1 >= nextStep) {
606 nextStep += kStepIncr;
610 if (ip1 > ilimit)
goto _cleanup;
612 curr = (
U32)(ip0 - base);
623 assert(base+curr+2 > istart);
624 hashTable[
ZSTD_hashPtr(base+curr+2, hlog, mls)] = curr+2;
628 while (ip0 <= ilimit) {
629 U32 const current2 = (
U32)(ip0-base);
630 U32 const repIndex2 = current2 - offset_2;
631 const BYTE* repMatch2 = repIndex2 < prefixStartIndex ?
632 dictBase - dictIndexDelta + repIndex2 :
634 if ( ((
U32)((prefixStartIndex-1) - (
U32)repIndex2) >= 3 )
636 const BYTE*
const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
637 size_t const repLength2 =
ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
638 U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset;
651 ip1 = ip0 + stepSize;
660 return (
size_t)(iend - anchor);
671 void const* src,
size_t srcSize)
673 U32 const mls = ms->cParams.minMatch;
674 assert(ms->dictMatchState != NULL);
679 return ZSTD_compressBlock_fast_dictMatchState_4_0(ms, seqStore, rep, src, srcSize);
681 return ZSTD_compressBlock_fast_dictMatchState_5_0(ms, seqStore, rep, src, srcSize);
683 return ZSTD_compressBlock_fast_dictMatchState_6_0(ms, seqStore, rep, src, srcSize);
685 return ZSTD_compressBlock_fast_dictMatchState_7_0(ms, seqStore, rep, src, srcSize);
692size_t ZSTD_compressBlock_fast_extDict_generic(
694 void const* src,
size_t srcSize,
U32 const mls,
U32 const hasStep)
696 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
698 U32 const hlog = cParams->hashLog;
700 size_t const stepSize = cParams->targetLength + !(cParams->targetLength) + 1;
703 const BYTE*
const istart = (
const BYTE*)src;
704 const BYTE* anchor = istart;
705 const U32 endIndex = (
U32)((
size_t)(istart -
base) + srcSize);
707 const U32 dictStartIndex = lowLimit;
708 const BYTE*
const dictStart = dictBase + dictStartIndex;
710 const U32 prefixStartIndex = dictLimit < lowLimit ? lowLimit : dictLimit;
711 const BYTE*
const prefixStart =
base + prefixStartIndex;
712 const BYTE*
const dictEnd = dictBase + prefixStartIndex;
713 const BYTE*
const iend = istart + srcSize;
714 const BYTE*
const ilimit = iend - 8;
715 U32 offset_1=rep[0], offset_2=rep[1];
716 U32 offsetSaved1 = 0, offsetSaved2 = 0;
718 const BYTE* ip0 = istart;
733 const BYTE* matchEnd = 0;
736 const BYTE* nextStep;
741 DEBUGLOG(5,
"ZSTD_compressBlock_fast_extDict_generic (offset_1=%u)", offset_1);
744 if (prefixStartIndex == dictStartIndex)
748 U32 const maxRep =
curr - dictStartIndex;
749 if (offset_2 >= maxRep) offsetSaved2 = offset_2, offset_2 = 0;
750 if (offset_1 >= maxRep) offsetSaved1 = offset_1, offset_1 = 0;
757 nextStep = ip0 + kStepIncr;
771 idx = hashTable[hash0];
772 idxBase = idx < prefixStartIndex ? dictBase :
base;
776 U32 const current2 = (
U32)(ip2 - base);
777 U32 const repIndex = current2 - offset_1;
778 const BYTE*
const repBase = repIndex < prefixStartIndex ? dictBase :
base;
780 if ( ((
U32)(prefixStartIndex - repIndex) >= 4)
788 current0 = (
U32)(ip0 - base);
789 hashTable[hash0] = current0;
794 match0 = repBase + repIndex;
795 matchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
796 assert((match0 != prefixStart) & (match0 != dictStart));
797 mLength = ip0[-1] == match0[-1];
806 U32 const mval = idx >= dictStartIndex ?
817 idx = hashTable[hash1];
818 idxBase = idx < prefixStartIndex ? dictBase :
base;
830 current0 = (
U32)(ip0 - base);
831 hashTable[hash0] = current0;
834 U32 const mval = idx >= dictStartIndex ?
845 idx = hashTable[hash1];
846 idxBase = idx < prefixStartIndex ? dictBase :
base;
859 if (ip2 >= nextStep) {
863 nextStep += kStepIncr;
865 }
while (ip3 < ilimit);
874 offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
877 rep[0] = offset_1 ? offset_1 : offsetSaved1;
878 rep[1] = offset_2 ? offset_2 : offsetSaved2;
881 return (
size_t)(iend - anchor);
886 {
U32 const offset = current0 - idx;
887 const BYTE*
const lowMatchPtr = idx < prefixStartIndex ? dictStart : prefixStart;
888 matchEnd = idx < prefixStartIndex ? dictEnd : iend;
889 match0 = idxBase + idx;
896 while (((ip0>anchor) & (match0>lowMatchPtr)) && (ip0[-1] == match0[-1])) {
908 ZSTD_storeSeq(seqStore, (
size_t)(ip0 - anchor), anchor, iend, offcode, mLength);
915 hashTable[hash1] = (
U32)(ip1 - base);
921 assert(base+current0+2 > istart);
922 hashTable[
ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2;
925 while (ip0 <= ilimit) {
926 U32 const repIndex2 = (
U32)(ip0-base) - offset_2;
927 const BYTE*
const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 :
base + repIndex2;
928 if ( (((
U32)((prefixStartIndex-1) - repIndex2) >= 3) & (offset_2 > 0))
930 const BYTE*
const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
931 size_t const repLength2 =
ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
932 {
U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; }
952 void const* src,
size_t srcSize)
954 U32 const mls = ms->cParams.minMatch;
955 assert(ms->dictMatchState == NULL);
960 return ZSTD_compressBlock_fast_extDict_4_0(ms, seqStore, rep, src, srcSize);
962 return ZSTD_compressBlock_fast_extDict_5_0(ms, seqStore, rep, src, srcSize);
964 return ZSTD_compressBlock_fast_extDict_6_0(ms, seqStore, rep, src, srcSize);
966 return ZSTD_compressBlock_fast_extDict_7_0(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)
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_fast_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_GEN_FAST_FN(dictMode, mls, step)
size_t ZSTD_compressBlock_fast(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_fast_noDict_generic(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize, U32 const mls, U32 const hasStep)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_compressBlock_fast_dictMatchState_generic(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize, U32 const mls, U32 const hasStep)
void ZSTD_fillHashTable(ZSTD_matchState_t *ms, const void *const end, ZSTD_dictTableLoadMethod_e dtlm, ZSTD_tableFillPurpose_e tfp)
size_t ZSTD_compressBlock_fast_extDict(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)