23 static inline void cpuid(
int output[4],
int functionnumber )
25 #if defined( __GNUC__ ) || defined( __clang__ ) // use inline assembly, Gnu/AT&T syntax 28 __asm(
"cpuid" :
"=a"( a ),
"=b"( b ),
"=c"( c ),
"=d"( d ) :
"a"( functionnumber ),
"c"( 0 ) : );
34 #elif defined( _MSC_VER ) || defined( __INTEL_COMPILER ) // Microsoft or Intel compiler, intrin.h included 36 __cpuidex( output, functionnumber, 0 );
38 #else // unknown platform. try inline assembly with masm/intel syntax 41 mov eax, functionnumber
55 static inline int64_t xgetbv(
int ctr )
57 #if ( defined( _MSC_FULL_VER ) && _MSC_FULL_VER >= 160040000 ) || \ 58 ( defined( __INTEL_COMPILER ) && \ 59 __INTEL_COMPILER >= 1200 ) // Microsoft or Intel compiler supporting _xgetbv intrinsic 61 return _xgetbv( ctr );
63 #elif defined( __GNUC__ ) // use inline assembly, Gnu/AT&T syntax 66 __asm(
"xgetbv" :
"=a"( a ),
"=d"( d ) :
"c"( ctr ) : );
69 #else // #elif defined (_WIN32) // other compiler. try inline assembly with masm/intel/MS 104 static int iset = -1;
109 int abcd[4] = {0, 0, 0, 0};
111 if ( abcd[0] == 0 )
return iset;
113 if ( ( abcd[3] & ( 1 << 0 ) ) == 0 )
return iset;
114 if ( ( abcd[3] & ( 1 << 23 ) ) == 0 )
return iset;
115 if ( ( abcd[3] & ( 1 << 15 ) ) == 0 )
return iset;
116 if ( ( abcd[3] & ( 1 << 24 ) ) == 0 )
return iset;
117 if ( ( abcd[3] & ( 1 << 25 ) ) == 0 )
return iset;
119 if ( ( abcd[3] & ( 1 << 26 ) ) == 0 )
return iset;
121 if ( ( abcd[2] & ( 1 << 0 ) ) == 0 )
return iset;
123 if ( ( abcd[2] & ( 1 << 9 ) ) == 0 )
return iset;
125 if ( ( abcd[2] & ( 1 << 19 ) ) == 0 )
return iset;
127 if ( ( abcd[2] & ( 1 << 23 ) ) == 0 )
return iset;
128 if ( ( abcd[2] & ( 1 << 20 ) ) == 0 )
return iset;
130 if ( ( abcd[2] & ( 1 << 27 ) ) == 0 )
return iset;
131 if ( ( xgetbv( 0 ) & 6 ) != 6 )
return iset;
132 if ( ( abcd[2] & ( 1 << 28 ) ) == 0 )
return iset;
135 if ( ( abcd[1] & ( 1 << 5 ) ) == 0 )
return iset;
137 if ( ( abcd[1] & ( 1 << 16 ) ) == 0 )
return iset;
139 if ( ( abcd[0] & 0x60 ) != 0x60 )
return iset;
142 if ( ( abcd[1] & ( 1 << 31 ) ) == 0 )
return iset;
144 if ( ( abcd[1] & 0x40020000 ) != 0x40020000 )
return iset;
155 return ( ( abcd[2] & ( 1 << 12 ) ) != 0 );
163 cpuid( abcd, 0x80000001 );
164 return ( ( abcd[2] & ( 1 << 16 ) ) != 0 );
172 cpuid( abcd, 0x80000001 );
173 return ( ( abcd[2] & ( 1 << 11 ) ) != 0 );
182 return ( ( abcd[2] & ( 1 << 29 ) ) != 0 );
191 return ( ( abcd[1] & ( 1 << 27 ) ) != 0 );
int instrset_detect(void)
unsigned long long uint64_t
#define cpuid(func, eax, ebx, ecx, edx)