19 static inline void cpuid (
int output[4],
int functionnumber) {
20 #if defined (_MSC_VER) // Microsoft compiler, intrin.h included 22 __cpuidex(output, functionnumber, 0);
23 #elif defined(__INTEL_COMPILER) // Intel compiler 25 __cpuid(output, functionnumber);
26 #elif defined(__GNUC__) || defined(__clang__) // use inline assembly, Gnu/AT&T syntax 29 __asm(
"cpuid" :
"=a"(a),
"=b"(b),
"=c"(c),
"=d"(d) :
"a"(functionnumber),
"c"(0) : );
35 #else // unknown platform. try inline assembly with masm/intel syntax 38 mov eax, functionnumber
52 static inline int64_t xgetbv (
int ctr) {
53 #if (defined (_MSC_FULL_VER) && _MSC_FULL_VER >= 160040000) || (defined (__INTEL_COMPILER) && __INTEL_COMPILER >= 1200) // Microsoft or Intel compiler supporting _xgetbv intrinsic 57 #elif defined(__GNUC__) // use inline assembly, Gnu/AT&T syntax 60 __asm(
"xgetbv" :
"=a"(a),
"=d"(d) :
"c"(ctr) : );
63 #else // #elif defined (_WIN32) // other compiler. try inline assembly with masm/intel/MS syntax 100 int abcd[4] = {0,0,0,0};
102 if (abcd[0] == 0)
return iset;
104 if ((abcd[3] & (1 << 0)) == 0)
return iset;
105 if ((abcd[3] & (1 << 23)) == 0)
return iset;
106 if ((abcd[3] & (1 << 15)) == 0)
return iset;
107 if ((abcd[3] & (1 << 24)) == 0)
return iset;
108 if ((abcd[3] & (1 << 25)) == 0)
return iset;
110 if ((abcd[3] & (1 << 26)) == 0)
return iset;
112 if ((abcd[2] & (1 << 0)) == 0)
return iset;
114 if ((abcd[2] & (1 << 9)) == 0)
return iset;
116 if ((abcd[2] & (1 << 19)) == 0)
return iset;
118 if ((abcd[2] & (1 << 23)) == 0)
return iset;
119 if ((abcd[2] & (1 << 20)) == 0)
return iset;
121 if ((abcd[2] & (1 << 27)) == 0)
return iset;
122 if ((xgetbv(0) & 6) != 6)
return iset;
123 if ((abcd[2] & (1 << 28)) == 0)
return iset;
126 if ((abcd[1] & (1 << 5)) == 0)
return iset;
129 if ((abcd[0] & 0x60) != 0x60)
return iset;
139 return ((abcd[2] & (1 << 12)) != 0);
146 cpuid(abcd, 0x80000001);
147 return ((abcd[2] & (1 << 16)) != 0);
154 cpuid(abcd, 0x80000001);
155 return ((abcd[2] & (1 << 11)) != 0);
162 bool hasFMA3(
void) {
return false; }
163 bool hasFMA4(
void) {
return false; }
164 bool hasXOP(
void) {
return false; }
int instrset_detect(void)
#define cpuid(func, eax, ebx, ecx, edx)
unsigned long long uint64_t