1#include "cpuid.h"
2
3extern void exit (int) __attribute__((noreturn));
4
5/* Determine what instruction set we've been compiled for,
6   and detect that we're running with it.  */
7static void __attribute__((constructor))
8check_isa (void)
9{
10  int a, b, c, d;
11  int c1, d1, c1e, d1e;
12
13  c1 = d1 = c1e = d1e = 0;
14
15#ifdef __MMX__
16  d1 |= bit_MMX;
17#endif
18#ifdef __3dNOW__
19  d1e |= bit_3DNOW;
20#endif
21#ifdef __3dNOW_A__
22  d1e |= bit_3DNOWP;
23#endif
24#ifdef __SSE__
25  d1 |= bit_SSE;
26#endif
27#ifdef __SSE2__
28  d1 |= bit_SSE2;
29#endif
30#ifdef __SSE3__
31  c1 |= bit_SSE3;
32#endif
33#ifdef __SSSE3__
34  c1 |= bit_SSSE3;
35#endif
36#ifdef __SSE4_1__
37  c1 |= bit_SSE4_1;
38#endif
39#ifdef __SSE4_2__
40  c1 |= bit_SSE4_2;
41#endif
42#ifdef __AES__
43  c1 |= bit_AES;
44#endif
45#ifdef __PCLMUL__
46  c1 |= bit_PCLMUL;
47#endif
48#ifdef __AVX__
49  c1 |= bit_AVX;
50#endif
51#ifdef __FMA__
52  c1 |= bit_FMA;
53#endif
54#ifdef __SSE4A__
55  c1e |= bit_SSE4a;
56#endif
57#ifdef __FMA4__
58  c1e |= bit_FMA4;
59#endif
60#ifdef __XOP__
61  c1e |= bit_XOP;
62#endif
63#ifdef __LWP__
64  c1e |= bit_LWP;
65#endif
66
67  if (c1 | d1)
68    {
69      if (!__get_cpuid (1, &a, &b, &c, &d))
70	goto fail;
71      if ((c & c1) != c1 || (d & d1) != d1)
72	goto fail;
73    }
74  if (c1e | d1e)
75    {
76      if (!__get_cpuid (0x80000001, &a, &b, &c, &d))
77	goto fail;
78      if ((c & c1e) != c1e || (d & d1e) != d1e)
79	goto fail;
80    }
81  return;
82
83 fail:
84  exit (0);
85}
86