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

View as plain text