Skip to content

Commit

Permalink
use windows version check instead
Browse files Browse the repository at this point in the history
  • Loading branch information
saucecontrol committed Dec 18, 2024
1 parent 87a70c4 commit 91ed568
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/native/minipal/cpufeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,34 @@ static bool IsApxEnabled()
}

#endif // defined(HOST_X86) || defined(HOST_AMD64)

#if defined(HOST_ARM64)
static bool IsWindows11OrGreater()
{
// Using RtlGetVersion since GetVersion call can be shimmed on Win8.1+.
typedef NTSTATUS (WINAPI *pFuncRtlGetVersion)(PRTL_OSVERSIONINFOW);

HMODULE hmodNtdll = LoadLibraryA("ntdll.dll");
if (hmodNtdll != NULL)
{
pFuncRtlGetVersion pRtlGetVersion = (pFuncRtlGetVersion)GetProcAddress(hmodNtdll, "RtlGetVersion");
if (pRtlGetVersion)
{
RTL_OSVERSIONINFOW osinfo;

ZeroMemory(&osinfo, sizeof(osinfo));
osinfo.dwOSVersionInfoSize = sizeof(osinfo);
if ((*pRtlGetVersion)(&osinfo) == 0)
{
return osinfo.dwMajorVersion >= 10 && osinfo.dwBuildNumber >= 22000;
}
}
}

return false;
}

#endif // HOST_ARM64
#endif // HOST_WINDOWS

int minipal_getcpufeatures(void)
Expand Down Expand Up @@ -475,6 +503,12 @@ int minipal_getcpufeatures(void)
// FP and SIMD support are enabled by default
result |= ARM64IntrinsicConstants_AdvSimd;

// RDM does not have an IsProcessorFeaturePresent flag, but it is a requirement for Windows 11
if (IsWindows11OrGreater())
{
result |= ARM64IntrinsicConstants_Rdm;
}

if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE))
{
result |= ARM64IntrinsicConstants_Aes;
Expand All @@ -495,7 +529,6 @@ int minipal_getcpufeatures(void)
if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE))
{
result |= ARM64IntrinsicConstants_Dp;
result |= ARM64IntrinsicConstants_Rdm;
}

if (IsProcessorFeaturePresent(PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE))
Expand Down

0 comments on commit 91ed568

Please sign in to comment.