From 6052da3c4399514c95245b2d342f04baa20958db Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 15:03:43 +0700 Subject: [PATCH] #951 Fix AVX detection. --- src/common/cpu/BasicCpuInfo.cpp | 15 ++++++++++++++- src/core/cpu/AdvancedCpuInfo.cpp | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/cpu/BasicCpuInfo.cpp b/src/common/cpu/BasicCpuInfo.cpp index e9018c98a..d7778bdde 100644 --- a/src/common/cpu/BasicCpuInfo.cpp +++ b/src/common/cpu/BasicCpuInfo.cpp @@ -36,6 +36,10 @@ # define bit_AES (1 << 25) #endif +#ifndef bit_OSXSAVE +# define bit_OSXSAVE (1 << 27) +#endif + #ifndef bit_AVX2 # define bit_AVX2 (1 << 5) #endif @@ -107,10 +111,19 @@ static inline bool has_avx2() } +static inline bool has_ossave() +{ + int32_t cpu_info[4] = { 0 }; + cpuid(PROCESSOR_INFO, cpu_info); + + return (cpu_info[ECX_Reg] & bit_OSXSAVE) != 0; +} + + xmrig::BasicCpuInfo::BasicCpuInfo() : m_assembly(ASM_NONE), m_aes(has_aes_ni()), - m_avx2(has_avx2()), + m_avx2(has_avx2() && has_ossave()), m_brand(), m_threads(std::thread::hardware_concurrency()) { diff --git a/src/core/cpu/AdvancedCpuInfo.cpp b/src/core/cpu/AdvancedCpuInfo.cpp index c41378e53..df6a385ee 100644 --- a/src/core/cpu/AdvancedCpuInfo.cpp +++ b/src/core/cpu/AdvancedCpuInfo.cpp @@ -85,7 +85,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : } } - m_avx2 = data.flags[CPU_FEATURE_AVX2]; + m_avx2 = data.flags[CPU_FEATURE_AVX2] && data.flags[CPU_FEATURE_OSXSAVE]; }