nx_h264_pmb_gate.nx source
↩ module page · 74 lines · 2801 B
1// nx_h264_pmb_gate.nx -- gate the P-macroblock type layer (Tables 7-13 / 7-18).
2// kinds, partition counts, sub-partition counts, ref-coding, + a composite MV count.
3// Exit 0/1. Log knowledge/status/h264_pmb_gate.log. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5import "nx_h264_pmb.nx"
6
7func gp(fd: i64, s: *u8) -> i64 {
8 var n: i64 = 0
9 while s[n] != (0 as u8) { n = n + 1 }
10 sys_write(1, s, n); if fd > 0 { sys_write(fd, s, n) }
11 return 0
12}
13func gn(fd: i64, v: i64) -> i64 {
14 let bb: *u8 = sys_mmap(28); var m: i64 = v
15 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if fd > 0 { sys_write(fd, "-\x00" as *u8, 1) } m = 0 - m }
16 let t: *u8 = sys_mmap(28); var k: i64 = 0
17 if m == 0 { t[0] = 48 as u8; k = 1 }
18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 var i: i64 = 0
20 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
21 sys_write(1, bb, k); if fd > 0 { sys_write(fd, bb, k) }
22 return 0
23}
24
25func main() -> i64 {
26 let fd: i64 = sys_openat_append("knowledge/status/h264_pmb_gate.log\x00" as *u8, 0x1a4)
27 gp(fd, "H264-PMB-GATE\n\x00" as *u8)
28 var ok: i64 = 1
29
30 // kinds
31 if nx_h264_pmb_kind(0) != 0 { ok = 0 }
32 if nx_h264_pmb_kind(4) != 4 { ok = 0 }
33 if nx_h264_pmb_kind(5) != (0 - 1) { ok = 0 }
34 if nx_h264_pmb_kind(25) != (0 - 1) { ok = 0 }
35 // nparts
36 if nx_h264_pmb_nparts(0) != 1 { ok = 0 }
37 if nx_h264_pmb_nparts(1) != 2 { ok = 0 }
38 if nx_h264_pmb_nparts(2) != 2 { ok = 0 }
39 if nx_h264_pmb_nparts(3) != 4 { ok = 0 }
40 if nx_h264_pmb_nparts(4) != 4 { ok = 0 }
41 // is_8x8
42 if nx_h264_pmb_is_8x8(0) != 0 { ok = 0 }
43 if nx_h264_pmb_is_8x8(3) != 1 { ok = 0 }
44 if nx_h264_pmb_is_8x8(4) != 1 { ok = 0 }
45 // codes_ref
46 if nx_h264_pmb_codes_ref(0) != 1 { ok = 0 }
47 if nx_h264_pmb_codes_ref(3) != 1 { ok = 0 }
48 if nx_h264_pmb_codes_ref(4) != 0 { ok = 0 }
49 // sub-parts
50 if nx_h264_psub_nparts(0) != 1 { ok = 0 }
51 if nx_h264_psub_nparts(1) != 2 { ok = 0 }
52 if nx_h264_psub_nparts(2) != 2 { ok = 0 }
53 if nx_h264_psub_nparts(3) != 4 { ok = 0 }
54
55 // composite: P_8x8 with sub_types [0,1,2,3] -> 1+2+2+4 = 9 sub-MVs
56 let subs: *i64 = sys_mmap(8 * 8) as *i64
57 subs[0]=0; subs[1]=1; subs[2]=2; subs[3]=3
58 var total: i64 = 0
59 var i: i64 = 0
60 while i < 4 { total = total + nx_h264_psub_nparts(subs[i]); i = i + 1 }
61 gp(fd, " P_8x8 sub[0,1,2,3] total sub-MVs=\x00" as *u8); gn(fd, total); gp(fd, " (expect 9)\n\x00" as *u8)
62 if total != 9 { ok = 0 }
63
64 if ok == 1 {
65 gp(fd, "H264-PMB-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8)
66 if fd > 0 { sys_close(fd) }
67 sys_exit(0)
68 return 0
69 }
70 gp(fd, "H264-PMB-GATE result=FAIL verdict=RED\n\x00" as *u8)
71 if fd > 0 { sys_close(fd) }
72 sys_exit(1)
73 return 1
74}