lib/zstd/compress/zstd_opt.c
Source file repositories/reference/linux-study-clean/lib/zstd/compress/zstd_opt.c
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/compress/zstd_opt.c- Extension
.c- Size
- 72058 bytes
- Lines
- 1582
- 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.
Dependency Surface
zstd_compress_internal.hhist.hzstd_opt.h
Detected Declarations
function Copyrightfunction ZSTD_fracWeightfunction ZSTD_fCostfunction ZSTD_compressedLiteralsfunction ZSTD_setBasePricesfunction sum_u32function ZSTD_downscaleStatsfunction ZSTD_scaleStatsfunction blockfunction literalsfunction ZSTD_litLengthPricefunction partfunction ZSTD_updateStatsfunction ZSTD_readMINMATCHfunction ZSTD_insertAndFindFirstIndexHash3function ZSTD_insertBt1function ZSTD_updateTree_internalfunction ZSTD_updateTreefunction ZSTD_insertBtAndGetAllMatchesfunction ZSTD_btGetAllMatches_internalfunction GEN_ZSTD_BT_GET_ALL_MATCHES_function ZSTD_optLdm_skipRawSeqStoreBytesfunction ZSTD_opt_getNextMatchAndUpdateSeqStorefunction ZSTD_optLdm_maybeAddMatchfunction ZSTD_optLdm_processMatchCandidatefunction listStatsfunction ZSTD_compressBlock_opt_genericfunction ZSTD_compressBlock_opt0function ZSTD_compressBlock_opt2function ZSTD_compressBlock_btoptfunction ZSTD_initStats_ultrafunction ZSTD_compressBlock_btultrafunction ZSTD_compressBlock_btultra2function ZSTD_compressBlock_btopt_dictMatchStatefunction ZSTD_compressBlock_btopt_extDictfunction ZSTD_compressBlock_btultra_dictMatchStatefunction ZSTD_compressBlock_btultra_extDict
Annotated Snippet
if (optPtr->litLengthSum == 0) { /* no literals stats collected -> first block assumed -> init */
/* heuristic: use pre-defined stats for too small inputs */
if (srcSize <= ZSTD_PREDEF_THRESHOLD) {
DEBUGLOG(5, "srcSize <= %i : use predefined stats", ZSTD_PREDEF_THRESHOLD);
optPtr->priceType = zop_predef;
}
assert(optPtr->symbolCosts != NULL);
if (optPtr->symbolCosts->huf.repeatMode == HUF_repeat_valid) {
/* huffman stats covering the full value set : table presumed generated by dictionary */
optPtr->priceType = zop_dynamic;
if (compressedLiterals) {
/* generate literals statistics from huffman table */
unsigned lit;
assert(optPtr->litFreq != NULL);
optPtr->litSum = 0;
for (lit=0; lit<=MaxLit; lit++) {
U32 const scaleLog = 11; /* scale to 2K */
U32 const bitCost = HUF_getNbBitsFromCTable(optPtr->symbolCosts->huf.CTable, lit);
assert(bitCost <= scaleLog);
optPtr->litFreq[lit] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
optPtr->litSum += optPtr->litFreq[lit];
} }
{ unsigned ll;
FSE_CState_t llstate;
FSE_initCState(&llstate, optPtr->symbolCosts->fse.litlengthCTable);
optPtr->litLengthSum = 0;
for (ll=0; ll<=MaxLL; ll++) {
U32 const scaleLog = 10; /* scale to 1K */
U32 const bitCost = FSE_getMaxNbBits(llstate.symbolTT, ll);
assert(bitCost < scaleLog);
optPtr->litLengthFreq[ll] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
optPtr->litLengthSum += optPtr->litLengthFreq[ll];
} }
{ unsigned ml;
FSE_CState_t mlstate;
FSE_initCState(&mlstate, optPtr->symbolCosts->fse.matchlengthCTable);
optPtr->matchLengthSum = 0;
for (ml=0; ml<=MaxML; ml++) {
U32 const scaleLog = 10;
U32 const bitCost = FSE_getMaxNbBits(mlstate.symbolTT, ml);
assert(bitCost < scaleLog);
optPtr->matchLengthFreq[ml] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
optPtr->matchLengthSum += optPtr->matchLengthFreq[ml];
} }
{ unsigned of;
FSE_CState_t ofstate;
FSE_initCState(&ofstate, optPtr->symbolCosts->fse.offcodeCTable);
optPtr->offCodeSum = 0;
for (of=0; of<=MaxOff; of++) {
U32 const scaleLog = 10;
U32 const bitCost = FSE_getMaxNbBits(ofstate.symbolTT, of);
assert(bitCost < scaleLog);
optPtr->offCodeFreq[of] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
optPtr->offCodeSum += optPtr->offCodeFreq[of];
} }
} else { /* first block, no dictionary */
assert(optPtr->litFreq != NULL);
if (compressedLiterals) {
/* base initial cost of literals on direct frequency within src */
unsigned lit = MaxLit;
HIST_count_simple(optPtr->litFreq, &lit, src, srcSize); /* use raw first block to init statistics */
optPtr->litSum = ZSTD_downscaleStats(optPtr->litFreq, MaxLit, 8, base_0possible);
}
{ unsigned const baseLLfreqs[MaxLL+1] = {
4, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1
};
ZSTD_memcpy(optPtr->litLengthFreq, baseLLfreqs, sizeof(baseLLfreqs));
optPtr->litLengthSum = sum_u32(baseLLfreqs, MaxLL+1);
}
{ unsigned ml;
for (ml=0; ml<=MaxML; ml++)
optPtr->matchLengthFreq[ml] = 1;
}
optPtr->matchLengthSum = MaxML+1;
Annotation
- Immediate include surface: `zstd_compress_internal.h`, `hist.h`, `zstd_opt.h`.
- Detected declarations: `function Copyright`, `function ZSTD_fracWeight`, `function ZSTD_fCost`, `function ZSTD_compressedLiterals`, `function ZSTD_setBasePrices`, `function sum_u32`, `function ZSTD_downscaleStats`, `function ZSTD_scaleStats`, `function block`, `function literals`.
- 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.