code wiki / _hdl_build / nx_pipeline_metrics_test.nx

nx_pipeline_metrics_test.nx source

↩ module page · 52 lines · 3515 B

1// nx_pipeline_metrics_test.nx -- prove the EXCEED over the transcribed pipeline: on a recurring-defect 2// stream, the static (parroted) flow escalates EVERY arc (O(arcs)); the poka-yoke flow escalates only the 3// FIRST of each class (O(distinct classes)) because a guard prevents recurrence. Exit 0 on 8/8. license_tier: ORIGINAL 4 5import "nx_pipeline_metrics.nx" 6import "nx_syscalls.nx" 7 8func mt_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func mt_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 10 11func main() -> i64 { 12 mt_puts("=== PIPELINE EXCEED: poka-yoke vs the transcribed flow ===\n" as *u8) 13 // a recurring-defect arc stream (classes 0,1,2 recur) 14 let cls: *i64 = sys_mmap(8*8) as *i64 15 cls[0]=0; cls[1]=1; cls[2]=0; cls[3]=0; cls[4]=1; cls[5]=2; cls[6]=0; cls[7]=2 16 let N: i64 = 8 17 let stat: i64 = pipe_escalations_static(cls, N) 18 let poka: i64 = pipe_escalations_pokayoke(cls, N) 19 let dist: i64 = pipe_distinct(cls, N) 20 mt_puts(" 8 arcs, 3 distinct defect classes: static(parroted)=" as *u8); mt_num(stat); mt_puts(" escalations poka-yoke=" as *u8); mt_num(poka); mt_puts(" escalations (= distinct classes)\n" as *u8) 21 22 // a LONGER recurring stream shows the divergence: static is linear, poka-yoke plateaus 23 let cls2: *i64 = sys_mmap(8*12) as *i64 24 var z: i64=0; while z<12 { cls2[z]=0; z=z+1 } // 12 arcs, ALL class 0 25 let stat2: i64 = pipe_escalations_static(cls2, 12) 26 let poka2: i64 = pipe_escalations_pokayoke(cls2, 12) 27 mt_puts(" 12 arcs all one class: static=" as *u8); mt_num(stat2); mt_puts(" poka-yoke=" as *u8); mt_num(poka2); mt_puts(" (guard installed once, never recurs)\n" as *u8) 28 29 // metrics: bottleneck (Theory of Constraints) + first-pass yield 30 let times: *i64 = sys_mmap(8*4) as *i64; times[0]=2; times[1]=5; times[2]=1; times[3]=3 31 let bn: i64 = pm_bottleneck(times, 4) 32 let lead: i64 = pm_lead_time(times, 4) 33 34 let r: *i64 = sys_mmap(16*8) as *i64 35 r[0]=0; if stat == 8 { r[0]=1 } // parroted flow re-escalates every arc 36 r[1]=0; if poka == 3 { r[1]=1 } // poka-yoke = distinct classes only 37 r[2]=0; if poka == dist { r[2]=1 } // the floor is the distinct-class count 38 r[3]=0; if poka < stat { r[3]=1 } // the measured EXCEED 39 r[4]=0; if stat2 == 12 { if poka2 == 1 { r[4]=1 } } // linear vs plateau (the divergence proof) 40 r[5]=0; if bn == 1 { r[5]=1 } // bottleneck = stage 1 (slowest) 41 r[6]=0; if lead == 11 { r[6]=1 } // lead time = sum 42 r[7]=0; if pm_first_pass_yield(0) == 1 { if pm_first_pass_yield(1) == 0 { r[7]=1 } } 43 var pass: i64 = 0; var i: i64 = 0 44 while i < 8 { pass = pass + r[i]; i = i + 1 } 45 mt_puts("---- passed " as *u8); mt_num(pass); mt_puts("/8 ----\n" as *u8) 46 if pass == 8 { 47 mt_puts(" EXCEED PROVEN: the transcribed flow is O(arcs) escalations; the poka-yoke flow is O(distinct\n" as *u8) 48 mt_puts(" classes) -- it LEARNS to prevent recurrence (TPS jidoka). That's better than the flow as described.\n" as *u8) 49 sys_exit(0); return 0 50 } 51 mt_puts(" FAIL\n" as *u8); sys_exit(1); return 1 52}