OSDN Git Service

2004-01-08 Stuart Hastings <stuart@apple.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / i386-cpuid.h
1 /* Helper file for i386 platform.  Runtime check for MMX/SSE/SSE2 support.
2    Used by 20020523-2.c and i386-sse-6.c, and possibly others.  */
3 /* Plagarized from 20020523-2.c.  */
4
5 #define bit_MMX (1 << 23)
6 #define bit_SSE (1 << 25)
7 #define bit_SSE2 (1 << 26)
8
9 #ifndef NOINLINE
10 #define NOINLINE __attribute__ ((noinline))
11 #endif
12
13 unsigned int i386_cpuid (void) NOINLINE;
14
15 unsigned int NOINLINE
16 i386_cpuid (void)
17 {
18   int fl1, fl2;
19
20   /* See if we can use cpuid.  */
21   __asm__ ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;"
22            "pushl %0; popfl; pushfl; popl %0; popfl"
23            : "=&r" (fl1), "=&r" (fl2)
24            : "i" (0x00200000));
25   if (((fl1 ^ fl2) & 0x00200000) == 0)
26     return (0);
27
28   /* Host supports cpuid.  See if cpuid gives capabilities, try
29      CPUID(0).  Preserve %ebx and %ecx; cpuid insn clobbers these, we
30      don't need their CPUID values here, and %ebx may be the PIC
31      register.  */
32   __asm__ ("push %%ecx ; push %%ebx ; cpuid ; pop %%ebx ; pop %%ecx"
33            : "=a" (fl1) : "0" (0) : "edx", "cc");
34   if (fl1 == 0)
35     return (0);
36
37   /* Invoke CPUID(1), return %edx; caller can examine bits to
38      determine what's supported.  */
39   __asm__ ("push %%ecx ; push %%ebx ; cpuid ; pop %%ebx ; pop %%ecx" : "=d" (fl2) : "a" (1) : "cc");
40
41   return fl2;
42 }
43