Core/HardwareInfo: Fix compilation for other arch than x86
This commit is contained in:
parent
71891b9788
commit
f034e71ba4
|
|
@ -11,26 +11,26 @@ namespace Nz
|
||||||
{
|
{
|
||||||
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
|
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
|
||||||
{
|
{
|
||||||
#if (defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)) && !defined(NAZARA_PLATFORM_WEB)
|
#if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) && (defined(NAZARA_ARCH_x86) || defined(NAZARA_ARCH_x86_64))
|
||||||
// https://en.wikipedia.org/wiki/CPUID
|
// https://en.wikipedia.org/wiki/CPUID
|
||||||
asm volatile(
|
asm volatile(
|
||||||
#ifdef NAZARA_ARCH_x86_64
|
#ifdef NAZARA_ARCH_x86_64
|
||||||
"pushq %%rbx \n\t" // save %rbx
|
"pushq %%rbx \n\t" // save %rbx
|
||||||
#else
|
#else
|
||||||
"pushl %%ebx \n\t" // save %ebx
|
"pushl %%ebx \n\t" // save %ebx
|
||||||
#endif
|
#endif
|
||||||
"cpuid \n\t"
|
"cpuid \n\t"
|
||||||
"movl %%ebx ,%[ebx] \n\t" // write the result into output var
|
"movl %%ebx ,%[ebx] \n\t" // write the result into output var
|
||||||
#ifdef NAZARA_ARCH_x86_64
|
#ifdef NAZARA_ARCH_x86_64
|
||||||
"popq %%rbx \n\t"
|
"popq %%rbx \n\t"
|
||||||
#else
|
#else
|
||||||
"popl %%ebx \n\t"
|
"popl %%ebx \n\t"
|
||||||
#endif
|
#endif
|
||||||
: "=a"(registers[0]), [ebx] "=r"(registers[1]), "=c"(registers[2]), "=d"(registers[3])
|
: "=a"(registers[0]), [ebx] "=r"(registers[1]), "=c"(registers[2]), "=d"(registers[3])
|
||||||
: "a"(functionId), "c" (subFunctionId));
|
: "a"(functionId), "c" (subFunctionId));
|
||||||
#else
|
#else
|
||||||
NazaraInternalError("Cpuid has been called although it is not supported");
|
NazaraInternalError("Cpuid has been called although it is not supported");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int HardwareInfoImpl::GetProcessorCount()
|
unsigned int HardwareInfoImpl::GetProcessorCount()
|
||||||
|
|
@ -49,12 +49,9 @@ namespace Nz
|
||||||
|
|
||||||
bool HardwareInfoImpl::IsCpuidSupported()
|
bool HardwareInfoImpl::IsCpuidSupported()
|
||||||
{
|
{
|
||||||
#ifdef NAZARA_ARCH_x86_64
|
#if defined(NAZARA_ARCH_x86_64)
|
||||||
return true; // cpuid is always supported on x64 arch
|
return true; // cpuid is always supported on x86_64 arch
|
||||||
#elif defined(NAZARA_PLATFORM_WEB)
|
#elif defined(NAZARA_ARCH_x86) && (defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL))
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
#if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
|
|
||||||
int supported;
|
int supported;
|
||||||
asm volatile (" pushfl\n"
|
asm volatile (" pushfl\n"
|
||||||
" pop %%eax\n"
|
" pop %%eax\n"
|
||||||
|
|
@ -73,9 +70,8 @@ namespace Nz
|
||||||
: "eax", "ecx", "memory"); // clobbered register
|
: "eax", "ecx", "memory"); // clobbered register
|
||||||
|
|
||||||
return supported != 0;
|
return supported != 0;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,31 +16,31 @@ namespace Nz
|
||||||
{
|
{
|
||||||
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
|
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_COMPILER_MSVC)
|
#if defined(NAZARA_COMPILER_MSVC) && (defined(NAZARA_ARCH_x86) || defined(NAZARA_ARCH_x86_64))
|
||||||
static_assert(sizeof(UInt32) == sizeof(int));
|
static_assert(sizeof(UInt32) == sizeof(int));
|
||||||
|
|
||||||
// Use intrinsic function if available
|
// Use intrinsic function if available
|
||||||
__cpuidex(reinterpret_cast<int*>(registers), static_cast<int>(functionId), static_cast<int>(subFunctionId));
|
__cpuidex(reinterpret_cast<int*>(registers), static_cast<int>(functionId), static_cast<int>(subFunctionId));
|
||||||
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
|
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) && (defined(NAZARA_ARCH_x86) || defined(NAZARA_ARCH_x86_64))
|
||||||
// https://en.wikipedia.org/wiki/CPUID
|
// https://en.wikipedia.org/wiki/CPUID
|
||||||
asm volatile(
|
asm volatile(
|
||||||
#ifdef NAZARA_ARCH_x86_64
|
#ifdef NAZARA_ARCH_x86_64
|
||||||
"pushq %%rbx \n\t" // save %rbx
|
"pushq %%rbx \n\t" // save %rbx
|
||||||
#else
|
#else
|
||||||
"pushl %%ebx \n\t" // save %ebx
|
"pushl %%ebx \n\t" // save %ebx
|
||||||
#endif
|
#endif
|
||||||
"cpuid \n\t"
|
"cpuid \n\t"
|
||||||
"movl %%ebx ,%[ebx] \n\t" // write the result into output var
|
"movl %%ebx ,%[ebx] \n\t" // write the result into output var
|
||||||
#ifdef NAZARA_ARCH_x86_64
|
#ifdef NAZARA_ARCH_x86_64
|
||||||
"popq %%rbx \n\t"
|
"popq %%rbx \n\t"
|
||||||
#else
|
#else
|
||||||
"popl %%ebx \n\t"
|
"popl %%ebx \n\t"
|
||||||
#endif
|
#endif
|
||||||
: "=a"(registers[0]), [ebx] "=r"(registers[1]), "=c"(registers[2]), "=d"(registers[3]) // output
|
: "=a"(registers[0]), [ebx] "=r"(registers[1]), "=c"(registers[2]), "=d"(registers[3]) // output
|
||||||
: "a"(functionId), "c" (subFunctionId)); // input
|
: "a"(functionId), "c" (subFunctionId)); // input
|
||||||
#else
|
#else
|
||||||
NazaraInternalError("Cpuid has been called although it is not supported");
|
NazaraInternalError("Cpuid has been called although it is not supported");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int HardwareInfoImpl::GetProcessorCount()
|
unsigned int HardwareInfoImpl::GetProcessorCount()
|
||||||
|
|
@ -63,9 +63,9 @@ namespace Nz
|
||||||
|
|
||||||
bool HardwareInfoImpl::IsCpuidSupported()
|
bool HardwareInfoImpl::IsCpuidSupported()
|
||||||
{
|
{
|
||||||
#ifdef NAZARA_ARCH_x86_64
|
#if defined(NAZARA_ARCH_x86_64)
|
||||||
return true; // cpuid is always supported on x64 arch
|
return true; // cpuid is always supported on x86_64 arch
|
||||||
#else
|
#elif defined(NAZARA_ARCH_x86)
|
||||||
#if defined(NAZARA_COMPILER_MSVC)
|
#if defined(NAZARA_COMPILER_MSVC)
|
||||||
int supported;
|
int supported;
|
||||||
__asm
|
__asm
|
||||||
|
|
@ -107,7 +107,9 @@ namespace Nz
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue