mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use __builtin_cpu_supports for AVX2 detection
This commit is contained in:
parent
f2d1cd418f
commit
06e139f4cb
|
@ -188,10 +188,10 @@ sint32 bitscanforward(sint32 source)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OPENRCT2_X86
|
#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)
|
#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;
|
return ret == 1;
|
||||||
#elif defined(OpenRCT2_CPUID_MSVC_X86)
|
#elif defined(OpenRCT2_CPUID_MSVC_X86)
|
||||||
__cpuid((int *)cpuid_outdata, (int)eax);
|
__cpuid((int *)cpuid_outdata, (int)eax);
|
||||||
|
@ -218,12 +218,20 @@ bool sse41_available()
|
||||||
bool avx2_available()
|
bool avx2_available()
|
||||||
{
|
{
|
||||||
#ifdef OPENRCT2_X86
|
#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).
|
// AVX2 support is declared as the 5th bit of EBX with CPUID(EAX = 7, ECX = 0).
|
||||||
uint32 regs[4] = { 0 };
|
uint32 regs[4] = { 0 };
|
||||||
if (cpuid_x86(regs, 7))
|
if (cpuid_x86(regs, 7))
|
||||||
{
|
{
|
||||||
return (regs[1] & (1 << 5));
|
return (regs[1] & (1 << 5));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue