From c466fd21d1cbca1371ee92e062cbb43770e50657 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 1 Jan 2018 18:23:04 -1000 Subject: [PATCH] Add highestFeature check to cpuid users --- src/Math.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Math.cpp b/src/Math.cpp index 6090cc3..e4719a4 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -45,6 +45,7 @@ void detectCPU() int regs[4]; getCpuInfo(0, regs); + int highestFeature = regs[0]; *reinterpret_cast((char*)g_cpuFeatures.cpuVendor) = regs[1]; *reinterpret_cast((char*)g_cpuFeatures.cpuVendor + 4) = regs[3]; *reinterpret_cast((char*)g_cpuFeatures.cpuVendor + 8) = regs[2]; @@ -64,20 +65,24 @@ void detectCPU() } } - getCpuInfo(1, regs); + if (highestFeature >= 1) + { + getCpuInfo(1, regs); + memset((bool*)&g_cpuFeatures.AESNI, ((regs[2] & 0x02000000) != 0), 1); + memset((bool*)&g_cpuFeatures.SSE1, ((regs[3] & 0x02000000) != 0), 1); + memset((bool*)&g_cpuFeatures.SSE2, ((regs[3] & 0x04000000) != 0), 1); + memset((bool*)&g_cpuFeatures.SSE3, ((regs[2] & 0x00000001) != 0), 1); + memset((bool*)&g_cpuFeatures.SSSE3, ((regs[2] & 0x00000200) != 0), 1); + memset((bool*)&g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1); + memset((bool*)&g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1); + memset((bool*)&g_cpuFeatures.AVX, ((regs[2] & 0x10000000) != 0), 1); + } - memset((bool*)&g_cpuFeatures.AESNI, ((regs[2] & 0x02000000) != 0), 1); - memset((bool*)&g_cpuFeatures.SSE1, ((regs[3] & 0x02000000) != 0), 1); - memset((bool*)&g_cpuFeatures.SSE2, ((regs[3] & 0x04000000) != 0), 1); - memset((bool*)&g_cpuFeatures.SSE3, ((regs[2] & 0x00000001) != 0), 1); - memset((bool*)&g_cpuFeatures.SSSE3, ((regs[2] & 0x00000200) != 0), 1); - memset((bool*)&g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1); - memset((bool*)&g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1); - memset((bool*)&g_cpuFeatures.AVX, ((regs[2] & 0x10000000) != 0), 1); - - getCpuInfoEx(7, 0, regs); - - memset((bool*)&g_cpuFeatures.AVX2, ((regs[1] & 0x00000020) != 0), 1); + if (highestFeature >= 7) + { + getCpuInfoEx(7, 0, regs); + memset((bool*)&g_cpuFeatures.AVX2, ((regs[1] & 0x00000020) != 0), 1); + } isCPUInit = true; #endif