diff --git a/src/Nazara/Core/Posix/HardwareInfoImpl.cpp b/src/Nazara/Core/Posix/HardwareInfoImpl.cpp index 0058832a8..20ea4950f 100644 --- a/src/Nazara/Core/Posix/HardwareInfoImpl.cpp +++ b/src/Nazara/Core/Posix/HardwareInfoImpl.cpp @@ -11,10 +11,22 @@ namespace Nz void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4]) { #if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) - // Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c - asm volatile ("cpuid" // Besoin d'être volatile ? - : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) // output - : "a" (functionId), "c" (subFunctionId)); // input + // https://en.wikipedia.org/wiki/CPUID + asm volatile( + #ifdef NAZARA_PLATFORM_x64 + "pushq %%rbx \n\t" // save %rbx + #else + "pushl %%ebx \n\t" // save %ebx + #endif + "cpuid \n\t" + "movl %%ebx ,%[ebx] \n\t" // write the result into output var + #ifdef NAZARA_PLATFORM_x64 + "popq %%rbx \n\t" + #else + "popl %%ebx \n\t" + #endif + : "=a"(registers[0]), [ebx] "=r"(registers[1]), "=c"(registers[2]), "=d"(registers[3]) + : "a"(functionId), "c" (subFunctionId)); #else NazaraInternalError("Cpuid has been called although it is not supported"); #endif @@ -22,7 +34,7 @@ namespace Nz unsigned int HardwareInfoImpl::GetProcessorCount() { - // Plus simple (et plus portable) que de passer par le CPUID + // Simpler (and more portable) than using CPUID return sysconf(_SC_NPROCESSORS_CONF); } @@ -37,7 +49,7 @@ namespace Nz bool HardwareInfoImpl::IsCpuidSupported() { #ifdef NAZARA_PLATFORM_x64 - return true; // Toujours supporté sur un processeur 64 bits + return true; // cpuid is always supported on x64 arch #else #if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) int supported; diff --git a/src/Nazara/Core/Win32/HardwareInfoImpl.cpp b/src/Nazara/Core/Win32/HardwareInfoImpl.cpp index 62b86bf91..542c58d79 100644 --- a/src/Nazara/Core/Win32/HardwareInfoImpl.cpp +++ b/src/Nazara/Core/Win32/HardwareInfoImpl.cpp @@ -22,10 +22,22 @@ namespace Nz // Visual propose une fonction intrinsèque pour le cpuid __cpuidex(reinterpret_cast(registers), static_cast(functionId), static_cast(subFunctionId)); #elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) - // Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c - asm volatile ("cpuid" // Besoin d'être volatile ? - : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]) // output - : "a" (functionId), "c" (subFunctionId)); // input + // https://en.wikipedia.org/wiki/CPUID + asm volatile( + #ifdef NAZARA_PLATFORM_x64 + "pushq %%rbx \n\t" // save %rbx + #else + "pushl %%ebx \n\t" // save %ebx + #endif + "cpuid \n\t" + "movl %%ebx ,%[ebx] \n\t" // write the result into output var + #ifdef NAZARA_PLATFORM_x64 + "popq %%rbx \n\t" + #else + "popl %%ebx \n\t" + #endif + : "=a"(registers[0]), [ebx] "=r"(registers[1]), "=c"(registers[2]), "=d"(registers[3]) // output + : "a"(functionId), "c" (subFunctionId)); // input #else NazaraInternalError("Cpuid has been called although it is not supported"); #endif @@ -33,7 +45,7 @@ namespace Nz unsigned int HardwareInfoImpl::GetProcessorCount() { - // Plus simple (et plus portable) que de passer par le CPUID + // Simpler (and more portable) than using CPUID SYSTEM_INFO infos; GetNativeSystemInfo(&infos); @@ -52,7 +64,7 @@ namespace Nz bool HardwareInfoImpl::IsCpuidSupported() { #ifdef NAZARA_PLATFORM_x64 - return true; // Toujours supporté sur un processeur 64 bits + return true; // cpuid is always supported on x64 arch #else #if defined(NAZARA_COMPILER_MSVC) int supported;