Use __builtin_cpu_supports for AVX2 detection

This commit is contained in:
Michał Janiszewski 2018-02-10 13:44:17 +01:00 committed by Michał Janiszewski
parent f2d1cd418f
commit 06e139f4cb
1 changed files with 10 additions and 2 deletions

View File

@ -188,10 +188,10 @@ sint32 bitscanforward(sint32 source)
#endif
#ifdef OPENRCT2_X86
static bool cpuid_x86(uint32 * cpuid_outdata, sint32 eax, sint32 ecx = 0)
static bool cpuid_x86(uint32 * cpuid_outdata, sint32 eax)
{
#if defined(OpenRCT2_CPUID_GNUC_X86)
int ret = __get_cpuid_count(eax, ecx, &cpuid_outdata[0], &cpuid_outdata[1], &cpuid_outdata[2], &cpuid_outdata[3]);
int ret = __get_cpuid(eax, &cpuid_outdata[0], &cpuid_outdata[1], &cpuid_outdata[2], &cpuid_outdata[3]);
return ret == 1;
#elif defined(OpenRCT2_CPUID_MSVC_X86)
__cpuid((int *)cpuid_outdata, (int)eax);
@ -218,12 +218,20 @@ bool sse41_available()
bool avx2_available()
{
#ifdef OPENRCT2_X86
// For GCC and similar use the builtin function, as cpuid changed its semantics in
// https://github.com/gcc-mirror/gcc/commit/132fa33ce998df69a9f793d63785785f4b93e6f1
// which causes it to ignore subleafs, but the new function is unavailable on Ubuntu's
// prehistoric toolchains
#if defined(OpenRCT2_CPUID_GNUC_X86)
return __builtin_cpu_supports("avx2");
#else
// AVX2 support is declared as the 5th bit of EBX with CPUID(EAX = 7, ECX = 0).
uint32 regs[4] = { 0 };
if (cpuid_x86(regs, 7))
{
return (regs[1] & (1 << 5));
}
#endif
#endif
return false;
}