From 3687fbd71652878ab091f7272b84537b63fe0b55 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 9 Feb 2026 22:47:18 +0000 Subject: [PATCH] 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 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Junyang Shao --- cpu/cpu_arm64.go | 9 +++------ cpu/cpu_darwin_arm64.go | 26 ++++++++++++++++++++++++++ cpu/cpu_gccgo_arm64.go | 1 + cpu/cpu_other_arm64.go | 6 ++++-- 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 cpu/cpu_darwin_arm64.go diff --git a/cpu/cpu_arm64.go b/cpu/cpu_arm64.go index 6d8eb784..5fc09e29 100644 --- a/cpu/cpu_arm64.go +++ b/cpu/cpu_arm64.go @@ -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() } } diff --git a/cpu/cpu_darwin_arm64.go b/cpu/cpu_darwin_arm64.go new file mode 100644 index 00000000..30ee0f29 --- /dev/null +++ b/cpu/cpu_darwin_arm64.go @@ -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 + } +} diff --git a/cpu/cpu_gccgo_arm64.go b/cpu/cpu_gccgo_arm64.go index 7f194678..05913081 100644 --- a/cpu/cpu_gccgo_arm64.go +++ b/cpu/cpu_gccgo_arm64.go @@ -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 } diff --git a/cpu/cpu_other_arm64.go b/cpu/cpu_other_arm64.go index ff74d7af..c604824a 100644 --- a/cpu/cpu_other_arm64.go +++ b/cpu/cpu_other_arm64.go @@ -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() +}