nx_x86_regalloc_use_gate.nx
buildroot/runtime/nx_x86_regalloc_use_gate.nx
about
nx_x86_regalloc_use_gate.nx -- GATE for LN7 "backend consumes its register allocation"
(lang.plan rung LN7, watch symbol x86_use_regalloc in nx_x86_64_ctx.nx).
THE RUNG'S DONE-RULE: the x86 emitter reads a homed/forwarded value IN PLACE as a source
operand of a compare/binop/SIB instead of copying it into a scratch register first, and the
allocator no longer spends a home register on a load it can forward. Measured on the estate's
own instrument runtime/nx_probe_bchk_asm.nx (a bounds-checked hot loop over [1024]i64):
pre-LN7 loop head: movq %r12, %r15 ; cmpq $1024, %r15 (copy the homed counter, THEN compare)
LN7 loop head: cmpq $1024, %r12 (compare the homed counter in place)
main() real instructions (crash-guard ON, the default build this gate uses): 62 -> 58
(--no-crash-guard shape is 64 -> 60; the guard adds a fixed prologue to both)
the loop-bound check reads the homed counter DIRECTLY: pre-LN7 copies it to a scratch reg
first (movq %r12,%r15 ; cmpq $1024,%r15), LN7 emits `cmpq $1024, %r12` -- present iff LN7.
checked-loop bench nx_bounds_perf: 8229/8278/8385 us -> 6939/6904/6912 us (median -16.5%)
All measured 2026-08-23 on the SOUND rule (X86_LN7_BLOCK_FWD_ENABLE with the cut-the-load-block
availability check; an earlier merge-unsound draft forwarded more but miscompiled self-host and
was rewritten). Instruction method = the awk equivalent ln7_main_instrs below.
Subject = the compiler under test (argv[1], default the live builder). This gate does NOT mutate
its own source to bite: the discriminator is the COMPILER, so the bite is running it against the
banked pre-LN7 compiler (T2 and T3 go RED) vs the LN7 compiler (all GREEN). Drive it as:
nx_x86_regalloc_use_gate _offc/nx_cc_sovereign.elf (LN7 live -> GREEN)
nx_x86_regalloc_use_gate /path/to/pre-ln7-compiler.elf (bite -> RED on T2,T3)
Driver = nx_ccgate_lib (the one compiler-gate driver): .s capture in /tmp/nxln7/, per-pid paths,
runnables under _build/ (NAS /tmp is noexec). ASCII-only source. license_tier: ORIGINAL. No hw
writes (Rule 26).
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_gate_verdict.nxnx_ccgate_lib.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 39 | const LN7_PROBE_MAIN_MAX: i64 = 60 |
| 43 | const LN7_DIRECT_CMP: *u8 = "cmpq $1024, %r12\x00" // LN7 in-place compare of the homed counter |
functions
| 47 | func ln7_main_instrs(path: *u8) -> i64 |
| 92 | func main(argc: i64, argv: *i64) -> i64 |