ZXC 1.0.3
High-performance asymmetric lossless compression library
Loading...
Searching...
No Matches
Internal Helpers

Platform abstractions, constants, and utility functions (private). More...

Macros

#define ZXC_SPL_MAX_INLINE_OUT_PER_SEQ   ((ZXC_TOKEN_LL_MASK - 1U) + ZXC_SPL_MAX_INLINE_ML) /* 33 */
 Maximum decoded output of one sequence with inline ll/ml, used by the 4x bounds checks to reserve the rest of a batch.
#define ZXC_SPL_INLINE_ML_CODE   (ZXC_TOKEN_ML_MASK - 1U) /* 14 */
 Longest match length code (length minus ZXC_LZ_MIN_MATCH_LEN) a SPL token carries inline; the code above it escapes to a varint.
#define ZXC_SPL_MAX_INLINE_ML   (ZXC_SPL_INLINE_ML_CODE + ZXC_LZ_MIN_MATCH_LEN) /* 19 */
 Longest match a SPL sequence carries without a varint extension.
#define ZXC_PAK_MAX_INLINE_OUT_PER_SEQ    ((ZXC_SEQ_LL_MASK - 1U) + (ZXC_SEQ_ML_MASK - 1U) + ZXC_LZ_MIN_MATCH_LEN) /* 513 */
#define ZXC_LZ_OFFSET_BIAS   1
 Base bias added to encoded offsets (stored = actual - bias).
#define ZXC_LZ_MAX_DIST   (ZXC_LZ_WINDOW_SIZE - 1)
 Maximum allowed offset distance.
#define ZXC_LZ_MINDIST   32
 Match distance floor the encoder holds to at levels 1 to 5, sized to the decoder's widest match-copy arm so the overlap kernel stays off the decode path.
#define ZXC_LZ_MINDIST_PROBE_PER_KB   1024
 Probe sampling: one position per KB, clamped.
#define ZXC_LZ_MINDIST_PROBE_MIN   16
#define ZXC_LZ_MINDIST_PROBE_MAX   64
#define ZXC_LZ_MINDIST_MAX_SHORT_PCT   20
 Short-distance hit rate, in percent, above which a block keeps its short match distances.
#define ZXC_LZ_SEARCH_MARGIN   (sizeof(uint64_t))
 Bytes at the block end where match search stops (left as literals).

Functions

static uint32_t zxc_read_varint (const uint8_t **ptr, const uint8_t *end)
 Reads a Prefix Varint encoded integer.

Aligned Allocator Abstraction

Macros around the cache-line-aligned allocator used for compression workspace and per-context scratch buffers.

The default is the pair defined below, wrapping _aligned_malloc on Windows and posix_memalign elsewhere - the core's only use of either. A host overrides both macros or neither; a vendored copy of this file defines both.

Kernel builds align by hand over the slab allocator (see contrib/linux-kernel): kmalloc guarantees only ARCH_KMALLOC_MINALIGN, 8 bytes on x86 and on arm64 since 6.5, short of the cache line the workspace layout assumes.

static void * zxc_aligned_malloc (const size_t size, const size_t alignment)
 Default cache-line-aligned allocator; release with zxc_aligned_free.
static void zxc_aligned_free (void *ptr)
 Counterpart of zxc_aligned_malloc; NULL is a no-op.
#define ZXC_ALIGNED_MALLOC(size, alignment)
 Cache-line-aligned allocator.
#define ZXC_ALIGNED_FREE(ptr)
 Counterpart deallocator for ZXC_ALIGNED_MALLOC.

Population Count

ZXC_POPCOUNT32 / ZXC_POPCOUNT64.

Default: the builtins, libgcc calls without a hardware count; a kernel maps them onto hweight32/64.

static int zxc_popcount32 (const uint32_t v)
 Portable SWAR popcount (MSVC).
static int zxc_popcount64 (const uint64_t v)
#define ZXC_POPCOUNT32(v)
#define ZXC_POPCOUNT64(v)

File Format Constants

Header fields, block sizes, and related constants.

The magic words are public, in zxc_constants.h.

static int zxc_magic_prefix_ok (const uint8_t *p, const size_t n)
 Whether the first n bytes (up to 4) at p agree with the magic word, so a frame may start there: the check a reader makes as bytes arrive.
#define ZXC_FILE_FORMAT_VERSION   9
 Current on-disk file format version.
#define ZXC_PAD_SIZE   32
 Safety padding appended to buffers to tolerate overruns.
#define ZXC_BLOCK_LIT_SLACK   32
 Readable bytes a SPL/PAK payload guarantees after its literal section.
#define ZXC_DECOMPRESS_TAIL_PAD   (4 * ZXC_PAK_MAX_INLINE_OUT_PER_SEQ + ZXC_PAD_SIZE) /* 2084 */
 Tail padding required on the decompression destination buffer.
#define ZXC_MT_BATCH_BYTES   ((size_t)256 * 1024)
 Output per multi-threaded decode job: smaller blocks travel several to a job, paying the thread handoff once.
#define ZXC_CACHE_LINE_SIZE   64
 Assumed CPU cache line size for alignment.
#define ZXC_ALIGNMENT_MASK   ((size_t)ZXC_CACHE_LINE_SIZE - 1)
 Bitmask for cache-line alignment checks.
#define ZXC_ALIGN_CL(x)
 Round x up to the next cache-line boundary.
#define ZXC_BITMAP_WORDS(n_bits)
 Number of uint64_t words needed to hold a bitmap of n_bits.
#define ZXC_FILE_FLAG_HAS_CHECKSUM   0x80U
 Bit flag in the Flags byte indicating checksum presence (bit 7).
#define ZXC_FILE_FLAG_HAS_DICTIONARY   0x40U
 Bit flag in the Flags byte indicating a dictionary is required (bit 6).
#define ZXC_FILE_FLAG_HAS_SEEK_TABLE   0x20U
 Bit flag in the Flags byte: a SEK block sits between the EOF block and the footer (bit 5).
#define ZXC_FILE_FLAG_RESERVED   0x10U
 Reserved bit in the Flags byte (bit 4), must be 0.
#define ZXC_FILE_CHECKSUM_ALGO_MASK   0x0FU
 Mask for the checksum algorithm id (bits 0-3).
#define ZXC_DICT_VERSION   2
 Current dictionary file format version.
#define ZXC_DICT_KGRAM_LEN   ZXC_LZ_MIN_MATCH_LEN
 K-gram length scanned by the dictionary trainer.
#define ZXC_DICT_SEGMENT_MAX   4096
 Longest trainer segment: one repetitive region cannot take the whole budget.
