060eed30c6b59f91bcfc90428960552c786aa828
[platform/upstream/gcc.git] / gcc / testsuite / gcc.target / i386 / i386.exp
1 # Copyright (C) 1997-2014 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # GCC testsuite that uses the `dg.exp' driver.
18
19 # Exit immediately if this isn't a x86 target.
20 if { ![istarget i?86*-*-*] && ![istarget x86_64-*-*] } then {
21   return
22 }
23
24 # Load support procs.
25 load_lib gcc-dg.exp
26 load_lib clearcap.exp
27 load_lib mpx-dg.exp
28
29 # Return 1 if attribute ms_hook_prologue is supported.
30 proc check_effective_target_ms_hook_prologue { } {
31     if { [check_no_compiler_messages ms_hook_prologue object {
32              void __attribute__ ((__ms_hook_prologue__)) foo ();
33          } ""] } {
34         return 1
35     } else {
36         return 0
37     }
38 }
39
40 # Return 1 if 3dnow instructions can be compiled.
41 proc check_effective_target_3dnow { } {
42     return [check_no_compiler_messages 3dnow object {
43         typedef int __m64 __attribute__ ((__vector_size__ (8)));
44         typedef float __v2sf __attribute__ ((__vector_size__ (8)));
45
46         __m64 _m_pfadd (__m64 __A, __m64 __B)
47         {
48             return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
49         }
50     } "-O2 -m3dnow" ]
51 }
52
53 # Return 1 if sse3 instructions can be compiled.
54 proc check_effective_target_sse3 { } {
55     return [check_no_compiler_messages sse3 object {
56         typedef double __m128d __attribute__ ((__vector_size__ (16)));
57         typedef double __v2df __attribute__ ((__vector_size__ (16)));
58
59         __m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
60         {
61             return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
62         }
63     } "-O2 -msse3" ]
64 }
65
66 # Return 1 if ssse3 instructions can be compiled.
67 proc check_effective_target_ssse3 { } {
68     return [check_no_compiler_messages ssse3 object {
69         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
70         typedef int __v4si __attribute__ ((__vector_size__ (16)));
71
72         __m128i _mm_abs_epi32 (__m128i __X)
73         {
74             return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
75         }
76     } "-O2 -mssse3" ]
77 }
78
79 # Return 1 if sse4 instructions can be compiled.
80 proc check_effective_target_sse4 { } {
81     return [check_no_compiler_messages sse4.1 object {
82         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
83         typedef int __v4si __attribute__ ((__vector_size__ (16)));
84
85         __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
86         {
87             return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
88                                                        (__v4si)__Y);
89         }
90     } "-O2 -msse4.1" ]
91 }
92
93 # Return 1 if aes instructions can be compiled.
94 proc check_effective_target_aes { } {
95     return [check_no_compiler_messages aes object {
96         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
97         typedef long long __v2di __attribute__ ((__vector_size__ (16)));
98
99         __m128i _mm_aesimc_si128 (__m128i __X)
100         {
101             return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
102         }
103     } "-O2 -maes" ]
104 }
105
106 # Return 1 if vaes instructions can be compiled.
107 proc check_effective_target_vaes { } {
108     return [check_no_compiler_messages vaes object {
109         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
110         typedef long long __v2di __attribute__ ((__vector_size__ (16)));
111
112         __m128i _mm_aesimc_si128 (__m128i __X)
113         {
114             return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
115         }
116     } "-O2 -maes -mavx" ]
117 }
118
119 # Return 1 if pclmul instructions can be compiled.
120 proc check_effective_target_pclmul { } {
121     return [check_no_compiler_messages pclmul object {
122         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
123         typedef long long __v2di __attribute__ ((__vector_size__ (16)));
124
125         __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
126         {
127             return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
128                                                           (__v2di)__Y,
129                                                           1);
130         }
131     } "-O2 -mpclmul" ]
132 }
133
134 # Return 1 if vpclmul instructions can be compiled.
135 proc check_effective_target_vpclmul { } {
136     return [check_no_compiler_messages vpclmul object {
137         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
138         typedef long long __v2di __attribute__ ((__vector_size__ (16)));
139
140         __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
141         {
142             return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
143                                                           (__v2di)__Y,
144                                                           1);
145         }
146     } "-O2 -mpclmul -mavx" ]
147 }
148
149 # Return 1 if sse4a instructions can be compiled.
150 proc check_effective_target_sse4a { } {
151     return [check_no_compiler_messages sse4a object {
152         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
153         typedef long long __v2di __attribute__ ((__vector_size__ (16)));
154
155         __m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
156         {
157             return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
158         }
159     } "-O2 -msse4a" ]
160 }
161
162 # Return 1 if fma4 instructions can be compiled.
163 proc check_effective_target_fma4 { } {
164     return [check_no_compiler_messages fma4 object {
165         typedef float __m128 __attribute__ ((__vector_size__ (16)));
166         typedef float __v4sf __attribute__ ((__vector_size__ (16)));
167         __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
168         {
169             return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
170                                                      (__v4sf)__B,
171                                                      (__v4sf)__C);
172         }
173     } "-O2 -mfma4" ]
174 }
175
176 # Return 1 if fma instructions can be compiled.
177 proc check_effective_target_fma { } {
178     return [check_no_compiler_messages fma object {
179         typedef float __m128 __attribute__ ((__vector_size__ (16)));
180         typedef float __v4sf __attribute__ ((__vector_size__ (16)));
181         __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
182         {
183             return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
184                                                      (__v4sf)__B,
185                                                      (__v4sf)__C);
186         }
187     } "-O2 -mfma" ]
188 }
189
190 # Return 1 if xop instructions can be compiled.
191 proc check_effective_target_xop { } {
192     return [check_no_compiler_messages xop object {
193         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
194         typedef short __v8hi __attribute__ ((__vector_size__ (16)));
195         __m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
196         {
197             return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
198                                                        (__v8hi)__B,
199                                                        (__v8hi)__C);
200         }
201     } "-O2 -mxop" ]
202 }
203
204 # Return 1 if lzcnt instruction can be compiled.
205 proc check_effective_target_lzcnt { } {
206     return [check_no_compiler_messages lzcnt object {
207         unsigned short _lzcnt (unsigned short __X)
208         {
209            return __builtin_clzs (__X);
210         }
211     } "-mlzcnt" ]
212 }
213
214 # Return 1 if bmi instructions can be compiled.
215 proc check_effective_target_bmi { } {
216     return [check_no_compiler_messages bmi object {
217         unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
218         {
219           return __builtin_ia32_bextr_u32 (__X, __Y);
220         }
221     } "-mbmi" ]
222 }
223
224 # Return 1 if bmi2 instructions can be compiled.
225 proc check_effective_target_bmi2 { } {
226     return [check_no_compiler_messages bmi2 object {
227         unsigned int
228         _bzhi_u32 (unsigned int __X, unsigned int __Y)
229         {
230             return __builtin_ia32_bzhi_si (__X, __Y);
231         }
232     } "-mbmi2" ]
233 }
234
235 # Return 1 if ADX instructions can be compiled.
236 proc check_effective_target_adx { } {
237     return [check_no_compiler_messages adx object {
238         unsigned char
239         _adxcarry_u32 (unsigned char __CF, unsigned int __X,
240                    unsigned int __Y, unsigned int *__P)
241         {
242             return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
243         }
244     } "-madx" ]
245 }
246
247 # Return 1 if rtm instructions can be compiled.
248 proc check_effective_target_rtm { } {
249     return [check_no_compiler_messages rtm object {
250         void
251         _rtm_xend (void)
252         {
253             return __builtin_ia32_xend ();
254         }
255     } "-mrtm" ]
256 }
257
258 # Return 1 if avx512f instructions can be compiled.
259 proc check_effective_target_avx512f { } {
260     return [check_no_compiler_messages avx512f object {
261         typedef long long __v8di __attribute__ ((__vector_size__ (64)));
262         __v8di
263         mm512_and_epi64  (__v8di __X, __v8di __Y)
264         {
265             return __builtin_ia32_pandq512_mask (__X, __Y, __X, -1);
266         }
267     } "-mavx512f" ]
268 }
269
270 # Return 1 if avx512vl instructions can be compiled.
271 proc check_effective_target_avx512vl { } {
272     return [check_no_compiler_messages avx512vl object {
273         typedef long long __v4di __attribute__ ((__vector_size__ (32)));
274         __v4di
275         mm256_and_epi64  (__v4di __X, __v4di __Y)
276         {
277             __v4di __W;
278             return __builtin_ia32_pandq256_mask (__X, __Y, __W, -1);
279         }
280     } "-mavx512vl" ]
281 }
282
283 # Return 1 if avx512cd instructions can be compiled.
284 proc check_effective_target_avx512cd { } {
285     return [check_no_compiler_messages avx512cd_trans object {
286         typedef long long __v8di __attribute__ ((__vector_size__ (64)));
287         __v8di
288         _mm512_conflict_epi64 (__v8di __W, __v8di __A)
289         {
290           return (__v8di) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A,
291                                                                  (__v8di) __W,
292                                                                  -1);
293         }
294    } "-Wno-psabi -mavx512cd" ]
295 }
296
297 # Return 1 if avx512er instructions can be compiled.
298 proc check_effective_target_avx512er { } {
299     return [check_no_compiler_messages avx512er_trans object {
300         typedef float __v16sf __attribute__ ((__vector_size__ (64)));
301         __v16sf
302         mm512_exp2a23_ps  (__v16sf __X)
303         {
304             return __builtin_ia32_exp2ps_mask (__X, __X, -1, 4);
305         }
306    } "-Wno-psabi -mavx512er" ]
307 }
308
309 # Return 1 if sha instructions can be compiled.
310 proc check_effective_target_sha { } {
311     return [check_no_compiler_messages sha object {
312         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
313         typedef int __v4si __attribute__ ((__vector_size__ (16)));
314
315         __m128i _mm_sha1msg1_epu32 (__m128i __X, __m128i __Y)
316         {
317             return (__m128i) __builtin_ia32_sha1msg1 ((__v4si)__X,
318                                                       (__v4si)__Y);
319         }
320     } "-O2 -msha" ]
321 }
322
323 # Return 1 if avx512dq instructions can be compiled.
324 proc check_effective_target_avx512dq { } {
325     return [check_no_compiler_messages avx512dq object {
326         typedef long long __v8di __attribute__ ((__vector_size__ (64)));
327         __v8di
328         _mm512_mask_mullo_epi64 (__v8di __W, __v8di __A, __v8di __B)
329         {
330             return (__v8di) __builtin_ia32_pmullq512_mask ((__v8di) __A,
331                                                             (__v8di) __B,
332                                                             (__v8di) __W,
333                                                             -1);
334         }
335     } "-mavx512dq" ]
336 }
337
338 # Return 1 if avx512bw instructions can be compiled.
339 proc check_effective_target_avx512bw { } {
340     return [check_no_compiler_messages avx512bw object {
341         typedef short __v32hi __attribute__ ((__vector_size__ (64)));
342         __v32hi
343         _mm512_mask_mulhrs_epi16 (__v32hi __W, __v32hi __A, __v32hi __B)
344         {
345             return (__v32hi) __builtin_ia32_pmulhrsw512_mask ((__v32hi) __A,
346                                                             (__v32hi) __B,
347                                                             (__v32hi) __W,
348                                                             -1);
349         }
350     } "-mavx512bw" ]
351 }
352
353 # Return 1 if avx512ifma instructions can be compiled.
354 proc check_effective_target_avx512ifma { } {
355     return [check_no_compiler_messages avx512ifma object {
356         typedef long long __v8di __attribute__ ((__vector_size__ (64)));
357         __v8di
358         _mm512_madd52lo_epu64 (__v8di __X, __v8di __Y, __v8di __Z)
359         {
360           return (__v8di) __builtin_ia32_vpmadd52luq512_mask ((__v8di) __X,
361                                                                (__v8di) __Y,
362                                                                (__v8di) __Z,
363                                                                -1);
364         }
365     } "-mavx512ifma" ]
366 }
367
368 # If a testcase doesn't have special options, use these.
369 global DEFAULT_CFLAGS
370 if ![info exists DEFAULT_CFLAGS] then {
371     set DEFAULT_CFLAGS " -ansi -pedantic-errors"
372 }
373
374 # Initialize `dg'.
375 dg-init
376 clearcap-init
377
378 global runtests
379 # Special case compilation of vect-args.c so we don't have to
380 # replicate it 16 times.
381 if [runtest_file_p $runtests $srcdir/$subdir/vect-args.c] {
382   foreach type { "" -mmmx -m3dnow -msse -msse2 -mavx -mavx2 -mavx512f } {
383     foreach level { "" -O } {
384       set flags "$type $level"
385       verbose -log "Testing vect-args, $flags" 1
386       dg-test $srcdir/$subdir/vect-args.c $flags ""
387     }
388   }
389 }
390
391 # Everything else.
392 set tests [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]]
393 set tests [prune $tests $srcdir/$subdir/vect-args.c]
394
395 # Main loop.
396 dg-runtest $tests "" $DEFAULT_CFLAGS
397
398 # All done.
399 clearcap-finish
400 dg-finish