hn.today

Platform-Independent SIMD in Go

go.dev5 points0 comments
Screenshot of Platform-Independent SIMD in Go

Go 1.26 and 1.27 introduce experimental SIMD support in two layers: an architecture-specific archsimd package and a portable simd package. SIMD enables high-throughput operations on vectors (useful for cryptography, data processing, AI and even Go’s GC), but hardware varies widely in vector sizes, masking semantics, and available instructions - examples include fixed 128-512 bit vectors on some ISAs, variable-length RISC-V vectors, AVX/AVX2/AVX512 on amd64, NEON (and SVE) on arm64, and wasm SIMD. The portable simd API removes fixed-size vectors from the type system, targets the intersection of commonly available operations, and augments gaps with efficient emulations. Supported backends currently include AVX/AVX2/AVX512, NEON, and wasm, and code compiled without hardware SIMD falls back to emulation so simd code always runs.

The design emphasizes write-once, near-assembly performance: simd types like simd.Uint8s and simd.Float32s load/store from slices, provide common arithmetic/comparison primitives, and allow architecture-specific implementations when needed via ToArch conversions. The blog shows a complete example implementing Int8s.OnesCount with platform-specialized paths and a shared emulation fallback; compiler-side specialization removes type-switch overhead. Developers enable the experiment with GOEXPERIMENT=simd. archsimd remains for low-level, size-specific optimizations, while simd aims for readable, portable vector code with efficient hardware use where available.

Read on go.dev0 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.