lib/zstd/compress/zstd_ldm.c
Source file repositories/reference/linux-study-clean/lib/zstd/compress/zstd_ldm.c
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/compress/zstd_ldm.c- Extension
.c- Size
- 29352 bytes
- Lines
- 747
- 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_ldm.h../common/debug.hlinux/xxhash.hzstd_fast.hzstd_double_fast.hzstd_ldm_geartab.h
Detected Declarations
function ZSTD_ldm_gear_initfunction ZSTD_ldm_gear_resetfunction ZSTD_ldm_gear_feedfunction ZSTD_ldm_adjustParametersfunction ZSTD_ldm_getTableSizefunction ZSTD_ldm_getMaxNbSeqfunction ZSTD_ldm_getBucketfunction ZSTD_ldm_insertEntryfunction ZSTD_ldm_countBackwardsMatchfunction ZSTD_ldm_countBackwardsMatch_2segmentsfunction ZSTD_ldm_fillFastTablesfunction ZSTD_ldm_fillHashTablefunction ZSTD_ldm_limitTableUpdatefunction ZSTD_ldm_generateSequences_internalfunction boostfunction ZSTD_ldm_reduceTablefunction ZSTD_ldm_generateSequencesfunction ZSTD_ldm_skipSequencesfunction maybeSplitSequencefunction ZSTD_ldm_skipRawSeqStoreBytesfunction ZSTD_ldm_blockCompress
Annotated Snippet
if (hashRateLog > 0 && hashRateLog <= maxBitsInMask) {
state->stopMask = (((U64)1 << hashRateLog) - 1) << (maxBitsInMask - hashRateLog);
} else {
/* In this degenerate case we simply honor the hash rate. */
state->stopMask = ((U64)1 << hashRateLog) - 1;
}
}
/* ZSTD_ldm_gear_reset()
* Feeds [data, data + minMatchLength) into the hash without registering any
* splits. This effectively resets the hash state. This is used when skipping
* over data, either at the beginning of a block, or skipping sections.
*/
static void ZSTD_ldm_gear_reset(ldmRollingHashState_t* state,
BYTE const* data, size_t minMatchLength)
{
U64 hash = state->rolling;
size_t n = 0;
#define GEAR_ITER_ONCE() do { \
hash = (hash << 1) + ZSTD_ldm_gearTab[data[n] & 0xff]; \
n += 1; \
} while (0)
while (n + 3 < minMatchLength) {
GEAR_ITER_ONCE();
GEAR_ITER_ONCE();
GEAR_ITER_ONCE();
GEAR_ITER_ONCE();
}
while (n < minMatchLength) {
GEAR_ITER_ONCE();
}
#undef GEAR_ITER_ONCE
}
/* ZSTD_ldm_gear_feed():
*
* Registers in the splits array all the split points found in the first
* size bytes following the data pointer. This function terminates when
* either all the data has been processed or LDM_BATCH_SIZE splits are
* present in the splits array.
*
* Precondition: The splits array must not be full.
* Returns: The number of bytes processed. */
static size_t ZSTD_ldm_gear_feed(ldmRollingHashState_t* state,
BYTE const* data, size_t size,
size_t* splits, unsigned* numSplits)
{
size_t n;
U64 hash, mask;
hash = state->rolling;
mask = state->stopMask;
n = 0;
#define GEAR_ITER_ONCE() do { \
hash = (hash << 1) + ZSTD_ldm_gearTab[data[n] & 0xff]; \
n += 1; \
if (UNLIKELY((hash & mask) == 0)) { \
splits[*numSplits] = n; \
*numSplits += 1; \
if (*numSplits == LDM_BATCH_SIZE) \
goto done; \
} \
} while (0)
while (n + 3 < size) {
GEAR_ITER_ONCE();
GEAR_ITER_ONCE();
GEAR_ITER_ONCE();
GEAR_ITER_ONCE();
}
while (n < size) {
GEAR_ITER_ONCE();
}
#undef GEAR_ITER_ONCE
done:
state->rolling = hash;
return n;
}
void ZSTD_ldm_adjustParameters(ldmParams_t* params,
const ZSTD_compressionParameters* cParams)
{
params->windowLog = cParams->windowLog;
ZSTD_STATIC_ASSERT(LDM_BUCKET_SIZE_LOG <= ZSTD_LDM_BUCKETSIZELOG_MAX);
DEBUGLOG(4, "ZSTD_ldm_adjustParameters");
if (params->hashRateLog == 0) {
Annotation
- Immediate include surface: `zstd_ldm.h`, `../common/debug.h`, `linux/xxhash.h`, `zstd_fast.h`, `zstd_double_fast.h`, `zstd_ldm_geartab.h`.
- Detected declarations: `function ZSTD_ldm_gear_init`, `function ZSTD_ldm_gear_reset`, `function ZSTD_ldm_gear_feed`, `function ZSTD_ldm_adjustParameters`, `function ZSTD_ldm_getTableSize`, `function ZSTD_ldm_getMaxNbSeq`, `function ZSTD_ldm_getBucket`, `function ZSTD_ldm_insertEntry`, `function ZSTD_ldm_countBackwardsMatch`, `function ZSTD_ldm_countBackwardsMatch_2segments`.
- 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.