Skip to content

Commit 3687fbd

Browse files
ncrucesgopherbot
authored andcommitted
cpu: better defaults on darwin ARM64
This is motivated by wazero/wazero#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: d5d0f1e GitHub-Pull-Request: #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>
1 parent 48062e9 commit 3687fbd

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

cpu/cpu_arm64.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ func initOptions() {
4444
}
4545

4646
func archInit() {
47-
switch runtime.GOOS {
48-
case "freebsd":
47+
if runtime.GOOS == "freebsd" {
4948
readARM64Registers()
50-
case "linux", "netbsd", "openbsd", "windows":
49+
} else {
50+
// Most platforms don't seem to allow directly reading these registers.
5151
doinit()
52-
default:
53-
// Many platforms don't seem to allow reading these registers.
54-
setMinimalFeatures()
5552
}
5653
}
5754

cpu/cpu_darwin_arm64.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2026 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+
package cpu
6+
7+
import "runtime"
8+
9+
func doinit() {
10+
ARM64.HasASIMD = true
11+
ARM64.HasFP = true
12+
13+
if runtime.GOOS != "ios" {
14+
// M-series SoCs are at least armv8.4-a
15+
ARM64.HasCRC32 = true // armv8.1
16+
ARM64.HasATOMICS = true // armv8.2
17+
ARM64.HasJSCVT = true // armv8.3, if HasFP
18+
19+
// Go already assumes these to be available
20+
// because they were on the M1.
21+
ARM64.HasAES = true
22+
ARM64.HasPMULL = true
23+
ARM64.HasSHA1 = true
24+
ARM64.HasSHA2 = true
25+
}
26+
}

cpu/cpu_gccgo_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ package cpu
99
func getisar0() uint64 { return 0 }
1010
func getisar1() uint64 { return 0 }
1111
func getpfr0() uint64 { return 0 }
12+
func getzfr0() uint64 { return 0 }

cpu/cpu_other_arm64.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !linux && !netbsd && !openbsd && !windows && arm64
5+
//go:build !linux && !netbsd && !openbsd && !windows && !darwin && arm64
66

77
package cpu
88

9-
func doinit() {}
9+
func doinit() {
10+
setMinimalFeatures()
11+
}

0 commit comments

Comments
 (0)