• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版7c2c14bed507d4f2e02ad8aaf5e5ee05760b9615 (tree)
时间2016-12-26 06:16:04
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Some more improvements of MUtils::CPUFetaures code.

更改概述

差异

--- a/include/MUtils/CPUFeatures.h
+++ b/include/MUtils/CPUFeatures.h
@@ -54,9 +54,12 @@ namespace MUtils
5454 static const quint32 FLAG_SSE2 = 0x008U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE2* instruction set extension
5555 static const quint32 FLAG_SSE3 = 0x010U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE3* instruction set extension
5656 static const quint32 FLAG_SSSE3 = 0x020U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSSE3* instruction set extension
57- static const quint32 FLAG_SSE4 = 0x030U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE4.1* instruction set extension
57+ static const quint32 FLAG_SSE41 = 0x040U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE4.1* instruction set extension
5858 static const quint32 FLAG_SSE42 = 0x080U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE4.2* instruction set extension
5959 static const quint32 FLAG_AVX = 0x100U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *AVX* instruction set extension
60+ static const quint32 FLAG_AVX2 = 0x200U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *AVX2* instruction set extension
61+ static const quint32 FLAG_FMA3 = 0x400U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *FMA3* instruction
62+ static const quint32 FLAG_LZCNT = 0x800U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *LZCNT* instruction
6063
6164 /**
6265 * \brief Struct to hold information about the CPU. See `_cpu_info_t` for details!
--- a/src/CPUFeatures_Win32.cpp
+++ b/src/CPUFeatures_Win32.cpp
@@ -49,6 +49,7 @@ MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(void)
4949
5050 //Detect the CPU identifier string
5151 MY_CPUID(&cpuInfo[0], 0);
52+ const uint32_t max_basic_cap = cpuInfo[0];
5253 memcpy(&features.idstr[0U * sizeof(uint32_t)], &cpuInfo[1], sizeof(uint32_t));
5354 memcpy(&features.idstr[1U * sizeof(uint32_t)], &cpuInfo[3], sizeof(uint32_t));
5455 memcpy(&features.idstr[2U * sizeof(uint32_t)], &cpuInfo[2], sizeof(uint32_t));
@@ -57,7 +58,7 @@ MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(void)
5758 features.vendor |= CHECK_VENDOR(features.idstr, "AuthenticAMD", VENDOR_AMD);
5859
5960 //Detect the CPU model and feature flags
60- if(cpuInfo[0] >= 1)
61+ if(max_basic_cap >= 1)
6162 {
6263 MY_CPUID(&cpuInfo[0], 1);
6364 features.features |= CHECK_FLAG(cpuInfo[3], 0x00008000, FLAG_CMOV);
@@ -66,7 +67,7 @@ MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(void)
6667 features.features |= CHECK_FLAG(cpuInfo[3], 0x04000000, FLAG_SSE2);
6768 features.features |= CHECK_FLAG(cpuInfo[2], 0x00000001, FLAG_SSE3);
6869 features.features |= CHECK_FLAG(cpuInfo[2], 0x00000200, FLAG_SSSE3);
69- features.features |= CHECK_FLAG(cpuInfo[2], 0x00080000, FLAG_SSE4);
70+ features.features |= CHECK_FLAG(cpuInfo[2], 0x00080000, FLAG_SSE41);
7071 features.features |= CHECK_FLAG(cpuInfo[2], 0x00100000, FLAG_SSE42);
7172
7273 //Check for AVX
@@ -75,6 +76,7 @@ MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(void)
7576 if((_xgetbv(0) & 0x6ui64) == 0x6ui64) /*AVX requires OS support!*/
7677 {
7778 features.features |= FLAG_AVX;
79+ features.features |= CHECK_FLAG(cpuInfo[2], 0x00001000, FLAG_FMA3);
7880 }
7981 }
8082
@@ -84,15 +86,33 @@ MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(void)
8486 features.family = ((cpuInfo[0] >> 8) & 0xf) + ((cpuInfo[0] >> 20) & 0xff);
8587 }
8688
89+ //Detect extended feature flags
90+ if (max_basic_cap >= 7)
91+ {
92+ MY_CPUID(&cpuInfo[1], 7);
93+ if (features.features & FLAG_AVX)
94+ {
95+ features.features |= CHECK_FLAG(cpuInfo[2], 0x00000020, FLAG_AVX2);
96+ }
97+ }
98+
8799 //Read the CPU "brand" string
88- MY_CPUID(&cpuInfo[0], 0x80000000);
89- const uint32_t nExIds = qBound(0x80000000, cpuInfo[0], 0x80000004);
90- for(uint32_t i = 0x80000002; i <= nExIds; ++i)
100+ if (max_basic_cap > 0)
91101 {
92- MY_CPUID(&cpuInfo[0], i);
93- memcpy(&features.brand[(i - 0x80000002) * sizeof(cpuInfo)], &cpuInfo[0], sizeof(cpuInfo));
102+ MY_CPUID(&cpuInfo[0], 0x80000000);
103+ const uint32_t max_extended_cap = qBound(0x80000000, cpuInfo[0], 0x80000004);
104+ if (max_extended_cap >= 0x80000001)
105+ {
106+ MY_CPUID(&cpuInfo[0], 0x80000001);
107+ features.features |= CHECK_FLAG(cpuInfo[2], 0x00000020, FLAG_LZCNT);
108+ for (uint32_t i = 0x80000002; i <= max_extended_cap; ++i)
109+ {
110+ MY_CPUID(&cpuInfo[0], i);
111+ memcpy(&features.brand[(i - 0x80000002) * sizeof(cpuInfo)], &cpuInfo[0], sizeof(cpuInfo));
112+ }
113+ features.brand[sizeof(features.brand) - 1] = '\0';
114+ }
94115 }
95- features.brand[sizeof(features.brand) - 1] = '\0';
96116
97117 //Detect 64-Bit processors
98118 #if (!(defined(_M_X64) || defined(_M_IA64)))
Show on old repository browser