7 // This file determines x86/AMD64 features a processor supports.
10 // - 0 if the machine matches the asked-for feature.
11 // - 1 if the machine does not.
12 // - 2 if the asked-for feature isn't recognised (this will be the case for
13 // any feature if run on a non-x86/AMD64 machine).
14 // - 3 if there was a usage error (it also prints an error message).
21 #if defined(VGA_x86) || defined(VGA_amd64)
22 static void cpuid ( unsigned int n,
23 unsigned int* a, unsigned int* b,
24 unsigned int* c, unsigned int* d )
26 __asm__ __volatile__ (
28 : "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) /* output */
32 static Bool go(char* cpu)
34 unsigned int level = 0, cmask = 0, dmask = 0, a, b, c, d;
36 if ( strcmp( cpu, "x86-fpu" ) == 0 ) {
39 } else if ( strcmp( cpu, "x86-cmov" ) == 0 ) {
42 } else if ( strcmp( cpu, "x86-mmx" ) == 0 ) {
45 } else if ( strcmp( cpu, "x86-mmxext" ) == 0 ) {
48 } else if ( strcmp( cpu, "x86-sse" ) == 0 ) {
51 } else if ( strcmp( cpu, "x86-sse2" ) == 0 ) {
54 } else if ( strcmp( cpu, "x86-sse3" ) == 0 ) {
57 } else if ( strcmp( cpu, "x86-ssse3" ) == 0 ) {
60 #if defined(VGA_amd64)
61 } else if ( strcmp( cpu, "amd64-sse3" ) == 0 ) {
64 } else if ( strcmp( cpu, "amd64-ssse3" ) == 0 ) {
67 } else if ( strcmp( cpu, "amd64-cx16" ) == 0 ) {
72 return 2; // Unrecognised feature.
75 assert( !(cmask != 0 && dmask != 0) );
76 assert( !(cmask == 0 && dmask == 0) );
78 cpuid( level & 0x80000000, &a, &b, &c, &d );
81 cpuid( level, &a, &b, &c, &d );
83 if (dmask > 0 && (d & dmask) != 0) return 0; // Feature present.
84 if (cmask > 0 && (c & cmask) != 0) return 0; // Feature present.
86 return 1; // Feature not present.
91 static Bool go(char* cpu)
93 return 2; // Feature not recognised (non-x86/AMD64 machine!)
96 #endif // defined(VGA_x86) || defined(VGA_amd64)
99 //---------------------------------------------------------------------------
101 //---------------------------------------------------------------------------
102 int main(int argc, char **argv)
105 fprintf( stderr, "usage: x86_amd64_features <feature>\n" );
106 exit(3); // Usage error.