simdvec

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func ConvertF64ToF32(dst []float32, src []float64)

ConvertF64ToF32 writes float32(src[i]) into dst for i in [0, len(src)). dst must have at least len(src) elements.

func MatmulKernelF32

func MatmulKernelF32(a, b, c []float32, M, K, N int) bool

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

func MatmulKernelF64(a, b, c []float64, M, K, N int)

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

func SumAxis0F64(dst, src []float64, nrows, rowstride int)

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).

func SumF64

func SumF64(src []float64) float64

SumF64 folds src into one float64 sum: the existing sequential left-to-right loop, verbatim semantics (the default build has only this path, so its bits are fixed).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL