From 158fdbf62bde752fdee97e3f0fce0398087ce566 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 23 Nov 2012 17:48:58 +0100 Subject: [PATCH] Made inline-assembly more readable Former-commit-id: 82d94d3c7f314d7d8396c0a73a53d2ffea7b4d3c --- src/Nazara/Core/Win32/HardwareInfoImpl.cpp | 55 +++++++++++----------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Nazara/Core/Win32/HardwareInfoImpl.cpp b/src/Nazara/Core/Win32/HardwareInfoImpl.cpp index 089168d31..c50c06bae 100644 --- a/src/Nazara/Core/Win32/HardwareInfoImpl.cpp +++ b/src/Nazara/Core/Win32/HardwareInfoImpl.cpp @@ -15,13 +15,12 @@ void NzHardwareInfoImpl::Cpuid(nzUInt32 code, nzUInt32 result[4]) { #if defined(NAZARA_COMPILER_MSVC) - __cpuid(reinterpret_cast(result), static_cast(code)); + __cpuid(reinterpret_cast(result), static_cast(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 @@ -43,37 +42,37 @@ bool NzHardwareInfoImpl::IsCpuidSupported() __asm { pushfd - pop eax - mov ecx, eax - xor eax, 0x200000 - push eax + pop eax + mov ecx, eax + xor eax, 0x200000 + push eax popfd pushfd - pop eax - xor eax, ecx - mov supported, eax - push ecx + pop eax + xor eax, ecx + mov supported, eax + push ecx popfd }; return supported != 0; #elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) int supported; - asm volatile - (" pushfl\n" - " pop %%eax\n" - " mov %%eax, %%ecx\n" - " xor $0x200000, %%eax\n" - " push %%eax\n" - " popfl\n" - " pushfl\n" - " pop %%eax\n" - " xor %%ecx, %%eax\n" - " mov %%eax, %0\n" - " push %%ecx\n" - " popfl\n" - : "=m" (supported) - : :"eax", "ecx", "memory"); + asm volatile (" pushfl\n" + " pop %%eax\n" + " mov %%eax, %%ecx\n" + " xor $0x200000, %%eax\n" + " push %%eax\n" + " popfl\n" + " pushfl\n" + " pop %%eax\n" + " xor %%ecx, %%eax\n" + " mov %%eax, %0\n" + " push %%ecx\n" + " popfl" + : "=m" (supported) // output + : // input + : "eax", "ecx", "memory"); // clobbered register return supported != 0; #else