From 95b8fb312e5df8ce08a583c67f1e6d1e98985a21 Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Wed, 12 Jul 2023 11:44:08 -0400 Subject: [PATCH] windows/msvc: use high level processor feature detection API see https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent --- gpt4all-backend/llmodel.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gpt4all-backend/llmodel.cpp b/gpt4all-backend/llmodel.cpp index d7c721e2..24b424c5 100644 --- a/gpt4all-backend/llmodel.cpp +++ b/gpt4all-backend/llmodel.cpp @@ -10,6 +10,9 @@ #include #include #include +#ifdef _MSC_VER +#include +#endif std::string s_implementations_search_path = "."; @@ -18,9 +21,7 @@ static bool has_at_least_minimal_hardware() { #ifndef _MSC_VER return __builtin_cpu_supports("avx"); #else - int cpuInfo[4]; - __cpuid(cpuInfo, 1); - return cpuInfo[2] & (1 << 28); + return IsProcessorFeaturePresent(PF_AVX_INSTRUCTIONS_AVAILABLE); #endif #else return true; // Don't know how to handle non-x86_64 @@ -32,9 +33,7 @@ static bool requires_avxonly() { #ifndef _MSC_VER return !__builtin_cpu_supports("avx2"); #else - int cpuInfo[4]; - __cpuidex(cpuInfo, 7, 0); - return !(cpuInfo[1] & (1 << 5)); + return !IsProcessorFeaturePresent(PF_AVX2_INSTRUCTIONS_AVAILABLE); #endif #else return false; // Don't know how to handle non-x86_64