code wiki / _hdl_build / nx_vcodec_entropy.nx

nx_vcodec_entropy.nx

buildroot/runtime/_hdl_build/nx_vcodec_entropy.nx

11572 B224 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tooltopic vcodec
docsdependenciesstructsconstsfunctions

about

nx_vcodec_entropy.nx -- R2 (build the codec UP, never settle): the flagged "rANS replaces RLE" entropy upgrade, MEASURED on REAL transform coefficients. The codec's lossy gap to x264 (~2.05x) is partly the entropy stage: fixed run/size RLE codes leave bits on the table vs an adaptive arithmetic coder that spends -log2(p) bits per symbol. We REUSE the proven sovereign range coder (nx_range_coder, patent-free arithmetic coding -- NOT CABAC) with an adaptive frequency model over the (run,size) tokens of real 4x4-WHT-quantized coefficients, mantissa carried as an explicit field. MEASURED: adaptive-arithmetic bytes vs fixed-RLE bytes on a real-ish frame; the entropy stage is LOSSLESS (decoded coefficients == encoded, bit-exact). Neg-control (TAMPER): corrupt a stream byte -> the decoded coefficients MUST change (the bytes are load-bearing -- the win is not fabricated). Positioned vs the x264 yardstick: prior gap 2.05x -> 2.05 * (rc/base) after this stage. HONEST SCOPE: improves ONLY the entropy stage; RDO + trellis-quant + in-loop deblock + the neural path are the bigger remaining levers to actually reach/exceed x264. main() is the SELF-VALIDATING GATE. Evidence -> knowledge/status/vcodec_entropy.log. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_range_coder.nx nx_vcodec_entropy.nx

imports: nx_range_coder.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main wht4 nx_rc_enc_init bitlen mdl_cumlow nx_rc_enc_symbol _rc_enc_renorm _rc_enc_put_byte mdl_update nx_rc_enc_done _rc_enc_put_byte ↻ nx_rc_dec_init decode_all nx_rc_dec_get_target nx_rc_dec_update _rc_dec_renorm mdl_update ↻ ew ewn sys_openat_append

structs

none

consts

18const K_MAGIC_4242: i64 = 4242
19const K_MAGIC_1103515245: i64 = 1103515245
20const K_MAGIC_12345: i64 = 12345
21const K_MAGIC_4096: i64 = 4096
23const NS: i64 = 257 // 256 (run<<4|size) tokens + EOB(256)
24const EOB: i64 = 256
25const STEP: i64 = 16
26const TOTMAX: i64 = 30000

functions

28func ew(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main
29func ewn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(fd,bb,k); return 0 }
called by 1: main
31func bitlen(v: i64) -> i64 { var n: i64=0; var x: i64=v; while x>0 { n=n+1; x=x>>1 } return n }
called by 1: main
33func wht4(B: *i64, T: *i64) -> i64
called by 1: main
50func mdl_update(freq: *i64, tot: *i64, sym: i64) -> i64
called by 2: decode_allmain
55func mdl_cumlow(freq: *i64, sym: i64) -> i64 { var s: i64=0; var i: i64=0; while i<sym { s=s+freq[i]; i=i+1 } return s }
called by 1: main
58func decode_all(dec: *RcDec, dq: *i64, NB: i64, freq: *i64, tot: *i64) -> i64
88func main() -> i64