simd

package module
v0.0.0-...-f686805 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 0 Imported by: 0

README

SIMD experiment (Go 1.27+)

This package requires Go 1.27 with GOEXPERIMENT=simd. Unlike simd/archsimd, the stdlib simd package it is built on is portable: no architecture build tag is required.

See benchmarks.

Platform support

Architecture Backing hardware
amd64 AVX / AVX2 / AVX-512, picked at runtime
arm64 NEON
wasm SIMD128
everything else pure-Go emulation

On the emulated tier, this package transparently falls back to the equivalent scalar github.com/samber/lo function instead of paying the emulation overhead.

Controlling the vector width

GODEBUG=simd=<0|128|256|512> forces a specific behaviour for the current process:

GODEBUG=simd=0   go test ./...  # force the scalar/lo.* fallback everywhere
GODEBUG=simd=128 go test ./...  # force 128-bit vectors
GODEBUG=simd=256 go test ./...  # force 256-bit vectors (panics if unsupported by the CPU)

Without GODEBUG=simd, the widest vector the CPU supports (with the required feature set) is used automatically. Building without GOEXPERIMENT=simd at all compiles this package to an empty stub with no exported symbols, same as before this package existed.

Running the tests

GOEXPERIMENT=simd go test ./...

Documentation

Overview

Package simd accelerates a subset of the samber/lo slice helpers (Sum, Mean, Min, Max, Clamp, SumBy, MeanBy, Contains) using the Go 1.27 stdlib "simd" package.

Unlike simd/archsimd, the stdlib "simd" package is portable: it maps to AVX/AVX2/AVX512 on amd64, NEON on arm64, SIMD128 on wasm, and falls back to a pure-Go emulation on every other architecture. This package therefore requires no per-architecture build tags.

Building this package requires Go 1.27+ and GOEXPERIMENT=simd. Without the experiment enabled, this file is the only one compiled: the package exposes no symbols.

Fallback

When the current process runs the emulated implementation (no hardware SIMD support, or GODEBUG=simd=0), every helper transparently falls back to the equivalent scalar github.com/samber/lo function, which is faster than paying the emulation overhead.

Jump to

Keyboard shortcuts

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