Documentation
¶
Overview ¶
Package simdvec holds vectorized inner loops for per-element, order-free operations (a[i]+b[i], dtype conversion, matmul inner kernel, sum reduction). Two implementations share one exported API, selected at build time:
simd.go //go:build goexperiment.simd → Go 1.27 experimental simd package nosimd.go //go:build !goexperiment.simd → plain scalar loops
Build tags are mandatory, not an optimization choice: the stdlib simd package only exists when the toolchain runs with GOEXPERIMENT=simd, so the default build could not compile simd.go at all. Under GOEXPERIMENT=simd the exported functions must stay bit-identical to the scalar versions, which restricts this package to operations with no cross-element dependence — reductions and dot products accumulate in a different order and must not be added here.
Matmul is the one deliberate exception to bit-equality between builds: under GOEXPERIMENT=simd the matmul kernel accumulates fused (MulAdd), which may differ from the default build's plain mul+add in the last ulp on generic float64 inputs — the same class of variation as numpy across BLAS backends. The in-library contract (einsum fold path bit-identical to the general path) holds in each build independently. The default build's code path keeps the original scalar kernel's exact bits and speed — the core contract of the dual-build design.
Float32 matmul joins the exception list (MatmulKernelF32 accumulates fused under GOEXPERIMENT=simd and may differ in the last ulp from the default build's generic kernel on generic float32 inputs); in the default build it is a shim that only returns false, so float32 always takes the generic kernel there, keeping the default path's bits and speed unchanged.
SumF64 joins the exception list: the simd build accumulates in parallel lanes and merges them in order (pairwise-ish), which may differ from the default build's sequential accumulation in the last ulp on generic float64 inputs (see SumF64). SumAxis0F64 is NOT an exception: lanes span columns only, each column still accumulates rows in ascending order — bit-identical across builds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddF64 ¶
func AddF64(dst, a, b []float64)
AddF64 writes a[i]+b[i] into dst for i in [0, len(a)). dst, a and b must have equal length. IEEE float64 addition is exact and order-free, so the vector result is bit-identical to the scalar loop.
func ConvertF64ToF32 ¶
ConvertF64ToF32 writes float32(src[i]) into dst for i in [0, len(src)). dst must have at least len(src) elements.
func MatmulKernelF32 ¶
MatmulKernelF32 is the default-build shim: it only reports false so the caller falls through to its generic kernel — default-build float32 matmul keeps today's exact code path, bits and speed (the core contract). The GOEXPERIMENT=simd twin computes with fused lanes and reports true; its fused accumulation joins the documented last-ulp exception list above.
func MatmulKernelF64 ¶
MatmulKernelF64 computes c = a@b for dense C-order float64 blocks: a is M×K, b is K×N, c is M×N and must be pre-zeroed. Verbatim lift of dot.go's original scalar kernel (4×8 register-blocked i-k-j, plain mul+add): "default unchanged" is the core contract of the dual-build design, so default-mode matmul keeps the original kernel's bits AND speed. The GOEXPERIMENT=simd twin accumulates fused (MulAdd) and may differ in the last ulp on generic float64 inputs — documented in the package doc and docs/performance.md.
func SumAxis0F64 ¶
SumAxis0F64 folds nrows consecutive rows of width rowstride from src into dst: dst[j] += src[row*rowstride+j] for rows 1..n-1 (row 0 already folded into dst by the caller). Sequential row order per column — bit-identical to the simd twin by construction (lanes span columns only).
Types ¶
This section is empty.