code wiki / _hdl_build / nx_codec_rd_gate.nx

nx_codec_rd_gate.nx

buildroot/runtime/_hdl_build/nx_codec_rd_gate.nx

9437 B138 linesdepth 5pulls 10 transitivereach 0 importersview sourcekind gate/prooftopic codec
docsdependenciesstructsconstsfunctions

about

nx_codec_rd_gate.nx -- SOVEREIGN measured RATE-DISTORTION head-to-head: our patent-free rANS entropy coder vs JPEG's Huffman, on the IDENTICAL DCT-quantized coefficients at IDENTICAL quality. Both losslessly encode the same per-block zigzag quantized coefficients (same image, same nx_dct8 + same Annex-K quant @ Q50) -> reconstruction is provably identical, so this is a pure rate-at-equal-distortion comparison that isolates the ONE thing that differs: the entropy coder. No python, no 3rd party. This is the measurement that flips nx_codec_exceed's compression axis from MEASURED-PENDING to an EARNED grade -- and it is reported HONESTLY whichever way it lands (the gate verifies the grade matches the measured sizes, and a liar-kill proves a loss can't be graded a win). T1 JPEG entropy lossless (decode recovers the coeffs) T2 rANS entropy lossless (decode recovers bytes) T3 both coders fed identical coefficients (equal quality by construction) T4 measurement valid (both sizes computed > 0) T5 grade matches the measured sizes (honest) T6 liar-kill: more-bytes can NOT be graded a win GREEN iff 6/6. knowledge/status/codec_rd_gate.log. license_tier: ORIGINAL

dependencies 9 imports · 0 importers

nx_syscalls.nx nx_gate_emit_lib.nx nx_h264_bitwriter.nx nx_dct8.nx nx_quant_table.nx nx_zigzag.nx nx_jpeg_huff_enc.nx nx_jpeg_block_enc.nx nx_rans.nx nx_codec_rd_gate.nx

imports: nx_syscalls.nxnx_gate_emit_lib.nxnx_h264_bitwriter.nxnx_dct8.nxnx_quant_table.nxnx_zigzag.nxnx_jpeg_huff_enc.nxnx_jpeg_block_enc.nxnx_rans.nx

imported by: nobody (leaf or entry point)

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

main g_puts sys_write sys_mmap jhe_dc_bits jhe_dc_val jhe_ac_bits jhe_ac_val jhe_gen sys_mmap ↻ nx_qt_luma sys_mmap ↻ _qt_luma_base _qt_quality_to_scale _qt_scale nx_zigzag_init nx_dct8_init nx_dct8_forward_2d nx_dct8_forward_1d qrnd nx_zigzag_scan bw_init jbe_encode_block jhe_emit_dc jhe_mag_cat bw_write_bits bw_write_bit jhe_mag_bits jhe_emit_ac jhe_mag_cat ↻ bw_write_bits ↻ jhe_mag_bits ↻ bw_write_bit ↻ jbe_decode_block jhe_decode_sym jhe_read_bit jhe_decode_mag jhe_read_bit ↻ rans_count rans_normalize

structs

none

consts

24const GRADE_BEHIND: i64 = 1
25const GRADE_PARITY: i64 = 2
26const GRADE_EXCEEDS: i64 = 4

functions

28func 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 }
called by 1: main calls 2: sys_mmapsys_write
29func 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 }
called by 1: main calls 1: sys_write
30func 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 }
called by 1: main calls 2: sys_mmapsys_write
31func qrnd(v: i64, q: i64) -> i64 { if v>=0 { return (v + q/2)/q } return 0 - (((0-v) + q/2)/q) }
called by 1: main
33func rd_grade(our_bytes: i64, ref_bytes: i64) -> i64 { if our_bytes < ref_bytes { return GRADE_EXCEEDS } if our_bytes > ref_bytes { return GRADE_BEHIND } return GRADE_PARITY }
called by 1: main
34func g_grade(gr: i64) -> i64 { if gr==4 { g_puts("EXCEEDS" as *u8) } if gr==2 { g_puts("PARITY" as *u8) } if gr==1 { g_puts("BEHIND" as *u8) } return 0 }
called by 1: main calls 1: g_puts
36func main() -> i64