#define ZXC_DICT_HASH_BITS   16
 Address bits for the dictionary trainer's k-gram frequency table.
#define ZXC_DICT_MAX_SEGMENTS   (1U << 16)
 Maximum number of candidate segments the dictionary trainer keeps.
#define ZXC_DICT_SAMPLE_TARGET   (1U << 19)
 Target number of sampled k-gram positions for the trainer's frequency estimate.
#define ZXC_DICT_HASH_SIZE   (1U << ZXC_DICT_HASH_BITS)
 Number of buckets in the dictionary trainer's frequency table.
#define ZXC_DICT_HUF_TRAIN_BLOCK   4096U
 Training block size for the shared-table literal statistics.
#define ZXC_DICT_HUF_SAMPLE_BUDGET   (8U << 20)
 Cap on the corpus bytes compressed by the literal-table trainer: the histogram converges early, so past it slices are strided evenly instead.
#define ZXC_BLOCK_HEADER_SIZE   8
 Block header size: Type(1)+Flags(1)+Reserved(1)+Checksum(1)+CompSize(4).
#define ZXC_BLOCK_CHECKSUM_SIZE   4
 Size of the per-block checksum field in bytes.
#define ZXC_SPL_HEADER_BINARY_SIZE   12
 Binary size of a SPL block sub-header.
#define ZXC_PAK_HEADER_BINARY_SIZE   12
 Binary size of a PAK block sub-header.
#define ZXC_SPL_DESC_MAX_SIZE   (2 * sizeof(uint32_t))
 Widest SPL section descriptors: the literal and token section sizes.
#define ZXC_BLOCK_FORMAT_OVERHEAD   68
 Worst-case format overhead inside a single block beyond the outer 8-byte block header and the optional 4-byte checksum.
#define ZXC_CHECKSUM_RAPIDHASH   0
 Checksum algorithm id for RapidHash (default, sole implementation).

Seekable Format Constants

Seek table block appended between EOF block and footer.

