Browse Source

Replaced some win32 cpuid code.

tags/2021-05-28
jules 11 years ago
parent
commit
47aad5a8e7
2 changed files with 33 additions and 37 deletions
  1. +1
    -0
      extras/Demo/Source/Demos/SystemInfoDemo.cpp
  2. +32
    -37
      modules/juce_core/native/juce_win32_SystemStats.cpp

+ 1
- 0
extras/Demo/Source/Demos/SystemInfoDemo.cpp View File

@@ -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


+ 32
- 37
modules/juce_core/native/juce_win32_SystemStats.cpp View File

@@ -45,72 +45,67 @@ void Logger::outputDebugString (const String& text)
#pragma intrinsic (__cpuid)
#pragma intrinsic (__rdtsc)
String SystemStats::getCpuVendor()
static void callCPUID (int result[4], int infoType)
{
int info [4];
__cpuid (info, 0);
char v [12];
memcpy (v, info + 1, 4);
memcpy (v + 4, info + 3, 4);
memcpy (v + 8, info + 2, 4);
return String (v, 12);
__cpuid (result, infoType);
}
#else
//==============================================================================
// CPU info functions using old fashioned inline asm...
static void juce_getCpuVendor (char* const v)
static void callCPUID (int result[4], int infoType)
{
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));
__asm__ __volatile__ ("cpuid" : "=a" (result[0]), "=b" (result[1]), "=c" (result[2]),"=d" (result[3]) : "a" (infoType));
#else
__asm
{
mov eax, 0
mov esi, result
mov eax, infoType
xor ecx, ecx
cpuid
mov [vendor], ebx
mov [vendor + 4], edx
mov [vendor + 8], ecx
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)
{
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
#endif
memcpy (v, vendor, 16);
}
#endif
String SystemStats::getCpuVendor()
{
char v [16];
juce_getCpuVendor (v);
return String (v, 16);
}
#endif
int info[4] = { 0 };
callCPUID (info, 0);
char v [12];
memcpy (v, info + 1, 4);
memcpy (v + 4, info + 3, 4);
memcpy (v + 8, info + 2, 4);
return String (v, 12);
}
//==============================================================================
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);


Loading…
Cancel
Save