LEFT | RIGHT |
1 /* Test case to check if Multiversioning works. */ | 1 /* Test case to check if Multiversioning works. */ |
2 /* { dg-do run { target i?86-*-* x86_64-*-* } } */ | 2 /* { dg-do run { target i?86-*-* x86_64-*-* } } */ |
3 /* { dg-require-ifunc "" } */ | 3 /* { dg-require-ifunc "" } */ |
4 /* { dg-options "-O2 -fPIC" } */ | 4 /* { dg-options "-O2 -fPIC -mno-avx" } */ |
5 | 5 |
6 #include <assert.h> | 6 #include <assert.h> |
7 | 7 |
8 /* Default version. */ | 8 /* Default version. */ |
9 int foo (); | 9 int foo (); |
10 /* The other versions of foo. Mix up the ordering and· | 10 /* The other versions of foo. Mix up the ordering and· |
11 check if the dispatching does it in the order of priority. */ | 11 check if the dispatching does it in the order of priority. */ |
12 /* Check combination of target attributes. */ | 12 /* Check combination of target attributes. */ |
13 int foo () __attribute__ ((target("arch=corei7,popcnt"))); | 13 int foo () __attribute__ ((target("arch=corei7,popcnt"))); |
14 /* The target operands in this declaration and the definition are re-ordered. | 14 /* The target operands in this declaration and the definition are re-ordered. |
15 This should still work. */ | 15 This should still work. */ |
16 int foo () __attribute__ ((target("ssse3,avx2"))); | 16 int foo () __attribute__ ((target("ssse3,avx2"))); |
17 | 17 |
18 /* Check for all target attributes for which dispatchers are available. */ | 18 /* Check for all target attributes for which dispatchers are available. */ |
19 /* Check arch= */ | 19 /* Check arch= */ |
20 int foo () __attribute__((target("arch=core2"))); | 20 int foo () __attribute__((target("arch=core2"))); |
21 int foo () __attribute__((target("arch=corei7"))); | 21 int foo () __attribute__((target("arch=corei7"))); |
22 int foo () __attribute__((target("arch=atom"))); | 22 int foo () __attribute__((target("arch=atom"))); |
| 23 /* Check ISAs */ |
| 24 int foo () __attribute__((target("avx"))); |
| 25 int foo () __attribute__ ((target("arch=core2,sse4.2"))); |
| 26 /* Check more arch=. */ |
23 int foo () __attribute__((target("arch=amdfam10"))); | 27 int foo () __attribute__((target("arch=amdfam10"))); |
24 int foo () __attribute__((target("arch=bdver1"))); | 28 int foo () __attribute__((target("arch=bdver1"))); |
25 int foo () __attribute__((target("arch=bdver2"))); | 29 int foo () __attribute__((target("arch=bdver2"))); |
26 /* Check ISAs */ | 30 |
27 int foo () __attribute__((target("sse3"))); | |
28 int foo () __attribute__((target("sse2"))); | |
29 int foo () __attribute__((target("sse"))); | |
30 int foo () __attribute__((target("avx"))); | |
31 int foo () __attribute__((target("sse4.2"))); | |
32 int foo () __attribute__((target("popcnt"))); | |
33 int foo () __attribute__((target("sse4.1"))); | |
34 int foo () __attribute__((target("ssse3"))); | |
35 int foo () __attribute__((target("mmx"))); | |
36 int foo () __attribute__((target("avx2"))); | |
37 int (*p)() = &foo; | 31 int (*p)() = &foo; |
38 int main () | 32 int main () |
39 { | 33 { |
40 int val = foo (); | 34 int val = foo (); |
41 assert (val == (*p)()); | 35 assert (val == (*p)()); |
42 | 36 |
43 /* Check in the exact same order in which the dispatching | 37 /* Check in the exact same order in which the dispatching |
44 is expected to happen. */ | 38 is expected to happen. */ |
45 if (__builtin_cpu_is ("bdver1")) | 39 if (__builtin_cpu_is ("bdver1")) |
46 assert (val == 1); | 40 assert (val == 1); |
47 else if (__builtin_cpu_is ("bdver2")) | 41 else if (__builtin_cpu_is ("bdver2")) |
48 assert (val == 2); | 42 assert (val == 2); |
49 else if (__builtin_cpu_supports ("avx2") | 43 else if (__builtin_cpu_supports ("avx2") |
50 && __builtin_cpu_supports ("ssse3")) | 44 && __builtin_cpu_supports ("ssse3")) |
51 assert (val == 3); | 45 assert (val == 3); |
52 else if (__builtin_cpu_supports ("avx2")) | 46 else if (__builtin_cpu_supports ("avx")) |
53 assert (val == 4); | 47 assert (val == 4); |
54 else if (__builtin_cpu_supports ("avx")) | |
55 assert (val == 5); | |
56 else if (__builtin_cpu_is ("corei7") | 48 else if (__builtin_cpu_is ("corei7") |
57 && __builtin_cpu_supports ("popcnt")) | 49 && __builtin_cpu_supports ("popcnt")) |
| 50 assert (val == 5); |
| 51 else if (__builtin_cpu_is ("corei7")) |
58 assert (val == 6); | 52 assert (val == 6); |
59 else if (__builtin_cpu_supports ("popcnt")) | 53 else if (__builtin_cpu_is ("amdfam10h")) |
60 assert (val == 7); | 54 assert (val == 7); |
61 else if (__builtin_cpu_is ("corei7")) | 55 else if (__builtin_cpu_is ("core2") |
| 56 » && __builtin_cpu_supports ("sse4.2")) |
62 assert (val == 8); | 57 assert (val == 8); |
63 else if (__builtin_cpu_supports ("sse4.2")) | 58 else if (__builtin_cpu_is ("core2")) |
64 assert (val == 9); | 59 assert (val == 9); |
65 else if (__builtin_cpu_supports ("sse4.1")) | 60 else if (__builtin_cpu_is ("atom")) |
66 assert (val == 10); | 61 assert (val == 10); |
67 else if (__builtin_cpu_is ("amdfam10h")) | |
68 assert (val == 11); | |
69 else if (__builtin_cpu_is ("core2")) | |
70 assert (val == 12); | |
71 else if (__builtin_cpu_is ("atom")) | |
72 assert (val == 13); | |
73 else if (__builtin_cpu_supports ("ssse3")) | |
74 assert (val == 14); | |
75 else if (__builtin_cpu_supports ("sse3")) | |
76 assert (val == 15); | |
77 else if (__builtin_cpu_supports ("sse2")) | |
78 assert (val == 16); | |
79 else if (__builtin_cpu_supports ("sse")) | |
80 assert (val == 17); | |
81 else if (__builtin_cpu_supports ("mmx")) | |
82 assert (val == 18); | |
83 else | 62 else |
84 assert (val == 0); | 63 assert (val == 0); |
85 ·· | 64 ·· |
86 return 0; | 65 return 0; |
87 } | 66 } |
88 | 67 |
89 int foo () | 68 int foo () |
90 { | 69 { |
91 return 0; | 70 return 0; |
| 71 } |
| 72 |
| 73 int __attribute__ ((target("arch=corei7,popcnt"))) |
| 74 foo () |
| 75 { |
| 76 return 5; |
| 77 } |
| 78 int __attribute__ ((target("avx2,ssse3"))) |
| 79 foo () |
| 80 { |
| 81 return 3; |
| 82 } |
| 83 |
| 84 int __attribute__ ((target("arch=core2"))) |
| 85 foo () |
| 86 { |
| 87 return 9; |
| 88 } |
| 89 |
| 90 int __attribute__ ((target("arch=corei7"))) |
| 91 foo () |
| 92 { |
| 93 return 6; |
| 94 } |
| 95 |
| 96 int __attribute__ ((target("arch=atom"))) |
| 97 foo () |
| 98 { |
| 99 return 10; |
| 100 } |
| 101 |
| 102 int __attribute__ ((target("avx"))) |
| 103 foo () |
| 104 { |
| 105 return 4; |
| 106 } |
| 107 |
| 108 int __attribute__ ((target("arch=core2,sse4.2"))) |
| 109 foo () |
| 110 { |
| 111 return 8; |
| 112 } |
| 113 |
| 114 int __attribute__ ((target("arch=amdfam10"))) |
| 115 foo () |
| 116 { |
| 117 return 7; |
92 } | 118 } |
93 | 119 |
94 int __attribute__ ((target("arch=bdver1"))) | 120 int __attribute__ ((target("arch=bdver1"))) |
95 foo () | 121 foo () |
96 { | 122 { |
97 return 1; | 123 return 1; |
98 } | 124 } |
99 | 125 |
100 int __attribute__ ((target("arch=bdver2"))) | 126 int __attribute__ ((target("arch=bdver2"))) |
101 foo () | 127 foo () |
102 { | 128 { |
103 return 2; | 129 return 2; |
104 } | 130 } |
105 | |
106 int __attribute__ ((target("avx2,ssse3"))) | |
107 foo () | |
108 { | |
109 return 3; | |
110 } | |
111 | |
112 int __attribute__ ((target("avx2"))) | |
113 foo () | |
114 { | |
115 return 4; | |
116 } | |
117 | |
118 int __attribute__ ((target("avx"))) | |
119 foo () | |
120 { | |
121 return 5; | |
122 } | |
123 | |
124 int __attribute__ ((target("arch=corei7,popcnt"))) | |
125 foo () | |
126 { | |
127 return 6; | |
128 } | |
129 | |
130 int __attribute__ ((target("popcnt"))) | |
131 foo () | |
132 { | |
133 return 7; | |
134 } | |
135 | |
136 int __attribute__ ((target("arch=corei7"))) | |
137 foo () | |
138 { | |
139 return 8; | |
140 } | |
141 | |
142 int __attribute__ ((target("sse4.2"))) | |
143 foo () | |
144 { | |
145 return 9; | |
146 } | |
147 | |
148 int __attribute__ ((target("sse4.1"))) | |
149 foo () | |
150 { | |
151 return 10; | |
152 } | |
153 | |
154 int __attribute__ ((target("arch=amdfam10"))) | |
155 foo () | |
156 { | |
157 return 11; | |
158 } | |
159 | |
160 int __attribute__ ((target("arch=core2"))) | |
161 foo () | |
162 { | |
163 return 12; | |
164 } | |
165 | |
166 int __attribute__ ((target("arch=atom"))) | |
167 foo () | |
168 { | |
169 return 13; | |
170 } | |
171 | |
172 int __attribute__ ((target("ssse3"))) | |
173 foo () | |
174 { | |
175 return 14; | |
176 } | |
177 | |
178 int __attribute__ ((target("sse3"))) | |
179 foo () | |
180 { | |
181 return 15; | |
182 } | |
183 | |
184 int __attribute__ ((target("sse2"))) | |
185 foo () | |
186 { | |
187 return 16; | |
188 } | |
189 | |
190 int __attribute__ ((target("sse"))) | |
191 foo () | |
192 { | |
193 return 17; | |
194 } | |
195 | |
196 int __attribute__ ((target("mmx"))) | |
197 foo () | |
198 { | |
199 return 18; | |
200 } | |
LEFT | RIGHT |