Optional: a ZXC_BLOCK_SEK block of groups, each a u64 anchor (its first block's offset) then one u32 on-disk size per block. Readers derive the block count from the footer and read groups on access; the header's size field holds the table size modulo 2^32.

static uint64_t zxc_seek_group_count (const uint64_t nblocks)
 Groups holding nblocks blocks; the last one may be partial.
static uint32_t zxc_seek_group_len (const uint64_t nblocks, const uint64_t g)
 Blocks in group g of nblocks: ZXC_SEEK_GROUP, fewer for the last.
static uint64_t zxc_seek_table_bytes (const uint64_t nblocks)
 Byte size of the groups for nblocks blocks, in 64 bits.
static uint32_t zxc_seek_size_field (const uint64_t table_bytes)
 SEK header size field: table_bytes with its high half folded onto the low one.
#define ZXC_SEEK_GROUP   64U
 Blocks per group.
#define ZXC_SEEK_ANCHOR_SIZE   8U
 Group anchor: offset of its first block, u64.
#define ZXC_SEEK_SIZE_ENTRY   4U
 One block's on-disk size, u32.
#define ZXC_SEEK_GROUP_BYTES   (ZXC_SEEK_ANCHOR_SIZE + ZXC_SEEK_GROUP * ZXC_SEEK_SIZE_ENTRY)
 Full group: anchor + ZXC_SEEK_GROUP sizes.

Heap Allocator Abstraction

Macros around the libc allocators so non-libc targets (Linux kernel, embedded freestanding builds, custom arenas) can override them via -D flags before including any zxc header, or by vendoring this file.

Note
Aligned allocations go through ZXC_ALIGNED_MALLOC / ZXC_ALIGNED_FREE (see below), not these.
#define ZXC_MALLOC(size)
 Heap allocator.
#define ZXC_CALLOC(nmemb, size)
 Zero-initialised heap allocator.
#define ZXC_REALLOC(ptr, size)
 In-place / move heap reallocator.
#define ZXC_FREE(ptr)
 Heap deallocator.

Atomic Qualifier

Provides a portable atomic / volatile qualifier.

ZXC_ATOMIC expands to _Atomic, or to volatile where the compiler leaves out the optional C11 atomics (__STDC_NO_ATOMICS__, as MSVC does).

#define ZXC_ATOMIC   _Atomic
#define ZXC_USE_C11_ATOMICS   1

Compiler Abstractions

Portable wrappers for branch hints, prefetch, memory ops, alignment, and forced inlining.

#define LIKELY(x)
#define UNLIKELY(x)
#define RESTRICT
#define ZXC_PREFETCH_READ(ptr)
#define ZXC_MEMCPY(dst, src, n)
#define ZXC_MEMSET(dst, val, n)
#define ZXC_ALWAYS_INLINE   inline
 Forces a function to be inlined (fallback for non-GCC/Clang/MSVC compilers).
#define ZXC_NOINLINE
 Prevents inlining (best-effort no-op fallback for unknown compilers).
#define ZXC_COLD
#define ZXC_ALIGN(x)
 Specifies memory alignment using C11 _Alignas.

SPL Token Constants

4-bit literal length / 4-bit match length / 16-bit offset.

#define ZXC_TOKEN_LIT_BITS   4
 Bits for Literal Length in a SPL token.
#define ZXC_TOKEN_ML_BITS   4
 Bits for Match Length in a SPL token.
#define ZXC_TOKEN_LL_MASK   ((1U << ZXC_TOKEN_LIT_BITS) - 1)
 Mask to extract Literal Length from a SPL token.
#define ZXC_TOKEN_ML_MASK   ((1U << ZXC_TOKEN_ML_BITS) - 1)
 Mask to extract Match Length from a SPL token.

PAK Sequence Constants

8-bit literal length / 8-bit match length / 16-bit offset.

#define ZXC_SEQ_LL_BITS   8
 Bits for Literal Length in a PAK sequence.
#define ZXC_SEQ_ML_BITS   8
 Bits for Match Length in a PAK sequence.
#define ZXC_SEQ_OFF_BITS   16
 Bits for Offset in a PAK sequence.
#define ZXC_SEQ_LL_MASK   ((1U << ZXC_SEQ_LL_BITS) - 1)
 Mask to extract Literal Length from a PAK sequence.
#define ZXC_SEQ_ML_MASK   ((1U << ZXC_SEQ_ML_BITS) - 1)
 Mask to extract Match Length from a PAK sequence.
#define ZXC_SEQ_OFF_MASK   ((1U << ZXC_SEQ_OFF_BITS) - 1)
 Mask to extract Offset from a PAK sequence.
#define ZXC_SEQ_LL_SHIFT   (ZXC_SEQ_ML_BITS + ZXC_SEQ_OFF_BITS)
 Shift of the Literal Length field: the top byte of the word.
#define ZXC_SEQ_ML_SHIFT   ZXC_SEQ_OFF_BITS
 Shift of the Match Length field: just above the offset.

Literal Stream Encoding

#define ZXC_LIT_RLE_FLAG   0x80U
 Flag bit indicating an RLE run in the literal stream (0x80).
#define ZXC_LIT_LEN_MASK   (ZXC_LIT_RLE_FLAG - 1)
 Mask to extract the run/literal length (lower 7 bits).
#define ZXC_LIT_RUN_MAX   (ZXC_LIT_LEN_MASK + 1U) /* 128 */
 Longest literal run one token carries: a length field of 0 means 1 byte.
#define ZXC_LIT_RLE_RUN_MIN   4U
 Shortest run worth an RLE token: a length field of 0 means this many bytes.
#define ZXC_LIT_RLE_RUN_MAX   (ZXC_LIT_LEN_MASK + ZXC_LIT_RLE_RUN_MIN) /* 131 */
 Longest run one RLE token carries.

LZ77 Constants

Hash table geometry, sliding window, and match parameters.

The hash table uses a split layout with 15-bit addressing (32 768 buckets):

  • hash_table[]: uint32_t, stores (epoch << offset_bits) | position (128 KB).
  • hash_tags[]: uint8_t, stores an 8-bit tag for fast rejection (32 KB). Total: 160 KB. The tag table fits in L1 cache, enabling a "filter-first" access pattern that avoids cold loads into hash_table on the ~60-75% of lookups where the tag mismatches. The 64 KB sliding window allows chain_table to use uint16_t.
#define ZXC_LZ_HASH_BITS   15
 Address bits for the LZ77 hash table (2^15 = 32 768 buckets).
#define ZXC_LZ_HASH_SIZE   (1U << ZXC_LZ_HASH_BITS)
 Maximum number of entries in the hash table.
#define ZXC_LZ_WINDOW_SIZE   (1U << 16)
 Sliding window size (64 KB).
#define ZXC_LZ_WINDOW_MASK   (ZXC_LZ_WINDOW_SIZE - 1U)
 Mask for ring-buffer indexing into chain_table (power-of-two window).
#define ZXC_LZ_MIN_MATCH_LEN   5
 Minimum match length for an LZ77 match.
#define ZXC_MAX_VARINT_VALUE   ((uint32_t)(ZXC_BLOCK_SIZE_MAX - 1U))
 Maximum legitimate value a varint can decode to.
#define ZXC_VARINT_INVALID   (2U * ZXC_BLOCK_SIZE_MAX)
 A truncated or out-of-spec varint: a length no output holds.

Varint reach: the first value each encoded length cannot hold (7, 14, 21 bits).

#define ZXC_VARINT_1B_LIMIT   (1U << 7)
#define ZXC_VARINT_2B_LIMIT   (1U << 14)
#define ZXC_VARINT_3B_LIMIT   (1U << 21)

Detailed Description

Platform abstractions, constants, and utility functions (private).

Macro Definition Documentation

◆ LIKELY

#define LIKELY ( x)
Value:
(x)

Definition at line 236 of file zxc_internal.h.

◆ RESTRICT

#define RESTRICT

Definition at line 238 of file zxc_internal.h.

◆ UNLIKELY

#define UNLIKELY ( x)
Value:
(x)

Definition at line 237 of file zxc_internal.h.

◆ ZXC_ALIGN

#define ZXC_ALIGN ( x)
Value:
_Alignas(x)

Specifies memory alignment using C11 _Alignas.

Parameters
xAlignment boundary in bytes (must be a power of 2).

Definition at line 258 of file zxc_internal.h.

◆ ZXC_ALIGN_CL

#define ZXC_ALIGN_CL ( x)
Value:
#define ZXC_ALIGNMENT_MASK
Bitmask for cache-line alignment checks.

Round x up to the next cache-line boundary.

Definition at line 374 of file zxc_internal.h.

Referenced by compute_cctx_layout(), zxc_cctx_alloc_entropy_scratch(), and zxc_opt_dp_sizes().

◆ ZXC_ALIGNED_FREE

#define ZXC_ALIGNED_FREE ( ptr)
Value:
static void zxc_aligned_free(void *ptr)
Counterpart of zxc_aligned_malloc; NULL is a no-op.
Definition zxc_deps.h:124

Counterpart deallocator for ZXC_ALIGNED_MALLOC.

Definition at line 137 of file zxc_deps.h.

Referenced by zxc_cctx_free(), zxc_cctx_init(), and zxc_stream_engine_stop().

◆ ZXC_ALIGNED_MALLOC

#define ZXC_ALIGNED_MALLOC ( size,
alignment )
Value:
zxc_aligned_malloc(size, alignment)
static void * zxc_aligned_malloc(const size_t size, const size_t alignment)
Default cache-line-aligned allocator; release with zxc_aligned_free.
Definition zxc_deps.h:113

Cache-line-aligned allocator.

Definition at line 134 of file zxc_deps.h.

Referenced by zxc_cctx_alloc_entropy_scratch(), zxc_cctx_init(), and zxc_stream_engine_start().

◆ ZXC_ALIGNMENT_MASK

#define ZXC_ALIGNMENT_MASK   ((size_t)ZXC_CACHE_LINE_SIZE - 1)

Bitmask for cache-line alignment checks.

Definition at line 372 of file zxc_internal.h.

Referenced by zxc_stream_engine_start().

◆ ZXC_ALWAYS_INLINE

#define ZXC_ALWAYS_INLINE   inline

Forces a function to be inlined (fallback for non-GCC/Clang/MSVC compilers).

Definition at line 246 of file zxc_internal.h.

