lib/zstd/decompress/huf_decompress.c
Source file repositories/reference/linux-study-clean/lib/zstd/decompress/huf_decompress.c
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/decompress/huf_decompress.c- Extension
.c- Size
- 76887 bytes
- Lines
- 1942
- 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
../common/zstd_deps.h../common/compiler.h../common/bitstream.h../common/fse.h../common/huf.h../common/error_private.h../common/zstd_internal.h../common/bits.h
Detected Declarations
function fnfunction HUF_getDTableDescfunction HUF_initFastDStreamfunction HUF_DecompressFastArgs_initfunction HUF_initRemainingDStreamfunction HUF_DEltX1_set4function HUF_rescaleStatsfunction HUF_readDTableX1_wkspfunction HUF_decodeSymbolX1function HUF_decodeStreamX1function HUF_decompress1X1_usingDTable_internal_bodyfunction HUF_decompress4X1_usingDTable_internal_bodyfunction HUF_decompress4X1_usingDTable_internal_bmi2function HUF_decompress4X1_usingDTable_internal_defaultfunction HUF_decompress4X1_usingDTable_internal_fast_c_loopfunction HUF_decompress4X1_usingDTable_internal_fastfunction HUF_decompress4X1_usingDTable_internalfunction HUF_decompress4X1_DCtx_wkspfunction HUF_buildDEltX2U32function HUF_buildDEltX2function HUF_buildDEltX2U64function HUF_fillDTableX2ForWeightfunction HUF_fillDTableX2Level2function HUF_fillDTableX2function HUF_readDTableX2_wkspfunction HUF_decodeSymbolX2function HUF_decodeLastSymbolX2function HUF_decodeStreamX2function HUF_decompress1X2_usingDTable_internal_bodyfunction HUF_decompress4X2_usingDTable_internal_bodyfunction HUF_decompress4X2_usingDTable_internal_bmi2function HUF_decompress4X2_usingDTable_internal_defaultfunction HUF_decompress4X2_usingDTable_internal_fast_c_loopfunction HUF_decompress4X2_usingDTable_internal_fastfunction HUF_decompress4X2_usingDTable_internalfunction HUF_decompress1X2_DCtx_wkspfunction HUF_decompress4X2_DCtx_wkspfunction HUF_selectDecoderfunction HUF_decompress1X_DCtx_wkspfunction HUF_decompress1X_usingDTablefunction HUF_decompress1X1_DCtx_wkspfunction HUF_decompress4X_usingDTablefunction HUF_decompress4X_hufOnly_wksp
Annotated Snippet
if (flags & HUF_flags_bmi2) { \
return fn##_bmi2(dst, dstSize, cSrc, cSrcSize, DTable); \
} \
return fn##_default(dst, dstSize, cSrc, cSrcSize, DTable); \
}
#else
#define HUF_DGEN(fn) \
static size_t fn(void* dst, size_t dstSize, void const* cSrc, \
size_t cSrcSize, HUF_DTable const* DTable, int flags) \
{ \
(void)flags; \
return fn##_body(dst, dstSize, cSrc, cSrcSize, DTable); \
}
#endif
/*-***************************/
/* generic DTableDesc */
/*-***************************/
typedef struct { BYTE maxTableLog; BYTE tableType; BYTE tableLog; BYTE reserved; } DTableDesc;
static DTableDesc HUF_getDTableDesc(const HUF_DTable* table)
{
DTableDesc dtd;
ZSTD_memcpy(&dtd, table, sizeof(dtd));
return dtd;
}
static size_t HUF_initFastDStream(BYTE const* ip) {
BYTE const lastByte = ip[7];
size_t const bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
size_t const value = MEM_readLEST(ip) | 1;
assert(bitsConsumed <= 8);
assert(sizeof(size_t) == 8);
return value << bitsConsumed;
}
/*
* The input/output arguments to the Huffman fast decoding loop:
*
* ip [in/out] - The input pointers, must be updated to reflect what is consumed.
* op [in/out] - The output pointers, must be updated to reflect what is written.
* bits [in/out] - The bitstream containers, must be updated to reflect the current state.
* dt [in] - The decoding table.
* ilowest [in] - The beginning of the valid range of the input. Decoders may read
* down to this pointer. It may be below iend[0].
* oend [in] - The end of the output stream. op[3] must not cross oend.
* iend [in] - The end of each input stream. ip[i] may cross iend[i],
* as long as it is above ilowest, but that indicates corruption.
*/
typedef struct {
BYTE const* ip[4];
BYTE* op[4];
U64 bits[4];
void const* dt;
BYTE const* ilowest;
BYTE* oend;
BYTE const* iend[4];
} HUF_DecompressFastArgs;
typedef void (*HUF_DecompressFastLoopFn)(HUF_DecompressFastArgs*);
/*
* Initializes args for the fast decoding loop.
* @returns 1 on success
* 0 if the fallback implementation should be used.
* Or an error code on failure.
*/
static size_t HUF_DecompressFastArgs_init(HUF_DecompressFastArgs* args, void* dst, size_t dstSize, void const* src, size_t srcSize, const HUF_DTable* DTable)
{
void const* dt = DTable + 1;
U32 const dtLog = HUF_getDTableDesc(DTable).tableLog;
const BYTE* const istart = (const BYTE*)src;
BYTE* const oend = ZSTD_maybeNullPtrAdd((BYTE*)dst, dstSize);
/* The fast decoding loop assumes 64-bit little-endian.
* This condition is false on x32.
*/
if (!MEM_isLittleEndian() || MEM_32bits())
return 0;
/* Avoid nullptr addition */
if (dstSize == 0)
return 0;
Annotation
- Immediate include surface: `../common/zstd_deps.h`, `../common/compiler.h`, `../common/bitstream.h`, `../common/fse.h`, `../common/huf.h`, `../common/error_private.h`, `../common/zstd_internal.h`, `../common/bits.h`.
- Detected declarations: `function fn`, `function HUF_getDTableDesc`, `function HUF_initFastDStream`, `function HUF_DecompressFastArgs_init`, `function HUF_initRemainingDStream`, `function HUF_DEltX1_set4`, `function HUF_rescaleStats`, `function HUF_readDTableX1_wksp`, `function HUF_decodeSymbolX1`, `function HUF_decodeStreamX1`.
- 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.