code wiki / _hdl_build / nx_simd.nx
nx_simd.nx
buildroot/runtime/_hdl_build/nx_simd.nx
about
nx_simd.nx -- sovereign SIMD: lane-wise vector ops + a VECTORIZING TRANSFORM, the
start of the arc that wins the float/throughput benchmarks (mandelbrot, n-body,
spectral-norm) which are lost on scalar code. One vector instruction does VW lanes
at ~one scalar op's cost (uops.info/nanoBench: vmulps 8 lanes @ 0.5cy = 8x), so a
vectorized loop issues ~N/VW ops instead of N. Here the transform takes a scalar
elementwise kernel and produces its vector form, PROVEN 1:1 over a real array
(including the scalar tail for non-multiples of VW). Integer lanes first -- the
vectorization machinery (ops, transform, 1:1 proof, lane cost) is the reusable
part; float lanes + per-arch emit (AVX2 / NEON / RVV) lower onto the spec encoder.
nanoBench (Abel, github.com/andreas-abel/nanoBench) measures these vector costs on
Intel AND AMD/ARM -- the per-arch numbers the vectorizer's cost model consumes.
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_simd_test.nx
structs
| none |
consts
| 16 | const VW: i64 = 8 // vector width (lanes); models AVX2 (8x i32) / AVX-512 (8x i64) |
functions
| 19 | func v_load(out: *i64, mem: *i64, off: i64) -> i64 { var j: i64 = 0; while j < VW { out[j] = mem[off + j]; j = j + 1 } return 0 } called by 1: k_vector |
| 20 | func v_store(mem: *i64, off: i64, v: *i64) -> i64 { var j: i64 = 0; while j < VW { mem[off + j] = v[j]; j = j + 1 } return 0 } called by 1: k_vector |
| 21 | func v_add(out: *i64, a: *i64, b: *i64) -> i64 { var j: i64 = 0; while j < VW { out[j] = a[j] + b[j]; j = j + 1 } return 0 } called by 1: k_vector |
| 22 | func v_sub(out: *i64, a: *i64, b: *i64) -> i64 { var j: i64 = 0; while j < VW { out[j] = a[j] - b[j]; j = j + 1 } return 0 } |
| 23 | func v_mul(out: *i64, a: *i64, b: *i64) -> i64 { var j: i64 = 0; while j < VW { out[j] = a[j] * b[j]; j = j + 1 } return 0 } called by 1: k_vector |
| 27 | func k_scalar(c: *i64, a: *i64, b: *i64, d: *i64, n: i64) -> i64 called by 1: main |
| 36 | func k_vector(c: *i64, a: *i64, b: *i64, d: *i64, n: i64) -> i64 |