Referenced by zxc_block_header_ok(), zxc_block_is_short_dist_bound(), zxc_block_size_ceil(), zxc_cctx_max_seq(), zxc_chain_delta(), zxc_checksum(), zxc_copy16(), zxc_copy32(), zxc_ctz32(), zxc_ctz64(), zxc_decode_block_pak_impl(), zxc_decode_block_spl_impl(), zxc_decode_copy_literals(), zxc_decode_copy_match(), zxc_decode_copy_match_short(), zxc_decode_copy_match_spl(), zxc_decode_copy_overlap_run32(), zxc_decode_copy_overlap_short(), zxc_decode_fill_run(), zxc_decompress_chunk_wrapper_body(), zxc_decompress_safe_variant(), zxc_digest_combine(), zxc_emit_extra(), zxc_epoch_pos(), zxc_extras_move(), zxc_file_header_sign(), zxc_flush_literals(), zxc_footer_dsize_plausible(), zxc_footer_layout(), zxc_frame_info_copy(), zxc_get_lz77_params(), zxc_hash16(), zxc_hash8(), zxc_hash_func(), zxc_hash_tag(), zxc_huf_nudge_j(), zxc_lazy_probe(), zxc_le16(), zxc_le32(), zxc_le64(), zxc_log2_u32(), zxc_lz77_find_best_match(), zxc_match_reaches(), zxc_num_procs(), zxc_opt_dp_sizes(), zxc_opt_dp_update_const_cost(), zxc_opt_relax(), zxc_pivco_emit_leaf_pair(), zxc_pivco_flat_leaves(), zxc_pivco_leaves(), zxc_pivco_merge(), zxc_pivco_run_bytes(), zxc_read_gnr_header(), zxc_read_varint(), zxc_ring_next(), zxc_scan_src_mem(), zxc_seek_block_count(), zxc_seek_group_count(), zxc_seek_group_len(), zxc_seek_size_field(), zxc_seek_table_bytes(), zxc_spl_desc_size(), zxc_spl_match_split_piece(), zxc_spl_match_split_pieces(), zxc_spl_put_seq(), zxc_store_le16(), zxc_store_le32(), zxc_store_le64(), zxc_stream_process(), zxc_uint_bytes(), zxc_validate_block_size(), zxc_variants(), zxc_varint_keep(), zxc_wild_copy32(), zxc_write_gnr_header(), and zxc_write_varint().

◆ ZXC_ATOMIC

#define ZXC_ATOMIC   _Atomic

Definition at line 64 of file zxc_internal.h.

◆ ZXC_BITMAP_WORDS

#define ZXC_BITMAP_WORDS ( n_bits)
Value:
(((n_bits) + 63) / 64)

Number of uint64_t words needed to hold a bitmap of n_bits.

Equivalent to ceil(n_bits / 64).

Definition at line 383 of file zxc_internal.h.

Referenced by zxc_lz77_optimal_parse_spl(), and zxc_opt_dp_sizes().

◆ ZXC_BLOCK_CHECKSUM_SIZE

◆ ZXC_BLOCK_FORMAT_OVERHEAD

#define ZXC_BLOCK_FORMAT_OVERHEAD   68

Worst-case format overhead inside a single block beyond the outer 8-byte block header and the optional 4-byte checksum.

Sub-header (12 B) + widest SPL section descriptors (ZXC_SPL_DESC_MAX_SIZE, 8 B) + widest slack padding (ZXC_BLOCK_LIT_SLACK) = 52 B, plus the customary 16 B of margin for future format evolution. Used by zxc_compress_block_bound() and zxc_compress_bound().

Definition at line 447 of file zxc_internal.h.

Referenced by zxc_compress_block_bound(), and zxc_compress_bound().

◆ ZXC_BLOCK_HEADER_SIZE

◆ ZXC_BLOCK_LIT_SLACK

#define ZXC_BLOCK_LIT_SLACK   32

Readable bytes a SPL/PAK payload guarantees after its literal section.

A wire guarantee, not a buffer allowance - hence separate from ZXC_PAD_SIZE even though the values match. RAW literals point into the caller's buffer and zxc_decode_copy_literals overshoots by up to 31 B, so it needs readable bytes behind it.

The following sections usually supply them for free (tokens + offsets clear 32 B from 16 sequences on); the encoder pads only the shortfall, inside the extras section. Extras are read on demand, so an over-long end pointer is harmless - no wire field, nothing to validate about the padding.

Definition at line 346 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), zxc_decode_block_spl_impl(), zxc_encode_block_pak(), and zxc_encode_block_spl().

◆ ZXC_CACHE_LINE_SIZE

#define ZXC_CACHE_LINE_SIZE   64

Assumed CPU cache line size for alignment.

Definition at line 370 of file zxc_internal.h.

Referenced by zxc_cctx_alloc_entropy_scratch(), zxc_cctx_init(), zxc_decode_block_pak_impl(), zxc_encode_block_pak(), and zxc_stream_engine_start().

◆ ZXC_CALLOC

#define ZXC_CALLOC ( nmemb,
size )
Value:
calloc(nmemb, size)

Zero-initialised heap allocator.

Default: libc calloc.

Definition at line 74 of file zxc_deps.h.

Referenced by zxc_create_cctx(), zxc_create_dctx(), zxc_cstream_create(), zxc_dict_train_content(), zxc_dstream_create(), zxc_huf_build_code_lengths(), zxc_seekable_decompress_range_mt(), and zxc_seekable_parse().

◆ ZXC_CHECKSUM_RAPIDHASH

#define ZXC_CHECKSUM_RAPIDHASH   0

Checksum algorithm id for RapidHash (default, sole implementation).

Definition at line 453 of file zxc_internal.h.

Referenced by zxc_compress_chunk_wrapper(), zxc_decompress_chunk_wrapper_body(), zxc_dict_compute_id(), zxc_dict_load(), zxc_read_file_header(), and zxc_write_file_header().

◆ ZXC_COLD

#define ZXC_COLD

Definition at line 252 of file zxc_internal.h.

◆ ZXC_DECOMPRESS_TAIL_PAD

#define ZXC_DECOMPRESS_TAIL_PAD   (4 * ZXC_PAK_MAX_INLINE_OUT_PER_SEQ + ZXC_PAD_SIZE) /* 2084 */

Tail padding required on the decompression destination buffer.

The decoder's fast path uses speculative wild-copy writes and gates fast-loop entry on d_end - ZXC_DECOMPRESS_TAIL_PAD. Sizing dst_capacity to uncompressed_size + ZXC_DECOMPRESS_TAIL_PAD guarantees the fast path is reachable and that tail bounds checks never spuriously reject the last literals of a valid block.

Sized by the PAK 4x loop, whose entry check runs once per batch: four sequences of inline (pre-varint) output, plus the wild-copy overshoot. Memory safety rests on this bound (static_assert below); SPL needs less.

See also
zxc_decompress_block_bound()

Definition at line 362 of file zxc_internal.h.

Referenced by compute_cctx_layout(), ds_handle_need_file_header(), zxc_cctx_alloc_entropy_scratch(), zxc_cctx_init_in_workspace(), zxc_dctx_decode_frame(), zxc_decode_block_pak_impl(), zxc_decompress_block(), zxc_decompress_block_bound(), zxc_inplace_margin(), zxc_inplace_probe(), zxc_seek_mt_job(), zxc_seekable_decompress_range(), zxc_static_decompress_block(), zxc_stream_decode_job(), and zxc_stream_engine_start().

