code wiki / _hdl_build / nx_latency_metric_test.nx
nx_latency_metric_test.nx
buildroot/runtime/_hdl_build/nx_latency_metric_test.nx
about
nx_latency_metric_test.nx -- proves the HONEST latency-metric organ and uses it
to race three divider TOPOLOGIES at W=16: radix-2 (W stages), radix-4 (W/2
stages), and the scalar-equivalent Newton-Raphson reciprocal structure
(~log W iterations of multiply-heavy work).
WHAT THIS PROVES (FAIL LOUD on every leg):
(1) The organ's UNIT metric matches the functional sim's implicit depth-1
model: on a tiny hand-built chain whose longest path is known by hand,
nx_lat_unit returns exactly that hand-counted op-depth.
(2) The HONEST metric does NOT treat a multiplier as depth-1: a single MUL
cell costs 2*ceil(log2 W) gate levels, an ADD costs ceil(log2 W), a
boolean costs 1 -- asserted directly against nx_lat_kind_weight, and
asserted on a one-MUL chain whose honest depth > its unit depth.
(3) THE RACE, told HONESTLY across WIDTH -- the trap, and where it flips. The
SAME Newton topology is measured with a DEEP multiplier (the real
nx_mul_wide 32-bit-limb schoolbook) and a SHALLOW one (single-cell Wallace
model, 2*logW), at W=16 and W=64. The MEASURED honest critical paths are:
W=16: radix-2=181 radix-4=139 Newton-deep=363 Newton-shallow=166
W=64: radix-2=967 radix-4=743 Newton-deep=709 Newton-shallow=320
So, honestly:
- At SMALL width (W=16) the multiplicative method does NOT pay off:
radix-4 wins; the DEEP-multiplier Newton is the WORST (363); and even
the SHALLOW-multiplier Newton (166) still loses to radix-4 (139). The
naive "log(W) multiplies beats W subtracts" LATENCY claim is FALSE here.
- At LARGE width (W=64) the log(W) FRONTIER appears: BOTH Newton variants
beat BOTH radix dividers (320 and 709 vs 743 and 967), because the radix
dividers' stage count grows linearly in W while Newton's iteration count
grows only ~log W. Ordering: shallow-Newton < deep-Newton < r4 < r2.
- THE CROSSOVER is the headline: the SAME shallow-multiplier Newton goes
from LOSING to radix-4 at W=16 to BEATING it at W=64. That measured sign-
flip IS the multiplicative-divider latency win -- and the honest metric
refuses to award it at a width where it is not real.
Invariant independent of width + multiplier: radix-4 (W/2 stages) always
beats radix-2 (W stages). All orderings are ASSERTED, not assumed.
Known-answer lines (printed for the gate): four honest critical paths at W=16,
then at W=64, then the kind-weight spot-checks. exit 0 iff all asserts hold.
HONESTY SCOPE: the Newton network here is the algorithm's STRUCTURAL skeleton
(the exact operator dependency chain of nx_alu_divider_newton.nx: normalize ->
dependencies 4 imports · 0 importers
imports: nx_latency_metric.nxnx_alu_divider_r4.nxnx_mul_wide.nxnx_newton_struct.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
| none |
functions
| 54 | func _emit_num(v: i64) -> i64 called by 1: main |
| 62 | func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 } called by 1: main |
| 65 | func _mk_gsim(ninputs: i64) -> *NxGsim |
| 74 | func _mk_depth() -> *i64 { return sys_mmap(8192 * 8) as *i64 } called by 1: main |
| 79 | func _measure(W: i64, iters: i64, depth: *i64, out: *i64) -> i64 |
| 102 | func main() -> i64 |