diff --git a/src/simd/archsimd/_gen/simdgen/gen_simdTypes.go b/src/simd/archsimd/_gen/simdgen/gen_simdTypes.go
index 25d53ed..da7a3af 100644
--- a/src/simd/archsimd/_gen/simdgen/gen_simdTypes.go
+++ b/src/simd/archsimd/_gen/simdgen/gen_simdTypes.go
@@ -217,9 +217,17 @@
//
// {{.Feature}} is defined on all GOARCHes, but will only return true on
// GOARCH {{.GoArch}}.
+{{- if .GOAMD64}}
+//
+// When the program is compiled with GOAMD64=v{{.GOAMD64}} or higher,
+// {{.Feature}} always returns true, allowing the compiler to remove
+// code paths that handle the absence of the feature.
+{{- end}}
func ({{.FeatureVar}}Features) {{.Feature}}() bool {
{{- if .Virtual}}
return {{range $i, $dep := .Implies}}{{if $i}} && {{end}}cpu.{{$f.FeatureVar}}.Has{{$dep}}{{end}}
+{{- else if .GOAMD64}}
+ return goamd64v{{.GOAMD64}} || cpu.{{.FeatureVar}}.Has{{.Feature}}
{{- else}}
return cpu.{{.FeatureVar}}.Has{{.Feature}}
{{- end}}
@@ -640,6 +648,12 @@
// Virtual means this feature is not represented directly in internal/cpu,
// but is instead the logical AND of the features in Implies.
Virtual bool
+
+ // GOAMD64 is the lowest GOAMD64 microarchitecture level that guarantees
+ // this feature, or 0 if no level does. When it is non-zero, the feature
+ // check returns true as a compile-time constant if the corresponding
+ // amd64.v<N> build tag is set. Only meaningful on GOARCH amd64.
+ GOAMD64 int
}
// goarchFeatureInfo maps from GOARCH to CPU feature to additional information
@@ -710,6 +724,7 @@
Virtual bool
Implies []string
ImpliesAll string
+ GOAMD64 int
}
var features []feature
for _, k := range featureKeys {
@@ -721,6 +736,7 @@
Virtual: fi.Virtual,
Implies: fi.Implies,
ImpliesAll: featureImplies(k.GoArch, k.Feature),
+ GOAMD64: fi.GOAMD64,
})
}
diff --git a/src/simd/archsimd/_gen/simdgen/xed.go b/src/simd/archsimd/_gen/simdgen/xed.go
index 6e01b66..27250fe 100644
--- a/src/simd/archsimd/_gen/simdgen/xed.go
+++ b/src/simd/archsimd/_gen/simdgen/xed.go
@@ -858,12 +858,17 @@
// TODO: In general, Intel doesn't make any guarantees about what flags are
// set, so this means our feature checks need to ensure these, just to be
// sure.
+ // The GOAMD64 fields record which GOAMD64 microarchitecture level
+ // guarantees each feature: v3 guarantees AVX, AVX2, and FMA, and v4
+ // additionally guarantees the AVX-512 features that make up the
+ // combined "AVX512" feature (F, BW, CD, DQ, and VL).
var features = map[string]featureInfo{
- "AVX2": {Implies: []string{"AVX"}},
- "AVX512": {Implies: []string{"AVX2"}},
+ "AVX": {GOAMD64: 3},
+ "AVX2": {Implies: []string{"AVX"}, GOAMD64: 3},
+ "AVX512": {Implies: []string{"AVX2"}, GOAMD64: 4},
"AVXAES": {Virtual: true, Implies: []string{"AVX", "AES"}},
- "FMA": {Implies: []string{"AVX"}},
+ "FMA": {Implies: []string{"AVX"}, GOAMD64: 3},
"VAES": {Implies: []string{"AVX"}},
// AVX-512 subfeatures.
diff --git a/src/simd/archsimd/cpu.go b/src/simd/archsimd/cpu.go
index 8266bef..69853cd 100644
--- a/src/simd/archsimd/cpu.go
+++ b/src/simd/archsimd/cpu.go
@@ -14,8 +14,12 @@
//
// AVX is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
+//
+// When the program is compiled with GOAMD64=v3 or higher,
+// AVX always returns true, allowing the compiler to remove
+// code paths that handle the absence of the feature.
func (X86Features) AVX() bool {
- return cpu.X86.HasAVX
+ return goamd64v3 || cpu.X86.HasAVX
}
// AVX2 returns whether the CPU supports the AVX2 feature.
@@ -24,8 +28,12 @@
//
// AVX2 is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
+//
+// When the program is compiled with GOAMD64=v3 or higher,
+// AVX2 always returns true, allowing the compiler to remove
+// code paths that handle the absence of the feature.
func (X86Features) AVX2() bool {
- return cpu.X86.HasAVX2
+ return goamd64v3 || cpu.X86.HasAVX2
}
// AVX512 returns whether the CPU supports the AVX512F+CD+BW+DQ+VL features.
@@ -39,8 +47,12 @@
//
// AVX512 is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
+//
+// When the program is compiled with GOAMD64=v4 or higher,
+// AVX512 always returns true, allowing the compiler to remove
+// code paths that handle the absence of the feature.
func (X86Features) AVX512() bool {
- return cpu.X86.HasAVX512
+ return goamd64v4 || cpu.X86.HasAVX512
}
// AVX512BITALG returns whether the CPU supports the AVX512BITALG feature.
@@ -147,8 +159,12 @@
//
// FMA is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
+//
+// When the program is compiled with GOAMD64=v3 or higher,
+// FMA always returns true, allowing the compiler to remove
+// code paths that handle the absence of the feature.
func (X86Features) FMA() bool {
- return cpu.X86.HasFMA
+ return goamd64v3 || cpu.X86.HasFMA
}
// SHA returns whether the CPU supports the SHA feature.
diff --git a/src/simd/archsimd/cpu_amd64v3_off.go b/src/simd/archsimd/cpu_amd64v3_off.go
new file mode 100644
index 0000000..4c3e41a
--- /dev/null
+++ b/src/simd/archsimd/cpu_amd64v3_off.go
@@ -0,0 +1,12 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build goexperiment.simd && !amd64.v3
+
+package archsimd
+
+// goamd64v3 reports whether the program is compiled for the GOAMD64=v3
+// microarchitecture level or higher, which guarantees the AVX, AVX2,
+// and FMA CPU features.
+const goamd64v3 = false
diff --git a/src/simd/archsimd/cpu_amd64v3_on.go b/src/simd/archsimd/cpu_amd64v3_on.go
new file mode 100644
index 0000000..9cd7ee4
--- /dev/null
+++ b/src/simd/archsimd/cpu_amd64v3_on.go
@@ -0,0 +1,12 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build goexperiment.simd && amd64.v3
+
+package archsimd
+
+// goamd64v3 reports whether the program is compiled for the GOAMD64=v3
+// microarchitecture level or higher, which guarantees the AVX, AVX2,
+// and FMA CPU features.
+const goamd64v3 = true
diff --git a/src/simd/archsimd/cpu_amd64v4_off.go b/src/simd/archsimd/cpu_amd64v4_off.go
new file mode 100644
index 0000000..023e0ad
--- /dev/null
+++ b/src/simd/archsimd/cpu_amd64v4_off.go
@@ -0,0 +1,12 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build goexperiment.simd && !amd64.v4
+
+package archsimd
+
+// goamd64v4 reports whether the program is compiled for the GOAMD64=v4
+// microarchitecture level or higher, which guarantees the AVX512F, BW,
+// CD, DQ, and VL CPU features that make up the combined AVX512 feature.
+const goamd64v4 = false
diff --git a/src/simd/archsimd/cpu_amd64v4_on.go b/src/simd/archsimd/cpu_amd64v4_on.go
new file mode 100644
index 0000000..711b9ed
--- /dev/null
+++ b/src/simd/archsimd/cpu_amd64v4_on.go
@@ -0,0 +1,12 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build goexperiment.simd && amd64.v4
+
+package archsimd
+
+// goamd64v4 reports whether the program is compiled for the GOAMD64=v4
+// microarchitecture level or higher, which guarantees the AVX512F, BW,
+// CD, DQ, and VL CPU features that make up the combined AVX512 feature.
+const goamd64v4 = true