◆ ZXC_DICT_HASH_BITS

#define ZXC_DICT_HASH_BITS   16

Address bits for the dictionary trainer's k-gram frequency table.

Definition at line 413 of file zxc_internal.h.

Referenced by zxc_dict_hash().

◆ ZXC_DICT_HASH_SIZE

#define ZXC_DICT_HASH_SIZE   (1U << ZXC_DICT_HASH_BITS)

Number of buckets in the dictionary trainer's frequency table.

Definition at line 421 of file zxc_internal.h.

Referenced by zxc_dict_train_content().

◆ ZXC_DICT_HUF_SAMPLE_BUDGET

#define ZXC_DICT_HUF_SAMPLE_BUDGET   (8U << 20)

Cap on the corpus bytes compressed by the literal-table trainer: the histogram converges early, so past it slices are strided evenly instead.

Definition at line 426 of file zxc_internal.h.

Referenced by zxc_dict_train_huf().

◆ ZXC_DICT_HUF_TRAIN_BLOCK

#define ZXC_DICT_HUF_TRAIN_BLOCK   4096U

Training block size for the shared-table literal statistics.

Definition at line 423 of file zxc_internal.h.

Referenced by zxc_dict_train_huf().

◆ ZXC_DICT_KGRAM_LEN

#define ZXC_DICT_KGRAM_LEN   ZXC_LZ_MIN_MATCH_LEN

K-gram length scanned by the dictionary trainer.

Aligned on the LZ minimum match length so trained patterns are matchable at encode time.

Definition at line 409 of file zxc_internal.h.

Referenced by zxc_dict_train_content().

◆ ZXC_DICT_MAX_SEGMENTS

#define ZXC_DICT_MAX_SEGMENTS   (1U << 16)

Maximum number of candidate segments the dictionary trainer keeps.

Definition at line 415 of file zxc_internal.h.

Referenced by zxc_dict_train_content().

◆ ZXC_DICT_SAMPLE_TARGET

#define ZXC_DICT_SAMPLE_TARGET   (1U << 19)

Target number of sampled k-gram positions for the trainer's frequency estimate.

Bounds the count so 16-bit counters stay unsaturated on large corpora; the trainer strides the corpus to hit roughly this many positions.

Definition at line 419 of file zxc_internal.h.

Referenced by zxc_dict_train_content().

◆ ZXC_DICT_SEGMENT_MAX

#define ZXC_DICT_SEGMENT_MAX   4096

Longest trainer segment: one repetitive region cannot take the whole budget.

Definition at line 411 of file zxc_internal.h.

Referenced by zxc_dict_train_content().

◆ ZXC_DICT_VERSION

#define ZXC_DICT_VERSION   2

Current dictionary file format version.

A 128-byte packed Huffman code-lengths table (shared literal table) always follows the dictionary content. Version 2 re-signs the header with the multiplicative hash of FORMAT.md section 7.1, so version 1 fails on the version byte instead of on an unmatchable checksum.

Definition at line 406 of file zxc_internal.h.

Referenced by zxc_dict_huf(), zxc_dict_load(), and zxc_dict_save().

◆ ZXC_FILE_CHECKSUM_ALGO_MASK

#define ZXC_FILE_CHECKSUM_ALGO_MASK   0x0FU

Mask for the checksum algorithm id (bits 0-3).

Definition at line 395 of file zxc_internal.h.

Referenced by zxc_read_file_header().

◆ ZXC_FILE_FLAG_HAS_CHECKSUM

#define ZXC_FILE_FLAG_HAS_CHECKSUM   0x80U

Bit flag in the Flags byte indicating checksum presence (bit 7).

Definition at line 386 of file zxc_internal.h.

Referenced by zxc_read_file_header(), and zxc_write_file_header().

◆ ZXC_FILE_FLAG_HAS_DICTIONARY

#define ZXC_FILE_FLAG_HAS_DICTIONARY   0x40U

Bit flag in the Flags byte indicating a dictionary is required (bit 6).

Definition at line 388 of file zxc_internal.h.

Referenced by zxc_get_dict_id(), zxc_read_file_header(), and zxc_write_file_header().

◆ ZXC_FILE_FLAG_HAS_SEEK_TABLE

#define ZXC_FILE_FLAG_HAS_SEEK_TABLE   0x20U

Bit flag in the Flags byte: a SEK block sits between the EOF block and the footer (bit 5).

Definition at line 391 of file zxc_internal.h.

Referenced by zxc_read_file_header(), and zxc_write_file_header().

◆ ZXC_FILE_FLAG_RESERVED

#define ZXC_FILE_FLAG_RESERVED   0x10U

Reserved bit in the Flags byte (bit 4), must be 0.

Definition at line 393 of file zxc_internal.h.

Referenced by zxc_read_file_header().

◆ ZXC_FILE_FORMAT_VERSION

#define ZXC_FILE_FORMAT_VERSION   9

Current on-disk file format version.

A decoder for version N reads 9 to N (FORMAT.md Sec 10.3); others get ZXC_ERROR_BAD_VERSION.

Definition at line 329 of file zxc_internal.h.

Referenced by zxc_read_file_header(), and zxc_write_file_header().

◆ ZXC_FREE

◆ ZXC_LIT_LEN_MASK

#define ZXC_LIT_LEN_MASK   (ZXC_LIT_RLE_FLAG - 1)

Mask to extract the run/literal length (lower 7 bits).

Definition at line 547 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl(), and zxc_encode_block_spl().

◆ ZXC_LIT_RLE_FLAG

#define ZXC_LIT_RLE_FLAG   0x80U

Flag bit indicating an RLE run in the literal stream (0x80).

Definition at line 545 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl(), and zxc_encode_block_spl().

◆ ZXC_LIT_RLE_RUN_MAX

#define ZXC_LIT_RLE_RUN_MAX   (ZXC_LIT_LEN_MASK + ZXC_LIT_RLE_RUN_MIN) /* 131 */

Longest run one RLE token carries.

Definition at line 553 of file zxc_internal.h.

Referenced by zxc_encode_block_spl().

◆ ZXC_LIT_RLE_RUN_MIN

#define ZXC_LIT_RLE_RUN_MIN   4U

Shortest run worth an RLE token: a length field of 0 means this many bytes.

Definition at line 551 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl(), and zxc_encode_block_spl().

◆ ZXC_LIT_RUN_MAX

#define ZXC_LIT_RUN_MAX   (ZXC_LIT_LEN_MASK + 1U) /* 128 */

