code wiki / _hdl_build / nx_cost_oracle.nx

nx_cost_oracle.nx

buildroot/runtime/_hdl_build/nx_cost_oracle.nx

2845 B53 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind librarytopic cost
docsdependenciesstructsconstsfunctions

about

nx_cost_oracle.nx -- bits-up DETERMINISTIC measurement for fair performance head-to-heads (operator: "avoid the pitfalls of emulators and all the other stuff"). The emulator/timing pitfall: wall-clock and emulated cycle counts are NON-deterministic (vary by machine, emulator, cache, frequency scaling), so judging speed by time is BIASED -- the same two programs can flip winners across runs. The fix, from the hardware up: judge by a COUNTED INVARIANT that is identical every run -- retired instruction count, gate-toggle (switching) activity, or bytes moved. The cost oracle REFUSES to render a verdict on a non-deterministic metric. This is the performance arm of the Referee's DETERMINISM gate. license_tier: ORIGINAL Pairs with nx_referee (fair judging) + nx_gate_energy (toggles) + nx_uops_cost.

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_cost_oracle.nx nx_boolsynth4.nx nx_cost_oracle_test.nx

imports: nx_syscalls.nx

imported by: nx_boolsynth4.nxnx_cost_oracle_test.nx

structs

none

consts

12const CO_WALLCLOCK: i64 = 0 // wall-clock / emulated time -- NON-deterministic -> UNFAIR to judge on
13const CO_INSN: i64 = 1 // retired instruction count -- deterministic
14const CO_TOGGLES: i64 = 2 // gate switching activity -- deterministic, hardware-portable
15const CO_BYTES: i64 = 3 // memory bytes moved -- deterministic
17const CO_REJECT: i64 = 0 - 1 // refuse to judge (non-deterministic metric)
18const CO_TIE: i64 = 0
19const CO_A_FASTER: i64 = 1
20const CO_B_FASTER: i64 = 2

functions

23func co_metric_deterministic(kind: i64) -> i64 { if kind == CO_WALLCLOCK { return 0 } return 1 }
called by 2: co_fair_verdictmain
26func co_reproducible(samples: *i64, n: i64) -> i64
called by 1: main
33func co_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
called by 1: co_fair_verdict
36func co_fair_verdict(kind: i64, cost_a: i64, cost_b: i64, margin: i64) -> i64
called by 1: main calls 2: co_metric_deterministicco_abs
44func co_wallclock_flips(a_samples: *i64, b_samples: *i64, n: i64) -> i64
called by 1: main