|
ZXC 1.0.3
High-performance asymmetric lossless compression library
|
Block-level decompression: SPL / PAK / RAW decoding with SIMD-accelerated bit-unpacking and overlapping copies. More...
Go to the source code of this file.
Macros | |
| #define | DECODE_MATCH_SAFE(ml, off, COPY) |
| #define | DECODE_MATCH_FAST(ml, off, COPY) |
| #define | SPL_OFF8 (gh.enc_off == 1) |
| True when the SPL offset stream stores 1-byte offsets, 2-byte otherwise. | |
| #define | DECODE_SPL_SEQ(LL, ML, OFF, RESERVE, N_REM, DECODE, ON_FAIL) |
Decodes one SPL sequence of a 4x batch: extracts ll/ml, applies the varint extensions with their bounds checks, then emits via DECODE. | |
| #define | DECODE_SPL_BATCH_4X(DECODE, ON_FAIL) |
| One full SPL 4x batch: token word, four offsets (1- or 2-byte form), four DECODE_SPL_SEQ emissions, sequence-count update. | |
| #define | DECODE_PAK_SEQ(S, RESERVE, N_REM, DECODE, ON_FAIL) |
PAK twin of DECODE_SPL_SEQ, decoding one sequence word S (ll in the top byte, ml bits, 16-bit offset). | |
| #define | DECODE_PAK_BATCH_4X(DECODE, ON_FAIL, PREFETCH) |
| One full PAK 4x batch. | |
Functions | |
| static void | zxc_decode_copy_overlap_run32 (uint8_t *dst, const uint32_t off, const uint64_t ml) |
Copies an ml-byte run of period off (2..31) with 32-byte stores. | |
| static void | zxc_decode_copy_overlap_short (uint8_t *dst, const uint32_t off, const uint64_t ml) |
Overlap copy for a run of period off (2..31) bounded by ml <= 32. | |
| static void | zxc_decode_fill_run (uint8_t *dst, const uint8_t byte, const uint64_t ml) |
Fills an ml-byte single-byte run (LZ offset == 1) with wild stores. | |
| static void | zxc_wild_copy32 (uint8_t *dst, const uint8_t *src, const size_t len) |
Copies len bytes in 32-byte wild chunks (the zxc_copy32 width). | |
| static void | zxc_decode_copy_literals (uint8_t *dst, const uint8_t *src, const uint64_t ll) |
Copies ll literal bytes from src to dst using 32-byte wild copies. | |
| static void | zxc_decode_copy_match (uint8_t *d_ptr, const uint32_t off, const uint64_t ml) |
Copies an ml-byte LZ match from d_ptr-off to d_ptr, handling overlap. | |
| static void | zxc_decode_copy_match_short (uint8_t *d_ptr, const uint32_t off, const uint64_t ml) |
| Match copy for a length that cannot exceed 32 bytes. | |
| static void | zxc_decode_copy_match_spl (uint8_t *d_ptr, const uint32_t off, const uint64_t ml) |
| SPL match copy: bounded form when the ml nibble did not saturate. | |
| static void | zxc_decode_copy_match_exact (uint8_t *d_ptr, const uint8_t *match_src, const size_t off, const size_t ml) |
| Exact-size match copy for the tail loops (no overshoot headroom). | |
| static int | zxc_ensure_entropy_scratch (const zxc_cctx_t *ctx) |
| Ensures the entropy decode scratch (tok_buffer + pivco_scratch) is available before decoding an entropy section. | |
| static int | zxc_decode_lit_pivco (const zxc_cctx_t *ctx, const uint8_t *payload, const size_t psize, const size_t required_size) |
| static int | zxc_decode_lit_pivco_dict (const zxc_cctx_t *ctx, const uint8_t *payload, const size_t psize, const size_t required_size) |
| static int | zxc_decode_tok_pivco (const zxc_cctx_t *ctx, const uint8_t *payload, const size_t psize, const size_t n_tok) |
| static int | zxc_decode_block_spl_entropy (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Cold specializations for entropy-coded SPL tokens (level 7). | |
| static int | zxc_decode_block_spl_entropy_dict (const zxc_cctx_t *ctx, const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_capacity) |
| static int | zxc_decode_block_spl_entropy_safe (const zxc_cctx_t *ctx, const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_capacity) |
| static int | zxc_decode_block_spl_impl (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity, const int safe, const int has_dict, const int tok_entropy) |
| Unified SPL (split streams) block decoder body, shared by the fast, safe, dictionary and entropy-token variants. | |
| static int | zxc_decode_block_pak_impl (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity, const int safe, const int has_dict) |
| Unified PAK (packed sequences) block decoder body, shared by the fast, safe and dictionary variants. | |
| static int | zxc_decode_block_spl (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Decode a no-dict SPL block (plain, inlinable path). | |
| static int | zxc_decode_block_pak (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Decode a no-dict PAK block (plain, inlinable path). | |
| static int | zxc_decode_block_spl_dict (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Decode a SPL block against a dictionary prefix (cold path). | |
| static int | zxc_decode_block_pak_dict (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Decode a PAK block against a dictionary prefix (cold path). | |
| static int | zxc_decode_block_spl_safe (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Decode a SPL block with the strict-tail safe loop (no wild copies). | |
| static int | zxc_decode_block_pak_safe (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_size, uint8_t *dst, const size_t dst_capacity) |
| Decode a PAK block with the strict-tail safe loop (no wild copies). | |
| static int | zxc_decompress_chunk_wrapper_body (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_sz, uint8_t *dst, const size_t dst_cap, const uint64_t block_index, const int has_dict, const int safe) |
| Shared chunk-decode body: validates the header, decodes, then verifies the optional checksum. | |
| int | zxc_decompress_chunk_wrapper (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_sz, uint8_t *dst, const size_t dst_cap, const uint64_t block_index) |
| Public no-dict chunk decoder (decompression hot path). | |
| int | zxc_decompress_chunk_wrapper_dict (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_sz, uint8_t *dst, const size_t dst_cap, const uint64_t block_index) |
| Public dictionary chunk decoder. | |
| int | zxc_decompress_chunk_wrapper_safe (const zxc_cctx_t *ctx, const uint8_t *src, const size_t src_sz, uint8_t *dst, const size_t dst_cap, const uint64_t block_index) |
| Public strict-tail safe chunk decoder (dst_cap == exact decoded size). | |
Variables | |
| static const uint8_t | zxc_overlap_strides32 [32] |
| Store stride for the 32-byte pattern: (32 / off) * off. | |
Block-level decompression: SPL / PAK / RAW decoding with SIMD-accelerated bit-unpacking and overlapping copies.
Like zxc_compress.c, this file is compiled multiple times with ZXC_FUNCTION_SUFFIX to produce per-ISA variants.
Definition in file zxc_decompress.c.
| #define DECODE_MATCH_FAST | ( | ml, | |
| off, | |||
| COPY ) |
Definition at line 541 of file zxc_decompress.c.
| #define DECODE_MATCH_SAFE | ( | ml, | |
| off, | |||
| COPY ) |
Definition at line 532 of file zxc_decompress.c.
| #define DECODE_PAK_BATCH_4X | ( | DECODE, | |
| ON_FAIL, | |||
| PREFETCH ) |
One full PAK 4x batch.
PREFETCH is the literal-stream prefetch statement of the post-threshold FAST loops ((void)0 elsewhere), placed exactly where the hand-unrolled bodies had it.
Definition at line 680 of file zxc_decompress.c.
Referenced by zxc_decode_block_pak_impl().
| #define DECODE_PAK_SEQ | ( | S, | |
| RESERVE, | |||
| N_REM, | |||
| DECODE, | |||
| ON_FAIL ) |
PAK twin of DECODE_SPL_SEQ, decoding one sequence word S (ll in the top byte, ml bits, 16-bit offset).
References the call site's extras_ptr/extras_end instead of e_ptr/e_end.
Definition at line 647 of file zxc_decompress.c.
| #define DECODE_SPL_BATCH_4X | ( | DECODE, | |
| ON_FAIL ) |
One full SPL 4x batch: token word, four offsets (1- or 2-byte form), four DECODE_SPL_SEQ emissions, sequence-count update.
The offsets stay packed in one u64 of 16-bit lanes, 1-byte offsets spread into it, and each sequence extracts its own: four decoded offsets held live cost x86-64 spills.
Definition at line 613 of file zxc_decompress.c.
Referenced by zxc_decode_block_spl_impl().
| #define DECODE_SPL_SEQ | ( | LL, | |
| ML, | |||
| OFF, | |||
| RESERVE, | |||
| N_REM, | |||
| DECODE, | |||
| ON_FAIL ) |
Decodes one SPL sequence of a 4x batch: extracts ll/ml, applies the varint extensions with their bounds checks, then emits via DECODE.
Like DECODE_MATCH_SAFE, references the call site's local names (e_ptr, e_end, l_ptr, l_end, d_ptr, d_end). RESERVE is the sum of the inline (pre-varint) literal lengths of the batch's remaining sequences, so one l_ptr bound covers the whole batch; N_REM counts the remaining sequences, reserving their worst-case inline output in the d_ptr bound (0 for the last sequence - the compiler folds the dead terms). ON_FAIL is goto rollback_* in the state-saving safe variants and return ZXC_ERROR_OVERFLOW otherwise.
Definition at line 573 of file zxc_decompress.c.
| #define SPL_OFF8 (gh.enc_off == 1) |
True when the SPL offset stream stores 1-byte offsets, 2-byte otherwise.
The single definition of the offset width: the stream-size check, the validation span and every read site expand from this, so a bound can never drift from the width actually consumed. A macro rather than a local flag on purpose – holding one more value live across the decode costs more spills in these register-starved loops than re-reading the header field.
References the call site's gh, like the DECODE_* macros below.
Definition at line 558 of file zxc_decompress.c.
Referenced by zxc_decode_block_spl_impl().
|
static |
Decode a no-dict PAK block (plain, inlinable path).
Wrapper over zxc_decode_block_pak_impl with safe=0, has_dict=0.
| [in,out] | ctx | Decompression context. |
| [in] | src | Compressed PAK block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer. |
| [in] | dst_capacity | Capacity of dst in bytes. |
Definition at line 1484 of file zxc_decompress.c.
References zxc_decode_block_pak_impl().
Referenced by zxc_decompress_chunk_wrapper_body().
|
static |
Decode a PAK block against a dictionary prefix (cold path).
Wrapper over zxc_decode_block_pak_impl with safe=0, has_dict=1 (NOINLINE; see zxc_decode_block_spl_dict).
| [in,out] | ctx | Decompression context (dict prefix in its buffer). |
| [in] | src | Compressed PAK block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer. |
| [in] | dst_capacity | Capacity of dst in bytes. |
Definition at line 1527 of file zxc_decompress.c.
References zxc_decode_block_pak_impl(), and ZXC_NOINLINE.
Referenced by zxc_decompress_chunk_wrapper_body().
|
inlinestatic |
Unified PAK (packed sequences) block decoder body, shared by the fast, safe and dictionary variants.
Decodes a block in the internal PAK format. The decompressed size is not on the wire: it falls out of walking the sequences. safe and has_dict must be compile-time constants (0 or 1): the 4x-unrolled loops are duplicated inside if(safe)/else branches so each variant keeps single-assignment const save pointers, and after constant propagation only one branch survives per wrapper.
| [in,out] | ctx | Decompression context (dict buffer, tables). |
| [in] | src | Compressed block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer for decoded bytes. |
| [in] | dst_capacity | Capacity of dst in bytes. |
| [in] | safe | Compile-time flag: 1 = strict bounds-checked loop. |
| [in] | has_dict | Compile-time flag: 1 = resolve matches against a dict prefix. |
dst on success, or a negative zxc_error_t. Definition at line 1184 of file zxc_decompress.c.
References DECODE_PAK_BATCH_4X, zxc_gnr_header_t::enc_lit, zxc_gnr_header_t::enc_tok, zxc_gnr_header_t::n_literals, zxc_gnr_header_t::n_sequences, ZXC_ALWAYS_INLINE, ZXC_BLOCK_LIT_SLACK, ZXC_CACHE_LINE_SIZE, zxc_decode_copy_literals(), zxc_decode_copy_match(), zxc_decode_copy_match_exact(), ZXC_DECOMPRESS_TAIL_PAD, ZXC_ERROR_BAD_HEADER, ZXC_ERROR_BAD_OFFSET, ZXC_ERROR_CORRUPT_DATA, ZXC_ERROR_OVERFLOW, zxc_le32(), ZXC_LZ_MIN_MATCH_LEN, ZXC_LZ_OFFSET_BIAS, ZXC_OK, ZXC_PAD_SIZE, ZXC_PAK_HEADER_BINARY_SIZE, zxc_read_pak_header(), zxc_read_varint(), ZXC_SEQ_LL_MASK, ZXC_SEQ_LL_SHIFT, ZXC_SEQ_ML_MASK, ZXC_SEQ_ML_SHIFT, and ZXC_SEQ_OFF_MASK.
Referenced by zxc_decode_block_pak(), zxc_decode_block_pak_dict(), and zxc_decode_block_pak_safe().
|
static |
Decode a PAK block with the strict-tail safe loop (no wild copies).
Wrapper over zxc_decode_block_pak_impl with safe=1, has_dict=0 (the strict-tail safe path never carries a dict; see zxc_decode_block_spl_safe).
| [in,out] | ctx | Decompression context. |
| [in] | src | Compressed PAK block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer (capacity == exact decoded size). |
| [in] | dst_capacity | Capacity of dst in bytes. |
Definition at line 1570 of file zxc_decompress.c.
References zxc_decode_block_pak_impl(), and ZXC_NOINLINE.
Referenced by zxc_decompress_chunk_wrapper_body().
|
static |
Decode a no-dict SPL block (plain, inlinable path).
Wrapper over zxc_decode_block_spl_impl with safe=0, has_dict=0, so the no-dict chunk wrapper inlines it exactly like the dict-free build.
| [in,out] | ctx | Decompression context. |
| [in] | src | Compressed SPL block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer. |
| [in] | dst_capacity | Capacity of dst in bytes. |
Definition at line 1466 of file zxc_decompress.c.
References zxc_decode_block_spl_impl().
Referenced by zxc_decompress_chunk_wrapper_body().
|
static |
Decode a SPL block against a dictionary prefix (cold path).
Wrapper over zxc_decode_block_spl_impl with safe=0, has_dict=1. NOINLINE: only reached on the cold dict path (zxc_decompress_chunk_wrapper_dict), so it never loads into I-cache on a no-dict stream.
| [in,out] | ctx | Decompression context (dict prefix in its buffer). |
| [in] | src | Compressed SPL block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer. |
| [in] | dst_capacity | Capacity of dst in bytes. |
Definition at line 1505 of file zxc_decompress.c.
References zxc_decode_block_spl_impl(), and ZXC_NOINLINE.
Referenced by zxc_decompress_chunk_wrapper_body().
|
static |
Cold specializations for entropy-coded SPL tokens (level 7).
Each wrapper fixes tok_entropy=1 plus one (safe, has_dict) combo as compile-time constants, so the inlined impl is fully specialized and the RAW-token fast path stays untouched.
Definition at line 1428 of file zxc_decompress.c.
References zxc_decode_block_spl_impl(), and ZXC_NOINLINE.
Referenced by zxc_decode_block_spl_impl().
|
static |
Definition at line 1436 of file zxc_decompress.c.
|
static |
Definition at line 1445 of file zxc_decompress.c.
|
inlinestatic |
Unified SPL (split streams) block decoder body, shared by the fast, safe, dictionary and entropy-token variants.
Decodes a block in the internal SPL format. The decompressed size is not on the wire: it falls out of walking the sequences. safe, has_dict and tok_entropy must be compile-time constants (0 or 1): the 4x-unrolled loops are duplicated inside if(safe)/else branches so each variant keeps single-assignment const save pointers, and after constant propagation only one branch survives per wrapper (codegen equivalent to a hand-written pair).
The tok_entropy dimension keeps the token pointer on a SINGLE provenance per instantiation (in-place src tokens vs ctx->tok_buffer): the tok_entropy=0 instantiations tail-call their entropy twin right after the header parse when they meet enc_tok == 2.
| [in,out] | ctx | Decompression context (dict buffer, scratch). |
| [in] | src | Compressed block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer for decoded bytes. |
| [in] | dst_capacity | Capacity of dst in bytes. |
| [in] | safe | Compile-time flag: 1 = strict bounds-checked loop. |
| [in] | has_dict | Compile-time flag: 1 = resolve matches against a dict prefix. |
| [in] | tok_entropy | Compile-time flag: 1 = tokens are a PivCo section decoded into ctx->tok_buffer (level 7). |
dst on success, or a negative zxc_error_t. Definition at line 806 of file zxc_decompress.c.
References DECODE_SPL_BATCH_4X, zxc_gnr_header_t::enc_lit, zxc_gnr_header_t::enc_off, zxc_gnr_header_t::enc_tok, zxc_gnr_header_t::n_literals, zxc_gnr_header_t::n_sequences, SPL_OFF8, ZXC_ALWAYS_INLINE, ZXC_BLOCK_LIT_SLACK, zxc_copy16(), zxc_copy32(), zxc_decode_block_spl_entropy(), zxc_decode_copy_literals(), zxc_decode_copy_match_exact(), zxc_decode_copy_match_spl(), ZXC_ERROR_BAD_HEADER, ZXC_ERROR_BAD_OFFSET, ZXC_ERROR_CORRUPT_DATA, ZXC_ERROR_DST_TOO_SMALL, ZXC_ERROR_OVERFLOW, zxc_le16(), ZXC_LIT_LEN_MASK, ZXC_LIT_RLE_FLAG, ZXC_LIT_RLE_RUN_MIN, ZXC_LZ_MIN_MATCH_LEN, ZXC_LZ_OFFSET_BIAS, ZXC_OK, ZXC_PAD_SIZE, zxc_read_spl_header_and_desc(), zxc_read_varint(), ZXC_SPL_MAX_INLINE_OUT_PER_SEQ, ZXC_TOKEN_LIT_BITS, ZXC_TOKEN_LL_MASK, and ZXC_TOKEN_ML_MASK.
Referenced by zxc_decode_block_spl(), zxc_decode_block_spl_dict(), zxc_decode_block_spl_entropy(), and zxc_decode_block_spl_safe().
|
static |
Decode a SPL block with the strict-tail safe loop (no wild copies).
Wrapper over zxc_decode_block_spl_impl with safe=1, has_dict=0. The safe path never carries a dict (block_safe routes dict inputs to the bounce path), so has_dict=0 folds the dead dict handling.
| [in,out] | ctx | Decompression context. |
| [in] | src | Compressed SPL block payload. |
| [in] | src_size | Size of src in bytes. |
| [out] | dst | Destination buffer (capacity == exact decoded size). |
| [in] | dst_capacity | Capacity of dst in bytes. |
Definition at line 1549 of file zxc_decompress.c.
References zxc_decode_block_spl_impl(), and ZXC_NOINLINE.
Referenced by zxc_decompress_chunk_wrapper_body().
|
inlinestatic |
Copies ll literal bytes from src to dst using 32-byte wild copies.
Writes in 32-byte chunks – the width of zxc_copy32 – and may overshoot by up to 31 bytes past ll; the caller must guarantee dst has at least ZXC_PAD_SIZE bytes of writable headroom (the unrolled loops and the trailing-literal margins ensure this). Pointers are taken by value and the caller advances its own cursors by ll, keeping them in registers on the hot path.
| [out] | dst | Output cursor. Must not overlap src and must have ZXC_PAD_SIZE bytes of overshoot headroom. |
| [in] | src | Literal-stream source. Must not overlap dst (RESTRICT). |
| [in] | ll | Number of literal bytes to copy. |
Definition at line 408 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, and zxc_wild_copy32().
Referenced by zxc_decode_block_pak_impl(), and zxc_decode_block_spl_impl().
|
inlinestatic |
Copies an ml-byte LZ match from d_ptr-off to d_ptr, handling overlap.
The source d_ptr-off may overlap the destination (the LZ repeat case), so the copy strategy is chosen by back-reference distance:
off >= 32 : 32-byte wild copies (no overlap within a chunk);off == 1 : single-byte run via zxc_decode_fill_run;The 32 and 16 below are the widths of zxc_copy32 and zxc_copy16 – a copy may never be wider than the distance it reads back, or it would read bytes it is still writing. They are not ZXC_PAD_SIZE, which measures the overshoot the caller leaves writable and merely happens to equal 32.
Like zxc_decode_copy_literals it may overshoot up to 31 bytes past ml, so d_ptr must have ZXC_PAD_SIZE bytes of headroom. d_ptr is taken by value; the caller advances its cursor by ml.
| [in,out] | d_ptr | Output cursor; the match source is d_ptr-off. Must have ZXC_PAD_SIZE bytes of overshoot headroom. |
| [in] | off | Resolved (bias-removed) back-reference distance, >= 1. |
| [in] | ml | Match length in bytes (>= ZXC_LZ_MIN_MATCH_LEN). |
Definition at line 437 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, zxc_decode_copy_overlap_run32(), zxc_decode_fill_run(), and zxc_wild_copy32().
Referenced by zxc_decode_block_pak_impl(), and zxc_decode_copy_match_spl().
|
static |
Exact-size match copy for the tail loops (no overshoot headroom).
The tail/remaining-sequence loops validate against d_end exactly, so the wild-copy ladder above (which overshoots up to ZXC_PAD_SIZE) is off limits there. For overlapping matches this expands the run by doubling: every ZXC_MEMCPY source range ends at or before its destination start, and nothing is written past d_ptr+ml. Since each copied prefix length is a multiple of off, the result is byte-identical to the naive per-byte copy, in O(log(ml/off)) calls instead of O(ml) iterations.
| [in,out] | d_ptr | Output cursor (match source is d_ptr-off). |
| [in] | match_src | Match source, equal to d_ptr-off. |
| [in] | off | Back-reference distance, >= 1. |
| [in] | ml | Match length in bytes. |
Definition at line 508 of file zxc_decompress.c.
References ZXC_NOINLINE.
Referenced by zxc_decode_block_pak_impl(), and zxc_decode_block_spl_impl().
|
inlinestatic |
Match copy for a length that cannot exceed 32 bytes.
zxc_decode_copy_match without its length ladder, which a bounded ml makes unreachable. Below 32 a full-width copy would read destination bytes not written yet, hence the overlap form.
The 32 is the width of zxc_copy32, not ZXC_PAD_SIZE - they only happen to share a value.
| [in,out] | d_ptr | Output cursor; match source is d_ptr-off. Needs ZXC_PAD_SIZE bytes of overshoot headroom. |
| [in] | off | Resolved back-reference distance, >= 1. |
| [in] | ml | Match length, <= 32 (caller's obligation). |
Definition at line 464 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, zxc_copy32(), zxc_decode_copy_overlap_short(), and zxc_decode_fill_run().
Referenced by zxc_decode_copy_match_spl().
|
inlinestatic |
SPL match copy: bounded form when the ml nibble did not saturate.
The test is exact (the escape always yields more) and statically decidable from either predecessor, so jump threading folds it away. PAK uses zxc_decode_copy_match directly - its inline ml reaches 259.
Definition at line 483 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, zxc_decode_copy_match(), zxc_decode_copy_match_short(), and ZXC_SPL_MAX_INLINE_ML.
Referenced by zxc_decode_block_spl_impl().
|
inlinestatic |
Copies an ml-byte run of period off (2..31) with 32-byte stores.
Builds the run's first 32 bytes in a register pair, then stores them repeatedly. Nothing is re-shuffled: advancing by a multiple of off keeps the pattern in phase.
Replaced a 16-byte form that reloaded the source every iteration, which for offsets of 17 and up straddled two of its own recent stores and stalled on store forwarding - worth up to 7x on periodic data.
Reading 32 source bytes touches destination bytes not written yet on the smallest offsets. They are never selected (every mask index is < off) and sit inside the ZXC_PAD_SIZE headroom the caller owes.
May overshoot up to 31 bytes past ml, like the 32-byte copy ladder.
| [out] | dst | Output cursor; the run source is dst - off. |
| [in] | off | Back-reference distance, in [2, 31]. |
| [in] | ml | Run length in bytes (>= 1). |
Definition at line 148 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, zxc_copy16(), and zxc_overlap_strides32.
Referenced by zxc_decode_copy_match().
|
inlinestatic |
Overlap copy for a run of period off (2..31) bounded by ml <= 32.
Bounded length buys two things over zxc_decode_copy_overlap_run32(): the loop disappears, and the upper 16 bytes are skipped whenever ml allows - which is most of the time, SPL matches averaging 7 to 11 bytes here.
The lower half never needs the second source register: its mask indices are i % off for i < 16, hence always below 16. Only the upper half can reach past 15, and only when off > 16.
Overshoots to 16 or 32 bytes, so the caller owes ZXC_PAD_SIZE of headroom. Reading 32 source bytes is safe because no mask index reaches dst (all are < off).
| [out] | dst | Output cursor; the run source is dst - off. |
| [in] | off | Back-reference distance, in [2, 31]. |
| [in] | ml | Match length, <= 32. |
Definition at line 243 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE.
Referenced by zxc_decode_copy_match_short().
|
inlinestatic |
Fills an ml-byte single-byte run (LZ offset == 1) with wild stores.
Splats byte into a vector register and emits 32-byte chunks, avoiding a libc memset call on the typically short runs of the hot path. Like the other run copiers it may overshoot up to 31 bytes past ml; the caller must guarantee ZXC_PAD_SIZE bytes of headroom. Falls back to ZXC_MEMSET on non-SIMD builds.
| [out] | dst | Output cursor. |
| [in] | byte | Byte value to replicate. |
| [in] | ml | Run length in bytes (>= 1). |
Definition at line 314 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE.
Referenced by zxc_decode_copy_match(), and zxc_decode_copy_match_short().
|
static |
Definition at line 717 of file zxc_decompress.c.
|
static |
Definition at line 738 of file zxc_decompress.c.
|
static |
Definition at line 753 of file zxc_decompress.c.
| int zxc_decompress_chunk_wrapper | ( | const zxc_cctx_t * | ctx, |
| const uint8_t * | src, | ||
| const size_t | src_sz, | ||
| uint8_t * | dst, | ||
| const size_t | dst_cap, | ||
| const uint64_t | block_index ) |
Public no-dict chunk decoder (decompression hot path).
Decompresses one chunk through the runtime ISA dispatch.
Inlines the plain SPL/PAK decoders via zxc_decompress_chunk_wrapper_body with has_dict=0, so it carries no dict code and matches the dict-free build.
Definition at line 1673 of file zxc_decompress.c.
References zxc_decompress_chunk_wrapper_body().
Referenced by zxc_dstream_decompress(), zxc_seek_mt_job(), zxc_seekable_decompress_range(), and zxc_stream_process().
|
inlinestatic |
Shared chunk-decode body: validates the header, decodes, then verifies the optional checksum.
has_dict and safe are compile-time constants: the no-dict instantiation folds the SPL/PAK selection to the plain (inlinable) decoders, so zxc_decompress_chunk_wrapper carries no dict code and matches the dict-free build; the dict and safe instantiations call the NOINLINE _dict / _safe decoders (the strict-tail safe path never carries a dict).
| [in,out] | ctx | Decompression context. |
| [in] | src | Compressed block (header + payload + optional checksum). |
| [in] | src_sz | Size of src in bytes. |
| [out] | dst | Destination buffer for the decoded block. |
| [in] | dst_cap | Capacity of dst in bytes. |
| [in] | block_index | Frame position of the block: the checksum seed. |
| [in] | has_dict | Compile-time flag: 1 = dictionary-aware decoders. |
| [in] | safe | Compile-time flag: 1 = strict-tail safe decoders. |
Definition at line 1605 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, ZXC_BLOCK_CHECKSUM_SIZE, zxc_block_header_ok(), ZXC_BLOCK_HEADER_SIZE, zxc_checksum(), ZXC_CHECKSUM_RAPIDHASH, zxc_decode_block_pak(), zxc_decode_block_pak_dict(), zxc_decode_block_pak_safe(), zxc_decode_block_spl(), zxc_decode_block_spl_dict(), zxc_decode_block_spl_safe(), ZXC_ERROR_BAD_BLOCK_SIZE, ZXC_ERROR_BAD_BLOCK_TYPE, ZXC_ERROR_BAD_CHECKSUM, ZXC_ERROR_BAD_HEADER, ZXC_ERROR_CORRUPT_DATA, ZXC_ERROR_DST_TOO_SMALL, ZXC_ERROR_SRC_TOO_SMALL, and zxc_le32().
Referenced by zxc_decompress_chunk_wrapper(), zxc_decompress_chunk_wrapper_dict(), and zxc_decompress_chunk_wrapper_safe().
| int zxc_decompress_chunk_wrapper_dict | ( | const zxc_cctx_t * | ctx, |
| const uint8_t * | src, | ||
| const size_t | src_sz, | ||
| uint8_t * | dst, | ||
| const size_t | dst_cap, | ||
| const uint64_t | block_index ) |
Public dictionary chunk decoder.
Routes through zxc_decompress_chunk_wrapper_body with has_dict=1, which calls the NOINLINE _dict decoders (slower: dict back-refs read the prepended dictionary). Used only when ctx->dict_size != 0.
| [in,out] | ctx | Decompression context (dict prefix in its buffer). |
| [in] | src | Compressed block bytes. |
| [in] | src_sz | Size of src in bytes. |
| [out] | dst | Destination buffer for the decoded block. |
| [in] | dst_cap | Capacity of dst in bytes. |
| [in] | block_index | Frame position of the block: the checksum seed. |
Definition at line 1696 of file zxc_decompress.c.
References zxc_decompress_chunk_wrapper_body().
| int zxc_decompress_chunk_wrapper_safe | ( | const zxc_cctx_t * | ctx, |
| const uint8_t * | src, | ||
| const size_t | src_sz, | ||
| uint8_t * | dst, | ||
| const size_t | dst_cap, | ||
| const uint64_t | block_index ) |
Public strict-tail safe chunk decoder (dst_cap == exact decoded size).
Exact-capacity variant for the safe block API; dispatch table only.
Routes through zxc_decompress_chunk_wrapper_body with safe=1, which calls the NOINLINE _safe decoders (no bounce buffer, no tail padding); RAW blocks are copied directly. Dict inputs are not handled here (the caller routes them to the bounce-capable path).
| [in,out] | ctx | Decompression context. |
| [in] | src | Compressed block bytes. |
| [in] | src_sz | Size of src in bytes. |
| [out] | dst | Destination buffer (capacity == exact decoded size). |
| [in] | dst_cap | Capacity of dst in bytes. |
| [in] | block_index | Frame position of the block: the checksum seed. |
Definition at line 1720 of file zxc_decompress.c.
References zxc_decompress_chunk_wrapper_body().
|
static |
Ensures the entropy decode scratch (tok_buffer + pivco_scratch) is available before decoding an entropy section.
Heap contexts defer this scratch to the first entropy section (zxc_cctx_alloc_entropy_scratch allocates it once); static workspaces pre-carve it, making this a no-op. The const cast is sound: every context lives in writable memory (heap allocation or caller workspace) - the decode chain is const only because steady-state decoding never mutates the context.
| [in] | ctx | Decompression context (mutated on the first entropy block). |
Definition at line 712 of file zxc_decompress.c.
References zxc_cctx_alloc_entropy_scratch(), ZXC_NOINLINE, and ZXC_OK.
|
inlinestatic |
Copies len bytes in 32-byte wild chunks (the zxc_copy32 width).
Writes at least one chunk and may overshoot len by up to 31 bytes, into the caller's ZXC_PAD_SIZE headroom. The tail loop is counted on purpose: a pointer bound costs one more register in the inlined SPL 4x loop, which clang pays by reloading d_floor from the stack on every sequence.
| [out] | dst | Output cursor. |
| [in] | src | Source, disjoint from dst or at least 32 bytes behind it. |
| [in] | len | Bytes to copy, >= 1. |
Definition at line 377 of file zxc_decompress.c.
References ZXC_ALWAYS_INLINE, and zxc_copy32().
Referenced by zxc_decode_copy_literals(), and zxc_decode_copy_match().
|
static |
Store stride for the 32-byte pattern: (32 / off) * off.
Past 16 no second period fits, so the stride is the offset itself and each store's tail gets rewritten by the next one.
Definition at line 122 of file zxc_decompress.c.
Referenced by zxc_decode_copy_overlap_run32().