Longest literal run one token carries: a length field of 0 means 1 byte.

Definition at line 549 of file zxc_internal.h.

Referenced by zxc_encode_block_spl().

◆ ZXC_LITTLE_ENDIAN

#define ZXC_LITTLE_ENDIAN

Definition at line 281 of file zxc_internal.h.

◆ ZXC_LZ_HASH_BITS

#define ZXC_LZ_HASH_BITS   15

Address bits for the LZ77 hash table (2^15 = 32 768 buckets).

Definition at line 568 of file zxc_internal.h.

Referenced by zxc_hash_func().

◆ ZXC_LZ_HASH_SIZE

#define ZXC_LZ_HASH_SIZE   (1U << ZXC_LZ_HASH_BITS)

Maximum number of entries in the hash table.

Definition at line 570 of file zxc_internal.h.

Referenced by compute_cctx_layout(), zxc_encode_block_pak(), and zxc_encode_block_spl().

◆ ZXC_LZ_MAX_DIST

#define ZXC_LZ_MAX_DIST   (ZXC_LZ_WINDOW_SIZE - 1)

Maximum allowed offset distance.

Definition at line 679 of file zxc_internal.h.

Referenced by zxc_lazy_probe(), and zxc_lz77_find_best_match().

◆ ZXC_LZ_MIN_MATCH_LEN

◆ ZXC_LZ_MINDIST

#define ZXC_LZ_MINDIST   32

Match distance floor the encoder holds to at levels 1 to 5, sized to the decoder's widest match-copy arm so the overlap kernel stays off the decode path.

Applied per block, and only where ZXC_LZ_MINDIST_MAX_SHORT_PCT clears it; levels 6 and 7 keep every distance. Encoder policy: no format bit moves, so any decoder of the same format version reads the result. 1 disables.

Definition at line 698 of file zxc_internal.h.

Referenced by zxc_block_is_short_dist_bound(), and zxc_get_lz77_params().

◆ ZXC_LZ_MINDIST_MAX_SHORT_PCT

#define ZXC_LZ_MINDIST_MAX_SHORT_PCT   20

Short-distance hit rate, in percent, above which a block keeps its short match distances.

Measured: natural text 2-5 %, XML around 25 %, JSON 50-60 %, periodic data 100 %. Decode gains follow the same order, so the cut sits just above text and below everything that measured neutral or worse.

Definition at line 715 of file zxc_internal.h.

Referenced by zxc_block_is_short_dist_bound().

◆ ZXC_LZ_MINDIST_PROBE_MAX

#define ZXC_LZ_MINDIST_PROBE_MAX   64

Definition at line 707 of file zxc_internal.h.

◆ ZXC_LZ_MINDIST_PROBE_MIN

#define ZXC_LZ_MINDIST_PROBE_MIN   16

Definition at line 706 of file zxc_internal.h.

◆ ZXC_LZ_MINDIST_PROBE_PER_KB

#define ZXC_LZ_MINDIST_PROBE_PER_KB   1024

Probe sampling: one position per KB, clamped.

Proportional on purpose: a fixed count costs the same on a 4 KB block as on a 512 KB one, which measured as a third of the compression time on small, highly compressible inputs.

Definition at line 705 of file zxc_internal.h.

Referenced by zxc_block_is_short_dist_bound().

◆ ZXC_LZ_OFFSET_BIAS

#define ZXC_LZ_OFFSET_BIAS   1

Base bias added to encoded offsets (stored = actual - bias).

Definition at line 677 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), zxc_decode_block_spl_impl(), zxc_encode_block_pak(), zxc_encode_block_spl(), and zxc_lz77_optimal_parse_spl().

◆ ZXC_LZ_SEARCH_MARGIN

#define ZXC_LZ_SEARCH_MARGIN   (sizeof(uint64_t))

Bytes at the block end where match search stops (left as literals).

Equals the 8-byte word the finder reads at each probe, so ip+8<=iend.

Definition at line 718 of file zxc_internal.h.

Referenced by zxc_encode_block_pak(), zxc_encode_block_spl(), and zxc_lz77_optimal_parse_spl().

◆ ZXC_LZ_WINDOW_MASK

#define ZXC_LZ_WINDOW_MASK   (ZXC_LZ_WINDOW_SIZE - 1U)

Mask for ring-buffer indexing into chain_table (power-of-two window).

Definition at line 574 of file zxc_internal.h.

Referenced by zxc_encode_block_spl(), zxc_lazy_probe(), zxc_lz77_find_best_match(), and zxc_lz_seed_dict().

◆ ZXC_LZ_WINDOW_SIZE

#define ZXC_LZ_WINDOW_SIZE   (1U << 16)

Sliding window size (64 KB).

Definition at line 572 of file zxc_internal.h.

Referenced by compute_cctx_layout(), zxc_chain_delta(), and zxc_lz77_optimal_parse_spl().

◆ ZXC_MALLOC

◆ ZXC_MAX_VARINT_VALUE

#define ZXC_MAX_VARINT_VALUE   ((uint32_t)(ZXC_BLOCK_SIZE_MAX - 1U))

Maximum legitimate value a varint can decode to.

A varint value represents (ll - MASK) or (ml - MASK) and is therefore always strictly less than ZXC_BLOCK_SIZE_MAX (enforced by the Block API entry points). The cap is set to (ZXC_BLOCK_SIZE_MAX - 1), which fits cleanly in a 3-byte varint (21 bits): the decoder rejects any 4- or 5-byte encoding, and the encoder refuses to emit values above this bound. Together they bound the varint surface to exactly the format-defined block size limit.

Definition at line 585 of file zxc_internal.h.

Referenced by zxc_write_varint().

◆ ZXC_MEMCPY

#define ZXC_MEMCPY ( dst,
src,
n )
Value:
memcpy(dst, src, n)

Definition at line 240 of file zxc_internal.h.

◆ ZXC_MEMSET

#define ZXC_MEMSET ( dst,
val,
n )
Value:
memset(dst, val, n)

Definition at line 241 of file zxc_internal.h.

◆ ZXC_MT_BATCH_BYTES

#define ZXC_MT_BATCH_BYTES   ((size_t)256 * 1024)

Output per multi-threaded decode job: smaller blocks travel several to a job, paying the thread handoff once.

Used by the FILE* engine (regular files only) and the seekable range reader.

Definition at line 368 of file zxc_internal.h.

Referenced by zxc_seekable_decompress_range_mt(), and zxc_stream_engine_start().

◆ ZXC_NOINLINE

◆ ZXC_PAD_SIZE

