Skip to content

Commit

Permalink
internal/cpu: add ARM64.HasSHA3
Browse files Browse the repository at this point in the history
For golang#69536

Change-Id: If237226ba03e282443b4fc90484968c903198cb1
  • Loading branch information
FiloSottile committed Sep 30, 2024
1 parent ae9387d commit 96f3fa4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/internal/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var ARM64 struct {
HasSHA1 bool
HasSHA2 bool
HasSHA512 bool
HasSHA3 bool
HasCRC32 bool
HasATOMICS bool
HasCPUID bool
Expand Down
14 changes: 10 additions & 4 deletions src/internal/cpu/cpu_arm64_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ package cpu
import _ "unsafe" // for linkname

func osInit() {
// macOS 12 moved these to the hw.optional.arm tree, but as of Go 1.24 we
// still support macOS 11. See [Determine Encryption Capabilities].
//
// [Determine Encryption Capabilities]: https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855
ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00"))
ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00"))
ARM64.HasSHA512 = sysctlEnabled([]byte("hw.optional.armv8_2_sha512\x00"))
ARM64.HasSHA3 = sysctlEnabled([]byte("hw.optional.armv8_2_sha3\x00"))

ARM64.HasDIT = sysctlEnabled([]byte("hw.optional.arm.FEAT_DIT\x00"))

// There are no hw.optional sysctl values for the below features on Mac OS 11.0
// to detect their supported state dynamically. Assume the CPU features that
// Apple Silicon M1 supports to be available as a minimal set of features
// to all Go programs running on darwin/arm64.
// There are no hw.optional sysctl values for the below features on macOS 11
// to detect their supported state dynamically (although they are available
// in the hw.optional.arm tree on macOS 12). Assume the CPU features that
// Apple Silicon M1 supports to be available on all future iterations.
ARM64.HasAES = true
ARM64.HasPMULL = true
ARM64.HasSHA1 = true
Expand Down

0 comments on commit 96f3fa4

Please sign in to comment.