code wiki / _hdl_build / nx_eqsat_constfold_bench.nx
nx_eqsat_constfold_bench.nx
buildroot/runtime/_hdl_build/nx_eqsat_constfold_bench.nx
about
nx_eqsat_constfold_bench.nx -- CONST-FOLD-HEAVY race vs egg 0.11.0.
THE RACE (engine-only, SAME const-heavy expression both sides):
egg target = nxc2/bench/nx_constfold_egg_bench.rs (copy into
/tmp/race_egg/examples/), the const-fold ANALYSIS graph build(n):
acc = 1; for i in 0..N: leaf=(i%7)+2; acc = acc {+,*,-} leaf (cycle by i%3)
so EVERY subtree is a known constant -- the const-fold analysis must evaluate +
collapse all N nodes, folding the whole chain to a single Num. egg does this via
its ConstantFold Analysis (make/merge/modify); WE do it via make-on-add + a CONST
merge through the union chokepoint citing NX_EQSAT_RULE_CONSTFOLD.
OUR side, per timed iteration (the SAME end-to-end optimize pipeline egg ran):
nx_eqsat_init (fresh e-graph)
enable_constfold (egg's ConstantFold analysis ON)
build the all-const chain (egg's RecExpr build; fold fires at add-time)
nx_eqsat_saturate (egg's Runner::run -- analysis to fixpoint)
nx_eqsat_recompute_best (egg's Extractor bottom-up cost)
nx_eqsat_extract_best_node(root) (egg's find_best -> a single Num)
FAIL LOUD: before timing, one verified iteration asserts the WHOLE chain folded
-- root's canonical best_node is a CONST (cost 0). A fast wrong answer (chain not
folded) loses, exit nonzero.
Output (one line):
NX_CONSTFOLD_ENGINE_ONLY N=<n> ITERS=<it> FOLD=<v> TOTAL_US=<t> US_PER_OP_NS=<u>
(US_PER_OP_NS = total_us*1000/iters = nanoseconds/op; /1000 for us/op.)
SOVEREIGN: no .sh; runs on the pinned NishiLang compiler. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_eqsat.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
| 31 | const K_MAGIC_2000: i64 = 2000 |
| 32 | const K_MAGIC_4096: i64 = 4096 |
functions
| 34 | func _emit_num(v: i64) -> i64 called by 1: main |
| 42 | func _emit_str(s: *u8, len: i64) -> i64 { sys_write(1, s, len); return 0 } called by 1: main |
| 43 | func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 } called by 1: main |
| 55 | func _one_iter(g: *NxEGraph, nodes: *NxENode, cap_nodes: i64, |
| 83 | func main() -> i64 |