◆ ZXC_PAK_HEADER_BINARY_SIZE

#define ZXC_PAK_HEADER_BINARY_SIZE   12

Binary size of a PAK block sub-header.

Definition at line 435 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), zxc_read_pak_header(), and zxc_write_pak_header().

◆ ZXC_PAK_MAX_INLINE_OUT_PER_SEQ

#define ZXC_PAK_MAX_INLINE_OUT_PER_SEQ    ((ZXC_SEQ_LL_MASK - 1U) + (ZXC_SEQ_ML_MASK - 1U) + ZXC_LZ_MIN_MATCH_LEN) /* 513 */

Definition at line 674 of file zxc_internal.h.

◆ ZXC_POPCOUNT32

#define ZXC_POPCOUNT32 ( v)
Value:
static int zxc_popcount32(const uint32_t v)
Portable SWAR popcount (MSVC).
Definition zxc_deps.h:160

Definition at line 169 of file zxc_deps.h.

◆ ZXC_POPCOUNT64

#define ZXC_POPCOUNT64 ( v)
Value:
zxc_popcount64(v)

Definition at line 170 of file zxc_deps.h.

◆ ZXC_PREFETCH_READ

#define ZXC_PREFETCH_READ ( ptr)

Definition at line 239 of file zxc_internal.h.

◆ ZXC_REALLOC

#define ZXC_REALLOC ( ptr,
size )
Value:
realloc(ptr, size)

In-place / move heap reallocator.

Default: libc realloc.

Definition at line 80 of file zxc_deps.h.

Referenced by cs_compress_block_from(), cs_stage_eof(), ds_handle_need_block_header(), zxc_async_writer(), zxc_seekable_decompress_range(), zxc_seekable_parse(), and zxc_seekable_set_dict().

◆ ZXC_SEEK_ANCHOR_SIZE

#define ZXC_SEEK_ANCHOR_SIZE   8U

Group anchor: offset of its first block, u64.

Definition at line 466 of file zxc_internal.h.

Referenced by zxc_seek_load_spans(), zxc_seek_table_bytes(), zxc_seek_table_size(), zxc_seek_write_group(), and zxc_write_seek_table_from_blocks().

◆ ZXC_SEEK_GROUP

#define ZXC_SEEK_GROUP   64U

◆ ZXC_SEEK_GROUP_BYTES

#define ZXC_SEEK_GROUP_BYTES   (ZXC_SEEK_ANCHOR_SIZE + ZXC_SEEK_GROUP * ZXC_SEEK_SIZE_ENTRY)

◆ ZXC_SEEK_SIZE_ENTRY

#define ZXC_SEEK_SIZE_ENTRY   4U

One block's on-disk size, u32.

Definition at line 468 of file zxc_internal.h.

Referenced by zxc_seek_load_spans(), zxc_seek_table_bytes(), zxc_seek_write_group(), and zxc_write_seek_table_from_blocks().

◆ ZXC_SEQ_LL_BITS

#define ZXC_SEQ_LL_BITS   8

Bits for Literal Length in a PAK sequence.

Definition at line 523 of file zxc_internal.h.

◆ ZXC_SEQ_LL_MASK

#define ZXC_SEQ_LL_MASK   ((1U << ZXC_SEQ_LL_BITS) - 1)

Mask to extract Literal Length from a PAK sequence.

Definition at line 529 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), and zxc_encode_block_pak().

◆ ZXC_SEQ_LL_SHIFT

#define ZXC_SEQ_LL_SHIFT   (ZXC_SEQ_ML_BITS + ZXC_SEQ_OFF_BITS)

Shift of the Literal Length field: the top byte of the word.

Definition at line 535 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), and zxc_encode_block_pak().

◆ ZXC_SEQ_ML_BITS

#define ZXC_SEQ_ML_BITS   8

Bits for Match Length in a PAK sequence.

Definition at line 525 of file zxc_internal.h.

◆ ZXC_SEQ_ML_MASK

#define ZXC_SEQ_ML_MASK   ((1U << ZXC_SEQ_ML_BITS) - 1)

Mask to extract Match Length from a PAK sequence.

Definition at line 531 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), and zxc_encode_block_pak().

◆ ZXC_SEQ_ML_SHIFT

#define ZXC_SEQ_ML_SHIFT   ZXC_SEQ_OFF_BITS

Shift of the Match Length field: just above the offset.

Definition at line 537 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), and zxc_encode_block_pak().

◆ ZXC_SEQ_OFF_BITS

#define ZXC_SEQ_OFF_BITS   16

Bits for Offset in a PAK sequence.

Definition at line 527 of file zxc_internal.h.

◆ ZXC_SEQ_OFF_MASK

#define ZXC_SEQ_OFF_MASK   ((1U << ZXC_SEQ_OFF_BITS) - 1)

Mask to extract Offset from a PAK sequence.

Definition at line 533 of file zxc_internal.h.

Referenced by zxc_decode_block_pak_impl(), and zxc_encode_block_pak().

◆ ZXC_SPL_DESC_MAX_SIZE

#define ZXC_SPL_DESC_MAX_SIZE   (2 * sizeof(uint32_t))

Widest SPL section descriptors: the literal and token section sizes.

Definition at line 437 of file zxc_internal.h.

◆ ZXC_SPL_HEADER_BINARY_SIZE

#define ZXC_SPL_HEADER_BINARY_SIZE   12

Binary size of a SPL block sub-header.

Definition at line 433 of file zxc_internal.h.

Referenced by zxc_read_spl_header_and_desc(), and zxc_write_spl_header_and_desc().

◆ ZXC_SPL_INLINE_ML_CODE

#define ZXC_SPL_INLINE_ML_CODE   (ZXC_TOKEN_ML_MASK - 1U) /* 14 */

Longest match length code (length minus ZXC_LZ_MIN_MATCH_LEN) a SPL token carries inline; the code above it escapes to a varint.

Definition at line 667 of file zxc_internal.h.

Referenced by zxc_spl_match_split_block(), and zxc_spl_match_split_piece().

◆ ZXC_SPL_MAX_INLINE_ML

#define ZXC_SPL_MAX_INLINE_ML   (ZXC_SPL_INLINE_ML_CODE + ZXC_LZ_MIN_MATCH_LEN) /* 19 */

Longest match a SPL sequence carries without a varint extension.

Below ZXC_PAD_SIZE, so the inline path needs no length ladder: one 32-byte store covers it. The escape path always yields more, so comparing against this recovers "was the ml nibble inline".

Definition at line 673 of file zxc_internal.h.

Referenced by zxc_decode_copy_match_spl(), and zxc_spl_match_split_pieces().

