code wiki / _hdl_build / nx_vcodec_entropy.nx
nx_vcodec_entropy.nx
buildroot/runtime/_hdl_build/nx_vcodec_entropy.nx
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
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
structs
| none |
consts
| 18 | const K_MAGIC_4242: i64 = 4242 |
| 19 | const K_MAGIC_1103515245: i64 = 1103515245 |
| 20 | const K_MAGIC_12345: i64 = 12345 |
| 21 | const K_MAGIC_4096: i64 = 4096 |
| 23 | const NS: i64 = 257 // 256 (run<<4|size) tokens + EOB(256) |
| 24 | const EOB: i64 = 256 |
| 25 | const STEP: i64 = 16 |
| 26 | const TOTMAX: i64 = 30000 |
functions
| 28 | func 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 |
| 29 | func 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 |
| 31 | func 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 |
| 33 | func wht4(B: *i64, T: *i64) -> i64 called by 1: main |
| 50 | func mdl_update(freq: *i64, tot: *i64, sym: i64) -> i64 |
| 55 | func 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 |
| 58 | func decode_all(dec: *RcDec, dq: *i64, NB: i64, freq: *i64, tot: *i64) -> i64 |
| 88 | func main() -> i64 |