Source file src/internal/cpu/cpu_arm64_darwin.go
1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build arm64 && darwin && !ios 6 7 package cpu 8 9 import _ "unsafe" // for linkname 10 11 func osInit() { 12 // macOS 12 moved these to the hw.optional.arm tree, but as of Go 1.24 we 13 // still support macOS 11. See [Determine Encryption Capabilities]. 14 // 15 // [Determine Encryption Capabilities]: https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855 16 ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00")) 17 ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00")) 18 ARM64.HasSHA512 = sysctlEnabled([]byte("hw.optional.armv8_2_sha512\x00")) 19 ARM64.HasSHA3 = sysctlEnabled([]byte("hw.optional.armv8_2_sha3\x00")) 20 21 ARM64.HasDIT = sysctlEnabled([]byte("hw.optional.arm.FEAT_DIT\x00")) 22 23 // There are no hw.optional sysctl values for the below features on macOS 11 24 // to detect their supported state dynamically (although they are available 25 // in the hw.optional.arm tree on macOS 12). Assume the CPU features that 26 // Apple Silicon M1 supports to be available on all future iterations. 27 ARM64.HasAES = true 28 ARM64.HasPMULL = true 29 ARM64.HasSHA1 = true 30 ARM64.HasSHA2 = true 31 } 32 33 //go:noescape 34 func getsysctlbyname(name []byte) (int32, int32) 35 36 // sysctlEnabled should be an internal detail, 37 // but widely used packages access it using linkname. 38 // Notable members of the hall of shame include: 39 // - github.com/bytedance/gopkg 40 // - github.com/songzhibin97/gkit 41 // 42 // Do not remove or change the type signature. 43 // See go.dev/issue/67401. 44 // 45 //go:linkname sysctlEnabled 46 func sysctlEnabled(name []byte) bool { 47 ret, value := getsysctlbyname(name) 48 if ret < 0 { 49 return false 50 } 51 return value > 0 52 } 53