code wiki / _hdl_build / nx_codegen_defect_census.nx
nx_codegen_defect_census.nx
buildroot/runtime/_hdl_build/nx_codegen_defect_census.nx
about
nx_codegen_defect_census.nx -- SOVEREIGN read-only codegen defect census for
rung X-PERF-003c1 (the honest BEFORE defect-count the codegen-win rung drives
toward zero).
WHAT IT DOES (no compiler change -- pure read-only analysis):
(1) invokes the REAL sovereign toolchain (fork+execve nx_cc_sovereign.elf on
runtime/_hdl_build/nx_clbg_fannkuch.nx, stdout redirected to /tmp/fk.s) to
regenerate the actual asm for the fannkuch hot loop -- NOT a fixture.
(2) brackets the scan to the fannkuch_redux function body (from "fannkuch_redux:"
to the next function label "fk_puts:") and mechanically tallies, per
redundant-codegen defect class, occurrences in that hot region:
(a) store-then-reload-same-slot : "movq %rR, -K(%rbp)" followed (within a
small window) by "movq -K(%rbp), %rR" -- the value just spilled is read
straight back into the same register (regalloc not coalescing).
(b) dead spill stores : "movq %rR, -K(%rbp)" where slot -K(%rbp) is NEVER
referenced again in the region -> the store is dead (regalloc homing a
temp that nothing consumes).
(c) constant rematerialization : "movabsq $C, ..." emitted more than once
for the same constant C inside the region (no constant pool / no CSE in
the home-everything emitter).
(3) names the SINGLE dominant class by count and pins the originating module:
store-then-reload / dead-spill -> origin=regalloc-home-everything (the
linear-scan register allocator is not firing on this path: every IR temp
gets a unique -NNNN(%rbp) home and round-trips through memory).
constant rematerialization -> origin=peephole-missing-in-emitter (the
instruction emitter rematerializes constants instead of reusing a live
value / constant pool).
(4) prints a single machine-parseable MEASURED line the gate reads back:
CODEGENDEFECT target=fannkuch_hot total_redundant=<N> store_reload=<a>
dead_spill=<b> const_remat=<c> dominant=<class> count=<n> origin=<module>
region_lines=<L> verdict=MEASURED
PASS (enforced by _xperf003c1_gate): census runs on the REAL sovereign-emitted asm,
emits the MEASURED line, and the dominant defect count is > 0 (a real, addressable
ROI target exists). spec: knowledge/specs/2026-06-13-codegen-defect-census.md
genealogy_id: codegen_defect_census
lineage_id: function
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 40 | const C_MODE_RWX: i64 = 0x1a4 // 0644 |
| 41 | const C_BUFSZ: i64 = 262144 // 256 KiB asm slurp buffer (fk.s ~62 KiB) |
| 42 | const C_MAXLINES: i64 = 8192 // line-index table capacity |
| 43 | const C_WIN: i64 = 6 // store->reload lookahead window (lines) |
| 44 | const C_MAXCONST: i64 = 256 // distinct-constant table capacity |
functions
| 46 | func c_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 47 | func c_putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; 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)) as u8;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 } |
| 51 | func c_run(path: *u8, argv: *i64, envp: *i64, redir_out: i64) -> i64 |
| 66 | func c_slurp(path: *u8, buf: *u8, cap: i64) -> i64 |
| 81 | func c_match_at(buf: *u8, i: i64, key: *u8) -> i64 |
| 91 | func c_index_lines(buf: *u8, blen: i64, lstart: *i64) -> i64 called by 1: main |
| 112 | func c_parse_store(buf: *u8, off: i64, regbuf: *i64) -> i64 |
| 157 | func c_parse_reload(buf: *u8, off: i64, regbuf: *i64) -> i64 |
| 188 | func c_slot_used(buf: *u8, from: i64, to: i64, k: i64, needle: *u8) -> i64 |
| 213 | func c_parse_movabsq(buf: *u8, off: i64) -> i64 |
| 236 | func main() -> i64 |