nx_zstd_seq.nx
buildroot/runtime/nx_zstd_seq.nx
about
nx_zstd_seq.nx -- Zstandard sequences: header, code tables, execution.
The last zstd layer. A sequence is a triple (literal_length, match_length,
offset): copy N literals, then copy M bytes from earlier in the OUTPUT. The
literals come from nx_zstd_lit; this turns them plus the sequence list into
the decompressed bytes.
THE MATCH COPY MUST BE BYTE BY BYTE. An offset SMALLER than the match length
is legal and extremely common -- it is how zstd encodes runs, and the copy
deliberately reads bytes it wrote moments earlier in the same operation.
A bulk move that reads the whole source region up front produces the wrong
bytes for every position past the first `offset` of them. offset=1 with
match_length=100 is a 100-byte run of one value; a bulk copy gives one byte
and 99 of whatever was already there.
THE SEQUENCE COUNT IS 1, 2 OR 3 BYTES with a discontinuous encoding: below
128 it is the byte itself, below 255 it is a two-byte form biased by 0x8000,
and exactly 255 escapes to a three-byte form biased by 0x7F00. Treating it
as a plain varint mis-sizes the header and every table after it.
THE LITERAL AND MATCH LENGTH CODES ARE BASELINE PLUS EXTRA BITS, and the
baselines are NOT uniform -- the first 16 literal-length codes are the value
itself, then the table jumps. Match lengths start at 3, not 0, because a
match shorter than 3 is never worth encoding.
genealogy_id: zstandard_rfc8878_sequences
lineage_id: nx_zstd_seq_v1
license_tier: ORIGINAL
dependencies 1 imports · 5 importers
imports: nx_syscalls.nx
imported by: nx_zstd_block.nxnx_zstd_block_gate.nxnx_zstd_seq_gate.nxnx_zstd_seqdec.nxnx_zstd_seqdec_gate.nx
structs
| none |
consts
| 32 | const NX_SEQ_MODE_PREDEFINED: i64 = 0 |
| 33 | const NX_SEQ_MODE_RLE: i64 = 1 |
| 34 | const NX_SEQ_MODE_FSE: i64 = 2 |
| 35 | const NX_SEQ_MODE_REPEAT: i64 = 3 |
| 37 | const NX_SEQ_FLD_COUNT: i64 = 0 |
| 38 | const NX_SEQ_FLD_LLMODE: i64 = 1 |
| 39 | const NX_SEQ_FLD_OFMODE: i64 = 2 |
| 40 | const NX_SEQ_FLD_MLMODE: i64 = 3 |
| 41 | const NX_SEQ_FLD_HDRLEN: i64 = 4 |
functions
| 43 | func nx_seq_at(d: *u8, i: i64) -> i64 { return (d[i] as i64) & 255 } called by 1: nx_zstd_seq_header |
| 47 | func nx_zstd_seq_header(d: *u8, n: i64, off: i64, fld: *i64) -> i64 |
| 93 | func nx_zstd_ll_base(code: i64) -> i64 |
| 119 | func nx_zstd_ll_extra(code: i64) -> i64 |
| 144 | func nx_zstd_ml_base(code: i64) -> i64 |
| 171 | func nx_zstd_ml_extra(code: i64) -> i64 |
| 197 | func nx_zstd_of_base(code: i64) -> i64 |
| 203 | func nx_zstd_of_extra(code: i64) -> i64 |
| 216 | func nx_zstd_seq_execute(lit: *u8, lit_len: i64, seqs: *i64, nseq: i64, |