Skip to content

Commit f1b1557

Browse files
tpaintrandall77
authored andcommitted
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 <[email protected]> Reviewed-by: Martin Möhrmann <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]>
1 parent 2c5b174 commit f1b1557

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/internal/cpu/cpu.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var X86 struct {
3737
HasPCLMULQDQ bool
3838
HasPOPCNT bool
3939
HasRDTSCP bool
40+
HasSHA bool
4041
HasSSE3 bool
4142
HasSSSE3 bool
4243
HasSSE41 bool

src/internal/cpu/cpu_x86.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
cpuid_BMI2 = 1 << 8
4040
cpuid_ERMS = 1 << 9
4141
cpuid_ADX = 1 << 19
42+
cpuid_SHA = 1 << 29
4243

4344
// edx bits for CPUID 0x80000001
4445
cpuid_RDTSCP = 1 << 27
@@ -53,6 +54,7 @@ func doinit() {
5354
{Name: "erms", Feature: &X86.HasERMS},
5455
{Name: "pclmulqdq", Feature: &X86.HasPCLMULQDQ},
5556
{Name: "rdtscp", Feature: &X86.HasRDTSCP},
57+
{Name: "sha", Feature: &X86.HasSHA},
5658
}
5759
level := getGOAMD64level()
5860
if level < 2 {
@@ -125,6 +127,7 @@ func doinit() {
125127
X86.HasBMI2 = isSet(ebx7, cpuid_BMI2)
126128
X86.HasERMS = isSet(ebx7, cpuid_ERMS)
127129
X86.HasADX = isSet(ebx7, cpuid_ADX)
130+
X86.HasSHA = isSet(ebx7, cpuid_SHA)
128131

129132
var maxExtendedInformation uint32
130133
maxExtendedInformation, _, _, _ = cpuid(0x80000000, 0)

0 commit comments

Comments
 (0)