code wiki / (root) / nx_h264_ctfull_gate.nx

nx_h264_ctfull_gate.nx source

↩ module page · 116 lines · 3897 B

1// nx_h264_ctfull_gate.nx -- validate the FULL 0<=nC<2 coeff_token table. 2// (a) count = 62 (all valid (tc,t1): (0,0)+ tc1..16 x t1 0..min(tc,3)) 3// (b) PREFIX-FREE over all 62 (catches transcription collisions) 4// (c) COVERAGE: every valid (tc,t1) present 5// (d) ROUND-TRIP every entry: encode->decode->recover 6// stdout + knowledge/status/h264_ctfull_gate.log. Exit 0/1. 7// Sovereign: nx_syscalls + nx_h264_bits + nx_h264_bitwriter + nx_h264_coeff_token. 8// license_tier: ORIGINAL 9import "nx_syscalls.nx" 10import "nx_h264_bits.nx" 11import "nx_h264_bitwriter.nx" 12import "nx_h264_coeff_token.nx" 13 14func gp(logfd: i64, s: *u8) -> i64 { 15 var n: i64 = 0 16 while s[n] != (0 as u8) { n = n + 1 } 17 sys_write(1, s, n) 18 if logfd > 0 { sys_write(logfd, s, n) } 19 return 0 20} 21func gn(logfd: i64, v: i64) -> i64 { 22 let bb: *u8 = sys_mmap(28) 23 var m: i64 = v 24 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m } 25 let t: *u8 = sys_mmap(28) 26 var k: i64 = 0 27 if m == 0 { t[0] = 48 as u8; k = 1 } 28 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 29 var i: i64 = 0 30 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 31 sys_write(1, bb, k) 32 if logfd > 0 { sys_write(logfd, bb, k) } 33 return 0 34} 35 36func main() -> i64 { 37 let logfd: i64 = sys_openat_append("knowledge/status/h264_ctfull_gate.log\x00" as *u8, 0x1a4) 38 gp(logfd, "H264-CTFULL-GATE (full nC<2 coeff_token)\n\x00" as *u8) 39 var ok: i64 = 1 40 let ln: *i64 = sys_mmap(80 * 8) as *i64 41 let cd: *i64 = sys_mmap(80 * 8) as *i64 42 let tc: *i64 = sys_mmap(80 * 8) as *i64 43 let to: *i64 = sys_mmap(80 * 8) as *i64 44 let n: i64 = ct_table_nc01(ln, cd, tc, to) 45 gp(logfd, " count=\x00" as *u8); gn(logfd, n); gp(logfd, " (expect 62)\n\x00" as *u8) 46 if n != 62 { ok = 0 } 47 48 // prefix-free 49 var pf: i64 = 1 50 var i: i64 = 0 51 while i < n { 52 var j: i64 = 0 53 while j < n { 54 if i != j { 55 if ln[i] <= ln[j] { 56 if (cd[j] >> (ln[j] - ln[i])) == cd[i] { pf = 0 } 57 } 58 } 59 j = j + 1 60 } 61 i = i + 1 62 } 63 gp(logfd, " prefix_free=\x00" as *u8); gn(logfd, pf); gp(logfd, " (expect 1)\n\x00" as *u8) 64 if pf != 1 { ok = 0 } 65 66 // coverage 67 var cov: i64 = 1 68 var t: i64 = 0 69 while t <= 16 { 70 var u: i64 = 0 71 var umax: i64 = t 72 if umax > 3 { umax = 3 } 73 if t == 0 { umax = 0 } 74 while u <= umax { 75 var found: i64 = 0 76 var z: i64 = 0 77 while z < n { if tc[z] == t { if to[z] == u { found = 1 } } z = z + 1 } 78 if found == 0 { cov = 0 } 79 u = u + 1 80 } 81 t = t + 1 82 } 83 gp(logfd, " coverage=\x00" as *u8); gn(logfd, cov); gp(logfd, " (expect 1)\n\x00" as *u8) 84 if cov != 1 { ok = 0 } 85 86 // round-trip all 87 var rt: i64 = 1 88 i = 0 89 while i < n { 90 let buf: *u8 = sys_mmap(8) 91 let bw: *BitWriter = sys_mmap(NX_BW_BYTES) as *BitWriter 92 bw_init(bw, buf, 8) 93 nx_coeff_token_encode(bw, tc[i], to[i]) 94 let br: *BitReader = sys_mmap(NX_BR_BYTES) as *BitReader 95 br_init(br, buf, 8) 96 let out: *i64 = sys_mmap(16) as *i64 97 let d: i64 = nx_coeff_token_decode(br, out) 98 if d != 1 { rt = 0 } 99 if out[0] != tc[i] { rt = 0 } 100 if out[1] != to[i] { rt = 0 } 101 i = i + 1 102 } 103 gp(logfd, " round_trip_all=\x00" as *u8); gn(logfd, rt); gp(logfd, " (expect 1)\n\x00" as *u8) 104 if rt != 1 { ok = 0 } 105 106 if ok == 1 { 107 gp(logfd, "H264-CTFULL-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 108 if logfd > 0 { sys_close(logfd) } 109 sys_exit(0) 110 return 0 111 } 112 gp(logfd, "H264-CTFULL-GATE result=FAIL verdict=RED\n\x00" as *u8) 113 if logfd > 0 { sys_close(logfd) } 114 sys_exit(1) 115 return 1 116}