Common: Fix AVX check on mingw/lower targets.

This commit is contained in:
Unknown W. Brackets committed 2021-02-14 10:30:10 -08:00
1 parent 622b078518
commit 7aa4b53422
1 file changed
+21 -14
+21 -14
View File
@@ -26,6 +26,7 @@
#include <sys/sysctl.h>
#endif
#include <cstdint>
#include <memory.h>
#include <set>
@@ -34,10 +35,9 @@
#include "Common/File/FileUtil.h"
#include "Common/StringUtils.h"
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
#include "Common/CommonWindows.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
#define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64
@@ -55,21 +55,27 @@ void do_cpuid(u32 regs[4], u32 cpuid_leaf) {
__cpuid((int *)regs, cpuid_leaf);
}
#ifdef __MINGW32__
static uint64_t do_xgetbv(unsigned int index) {
unsigned int eax, edx;
// This is xgetbv directly, so we can avoid compilers warning we need runtime checks.
asm(".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(index));
return ((uint64_t)edx << 32) | eax;
}
#else
#define do_xgetbv _xgetbv
#endif
#else // _WIN32
#ifdef _M_SSE
#include <emmintrin.h>
#define _XCR_XFEATURE_ENABLED_MASK 0
static unsigned long long _xgetbv(unsigned int index)
{
static uint64_t do_xgetbv(unsigned int index) {
unsigned int eax, edx;
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
return ((unsigned long long)edx << 32) | eax;
return ((uint64_t)edx << 32) | eax;
}
#else
#define _XCR_XFEATURE_ENABLED_MASK 0
#endif // _M_SSE
#if !defined(MIPS)
@@ -98,6 +104,9 @@ void do_cpuid(u32 regs[4], u32 cpuid_leaf)
#endif // !win32
#ifndef _XCR_XFEATURE_ENABLED_MASK
#define _XCR_XFEATURE_ENABLED_MASK 0
#endif
CPUInfo cpu_info;
@@ -215,10 +224,8 @@ void CPUInfo::Detect() {
// - Is the XSAVE bit set in CPUID? ( >>26)
// - Is the OSXSAVE bit set in CPUID? ( >>27)
// - XGETBV result has the XCR bit set.
if (((cpu_id[2] >> 28) & 1) && ((cpu_id[2] >> 27) & 1) && ((cpu_id[2] >> 26) & 1))
{
if ((_xgetbv(_XCR_XFEATURE_ENABLED_MASK) & 0x6) == 0x6)
{
if (((cpu_id[2] >> 28) & 1) && ((cpu_id[2] >> 27) & 1) && ((cpu_id[2] >> 26) & 1)) {
if ((do_xgetbv(_XCR_XFEATURE_ENABLED_MASK) & 0x6) == 0x6) {
bAVX = true;
if ((cpu_id[2] >> 12) & 1)
bFMA3 = true;