Repository navigation
Description
Go version
go1.26.5 (toolchain host darwin/arm64, cross-compiling and executing on linux/amd64), GOEXPERIMENT=simd.
What did you do?
Wrote an FMA-saturation loop over N independent archsimd.Float32x16 accumulators, with distinct starting values so CSE cannot merge the chains, and swept N:
package main
import "simd/archsimd"
//go:noinline
func chains(x []float32, n int) archsimd.Float32x16 {
v := archsimd.LoadFloat32x16Slice(x)
a0 := archsimd.LoadFloat32x16Slice(x[0:])
a1 := archsimd.LoadFloat32x16Slice(x[16:])
// ... aN-1
for k := 0; k < n; k++ {
a0 = v.MulAdd(v, a0)
a1 = v.MulAdd(v, a1)
// ... aN-1
}
s := a0
s = s.Add(a1)
// ... aN-1
return s
}
func main() {
x := make([]float32, 1024)
_ = chains(x, 3)
}(Accumulators must be distinct named variables rather than an array element — an
array is not SROA'd here and goes to memory for an unrelated reason, cf. #79322.)
Then counted, in the steady-state loop of the -gcflags=-S listing, the vector
stack traffic and the set of Z registers named anywhere in the function.
What did you expect to see?
AVX-512 has 32 architectural vector registers, and _gen/AMD64Ops.go:128 declares
the operand mask used by the AVX-512 ops as 31 of them:
w = buildReg("X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X27 X28 X29 X30 X31")VFMADD213PS512 and friends use the w31 shape built from it, so the op
definitions say Z16–Z31 are legal operands. I expected the frontier — the largest
N with no spilling — to be about 29 (31 registers, minus the shared multiplicand,
minus one scratch), and I expected to see registers above Z15 in the listing.
What did you see instead?
The frontier is 13, and no register above Z14 is ever named, in any of the
functions, at any N:
| N (accumulators) | insns in loop | vector stack refs per iteration | register copies |
|---|---|---|---|
| 13 | 43 | 0 | 27 |
| 14 | 45 | 14 | 14 |
| 15 | 51 | 19 | 14 |
| 16 | 55 | 24 | 12 |
| 20 | 79 | 44 | 12 |
$ GOEXPERIMENT=simd GOARCH=amd64 GOOS=linux go build -gcflags=-S . 2>&1 \
| grep -oE '\bZ[0-9]+\b' | sort -u -V | tr '\n' ' '
Z0 Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9 Z10 Z11 Z12 Z13 Z14
At N=20 the loop makes 44 stack references per iteration to hold 20 values, on a
machine with 32 registers of which 17 are never touched.
The frontier of 13 is 15 − 1 (the shared multiplicand) − 1 (a scratch register, see below), i.e. exactly the 15-register budget.
Where it comes from
regalloc.go:942 picks a value's candidate register set by type:
if t.IsSIMD() {
if t.Size() > 8 {
return s.f.Config.fpRegMask & s.allocatable
}
// K mask
return s.f.Config.gpRegMask & s.allocatable
}and s.allocatable (regalloc.go:721) is the union of exactly three masks:
s.allocatable = s.f.Config.gpRegMask | s.f.Config.fpRegMask | s.f.Config.specialRegMaskOn amd64 (opGen.go:96119–96121):
| mask | value | bits | registers |
|---|---|---|---|
fpRegMaskAMD64 |
2147418112 = 0x7FFF0000 |
16–30 | X0–X14 |
specialRegMaskAMD64 |
71494644084506624 |
49–55 | K1–K7 |
gpRegMaskAMD64 |
49135 = 0xBFEF |
0–13, 15 | integer, minus BP/g |
registersAMD64 numbers X15 as 31 and X16–X31 as 32–47. Bit 31 is
excluded deliberately (X15 is the ABI zero register). Bits 32–47 appear in no
mask at all, so Z16–Z31 are not allocatable to any value, and the register shapes
that list them are trimmed by the intersection with s.allocatable.
So the mismatch is between the op definitions (31 registers legal) and the
allocator (15 offered). Nothing warns; the only symptom is spilling.
Why it matters
This is the binding constraint on writing a competitive dense-linear-algebra
microkernel in pure Go with GOEXPERIMENT=simd. In a project doing exactly that
(a float32 BLAS subset, https://github.com/scttfrdmn/keel), a 115-shape sweep of
SGEMM microkernel tiles finds the zero-spill frontier at 8 accumulators, where
a 32-register file supports 24. Two consequences that are not obvious:
- A hard floor on memory traffic. With
MRrows andV16-lane vectors along
N, a tile reads1/MR + 1/Vvectors per FMA. Getting below 0.75 needsMR ≥ 3
andV ≥ 3, hence ≥9 accumulators — one past the frontier. So no zero-spill
shape of any size can read less than three quarters of a vector per FMA. With 24
accumulators available the floor would be 0.42. - A measured throughput ceiling on one class of host. The instruction count
the 15-register budget forces (4.625 instructions per FMA on the best shipped
shape) is itself the binding constraint on a 2-FMA/cycle, ~4-wide-issue part:
on an i9-9960X (Skylake-X) that kernel reaches 46.0% of the machine's measured
single-core FMA peak, and 94.6% of the ceiling its own instruction mix implies —
i.e. it is at the front end's limit, not the FMA units'. The two Zen hosts
(7950X3D, Ryzen AI MAX+ 395), with wider front ends, reach 96.6% and 64.2%.
The same clamp is presumably why the 213-form register copies in the table above
are so expensive: at 13 accumulators there is no free register for an FMA result
to land in, and the loop pays 27 copies for 13 FMAs. (That half is a separate
issue about the FMA forms available, filed separately.)
Question
Is the exclusion of X16–X31 from fpRegMaskAMD64 deliberate — e.g. something in
the ABI, the register-mask width (regMask is 64 bits and bits 32–47 are already
spoken for), or save/restore cost — or is it an oversight that predates
GOEXPERIMENT=simd having ops that can name those registers? If it is deliberate,
it seems worth documenting alongside #78979, since "AVX-512 with half the register
file" is a materially different target for library authors than AVX-512.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
P2: file T9/T10/T12 upstream as golang/go#80828, #80829, #80830
gabyhelp commentedon Aug 11, 2026
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
JunyangShao commentedon Aug 13, 2026
I think we have a plan to support the high-number Z registers, don't know the status.
@cherrymui
cherrymui commentedon Aug 13, 2026
Could you try Go 1.27RC3 or tip? I believe it should already work now.
P5: T-78 refutes #18's cause on go1.27.0 — 31 registers allocatable, …
scttfrdmn commentedon Aug 30, 2026
Confirmed fixed on go1.27.0 — thank you for the pointer.
First, the correction I owe: this issue duplicates #78753, which was already closed when I
filed it, and the fix is CL 768262 (
[dev.simd] cmd/compile: make X/Y/Z16-31 allocatable,merged 2026-04-23). gabyhelp listed #78753 in the first comment here and I didn't follow it.
The allocator now offers 31 of 32.
regalloc.gounions four masks rather than three —simdRegMaskis new — andregMaskis now a two-word struct, which answers the widthquestion this issue asked:
specialRegMaskAMD64went from71494644084506624to71776114766249984. The differenceis
281470681743360, which is exactly bits 32–47 — X16–X31 underregistersAMD64'snumbering. Only X15, the ABI zero register, is now in no mask, and that was always
deliberate.
Re-running the sweep: the register count improved much more than the code did. Same
repro, ported (
LoadFloat32x16Sliceis nowLoadFloat32x16), counted the same way in thesteady-state loop, highest
Znamed anywhere in the function. No go1.26.5 toolchain isinstalled here, so every 1.26.5 column is quoted from this issue's own table rather than
re-run — the N=13 row is the control on that.
Two controls on that table. N=13 reproduces all three of its go1.26.5 columns exactly,
which is what you would expect below the frontier and says the ported repro is still the
same measurement. And every row on both toolchains closes as
insns = N + refs + copies + 3, so nothing outside those two columns moved.The spilling that went away came back as register-to-register copies, nearly one for
one. At N=14, −12 refs and +26−14 = +12 copies, for a net of zero instructions. At
N=15, −16 and +16, again zero. At N=16 the net is 1 instruction out of 55. Only at
N=20 does it pay, and there it is 11 out of 79. The frontier — largest N with no vector
stack traffic — is still 13, unchanged.
The reason is property 2 of the original report, which is #80829: with no
231/132FMAform,
a = v.MulAdd(v, a)cannot land ina, so every accumulator needs a copy periteration. At 15 registers that surfaced as spills; at 31 it surfaces as copies. For this
shape the register fix is close to neutral until #80829 lands. I've left the measurement
there rather than reopening this.
Same story on a real kernel — a 6×32 float32 GEMM microkernel, 12 accumulators, unrolled
by 4. Recorded at 270 instructions with 90 vector stack references for 48 FMAs on
go1.26.5; re-measured on go1.27.0 it is 219 with 44, and it now allocates Z16–Z23.
But 45 of those 219 are register copies, only 3 of the 12 accumulators still spill, and 36
of the 44 remaining stack references are broadcast-scalar round-trips through legacy-SSE
MOVUPS, which is #80835.Identical under
GOAMD64v1, v3 and v4. I checked because CL 767380 had proposedgating on v4; the CL that actually landed is unconditional and behaves that way.
One thing I could not reconcile, in case it is a leftover rather than intent:
simdRegMaskAMD64is still2147418112, i.e. X0–X14, andcompatRegsreturnssimdRegMask.intersect(s.allocatable)for SIMD values wider than 8 bytes — yet thelisting allocates Z16–Z23 freely, including plain
VMOVDQU64 Z0, Z16copies and a reloadinto Z19. So something other than
compatRegsis choosing those registers and I may bereading the wrong path. Is
simdRegMaskAMD64still X0–X14 on purpose?Happy for this to be closed as a duplicate of #78753.
P5: reply to golang/go#80828; CL 1 stays on #80829; §5 rule 23
cherrymui commentedon Aug 31, 2026
Thanks