Go 1.27 adds experimental write-once SIMD that runs on any CPU
Go is exposing SIMD—the CPU capability that applies one operation across a vector of values at once—directly to Go code for the first time. Previously the only way to reach it was hand-written Go assembly, worthwhile only for the hottest compute kernels, so most code that could vectorize simply didn’t. Go 1.26 shipped architecture-specific APIs for amd64, and Go 1.27 extended them to arm64 NEON and wasm via an archsimd package.
The headline addition in 1.27 is a portable simd package, modeled loosely on C++‘s Highway, that hides the wide variation between platforms: fixed versus runtime-queried vector sizes, differing mask models (bitmasks, dedicated mask registers, per-byte masks), and uneven instruction support. It does this by dropping fixed-size vector types, exposing only the operations common to all supported architectures, and emulating the gaps. Code compiles once and runs everywhere—hitting near-assembly speed when the operations map to hardware (AVX/AVX2/AVX512, NEON, wasm SIMD) and falling back to emulation where they don’t. Vectors are typed as pluralized primitives like simd.Float32s, loaded from and stored to slices.
The first release is deliberately narrow: there’s no cross-lane reduction yet (ReduceSum is slated for the next version), and Int8s.OnesCount is among the operations still missing. For cases the portable layer can’t cover, a ToArch/FromArch escape hatch lets developers drop into architecture-specific code, at the cost of writing and emulating each platform themselves. The whole thing is gated behind GOEXPERIMENT=simd, and notably the design explicitly aims to stay readable enough for LLMs to write it.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.