Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / g++.dg / ext / mv2.C
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" } */
6
7 #include <assert.h>
8
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
24 int main ()
25 {
26   int val = foo ();
27
28   if (__builtin_cpu_supports ("avx2"))
29     assert (val == 1);
30   else if (__builtin_cpu_supports ("avx"))
31     assert (val == 2);
32   else if (__builtin_cpu_supports ("popcnt"))
33     assert (val == 3);
34   else if (__builtin_cpu_supports ("sse4.2"))
35     assert (val == 4);
36   else if (__builtin_cpu_supports ("sse4.1"))
37     assert (val == 5);
38   else if (__builtin_cpu_supports ("ssse3"))
39     assert (val == 6);
40   else if (__builtin_cpu_supports ("sse3"))
41     assert (val == 7);
42   else if (__builtin_cpu_supports ("sse2"))
43     assert (val == 8);
44   else if (__builtin_cpu_supports ("sse"))
45     assert (val == 9);
46   else if (__builtin_cpu_supports ("mmx"))
47     assert (val == 10);
48   else
49     assert (val == 0);
50
51   return 0;
52 }
53
54 int __attribute__ ((target("default")))
55 foo ()
56 {
57   return 0;
58 }
59
60 int __attribute__ ((target("mmx")))
61 foo ()
62 {
63   return 10;
64 }
65
66 int __attribute__ ((target("sse")))
67 foo ()
68 {
69   return 9;
70 }
71
72 int __attribute__ ((target("sse2")))
73 foo ()
74 {
75   return 8;
76 }
77
78 int __attribute__ ((target("sse3")))
79 foo ()
80 {
81   return 7;
82 }
83
84 int __attribute__ ((target("ssse3")))
85 foo ()
86 {
87   return 6;
88 }
89
90 int __attribute__ ((target("sse4.1")))
91 foo ()
92 {
93   return 5;
94 }
95
96 int __attribute__ ((target("sse4.2")))
97 foo ()
98 {
99   return 4;
100 }
101
102 int __attribute__ ((target("popcnt")))
103 foo ()
104 {
105   return 3;
106 }
107
108 int __attribute__ ((target("avx")))
109 foo ()
110 {
111   return 2;
112 }
113
114 int __attribute__ ((target("avx2")))
115 foo ()
116 {
117   return 1;
118 }