22 static inline void cpuid(
int output[4],
int functionnumber ) {
23 #if defined( __GNUC__ ) || defined( __clang__ ) // use inline assembly, Gnu/AT&T syntax 26 __asm(
"cpuid" :
"=a"( a ),
"=b"( b ),
"=c"( c ),
"=d"( d ) :
"a"( functionnumber ),
"c"( 0 ) : );
32 #elif defined( _MSC_VER ) || defined( __INTEL_COMPILER ) // Microsoft or Intel compiler, intrin.h included 34 __cpuidex( output, functionnumber, 0 );
36 #else // unknown platform. try inline assembly with masm/intel syntax 39 mov eax, functionnumber
53 static inline int64_t xgetbv(
int ctr ) {
54 #if ( defined( _MSC_FULL_VER ) && _MSC_FULL_VER >= 160040000 ) || \ 55 ( defined( __INTEL_COMPILER ) && __INTEL_COMPILER >= 1200 ) // Microsoft or Intel compiler supporting _xgetbv 58 return _xgetbv( ctr );
60 #elif defined( __GNUC__ ) // use inline assembly, Gnu/AT&T syntax 63 __asm(
"xgetbv" :
"=a"( a ),
"=d"( d ) :
"c"( ctr ) : );
66 #else // #elif defined (_WIN32) // other compiler. try inline assembly with masm/intel/MS 100 static int iset = -1;
105 int abcd[4] = {0, 0, 0, 0};
107 if ( abcd[0] == 0 )
return iset;
109 if ( ( abcd[3] & ( 1 << 0 ) ) == 0 )
return iset;
110 if ( ( abcd[3] & ( 1 << 23 ) ) == 0 )
return iset;
111 if ( ( abcd[3] & ( 1 << 15 ) ) == 0 )
return iset;
112 if ( ( abcd[3] & ( 1 << 24 ) ) == 0 )
return iset;
113 if ( ( abcd[3] & ( 1 << 25 ) ) == 0 )
return iset;
115 if ( ( abcd[3] & ( 1 << 26 ) ) == 0 )
return iset;
117 if ( ( abcd[2] & ( 1 << 0 ) ) == 0 )
return iset;
119 if ( ( abcd[2] & ( 1 << 9 ) ) == 0 )
return iset;
121 if ( ( abcd[2] & ( 1 << 19 ) ) == 0 )
return iset;
123 if ( ( abcd[2] & ( 1 << 23 ) ) == 0 )
return iset;
124 if ( ( abcd[2] & ( 1 << 20 ) ) == 0 )
return iset;
126 if ( ( abcd[2] & ( 1 << 27 ) ) == 0 )
return iset;
127 if ( ( xgetbv( 0 ) & 6 ) != 6 )
return iset;
128 if ( ( abcd[2] & ( 1 << 28 ) ) == 0 )
return iset;
131 if ( ( abcd[1] & ( 1 << 5 ) ) == 0 )
return iset;
133 if ( ( abcd[1] & ( 1 << 16 ) ) == 0 )
return iset;
135 if ( ( abcd[0] & 0x60 ) != 0x60 )
return iset;
138 if ( ( abcd[1] & ( 1 << 31 ) ) == 0 )
return iset;
140 if ( ( abcd[1] & 0x40020000 ) != 0x40020000 )
return iset;
150 return ( ( abcd[2] & ( 1 << 12 ) ) != 0 );
157 cpuid( abcd, 0x80000001 );
158 return ( ( abcd[2] & ( 1 << 16 ) ) != 0 );
165 cpuid( abcd, 0x80000001 );
166 return ( ( abcd[2] & ( 1 << 11 ) ) != 0 );
174 return ( ( abcd[2] & ( 1 << 29 ) ) != 0 );
182 return ( ( abcd[1] & ( 1 << 27 ) ) != 0 );
int instrset_detect(void)
unsigned long long uint64_t
#define cpuid(func, eax, ebx, ecx, edx)