Lobsters | 📄 原文链接 | 2026-10-26 收录

Go 终于能用 SIMD:archsimd 与可移植 simd 包

来源:internals-for-interns.com — 2026-10

📋 概述

Go 里最普通的逐元素数组加法,CPU 其实一次能算八对,但纯 Go 循环永远用不上这些硬件,因为以前想用 SIMD 只能手写汇编。Go 1.26 引入实验性的 simd/archsimd 包,Go 1.27 又在它之上提供可移植的 simd 包。作者以 Go 1.27.0 加 GOEXPERIMENT=simd 为例,从向量寄存器与 lane 讲起,把比较、掩码、blend、permute、水平加法、尾部处理一路讲到编译器如何把方法调用变成一条 VADDPS 指令。

🔑 核心要点

💡 金句

The funny thing is that the same CPU has hardware that could handle eight pairs at once, and a plain Go loop never uses it.
← 返回 Lobsters 首页