code wiki / _hdl_build / nx_superopt_test.nx

nx_superopt_test.nx

buildroot/runtime/_hdl_build/nx_superopt_test.nx

13733 B254 linesdepth 8pulls 12 transitivereach 0 importersview sourcekind gate/prooftopic superopt
docsdependenciesstructsconstsfunctions

about

nx_superopt_test.nx -- GATE + proof for the mechanized superoptimizer organ (nx_superopt.nx, the AUTHOR leg of the Sovereign Invention Engine). Proves, with NO LLM in the loop, one full PROPOSE/SCORE/VERIFY/EMIT invention tick on the smallest end-to-end-provable example: SEED (mul x 8) --> EMIT (shl x 3). It self-asserts a known answer + sys_exit(0), establishing: (1) the loop FOUND a cheaper equivalent of the seed (cand_count==3, root=SHL, shift=3) -- PROPOSE via nx_eqsat saturation, EMIT via the extractor. (2) the cheaper form is TRIANGULATED-EQUIVALENT to the seed over a dense(exhaustive small-width) + random + edge battery via THREE genuinely independent legs -- AND we prove the check would CATCH a non-equivalent candidate (the (shl x 2) negative control is REJECTED by the same battery). (3) the cost STRICTLY decreased on the honest metric, twice independently: Tier-1 e-graph op-cost 3 -> 1, AND Tier-2 honest gate-level latency at W=64: MUL = 2*ceil(log2 64) = 12 -> SHL = ceil(log2 64) = 6. LEG INDEPENDENCE (the keystone honesty defense -- legs must not collude on the same i64 instruction): LEG0 = candidate emit-DAG interp; LEG1 = candidate lowered-NxGsim gate-sim (independent code path); LEG2 = the SEED's value via a shift-FREE repeated-doubling multiply (never takes the candidate's `<<` path). ORACLE = the SEED emit-DAG (mul x 8) interpreted directly. A wrong shift count makes LEG2 (and the oracle) disagree with LEG0/LEG1 -- exactly what the negative control demonstrates is CAUGHT. KNOWN ANSWER (FAIL LOUD), one line: "<found> <seed_cost> <cand_cost> <seed_lat> <cand_lat> <root_op> <cand_count> <bpass> <btotal> <neg_rejected> <neg_first_bad_leg>" = "1 3 1 12 6 11 3 <N> <N> 1 0 " where N = battery vector count, root_op 11 = SHL, neg_rejected 1 = the (shl x 2) wrong candidate FAILED the battery, neg_first_bad_leg 0 = leg 0 (emit-interp of the wrong candidate) first diverged. Expected: "1 3 1 12 6 11 3 585 585 1 0 " run=0

dependencies 1 imports · 0 importers

nx_superopt.nx nx_superopt_test.nx

imports: nx_superopt.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_eqsat_init nx_eqsat_add_var nx_eqsat_add nx_eqsat_op_is_valid nx_eqsat_arity_for nx_cf_intern_const nx_eqsat_add_const nx_eqsat_add ↻ nx_eqsat_mix nx_cf_make_const_node nx_eqsat_new_class nx_eqsat_find nx_eqsat_find ↻ nx_eqsat_fold_value nx_eqsat_op_to_gate_kind nx_gsim_kind_supported nx_eqsat_arity_for ↻ nx_eqsat_find ↻ nx_gsim_eval_cell nx_eqsat_op_cost nx_eqsat_new_class ↻ nx_eqsat_union_cited nx_eqsat_find ↻ nx_eqsat_log_rule nx_eqsat_push_dirty nx_eqsat_fingerprint nx_eqsat_mix ↻ nx_hmap_has nx_hmap_probe_find nx_hmap_hash nx_hmap_entry_at nx_hmap_get nx_hmap_probe_find ↻ nx_hmap_entry_at ↻ nx_eqsat_node_matches nx_eqsat_arity_for ↻ nx_eqsat_find ↻ nx_hmap_put nx_hmap_probe_insert

structs

none

consts

37const SO_W: i64 = 64 // honest-metric datapath width for Tier-2 scoring

functions

39func _emit_num(v: i64) -> i64
called by 1: main
47func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 }
called by 1: main
52func found_or(bpass: i64, btotal: i64, cand_cost: i64, seed_cost: i64) -> i64
called by 1: main
58func main() -> i64