Platform-independent SIMD in Go
Go 1.26 and 1.27 introduce experimental, platform-independent SIMD APIs allowing write-once vector processing with hardware performance and fallback emulation.
read it Essential reading for Go developers looking to optimize compute-heavy tasks without dropping down into architecture-specific assembly.
summary
Go is introducing experimental architecture-agnostic SIMD packages in versions 1.26 and 1.27 to simplify vector programming across platforms like amd64, arm64, and wasm. The new simd package hides vector-size variations and missing instructions by providing a uniform interface with built-in fallback emulations and compiler-driven function specialization. This approach bridges the performance gap for data-intensive workloads without forcing developers to maintain multiple platform-specific assembly implementations. Developers can also escape to lower-level archsimd intrinsics when highly specialized instructions are required.
key points
- The portable simd package uses a size-agnostic design inspired by C++ Highway, supporting AVX, NEON, and Wasm with automatic emulation on unsupported platforms.
- The Go compiler uses AST rewriting to specialize functions and eliminate runtime dispatch overhead for SIMD operations.
- Developers can escape to architecture-specific archsimd intrinsics using ToArch() and conversion functions when missing specialized operations.
- Build-time control flags via GODEBUG=simd=... allow testing different vector lengths and forced emulation modes.
who should read it
Go systems programmers, performance engineers, and developers working on data processing, cryptography, or numerical computing.
discussion warm
consensus
Commenters are overwhelmingly enthusiastic about Go adding portable SIMD, praising the design choices for handling variable-length vectors and noting it significantly reduces the need for CGO or manual assembly.
pushback
Some point out that portable SIMD can carry a minor performance penalty compared to hand-tuned platform-specific intrinsics, while others debate how it compares to vector approaches in languages like Mojo or Rust.
https://imjasonh.github.io/playground/palette-swap/ swaps colors in a provided image in wasm, entirely locally in your browser, to benchmark portable SIMD vs non-portable archsimd vs non-SIMD.
Portable SIMD is ~11% slower than non-portable SIMD in this case, but both are ~5x faster than non-SIMD.
Provides a concrete benchmark showing that portable SIMD is only about 11 percent slower than platform-specific SIMD while still achieving a 5x speedup over scalar code.
Generated by an LLM from the article and thread. Check the sources before relying on it.