hn.today

Platform-Independent SIMD in Go

go.dev13 points1 comments
Screenshot of Platform-Independent SIMD in Go

Go 1.26 and 1.27 add experimental SIMD support that makes vectorized operations accessible from Go without writing assembly. There are two complementary APIs: archsimd exposes architecture-specific, fixed-size vector primitives for maximal control, while a new platform- and size-agnostic simd package provides a portable, write-once abstraction built around the intersection of operations available across hardware. The design addresses wide variation in SIMD: fixed vs. variable vector lengths, differing mask semantics, and divergent instruction sets. The stated goal is to provide code that attains near-assembly performance when hardware supports the operations, and otherwise falls back to efficient emulation so vectorized programs always run.

The simd package removes fixed-size vectors from the type system and supplies plural primitive vector types (for example simd.Uint8s or simd.Float32s) loaded from and stored to slices. When an operation is missing for a platform, simd code can convert to arch-specific representations with ToArch, switch on concrete archsimd types, and either call native instructions or a shared emulation; the compiler specializes and optimizes these switches away. Example use includes implementing Int8s.OnesCount via AVX/AVX512, NEON, wasm, or a portable emulation. Supported backends include AVX/AVX2/AVX512 on amd64, NEON on arm64, and wasm SIMD; enable it with GOEXPERIMENT=simd.

Read on go.dev1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.