--- a/src/internal/cpu/cpu_arm64_other.go +++ b/src/internal/cpu/cpu_arm64_other.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd +//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd && !windows package cpu --- a/src/internal/cpu/cpu_arm64_windows.go +++ b/src/internal/cpu/cpu_arm64_windows.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. + +//go:build arm64 + +package cpu + +func osInit() { + // TODO(brainman): we don't know how to retrieve those bits form user space - leaving them as false for now + // https://github.com/golang/go/issues/76791#issuecomment-3877873959 + ARM64.HasCPUID = false + ARM64.HasDIT = false + ARM64.IsNeoverse = false + + if isProcessorFeaturePresent(_PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) { + ARM64.HasAES = true + ARM64.HasPMULL = true + ARM64.HasSHA1 = true + ARM64.HasSHA2 = true + } + ARM64.HasSHA3 = isProcessorFeaturePresent(_PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE) + ARM64.HasCRC32 = isProcessorFeaturePresent(_PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) + ARM64.HasSHA512 = isProcessorFeaturePresent(_PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE) + ARM64.HasATOMICS = isProcessorFeaturePresent(_PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE) +} --- a/src/internal/cpu/cpu_windows.go +++ b/src/internal/cpu/cpu_windows.go @@ -0,0 +1,20 @@ +// 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 _ "unsafe" // for linkname + +const ( + _PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE = 30 + _PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE = 31 + _PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE = 34 + _PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE = 64 + _PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE = 65 +) + +// isProcessorFeaturePresent calls windows IsProcessorFeaturePresent API. +// +//go:linkname isProcessorFeaturePresent +func isProcessorFeaturePresent(processorFeature uint32) bool // Implemented in runtime package. --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -39,6 +39,7 @@ const ( //go:cgo_import_dynamic runtime._GetSystemDirectoryA GetSystemDirectoryA%2 "kernel32.dll" //go:cgo_import_dynamic runtime._GetSystemInfo GetSystemInfo%1 "kernel32.dll" //go:cgo_import_dynamic runtime._GetThreadContext GetThreadContext%2 "kernel32.dll" +//go:cgo_import_dynamic runtime._IsProcessorFeaturePresent IsProcessorFeaturePresent%1 "kernel32.dll" //go:cgo_import_dynamic runtime._SetThreadContext SetThreadContext%2 "kernel32.dll" //go:cgo_import_dynamic runtime._LoadLibraryExW LoadLibraryExW%3 "kernel32.dll" //go:cgo_import_dynamic runtime._PostQueuedCompletionStatus PostQueuedCompletionStatus%4 "kernel32.dll" @@ -96,6 +97,7 @@ var ( _GetSystemDirectoryA, _GetSystemInfo, _GetThreadContext, + _IsProcessorFeaturePresent, _SetThreadContext, _LoadLibraryExW, _PostQueuedCompletionStatus, @@ -261,6 +263,12 @@ func windows_QueryPerformanceFrequency() int64 { return frequency } +//go:linkname cpu_isProcessorFeaturePresent internal/cpu.isProcessorFeaturePresent +func cpu_isProcessorFeaturePresent(processorFeature uint32) bool { + ret := stdcall(_IsProcessorFeaturePresent, uintptr(processorFeature)) + return ret != 0 +} + func loadOptionalSyscalls() { bcryptPrimitives := windowsLoadSystemLib(bcryptprimitivesdll[:]) if bcryptPrimitives == 0 {