diff --git a/cmake/tests/cpuid.cpp b/cmake/tests/cpuid.cpp index 27426ceecf57..854ac3cba3a9 100644 --- a/cmake/tests/cpuid.cpp +++ b/cmake/tests/cpuid.cpp @@ -7,98 +7,82 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //////////////////////////////////////////////////////////////////////////////// +#include #include +using namespace std; -enum { eax,ebx,ecx,edx }; +struct registers_t { uint32_t eax, ebx, ecx, edx; }; -#if defined(__GNUC__) -void __cpuid( int CPUInfo[4],int InfoType) +#if defined __GNUC__ +void __cpuid(registers_t& CPUInfo, uint32_t InfoType) { __asm__ __volatile__ - ( - "cpuid":\ - "=a" (CPUInfo[eax]), "=b" (CPUInfo[ebx]) - , "=c" (CPUInfo[ecx]), "=d" (CPUInfo[edx]) - : "a" (InfoType) - ); + ( + "cpuid": + "=a" (CPUInfo.eax), "=b" (CPUInfo.ebx) + , "=c" (CPUInfo.ecx), "=d" (CPUInfo.edx) + : "a" (InfoType) + ); } -void __cpuidex(int CPUInfo[4],int InfoType,int ECXValue) -{ - __asm__ __volatile__ - ( - "cpuid":\ - "=a" (CPUInfo[eax]), "=b" (CPUInfo[ebx]) - , "=c" (CPUInfo[ecx]), "=d" (CPUInfo[edx]) - : "a" (InfoType), "c" (ECXValue) - ); -} - -#elif defined(_MSC_VER) +#elif defined _MSC_VER #include #endif -bool has_bit_set(int value, int bit) +bool has_bit_set(uint32_t value, uint32_t bit) { - return (value & (1<= noptions) return -2; - if(target == "clflush") m = options[0]; - else if(target == "cx8" ) m = options[1]; - else if(target == "cx16" ) m = options[2]; - else if(target == "cmov" ) m = options[3]; - else if(target == "msr" ) m = options[4]; - else if(target == "rdtsc" ) m = options[5]; - else if(target == "rdtscp" ) m = options[6]; - else if(target == "mmx" ) m = options[7]; - else if(target == "sse" ) m = options[8]; - else if(target == "sse2" ) m = options[9]; - else if(target == "sse3" ) m = options[10]; - else if(target == "ssse3" ) m = options[11]; - else if(target == "sse4.1" ) m = options[12]; - else if(target == "sse4.2" ) m = options[13]; - else if(target == "avx" ) m = options[14]; - else if(target == "xop" ) m = options[15]; - else if(target == "fma4" ) m = options[16]; - - __cpuid(registers,m.function); + __cpuid(registers, m.function); // exit with 0 if the bit is set - return !has_bit_set(registers[m.reg],m.bit); + return !has_bit_set(registers.*m.reg, m.bit); } -