code wiki / _hdl_build / nx_svc_gate.nx

nx_svc_gate.nx source

↩ module page · 48 lines · 2943 B

1// nx_svc_gate.nx -- proves the sovereign SVC temporal layers (nx_svc). Native, fast. 2import "nx_syscalls.nx" 3import "nx_gate_emit_lib.nx" 4import "nx_svc.nx" 5import "nx_gate_verdict.nx" 6 7func main() -> i64 { 8 g_puts("nx_svc gate (dyadic temporal SVC layers)\n" as *u8) 9 var pass: i64 = 0; var total: i64 = 0 10 let NL: i64 = 3 11 12 // 1) dyadic layer pattern over a period: [0,2,1,2,0,2,1,2] 13 g_puts(" [measure] layers n=0..7: " as *u8) 14 var ok1: i64 = 1 15 let want: *i64 = sys_mmap(8*8) as *i64 16 want[0]=0; want[1]=2; want[2]=1; want[3]=2; want[4]=0; want[5]=2; want[6]=1; want[7]=2 17 var i: i64 = 0 18 while i < 8 { let l: i64 = svc_temporal_id(i, NL); g_pn(l); g_puts(" " as *u8); if l != want[i] { ok1 = 0 } i = i + 1 } 19 g_puts("\n" as *u8) 20 pass = pass + g_check("dyadic temporal pattern [0,2,1,2,...]" as *u8, ok1); total=total+1 21 22 // 2) a weak link (max_layer 0) decodes only base frames {0,4} = 1/4 fps; good link (max 2) decodes all 23 var base_cnt: i64 = 0; var all_cnt: i64 = 0 24 i = 0; while i < 8 { if svc_can_decode(i, NL, 0) == 1 { base_cnt = base_cnt + 1 } if svc_can_decode(i, NL, 2) == 1 { all_cnt = all_cnt + 1 } i = i + 1 } 25 pass = pass + g_check("weak link decodes base only (2/8), good link all (8/8)" as *u8, (base_cnt == 2) & (all_cnt == 8)); total=total+1 26 27 // 3) fps fractions: 1/4, 2/4, 4/4 of the period (period = 4) 28 pass = pass + g_check("fps fractions per layer: 1,2,4 of period 4" as *u8, (svc_frames_per_period(0)==1) & (svc_frames_per_period(1)==2) & (svc_frames_per_period(2)==4) & (svc_period(NL)==4)); total=total+1 29 30 // 4) reference INVARIANT: a base frame referencing a higher-layer frame is ILLEGAL (drop-safe); base->base ok 31 var r4: i64 = 1 32 if svc_valid_ref(0, 4, NL) != 1 { r4 = 0 } // base(0) -> base(4): legal (same layer) 33 if svc_valid_ref(0, 2, NL) != 1 { r4 = 0 } // base(0) -> enhancement(2,layer1): legal (refs a LOWER layer) 34 if svc_valid_ref(2, 4, NL) == 1 { r4 = 0 } // enhancement(2,layer1) -> base(4): ILLEGAL (base would orphan if layer1 dropped) 35 if svc_valid_ref(4, 2, NL) == 1 { r4 = 0 } // future ref illegal 36 pass = pass + g_check("reference invariant: kept frames never reference droppable higher layers" as *u8, r4); total=total+1 37 38 g_puts("---- svc gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 39 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 40 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 41 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 42 let ctr__dry: *i64 = gv_ctr() 43 ctr__dry[0] = pass 44 ctr__dry[1] = total 45 let rc__dry: i64 = gv_verdict("SVC-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 46 sys_exit(rc__dry) 47 return rc__dry 48}