code wiki / _hdl_build / nx_measure_cost_test.nx
nx_measure_cost_test.nx
buildroot/runtime/_hdl_build/nx_measure_cost_test.nx
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
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
structs
| none |
consts
| 15 | const MC_ITERS: i64 = 2000000 |
functions
| 19 | func mc_time_add(seed: i64) -> i64 |
| 28 | func mc_time_mul(seed: i64) -> i64 |
| 37 | func mc_time_div(seed: i64) -> i64 |
| 47 | func _emit(name: *u8, v: i64) -> i64 |
| 57 | func main() -> i64 |