code wiki / (root) / nx_h264_nc_gate.nx

nx_h264_nc_gate.nx source

↩ module page · 74 lines · 3210 B

1// nx_h264_nc_gate.nx -- REFEREE for nC derivation + coeff_token table select. 2// nc_luma: both(nA3,nB5)->(3+5+1)>>1=4 ; leftonly(nA2)->2 ; toponly(nB6)->6 ; neither->0 3// table: nC0->0 nC1->0 nC2->1 nC3->1 nC4->2 nC7->2 nC8->3 nC=-1->4 4// Every value PRINTED. stdout + knowledge/status/h264_nc_gate.log. Exit 0/1. 5// Sovereign: nx_syscalls + nx_h264_nc. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_h264_nc.nx" 8 9func gp(logfd: i64, s: *u8) -> i64 { 10 var n: i64 = 0 11 while s[n] != (0 as u8) { n = n + 1 } 12 sys_write(1, s, n) 13 if logfd > 0 { sys_write(logfd, s, n) } 14 return 0 15} 16func gn(logfd: i64, v: i64) -> i64 { 17 let bb: *u8 = sys_mmap(28) 18 var m: i64 = v 19 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m } 20 let t: *u8 = sys_mmap(28) 21 var k: i64 = 0 22 if m == 0 { t[0] = 48 as u8; k = 1 } 23 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 var i: i64 = 0 25 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 26 sys_write(1, bb, k) 27 if logfd > 0 { sys_write(logfd, bb, k) } 28 return 0 29} 30 31func main() -> i64 { 32 let logfd: i64 = sys_openat_append("knowledge/status/h264_nc_gate.log\x00" as *u8, 0x1a4) 33 gp(logfd, "H264-NC-GATE (nC derivation + table select)\n\x00" as *u8) 34 var ok: i64 = 1 35 36 let both: i64 = nx_h264_nc_luma(3, 1, 5, 1) 37 let la: i64 = nx_h264_nc_luma(2, 1, 0, 0) 38 let lb: i64 = nx_h264_nc_luma(0, 0, 6, 1) 39 let nn: i64 = nx_h264_nc_luma(0, 0, 0, 0) 40 gp(logfd, " nc: both=\x00" as *u8); gn(logfd, both); gp(logfd, " leftonly=\x00" as *u8); gn(logfd, la); gp(logfd, " toponly=\x00" as *u8); gn(logfd, lb); gp(logfd, " neither=\x00" as *u8); gn(logfd, nn); gp(logfd, " (expect 4 2 6 0)\n\x00" as *u8) 41 if both != 4 { ok = 0 } 42 if la != 2 { ok = 0 } 43 if lb != 6 { ok = 0 } 44 if nn != 0 { ok = 0 } 45 46 let t0: i64 = nx_h264_coeff_token_table(0) 47 let t1: i64 = nx_h264_coeff_token_table(1) 48 let t2: i64 = nx_h264_coeff_token_table(2) 49 let t3: i64 = nx_h264_coeff_token_table(3) 50 let t4: i64 = nx_h264_coeff_token_table(4) 51 let t7: i64 = nx_h264_coeff_token_table(7) 52 let t8: i64 = nx_h264_coeff_token_table(8) 53 let tc: i64 = nx_h264_coeff_token_table(0 - 1) 54 gp(logfd, " table: nC0=\x00" as *u8); gn(logfd, t0); gp(logfd, " 1=\x00" as *u8); gn(logfd, t1); gp(logfd, " 2=\x00" as *u8); gn(logfd, t2); gp(logfd, " 3=\x00" as *u8); gn(logfd, t3); gp(logfd, " 4=\x00" as *u8); gn(logfd, t4); gp(logfd, " 7=\x00" as *u8); gn(logfd, t7); gp(logfd, " 8=\x00" as *u8); gn(logfd, t8); gp(logfd, " -1=\x00" as *u8); gn(logfd, tc); gp(logfd, " (expect 0 0 1 1 2 2 3 4)\n\x00" as *u8) 55 if t0 != 0 { ok = 0 } 56 if t1 != 0 { ok = 0 } 57 if t2 != 1 { ok = 0 } 58 if t3 != 1 { ok = 0 } 59 if t4 != 2 { ok = 0 } 60 if t7 != 2 { ok = 0 } 61 if t8 != 3 { ok = 0 } 62 if tc != 4 { ok = 0 } 63 64 if ok == 1 { 65 gp(logfd, "H264-NC-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 66 if logfd > 0 { sys_close(logfd) } 67 sys_exit(0) 68 return 0 69 } 70 gp(logfd, "H264-NC-GATE result=FAIL verdict=RED\n\x00" as *u8) 71 if logfd > 0 { sys_close(logfd) } 72 sys_exit(1) 73 return 1 74}