Skip to content

Commit fc646e4

Browse files
committed
cpu: use IsProcessorFeaturePresent to calculate ARM64 on windows
For golang/go#76791 Change-Id: I9500b38b17b5e3e141df8770d82c725c2ba8fd65 Cq-Include-Trybots: luci.golang.try:x_sys-gotip-windows-arm64 Reviewed-on: https://go-review.googlesource.com/c/sys/+/740880 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Quim Muntal <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent f11c7bb commit fc646e4

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

cpu/cpu_arm64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func archInit() {
4747
switch runtime.GOOS {
4848
case "freebsd":
4949
readARM64Registers()
50-
case "linux", "netbsd", "openbsd":
50+
case "linux", "netbsd", "openbsd", "windows":
5151
doinit()
5252
default:
5353
// Many platforms don't seem to allow reading these registers.

cpu/cpu_other_arm64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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 && arm64
5+
//go:build !linux && !netbsd && !openbsd && !windows && arm64
66

77
package cpu
88

cpu/cpu_windows_arm64.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 (
8+
"golang.org/x/sys/windows"
9+
)
10+
11+
func doinit() {
12+
// set HasASIMD and HasFP to true as per
13+
// https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#base-requirements
14+
//
15+
// The ARM64 version of Windows always presupposes that it's running on an ARMv8 or later architecture.
16+
// Both floating-point and NEON support are presumed to be present in hardware.
17+
//
18+
ARM64.HasASIMD = true
19+
ARM64.HasFP = true
20+
21+
if windows.IsProcessorFeaturePresent(windows.PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) {
22+
ARM64.HasAES = true
23+
ARM64.HasPMULL = true
24+
ARM64.HasSHA1 = true
25+
ARM64.HasSHA2 = true
26+
}
27+
ARM64.HasSHA3 = windows.IsProcessorFeaturePresent(windows.PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE)
28+
ARM64.HasCRC32 = windows.IsProcessorFeaturePresent(windows.PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)
29+
ARM64.HasSHA512 = windows.IsProcessorFeaturePresent(windows.PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE)
30+
ARM64.HasATOMICS = windows.IsProcessorFeaturePresent(windows.PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE)
31+
if windows.IsProcessorFeaturePresent(windows.PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE) {
32+
ARM64.HasASIMDDP = true
33+
ARM64.HasASIMDRDM = true
34+
}
35+
if windows.IsProcessorFeaturePresent(windows.PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE) {
36+
ARM64.HasLRCPC = true
37+
ARM64.HasSM3 = true
38+
}
39+
ARM64.HasSVE = windows.IsProcessorFeaturePresent(windows.PF_ARM_SVE_INSTRUCTIONS_AVAILABLE)
40+
ARM64.HasSVE2 = windows.IsProcessorFeaturePresent(windows.PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE)
41+
ARM64.HasJSCVT = windows.IsProcessorFeaturePresent(windows.PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE)
42+
}

0 commit comments

Comments
 (0)