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