code wiki / _hdl_build / nx_vcodec_832_twin.nx

nx_vcodec_832_twin.nx source

↩ module page · 82 lines · 3724 B

1// nx_vcodec_832_twin.nx -- Encodes deterministic panning content via a shared live path and prints per-frame byte counts for native and wasm compile parity. 2import "nx_gate_base.nx" 3// nx_vcodec_832_twin.nx -- NATIVE twin of vc_832_check.js's wasm lane: encode the IDENTICAL deterministic 4// panning content (integer math kept < 2^26 so the JS side is double-exact; NO noise -- the LCG is not 5// JS-portable) through the SAME live path (vv_enc_rct8, emode 673, qp20, thresh qp*30, chained recon) and 6// print PER-FRAME byte counts. The JS harness prints the same from the freshly built wasm; equality across 7// 30 chained frames = native<->wasm compile parity (the 823-class vet: any recon/MV divergence compounds 8// into different byte counts within a frame or two). license_tier: ORIGINAL 9import "nx_syscalls.nx" 10import "nx_video_codec_wasm.nx" 11const K_MAGIC_2097152: i64 = 2097152 12const K_MAGIC_4096: i64 = 4096 13const K_MAGIC_8192: i64 = 8192 14 15const TW: i64 = 320 16const TH: i64 = 256 17const TQP: i64 = 20 18 19func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 20" as *u8); return ok } 21func gn(v: i64) -> i64 { 22 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 23 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} 24 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 25 26func seedctxe(rctx: *i64, emode: i64, est: *i64, probs: *i64, rcbuf: *u8, t8c: *i64) -> i64 { 27 rctx[0]=emode; rctx[1]=est as i64; rctx[2]=probs as i64; rctx[3]=rcbuf as i64; rctx[4]=t8c as i64 28 rctx[5]=0; rctx[6]=0; rctx[7]=0; return 0 } 29 30// IDENTICAL to the JS fill (no noise): pan pxf px/frame over a modulo texture 31func twin_fill(cur: *u8, f: i64, pxf: i64) -> i64 { 32 let N: i64 = TW*TH; let C: i64 = (TW/2)*(TH/2) 33 let dx: i64 = f * pxf 34 var y: i64 = 0 35 while y < TH { 36 var x: i64 = 0 37 while x < TW { 38 let sx2: i64 = x + dx 39 let v: i64 = 90 + (((sx2 >> 3) * 13 + (y >> 3) * 7) % 61) + (((sx2 * 5 + y * 3) >> 2) % 17) 40 var vv: i64 = v 41 if vv < 0 { vv = 0 } 42 if vv > 255 { vv = 255 } 43 cur[y*TW + x] = vv as u8 44 x = x + 1 45 } 46 y = y + 1 47 } 48 var i: i64 = 0 49 while i < 2*C { cur[N + i] = (120 + (i % 13)) as u8; i = i + 1 } 50 return 0 } 51 52func main() -> i64 { 53 gw("=== nx_vcodec_832_twin: NATIVE per-frame bytes (pan12, emode 673 qp20 thresh qp*30) ===\n" as *u8) 54 let N: i64 = TW*TH; let C2: i64 = (TW/2)*(TH/2); let sz: i64 = N + 2*C2 55 let cur: *u8 = sys_mmap(sz+64) 56 let prevR: *u8 = sys_mmap(sz+64) 57 let recon: *u8 = sys_mmap(sz+64) 58 let wire: *u8 = sys_mmap(K_MAGIC_2097152) 59 let blk: *i64 = sys_mmap(512) as *i64; let mv: *i64 = sys_mmap(128) as *i64 60 let est: *i64 = sys_mmap(64) as *i64; let probs: *i64 = sys_mmap(K_MAGIC_4096) as *i64 61 let rcbuf: *u8 = sys_mmap(K_MAGIC_2097152); let t8c: *i64 = sys_mmap(K_MAGIC_8192) as *i64 62 let rctx: *i64 = sys_mmap(128) as *i64 63 vc_t8_init(t8c) 64 var i: i64 = 0 65 while i < sz { prevR[i] = 0 as u8; i = i + 1 } 66 gw("bytes:" as *u8) 67 var f: i64 = 0 68 while f < 30 { 69 twin_fill(cur, f, 12) 70 var key: i64 = 0 71 if f == 0 { key = 1 } 72 seedctxe(rctx, 673, est, probs, rcbuf, t8c) 73 let nb: i64 = vv_enc_rct8(cur, prevR, recon, TW, TH, TQP, key, TQP*30, wire, K_MAGIC_2097152, blk, mv, rctx) 74 if nb <= 0 { gw(" ENCFAIL\n" as *u8); return 1 } 75 gw(" " as *u8); gn(nb) 76 var j: i64 = 0 77 while j < sz { prevR[j] = recon[j]; j = j + 1 } 78 f = f + 1 79 } 80 gw("\n" as *u8) 81 return 0 82}