Made inline-assembly more readable

Former-commit-id: 82d94d3c7f314d7d8396c0a73a53d2ffea7b4d3c
This commit is contained in:
Lynix 2012-11-23 17:48:58 +01:00
parent f4591bd331
commit 158fdbf62b
1 changed files with 27 additions and 28 deletions

View File

@ -15,13 +15,12 @@
void NzHardwareInfoImpl::Cpuid(nzUInt32 code, nzUInt32 result[4]) void NzHardwareInfoImpl::Cpuid(nzUInt32 code, nzUInt32 result[4])
{ {
#if defined(NAZARA_COMPILER_MSVC) #if defined(NAZARA_COMPILER_MSVC)
__cpuid(reinterpret_cast<int*>(result), static_cast<int>(code)); __cpuid(reinterpret_cast<int*>(result), static_cast<int>(code)); // Visual propose une fonction intrinsèque pour le cpuid
#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)
// Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c // Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c
asm volatile asm volatile ("cpuid" // Besoin d'être volatile ?
("cpuid" : "=a" (result[0]), "=b" (result[1]), "=c" (result[2]), "=d" (result[3]) // output
:"=a" (result[0]), "=b" (result[1]), "=c" (result[2]), "=d" (result[3]) : "a" (code), "c" (0)); // input
:"a" (code), "c" (0));
#else #else
NazaraInternalError("Cpuid has been called although it is not supported"); NazaraInternalError("Cpuid has been called although it is not supported");
#endif #endif
@ -43,37 +42,37 @@ bool NzHardwareInfoImpl::IsCpuidSupported()
__asm __asm
{ {
pushfd pushfd
pop eax pop eax
mov ecx, eax mov ecx, eax
xor eax, 0x200000 xor eax, 0x200000
push eax push eax
popfd popfd
pushfd pushfd
pop eax pop eax
xor eax, ecx xor eax, ecx
mov supported, eax mov supported, eax
push ecx push ecx
popfd popfd
}; };
return supported != 0; return supported != 0;
#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)
int supported; int supported;
asm volatile asm volatile (" pushfl\n"
(" pushfl\n" " pop %%eax\n"
" pop %%eax\n" " mov %%eax, %%ecx\n"
" mov %%eax, %%ecx\n" " xor $0x200000, %%eax\n"
" xor $0x200000, %%eax\n" " push %%eax\n"
" push %%eax\n" " popfl\n"
" popfl\n" " pushfl\n"
" pushfl\n" " pop %%eax\n"
" pop %%eax\n" " xor %%ecx, %%eax\n"
" xor %%ecx, %%eax\n" " mov %%eax, %0\n"
" mov %%eax, %0\n" " push %%ecx\n"
" push %%ecx\n" " popfl"
" popfl\n" : "=m" (supported) // output
: "=m" (supported) : // input
: :"eax", "ecx", "memory"); : "eax", "ecx", "memory"); // clobbered register
return supported != 0; return supported != 0;
#else #else