Skip to content

Commit 54fe89f

Browse files
committed
cpu: use IsProcessorFeaturePresent to calculate ARM64 on windows
This CL started as revert of CL 757482. Fixes golang/go#76791 Change-Id: Iaa78c73a6dde8d735e74e2c57c86375ccd5902c7 Reviewed-on: https://go-review.googlesource.com/c/sys/+/758960 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent df7d5d7 commit 54fe89f

4 files changed

Lines changed: 113 additions & 1 deletion

File tree

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 !darwin && !linux && !netbsd && !openbsd && arm64
5+
//go:build !darwin && !linux && !netbsd && !openbsd && !windows && arm64
66

77
package cpu
88

cpu/cpu_windows.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+
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -systemdll=false -output zcpu_windows.go cpu_windows.go
8+
9+
//sys isProcessorFeaturePresent(ProcessorFeature uint32) (ret bool) = kernel32.IsProcessorFeaturePresent
10+
11+
// The processor features to be tested for IsProcessorFeaturePresent, see
12+
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
13+
const (
14+
_PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE = 30
15+
_PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE = 31
16+
_PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE = 34
17+
_PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE = 43
18+
19+
_PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE = 44
20+
_PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE = 45
21+
_PF_ARM_SVE_INSTRUCTIONS_AVAILABLE = 46
22+
_PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE = 47
23+
24+
_PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE = 64
25+
_PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE = 65
26+
)

cpu/cpu_windows_arm64.go

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

cpu/zcpu_windows.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)