Skip to content

Commit d5d0f1e

Browse files
committed
cpu: better defaults on darwin ARM64
1 parent fc646e4 commit d5d0f1e

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)