Software Engineering

Go 1.27 introduces portable, platform-agnostic SIMD API

Key Takeaway

Go 1.27 introduces an experimental, portable SIMD interface that allows writing high-performance vectorized code once for multiple architectures.

Summary

Building on architecture-specific APIs from Go 1.26 and 1.27, the Go team has introduced a new experimental 'simd' package. This interface is designed to be platform- and size-agnostic, providing near-assembly performance on supported hardware while offering efficient emulation on platforms without SIMD support. It aims to simplify the development of computationally intensive tasks like cryptography and data processing by removing the need for architecture-specific Go assembly.

Technical details of the new SIMD package

  • The package is experimental and requires setting GOEXPERIMENT=simd at build time.
  • It abstracts away differences in vector sizes and masking implementations across architectures.
  • Currently supports AVX, AVX2, and AVX512 on amd64, NEON on arm64, and wasm SIMD instructions.
  • Vector types are implemented as capitalized primitive types, such as simd.Uint8s or simd.Float32s.
  • It uses an intersection-based approach, supporting operations common to all platforms and emulating others.
  • SIMD comparisons produce specific mask types (e.g., Mask8s for Int8s) to facilitate filtering and selection.

Why it matters

This change lowers the barrier for Go developers to write high-performance, vectorized code without mastering architecture-specific assembly, potentially accelerating performance in AI, cryptography, and data processing libraries.

Original reference: go.dev →