1# Copyright (C) 1997-2018 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.
20if { ![istarget i?86*-*-*] && ![istarget x86_64-*-*] } then {
21  return
22}
23
24# Load support procs.
25load_lib gcc-dg.exp
26load_lib clearcap.exp
27load_lib mpx-dg.exp
28
29# Return 1 if attribute ms_hook_prologue is supported.
30proc 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.
41proc 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.
54proc 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.
67proc 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 aes instructions can be compiled.
80proc check_effective_target_aes { } {
81    return [check_no_compiler_messages aes object {
82	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
83	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
84
85	__m128i _mm_aesimc_si128 (__m128i __X)
86	{
87	    return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
88	}
89    } "-O2 -maes" ]
90}
91
92# Return 1 if vaes instructions can be compiled.
93proc check_effective_target_vaes { } {
94    return [check_no_compiler_messages vaes object {
95	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
96	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
97
98	__m128i _mm_aesimc_si128 (__m128i __X)
99	{
100	    return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
101	}
102    } "-O2 -maes -mavx" ]
103}
104
105# Return 1 if pclmul instructions can be compiled.
106proc check_effective_target_pclmul { } {
107    return [check_no_compiler_messages pclmul object {
108	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
109	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
110
111	__m128i pclmulqdq_test (__m128i __X, __m128i __Y)
112	{
113	    return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
114							  (__v2di)__Y,
115							  1);
116	}
117    } "-O2 -mpclmul" ]
118}
119
120# Return 1 if vpclmul instructions can be compiled.
121proc check_effective_target_vpclmul { } {
122    return [check_no_compiler_messages vpclmul object {
123	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
124	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
125
126	__m128i pclmulqdq_test (__m128i __X, __m128i __Y)
127	{
128	    return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
129							  (__v2di)__Y,
130							  1);
131	}
132    } "-O2 -mpclmul -mavx" ]
133}
134
135# Return 1 if sse4a instructions can be compiled.
136proc check_effective_target_sse4a { } {
137    return [check_no_compiler_messages sse4a object {
138	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
139	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
140
141	__m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
142	{
143	    return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
144	}
145    } "-O2 -msse4a" ]
146}
147
148# Return 1 if fma4 instructions can be compiled.
149proc check_effective_target_fma4 { } {
150    return [check_no_compiler_messages fma4 object {
151        typedef float __m128 __attribute__ ((__vector_size__ (16)));
152	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
153	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
154	{
155	    return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
156						     (__v4sf)__B,
157						     (__v4sf)__C);
158	}
159    } "-O2 -mfma4" ]
160}
161
162# Return 1 if fma instructions can be compiled.
163proc check_effective_target_fma { } {
164    return [check_no_compiler_messages fma 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 -mfma" ]
174}
175
176# Return 1 if xop instructions can be compiled.
177proc check_effective_target_xop { } {
178    return [check_no_compiler_messages xop object {
179	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
180	typedef short __v8hi __attribute__ ((__vector_size__ (16)));
181	__m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
182	{
183	    return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
184						       (__v8hi)__B,
185						       (__v8hi)__C);
186	}
187    } "-O2 -mxop" ]
188}
189
190# Return 1 if lzcnt instruction can be compiled.
191proc check_effective_target_lzcnt { } {
192    return [check_no_compiler_messages lzcnt object {
193	unsigned short _lzcnt (unsigned short __X)
194	{
195	   return __builtin_clzs (__X);
196	}
197    } "-mlzcnt" ]
198}
199
200# Return 1 if bmi instructions can be compiled.
201proc check_effective_target_bmi { } {
202    return [check_no_compiler_messages bmi object {
203	unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
204	{
205	  return __builtin_ia32_bextr_u32 (__X, __Y);
206	}
207    } "-mbmi" ]
208}
209
210# Return 1 if ADX instructions can be compiled.
211proc check_effective_target_adx { } {
212    return [check_no_compiler_messages adx object {
213	unsigned char
214	_adxcarry_u32 (unsigned char __CF, unsigned int __X,
215		   unsigned int __Y, unsigned int *__P)
216	{
217	    return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
218	}
219    } "-madx" ]
220}
221
222# Return 1 if rtm instructions can be compiled.
223proc check_effective_target_rtm { } {
224    return [check_no_compiler_messages rtm object {
225	void
226	_rtm_xend (void)
227	{
228	    return __builtin_ia32_xend ();
229	}
230    } "-mrtm" ]
231}
232
233# Return 1 if avx512vl instructions can be compiled.
234proc check_effective_target_avx512vl { } {
235    return [check_no_compiler_messages avx512vl object {
236	typedef long long __v4di __attribute__ ((__vector_size__ (32)));
237	__v4di
238	mm256_and_epi64  (__v4di __X, __v4di __Y)
239	{
240            __v4di __W;
241            return __builtin_ia32_pandq256_mask (__X, __Y, __W, -1);
242	}
243    } "-mavx512vl" ]
244}
245
246# Return 1 if avx512cd instructions can be compiled.
247proc check_effective_target_avx512cd { } {
248    return [check_no_compiler_messages avx512cd_trans object {
249	typedef long long __v8di __attribute__ ((__vector_size__ (64)));
250	__v8di
251	_mm512_conflict_epi64 (__v8di __W, __v8di __A)
252	{
253	  return (__v8di) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A,
254								 (__v8di) __W,
255								 -1);
256	}
257   } "-Wno-psabi -mavx512cd" ]
258}
259
260# Return 1 if avx512er instructions can be compiled.
261proc check_effective_target_avx512er { } {
262    return [check_no_compiler_messages avx512er_trans object {
263	typedef float __v16sf __attribute__ ((__vector_size__ (64)));
264	__v16sf
265	mm512_exp2a23_ps  (__v16sf __X)
266	{
267	    return __builtin_ia32_exp2ps_mask (__X, __X, -1, 4);
268	}
269   } "-Wno-psabi -mavx512er" ]
270}
271
272# Return 1 if sha instructions can be compiled.
273proc check_effective_target_sha { } {
274    return [check_no_compiler_messages sha object {
275	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
276	typedef int __v4si __attribute__ ((__vector_size__ (16)));
277
278	__m128i _mm_sha1msg1_epu32 (__m128i __X, __m128i __Y)
279	{
280            return (__m128i) __builtin_ia32_sha1msg1 ((__v4si)__X,
281						      (__v4si)__Y);
282	}
283    } "-O2 -msha" ]
284}
285
286# Return 1 if avx512dq instructions can be compiled.
287proc check_effective_target_avx512dq { } {
288    return [check_no_compiler_messages avx512dq object {
289	typedef long long __v8di __attribute__ ((__vector_size__ (64)));
290	__v8di
291	_mm512_mask_mullo_epi64 (__v8di __W, __v8di __A, __v8di __B)
292	{
293	    return (__v8di) __builtin_ia32_pmullq512_mask ((__v8di) __A,
294							    (__v8di) __B,
295							    (__v8di) __W,
296							    -1);
297	}
298    } "-mavx512dq" ]
299}
300
301# Return 1 if avx512bw instructions can be compiled.
302proc check_effective_target_avx512bw { } {
303    return [check_no_compiler_messages avx512bw object {
304	typedef short __v32hi __attribute__ ((__vector_size__ (64)));
305	__v32hi
306	_mm512_mask_mulhrs_epi16 (__v32hi __W, __v32hi __A, __v32hi __B)
307	{
308	    return (__v32hi) __builtin_ia32_pmulhrsw512_mask ((__v32hi) __A,
309							    (__v32hi) __B,
310							    (__v32hi) __W,
311							    -1);
312	}
313    } "-mavx512bw" ]
314}
315
316# Return 1 if avx512ifma instructions can be compiled.
317proc check_effective_target_avx512ifma { } {
318    return [check_no_compiler_messages avx512ifma object {
319	typedef long long __v8di __attribute__ ((__vector_size__ (64)));
320	__v8di
321	_mm512_madd52lo_epu64 (__v8di __X, __v8di __Y, __v8di __Z)
322	{
323	  return (__v8di) __builtin_ia32_vpmadd52luq512_mask ((__v8di) __X,
324							       (__v8di) __Y,
325						               (__v8di) __Z,
326						               -1);
327	}
328    } "-mavx512ifma" ]
329}
330
331# Return 1 if avx512vbmi instructions can be compiled.
332proc check_effective_target_avx512vbmi { } {
333    return [check_no_compiler_messages avx512vbmi object {
334	typedef char __v64qi __attribute__ ((__vector_size__ (64)));
335	__v64qi
336	_mm512_multishift_epi64_epi8 (__v64qi __X, __v64qi __Y)
337	{
338	  return (__v64qi) __builtin_ia32_vpmultishiftqb512_mask ((__v64qi) __X,
339								 (__v64qi) __Y,
340								 (__v64qi) __Y,
341								 -1);
342	}
343    } "-mavx512vbmi" ]
344}
345
346# Return 1 if avx512_4fmaps instructions can be compiled.
347proc check_effective_target_avx5124fmaps { } {
348    return [check_no_compiler_messages avx5124fmaps object {
349	typedef float __v16sf __attribute__ ((__vector_size__ (64)));
350	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
351
352	__v16sf
353	_mm512_mask_4fmadd_ps (__v16sf __DEST, __v16sf __A, __v16sf __B, __v16sf __C,
354			       __v16sf __D, __v16sf __E, __v4sf *__F)
355	{
356	    return (__v16sf) __builtin_ia32_4fmaddps_mask ((__v16sf) __A,
357							  (__v16sf) __B,
358							  (__v16sf) __C,
359							  (__v16sf) __D,
360							  (__v16sf) __E,
361							  (const __v4sf *) __F,
362							  (__v16sf) __DEST,
363							  0xffff);
364	}
365    } "-mavx5124fmaps" ]
366}
367
368# Return 1 if avx512_4vnniw instructions can be compiled.
369proc check_effective_target_avx5124vnniw { } {
370    return [check_no_compiler_messages avx5124vnniw object {
371	typedef int __v16si __attribute__ ((__vector_size__ (64)));
372	typedef int __v4si __attribute__ ((__vector_size__ (16)));
373
374	__v16si
375	_mm512_4dpwssd_epi32 (__v16si __A, __v16si __B, __v16si __C,
376			      __v16si __D, __v16si __E, __v4si *__F)
377	{
378	    return (__v16si) __builtin_ia32_vp4dpwssd ((__v16si) __B,
379						       (__v16si) __C,
380						       (__v16si) __D,
381						       (__v16si) __E,
382						       (__v16si) __A,
383						       (const __v4si *) __F);
384	}
385    } "-mavx5124vnniw" ]
386}
387
388# Return 1 if avx512_vpopcntdq instructions can be compiled.
389proc check_effective_target_avx512vpopcntdq { } {
390    return [check_no_compiler_messages avx512vpopcntdq object {
391        typedef int __v16si __attribute__ ((__vector_size__ (64)));
392
393        __v16si
394        _mm512_popcnt_epi32 (__v16si __A)
395        {
396            return (__v16si) __builtin_ia32_vpopcountd_v16si ((__v16si) __A);
397        }
398    } "-mavx512vpopcntdq" ]
399}
400
401# Return 1 if 128 or 256-bit avx512_vpopcntdq instructions can be compiled.
402proc check_effective_target_avx512vpopcntdqvl { } {
403    return [check_no_compiler_messages avx512vpopcntdqvl object {
404        typedef int __v8si __attribute__ ((__vector_size__ (32)));
405
406        __v8si
407        _mm256_popcnt_epi32 (__v8si __A)
408        {
409            return (__v8si) __builtin_ia32_vpopcountd_v8si ((__v8si) __A);
410        }
411    } "-mavx512vpopcntdq -mavx512vl" ]
412}
413
414# Return 1 if gfni instructions can be compiled.
415proc check_effective_target_gfni { } {
416    return [check_no_compiler_messages gfni object {
417        typedef char __v16qi __attribute__ ((__vector_size__ (16)));
418
419        __v16qi
420        _mm_gf2p8affineinv_epi64_epi8 (__v16qi __A, __v16qi __B, const int __C)
421        {
422            return (__v16qi) __builtin_ia32_vgf2p8affineinvqb_v16qi ((__v16qi) __A,
423								     (__v16qi) __B,
424								      0);
425        }
426    } "-mgfni" ]
427}
428
429# Return 1 if avx512vbmi2 instructions can be compiled.
430proc check_effective_target_avx512vbmi2 { } {
431    return [check_no_compiler_messages avx512vbmi2 object {
432        typedef char __v16qi __attribute__ ((__vector_size__ (16)));
433	typedef unsigned long long __mmask16;
434
435	__v16qi
436	_mm_mask_compress_epi8 (__v16qi __A, __mmask16 __B, __v16qi __C)
437	{
438  		return (__v16qi) __builtin_ia32_compressqi128_mask((__v16qi)__C,
439								   (__v16qi)__A,
440								   (__mmask16)__B);
441	}
442    } "-mavx512vbmi2 -mavx512vl" ]
443}
444
445# Return 1 if avx512vbmi2 instructions can be compiled.
446proc check_effective_target_avx512vnni { } {
447    return [check_no_compiler_messages avx512vnni object {
448        typedef int __v16si __attribute__ ((__vector_size__ (64)));
449
450	__v16si
451	_mm_mask_compress_epi8 (__v16si __A, __v16si __B, __v16si __C)
452	{
453  		return (__v16si) __builtin_ia32_vpdpbusd_v16si ((__v16si)__A,
454								(__v16si)__B,
455								(__v16si)__C);
456	}
457    } "-mavx512vnni -mavx512f" ]
458}
459
460# Return 1 if vaes instructions can be compiled.
461proc check_effective_target_avx512vaes { } {
462    return [check_no_compiler_messages avx512vaes object {
463
464        typedef int __v16si __attribute__ ((__vector_size__ (64)));
465
466	__v32qi
467	_mm256_aesdec_epi128 (__v32qi __A, __v32qi __B)
468	{
469	  return (__v32qi)__builtin_ia32_vaesdec_v32qi ((__v32qi) __A, (__v32qi) __B);
470	}
471    } "-mvaes" ]
472}
473
474# Return 1 if vpclmulqdq instructions can be compiled.
475proc check_effective_target_vpclmulqdq { } {
476    return [check_no_compiler_messages vpclmulqdq object {
477        typedef long long __v4di __attribute__ ((__vector_size__ (32)));
478
479        __v4di
480        _mm256_clmulepi64_epi128 (__v4di __A, __v4di __B)
481        {
482            return (__v4di) __builtin_ia32_vpclmulqdq_v4di (__A, __B, 0);
483        }
484    } "-mvpclmulqdq -mavx512vl" ]
485}
486
487# Return 1 if avx512_bitalg instructions can be compiled.
488proc check_effective_target_avx512bitalg { } {
489    return [check_no_compiler_messages avx512bitalg object {
490        typedef short int __v32hi __attribute__ ((__vector_size__ (64)));
491
492        __v32hi
493        _mm512_popcnt_epi16 (__v32hi __A)
494        {
495            return (__v32hi) __builtin_ia32_vpopcountw_v32hi ((__v32hi) __A);
496        }
497    } "-mavx512bitalg" ]
498}
499
500# If a testcase doesn't have special options, use these.
501global DEFAULT_CFLAGS
502if ![info exists DEFAULT_CFLAGS] then {
503    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
504}
505
506# Initialize `dg'.
507dg-init
508clearcap-init
509
510global runtests
511# Special case compilation of vect-args.c so we don't have to
512# replicate it 16 times.
513if [runtest_file_p $runtests $srcdir/$subdir/vect-args.c] {
514  foreach type { "" -mmmx -m3dnow -msse -msse2 -mavx -mavx2 -mavx512f } {
515    foreach level { "" -O } {
516      set flags "$type $level"
517      verbose -log "Testing vect-args, $flags" 1
518      dg-test $srcdir/$subdir/vect-args.c $flags ""
519    }
520  }
521}
522
523# Everything else.
524set tests [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]]
525set tests [prune $tests $srcdir/$subdir/vect-args.c]
526
527# Main loop.
528dg-runtest $tests "" $DEFAULT_CFLAGS
529
530# All done.
531clearcap-finish
532dg-finish
533