[PR c++/84702] ICE with default tmpl arg of overload set
[official-gcc.git] / gcc / testsuite / g++.dg / ext / mv2.C
blobd4f1f92c611106e67c8b6b6fb3b17cd8aacdb26a
1 /* Test case to check if Multiversioning chooses the correct
2    dispatching order when versions are for various ISAs.  */
3 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
4 /* { dg-require-ifunc "" }  */
5 /* { dg-options "-O2" } */
7 #include <assert.h>
9 /* Default version.  */
10 int foo () __attribute__ ((target ("default")));
11 /* The dispatch checks should be in the exact reverse order of the
12    declarations below.  */
13 int foo () __attribute__ ((target ("mmx")));
14 int foo () __attribute__ ((target ("sse")));
15 int foo () __attribute__ ((target ("sse2")));
16 int foo () __attribute__ ((target ("sse3")));
17 int foo () __attribute__ ((target ("ssse3")));
18 int foo () __attribute__ ((target ("sse4.1")));
19 int foo () __attribute__ ((target ("sse4.2")));
20 int foo () __attribute__ ((target ("popcnt")));
21 int foo () __attribute__ ((target ("avx")));
22 int foo () __attribute__ ((target ("avx2")));
23 int foo () __attribute__ ((target ("avx512f")));
25 int main ()
27   int val = foo ();
29   if (__builtin_cpu_supports ("avx512f"))
30     assert (val == 11);
31   else if (__builtin_cpu_supports ("avx2"))
32     assert (val == 10);
33   else if (__builtin_cpu_supports ("avx"))
34     assert (val == 9);
35   else if (__builtin_cpu_supports ("popcnt"))
36     assert (val == 8);
37   else if (__builtin_cpu_supports ("sse4.2"))
38     assert (val == 7);
39   else if (__builtin_cpu_supports ("sse4.1"))
40     assert (val == 6);
41   else if (__builtin_cpu_supports ("ssse3"))
42     assert (val == 5);
43   else if (__builtin_cpu_supports ("sse3"))
44     assert (val == 4);
45   else if (__builtin_cpu_supports ("sse2"))
46     assert (val == 3);
47   else if (__builtin_cpu_supports ("sse"))
48     assert (val == 2);
49   else if (__builtin_cpu_supports ("mmx"))
50     assert (val == 1);
51   else
52     assert (val == 0);
54   return 0;
57 int __attribute__ ((target("default")))
58 foo ()
60   return 0;
63 int __attribute__ ((target("mmx")))
64 foo ()
66   return 1;
69 int __attribute__ ((target("sse")))
70 foo ()
72   return 2;
75 int __attribute__ ((target("sse2")))
76 foo ()
78   return 3;
81 int __attribute__ ((target("sse3")))
82 foo ()
84   return 4;
87 int __attribute__ ((target("ssse3")))
88 foo ()
90   return 5;
93 int __attribute__ ((target("sse4.1")))
94 foo ()
96   return 6;
99 int __attribute__ ((target("sse4.2")))
100 foo ()
102   return 7;
105 int __attribute__ ((target("popcnt")))
106 foo ()
108   return 8;
111 int __attribute__ ((target("avx")))
112 foo ()
114   return 9;
117 int __attribute__ ((target("avx2")))
118 foo ()
120   return 10;
123 int __attribute__ ((target("avx512f")))
124 foo ()
126   return 11;