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])
{
#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)
// Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c
asm volatile
("cpuid"
:"=a" (result[0]), "=b" (result[1]), "=c" (result[2]), "=d" (result[3])
:"a" (code), "c" (0));
asm volatile ("cpuid" // Besoin d'être volatile ?
: "=a" (result[0]), "=b" (result[1]), "=c" (result[2]), "=d" (result[3]) // output
: "a" (code), "c" (0)); // input
#else
NazaraInternalError("Cpuid has been called although it is not supported");
#endif
@ -59,8 +58,7 @@ bool NzHardwareInfoImpl::IsCpuidSupported()
return supported != 0;
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
int supported;
asm volatile
(" pushfl\n"
asm volatile (" pushfl\n"
" pop %%eax\n"
" mov %%eax, %%ecx\n"
" xor $0x200000, %%eax\n"
@ -71,9 +69,10 @@ bool NzHardwareInfoImpl::IsCpuidSupported()
" xor %%ecx, %%eax\n"
" mov %%eax, %0\n"
" push %%ecx\n"
" popfl\n"
: "=m" (supported)
: :"eax", "ecx", "memory");
" popfl"
: "=m" (supported) // output
: // input
: "eax", "ecx", "memory"); // clobbered register
return supported != 0;
#else