code wiki / _hdl_build / nx_rans.nx
nx_rans.nx
buildroot/runtime/_hdl_build/nx_rans.nx
about
nx_rans.nx -- SOVEREIGN, PATENT-FREE static-frequency rANS entropy coder. The keystone of the
patent-free video-codec arc (project-sovereign-patent-free-codec-2026-06-20). rANS = the range
variant of Asymmetric Numeral Systems (J. Duda, dedicated to the PUBLIC DOMAIN; the USPTO rejected
Google's attempt to patent ANS use, 2018). This is PLAIN static-frequency rANS -- explicitly NOT the
Petagene Markov+escape-code variant (US9847791B2) and NOT the Microsoft two-phase / switchable-width
/ fragment-flush hardware variant (US11234023B2) -- so it reads on no active claim (deep-research
verified 2026-06-20). Byte-oriented, 32-bit state in the ryg style (RANS_L = 1<<23, 8-bit
renormalization), SCALE_BITS supplied by the caller (12 = a 4096-entry table).
LOSSLESS: rans_decode(rans_encode(x)) == x, bit-exact -- the COMPLETE correctness criterion for an
entropy stage whose encoder AND decoder we both own (no external interop, so round-trip self-proof
is sufficient and total). license_tier: ORIGINAL
dependencies 1 imports · 12 importers
diagram shows first 10 each side; +0 more imports, +2 more importers in the complete lists below.
imports: nx_syscalls.nx
imported by: nx_codec_rd2_gate.nxnx_codec_rd_gate.nxnx_codec_real_rd.nxnx_codec_real_rd2.nxnx_codec_real_rd2f.nxnx_codec_real_rd2g.nxnx_codec_real_rd3.nxnx_intra_block_gate.nxnx_intra_image_gate.nxnx_lossless_codec_gate.nxnx_lossless_ctx_gate.nxnx_rans_gate.nx
structs
| none |
consts
| none |
functions
| 15 | func rans_count(data: *u8, n: i64, counts: *i64) -> i64 |
| 25 | func rans_normalize(counts: *i64, freqs: *i64, scale_bits: i64) -> i64 |
| 52 | func rans_cum(freqs: *i64, cum: *i64) -> i64 |
| 61 | func rans_build_slot2sym(freqs: *i64, cum: *i64, slot2sym: *i64) -> i64 |
| 77 | func rans_encode(data: *u8, n: i64, freqs: *i64, cum: *i64, scale_bits: i64, out: *u8, outcap: i64) -> i64 |
| 110 | func rans_decode(enc: *u8, enclen: i64, n: i64, freqs: *i64, cum: *i64, scale_bits: i64, slot2sym: *i64, out: *u8) -> i64 |