code wiki / _hdl_build / nx_mulchain_deep_probe.nx

nx_mulchain_deep_probe.nx source

↩ module page · 42 lines · 2077 B

1// nx_mulchain_deep_probe.nx -- MEASURE before building. Depth-6 cap (a deepen the team can 2// afford). For each constant report the minimal VERIFIED op-count at maxL=6 (or NONE), and we 3// time the whole batch externally to confirm depth-6 stays fast even for large primes (whose 4// true chain is ~30 ops -- the search must FAIL FAST there, ceding them to imul, not hang). 5// license_tier: ORIGINAL 6 7import "nx_mulchain.nx" 8import "nx_syscalls.nx" 9const K_MAGIC_2730: i64 = 2730 10const K_MAGIC_10007: i64 = 10007 11const K_MAGIC_43691: i64 = 43691 12const K_MAGIC_1000003: i64 = 1000003 13const K_MAGIC_715827883: i64 = 715827883 14const K_MAGIC_65535: i64 = 65535 15const K_MAGIC_123457: i64 = 123457 16 17func pr_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 18func pr_puts(s: *u8) -> i64 { sys_write(1, s, pr_slen(s)); return 0 } 19func pr_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 } 20 21func pr_minlen6(c: i64) -> i64 { 22 let op: *i64 = sys_mmap(8*20) as *i64; let a: *i64 = sys_mmap(8*20) as *i64; let b: *i64 = sys_mmap(8*20) as *i64 23 return mulchain_verified(c, 6, op, a, b) 24} 25 26func main() -> i64 { 27 let cs: *i64 = sys_mmap(8*16) as *i64 28 cs[0]=466; cs[1]=683; cs[2]=691; cs[3]=499; cs[4]=719; cs[5]=K_MAGIC_2730; cs[6]=K_MAGIC_10007; cs[7]=K_MAGIC_43691 29 cs[8]=K_MAGIC_1000003; cs[9]=K_MAGIC_715827883; cs[10]=45; cs[11]=100; cs[12]=255; cs[13]=K_MAGIC_65535; cs[14]=K_MAGIC_123457; cs[15]=0 30 pr_puts("constant min_verified_ops @ maxL=6\n" as *u8) 31 var i: i64 = 0 32 while i < 16 { 33 if cs[i] != 0 { 34 pr_puts(" c=" as *u8); pr_num(cs[i]); pr_puts(" -> " as *u8) 35 let L: i64 = pr_minlen6(cs[i]) 36 if L < 0 { pr_puts("NONE@6 (cede to imul)\n" as *u8) } else { pr_num(L); pr_puts(" ops\n" as *u8) } 37 } 38 i = i + 1 39 } 40 sys_exit(0) 41 return 0 42}