13#include "../common/bits.h"
15#if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \
16 || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \
17 || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) \
18 || !defined(ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR)
20#define kLazySkippingStep 8
33 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
35 U32 const hashLog = cParams->hashLog;
38 U32 const btLog = cParams->chainLog - 1;
39 U32 const btMask = (1 << btLog) - 1;
42 U32 const target = (
U32)(ip - base);
46 DEBUGLOG(7,
"ZSTD_updateDUBT, from %u to %u (dictLimit:%u)",
52 for ( ; idx < target ; idx++) {
54 U32 const matchIndex = hashTable[h];
56 U32*
const nextCandidatePtr = bt + 2*(idx&btMask);
57 U32*
const sortMarkPtr = nextCandidatePtr + 1;
59 DEBUGLOG(8,
"ZSTD_updateDUBT: insert %u", idx);
61 *nextCandidatePtr = matchIndex;
79 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
81 U32 const btLog = cParams->chainLog - 1;
82 U32 const btMask = (1 << btLog) - 1;
83 size_t commonLengthSmaller=0, commonLengthLarger=0;
87 const BYTE*
const ip = (
curr>=dictLimit) ? base + curr : dictBase + curr;
88 const BYTE*
const iend = (
curr>=dictLimit) ? inputEnd : dictBase + dictLimit;
89 const BYTE*
const dictEnd = dictBase + dictLimit;
90 const BYTE*
const prefixStart =
base + dictLimit;
92 U32* smallerPtr = bt + 2*(
curr&btMask);
93 U32* largerPtr = smallerPtr + 1;
94 U32 matchIndex = *smallerPtr;
97 U32 const maxDistance = 1U << cParams->windowLog;
98 U32 const windowLow = (
curr - windowValid > maxDistance) ? curr - maxDistance : windowValid;
101 DEBUGLOG(8,
"ZSTD_insertDUBT1(%u) (dictLimit=%u, lowLimit=%u)",
102 curr, dictLimit, windowLow);
106 for (; nbCompares && (matchIndex > windowLow); --nbCompares) {
107 U32*
const nextPtr = bt + 2*(matchIndex & btMask);
108 size_t matchLength =
MIN(commonLengthSmaller, commonLengthLarger);
109 assert(matchIndex < curr);
115 || (matchIndex+matchLength >= dictLimit)
116 || (curr < dictLimit) ) {
118 || (matchIndex+matchLength >= dictLimit)) ?
120 assert( (matchIndex+matchLength >= dictLimit)
121 || (curr < dictLimit) );
122 match = mBase + matchIndex;
123 matchLength +=
ZSTD_count(ip+matchLength, match+matchLength, iend);
125 match = dictBase + matchIndex;
126 matchLength +=
ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart);
127 if (matchIndex+matchLength >= dictLimit)
128 match =
base + matchIndex;
131 DEBUGLOG(8,
"ZSTD_insertDUBT1: comparing %u with %u : found %u common bytes ",
132 curr, matchIndex, (
U32)matchLength);
134 if (ip+matchLength == iend) {
138 if (match[matchLength] < ip[matchLength]) {
140 *smallerPtr = matchIndex;
141 commonLengthSmaller = matchLength;
142 if (matchIndex <= btLow) { smallerPtr=&dummy32;
break; }
143 DEBUGLOG(8,
"ZSTD_insertDUBT1: %u (>btLow=%u) is smaller : next => %u",
144 matchIndex, btLow, nextPtr[1]);
145 smallerPtr = nextPtr+1;
146 matchIndex = nextPtr[1];
149 *largerPtr = matchIndex;
150 commonLengthLarger = matchLength;
151 if (matchIndex <= btLow) { largerPtr=&dummy32;
break; }
152 DEBUGLOG(8,
"ZSTD_insertDUBT1: %u (>btLow=%u) is larger => %u",
153 matchIndex, btLow, nextPtr[0]);
155 matchIndex = nextPtr[0];
158 *smallerPtr = *largerPtr = 0;
164size_t ZSTD_DUBT_findBetterDictMatch (
166 const BYTE*
const ip,
const BYTE*
const iend,
174 const ZSTD_compressionParameters*
const dmsCParams = &dms->
cParams;
176 U32 const hashLog = dmsCParams->hashLog;
178 U32 dictMatchIndex = dictHashTable[h];
190 U32 const btLog = dmsCParams->chainLog - 1;
191 U32 const btMask = (1 << btLog) - 1;
192 U32 const btLow = (btMask >= dictHighLimit - dictLowLimit) ? dictLowLimit : dictHighLimit - btMask;
194 size_t commonLengthSmaller=0, commonLengthLarger=0;
199 for (; nbCompares && (dictMatchIndex > dictLowLimit); --nbCompares) {
200 U32*
const nextPtr = dictBt + 2*(dictMatchIndex & btMask);
201 size_t matchLength =
MIN(commonLengthSmaller, commonLengthLarger);
202 const BYTE* match = dictBase + dictMatchIndex;
203 matchLength +=
ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart);
204 if (dictMatchIndex+matchLength >= dictHighLimit)
205 match =
base + dictMatchIndex + dictIndexDelta;
207 if (matchLength > bestLength) {
208 U32 matchIndex = dictMatchIndex + dictIndexDelta;
210 DEBUGLOG(9,
"ZSTD_DUBT_findBetterDictMatch(%u) : found better match length %u -> %u and offsetCode %u -> %u (dictMatchIndex %u, matchIndex %u)",
214 if (ip+matchLength == iend) {
219 if (match[matchLength] < ip[matchLength]) {
220 if (dictMatchIndex <= btLow) {
break; }
221 commonLengthSmaller = matchLength;
222 dictMatchIndex = nextPtr[1];
225 if (dictMatchIndex <= btLow) {
break; }
226 commonLengthLarger = matchLength;
227 dictMatchIndex = nextPtr[0];
233 DEBUGLOG(8,
"ZSTD_DUBT_findBetterDictMatch(%u) : found match of length %u and offsetCode %u (pos %u)",
234 curr, (
U32)bestLength, (
U32)*offsetPtr, mIndex);
244 const BYTE*
const ip,
const BYTE*
const iend,
249 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
251 U32 const hashLog = cParams->hashLog;
253 U32 matchIndex = hashTable[h];
260 U32 const btLog = cParams->chainLog - 1;
261 U32 const btMask = (1 << btLog) - 1;
262 U32 const btLow = (btMask >=
curr) ? 0 : curr - btMask;
263 U32 const unsortLimit =
MAX(btLow, windowLow);
265 U32* nextCandidate = bt + 2*(matchIndex&btMask);
266 U32* unsortedMark = bt + 2*(matchIndex&btMask) + 1;
267 U32 nbCompares = 1U << cParams->searchLog;
268 U32 nbCandidates = nbCompares;
269 U32 previousCandidate = 0;
271 DEBUGLOG(7,
"ZSTD_DUBT_findBestMatch (%u) ", curr);
276 while ( (matchIndex > unsortLimit)
278 && (nbCandidates > 1) ) {
279 DEBUGLOG(8,
"ZSTD_DUBT_findBestMatch: candidate %u is unsorted",
281 *unsortedMark = previousCandidate;
282 previousCandidate = matchIndex;
283 matchIndex = *nextCandidate;
284 nextCandidate = bt + 2*(matchIndex&btMask);
285 unsortedMark = bt + 2*(matchIndex&btMask) + 1;
291 if ( (matchIndex > unsortLimit)
293 DEBUGLOG(7,
"ZSTD_DUBT_findBestMatch: nullify last unsorted candidate %u",
295 *nextCandidate = *unsortedMark = 0;
299 matchIndex = previousCandidate;
301 U32*
const nextCandidateIdxPtr = bt + 2*(matchIndex&btMask) + 1;
302 U32 const nextCandidateIdx = *nextCandidateIdxPtr;
303 ZSTD_insertDUBT1(ms, matchIndex, iend,
304 nbCandidates, unsortLimit, dictMode);
305 matchIndex = nextCandidateIdx;
310 {
size_t commonLengthSmaller = 0, commonLengthLarger = 0;
313 const BYTE*
const dictEnd = dictBase + dictLimit;
314 const BYTE*
const prefixStart =
base + dictLimit;
315 U32* smallerPtr = bt + 2*(
curr&btMask);
316 U32* largerPtr = bt + 2*(
curr&btMask) + 1;
317 U32 matchEndIdx =
curr + 8 + 1;
319 size_t bestLength = 0;
321 matchIndex = hashTable[h];
324 for (; nbCompares && (matchIndex > windowLow); --nbCompares) {
325 U32*
const nextPtr = bt + 2*(matchIndex & btMask);
326 size_t matchLength =
MIN(commonLengthSmaller, commonLengthLarger);
329 if ((dictMode !=
ZSTD_extDict) || (matchIndex+matchLength >= dictLimit)) {
330 match =
base + matchIndex;
331 matchLength +=
ZSTD_count(ip+matchLength, match+matchLength, iend);
333 match = dictBase + matchIndex;
334 matchLength +=
ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart);
335 if (matchIndex+matchLength >= dictLimit)
336 match =
base + matchIndex;
339 if (matchLength > bestLength) {
340 if (matchLength > matchEndIdx - matchIndex)
341 matchEndIdx = matchIndex + (
U32)matchLength;
344 if (ip+matchLength == iend) {
354 if (match[matchLength] < ip[matchLength]) {
356 *smallerPtr = matchIndex;
357 commonLengthSmaller = matchLength;
358 if (matchIndex <= btLow) { smallerPtr=&dummy32;
break; }
359 smallerPtr = nextPtr+1;
360 matchIndex = nextPtr[1];
363 *largerPtr = matchIndex;
364 commonLengthLarger = matchLength;
365 if (matchIndex <= btLow) { largerPtr=&dummy32;
break; }
367 matchIndex = nextPtr[0];
370 *smallerPtr = *largerPtr = 0;
372 assert(nbCompares <= (1U << ZSTD_SEARCHLOG_MAX));
374 bestLength = ZSTD_DUBT_findBetterDictMatch(
376 offBasePtr, bestLength, nbCompares,
380 assert(matchEndIdx > curr+8);
384 DEBUGLOG(8,
"ZSTD_DUBT_findBestMatch(%u) : found match of length %u and offsetCode %u (pos %u)",
385 curr, (
U32)bestLength, (
U32)*offBasePtr, mIndex);
396 const BYTE*
const ip,
const BYTE*
const iLimit,
401 DEBUGLOG(7,
"ZSTD_BtFindBestMatch");
403 ZSTD_updateDUBT(ms, ip, iLimit, mls);
404 return ZSTD_DUBT_findBestMatch(ms, ip, iLimit, offBasePtr, mls, dictMode);
414 U32 const target = (
U32)(ip - base);
417 U32 const chainSize = 1 << ms->
cParams.chainLog;
419 U32 const minChain = chainSize < target - idx ? target - chainSize : idx;
421 U32 const cacheSize = bucketSize - 1;
422 U32 const chainAttempts = (1 << ms->
cParams.searchLog) - cacheSize;
423 U32 const chainLimit = chainAttempts > 255 ? 255 : chainAttempts;
431 U32*
const tmpHashTable = hashTable;
432 U32*
const tmpChainTable = hashTable + ((size_t)1 << hashLog);
434 U32 const tmpMinChain = tmpChainSize < target ? target - tmpChainSize : idx;
440 assert(tmpMinChain <= minChain);
443 for ( ; idx < target; idx++) {
445 if (idx >= tmpMinChain) {
446 tmpChainTable[idx - tmpMinChain] = hashTable[h];
448 tmpHashTable[h] = idx;
454 for (hashIdx = 0; hashIdx < (1U << hashLog); hashIdx++) {
456 U32 countBeyondMinChain = 0;
457 U32 i = tmpHashTable[hashIdx];
458 for (count = 0; i >= tmpMinChain && count < cacheSize; count++) {
462 countBeyondMinChain++;
464 i = tmpChainTable[i - tmpMinChain];
466 if (count == cacheSize) {
467 for (count = 0; count < chainLimit;) {
469 if (!i || ++countBeyondMinChain > cacheSize) {
481 chainTable[chainPos++] = i;
483 if (i < tmpMinChain) {
486 i = tmpChainTable[i - tmpMinChain];
492 tmpHashTable[hashIdx] = ((chainPos - count) << 8) + count;
494 tmpHashTable[hashIdx] = 0;
497 assert(chainPos <= chainSize);
501 for (hashIdx = (1 << hashLog); hashIdx; ) {
503 U32 const chainPackedPointer = tmpHashTable[hashIdx];
505 for (i = 0; i < cacheSize; i++) {
506 hashTable[bucketIdx + i] = 0;
508 hashTable[bucketIdx + bucketSize - 1] = chainPackedPointer;
517 for (i = cacheSize - 1; i; i--)
518 hashTable[h + i] = hashTable[h + i - 1];
531 const BYTE*
const ip,
const BYTE*
const iLimit,
532 const BYTE*
const prefixStart,
const U32 curr,
533 const U32 dictLimit,
const size_t ddsIdx) {
537 const U32 ddsSize = (
U32)(ddsEnd - ddsBase);
538 const U32 ddsIndexDelta = dictLimit - ddsSize;
540 const U32 bucketLimit = nbAttempts < bucketSize - 1 ? nbAttempts : bucketSize - 1;
544 for (ddsAttempt = 0; ddsAttempt < bucketSize - 1; ddsAttempt++) {
549 U32 const chainPackedPointer = dms->
hashTable[ddsIdx + bucketSize - 1];
550 U32 const chainIndex = chainPackedPointer >> 8;
555 for (ddsAttempt = 0; ddsAttempt < bucketLimit; ddsAttempt++) {
558 matchIndex = dms->
hashTable[ddsIdx + ddsAttempt];
559 match = ddsBase + matchIndex;
566 (void)ddsLowestIndex;
567 assert(matchIndex >= ddsLowestIndex);
568 assert(match+4 <= ddsEnd);
575 if (currentMl > ml) {
578 if (ip+currentMl == iLimit) {
586 U32 const chainPackedPointer = dms->
hashTable[ddsIdx + bucketSize - 1];
587 U32 chainIndex = chainPackedPointer >> 8;
588 U32 const chainLength = chainPackedPointer & 0xFF;
589 U32 const chainAttempts = nbAttempts - ddsAttempt;
590 U32 const chainLimit = chainAttempts > chainLength ? chainLength : chainAttempts;
593 for (chainAttempt = 0 ; chainAttempt < chainLimit; chainAttempt++) {
597 for (chainAttempt = 0 ; chainAttempt < chainLimit; chainAttempt++, chainIndex++) {
601 match = ddsBase + matchIndex;
604 assert(matchIndex >= ddsLowestIndex);
605 assert(match+4 <= ddsEnd);
612 if (currentMl > ml) {
615 if (ip+currentMl == iLimit)
break;
626#define NEXT_IN_CHAIN(d, mask) chainTable[(d) & (mask)]
634 const ZSTD_compressionParameters*
const cParams,
635 const BYTE* ip,
U32 const mls,
U32 const lazySkipping)
638 const U32 hashLog = cParams->hashLog;
640 const U32 chainMask = (1 << cParams->chainLog) - 1;
642 const U32 target = (
U32)(ip - base);
645 while(idx < target) {
660 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
669 const BYTE*
const ip,
const BYTE*
const iLimit,
673 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
675 const U32 chainSize = (1 << cParams->chainLog);
676 const U32 chainMask = chainSize-1;
680 const BYTE*
const prefixStart = base + dictLimit;
681 const BYTE*
const dictEnd = dictBase + dictLimit;
682 const U32 curr = (
U32)(ip-base);
683 const U32 maxDistance = 1U << cParams->windowLog;
685 const U32 withinMaxDistance = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
687 const U32 lowLimit = isDictionary ? lowestValid : withinMaxDistance;
688 const U32 minChain = curr > chainSize ? curr - chainSize : 0;
689 U32 nbAttempts = 1U << cParams->searchLog;
708 for ( ; (matchIndex>=lowLimit) & (nbAttempts>0) ; nbAttempts--) {
710 if ((dictMode !=
ZSTD_extDict) || matchIndex >= dictLimit) {
711 const BYTE*
const match = base + matchIndex;
712 assert(matchIndex >= dictLimit);
717 const BYTE*
const match = dictBase + matchIndex;
718 assert(match+4 <= dictEnd);
724 if (currentMl > ml) {
727 if (ip+currentMl == iLimit)
break;
730 if (matchIndex <= minChain)
break;
734 assert(nbAttempts <= (1U << ZSTD_SEARCHLOG_MAX));
737 ip, iLimit, prefixStart, curr, dictLimit, ddsIdx);
740 const U32 dmsChainSize = (1 << dms->
cParams.chainLog);
741 const U32 dmsChainMask = dmsChainSize - 1;
745 const U32 dmsSize = (
U32)(dmsEnd - dmsBase);
746 const U32 dmsIndexDelta = dictLimit - dmsSize;
747 const U32 dmsMinChain = dmsSize > dmsChainSize ? dmsSize - dmsChainSize : 0;
751 for ( ; (matchIndex>=dmsLowestIndex) & (nbAttempts>0) ; nbAttempts--) {
753 const BYTE*
const match = dmsBase + matchIndex;
754 assert(match+4 <= dmsEnd);
759 if (currentMl > ml) {
761 assert(curr > matchIndex + dmsIndexDelta);
763 if (ip+currentMl == iLimit)
break;
766 if (matchIndex <= dmsMinChain)
break;
768 matchIndex = dmsChainTable[matchIndex & dmsChainMask];
779#define ZSTD_ROW_HASH_TAG_MASK ((1u << ZSTD_ROW_HASH_TAG_BITS) - 1)
780#define ZSTD_ROW_HASH_MAX_ENTRIES 64
782#define ZSTD_ROW_HASH_CACHE_MASK (ZSTD_ROW_HASH_CACHE_SIZE - 1)
799 U32 next = (*tagRow-1) & rowMask;
800 next += (next == 0) ? rowMask : 0;
801 *tagRow = (
BYTE)next;
809 assert((align & (align - 1)) == 0);
810 return (((
size_t)ptr) & (align - 1)) == 0;
826 assert(rowLog == 4 || rowLog == 5 || rowLog == 6);
838 U32 const rowLog,
U32 const mls,
839 U32 idx,
const BYTE*
const iLimit)
844 U32 const maxElemsToPrefetch = (base + idx) > iLimit ? 0 : (
U32)(iLimit - (base + idx) + 1);
847 for (; idx < lim; ++idx) {
866 BYTE const* tagTable,
BYTE const* base,
867 U32 idx,
U32 const hashLog,
868 U32 const rowLog,
U32 const mls,
886 U32 updateStartIdx,
U32 const updateEndIdx,
887 U32 const mls,
U32 const rowLog,
888 U32 const rowMask,
U32 const useCache)
895 DEBUGLOG(6,
"ZSTD_row_update_internalImpl(): updateStartIdx=%u, updateEndIdx=%u", updateStartIdx, updateEndIdx);
896 for (; updateStartIdx < updateEndIdx; ++updateStartIdx) {
900 U32*
const row = hashTable + relRow;
901 BYTE* tagRow = tagTable + relRow;
906 row[pos] = updateStartIdx;
917 U32 const mls,
U32 const rowLog,
918 U32 const rowMask,
U32 const useCache)
922 const U32 target = (
U32)(ip - base);
923 const U32 kSkipThreshold = 384;
924 const U32 kMaxMatchStartPositionsToUpdate = 96;
925 const U32 kMaxMatchEndPositionsToUpdate = 32;
933 if (
UNLIKELY(target - idx > kSkipThreshold)) {
934 U32 const bound = idx + kMaxMatchStartPositionsToUpdate;
936 idx = target - kMaxMatchEndPositionsToUpdate;
951 const U32 rowMask = (1u << rowLog) - 1;
954 DEBUGLOG(5,
"ZSTD_row_update(), rowLog=%u", rowLog);
965 assert((rowEntries == 16) || (rowEntries == 32) || rowEntries == 64);
968#if defined(ZSTD_ARCH_ARM_NEON)
973 if (rowEntries == 16) {
976 if (rowEntries == 32) {
979 if (rowEntries == 64) {
986#if defined(ZSTD_ARCH_X86_SSE2)
988ZSTD_row_getSSEMask(
int nbChunks,
const BYTE*
const src,
const BYTE tag,
const U32 head)
990 const __m128i comparisonMask = _mm_set1_epi8((
char)tag);
991 int matches[4] = {0};
993 assert(nbChunks == 1 || nbChunks == 2 || nbChunks == 4);
994 for (i=0; i<nbChunks; i++) {
995 const __m128i chunk = _mm_loadu_si128((
const __m128i*)(
const void*)(src + 16*i));
996 const __m128i equalMask = _mm_cmpeq_epi8(chunk, comparisonMask);
997 matches[i] = _mm_movemask_epi8(equalMask);
1006#if defined(ZSTD_ARCH_ARM_NEON)
1008ZSTD_row_getNEONMask(
const U32 rowEntries,
const BYTE*
const src,
const BYTE tag,
const U32 headGrouped)
1010 assert((rowEntries == 16) || (rowEntries == 32) || rowEntries == 64);
1011 if (rowEntries == 16) {
1017 const uint8x16_t chunk = vld1q_u8(src);
1018 const uint16x8_t equalMask = vreinterpretq_u16_u8(vceqq_u8(chunk, vdupq_n_u8(tag)));
1019 const uint8x8_t res = vshrn_n_u16(equalMask, 4);
1020 const U64 matches = vget_lane_u64(vreinterpret_u64_u8(res), 0);
1022 }
else if (rowEntries == 32) {
1026 const uint16x8x2_t chunk = vld2q_u16((
const uint16_t*)(
const void*)src);
1027 const uint8x16_t chunk0 = vreinterpretq_u8_u16(chunk.val[0]);
1028 const uint8x16_t chunk1 = vreinterpretq_u8_u16(chunk.val[1]);
1029 const uint8x16_t
dup = vdupq_n_u8(tag);
1030 const uint8x8_t t0 = vshrn_n_u16(vreinterpretq_u16_u8(vceqq_u8(chunk0, dup)), 6);
1031 const uint8x8_t t1 = vshrn_n_u16(vreinterpretq_u16_u8(vceqq_u8(chunk1, dup)), 6);
1032 const uint8x8_t res = vsli_n_u8(t0, t1, 4);
1033 const U64 matches = vget_lane_u64(vreinterpret_u64_u8(res), 0) ;
1036 const uint8x16x4_t chunk = vld4q_u8(src);
1037 const uint8x16_t
dup = vdupq_n_u8(tag);
1038 const uint8x16_t cmp0 = vceqq_u8(chunk.val[0], dup);
1039 const uint8x16_t cmp1 = vceqq_u8(chunk.val[1], dup);
1040 const uint8x16_t cmp2 = vceqq_u8(chunk.val[2], dup);
1041 const uint8x16_t cmp3 = vceqq_u8(chunk.val[3], dup);
1043 const uint8x16_t t0 = vsriq_n_u8(cmp1, cmp0, 1);
1044 const uint8x16_t t1 = vsriq_n_u8(cmp3, cmp2, 1);
1045 const uint8x16_t t2 = vsriq_n_u8(t1, t0, 2);
1046 const uint8x16_t t3 = vsriq_n_u8(t2, t2, 4);
1047 const uint8x8_t t4 = vshrn_n_u16(vreinterpretq_u16_u8(t3), 4);
1048 const U64 matches = vget_lane_u64(vreinterpret_u64_u8(t4), 0);
1063 const BYTE*
const src = tagRow;
1064 assert((rowEntries == 16) || (rowEntries == 32) || rowEntries == 64);
1068#if defined(ZSTD_ARCH_X86_SSE2)
1070 return ZSTD_row_getSSEMask(rowEntries / 16, src, tag, headGrouped);
1074# if defined(ZSTD_ARCH_ARM_NEON)
1077 return ZSTD_row_getNEONMask(rowEntries, src, tag, headGrouped);
1081 {
const int chunkSize =
sizeof(size_t);
1082 const size_t shiftAmount = ((chunkSize * 8) - chunkSize);
1083 const size_t xFF = ~((size_t)0);
1084 const size_t x01 = xFF / 0xFF;
1085 const size_t x80 = x01 << 7;
1086 const size_t splatChar = tag * x01;
1088 int i = rowEntries - chunkSize;
1089 assert((
sizeof(
size_t) == 4) || (
sizeof(
size_t) == 8));
1091 const size_t extractMagic = (xFF / 0x7F) >> chunkSize;
1095 chunk = (((chunk | x80) - x01) | chunk) & x80;
1096 matches <<= chunkSize;
1097 matches |= (chunk * extractMagic) >> shiftAmount;
1101 const size_t msb = xFF ^ (xFF >> 1);
1102 const size_t extractMagic = (msb / 0x1FF) | msb;
1106 chunk = (((chunk | x80) - x01) | chunk) & x80;
1107 matches <<= chunkSize;
1108 matches |= ((chunk >> 7) * extractMagic) >> shiftAmount;
1113 if (rowEntries == 16) {
1115 }
else if (rowEntries == 32) {
1143 const BYTE*
const ip,
const BYTE*
const iLimit,
1152 const ZSTD_compressionParameters*
const cParams = &ms->
cParams;
1156 const BYTE*
const prefixStart = base + dictLimit;
1157 const BYTE*
const dictEnd = dictBase + dictLimit;
1158 const U32 curr = (
U32)(ip-base);
1159 const U32 maxDistance = 1U << cParams->windowLog;
1161 const U32 withinMaxDistance = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
1163 const U32 lowLimit = isDictionary ? lowestValid : withinMaxDistance;
1164 const U32 rowEntries = (1U << rowLog);
1165 const U32 rowMask = rowEntries - 1;
1166 const U32 cappedSearchLog =
MIN(cParams->searchLog, rowLog);
1169 U32 nbAttempts = 1U << cappedSearchLog;
1178 U32 ddsExtraAttempts = 0;
1181 BYTE* dmsTagRow = NULL;
1189 ddsExtraAttempts = cParams->searchLog > rowLog ? 1U << (cParams->searchLog - rowLog) : 0;
1199 dmsTagRow = (
BYTE*)(dmsTagTable + dmsRelRow);
1200 dmsRow = dmsHashTable + dmsRelRow;
1220 U32*
const row = hashTable + relRow;
1221 BYTE* tagRow = (
BYTE*)(tagTable + relRow);
1222 U32 const headGrouped = (*tagRow & rowMask) * groupWidth;
1224 size_t numMatches = 0;
1225 size_t currMatch = 0;
1229 for (; (matches > 0) && (nbAttempts > 0); matches &= (matches - 1)) {
1231 U32 const matchIndex = row[matchPos];
1232 if(matchPos == 0)
continue;
1233 assert(numMatches < rowEntries);
1234 if (matchIndex < lowLimit)
1236 if ((dictMode !=
ZSTD_extDict) || matchIndex >= dictLimit) {
1241 matchBuffer[numMatches++] = matchIndex;
1249 tagRow[pos] = (
BYTE)tag;
1254 for (; currMatch < numMatches; ++currMatch) {
1255 U32 const matchIndex = matchBuffer[currMatch];
1257 assert(matchIndex < curr);
1258 assert(matchIndex >= lowLimit);
1260 if ((dictMode !=
ZSTD_extDict) || matchIndex >= dictLimit) {
1261 const BYTE*
const match = base + matchIndex;
1262 assert(matchIndex >= dictLimit);
1267 const BYTE*
const match = dictBase + matchIndex;
1268 assert(match+4 <= dictEnd);
1274 if (currentMl > ml) {
1277 if (ip+currentMl == iLimit)
break;
1282 assert(nbAttempts <= (1U << ZSTD_SEARCHLOG_MAX));
1285 ip, iLimit, prefixStart, curr, dictLimit, ddsIdx);
1291 const U32 dmsSize = (
U32)(dmsEnd - dmsBase);
1292 const U32 dmsIndexDelta = dictLimit - dmsSize;
1294 {
U32 const headGrouped = (*dmsTagRow & rowMask) * groupWidth;
1296 size_t numMatches = 0;
1297 size_t currMatch = 0;
1300 for (; (matches > 0) && (nbAttempts > 0); matches &= (matches - 1)) {
1302 U32 const matchIndex = dmsRow[matchPos];
1303 if(matchPos == 0)
continue;
1304 if (matchIndex < dmsLowestIndex)
1307 matchBuffer[numMatches++] = matchIndex;
1312 for (; currMatch < numMatches; ++currMatch) {
1313 U32 const matchIndex = matchBuffer[currMatch];
1315 assert(matchIndex >= dmsLowestIndex);
1316 assert(matchIndex < curr);
1318 {
const BYTE*
const match = dmsBase + matchIndex;
1319 assert(match+4 <= dmsEnd);
1324 if (currentMl > ml) {
1326 assert(curr > matchIndex + dmsIndexDelta);
1328 if (ip+currentMl == iLimit)
break;
1359#define ZSTD_BT_SEARCH_FN(dictMode, mls) ZSTD_BtFindBestMatch_##dictMode##_##mls
1360#define ZSTD_HC_SEARCH_FN(dictMode, mls) ZSTD_HcFindBestMatch_##dictMode##_##mls
1361#define ZSTD_ROW_SEARCH_FN(dictMode, mls, rowLog) ZSTD_RowFindBestMatch_##dictMode##_##mls##_##rowLog
1363#define ZSTD_SEARCH_FN_ATTRS FORCE_NOINLINE
1365#define GEN_ZSTD_BT_SEARCH_FN(dictMode, mls) \
1366 ZSTD_SEARCH_FN_ATTRS size_t ZSTD_BT_SEARCH_FN(dictMode, mls)( \
1367 ZSTD_matchState_t* ms, \
1368 const BYTE* ip, const BYTE* const iLimit, \
1369 size_t* offBasePtr) \
1371 assert(MAX(4, MIN(6, ms->cParams.minMatch)) == mls); \
1372 return ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, mls, ZSTD_##dictMode); \
1375#define GEN_ZSTD_HC_SEARCH_FN(dictMode, mls) \
1376 ZSTD_SEARCH_FN_ATTRS size_t ZSTD_HC_SEARCH_FN(dictMode, mls)( \
1377 ZSTD_matchState_t* ms, \
1378 const BYTE* ip, const BYTE* const iLimit, \
1379 size_t* offsetPtr) \
1381 assert(MAX(4, MIN(6, ms->cParams.minMatch)) == mls); \
1382 return ZSTD_HcFindBestMatch(ms, ip, iLimit, offsetPtr, mls, ZSTD_##dictMode); \
1385#define GEN_ZSTD_ROW_SEARCH_FN(dictMode, mls, rowLog) \
1386 ZSTD_SEARCH_FN_ATTRS size_t ZSTD_ROW_SEARCH_FN(dictMode, mls, rowLog)( \
1387 ZSTD_matchState_t* ms, \
1388 const BYTE* ip, const BYTE* const iLimit, \
1389 size_t* offsetPtr) \
1391 assert(MAX(4, MIN(6, ms->cParams.minMatch)) == mls); \
1392 assert(MAX(4, MIN(6, ms->cParams.searchLog)) == rowLog); \
1393 return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, mls, ZSTD_##dictMode, rowLog); \
1396#define ZSTD_FOR_EACH_ROWLOG(X, dictMode, mls) \
1397 X(dictMode, mls, 4) \
1398 X(dictMode, mls, 5) \
1401#define ZSTD_FOR_EACH_MLS_ROWLOG(X, dictMode) \
1402 ZSTD_FOR_EACH_ROWLOG(X, dictMode, 4) \
1403 ZSTD_FOR_EACH_ROWLOG(X, dictMode, 5) \
1404 ZSTD_FOR_EACH_ROWLOG(X, dictMode, 6)
1406#define ZSTD_FOR_EACH_MLS(X, dictMode) \
1411#define ZSTD_FOR_EACH_DICT_MODE(X, ...) \
1412 X(__VA_ARGS__, noDict) \
1413 X(__VA_ARGS__, extDict) \
1414 X(__VA_ARGS__, dictMatchState) \
1415 X(__VA_ARGS__, dedicatedDictSearch)
1426#define GEN_ZSTD_CALL_BT_SEARCH_FN(dictMode, mls) \
1428 return ZSTD_BT_SEARCH_FN(dictMode, mls)(ms, ip, iend, offsetPtr);
1429#define GEN_ZSTD_CALL_HC_SEARCH_FN(dictMode, mls) \
1431 return ZSTD_HC_SEARCH_FN(dictMode, mls)(ms, ip, iend, offsetPtr);
1432#define GEN_ZSTD_CALL_ROW_SEARCH_FN(dictMode, mls, rowLog) \
1434 return ZSTD_ROW_SEARCH_FN(dictMode, mls, rowLog)(ms, ip, iend, offsetPtr);
1436#define ZSTD_SWITCH_MLS(X, dictMode) \
1438 ZSTD_FOR_EACH_MLS(X, dictMode) \
1441#define ZSTD_SWITCH_ROWLOG(dictMode, mls) \
1444 ZSTD_FOR_EACH_ROWLOG(GEN_ZSTD_CALL_ROW_SEARCH_FN, dictMode, mls) \
1449#define ZSTD_SWITCH_SEARCH_METHOD(dictMode) \
1450 switch (searchMethod) { \
1451 case search_hashChain: \
1452 ZSTD_SWITCH_MLS(GEN_ZSTD_CALL_HC_SEARCH_FN, dictMode) \
1454 case search_binaryTree: \
1455 ZSTD_SWITCH_MLS(GEN_ZSTD_CALL_BT_SEARCH_FN, dictMode) \
1457 case search_rowHash: \
1458 ZSTD_SWITCH_MLS(ZSTD_SWITCH_ROWLOG, dictMode) \
1519 const void* src,
size_t srcSize,
1523 const BYTE*
const istart = (
const BYTE*)src;
1524 const BYTE* ip = istart;
1525 const BYTE* anchor = istart;
1526 const BYTE*
const iend = istart + srcSize;
1530 const BYTE*
const prefixLowest = base + prefixLowestIndex;
1534 U32 offset_1 = rep[0], offset_2 = rep[1];
1535 U32 offsetSaved1 = 0, offsetSaved2 = 0;
1539 const int isDxS = isDMS || isDDS;
1543 const BYTE*
const dictLowest = isDxS ? dictBase + dictLowestIndex : NULL;
1545 const U32 dictIndexDelta = isDxS ?
1546 prefixLowestIndex - (
U32)(dictEnd - dictBase) :
1548 const U32 dictAndPrefixLength = (
U32)((ip - prefixLowest) + (dictEnd - dictLowest));
1550 DEBUGLOG(5,
"ZSTD_compressBlock_lazy_generic (dictMode=%u) (searchFunc=%u)", (
U32)dictMode, (
U32)searchMethod);
1551 ip += (dictAndPrefixLength == 0);
1553 U32 const curr = (
U32)(ip - base);
1555 U32 const maxRep = curr - windowLow;
1556 if (offset_2 > maxRep) offsetSaved2 = offset_2, offset_2 = 0;
1557 if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
1562 assert(offset_1 <= dictAndPrefixLength);
1563 assert(offset_2 <= dictAndPrefixLength);
1574#if defined(__GNUC__) && defined(__x86_64__)
1578 __asm__(
".p2align 5");
1580 while (ip < ilimit) {
1581 size_t matchLength=0;
1583 const BYTE* start=ip+1;
1584 DEBUGLOG(7,
"search baseline (depth 0)");
1588 const U32 repIndex = (
U32)(ip - base) + 1 - offset_1;
1590 && repIndex < prefixLowestIndex) ?
1591 dictBase + (repIndex - dictIndexDelta) :
1593 if (((
U32)((prefixLowestIndex-1) - repIndex) >= 3 )
1595 const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
1597 if (depth==0)
goto _storeSequence;
1602 matchLength =
ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
1603 if (depth==0)
goto _storeSequence;
1607 {
size_t offbaseFound = 999999999;
1608 size_t const ml2 =
ZSTD_searchMax(ms, ip, iend, &offbaseFound, mls, rowLog, searchMethod, dictMode);
1609 if (ml2 > matchLength)
1610 matchLength = ml2, start = ip, offBase = offbaseFound;
1613 if (matchLength < 4) {
1634 size_t const mlRep =
ZSTD_count(ip+4, ip+4-offset_1, iend) + 4;
1635 int const gain2 = (int)(mlRep * 3);
1637 if ((mlRep >= 4) && (gain2 > gain1))
1641 const U32 repIndex = (
U32)(ip - base) - offset_1;
1642 const BYTE* repMatch = repIndex < prefixLowestIndex ?
1643 dictBase + (repIndex - dictIndexDelta) :
1645 if (((
U32)((prefixLowestIndex-1) - repIndex) >= 3 )
1647 const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
1648 size_t const mlRep =
ZSTD_count_2segments(ip+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
1649 int const gain2 = (int)(mlRep * 3);
1651 if ((mlRep >= 4) && (gain2 > gain1))
1655 {
size_t ofbCandidate=999999999;
1656 size_t const ml2 =
ZSTD_searchMax(ms, ip, iend, &ofbCandidate, mls, rowLog, searchMethod, dictMode);
1659 if ((ml2 >= 4) && (gain2 > gain1)) {
1660 matchLength = ml2, offBase = ofbCandidate, start = ip;
1665 if ((depth==2) && (ip<ilimit)) {
1670 size_t const mlRep =
ZSTD_count(ip+4, ip+4-offset_1, iend) + 4;
1671 int const gain2 = (int)(mlRep * 4);
1673 if ((mlRep >= 4) && (gain2 > gain1))
1677 const U32 repIndex = (
U32)(ip - base) - offset_1;
1678 const BYTE* repMatch = repIndex < prefixLowestIndex ?
1679 dictBase + (repIndex - dictIndexDelta) :
1681 if (((
U32)((prefixLowestIndex-1) - repIndex) >= 3 )
1683 const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
1684 size_t const mlRep =
ZSTD_count_2segments(ip+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
1685 int const gain2 = (int)(mlRep * 4);
1687 if ((mlRep >= 4) && (gain2 > gain1))
1691 {
size_t ofbCandidate=999999999;
1692 size_t const ml2 =
ZSTD_searchMax(ms, ip, iend, &ofbCandidate, mls, rowLog, searchMethod, dictMode);
1695 if ((ml2 >= 4) && (gain2 > gain1)) {
1696 matchLength = ml2, offBase = ofbCandidate, start = ip;
1709 while ( ((start > anchor) & (start -
OFFBASE_TO_OFFSET(offBase) > prefixLowest))
1711 { start--; matchLength++; }
1715 const BYTE* match = (matchIndex < prefixLowestIndex) ? dictBase + matchIndex - dictIndexDelta : base + matchIndex;
1716 const BYTE*
const mStart = (matchIndex < prefixLowestIndex) ? dictLowest : prefixLowest;
1717 while ((start>anchor) && (match>mStart) && (start[-1] == match[-1])) { start--; match--; matchLength++; }
1723 {
size_t const litLength = (size_t)(start - anchor);
1724 ZSTD_storeSeq(seqStore, litLength, anchor, iend, (
U32)offBase, matchLength);
1725 anchor = ip = start + matchLength;
1737 while (ip <= ilimit) {
1738 U32 const current2 = (
U32)(ip-base);
1739 U32 const repIndex = current2 - offset_2;
1740 const BYTE* repMatch = repIndex < prefixLowestIndex ?
1741 dictBase - dictIndexDelta + repIndex :
1743 if ( ((
U32)((prefixLowestIndex-1) - (
U32)repIndex) >= 3 )
1745 const BYTE*
const repEnd2 = repIndex < prefixLowestIndex ? dictEnd : iend;
1747 offBase = offset_2; offset_2 = offset_1; offset_1 = (
U32)offBase;
1758 while ( ((ip <= ilimit) & (offset_2>0))
1761 matchLength =
ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
1762 offBase = offset_2; offset_2 = offset_1; offset_1 = (
U32)offBase;
1771 offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
1774 rep[0] = offset_1 ? offset_1 : offsetSaved1;
1775 rep[1] = offset_2 ? offset_2 : offsetSaved2;
1778 return (
size_t)(iend - anchor);
1783#ifndef ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR
1786 void const* src,
size_t srcSize)
1793 void const* src,
size_t srcSize)
1800 void const* src,
size_t srcSize)
1807 void const* src,
size_t srcSize)
1814 void const* src,
size_t srcSize)
1821 void const* src,
size_t srcSize)
1827#ifndef ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR
1830 void const* src,
size_t srcSize)
1837 void const* src,
size_t srcSize)
1844 void const* src,
size_t srcSize)
1851 void const* src,
size_t srcSize)
1858 void const* src,
size_t srcSize)
1865 void const* src,
size_t srcSize)
1871#ifndef ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR
1874 void const* src,
size_t srcSize)
1881 void const* src,
size_t srcSize)
1888 void const* src,
size_t srcSize)
1895 void const* src,
size_t srcSize)
1902 void const* src,
size_t srcSize)
1909 void const* src,
size_t srcSize)
1915#ifndef ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR
1918 void const* src,
size_t srcSize)
1925 void const* src,
size_t srcSize)
1931#if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \
1932 || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \
1933 || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) \
1934 || !defined(ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR)
1940 const void* src,
size_t srcSize,
1943 const BYTE*
const istart = (
const BYTE*)src;
1944 const BYTE* ip = istart;
1945 const BYTE* anchor = istart;
1946 const BYTE*
const iend = istart + srcSize;
1950 const BYTE*
const prefixStart = base + dictLimit;
1952 const BYTE*
const dictEnd = dictBase + dictLimit;
1958 U32 offset_1 = rep[0], offset_2 = rep[1];
1960 DEBUGLOG(5,
"ZSTD_compressBlock_lazy_extDict_generic (searchFunc=%u)", (
U32)searchMethod);
1966 ip += (ip == prefixStart);
1972#if defined(__GNUC__) && defined(__x86_64__)
1976 __asm__(
".p2align 5");
1978 while (ip < ilimit) {
1979 size_t matchLength=0;
1981 const BYTE* start=ip+1;
1982 U32 curr = (
U32)(ip-base);
1986 const U32 repIndex = (
U32)(curr+1 - offset_1);
1987 const BYTE*
const repBase = repIndex < dictLimit ? dictBase : base;
1988 const BYTE*
const repMatch = repBase + repIndex;
1989 if ( ((
U32)((dictLimit-1) - repIndex) >= 3)
1990 & (offset_1 <= curr+1 - windowLow) )
1993 const BYTE*
const repEnd = repIndex < dictLimit ? dictEnd : iend;
1995 if (depth==0)
goto _storeSequence;
1999 {
size_t ofbCandidate = 999999999;
2001 if (ml2 > matchLength)
2002 matchLength = ml2, start = ip, offBase = ofbCandidate;
2005 if (matchLength < 4) {
2027 const U32 repIndex = (
U32)(curr - offset_1);
2028 const BYTE*
const repBase = repIndex < dictLimit ? dictBase : base;
2029 const BYTE*
const repMatch = repBase + repIndex;
2030 if ( ((
U32)((dictLimit-1) - repIndex) >= 3)
2031 & (offset_1 <= curr - windowLow) )
2034 const BYTE*
const repEnd = repIndex < dictLimit ? dictEnd : iend;
2035 size_t const repLength =
ZSTD_count_2segments(ip+4, repMatch+4, iend, repEnd, prefixStart) + 4;
2036 int const gain2 = (int)(repLength * 3);
2038 if ((repLength >= 4) && (gain2 > gain1))
2043 {
size_t ofbCandidate = 999999999;
2047 if ((ml2 >= 4) && (gain2 > gain1)) {
2048 matchLength = ml2, offBase = ofbCandidate, start = ip;
2053 if ((depth==2) && (ip<ilimit)) {
2059 const U32 repIndex = (
U32)(curr - offset_1);
2060 const BYTE*
const repBase = repIndex < dictLimit ? dictBase : base;
2061 const BYTE*
const repMatch = repBase + repIndex;
2062 if ( ((
U32)((dictLimit-1) - repIndex) >= 3)
2063 & (offset_1 <= curr - windowLow) )
2066 const BYTE*
const repEnd = repIndex < dictLimit ? dictEnd : iend;
2067 size_t const repLength =
ZSTD_count_2segments(ip+4, repMatch+4, iend, repEnd, prefixStart) + 4;
2068 int const gain2 = (int)(repLength * 4);
2070 if ((repLength >= 4) && (gain2 > gain1))
2075 {
size_t ofbCandidate = 999999999;
2079 if ((ml2 >= 4) && (gain2 > gain1)) {
2080 matchLength = ml2, offBase = ofbCandidate, start = ip;
2089 const BYTE* match = (matchIndex < dictLimit) ? dictBase + matchIndex : base + matchIndex;
2090 const BYTE*
const mStart = (matchIndex < dictLimit) ? dictStart : prefixStart;
2091 while ((start>anchor) && (match>mStart) && (start[-1] == match[-1])) { start--; match--; matchLength++; }
2097 {
size_t const litLength = (size_t)(start - anchor);
2098 ZSTD_storeSeq(seqStore, litLength, anchor, iend, (
U32)offBase, matchLength);
2099 anchor = ip = start + matchLength;
2110 while (ip <= ilimit) {
2111 const U32 repCurrent = (
U32)(ip-base);
2113 const U32 repIndex = repCurrent - offset_2;
2114 const BYTE*
const repBase = repIndex < dictLimit ? dictBase : base;
2115 const BYTE*
const repMatch = repBase + repIndex;
2116 if ( ((
U32)((dictLimit-1) - repIndex) >= 3)
2117 & (offset_2 <= repCurrent - windowLow) )
2120 const BYTE*
const repEnd = repIndex < dictLimit ? dictEnd : iend;
2122 offBase = offset_2; offset_2 = offset_1; offset_1 = (
U32)offBase;
2136 return (
size_t)(iend - anchor);
2140#ifndef ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR
2143 void const* src,
size_t srcSize)
2150 void const* src,
size_t srcSize)
2156#ifndef ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR
2159 void const* src,
size_t srcSize)
2167 void const* src,
size_t srcSize)
2174#ifndef ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR
2177 void const* src,
size_t srcSize)
2185 void const* src,
size_t srcSize)
2191#ifndef ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR
2194 void const* src,
size_t srcSize)
MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
MEM_STATIC unsigned ZSTD_highbit32(U32 val)
MEM_STATIC U64 ZSTD_rotateRight_U64(U64 const value, U32 count)
MEM_STATIC U32 ZSTD_rotateRight_U32(U32 const value, U32 count)
MEM_STATIC U16 ZSTD_rotateRight_U16(U16 const value, U32 count)
#define FORCE_INLINE_TEMPLATE
#define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
#define assert(condition)
MEM_STATIC U32 MEM_read32(const void *memPtr)
MEM_STATIC size_t MEM_readST(const void *memPtr)
MEM_STATIC unsigned MEM_isLittleEndian(void)
int32_t * dup(fif::state_stack &s, int32_t *p, fif::environment *e)
ZSTD_compressionParameters cParams
const ZSTD_matchState_t * dictMatchState
U32 hashCache[ZSTD_ROW_HASH_CACHE_SIZE]
#define OFFBASE_TO_OFFSET(o)
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 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
MEM_STATIC FORCE_INLINE_ATTR size_t ZSTD_hashPtrSalted(const void *p, U32 hBits, U32 mls, const U64 hashSalt)
#define OFFBASE_IS_OFFSET(o)
#define ZSTD_DUBT_UNSORTED_MARK
@ ZSTD_dedicatedDictSearch
#define ZSTD_ROW_HASH_CACHE_SIZE
#define BOUNDED(min, val, max)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_HcFindBestMatch(ZSTD_matchState_t *ms, const BYTE *const ip, const BYTE *const iLimit, size_t *offsetPtr, const U32 mls, const ZSTD_dictMode_e dictMode)
size_t ZSTD_compressBlock_btlazy2(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
MEM_STATIC U32 ZSTD_VecMask_next(ZSTD_VecMask val)
size_t ZSTD_compressBlock_lazy_extDict(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 void ZSTD_row_fillHashCache(ZSTD_matchState_t *ms, const BYTE *base, U32 const rowLog, U32 const mls, U32 idx, const BYTE *const iLimit)
size_t ZSTD_compressBlock_greedy_extDict_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_ROW_HASH_MAX_ENTRIES
FORCE_INLINE_TEMPLATE U32 ZSTD_row_matchMaskGroupWidth(const U32 rowEntries)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_RowFindBestMatch(ZSTD_matchState_t *ms, const BYTE *const ip, const BYTE *const iLimit, size_t *offsetPtr, const U32 mls, const ZSTD_dictMode_e dictMode, const U32 rowLog)
#define ZSTD_FOR_EACH_MLS_ROWLOG(X, dictMode)
size_t ZSTD_compressBlock_greedy_dedicatedDictSearch(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
MEM_STATIC int ZSTD_isAligned(void const *ptr, size_t align)
size_t ZSTD_compressBlock_lazy_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_FOR_EACH_MLS(X, dictMode)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR U32 ZSTD_insertAndFindFirstIndex_internal(ZSTD_matchState_t *ms, const ZSTD_compressionParameters *const cParams, const BYTE *ip, U32 const mls, U32 const lazySkipping)
size_t ZSTD_compressBlock_lazy_extDict_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
void ZSTD_row_update(ZSTD_matchState_t *const ms, const BYTE *ip)
#define GEN_ZSTD_HC_SEARCH_FN(dictMode, mls)
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_compressBlock_lazy_generic(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], const void *src, size_t srcSize, const searchMethod_e searchMethod, const U32 depth, ZSTD_dictMode_e const dictMode)
FORCE_INLINE_TEMPLATE U32 ZSTD_row_nextIndex(BYTE *const tagRow, U32 const rowMask)
#define ZSTD_SWITCH_SEARCH_METHOD(dictMode)
size_t ZSTD_compressBlock_lazy_dictMatchState_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_FOR_EACH_DICT_MODE(X,...)
size_t ZSTD_compressBlock_greedy_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_greedy_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_lazy2_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t *ms, const BYTE *const ip)
size_t ZSTD_compressBlock_btlazy2_extDict(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_greedy(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_lazy_extDict_generic(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], const void *src, size_t srcSize, const searchMethod_e searchMethod, const U32 depth)
#define kLazySkippingStep
size_t ZSTD_compressBlock_greedy_dedicatedDictSearch_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_ROW_HASH_CACHE_MASK
U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t *ms, const BYTE *ip)
size_t ZSTD_compressBlock_lazy2(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 void ZSTD_row_update_internal(ZSTD_matchState_t *ms, const BYTE *ip, U32 const mls, U32 const rowLog, U32 const rowMask, U32 const useCache)
size_t ZSTD_compressBlock_lazy2_dictMatchState_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
FORCE_INLINE_TEMPLATE void ZSTD_row_prefetch(U32 const *hashTable, BYTE const *tagTable, U32 const relRow, U32 const rowLog)
FORCE_INLINE_TEMPLATE size_t ZSTD_searchMax(ZSTD_matchState_t *ms, const BYTE *ip, const BYTE *iend, size_t *offsetPtr, U32 const mls, U32 const rowLog, searchMethod_e const searchMethod, ZSTD_dictMode_e const dictMode)
#define GEN_ZSTD_BT_SEARCH_FN(dictMode, mls)
size_t ZSTD_compressBlock_lazy_dedicatedDictSearch(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 void ZSTD_row_update_internalImpl(ZSTD_matchState_t *ms, U32 updateStartIdx, U32 const updateEndIdx, U32 const mls, U32 const rowLog, U32 const rowMask, U32 const useCache)
size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
FORCE_INLINE_TEMPLATE size_t ZSTD_dedicatedDictSearch_lazy_search(size_t *offsetPtr, size_t ml, U32 nbAttempts, const ZSTD_matchState_t *const dms, const BYTE *const ip, const BYTE *const iLimit, const BYTE *const prefixStart, const U32 curr, const U32 dictLimit, const size_t ddsIdx)
size_t ZSTD_compressBlock_lazy2_extDict_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
FORCE_INLINE_TEMPLATE ZSTD_VecMask ZSTD_row_getMatchMask(const BYTE *const tagRow, const BYTE tag, const U32 headGrouped, const U32 rowEntries)
size_t ZSTD_compressBlock_lazy_dedicatedDictSearch_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_lazy2_extDict(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_lazy(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_greedy_dictMatchState_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define NEXT_IN_CHAIN(d, mask)
size_t ZSTD_compressBlock_lazy2_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_greedy_extDict(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define GEN_ZSTD_ROW_SEARCH_FN(dictMode, mls, rowLog)
size_t ZSTD_compressBlock_lazy_row(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_ROW_HASH_TAG_MASK
FORCE_INLINE_TEMPLATE ZSTD_ALLOW_POINTER_OVERFLOW_ATTR size_t ZSTD_BtFindBestMatch(ZSTD_matchState_t *ms, const BYTE *const ip, const BYTE *const iLimit, size_t *offBasePtr, const U32 mls, const ZSTD_dictMode_e dictMode)
size_t ZSTD_compressBlock_btlazy2_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch(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 U32 ZSTD_row_nextCachedHash(U32 *cache, U32 const *hashTable, BYTE const *tagTable, BYTE const *base, U32 idx, U32 const hashLog, U32 const rowLog, U32 const mls, U64 const hashSalt)
#define ZSTD_ROW_HASH_TAG_BITS
#define ZSTD_LAZY_DDSS_BUCKET_LOG