code wiki / _hdl_build / nx_vcodec_msu_ours8.nx
nx_vcodec_msu_ours8.nx source
↩ module page · 87 lines · 4484 B
1import "nx_gate_base.nx"
2// nx_vcodec_msu_ours8.nx -- EXACT RD points for OUR codec at the vcv-8 GENTLE-DEBLOCK config (emode 681 =
3// 169 | 512 = rc+rich-intra+sig-map+P_8x8 partition + gentle in-loop deblock bit9) on /tmp/seq.y4m, for the MSU
4// head-to-head. Identical to nx_vcodec_msu_ours except emode carries bit9 (gentle deblock c1=qp/2+2 instead of the
5// over-aggressive qp*1.5+2). Emits OURS/OURSINTRA lines (same labels) so msu_bdrate.sh scores it unchanged. The
6// BD-rate DELTA vs nx_vcodec_msu_ours (full deblock, emode 169) = the exact measured deblock win. license: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_video_codec_wasm.nx"
9const K_MAGIC_4194304: i64 = 4194304
10const K_MAGIC_5120: i64 = 5120
11
12const SW: i64 = 352
13const SH: i64 = 288
14const NF: i64 = 48
15const SKIPMUL: i64 = 30
16
17func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
18" as *u8); return ok }
19func gn(v: i64) -> i64 {
20 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m}
21 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}
22 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
23func cpb(d: *u8, s: *u8, n: i64) -> i64 { var i: i64=0; while i<n { d[i]=s[i]; i=i+1 } return 0 }
24
25func frames(yuv: *u8, hi: i64, total: i64, fp: *i64, fdata: i64) -> i64 {
26 var nf: i64=0; var p: i64=hi
27 while nf < NF { if p>=total { break }
28 var q: i64=p; while q<total { if (yuv[q]&0xff)==10 { break } q=q+1 } q=q+1
29 if q+fdata>total { break } fp[nf]=(yuv as i64)+q; nf=nf+1; p=q+fdata }
30 return nf }
31
32func run(fp: *i64, qp: i64, emode: i64, sz: i64, allkey: i64) -> i64 {
33 return runpq(fp, qp, qp, emode, sz, allkey) }
34func runpq(fp: *i64, kq: i64, pq: i64, emode: i64, sz: i64, allkey: i64) -> i64 {
35 let prevE: *u8=sys_mmap(sz+64); let reconE: *u8=sys_mmap(sz+64)
36 let wire: *u8=sys_mmap(K_MAGIC_4194304); let blk: *i64=sys_mmap(512) as *i64; let mv: *i64=sys_mmap(128) as *i64
37 let est: *i64=sys_mmap(64) as *i64; let probs: *i64=sys_mmap(32*8) as *i64; let rcbuf: *u8=sys_mmap(K_MAGIC_4194304)
38 let t8c: *i64=sys_mmap(K_MAGIC_5120) as *i64; let rctx: *i64=sys_mmap(64) as *i64
39 vc_t8_init(t8c)
40 var z: i64=0; while z<sz { prevE[z]=0 as u8; z=z+1 }
41 rctx[1]=est as i64; rctx[2]=probs as i64; rctx[3]=rcbuf as i64; rctx[4]=t8c as i64; rctx[5]=0; rctx[6]=0; rctx[7]=0
42 var keyB: i64=0; var pB: i64=0; var sseY: i64=0; var keySSE: i64=0; var npix: i64=0
43 let NL: i64=SW*SH
44 var f: i64=0
45 while f < NF {
46 let cur: *u8=fp[f] as *u8
47 var key: i64=0; if f==0 { key=1 } if allkey==1 { key=1 }
48 var fq: i64 = kq; if key==0 { fq = pq }
49 rctx[0]=emode
50 let nb: i64 = vv_enc_rct8(cur, prevE, reconE, SW, SH, fq, key, fq*SKIPMUL, wire, K_MAGIC_4194304, blk, mv, rctx)
51 if nb<=0 { gw("enc fail\n" as *u8); return 1 }
52 if f==0 { keyB=nb } else { pB=pB+nb }
53 var pxi: i64=0; var fsse: i64=0
54 while pxi<NL { let d: i64=(reconE[pxi]&0xff)-(cur[pxi]&0xff); fsse=fsse+d*d; pxi=pxi+1 }
55 sseY=sseY+fsse; if f==0 { keySSE=fsse }
56 npix=npix+NL
57 cpb(prevE, reconE, sz)
58 f=f+1
59 }
60 if allkey==1 { gw("OURSINTRA kq=" as *u8) } else { gw("OURS kq=" as *u8) }
61 gn(kq); gw(" pq=" as *u8); gn(pq); gw(" total=" as *u8); gn(keyB+pB); gw(" key=" as *u8); gn(keyB)
62 gw(" ptot=" as *u8); gn(pB); gw(" sseY=" as *u8); gn(sseY); gw(" keySSE=" as *u8); gn(keySSE)
63 gw(" npix=" as *u8); gn(npix); gw("\n" as *u8)
64 return 0 }
65
66func main() -> i64 {
67 let box: *i64 = sys_mmap(16) as *i64
68 let yuv: *u8 = sys_read_file("/tmp/seq.y4m" as *u8, box)
69 if (yuv as i64)==0 { gw("cannot read /tmp/seq.y4m -> RED\n" as *u8); return 1 }
70 let total: i64=box[0]
71 var hi: i64=0; while hi<total { if (yuv[hi]&0xff)==10 { break } hi=hi+1 } hi=hi+1
72 let C2: i64=(SW/2)*(SH/2); let fdata: i64=SW*SH+2*C2; let sz: i64=fdata
73 let fp: *i64=sys_mmap(128*8) as *i64
74 let nf: i64=frames(yuv, hi, total, fp, fdata)
75 if nf < NF { gw("too few frames -> RED\n" as *u8); return 1 }
76 run(fp, 8, 681, sz, 0)
77 run(fp, 16, 681, sz, 0)
78 run(fp, 24, 681, sz, 0)
79 run(fp, 32, 681, sz, 0)
80 run(fp, 44, 681, sz, 0)
81 run(fp, 8, 681, sz, 1)
82 run(fp, 16, 681, sz, 1)
83 run(fp, 24, 681, sz, 1)
84 run(fp, 32, 681, sz, 1)
85 run(fp, 44, 681, sz, 1)
86 gw("MSU_OURS8: DONE\n" as *u8)
87 return 0 }