cpu: better defaults on darwin ARM64

This is motivated by
https://github.com/wazero/wazero/pull/2473
which needs to special case darwin for testing the availability of
HasATOMICS, although all M-series CPUs support it.

We could do sysctlbyname, like syscall_darwin_x86_gc.go, if that's
preferred:
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics

Change-Id: I0f5ea55ef5cda4956db44b2d40f2f10044fa3321
GitHub-Last-Rev: d5d0f1e989579de2a25c97c00c7e9db5d4b0cb29
GitHub-Pull-Request: golang/sys#267
Reviewed-on: https://go-review.googlesource.com/c/sys/+/743320
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
This commit is contained in:
Nuno Cruces
2026-02-12 09:29:35 -08:00
committed by Gopher Robot
parent 48062e9b9a
commit 3687fbd716
4 changed files with 34 additions and 8 deletions
+3 -6
View File
@@ -44,14 +44,11 @@ func initOptions() {
}
func archInit() {
switch runtime.GOOS {
case "freebsd":
if runtime.GOOS == "freebsd" {
readARM64Registers()
case "linux", "netbsd", "openbsd", "windows":
} else {
// Most platforms don't seem to allow directly reading these registers.
doinit()
default:
// Many platforms don't seem to allow reading these registers.
setMinimalFeatures()
}
}
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cpu
import "runtime"
func doinit() {
ARM64.HasASIMD = true
ARM64.HasFP = true
if runtime.GOOS != "ios" {
// M-series SoCs are at least armv8.4-a
ARM64.HasCRC32 = true // armv8.1
ARM64.HasATOMICS = true // armv8.2
ARM64.HasJSCVT = true // armv8.3, if HasFP
// Go already assumes these to be available
// because they were on the M1.
ARM64.HasAES = true
ARM64.HasPMULL = true
ARM64.HasSHA1 = true
ARM64.HasSHA2 = true
}
}
+1
View File
@@ -9,3 +9,4 @@ package cpu
func getisar0() uint64 { return 0 }
func getisar1() uint64 { return 0 }
func getpfr0() uint64 { return 0 }
func getzfr0() uint64 { return 0 }
+4 -2
View File
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !linux && !netbsd && !openbsd && !windows && arm64
//go:build !linux && !netbsd && !openbsd && !windows && !darwin && arm64
package cpu
func doinit() {}
func doinit() {
setMinimalFeatures()
}