From 47aad5a8e7632c2e2c7ff110f1ebfe67fae09812 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 8 Mar 2014 20:32:34 +0000 Subject: [PATCH] Replaced some win32 cpuid code. --- extras/Demo/Source/Demos/SystemInfoDemo.cpp | 1 + .../native/juce_win32_SystemStats.cpp | 99 +++++++++---------- 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/extras/Demo/Source/Demos/SystemInfoDemo.cpp b/extras/Demo/Source/Demos/SystemInfoDemo.cpp index 991d39cbb5..d006446556 100644 --- a/extras/Demo/Source/Demos/SystemInfoDemo.cpp +++ b/extras/Demo/Source/Demos/SystemInfoDemo.cpp @@ -114,6 +114,7 @@ static String getAllSystemInfo() << "CPU has MMX: " << (SystemStats::hasMMX() ? "yes" : "no") << newLine << "CPU has SSE: " << (SystemStats::hasSSE() ? "yes" : "no") << newLine << "CPU has SSE2: " << (SystemStats::hasSSE2() ? "yes" : "no") << newLine + << "CPU has SSE3: " << (SystemStats::hasSSE3() ? "yes" : "no") << newLine << "CPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no") << newLine << newLine << "Current working directory: " << File::getCurrentWorkingDirectory().getFullPathName() << newLine diff --git a/modules/juce_core/native/juce_win32_SystemStats.cpp b/modules/juce_core/native/juce_win32_SystemStats.cpp index 0098b46fe5..6bac9af041 100644 --- a/modules/juce_core/native/juce_win32_SystemStats.cpp +++ b/modules/juce_core/native/juce_win32_SystemStats.cpp @@ -45,10 +45,46 @@ void Logger::outputDebugString (const String& text) #pragma intrinsic (__cpuid) #pragma intrinsic (__rdtsc) +static void callCPUID (int result[4], int infoType) +{ + __cpuid (result, infoType); +} + +#else + +static void callCPUID (int result[4], int infoType) +{ + #if ! JUCE_MINGW + __try + #endif + { + #if JUCE_GCC + __asm__ __volatile__ ("cpuid" : "=a" (result[0]), "=b" (result[1]), "=c" (result[2]),"=d" (result[3]) : "a" (infoType)); + #else + __asm + { + mov esi, result + mov eax, infoType + xor ecx, ecx + cpuid + mov dword ptr [esi + 0], eax + mov dword ptr [esi + 4], ebx + mov dword ptr [esi + 8], ecx + mov dword ptr [esi + 12], edx + } + #endif + } + #if ! JUCE_MINGW + __except (EXCEPTION_EXECUTE_HANDLER) {} + #endif +} + +#endif + String SystemStats::getCpuVendor() { - int info [4]; - __cpuid (info, 0); + int info[4] = { 0 }; + callCPUID (info, 0); char v [12]; memcpy (v, info + 1, 4); @@ -58,59 +94,18 @@ String SystemStats::getCpuVendor() return String (v, 12); } -#else - -//============================================================================== -// CPU info functions using old fashioned inline asm... - -static void juce_getCpuVendor (char* const v) -{ - int vendor[4] = { 0 }; - - #if ! JUCE_MINGW - __try - #endif - { - #if JUCE_GCC - unsigned int dummy = 0; - __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0)); - #else - __asm - { - mov eax, 0 - cpuid - mov [vendor], ebx - mov [vendor + 4], edx - mov [vendor + 8], ecx - } - #endif - } - #if ! JUCE_MINGW - __except (EXCEPTION_EXECUTE_HANDLER) - { - } - #endif - - memcpy (v, vendor, 16); -} - -String SystemStats::getCpuVendor() -{ - char v [16]; - juce_getCpuVendor (v); - return String (v, 16); -} -#endif - - //============================================================================== void CPUInformation::initialise() noexcept { - hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0; - hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0; - hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0; - hasSSE3 = IsProcessorFeaturePresent (13 /*PF_SSE3_INSTRUCTIONS_AVAILABLE*/) != 0; - has3DNow = IsProcessorFeaturePresent (7 /*PF_AMD3D_INSTRUCTIONS_AVAILABLE*/) != 0; + int info[4] = { 0 }; + callCPUID (info, 1); + + // NB: IsProcessorFeaturePresent doesn't work on XP + hasMMX = (info[3] & (1 << 23)) != 0; + hasSSE = (info[3] & (1 << 25)) != 0; + hasSSE2 = (info[3] & (1 << 26)) != 0; + hasSSE3 = (info[2] & (1 << 0)) != 0; + has3DNow = (info[1] & (1 << 31)) != 0; SYSTEM_INFO systemInfo; GetNativeSystemInfo (&systemInfo);