code wiki / _hdl_build / nx_measure_cost_test.nx

nx_measure_cost_test.nx

buildroot/runtime/_hdl_build/nx_measure_cost_test.nx

3381 B85 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_measure_cost_test.nx -- the optimizer's cost model from MEASURED REALITY, not a datasheet. The Seed spores onto hardware and TIMES the actual operations (rdtsc cycle counter) to learn THIS machine's real costs -- so a slow/damaged/ asymmetric unit is reflected and the optimizer targets the hardware's true limits. (A board with a crippled divider measures div as expensive and the loop routes around it; a board with fast mul measures that and uses it.) Universal-reality invariant (true on every real CPU): integer DIV >> MUL >= ADD. We MEASURE it here -- the relative costs become the optimizer's cost table. Known answer (FAIL LOUD on the ordering, not exact cycles which vary): exit 0 iff measured div_cost > mul_cost AND mul_cost >= add_cost.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_measure_cost_test.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 mc_time_add sys_write mc_time_mul sys_write ↻ mc_time_div sys_write ↻ sys_write ↻ _emit sys_write ↻ sys_mmap sys_exit

structs

none

consts

15const MC_ITERS: i64 = 2000000

functions

19func mc_time_add(seed: i64) -> i64
called by 1: main calls 1: sys_write
28func mc_time_mul(seed: i64) -> i64
called by 1: main calls 1: sys_write
37func mc_time_div(seed: i64) -> i64
called by 1: main calls 1: sys_write
47func _emit(name: *u8, v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
57func main() -> i64