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 ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00")) 13 ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00")) 14 ARM64.HasSHA512 = sysctlEnabled([]byte("hw.optional.armv8_2_sha512\x00")) 15 ARM64.HasDIT = sysctlEnabled([]byte("hw.optional.arm.FEAT_DIT\x00")) 16 17 // There are no hw.optional sysctl values for the below features on Mac OS 11.0 18 // to detect their supported state dynamically. Assume the CPU features that 19 // Apple Silicon M1 supports to be available as a minimal set of features 20 // to all Go programs running on darwin/arm64. 21 ARM64.HasAES = true 22 ARM64.HasPMULL = true 23 ARM64.HasSHA1 = true 24 ARM64.HasSHA2 = true 25 } 26 27 //go:noescape 28 func getsysctlbyname(name []byte) (int32, int32) 29 30 // sysctlEnabled should be an internal detail, 31 // but widely used packages access it using linkname. 32 // Notable members of the hall of shame include: 33 // - github.com/bytedance/gopkg 34 // - github.com/songzhibin97/gkit 35 // 36 // Do not remove or change the type signature. 37 // See go.dev/issue/67401. 38 // 39 //go:linkname sysctlEnabled 40 func sysctlEnabled(name []byte) bool { 41 ret, value := getsysctlbyname(name) 42 if ret < 0 { 43 return false 44 } 45 return value > 0 46 } 47