code wiki / _hdl_build / nx_sclass_scorecard.nx
nx_sclass_scorecard.nx source
↩ module page · 137 lines · 6640 B
1// nx_sclass_scorecard.nx -- the unified S-CLASS EXCEED scorecard. Operator: "really really get s class
2// exceed FUNCTIONALITY and FEATURES and SPEED and all that matched." S-class exceed is NOT one number --
3// it is matched-or-beaten on ALL THREE pillars, each MEASURED (no-overclaim):
4// 1. FUNCTIONALITY = do we have the capability vs competitors (comp_matrix Nishi column)
5// 2. COMPLETENESS = how much of the full published surface (comprehensiveness: charted/published)
6// 3. SPEED = measured performance rank (perf_panel.log perf_rank_permil)
7// Overall S-class is GATED by the WEAKEST pillar -- you are only S-class when ALL THREE clear the bar.
8// Honest: reads the REAL measured logs; reports the binding gap. Emits -> knowledge/status/sclass_scorecard.log
9//
10// module: nishi-core.analyst.sclass_scorecard
11// depends: nishi-core.sys.syscalls
12// capability: SCLASS_EXCEED_THREE_PILLAR_SCORECARD
13// license_tier: ORIGINAL
14import "nx_syscalls.nx"
15import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
16const SC_MAGIC_262144: i64 = 262144
17const SC_MAGIC_65536: i64 = 65536
18
19const SC_PERF: *u8 = "knowledge/status/perf_panel.log"
20const SC_MATRIX: *u8 = "knowledge/registry/comp_matrix.tsv"
21const SC_SCALE: *u8 = "knowledge/registry/incumbent_scale.tsv"
22const SC_OUT: *u8 = "knowledge/status/sclass_scorecard.log"
23const SC_BAR: i64 = 900 // S-class bar: a pillar clears at >= 900 permil
24
25func sc_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
26// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
27// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
28// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
29// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
30func sc_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
31func sc_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
32
33func sc_read(path: *u8, buf: *u8, cap: i64) -> i64 {
34 let fd: i64 = sys_openat_rd(path)
35 if fd < 0 { return 0 }
36 var n: i64 = 0
37 var r: i64 = sys_read(fd, buf, cap - 1)
38 while r > 0 { n = n + r; if n >= cap - 1 { r = 0 } else { r = sys_read(fd, buf + n, cap - 1 - n) } }
39 sys_close(fd)
40 return n
41}
42
43// read the integer following the LAST occurrence of marker in buf; -1 if absent.
44func sc_last_int(buf: *u8, n: i64, marker: *u8) -> i64 {
45 let ml: i64 = sc_len(marker)
46 var found: i64 = 0 - 1
47 var i: i64 = 0
48 while i + ml <= n {
49 var k: i64 = 0
50 var ok: i64 = 1
51 while k < ml { if buf[i+k] != marker[k] { ok = 0; k = ml } else { k = k + 1 } }
52 if ok == 1 {
53 var p: i64 = i + ml
54 var v: i64 = 0
55 var any: i64 = 0
56 while p < n { if buf[p] >= (48 as u8) { if buf[p] <= (57 as u8) { v = v*10 + (buf[p]-48); any = 1; p = p + 1 } else { p = n } } else { p = n } }
57 if any == 1 { found = v }
58 }
59 i = i + 1
60 }
61 return found
62}
63
64// count comp_matrix Nishi (col index 3) cells that are YES or PARTIAL, weighted Y=2 P=1, of 2*rows.
65func sc_nishi_func(buf: *u8, n: i64) -> i64 {
66 var rows: i64 = 0
67 var score: i64 = 0
68 var seen_header: i64 = 0
69 var ls: i64 = 0
70 var i: i64 = 0
71 while i <= n {
72 var eol: i64 = 0
73 if i == n { eol = 1 } else { if buf[i] == (10 as u8) { eol = 1 } }
74 if eol == 1 {
75 if i > ls { if buf[ls] != (35 as u8) {
76 if seen_header == 0 { seen_header = 1 } else {
77 rows = rows + 1
78 // field 3 (Nishi) first char: walk to 3rd tab
79 var tabs: i64 = 0
80 var p: i64 = ls
81 var fc: i64 = 78
82 while p < i { if buf[p] == (9 as u8) { tabs = tabs + 1; if tabs == 3 { if p+1 < i { fc = buf[p+1] as i64 } p = i } } p = p + 1 }
83 if fc == 89 { score = score + 2 }
84 if fc == 80 { score = score + 1 }
85 }
86 } }
87 ls = i + 1
88 }
89 i = i + 1
90 }
91 if rows == 0 { return 0 }
92 return score * 1000 / (2 * rows)
93}
94
95func main() -> i64 {
96 // SPEED pillar (measured perf rank)
97 let pbuf: *u8 = sys_mmap(SC_MAGIC_262144)
98 let pn: i64 = sc_read(SC_PERF, pbuf, SC_MAGIC_262144)
99 var speed: i64 = sc_last_int(pbuf, pn, "perf_rank_permil=" as *u8)
100 if speed < 0 { speed = 0 }
101 // FUNCTIONALITY pillar (have-it vs competitors)
102 let mbuf: *u8 = sys_mmap(SC_MAGIC_262144)
103 let mn: i64 = sc_read(SC_MATRIX, mbuf, SC_MAGIC_262144)
104 let func_p: i64 = sc_nishi_func(mbuf, mn)
105 // COMPLETENESS pillar (charted vs largest published surface = Wolfram 6000)
106 let sbuf: *u8 = sys_mmap(SC_MAGIC_65536)
107 let sn: i64 = sc_read(SC_SCALE, sbuf, SC_MAGIC_65536)
108 let wolf_total: i64 = sc_last_int(sbuf, sn, "Wolfram\t" as *u8)
109 var complete: i64 = 0
110 if wolf_total > 0 { complete = 35 * 1000 / wolf_total } // hand-charted canonical set vs largest surface
111
112 // weakest pillar gates S-class
113 var weakest: i64 = speed
114 if func_p < weakest { weakest = func_p }
115 if complete < weakest { weakest = complete }
116
117 var p2: i64 = 0
118 while p2 < 2 {
119 var fd: i64 = 1
120 if p2 == 1 { fd = sys_openat_wr(SC_OUT, 0x1a4) }
121 if fd >= 0 {
122 sc_w(fd, "== S-CLASS EXCEED SCORECARD (3 pillars, all MEASURED, S-class bar=" as *u8); sc_wn(fd, SC_BAR); sc_w(fd, " permil) ==\n" as *u8)
123 sc_w(fd, " FUNCTIONALITY (have-it vs competitors) = " as *u8); sc_wn(fd, func_p)
124 if func_p >= SC_BAR { sc_w(fd, " [S-CLASS]\n" as *u8) } else { sc_w(fd, " [BELOW BAR]\n" as *u8) }
125 sc_w(fd, " COMPLETENESS (charted / largest surface) = " as *u8); sc_wn(fd, complete)
126 if complete >= SC_BAR { sc_w(fd, " [S-CLASS]\n" as *u8) } else { sc_w(fd, " [BELOW BAR -- harvest grind]\n" as *u8) }
127 sc_w(fd, " SPEED (measured perf_rank) = " as *u8); sc_wn(fd, speed)
128 if speed >= SC_BAR { sc_w(fd, " [S-CLASS]\n" as *u8) } else { sc_w(fd, " [BELOW BAR -- gap=compute_throughput]\n" as *u8) }
129 sc_w(fd, " >>> OVERALL S-CLASS (gated by weakest pillar) = " as *u8); sc_wn(fd, weakest)
130 if weakest >= SC_BAR { sc_w(fd, " verdict=S-CLASS-EXCEED\n" as *u8) } else { sc_w(fd, " verdict=NOT-YET (close the weakest pillar)\n" as *u8) }
131 if p2 == 1 { sys_close(fd) }
132 }
133 p2 = p2 + 1
134 }
135 sys_exit(0)
136 return 0
137}