tweak avx supported check
This commit is contained in:
parent
30dc604286
commit
bcf10cb899
1 changed files with 40 additions and 7 deletions
39
src/utils.c
39
src/utils.c
|
@ -13,6 +13,31 @@
|
||||||
|
|
||||||
BOOL util_is_avx_supported()
|
BOOL util_is_avx_supported()
|
||||||
{
|
{
|
||||||
|
const DWORD XMM_STATE_BIT = 1 << 1;
|
||||||
|
const DWORD YMM_STATE_BIT = 1 << 2;
|
||||||
|
const DWORD OS_AVX_BITS = XMM_STATE_BIT | YMM_STATE_BIT;
|
||||||
|
|
||||||
|
const DWORD AVX_BIT = 1 << 28;
|
||||||
|
const DWORD OSXSAVE_BIT = 1 << 27;
|
||||||
|
const DWORD XSAVE_BIT = 1 << 26;
|
||||||
|
const DWORD CPU_AVX_BITS = AVX_BIT | OSXSAVE_BIT | XSAVE_BIT;
|
||||||
|
|
||||||
|
BOOL result = FALSE;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int info[4] = { 0 };
|
||||||
|
__cpuid(info, 0);
|
||||||
|
|
||||||
|
if (info[0] >= 1)
|
||||||
|
{
|
||||||
|
__cpuid(info, 1);
|
||||||
|
|
||||||
|
if ((info[2] & CPU_AVX_BITS) == CPU_AVX_BITS)
|
||||||
|
{
|
||||||
unsigned int xcr0 = 0;
|
unsigned int xcr0 = 0;
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
@ -21,10 +46,18 @@ BOOL util_is_avx_supported()
|
||||||
__asm__("xgetbv" : "=a" (xcr0) : "c" (0) : "%edx");
|
__asm__("xgetbv" : "=a" (xcr0) : "c" (0) : "%edx");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int info[4] = { 0 };
|
result = (xcr0 & OS_AVX_BITS) == OS_AVX_BITS;
|
||||||
__cpuid(info, 1);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (info[2] & (1 << 27)) && (info[2] & (1 << 28)) && (xcr0 & 6);
|
#ifdef _MSC_VER
|
||||||
|
}
|
||||||
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void util_limit_game_ticks()
|
void util_limit_game_ticks()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue