code wiki / _hdl_build / nx_lossless_ctx_gate.nx
nx_lossless_ctx_gate.nx
buildroot/runtime/_hdl_build/nx_lossless_ctx_gate.nx
about
nx_lossless_ctx_gate.nx -- CONTEXT-MODELED lossless codec (the rung to close/beat FFV1): Paeth predictor +
residuals split into 8 CONTEXTS by local activity (|a-c|+|c-b| neighbor gradient), each context entropy-coded
with its OWN rANS table. Smooth regions (low activity) -> a context sharply peaked at 0 -> far cheaper than a
single global table. Bit-exact by construction (decode recomputes the context from already-decoded neighbors).
Patent-free: Paeth=PNG/PD, activity-context = JPEG-LS/FFV1-era technique (FFV1 itself is patent-free), rANS=PD.
Measured vs single-context (144362B), PNG (178419B), FFV1 (108111B). license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_gate_emit_lib.nxnx_rans.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
| none |
functions
| 11 | func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" 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(1,bb,k); return 0 } |
| 12 | func g_w(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 } |
| 13 | func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; 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 } |
| 14 | func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v } |
| 15 | func paeth(a: i64, b: i64, c: i64) -> i64 { let p: i64=a+b-c; let pa: i64=iabs(p-a); let pb: i64=iabs(p-b); let pc: i64=iabs(p-c); if pa<=pb { if pa<=pc { return a } return c } if pb<=pc { return b } return c } calls 1: iabs |
| 17 | func med(a: i64, b: i64, c: i64) -> i64 { var mx: i64=a; if b>a { mx=b } var mn: i64=a; if b<a { mn=b } if c>=mx { return mn } if c<=mn { return mx } return a+b-c } called by 1: main |
| 20 | func ctxof(act: i64) -> i64 { if act==0 { return 0 } if act<=2 { return 1 } if act<=5 { return 2 } if act<=10 { return 3 } if act<=20 { return 4 } if act<=40 { return 5 } if act<=80 { return 6 } return 7 } called by 1: main |
| 22 | func main() -> i64 |