23#ifdef ZXC_FUNCTION_SUFFIX
24#define ZXC_CAT_IMPL(x, y) x##y
25#define ZXC_CAT(x, y) ZXC_CAT_IMPL(x, y)
26#define zxc_decompress_chunk_wrapper ZXC_CAT(zxc_decompress_chunk_wrapper, ZXC_FUNCTION_SUFFIX)
27#define zxc_decompress_chunk_wrapper_dict \
28 ZXC_CAT(zxc_decompress_chunk_wrapper_dict, ZXC_FUNCTION_SUFFIX)
29#define zxc_decompress_chunk_wrapper_safe \
30 ZXC_CAT(zxc_decompress_chunk_wrapper_safe, ZXC_FUNCTION_SUFFIX)
32#ifndef ZXC_DISPATCH_ENTROPY
33#define zxc_huf_decode_section ZXC_CAT(zxc_huf_decode_section, ZXC_FUNCTION_SUFFIX)
34#define zxc_huf_decode_section_dict ZXC_CAT(zxc_huf_decode_section_dict, ZXC_FUNCTION_SUFFIX)
41#if defined(ZXC_USE_NEON64) || defined(ZXC_USE_NEON32) || defined(ZXC_USE_AVX2) || \
42 defined(ZXC_USE_AVX512)
48static const ZXC_ALIGN(32) uint8_t zxc_overlap_masks32[32][32] = {
49 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
53 {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
54 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
55 {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0,
56 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1},
57 {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
58 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3},
59 {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,
60 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1},
61 {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
62 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1},
63 {0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1,
64 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3},
65 {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
66 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7},
67 {0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6,
68 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4},
69 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5,
70 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1},
71 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4,
72 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
73 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3,
74 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7},
75 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2,
76 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5},
77 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 1,
78 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 1, 2, 3},
79 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
80 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1},
81 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
82 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
83 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
84 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},
85 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
86 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
87 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
88 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
89 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
90 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
91 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
92 16, 17, 18, 19, 20, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
93 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
94 16, 17, 18, 19, 20, 21, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
95 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
96 16, 17, 18, 19, 20, 21, 22, 0, 1, 2, 3, 4, 5, 6, 7, 8},
97 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
98 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6, 7},
99 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
100 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6},
101 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
102 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 1, 2, 3, 4, 5},
103 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
104 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 1, 2, 3, 4},
105 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
106 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0, 1, 2, 3},
107 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
108 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 0, 1, 2},
109 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
110 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 1},
111 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
112 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 0}
122static const uint8_t
zxc_overlap_strides32[32] = {32, 32, 32, 30, 32, 30, 30, 28, 32, 27, 30,
123 22, 24, 26, 28, 30, 32, 17, 18, 19, 20, 21,
124 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
152#if defined(ZXC_USE_NEON64)
154 tbl.val[0] = vld1q_u8(dst - off);
155 tbl.val[1] = vld1q_u8(dst - off + 16);
156 const uint8x16_t pat_lo = vqtbl2q_u8(tbl, vld1q_u8(zxc_overlap_masks32[off]));
157 const uint8x16_t pat_hi = vqtbl2q_u8(tbl, vld1q_u8(zxc_overlap_masks32[off] + 16));
159 vst1q_u8(dst + copied, pat_lo);
160 vst1q_u8(dst + copied + 16, pat_hi);
162 }
while (copied < ml);
164#elif defined(ZXC_USE_NEON32)
168 tbl.val[0] = vld1_u8(dst - off);
169 tbl.val[1] = vld1_u8(dst - off + 8);
170 tbl.val[2] = vld1_u8(dst - off + 16);
171 tbl.val[3] = vld1_u8(dst - off + 24);
172 const uint8_t*
const m = zxc_overlap_masks32[off];
173 const uint8x8_t p0 = vtbl4_u8(tbl, vld1_u8(m));
174 const uint8x8_t p1 = vtbl4_u8(tbl, vld1_u8(m + 8));
175 const uint8x8_t p2 = vtbl4_u8(tbl, vld1_u8(m + 16));
176 const uint8x8_t p3 = vtbl4_u8(tbl, vld1_u8(m + 24));
178 vst1_u8(dst + copied, p0);
179 vst1_u8(dst + copied + 8, p1);
180 vst1_u8(dst + copied + 16, p2);
181 vst1_u8(dst + copied + 24, p3);
183 }
while (copied < ml);
185#elif defined(ZXC_USE_AVX2) || defined(ZXC_USE_AVX512)
188 const __m128i t0 = _mm_loadu_si128((
const __m128i*)(dst - off));
189 const __m128i t1 = _mm_loadu_si128((
const __m128i*)(dst - off + 16));
190 const __m128i sixteen = _mm_set1_epi8(16);
191 const __m128i m_lo = _mm_load_si128((
const __m128i*)zxc_overlap_masks32[off]);
192 const __m128i m_hi = _mm_load_si128((
const __m128i*)(zxc_overlap_masks32[off] + 16));
193 const __m128i pat_lo =
194 _mm_blendv_epi8(_mm_shuffle_epi8(t0, m_lo),
195 _mm_shuffle_epi8(t1, _mm_sub_epi8(m_lo, sixteen)), _mm_slli_epi16(m_lo, 3));
196 const __m128i pat_hi =
197 _mm_blendv_epi8(_mm_shuffle_epi8(t0, m_hi),
198 _mm_shuffle_epi8(t1, _mm_sub_epi8(m_hi, sixteen)), _mm_slli_epi16(m_hi, 3));
200 _mm_storeu_si128((__m128i*)(dst + copied), pat_lo);
201 _mm_storeu_si128((__m128i*)(dst + copied + 16), pat_hi);
203 }
while (copied < ml);
208 const uint8_t* src = dst - off;
211 for (
size_t i = 0; i < 32; i++) {
213 if (++k == off) k = 0;
219 }
while (copied < ml);
245#if defined(ZXC_USE_NEON64)
246 const uint8x16_t s0 = vld1q_u8(dst - off);
247 vst1q_u8(dst, vqtbl1q_u8(s0, vld1q_u8(zxc_overlap_masks32[off])));
248 if (UNLIKELY(ml > 16)) {
251 tbl.val[1] = vld1q_u8(dst - off + 16);
252 vst1q_u8(dst + 16, vqtbl2q_u8(tbl, vld1q_u8(zxc_overlap_masks32[off] + 16)));
255#elif defined(ZXC_USE_NEON32)
257 lo_tbl.val[0] = vld1_u8(dst - off);
258 lo_tbl.val[1] = vld1_u8(dst - off + 8);
259 const uint8_t*
const m = zxc_overlap_masks32[off];
260 vst1_u8(dst, vtbl2_u8(lo_tbl, vld1_u8(m)));
261 vst1_u8(dst + 8, vtbl2_u8(lo_tbl, vld1_u8(m + 8)));
262 if (UNLIKELY(ml > 16)) {
264 tbl.val[0] = lo_tbl.val[0];
265 tbl.val[1] = lo_tbl.val[1];
266 tbl.val[2] = vld1_u8(dst - off + 16);
267 tbl.val[3] = vld1_u8(dst - off + 24);
268 vst1_u8(dst + 16, vtbl4_u8(tbl, vld1_u8(m + 16)));
269 vst1_u8(dst + 24, vtbl4_u8(tbl, vld1_u8(m + 24)));
272#elif defined(ZXC_USE_AVX2) || defined(ZXC_USE_AVX512)
275 const __m128i t0 = _mm_loadu_si128((
const __m128i*)(dst - off));
278 _mm_shuffle_epi8(t0, _mm_load_si128((
const __m128i*)zxc_overlap_masks32[off])));
279 if (UNLIKELY(ml > 16)) {
280 const __m128i t1 = _mm_loadu_si128((
const __m128i*)(dst - off + 16));
281 const __m128i m_hi = _mm_load_si128((
const __m128i*)(zxc_overlap_masks32[off] + 16));
283 (__m128i*)(dst + 16),
284 _mm_blendv_epi8(_mm_shuffle_epi8(t0, m_hi),
285 _mm_shuffle_epi8(t1, _mm_sub_epi8(m_hi, _mm_set1_epi8(16))),
286 _mm_slli_epi16(m_hi, 3)));
290 const uint8_t* src = dst - off;
291 const size_t n = (ml > 16) ? 32 : 16;
293 for (
size_t i = 0; i < n; i++) {
295 if (++k == off) k = 0;
316#if defined(ZXC_USE_AVX2) || defined(ZXC_USE_AVX512)
317 const __m256i v = _mm256_set1_epi8((
char)
byte);
318 _mm256_storeu_si256((__m256i*)dst, v);
319 if (UNLIKELY(ml > 32)) {
321 const uint8_t*
const last = dst + ml - 32;
324 _mm256_storeu_si256((__m256i*)p, v);
327#elif defined(ZXC_USE_SSE2)
328 const __m128i v = _mm_set1_epi8((
char)
byte);
329 _mm_storeu_si128((__m128i*)dst, v);
330 _mm_storeu_si128((__m128i*)(dst + 16), v);
331 if (UNLIKELY(ml > 32)) {
333 const uint8_t*
const last = dst + ml - 32;
336 _mm_storeu_si128((__m128i*)p, v);
337 _mm_storeu_si128((__m128i*)(p + 16), v);
340#elif defined(ZXC_USE_NEON64) || defined(ZXC_USE_NEON32)
341 const uint8x16_t v = vdupq_n_u8(
byte);
343 vst1q_u8(dst + 16, v);
344 if (UNLIKELY(ml > 32)) {
346 const uint8_t*
const last = dst + ml - 32;
354 ZXC_MEMSET(dst,
byte, ml);
379 if (UNLIKELY(len > 32)) {
380 size_t rem = len - 32;
409 const uint8_t* RESTRICT src,
439 const uint8_t* match_src = d_ptr - off;
440 if (LIKELY(off >= 32)) {
442 }
else if (off == 1) {
465 const uint32_t off,
const uint64_t ml) {
466 const uint8_t* match_src = d_ptr - off;
467 if (LIKELY(off >= 32)) {
469 }
else if (off == 1) {
509 const size_t off,
const size_t ml) {
511 ZXC_MEMCPY(d_ptr, match_src, ml);
512 }
else if (ml < 16) {
513 for (
size_t i = 0; i < ml; i++) d_ptr[i] = match_src[i];
516 ZXC_MEMCPY(d_ptr, match_src, n);
517 while (n <= ml - n) {
518 ZXC_MEMCPY(d_ptr + n, d_ptr, n);
521 ZXC_MEMCPY(d_ptr + n, d_ptr, ml - n);
532#define DECODE_MATCH_SAFE(ml, off, COPY) \
534 if (UNLIKELY((size_t)(d_ptr - d_floor) < (off))) return ZXC_ERROR_BAD_OFFSET; \
535 COPY(d_ptr, off, ml); \
541#define DECODE_MATCH_FAST(ml, off, COPY) \
543 COPY(d_ptr, off, ml); \
558#define SPL_OFF8 (gh.enc_off == 1)
573#define DECODE_SPL_SEQ(LL, ML, OFF, RESERVE, N_REM, DECODE, ON_FAIL) \
575 uint64_t ll = (LL); \
576 uint64_t ml = (ML); \
577 if (UNLIKELY(ll == ZXC_TOKEN_LL_MASK)) { \
578 ll += zxc_read_varint(&e_ptr, e_end); \
579 const uint64_t reserve = (RESERVE); \
583 if (UNLIKELY(ll + reserve > (size_t)(l_end - l_ptr) || \
584 ll + ml + ZXC_LZ_MIN_MATCH_LEN + \
585 (N_REM) * ZXC_SPL_MAX_INLINE_OUT_PER_SEQ + ZXC_PAD_SIZE > \
586 (size_t)(d_end - d_ptr))) \
588 zxc_decode_copy_literals(d_ptr, l_ptr, ll); \
591 zxc_copy16(d_ptr, l_ptr); \
595 if (UNLIKELY(ml == ZXC_TOKEN_ML_MASK)) { \
596 ml += zxc_read_varint(&e_ptr, e_end); \
598 if (UNLIKELY(ml + ZXC_LZ_MIN_MATCH_LEN + (N_REM) * ZXC_SPL_MAX_INLINE_OUT_PER_SEQ + \
600 (size_t)(d_end - d_ptr))) \
603 ml += ZXC_LZ_MIN_MATCH_LEN; \
604 DECODE(ml, OFF, zxc_decode_copy_match_spl); \
615#define DECODE_SPL_BATCH_4X(DECODE, ON_FAIL) \
617 uint32_t tokens = zxc_le32(t_ptr); \
618 t_ptr += sizeof(uint32_t); \
621 uint64_t x = zxc_le32(o_ptr); \
622 o_ptr += sizeof(uint32_t); \
623 x = (x | (x << 16)) & 0x0000FFFF0000FFFFULL; \
624 offs = (x | (x << 8)) & 0x00FF00FF00FF00FFULL; \
626 offs = zxc_le64(o_ptr); \
627 o_ptr += sizeof(uint64_t); \
629 DECODE_SPL_SEQ((tokens & 0x0F0) >> 4, (tokens & 0x00F), \
630 ZXC_LZ_OFFSET_BIAS + (uint32_t)(offs & 0xFFFF), \
631 ((tokens >> 12) & 0xF) + ((tokens >> 20) & 0xF) + (tokens >> 28), 3U, \
633 DECODE_SPL_SEQ((tokens & 0x0F000) >> 12, (tokens & 0x00F00) >> 8, \
634 ZXC_LZ_OFFSET_BIAS + (uint32_t)((offs >> 16) & 0xFFFF), \
635 ((tokens >> 20) & 0xF) + (tokens >> 28), 2U, DECODE, ON_FAIL); \
636 DECODE_SPL_SEQ((tokens & 0x0F00000) >> 20, (tokens & 0x00F0000) >> 16, \
637 ZXC_LZ_OFFSET_BIAS + (uint32_t)((offs >> 32) & 0xFFFF), (tokens >> 28), 1U, \
639 DECODE_SPL_SEQ((tokens >> 28), (tokens >> 24) & 0x0F, \
640 ZXC_LZ_OFFSET_BIAS + (uint32_t)(offs >> 48), 0, 0U, DECODE, ON_FAIL); \
649#define DECODE_PAK_SEQ(S, RESERVE, N_REM, DECODE, ON_FAIL) \
651 uint64_t ll = (S) >> ZXC_SEQ_LL_SHIFT; \
652 const uint32_t mb = ((S) >> ZXC_SEQ_ML_SHIFT) & ZXC_SEQ_ML_MASK; \
653 uint64_t ml = mb + ZXC_LZ_MIN_MATCH_LEN; \
654 if (UNLIKELY(ll == ZXC_SEQ_LL_MASK)) { \
655 ll += zxc_read_varint(&extras_ptr, extras_end); \
656 const uint64_t reserve = (RESERVE); \
658 if (UNLIKELY(ll + reserve > (size_t)(l_end - l_ptr) || \
659 ll + ml + (N_REM) * ZXC_PAK_MAX_INLINE_OUT_PER_SEQ + ZXC_PAD_SIZE > \
660 (size_t)(d_end - d_ptr))) \
663 if (UNLIKELY(mb == ZXC_SEQ_ML_MASK)) { \
664 ml += zxc_read_varint(&extras_ptr, extras_end); \
665 if (UNLIKELY(ll + ml + (N_REM) * ZXC_PAK_MAX_INLINE_OUT_PER_SEQ + ZXC_PAD_SIZE > \
666 (size_t)(d_end - d_ptr))) \
669 const uint32_t off = ((S) & ZXC_SEQ_OFF_MASK) + ZXC_LZ_OFFSET_BIAS; \
671 zxc_decode_copy_literals(d_ptr, l_ptr, ll); \
674 DECODE(ml, off, zxc_decode_copy_match); \
682#define DECODE_PAK_BATCH_4X(DECODE, ON_FAIL, PREFETCH) \
684 uint32_t s1 = zxc_le32(seq_ptr); \
685 uint32_t s2 = zxc_le32(seq_ptr + sizeof(uint32_t)); \
686 uint32_t s3 = zxc_le32(seq_ptr + 2 * sizeof(uint32_t)); \
687 uint32_t s4 = zxc_le32(seq_ptr + 3 * sizeof(uint32_t)); \
688 seq_ptr += 4 * sizeof(uint32_t); \
691 s1, (s2 >> ZXC_SEQ_LL_SHIFT) + (s3 >> ZXC_SEQ_LL_SHIFT) + (s4 >> ZXC_SEQ_LL_SHIFT), \
692 3U, DECODE, ON_FAIL); \
693 DECODE_PAK_SEQ(s2, (s3 >> ZXC_SEQ_LL_SHIFT) + (s4 >> ZXC_SEQ_LL_SHIFT), 2U, DECODE, \
695 DECODE_PAK_SEQ(s3, (s4 >> ZXC_SEQ_LL_SHIFT), 1U, DECODE, ON_FAIL); \
696 DECODE_PAK_SEQ(s4, 0, 0U, DECODE, ON_FAIL); \
715 if (LIKELY(ctx->pivco_scratch))
return ZXC_OK;
720 const uint8_t* RESTRICT payload,
722 const size_t required_size) {
724 if (UNLIKELY(arc !=
ZXC_OK))
return arc;
725 if (UNLIKELY(ctx->lit_buffer_cap < required_size +
ZXC_PAD_SIZE ||
734#define zxc_decode_lit_pivco_dict(ctx, payload, psize, required_size) ZXC_ERROR_DICT_REQUIRED
735#define zxc_decode_block_spl_entropy_dict(ctx, src, src_size, dst, dst_capacity) \
736 ZXC_ERROR_DICT_REQUIRED
737#define zxc_decode_block_spl_dict(ctx, src, src_size, dst, dst_capacity) ZXC_ERROR_DICT_REQUIRED
738#define zxc_decode_block_pak_dict(ctx, src, src_size, dst, dst_capacity) ZXC_ERROR_DICT_REQUIRED
741 const uint8_t* RESTRICT payload,
743 const size_t required_size) {
746 if (UNLIKELY(arc !=
ZXC_OK))
return arc;
747 if (UNLIKELY(ctx->lit_buffer_cap < required_size +
ZXC_PAD_SIZE ||
751 &ctx->dict_huf->tree, ctx->pivco_scratch);
756 const uint8_t* RESTRICT payload,
757 const size_t psize,
const size_t n_tok) {
759 if (UNLIKELY(arc !=
ZXC_OK))
return arc;
760 if (UNLIKELY(n_tok +
ZXC_PAD_SIZE > ctx->tok_buffer_cap ||
767 const uint8_t* RESTRICT src,
size_t src_size,
768 uint8_t* RESTRICT dst,
size_t dst_capacity);
771 const uint8_t* RESTRICT src,
772 size_t src_size, uint8_t* RESTRICT dst,
773 size_t dst_capacity);
776 const uint8_t* RESTRICT src,
777 size_t src_size, uint8_t* RESTRICT dst,
778 size_t dst_capacity);
809 const uint8_t* RESTRICT src,
810 const size_t src_size, uint8_t* RESTRICT dst,
811 const size_t dst_capacity,
const int safe,
812 const int has_dict,
const int tok_entropy) {
816 const size_t dict_size = has_dict ? ctx->dict_size : 0;
830 if (!tok_entropy && UNLIKELY(gh.
enc_tok == ZXC_SECTION_ENCODING_HUFFMAN)) {
831 if (safe)
return zxc_decode_block_spl_entropy_safe(ctx, src, src_size, dst, dst_capacity);
833 return zxc_decode_block_spl_entropy_dict(ctx, src, src_size, dst, dst_capacity);
837 const uint8_t* p_data = src + (size_t)hdr_sz;
838 const uint8_t* p_curr = p_data;
841 const uint8_t* l_ptr;
842 const uint8_t* l_end;
843 uint8_t* rle_buf = NULL;
845 size_t lit_stream_size = lit_comp;
849 if (gh.
enc_lit == ZXC_SECTION_ENCODING_HUFFMAN ||
850 gh.
enc_lit == ZXC_SECTION_ENCODING_HUFFMAN_DICT) {
851 if (UNLIKELY(lit_stream_size > (
size_t)(src + src_size - p_curr)))
853 if (required_size == 0) {
857 if (UNLIKELY(required_size > dst_capacity || required_size > SIZE_MAX -
ZXC_PAD_SIZE))
860 (gh.
enc_lit == ZXC_SECTION_ENCODING_HUFFMAN)
861 ? zxc_decode_lit_pivco(ctx, p_curr, lit_stream_size, required_size)
862 : zxc_decode_lit_pivco_dict(ctx, p_curr, lit_stream_size, required_size);
863 if (UNLIKELY(rc !=
ZXC_OK))
return rc;
864 l_ptr = ctx->lit_buffer;
865 l_end = ctx->lit_buffer + required_size;
867 }
else if (gh.
enc_lit == ZXC_SECTION_ENCODING_RLE) {
868 if (required_size > 0) {
869 if (UNLIKELY(required_size > dst_capacity || required_size > SIZE_MAX -
ZXC_PAD_SIZE))
877 rle_buf = ctx->lit_buffer;
878 if (UNLIKELY(!rle_buf || lit_stream_size > (
size_t)(src + src_size - p_curr)))
881 const uint8_t* r_ptr = p_curr;
882 const uint8_t* r_end = r_ptr + lit_stream_size;
883 uint8_t* w_ptr = rle_buf;
884 const uint8_t*
const w_end = rle_buf + required_size;
886 while (r_ptr < r_end && w_ptr < w_end) {
887 uint8_t token = *r_ptr++;
891 const uint32_t len = (uint32_t)token + 1;
892 if (UNLIKELY(w_ptr + len > w_end || r_ptr + len > r_end))
898 if (LIKELY(r_ptr + 32 <= r_end)) {
902 if (UNLIKELY(len > 32)) {
907 zxc_copy32(w_ptr + len - 32, r_ptr + len - 32);
908 }
else if (len <= 96) {
910 zxc_copy32(w_ptr + len - 32, r_ptr + len - 32);
914 zxc_copy32(w_ptr + len - 32, r_ptr + len - 32);
919 ZXC_MEMCPY(w_ptr, r_ptr, len);
927 if (UNLIKELY(w_ptr + len > w_end || r_ptr >= r_end))
929 ZXC_MEMSET(w_ptr, *r_ptr++, len);
935 l_end = rle_buf + required_size;
941 }
else if (gh.
enc_lit == ZXC_SECTION_ENCODING_RAW) {
942 if (UNLIKELY(lit_stream_size > (
size_t)(src + src_size - p_curr)))
945 l_end = p_curr + lit_stream_size;
950 p_curr += lit_stream_size;
955 const size_t sz_tokens = tok_comp;
958 const size_t payload_avail = (size_t)(src + src_size - p_data);
959 const uint64_t consumed = (uint64_t)lit_stream_size + (uint64_t)sz_tokens + sz_offsets;
961 const size_t sz_extras = payload_avail - (size_t)consumed;
972 const uint8_t* o_ptr = p_curr + sz_tokens;
973 const uint8_t* e_ptr = o_ptr + (size_t)sz_offsets;
974 const uint8_t*
const e_end = e_ptr + sz_extras;
976 const uint8_t* RESTRICT t_ptr;
984 const int rc = zxc_decode_tok_pivco(ctx, p_curr, sz_tokens, gh.
n_sequences);
985 if (UNLIKELY(rc !=
ZXC_OK))
return rc;
986 t_ptr = ctx->tok_buffer;
989 uint8_t* d_ptr = dst;
990 const uint8_t*
const d_end = dst + dst_capacity;
992 const uint8_t*
const d_floor = dst - dict_size;
995 const uint8_t*
const d_end_safe = (dst_capacity > d_margin_4x) ? d_end - d_margin_4x : dst;
999 const size_t spl_sz_lit = (size_t)(l_end - l_ptr);
1002 const uint8_t*
const l_end_safe_4x =
1003 (spl_sz_lit > spl_margin_4x) ? l_end - spl_margin_4x : l_ptr;
1004 const uint8_t*
const l_end_safe_1x =
1005 (spl_sz_lit > spl_margin_1x) ? l_end - spl_margin_1x : l_ptr;
1013 const size_t off_span =
SPL_OFF8 ? (1U << 8) : (1U << 16);
1014 const size_t span = (dict_size >= off_span) ? 0 : off_span - dict_size;
1015 const uint8_t*
const d_bounds = (span >= dst_capacity) ? d_end : dst + span;
1020 while (n_seq >= 4 && d_ptr < d_end_safe && l_ptr < l_end_safe_4x && d_ptr < d_bounds) {
1021 const uint8_t*
const t_save = t_ptr;
1022 const uint8_t*
const o_save = o_ptr;
1023 const uint8_t*
const e_save = e_ptr;
1024 uint8_t*
const d_save = d_ptr;
1025 const uint8_t*
const l_save = l_ptr;
1038 while (n_seq >= 4 && d_ptr < d_end_safe && l_ptr < l_end_safe_4x && d_ptr < d_bounds) {
1045 while (n_seq >= 4 && d_ptr < d_end_safe && l_ptr < l_end_safe_4x) {
1046 const uint8_t*
const t_save = t_ptr;
1047 const uint8_t*
const o_save = o_ptr;
1048 const uint8_t*
const e_save = e_ptr;
1049 uint8_t*
const d_save = d_ptr;
1050 const uint8_t*
const l_save = l_ptr;
1063 while (n_seq >= 4 && d_ptr < d_end_safe && l_ptr < l_end_safe_4x) {
1069 while (n_seq > 0 && d_ptr < d_end_safe && l_ptr < l_end_safe_1x) {
1071 const uint8_t* t_save = t_ptr;
1072 const uint8_t* o_save = o_ptr;
1073 const uint8_t* e_save = e_ptr;
1075 uint8_t token = *t_ptr++;
1083 o_ptr +=
sizeof(uint16_t);
1094 if (UNLIKELY(ll + ml +
ZXC_PAD_SIZE > (
size_t)(d_end - d_ptr))) {
1112 if (UNLIKELY(d_ptr < d_bounds && (
size_t)(d_ptr - d_floor) < offset))
1124 uint8_t token = *t_ptr++;
1132 o_ptr +=
sizeof(uint16_t);
1139 if (UNLIKELY(ll + ml > (
size_t)(d_end - d_ptr) || ll > (
size_t)(l_end - l_ptr)))
1141 ZXC_MEMCPY(d_ptr, l_ptr, ll);
1146 const uint8_t* match_src = d_ptr - offset;
1158 const size_t remaining_literals = (size_t)(l_end - l_ptr);
1159 if (UNLIKELY(remaining_literals > (
size_t)(d_end - d_ptr)))
return ZXC_ERROR_OVERFLOW;
1160 ZXC_MEMCPY(d_ptr, l_ptr, remaining_literals);
1161 d_ptr += remaining_literals;
1163 return (
int)(d_ptr - dst);
1187 const uint8_t* RESTRICT src,
1188 const size_t src_size, uint8_t* RESTRICT dst,
1189 const size_t dst_capacity,
const int safe,
1190 const int has_dict) {
1194 const size_t dict_size = has_dict ? ctx->dict_size : 0;
1197 if (UNLIKELY(gh.
enc_lit != ZXC_SECTION_ENCODING_RAW || gh.
enc_tok != 0))
1201 const uint8_t* p_curr = p_data;
1207 const uint64_t sz_seqs = (uint64_t)gh.
n_sequences *
sizeof(uint32_t);
1209 const size_t payload_avail = (size_t)(src + src_size - p_data);
1210 const uint64_t consumed = (uint64_t)sz_lit + sz_seqs;
1212 const size_t sz_exts = payload_avail - (size_t)consumed;
1218 const uint8_t* l_ptr = p_curr;
1219 const uint8_t* l_end = l_ptr + sz_lit;
1222 const uint8_t* seq_ptr = p_curr;
1223 const uint8_t* extras_ptr = p_curr + (size_t)sz_seqs;
1224 const uint8_t*
const extras_end = extras_ptr + sz_exts;
1226 uint8_t* d_ptr = dst;
1227 const uint8_t*
const d_end = dst + dst_capacity;
1229 const uint8_t*
const d_floor = dst - dict_size;
1230 const uint8_t*
const d_end_safe =
1235 const uint8_t*
const d_end_fast =
1242 const uint8_t*
const l_end_safe_4x = (sz_lit > pak_margin_4x) ? l_end - pak_margin_4x : l_ptr;
1243 const uint8_t*
const l_end_safe_1x = (sz_lit > pak_margin_1x) ? l_end - pak_margin_1x : l_ptr;
1249 const size_t off_span = 1U << 16;
1250 const size_t span = (dict_size >= off_span) ? 0 : off_span - dict_size;
1251 const uint8_t*
const d_bounds = (span >= dst_capacity) ? d_end : dst + span;
1258 while (n_seq >= 4 && d_ptr < d_end_fast && l_ptr < l_end_safe_4x && d_ptr < d_bounds) {
1259 const uint8_t*
const t_save = seq_ptr;
1260 const uint8_t*
const e_save = extras_ptr;
1261 uint8_t*
const d_save = d_ptr;
1262 const uint8_t*
const l_save = l_ptr;
1268 extras_ptr = e_save;
1274 while (n_seq >= 4 && d_ptr < d_end_fast && l_ptr < l_end_safe_4x && d_ptr < d_bounds) {
1280 while (n_seq > 0 && d_ptr < d_end_safe && d_ptr < d_bounds) {
1282 seq_ptr +=
sizeof(uint32_t);
1295 if (UNLIKELY(ll + ml +
ZXC_PAD_SIZE > (
size_t)(d_end - d_ptr) ||
1298 if (UNLIKELY(ll + ml > (
size_t)(d_end - d_ptr) || ll > (
size_t)(l_end - l_ptr)))
1300 ZXC_MEMCPY(d_ptr, l_ptr, ll);
1305 const uint8_t* match_src = d_ptr - offset;
1320 while (n_seq >= 4 && d_ptr < d_end_fast && l_ptr < l_end_safe_4x) {
1321 const uint8_t*
const t_save = seq_ptr;
1322 const uint8_t*
const e_save = extras_ptr;
1323 uint8_t*
const d_save = d_ptr;
1324 const uint8_t*
const l_save = l_ptr;
1331 extras_ptr = e_save;
1337 while (n_seq >= 4 && d_ptr < d_end_fast && l_ptr < l_end_safe_4x) {
1344 while (n_seq > 0 && d_ptr < d_end_safe && l_ptr < l_end_safe_1x) {
1346 const uint8_t* seq_save = seq_ptr;
1347 const uint8_t* ext_save = extras_ptr;
1349 const uint32_t seq =
zxc_le32(seq_ptr);
1350 seq_ptr +=
sizeof(uint32_t);
1363 if (UNLIKELY(ll + ml +
ZXC_PAD_SIZE > (
size_t)(d_end - d_ptr) ||
1366 extras_ptr = ext_save;
1375 if (UNLIKELY(d_ptr < d_bounds && (
size_t)(d_ptr - d_floor) < offset))
1388 seq_ptr +=
sizeof(uint32_t);
1398 if (UNLIKELY(ll + ml > (
size_t)(d_end - d_ptr) || ll > (
size_t)(l_end - l_ptr)))
1400 ZXC_MEMCPY(d_ptr, l_ptr, ll);
1405 const uint8_t* match_src = d_ptr - offset;
1417 const size_t remaining_literals = (size_t)(l_end - l_ptr);
1418 if (UNLIKELY(remaining_literals > (
size_t)(d_end - d_ptr)))
return ZXC_ERROR_OVERFLOW;
1419 ZXC_MEMCPY(d_ptr, l_ptr, remaining_literals);
1420 d_ptr += remaining_literals;
1422 return (
int)(d_ptr - dst);
1431 const uint8_t* RESTRICT src,
1432 const size_t src_size, uint8_t* RESTRICT dst,
1433 const size_t dst_capacity) {
1439 const uint8_t* RESTRICT src,
1440 const size_t src_size,
1441 uint8_t* RESTRICT dst,
1442 const size_t dst_capacity) {
1448 const uint8_t* RESTRICT src,
1449 const size_t src_size,
1450 uint8_t* RESTRICT dst,
1451 const size_t dst_capacity) {
1469 const size_t src_size, uint8_t* RESTRICT dst,
1470 const size_t dst_capacity) {
1487 const size_t src_size, uint8_t* RESTRICT dst,
1488 const size_t dst_capacity) {
1508 const uint8_t* RESTRICT src,
1509 const size_t src_size, uint8_t* RESTRICT dst,
1510 const size_t dst_capacity) {
1530 const uint8_t* RESTRICT src,
1531 const size_t src_size, uint8_t* RESTRICT dst,
1532 const size_t dst_capacity) {
1552 const uint8_t* RESTRICT src,
1553 const size_t src_size, uint8_t* RESTRICT dst,
1554 const size_t dst_capacity) {
1573 const uint8_t* RESTRICT src,
1574 const size_t src_size, uint8_t* RESTRICT dst,
1575 const size_t dst_capacity) {
1579#undef DECODE_PAK_BATCH_4X
1580#undef DECODE_PAK_SEQ
1581#undef DECODE_SPL_BATCH_4X
1582#undef DECODE_SPL_SEQ
1583#undef DECODE_MATCH_FAST
1585#undef DECODE_MATCH_SAFE
1608 const zxc_cctx_t* RESTRICT ctx,
const uint8_t* RESTRICT src,
const size_t src_sz,
1609 uint8_t* RESTRICT dst,
const size_t dst_cap,
const uint64_t block_index,
const int has_dict,
1614 const uint8_t type = src[0];
1615 const uint32_t comp_sz =
zxc_le32(src + 3);
1616 const int has_checksum = ctx->checksum_enabled;
1622 const size_t expected_sz =
1644 ZXC_MEMCPY(dst, data, comp_sz);
1645 decoded_sz = (int)comp_sz;
1655 if (UNLIKELY(decoded_sz > 0 && (
size_t)decoded_sz > ctx->chunk_size))
1658 if (has_checksum && LIKELY(decoded_sz >= 0)) {
1659 const uint32_t stored =
zxc_le32(data + comp_sz);
1660 if (UNLIKELY(stored !=
1676 const size_t src_sz, uint8_t* RESTRICT dst,
const size_t dst_cap,
1677 const uint64_t block_index) {
1699 const size_t src_sz, uint8_t* RESTRICT dst,
1700 const size_t dst_cap,
const uint64_t block_index) {
1723 const size_t src_sz, uint8_t* RESTRICT dst,
1724 const size_t dst_cap,
const uint64_t block_index) {
@ ZXC_ERROR_BAD_BLOCK_TYPE
Unknown or unexpected block type.
@ ZXC_ERROR_OVERFLOW
Buffer overflow detected during processing.
@ ZXC_ERROR_BAD_OFFSET
Invalid match offset during decompression.
@ ZXC_ERROR_CORRUPT_DATA
Corrupted compressed data.
@ ZXC_ERROR_BAD_HEADER
Corrupted or invalid header (checksum mismatch).
@ ZXC_ERROR_DST_TOO_SMALL
Destination buffer too small.
@ ZXC_ERROR_SRC_TOO_SMALL
Source buffer too small or truncated input.
@ ZXC_ERROR_DICT_REQUIRED
File requires a dictionary but none was provided.
@ ZXC_ERROR_BAD_CHECKSUM
A block's decoded bytes fail its checksum, or the archive digest mismatches.
@ ZXC_OK
Success (no error).
@ ZXC_ERROR_BAD_BLOCK_SIZE
Invalid block size.
#define ZXC_LIT_LEN_MASK
Mask to extract the run/literal length (lower 7 bits).
#define ZXC_SEQ_OFF_MASK
Mask to extract Offset from a PAK sequence.
#define ZXC_ALWAYS_INLINE
Forces a function to be inlined (fallback for non-GCC/Clang/MSVC compilers).
#define ZXC_LIT_RLE_RUN_MIN
Shortest run worth an RLE token: a length field of 0 means this many bytes.
#define ZXC_SEQ_ML_MASK
Mask to extract Match Length from a PAK sequence.
#define ZXC_CHECKSUM_RAPIDHASH
Checksum algorithm id for RapidHash (default, sole implementation).
#define ZXC_SEQ_ML_SHIFT
Shift of the Match Length field: just above the offset.
#define ZXC_SPL_MAX_INLINE_OUT_PER_SEQ
Maximum decoded output of one sequence with inline ll/ml, used by the 4x bounds checks to reserve the...
#define ZXC_SEQ_LL_SHIFT
Shift of the Literal Length field: the top byte of the word.
#define ZXC_TOKEN_ML_MASK
Mask to extract Match Length from a SPL token.
#define ZXC_TOKEN_LL_MASK
Mask to extract Literal Length from a SPL token.
#define ZXC_LZ_MIN_MATCH_LEN
Minimum match length for an LZ77 match.
#define ZXC_PAD_SIZE
Safety padding appended to buffers to tolerate overruns.
#define ZXC_LZ_OFFSET_BIAS
Base bias added to encoded offsets (stored = actual - bias).
#define ZXC_BLOCK_HEADER_SIZE
Block header size: Type(1)+Flags(1)+Reserved(1)+Checksum(1)+CompSize(4).
#define ZXC_BLOCK_LIT_SLACK
Readable bytes a SPL/PAK payload guarantees after its literal section.
#define ZXC_PAK_HEADER_BINARY_SIZE
Binary size of a PAK block sub-header.
#define ZXC_NOINLINE
Prevents inlining (best-effort no-op fallback for unknown compilers).
#define ZXC_SPL_MAX_INLINE_ML
Longest match a SPL sequence carries without a varint extension.
#define ZXC_ALIGN(x)
Specifies memory alignment using C11 _Alignas.
static uint32_t zxc_read_varint(const uint8_t **ptr, const uint8_t *end)
Reads a Prefix Varint encoded integer.
#define ZXC_LIT_RLE_FLAG
Flag bit indicating an RLE run in the literal stream (0x80).
#define ZXC_BLOCK_CHECKSUM_SIZE
Size of the per-block checksum field in bytes.
#define ZXC_CACHE_LINE_SIZE
Assumed CPU cache line size for alignment.
#define ZXC_TOKEN_LIT_BITS
Bits for Literal Length in a SPL token.
#define ZXC_DECOMPRESS_TAIL_PAD
Tail padding required on the decompression destination buffer.
#define ZXC_SEQ_LL_MASK
Mask to extract Literal Length from a PAK sequence.
Compression / decompression context.
Build configuration: what the ZXC_BUILD_SIMD_VARIANTS choice runs, derived once.
int zxc_cctx_alloc_entropy_scratch(zxc_cctx_t *ctx)
Lazily allocates the deferred decode-side entropy scratch.
int zxc_read_spl_header_and_desc(const uint8_t *src, const size_t len, zxc_gnr_header_t *gh, uint32_t *lit_comp, uint32_t *tok_comp)
Parses a SPL block header and its section descriptors from src.
int zxc_read_pak_header(const uint8_t *src, const size_t len, zxc_gnr_header_t *gh)
Parses a PAK block header from src.
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 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).
#define SPL_OFF8
True when the SPL offset stream stores 1-byte offsets, 2-byte otherwise.
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 int zxc_ensure_entropy_scratch(const zxc_cctx_t *ctx)
Ensures the entropy decode scratch (tok_buffer + pivco_scratch) is available before decoding an entro...
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 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_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_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.
#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,...
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.
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.
#define DECODE_PAK_BATCH_4X(DECODE, ON_FAIL, PREFETCH)
One full PAK 4x batch.
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 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_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).
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).
static const uint8_t zxc_overlap_strides32[32]
Store stride for the 32-byte pattern: (32 / off) * off.
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 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 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-toke...
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 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.
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).
static int zxc_decode_block_spl_entropy(const zxc_cctx_t *ctx, const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_capacity)
Cold specializations for entropy-coded SPL tokens (level 7).
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.
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).
int zxc_huf_decode_section_dict(const uint8_t *payload, const size_t payload_size, uint8_t *dst, const size_t n, const zxc_pivco_tree_t *tree, uint8_t *scratch)
Decode a PivCo dict section against a prebuilt dict tree.
int zxc_huf_decode_section(const uint8_t *payload, const size_t payload_size, uint8_t *dst, const size_t n, uint8_t *scratch)
Decode a PivCo literal section into dst (exactly n bytes).
Error codes and error-name lookup for the ZXC library.
Internal definitions, constants, SIMD helpers, and utility functions.
#define ZXC_PIVCO_SCRATCH_PAD
Extra scratch slack required past n by the PivCo decoder.
static uint32_t zxc_le32(const void *p)
Reads a little-endian 32-bit value from a possibly unaligned address.
static void zxc_copy32(void *dst, const void *src)
Copies 32 bytes from source to destination using SIMD when available.
static uint16_t zxc_le16(const void *p)
Reads a little-endian 16-bit value from a possibly unaligned address.
static void zxc_copy16(void *dst, const void *src)
Copies exactly 16 bytes as one vector move where the ISA has one.
static uint32_t zxc_checksum(const void *input, const size_t len, const uint64_t seed, const uint8_t hash_method)
Calculates a 32-bit hash for a given input buffer.
static int zxc_block_header_ok(const uint8_t *p)
Block header integrity (FORMAT.md Sec 4.1, 7.1): checksum byte matches, Block Flags and Reserved are ...