code wiki / _hdl_build / nx_codegen_defect_census.nx

nx_codegen_defect_census.nx

buildroot/runtime/_hdl_build/nx_codegen_defect_census.nx

15605 B395 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic codegen
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_codegen_defect_census.nx

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

main c_puts sys_write sys_mmap sys_openat_wr sys_exit c_run sys_fork sys_dup3 sys_execve sys_exit ↻ sys_mmap ↻ sys_wait4 sys_close c_putn sys_mmap ↻ sys_write ↻ c_slurp sys_openat_rd sys_read sys_close ↻ c_index_lines c_match_at c_parse_store c_match_at ↻ c_parse_reload c_match_at ↻ c_slot_used sys_mmap ↻ c_match_at ↻ c_parse_movabsq c_match_at ↻

structs

none

consts

40const C_MODE_RWX: i64 = 0x1a4 // 0644
41const C_BUFSZ: i64 = 262144 // 256 KiB asm slurp buffer (fk.s ~62 KiB)
42const C_MAXLINES: i64 = 8192 // line-index table capacity
43const C_WIN: i64 = 6 // store->reload lookahead window (lines)
44const C_MAXCONST: i64 = 256 // distinct-constant table capacity

functions

46func 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 }
called by 1: main calls 1: sys_write
47func 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 }
called by 1: main calls 2: sys_mmapsys_write
51func c_run(path: *u8, argv: *i64, envp: *i64, redir_out: i64) -> i64
66func c_slurp(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
81func c_match_at(buf: *u8, i: i64, key: *u8) -> i64
91func c_index_lines(buf: *u8, blen: i64, lstart: *i64) -> i64
called by 1: main
112func c_parse_store(buf: *u8, off: i64, regbuf: *i64) -> i64
called by 1: main calls 1: c_match_at
157func c_parse_reload(buf: *u8, off: i64, regbuf: *i64) -> i64
called by 1: main calls 1: c_match_at
188func c_slot_used(buf: *u8, from: i64, to: i64, k: i64, needle: *u8) -> i64
called by 1: main calls 2: sys_mmapc_match_at
213func c_parse_movabsq(buf: *u8, off: i64) -> i64
called by 1: main calls 1: c_match_at
236func main() -> i64