aboutsummaryrefslogtreecommitdiff
path: root/src/simd/archsimd/cpu.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2026-01-13 09:34:53 -0500
committerCherry Mui <cherryyz@google.com>2026-01-13 12:17:09 -0800
commit9ef1692c93bf96328bcaf7a5c8a46094748da7f3 (patch)
tree96266bb6505523fc2a42b89ce1bfb59dfe4b61b2 /src/simd/archsimd/cpu.go
parente2fef50def98b87107ab963f657d43d7869b8463 (diff)
downloadgo-9ef1692c93bf96328bcaf7a5c8a46094748da7f3.tar.xz
simd/archsimd/_gen/simdgen: feature implications
This simplifies our handling of XED features, adds a table of which features imply which other features, and adds this information to the documentation of the CPU features APIs. As part of this we fix an issue around the "AVXAES" feature. AVXAES is defined as the combination of the AVX and AES CPUID flags. Several other features also work like this, but have hand-written logic in internal/cpu to compute logical feature flags from the underlying CPUID bits. For these, we expose a single feature check function from the SIMD API. AVXAES currently doesn't work like this: it requires the user to check both features. However, this forces the SIMD API to expose an "AES" feature check, which really has nothing to do with SIMD. To make this consistent, we introduce an AVXAES feature check function and use it in feature requirement docs. Unlike the others combo features, this is implemented in the simd package, but the difference is invisible to the user. Change-Id: I2985ebd361f0ecd45fd428903efe4c981a5ec65d Reviewed-on: https://go-review.googlesource.com/c/go/+/736100 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/736200 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/simd/archsimd/cpu.go')
-rw-r--r--src/simd/archsimd/cpu.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/simd/archsimd/cpu.go b/src/simd/archsimd/cpu.go
index d0c0ff5426..1cd765268f 100644
--- a/src/simd/archsimd/cpu.go
+++ b/src/simd/archsimd/cpu.go
@@ -10,14 +10,6 @@ type X86Features struct{}
var X86 X86Features
-// AES returns whether the CPU supports the AES feature.
-//
-// AES is defined on all GOARCHes, but will only return true on
-// GOARCH amd64.
-func (X86Features) AES() bool {
- return cpu.X86.HasAES
-}
-
// AVX returns whether the CPU supports the AVX feature.
//
// AVX is defined on all GOARCHes, but will only return true on
@@ -28,6 +20,8 @@ func (X86Features) AVX() bool {
// AVX2 returns whether the CPU supports the AVX2 feature.
//
+// If it returns true, then the CPU also supports AVX.
+//
// AVX2 is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX2() bool {
@@ -41,6 +35,8 @@ func (X86Features) AVX2() bool {
// Nearly every CPU that has shipped with any support for AVX-512 has
// supported all five of these features.
//
+// If it returns true, then the CPU also supports AVX and AVX2.
+//
// AVX512 is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512() bool {
@@ -49,6 +45,8 @@ func (X86Features) AVX512() bool {
// AVX512BITALG returns whether the CPU supports the AVX512BITALG feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512BITALG is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512BITALG() bool {
@@ -57,6 +55,8 @@ func (X86Features) AVX512BITALG() bool {
// AVX512GFNI returns whether the CPU supports the AVX512GFNI feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512GFNI is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512GFNI() bool {
@@ -65,6 +65,8 @@ func (X86Features) AVX512GFNI() bool {
// AVX512VAES returns whether the CPU supports the AVX512VAES feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512VAES is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512VAES() bool {
@@ -73,6 +75,8 @@ func (X86Features) AVX512VAES() bool {
// AVX512VBMI returns whether the CPU supports the AVX512VBMI feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512VBMI is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512VBMI() bool {
@@ -81,6 +85,8 @@ func (X86Features) AVX512VBMI() bool {
// AVX512VBMI2 returns whether the CPU supports the AVX512VBMI2 feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512VBMI2 is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512VBMI2() bool {
@@ -89,6 +95,8 @@ func (X86Features) AVX512VBMI2() bool {
// AVX512VNNI returns whether the CPU supports the AVX512VNNI feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512VNNI is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512VNNI() bool {
@@ -105,14 +113,28 @@ func (X86Features) AVX512VPCLMULQDQ() bool {
// AVX512VPOPCNTDQ returns whether the CPU supports the AVX512VPOPCNTDQ feature.
//
+// If it returns true, then the CPU also supports AVX, AVX2, and AVX512.
+//
// AVX512VPOPCNTDQ is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVX512VPOPCNTDQ() bool {
return cpu.X86.HasAVX512VPOPCNTDQ
}
+// AVXAES returns whether the CPU supports the AVXAES feature.
+//
+// If it returns true, then the CPU also supports AES and AVX.
+//
+// AVXAES is defined on all GOARCHes, but will only return true on
+// GOARCH amd64.
+func (X86Features) AVXAES() bool {
+ return cpu.X86.HasAVX && cpu.X86.HasAES
+}
+
// AVXVNNI returns whether the CPU supports the AVXVNNI feature.
//
+// If it returns true, then the CPU also supports AVX and AVX2.
+//
// AVXVNNI is defined on all GOARCHes, but will only return true on
// GOARCH amd64.
func (X86Features) AVXVNNI() bool {