lib/zstd/compress/zstd_lazy.c
Source file repositories/reference/linux-study-clean/lib/zstd/compress/zstd_lazy.c
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/compress/zstd_lazy.c- Extension
.c- Size
- 102828 bytes
- Lines
- 2201
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
zstd_compress_internal.hzstd_lazy.h../common/bits.h
Detected Declarations
function Copyrightfunction ZSTD_insertDUBT1function ZSTD_DUBT_findBetterDictMatchfunction ZSTD_DUBT_findBestMatchfunction ZSTD_BtFindBestMatchfunction ZSTD_dedicatedDictSearch_lazy_loadDictionaryfunction ZSTD_dedicatedDictSearch_lazy_searchfunction ZSTD_insertAndFindFirstIndex_internalfunction ZSTD_insertAndFindFirstIndexfunction ZSTD_HcFindBestMatchfunction ZSTD_VecMask_nextfunction ZSTD_row_nextIndexfunction ZSTD_isAlignedfunction ZSTD_row_prefetchfunction ZSTD_row_fillHashCachefunction ZSTD_row_nextCachedHashfunction ZSTD_row_update_internalImplfunction ZSTD_row_update_internalfunction ZSTD_row_update_internalfunction ZSTD_row_matchMaskGroupWidthfunction ZSTD_row_getSSEMaskfunction ZSTD_row_getNEONMaskfunction ZSTD_row_getMatchMaskfunction ZSTD_RowFindBestMatchfunction ZSTD_searchMaxfunction ZSTD_compressBlock_lazy_genericfunction ZSTD_compressBlock_greedyfunction ZSTD_compressBlock_greedy_dictMatchStatefunction ZSTD_compressBlock_greedy_dedicatedDictSearchfunction ZSTD_compressBlock_greedy_rowfunction ZSTD_compressBlock_greedy_dictMatchState_rowfunction ZSTD_compressBlock_greedy_dedicatedDictSearch_rowfunction ZSTD_compressBlock_lazyfunction ZSTD_compressBlock_lazy_dictMatchStatefunction ZSTD_compressBlock_lazy_dedicatedDictSearchfunction ZSTD_compressBlock_lazy_rowfunction ZSTD_compressBlock_lazy_dictMatchState_rowfunction ZSTD_compressBlock_lazy_dedicatedDictSearch_rowfunction ZSTD_compressBlock_lazy2function ZSTD_compressBlock_lazy2_dictMatchStatefunction ZSTD_compressBlock_lazy2_dedicatedDictSearchfunction ZSTD_compressBlock_lazy2_rowfunction ZSTD_compressBlock_lazy2_dictMatchState_rowfunction ZSTD_compressBlock_lazy2_dedicatedDictSearch_rowfunction ZSTD_compressBlock_btlazy2function ZSTD_compressBlock_btlazy2_dictMatchStatefunction ZSTD_compressBlock_lazy_extDict_genericfunction ZSTD_compressBlock_greedy_extDict
Annotated Snippet
if (ip+matchLength == iend) { /* equal : no way to know if inf or sup */
break; /* drop , to guarantee consistency ; miss a bit of compression, but other solutions can corrupt tree */
}
if (match[matchLength] < ip[matchLength]) { /* necessarily within buffer */
/* match is smaller than current */
*smallerPtr = matchIndex; /* update smaller idx */
commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */
if (matchIndex <= btLow) { smallerPtr=&dummy32; break; } /* beyond tree size, stop searching */
DEBUGLOG(8, "ZSTD_insertDUBT1: %u (>btLow=%u) is smaller : next => %u",
matchIndex, btLow, nextPtr[1]);
smallerPtr = nextPtr+1; /* new "candidate" => larger than match, which was smaller than target */
matchIndex = nextPtr[1]; /* new matchIndex, larger than previous and closer to current */
} else {
/* match is larger than current */
*largerPtr = matchIndex;
commonLengthLarger = matchLength;
if (matchIndex <= btLow) { largerPtr=&dummy32; break; } /* beyond tree size, stop searching */
DEBUGLOG(8, "ZSTD_insertDUBT1: %u (>btLow=%u) is larger => %u",
matchIndex, btLow, nextPtr[0]);
largerPtr = nextPtr;
matchIndex = nextPtr[0];
} }
*smallerPtr = *largerPtr = 0;
}
static
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
size_t ZSTD_DUBT_findBetterDictMatch (
const ZSTD_MatchState_t* ms,
const BYTE* const ip, const BYTE* const iend,
size_t* offsetPtr,
size_t bestLength,
U32 nbCompares,
U32 const mls,
const ZSTD_dictMode_e dictMode)
{
const ZSTD_MatchState_t * const dms = ms->dictMatchState;
const ZSTD_compressionParameters* const dmsCParams = &dms->cParams;
const U32 * const dictHashTable = dms->hashTable;
U32 const hashLog = dmsCParams->hashLog;
size_t const h = ZSTD_hashPtr(ip, hashLog, mls);
U32 dictMatchIndex = dictHashTable[h];
const BYTE* const base = ms->window.base;
const BYTE* const prefixStart = base + ms->window.dictLimit;
U32 const curr = (U32)(ip-base);
const BYTE* const dictBase = dms->window.base;
const BYTE* const dictEnd = dms->window.nextSrc;
U32 const dictHighLimit = (U32)(dms->window.nextSrc - dms->window.base);
U32 const dictLowLimit = dms->window.lowLimit;
U32 const dictIndexDelta = ms->window.lowLimit - dictHighLimit;
U32* const dictBt = dms->chainTable;
U32 const btLog = dmsCParams->chainLog - 1;
U32 const btMask = (1 << btLog) - 1;
U32 const btLow = (btMask >= dictHighLimit - dictLowLimit) ? dictLowLimit : dictHighLimit - btMask;
size_t commonLengthSmaller=0, commonLengthLarger=0;
(void)dictMode;
assert(dictMode == ZSTD_dictMatchState);
for (; nbCompares && (dictMatchIndex > dictLowLimit); --nbCompares) {
U32* const nextPtr = dictBt + 2*(dictMatchIndex & btMask);
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
const BYTE* match = dictBase + dictMatchIndex;
matchLength += ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart);
if (dictMatchIndex+matchLength >= dictHighLimit)
match = base + dictMatchIndex + dictIndexDelta; /* to prepare for next usage of match[matchLength] */
if (matchLength > bestLength) {
U32 matchIndex = dictMatchIndex + dictIndexDelta;
if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit32(curr-matchIndex+1) - ZSTD_highbit32((U32)offsetPtr[0]+1)) ) {
DEBUGLOG(9, "ZSTD_DUBT_findBetterDictMatch(%u) : found better match length %u -> %u and offsetCode %u -> %u (dictMatchIndex %u, matchIndex %u)",
curr, (U32)bestLength, (U32)matchLength, (U32)*offsetPtr, OFFSET_TO_OFFBASE(curr - matchIndex), dictMatchIndex, matchIndex);
bestLength = matchLength, *offsetPtr = OFFSET_TO_OFFBASE(curr - matchIndex);
}
if (ip+matchLength == iend) { /* reached end of input : ip[matchLength] is not valid, no way to know if it's larger or smaller than match */
break; /* drop, to guarantee consistency (miss a little bit of compression) */
}
}
if (match[matchLength] < ip[matchLength]) {
if (dictMatchIndex <= btLow) { break; } /* beyond tree size, stop the search */
commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */
dictMatchIndex = nextPtr[1]; /* new matchIndex larger than previous (closer to current) */
} else {
Annotation
- Immediate include surface: `zstd_compress_internal.h`, `zstd_lazy.h`, `../common/bits.h`.
- Detected declarations: `function Copyright`, `function ZSTD_insertDUBT1`, `function ZSTD_DUBT_findBetterDictMatch`, `function ZSTD_DUBT_findBestMatch`, `function ZSTD_BtFindBestMatch`, `function ZSTD_dedicatedDictSearch_lazy_loadDictionary`, `function ZSTD_dedicatedDictSearch_lazy_search`, `function ZSTD_insertAndFindFirstIndex_internal`, `function ZSTD_insertAndFindFirstIndex`, `function ZSTD_HcFindBestMatch`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.