code wiki / (root) / nx_f32_matmul.nx

nx_f32_matmul.nx

buildroot/runtime/nx_f32_matmul.nx

2543 B78 linesdepth 3pulls 4 transitivereach 115 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_matmul.nx -- bits-up f32 dot product + GEMM kernel. L7 composition brick. Last load-bearing math primitive for an end-to-end f32-mode transformer block. Composes nx_f32_mul + nx_f32_add over rows / columns. API: nx_f32_dot(a, b, n) -- scalar dot product (sum of a[i]*b[i]) nx_f32_matmul(a, b, c, m, k, n) -- C[m,n] = A[m,k] @ B[k,n] row-major storage Bit-exact when all operands and intermediate sums are representable f32 (e.g., small ints). Otherwise round-to- nearest-even accumulates per the L4 f32 ops. No libm. Inner MAC uses nx_f32_hw SSE intrinsics (__f32_add/__f32_mul -> real addss/mulss on the FPU), which are BIT-EXACT vs the bits-up software f32 (proven by nx_f32_hw_matmul_gate's hw==sw differential) but replace dozens of integer ops per multiply with one instruction -- the hardware rung the LLM forward stands on.

dependencies 4 imports · 25 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx nx_f32_hw.nx nx_f32_matmul.nx nx_f32_attn_multi.nx nx_f32_attn_multi_test.nx nx_f32_hw_matmul_gate.nx nx_f32_hw_matmul_perf.nx nx_f32_lazy_weight.nx nx_f32_lazy_weight_test.nx nx_f32_llama_block.nx nx_f32_llama_block_test.nx nx_f32_llama_block_v4.nx nx_f32_llama_block_v4_test.nx

diagram shows first 10 each side; +0 more imports, +15 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_hw.nx

imported by: nx_f32_attn_multi.nxnx_f32_attn_multi_test.nxnx_f32_hw_matmul_gate.nxnx_f32_hw_matmul_perf.nxnx_f32_lazy_weight.nxnx_f32_lazy_weight_test.nxnx_f32_llama_block.nxnx_f32_llama_block_test.nxnx_f32_llama_block_v4.nxnx_f32_llama_block_v4_test.nxnx_f32_llama_v4b.nxnx_f32_llama_v4p.nxnx_f32_llm.nxnx_f32_llm_v4.nxnx_f32_matmul_gate.nxnx_f32_matmul_perf.nxnx_f32_matmul_t.nxnx_f32_matmul_t_test.nxnx_f32_matmul_test.nxnx_f32_mha.nxnx_f32_mha_multi.nxnx_f32_mha_multi_test.nxnx_f32_mha_test.nxnx_f32_transformer.nxnx_vit_speed_probe.nx

structs

none

consts

25const NX_F32_MM_OK: nx_int = 0
26const NX_F32_MM_ERR_BAD_DIM: nx_int = 1
27const NX_F32_MM_N_VERDICTS: nx_int = 2

functions

29func nx_f32_mm_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
37func nx_f32_dot(a: *i64, b: *i64, n: nx_int) -> i64
54func nx_f32_matmul(a: *i64, b: *i64, c: *i64,