nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | static __inline__ void cpuid(int n, |
| 6 | unsigned int *a, unsigned int *b, |
| 7 | unsigned int *c, unsigned int *d) |
| 8 | { |
| 9 | __asm__ __volatile__ ( |
| 10 | "cpuid" |
| 11 | : "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) /* output */ |
| 12 | : "0" (n) /* input */ |
| 13 | ); |
| 14 | } |
| 15 | |
| 16 | int main(int argc, char **argv) |
| 17 | { |
| 18 | unsigned int mask = 0; |
| 19 | unsigned int a; |
| 20 | unsigned int b; |
| 21 | unsigned int c; |
| 22 | unsigned int d; |
| 23 | |
| 24 | if ( argc == 2 ) |
| 25 | { |
| 26 | if ( strcmp( argv[1], "mmx" ) == 0 ) mask = 1 << 23; |
| 27 | else if ( strcmp( argv[1], "sse" ) == 0 ) mask = 1 << 25; |
| 28 | else if ( strcmp( argv[1], "sse2" ) == 0 ) mask = 1 << 26; |
| 29 | } |
| 30 | |
| 31 | if ( mask == 0 ) |
| 32 | { |
| 33 | fprintf( stderr, "usage: cputest [mmx|sse|sse2]\n" ); |
| 34 | exit( 1 ); |
| 35 | } |
| 36 | |
| 37 | cpuid( 0, &a, &b, &c, &d ); |
| 38 | |
| 39 | if ( a >= 1 ) |
| 40 | { |
| 41 | cpuid( 1, &a, &b, &c, &d ); |
| 42 | |
| 43 | if ( ( d & mask ) != 0 ) exit( 0 ); |
| 44 | } |
| 45 | |
| 46 | exit( 1 ); |
| 47 | } |