code wiki / _hdl_build / nx_eqsat_constfold_bench.nx

nx_eqsat_constfold_bench.nx

buildroot/runtime/_hdl_build/nx_eqsat_constfold_bench.nx

7162 B131 linesdepth 7pulls 9 transitivereach 0 importersview sourcekind benchtopic eqsat
docsdependenciesstructsconstsfunctions

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

nx_eqsat.nx nx_eqsat_constfold_bench.nx

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

main _one_iter nx_eqsat_init nx_eqsat_enable_constfold sys_mmap nx_eqsat_add_const nx_eqsat_add nx_eqsat_op_is_valid nx_eqsat_arity_for nx_cf_intern_const nx_eqsat_add_const ↻ 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 ↻

structs

none

consts

31const K_MAGIC_2000: i64 = 2000
32const K_MAGIC_4096: i64 = 4096

functions

34func _emit_num(v: i64) -> i64
called by 1: main
42func _emit_str(s: *u8, len: i64) -> i64 { sys_write(1, s, len); return 0 }
called by 1: main
43func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 }
called by 1: main
55func _one_iter(g: *NxEGraph, nodes: *NxENode, cap_nodes: i64,
83func main() -> i64