nx_zstd_seqdec.nx
buildroot/runtime/nx_zstd_seqdec.nx
about
nx_zstd_seqdec.nx -- zstd sequence decoding: repeat offsets + the loop.
The last piece of zstd's compressed path, built on RFC 8878 rather than
recollection. Two things here are easy to get subtly wrong and impossible
to notice without the spec.
REPEAT OFFSETS SHIFT WHEN LITERALS_LENGTH IS ZERO. An Offset_Value of 1..3
names one of three remembered offsets -- but ONLY when the sequence carries
literals. When Literals_Length is zero the whole mapping slides by one:
1 means Repeated_Offset2, 2 means Repeated_Offset3, and 3 means
Repeated_Offset1 MINUS ONE BYTE. That last case is not a typo and not a
repeat at all; it is a distinct encoding that exists because
Repeated_Offset1 is unreachable in that position. A decoder missing this
produces correct output until the first zero-literal sequence and wrong
output forever after -- and zero-literal sequences are common in
highly-repetitive data, which is exactly what zstd is good at.
AN OFFSET_VALUE OF 1 WITH LITERALS DOES NOT REORDER THE HISTORY. Every other
repeat case moves the used offset to the front. Reordering on this one too
looks harmless and desynchronises the history from the encoder's.
THE ORDER IS FIXED AND ASYMMETRIC. Extra bits are read offset, then match
length, then literals length. States are updated literals length, then match
length, then offset. The two orders are NOT the same, and all three states
share one bit reader, so any deviation shifts every subsequent read.
genealogy_id: rfc8878_sequence_decoding
lineage_id: nx_zstd_seqdec_v1
license_tier: ORIGINAL
dependencies 5 imports · 3 importers
imports: nx_syscalls.nxnx_zstd_fse.nxnx_zstd_bits.nxnx_zstd_fse_dec.nxnx_zstd_seq.nx
imported by: nx_zstd_block.nxnx_zstd_block_gate.nxnx_zstd_seqdec_gate.nx
structs
| none |
consts
| 37 | const NX_REP_INIT1: i64 = 1 |
| 38 | const NX_REP_INIT2: i64 = 4 |
| 39 | const NX_REP_INIT3: i64 = 8 |
functions
| 45 | func nx_zstd_rep_init(rep: *i64) -> i64 |
| 54 | func nx_zstd_rep_apply(rep: *i64, offset_value: i64, literals_length: i64) -> i64 |
| 97 | func nx_zstd_seq_one(tll: *NxFseTable, tml: *NxFseTable, tof: *NxFseTable, |
| 156 | func nx_zstd_seq_decode_all(tll: *NxFseTable, tml: *NxFseTable, tof: *NxFseTable, called by 2: nx_zstd_block_decompressmain calls 4: sys_mmapnx_zstd_fse_state_initnx_zstd_rep_initnx_zstd_seq_one |