Black Lives Matter. Support the Equal Justice Initiative.

Source file src/internal/cpu/cpu_arm64_darwin.go

Documentation: internal/cpu

     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  // +build arm64,darwin,!ios
     7  
     8  package cpu
     9  
    10  func osInit() {
    11  	ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00"))
    12  	ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00"))
    13  
    14  	// There are no hw.optional sysctl values for the below features on Mac OS 11.0
    15  	// to detect their supported state dynamically. Assume the CPU features that
    16  	// Apple Silicon M1 supports to be available as a minimal set of features
    17  	// to all Go programs running on darwin/arm64.
    18  	ARM64.HasAES = true
    19  	ARM64.HasPMULL = true
    20  	ARM64.HasSHA1 = true
    21  	ARM64.HasSHA2 = true
    22  }
    23  
    24  //go:noescape
    25  func getsysctlbyname(name []byte) (int32, int32)
    26  
    27  func sysctlEnabled(name []byte) bool {
    28  	ret, value := getsysctlbyname(name)
    29  	if ret < 0 {
    30  		return false
    31  	}
    32  	return value > 0
    33  }
    34  

View as plain text