From: Tom Thorogood Date: Sun, 19 Oct 2025 01:21:16 +0000 (+1030) Subject: [dev.simd] simd: add AES feature check X-Git-Tag: go1.26rc1~147^2~38 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=20b33395428deee4511cb5f595a37d69899455a4;p=gostls13.git [dev.simd] simd: add AES feature check CL 706055 added AES support but chose to not generate feature checks for composite features. Intel lists AES as AVXAES which gets manually mapped to the composite feature AVX, AES. With the previous writeSIMDFeatures code ignoring composite features, and there being no other references to AES, we neglected to generate a feature check at all. To resolve this, we instead split composite features into their constituent parts and ensure that each feature has a check generated. Currently AVXAES is the only composite feature. Updates #73787 Change-Id: Ic8e9d8a3c9c0854fc717512c2ce092d81cb6b66c Reviewed-on: https://go-review.googlesource.com/c/go/+/712880 Reviewed-by: Junyang Shao LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui --- diff --git a/src/simd/_gen/simdgen/gen_simdTypes.go b/src/simd/_gen/simdgen/gen_simdTypes.go index 03bb4989d9..2d81231cda 100644 --- a/src/simd/_gen/simdgen/gen_simdTypes.go +++ b/src/simd/_gen/simdgen/gen_simdTypes.go @@ -547,10 +547,12 @@ func writeSIMDFeatures(ops []Operation) *bytes.Buffer { } featureSet := make(map[featureKey]struct{}) for _, op := range ops { - if !strings.Contains(op.CPUFeature, ",") { - featureSet[featureKey{op.GoArch, op.CPUFeature}] = struct{}{} + // Generate a feature check for each independant feature in a + // composite feature. + for feature := range strings.SplitSeq(op.CPUFeature, ",") { + feature = strings.TrimSpace(feature) + featureSet[featureKey{op.GoArch, feature}] = struct{}{} } - // Don't generate feature checks for composite features. } features := slices.SortedFunc(maps.Keys(featureSet), func(a, b featureKey) int { if c := cmp.Compare(a.GoArch, b.GoArch); c != 0 { diff --git a/src/simd/cpu.go b/src/simd/cpu.go index 2837c76d32..7d4fe25003 100644 --- a/src/simd/cpu.go +++ b/src/simd/cpu.go @@ -6,6 +6,14 @@ package simd import "internal/cpu" +// HasAES returns whether the CPU supports the AES feature. +// +// HasAES is defined on all GOARCHes, but will only return true on +// GOARCH amd64. +func HasAES() bool { + return cpu.X86.HasAES +} + // HasAVX returns whether the CPU supports the AVX feature. // // HasAVX is defined on all GOARCHes, but will only return true on