internal/cpu: detect sha-ni instruction support for AMD64

addresses proposal #53084
    required by sha-256 change list developed for #50543

Change-Id: I5454d746fce069a7a4993d70dc5b0a5544f8eeaf
Reviewed-on: https://go-review.googlesource.com/c/go/+/408794
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@google.com>
This commit is contained in:
ted 2022-05-25 20:03:48 -04:00 committed by Keith Randall
parent 2c5b174616
commit f1b1557cf3
2 changed files with 4 additions and 0 deletions

View file

@ -37,6 +37,7 @@ var X86 struct {
HasPCLMULQDQ bool
HasPOPCNT bool
HasRDTSCP bool
HasSHA bool
HasSSE3 bool
HasSSSE3 bool
HasSSE41 bool

View file

@ -39,6 +39,7 @@ const (
cpuid_BMI2 = 1 << 8
cpuid_ERMS = 1 << 9
cpuid_ADX = 1 << 19
cpuid_SHA = 1 << 29
// edx bits for CPUID 0x80000001
cpuid_RDTSCP = 1 << 27
@ -53,6 +54,7 @@ func doinit() {
{Name: "erms", Feature: &X86.HasERMS},
{Name: "pclmulqdq", Feature: &X86.HasPCLMULQDQ},
{Name: "rdtscp", Feature: &X86.HasRDTSCP},
{Name: "sha", Feature: &X86.HasSHA},
}
level := getGOAMD64level()
if level < 2 {
@ -125,6 +127,7 @@ func doinit() {
X86.HasBMI2 = isSet(ebx7, cpuid_BMI2)
X86.HasERMS = isSet(ebx7, cpuid_ERMS)
X86.HasADX = isSet(ebx7, cpuid_ADX)
X86.HasSHA = isSet(ebx7, cpuid_SHA)
var maxExtendedInformation uint32
maxExtendedInformation, _, _, _ = cpuid(0x80000000, 0)