summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/isa-check.h
blob: 8ddbf4dfc2b87805ac06d3ffcd74b7063717b1d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "cpuid.h"

extern void exit (int) __attribute__((noreturn));

/* Determine what instruction set we've been compiled for,
   and detect that we're running with it.  */
static void __attribute__((constructor))
check_isa (void)
{
  int a, b, c, d;
  int c1, d1, c1e, d1e;

  c1 = d1 = c1e = d1e = 0;

#ifdef __MMX__
  d1 |= bit_MMX;
#endif
#ifdef __3dNOW__
  d1e |= bit_3DNOW;
#endif
#ifdef __3dNOW_A__
  d1e |= bit_3DNOWP;
#endif
#ifdef __SSE__
  d1 |= bit_SSE;
#endif
#ifdef __SSE2__
  d1 |= bit_SSE2;
#endif
#ifdef __SSE3__
  c1 |= bit_SSE3;
#endif
#ifdef __SSSE3__
  c1 |= bit_SSSE3;
#endif
#ifdef __SSE4_1__
  c1 |= bit_SSE4_1;
#endif
#ifdef __SSE4_2__
  c1 |= bit_SSE4_2;
#endif
#ifdef __AES__
  c1 |= bit_AES;
#endif
#ifdef __PCLMUL__
  c1 |= bit_PCLMUL;
#endif
#ifdef __AVX__
  c1 |= bit_AVX;
#endif
#ifdef __FMA__
  c1 |= bit_FMA;
#endif
#ifdef __SSE4A__
  c1e |= bit_SSE4a;
#endif
#ifdef __FMA4__
  c1e |= bit_FMA4;
#endif
#ifdef __XOP__
  c1e |= bit_XOP;
#endif
#ifdef __LWP__
  c1e |= bit_LWP;
#endif

  if (c1 | d1)
    {
      if (!__get_cpuid (1, &a, &b, &c, &d))
	goto fail;
      if ((c & c1) != c1 || (d & d1) != d1)
	goto fail;
    }
  if (c1e | d1e)
    {
      if (!__get_cpuid (0x80000001, &a, &b, &c, &d))
	goto fail;
      if ((c & c1e) != c1e || (d & d1e) != d1e)
	goto fail;
    }
  return;

 fail:
  exit (0);
}