◆ ZXC_SPL_MAX_INLINE_OUT_PER_SEQ

#define ZXC_SPL_MAX_INLINE_OUT_PER_SEQ   ((ZXC_TOKEN_LL_MASK - 1U) + ZXC_SPL_MAX_INLINE_ML) /* 33 */

Maximum decoded output of one sequence with inline ll/ml, used by the 4x bounds checks to reserve the rest of a batch.

Keep it small - the loop margins scale with it. Widening it to 543 once cost 2 percent of decode on silesia.

Definition at line 664 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl().

◆ ZXC_TOKEN_LIT_BITS

#define ZXC_TOKEN_LIT_BITS   4

Bits for Literal Length in a SPL token.

Definition at line 508 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl(), zxc_spl_match_split_block(), and zxc_spl_put_seq().

◆ ZXC_TOKEN_LL_MASK

#define ZXC_TOKEN_LL_MASK   ((1U << ZXC_TOKEN_LIT_BITS) - 1)

Mask to extract Literal Length from a SPL token.

Definition at line 512 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl(), zxc_spl_match_split_block(), and zxc_spl_put_seq().

◆ ZXC_TOKEN_ML_BITS

#define ZXC_TOKEN_ML_BITS   4

Bits for Match Length in a SPL token.

Definition at line 510 of file zxc_internal.h.

◆ ZXC_TOKEN_ML_MASK

#define ZXC_TOKEN_ML_MASK   ((1U << ZXC_TOKEN_ML_BITS) - 1)

Mask to extract Match Length from a SPL token.

Definition at line 514 of file zxc_internal.h.

Referenced by zxc_decode_block_spl_impl(), zxc_lz77_optimal_parse_spl(), zxc_spl_match_split_analyze(), zxc_spl_match_split_block(), and zxc_spl_put_seq().

◆ ZXC_USE_C11_ATOMICS

#define ZXC_USE_C11_ATOMICS   1

Definition at line 65 of file zxc_internal.h.

◆ ZXC_VARINT_1B_LIMIT

#define ZXC_VARINT_1B_LIMIT   (1U << 7)

Definition at line 590 of file zxc_internal.h.

◆ ZXC_VARINT_2B_LIMIT

#define ZXC_VARINT_2B_LIMIT   (1U << 14)

Definition at line 591 of file zxc_internal.h.

◆ ZXC_VARINT_3B_LIMIT

#define ZXC_VARINT_3B_LIMIT   (1U << 21)

Definition at line 592 of file zxc_internal.h.

◆ ZXC_VARINT_INVALID

#define ZXC_VARINT_INVALID   (2U * ZXC_BLOCK_SIZE_MAX)

A truncated or out-of-spec varint: a length no output holds.

Definition at line 587 of file zxc_internal.h.

Referenced by zxc_read_varint().

Function Documentation

◆ zxc_aligned_free()

void zxc_aligned_free ( void * ptr)
inlinestatic

Counterpart of zxc_aligned_malloc; NULL is a no-op.

Definition at line 124 of file zxc_deps.h.

◆ zxc_aligned_malloc()

void * zxc_aligned_malloc ( const size_t size,
const size_t alignment )
inlinestatic

Default cache-line-aligned allocator; release with zxc_aligned_free.

Definition at line 113 of file zxc_deps.h.

◆ zxc_magic_prefix_ok()

int zxc_magic_prefix_ok ( const uint8_t * p,
const size_t n )
inlinestatic

Whether the first n bytes (up to 4) at p agree with the magic word, so a frame may start there: the check a reader makes as bytes arrive.

Definition at line 319 of file zxc_internal.h.

References ZXC_MAGIC_WORD.

Referenced by ds_handle_need_file_header(), and zxc_container_next().

◆ zxc_popcount32()

int zxc_popcount32 ( const uint32_t v)
inlinestatic

Portable SWAR popcount (MSVC).

Definition at line 160 of file zxc_deps.h.

◆ zxc_popcount64()

int zxc_popcount64 ( const uint64_t v)
inlinestatic

Definition at line 166 of file zxc_deps.h.

◆ zxc_read_varint()

uint32_t zxc_read_varint ( const uint8_t ** ptr,
const uint8_t * end )
inlinestatic

Reads a Prefix Varint encoded integer.

Unary prefix bits in the first byte give the total length, at most 3 bytes since that covers every length the format admits:

Format:

  • 1 byte (0xxxxxxx): 7-bit payload (val < 2^7 = 128)
  • 2 bytes (10xxxxxx): 14-bit payload (val < 2^14 = 16384)
  • 3 bytes (110xxxxx): 21-bit payload (val < 2^21 = 2097152)
Parameters
[in,out]ptrPointer to a pointer to the current position in the stream.
[in]endPointer to the end of the readable stream (for bounds checking).
Returns
The decoded 32-bit integer, or ZXC_VARINT_INVALID if the encoding is truncated or out of spec.

Definition at line 620 of file zxc_internal.h.

References ZXC_ALWAYS_INLINE, and ZXC_VARINT_INVALID.

Referenced by zxc_decode_block_pak_impl(), zxc_decode_block_spl_impl(), zxc_spl_match_split_block(), and zxc_varint_keep().

◆ zxc_seek_group_count()

uint64_t zxc_seek_group_count ( const uint64_t nblocks)
inlinestatic

Groups holding nblocks blocks; the last one may be partial.

Definition at line 473 of file zxc_internal.h.

References ZXC_ALWAYS_INLINE, and ZXC_SEEK_GROUP.

Referenced by zxc_seek_load_spans(), and zxc_seek_table_bytes().

◆ zxc_seek_group_len()

uint32_t zxc_seek_group_len ( const uint64_t nblocks,
const uint64_t g )
inlinestatic

Blocks in group g of nblocks: ZXC_SEEK_GROUP, fewer for the last.

Definition at line 478 of file zxc_internal.h.

References ZXC_ALWAYS_INLINE, and ZXC_SEEK_GROUP.

Referenced by zxc_seek_load_spans(), zxc_stream_finish_compress(), and zxc_write_seek_table().

◆ zxc_seek_size_field()

uint32_t zxc_seek_size_field ( const uint64_t table_bytes)
inlinestatic

SEK header size field: table_bytes with its high half folded onto the low one.

Exact below 4 GiB; above, all 64 bits count.

Definition at line 490 of file zxc_internal.h.

References ZXC_ALWAYS_INLINE.

Referenced by zxc_seek_table_header().

◆ zxc_seek_table_bytes()

uint64_t zxc_seek_table_bytes ( const uint64_t nblocks)
inlinestatic