From e6b4dcb6a24b6b50d4dca36b3c2c8bb1b4638b90 Mon Sep 17 00:00:00 2001 From: hogliux Date: Tue, 26 Jan 2016 10:06:30 +0000 Subject: [PATCH] Add SSE4.1, SSE4.2 and AVX2 system stat flags and fix documentation typo --- examples/Demo/Source/Demos/SystemInfoDemo.cpp | 23 +++++++++++-------- .../native/juce_linux_SystemStats.cpp | 3 +++ .../juce_core/native/juce_mac_SystemStats.mm | 5 ++++ .../native/juce_win32_SystemStats.cpp | 6 +++++ modules/juce_core/system/juce_SystemStats.cpp | 8 +++++-- modules/juce_core/system/juce_SystemStats.h | 17 ++++++++------ 6 files changed, 44 insertions(+), 18 deletions(-) diff --git a/examples/Demo/Source/Demos/SystemInfoDemo.cpp b/examples/Demo/Source/Demos/SystemInfoDemo.cpp index ab383ecce9..f1fa50e639 100644 --- a/examples/Demo/Source/Demos/SystemInfoDemo.cpp +++ b/examples/Demo/Source/Demos/SystemInfoDemo.cpp @@ -120,15 +120,20 @@ static String getAllSystemInfo() << "User language: " << SystemStats::getUserLanguage() << newLine << "Display language: " << SystemStats::getDisplayLanguage() << newLine << newLine - << "Number of CPUs: " << SystemStats::getNumCpus() << newLine - << "Memory size: " << SystemStats::getMemorySizeInMegabytes() << " MB" << newLine - << "CPU vendor: " << SystemStats::getCpuVendor() << newLine - << "CPU speed: " << SystemStats::getCpuSpeedInMegaherz() << " MHz" << newLine - << "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 + << "Number of CPUs: " << SystemStats::getNumCpus() << newLine + << "Memory size: " << SystemStats::getMemorySizeInMegabytes() << " MB" << newLine + << "CPU vendor: " << SystemStats::getCpuVendor() << newLine + << "CPU speed: " << SystemStats::getCpuSpeedInMegaherz() << " MHz" << newLine + << "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 SSSE3: " << (SystemStats::hasSSSE3() ? "yes" : "no") << newLine + << "CPU has SSE4.1: " << (SystemStats::hasSSE41() ? "yes" : "no") << newLine + << "CPU has SSE4.2: " << (SystemStats::hasSSE42() ? "yes" : "no") << newLine + << "CPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no") << newLine + << "CPU has AVX: " << (SystemStats::hasAVX() ? "yes" : "no") << newLine + << "CPU has AVX2: " << (SystemStats::hasAVX2() ? "yes" : "no") << newLine << newLine << "Current working directory: " << File::getCurrentWorkingDirectory().getFullPathName() << newLine << "Current application file: " << File::getSpecialLocation (File::currentApplicationFile).getFullPathName() << newLine diff --git a/modules/juce_core/native/juce_linux_SystemStats.cpp b/modules/juce_core/native/juce_linux_SystemStats.cpp index 85062bf2e3..b7665f825a 100644 --- a/modules/juce_core/native/juce_linux_SystemStats.cpp +++ b/modules/juce_core/native/juce_linux_SystemStats.cpp @@ -156,7 +156,10 @@ void CPUInformation::initialise() noexcept hasSSE3 = flags.contains ("sse3"); has3DNow = flags.contains ("3dnow"); hasSSSE3 = flags.contains ("ssse3"); + hasSSE41 = flags.contains ("sse4_1"); + hasSSE42 = flags.contains ("sse4_2"); hasAVX = flags.contains ("avx"); + hasAVX2 = flags.contains ("avx2"); numCpus = LinuxStatsHelpers::getCpuInfo ("processor").getIntValue() + 1; } diff --git a/modules/juce_core/native/juce_mac_SystemStats.mm b/modules/juce_core/native/juce_mac_SystemStats.mm index 0767a76066..28589dc4ef 100644 --- a/modules/juce_core/native/juce_mac_SystemStats.mm +++ b/modules/juce_core/native/juce_mac_SystemStats.mm @@ -81,7 +81,12 @@ void CPUInformation::initialise() noexcept has3DNow = (b & (1u << 31)) != 0; hasSSE3 = (c & (1u << 0)) != 0; hasSSSE3 = (c & (1u << 9)) != 0; + hasSSE41 = (c & (1u << 20)) != 0; + hasSSE42 = (c & (1u << 19)) != 0; hasAVX = (c & (1u << 28)) != 0; + + SystemStatsHelpers::doCPUID (a, b, c, d, 7); + hasAVX2 = (b & (1u << 5)) != 0; #endif numCpus = (int) [[NSProcessInfo processInfo] activeProcessorCount]; diff --git a/modules/juce_core/native/juce_win32_SystemStats.cpp b/modules/juce_core/native/juce_win32_SystemStats.cpp index fee1b764ef..eb4c45ba83 100644 --- a/modules/juce_core/native/juce_win32_SystemStats.cpp +++ b/modules/juce_core/native/juce_win32_SystemStats.cpp @@ -107,8 +107,14 @@ void CPUInformation::initialise() noexcept hasSSE3 = (info[2] & (1 << 0)) != 0; hasAVX = (info[2] & (1 << 28)) != 0; hasSSSE3 = (info[2] & (1 << 9)) != 0; + hasSSE41 = (info[2] & (1 << 19)) != 0; + hasSSE42 = (info[2] & (1 << 20)) != 0; has3DNow = (info[1] & (1 << 31)) != 0; + callCPUID (info, 7); + + hasAVX2 = (info[1] & (1 << 5)) != 0; + SYSTEM_INFO systemInfo; GetNativeSystemInfo (&systemInfo); numCpus = (int) systemInfo.dwNumberOfProcessors; diff --git a/modules/juce_core/system/juce_SystemStats.cpp b/modules/juce_core/system/juce_SystemStats.cpp index 65bb117cba..598fd871dd 100644 --- a/modules/juce_core/system/juce_SystemStats.cpp +++ b/modules/juce_core/system/juce_SystemStats.cpp @@ -68,7 +68,8 @@ struct CPUInformation CPUInformation() noexcept : numCpus (0), hasMMX (false), hasSSE (false), hasSSE2 (false), hasSSE3 (false), has3DNow (false), - hasSSSE3 (false), hasAVX (false) + hasSSSE3 (false), hasSSE41 (false), hasSSE42 (false), + hasAVX (false), hasAVX2 (false) { initialise(); } @@ -76,7 +77,7 @@ struct CPUInformation void initialise() noexcept; int numCpus; - bool hasMMX, hasSSE, hasSSE2, hasSSE3, has3DNow, hasSSSE3, hasAVX; + bool hasMMX, hasSSE, hasSSE2, hasSSE3, has3DNow, hasSSSE3, hasSSE41, hasSSE42, hasAVX, hasAVX2; }; static const CPUInformation& getCPUInformation() noexcept @@ -92,7 +93,10 @@ bool SystemStats::hasSSE() noexcept { return getCPUInformation().hasSS bool SystemStats::hasSSE2() noexcept { return getCPUInformation().hasSSE2; } bool SystemStats::hasSSE3() noexcept { return getCPUInformation().hasSSE3; } bool SystemStats::hasSSSE3() noexcept { return getCPUInformation().hasSSSE3; } +bool SystemStats::hasSSE41() noexcept { return getCPUInformation().hasSSE41; } +bool SystemStats::hasSSE42() noexcept { return getCPUInformation().hasSSE42; } bool SystemStats::hasAVX() noexcept { return getCPUInformation().hasAVX; } +bool SystemStats::hasAVX2() noexcept { return getCPUInformation().hasAVX2; } //============================================================================== diff --git a/modules/juce_core/system/juce_SystemStats.h b/modules/juce_core/system/juce_SystemStats.h index 9cbd187e0d..28f4399f72 100644 --- a/modules/juce_core/system/juce_SystemStats.h +++ b/modules/juce_core/system/juce_SystemStats.h @@ -152,13 +152,16 @@ public: */ static String getCpuVendor(); - static bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */ - static bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */ - static bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */ - static bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */ - static bool hasSSE3() noexcept; /**< Returns true if Intel SSE2 instructions are available. */ - static bool hasSSSE3() noexcept; /**< Returns true if Intel SSSE3 instructions are available. */ - static bool hasAVX() noexcept; /**< Returns true if Intel AVX instructions are available. */ + static bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */ + static bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */ + static bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */ + static bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */ + static bool hasSSE3() noexcept; /**< Returns true if Intel SSE3 instructions are available. */ + static bool hasSSSE3() noexcept; /**< Returns true if Intel SSSE3 instructions are available. */ + static bool hasSSE41() noexcept; /**< Returns true if Intel SSE4.1 instructions are available. */ + static bool hasSSE42() noexcept; /**< Returns true if Intel SSE4.2 instructions are available. */ + static bool hasAVX() noexcept; /**< Returns true if Intel AVX instructions are available. */ + static bool hasAVX2() noexcept; /**< Returns true if Intel AVX2 instructions are available. */ //============================================================================== /** Finds out how much RAM is in the machine.