1# Copyright (C) 1997-2013 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
26
27# Return 1 if attribute ms_hook_prologue is supported.
28proc check_effective_target_ms_hook_prologue { } {
29    if { [check_no_compiler_messages ms_hook_prologue object {
30	     void __attribute__ ((__ms_hook_prologue__)) foo ();
31	 } ""] } {
32	return 1
33    } else {
34	return 0
35    }
36}
37
38# Return 1 if 3dnow instructions can be compiled.
39proc check_effective_target_3dnow { } {
40    return [check_no_compiler_messages 3dnow object {
41	typedef int __m64 __attribute__ ((__vector_size__ (8)));
42	typedef float __v2sf __attribute__ ((__vector_size__ (8)));
43
44	__m64 _m_pfadd (__m64 __A, __m64 __B)
45	{
46	    return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
47	}
48    } "-O2 -m3dnow" ]
49}
50
51# Return 1 if sse3 instructions can be compiled.
52proc check_effective_target_sse3 { } {
53    return [check_no_compiler_messages sse3 object {
54	typedef double __m128d __attribute__ ((__vector_size__ (16)));
55	typedef double __v2df __attribute__ ((__vector_size__ (16)));
56
57	__m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
58	{
59	    return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
60	}
61    } "-O2 -msse3" ]
62}
63
64# Return 1 if ssse3 instructions can be compiled.
65proc check_effective_target_ssse3 { } {
66    return [check_no_compiler_messages ssse3 object {
67	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
68	typedef int __v4si __attribute__ ((__vector_size__ (16)));
69
70	__m128i _mm_abs_epi32 (__m128i __X)
71	{
72	    return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
73	}
74    } "-O2 -mssse3" ]
75}
76
77# Return 1 if sse4 instructions can be compiled.
78proc check_effective_target_sse4 { } {
79    return [check_no_compiler_messages sse4.1 object {
80	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
81	typedef int __v4si __attribute__ ((__vector_size__ (16)));
82
83	__m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
84	{
85	    return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
86						       (__v4si)__Y);
87	}
88    } "-O2 -msse4.1" ]
89}
90
91# Return 1 if aes instructions can be compiled.
92proc check_effective_target_aes { } {
93    return [check_no_compiler_messages aes object {
94	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
95	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
96
97	__m128i _mm_aesimc_si128 (__m128i __X)
98	{
99	    return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
100	}
101    } "-O2 -maes" ]
102}
103
104# Return 1 if vaes instructions can be compiled.
105proc check_effective_target_vaes { } {
106    return [check_no_compiler_messages vaes object {
107	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
108	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
109
110	__m128i _mm_aesimc_si128 (__m128i __X)
111	{
112	    return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
113	}
114    } "-O2 -maes -mavx" ]
115}
116
117# Return 1 if pclmul instructions can be compiled.
118proc check_effective_target_pclmul { } {
119    return [check_no_compiler_messages pclmul object {
120	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
121	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
122
123	__m128i pclmulqdq_test (__m128i __X, __m128i __Y)
124	{
125	    return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
126							  (__v2di)__Y,
127							  1);
128	}
129    } "-O2 -mpclmul" ]
130}
131
132# Return 1 if vpclmul instructions can be compiled.
133proc check_effective_target_vpclmul { } {
134    return [check_no_compiler_messages vpclmul object {
135	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
136	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
137
138	__m128i pclmulqdq_test (__m128i __X, __m128i __Y)
139	{
140	    return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
141							  (__v2di)__Y,
142							  1);
143	}
144    } "-O2 -mpclmul -mavx" ]
145}
146
147# Return 1 if sse4a instructions can be compiled.
148proc check_effective_target_sse4a { } {
149    return [check_no_compiler_messages sse4a object {
150	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
151	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
152
153	__m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
154	{
155	    return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
156	}
157    } "-O2 -msse4a" ]
158}
159
160# Return 1 if fma4 instructions can be compiled.
161proc check_effective_target_fma4 { } {
162    return [check_no_compiler_messages fma4 object {
163        typedef float __m128 __attribute__ ((__vector_size__ (16)));
164	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
165	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
166	{
167	    return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
168						     (__v4sf)__B,
169						     (__v4sf)__C);
170	}
171    } "-O2 -mfma4" ]
172}
173
174# Return 1 if fma instructions can be compiled.
175proc check_effective_target_fma { } {
176    return [check_no_compiler_messages fma object {
177        typedef float __m128 __attribute__ ((__vector_size__ (16)));
178	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
179	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
180	{
181	    return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
182						     (__v4sf)__B,
183						     (__v4sf)__C);
184	}
185    } "-O2 -mfma" ]
186}
187
188# Return 1 if xop instructions can be compiled.
189proc check_effective_target_xop { } {
190    return [check_no_compiler_messages xop object {
191	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
192	typedef short __v8hi __attribute__ ((__vector_size__ (16)));
193	__m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
194	{
195	    return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
196						       (__v8hi)__B,
197						       (__v8hi)__C);
198	}
199    } "-O2 -mxop" ]
200}
201
202# Return 1 if lzcnt instruction can be compiled.
203proc check_effective_target_lzcnt { } {
204    return [check_no_compiler_messages lzcnt object {
205	unsigned short _lzcnt (unsigned short __X)
206	{
207	   return __builtin_clzs (__X);
208	}
209    } "-mlzcnt" ]
210}
211
212# Return 1 if avx2 instructions can be compiled.
213proc check_effective_target_avx2 { } {
214    return [check_no_compiler_messages avx2 object {
215	typedef long long __v4di __attribute__ ((__vector_size__ (32)));
216	__v4di
217	mm256_is32_andnotsi256  (__v4di __X, __v4di __Y)
218        {
219	   return __builtin_ia32_andnotsi256 (__X, __Y);
220	}
221    } "-O0 -mavx2" ]
222}
223
224# Return 1 if bmi instructions can be compiled.
225proc check_effective_target_bmi { } {
226    return [check_no_compiler_messages bmi object {
227	unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
228	{
229	  return __builtin_ia32_bextr_u32 (__X, __Y);
230	}
231    } "-mbmi" ]
232}
233
234# Return 1 if bmi2 instructions can be compiled.
235proc check_effective_target_bmi2 { } {
236    return [check_no_compiler_messages bmi2 object {
237	unsigned int
238	_bzhi_u32 (unsigned int __X, unsigned int __Y)
239	{
240	    return __builtin_ia32_bzhi_si (__X, __Y);
241	}
242    } "-mbmi2" ]
243}
244
245# Return 1 if ADX instructions can be compiled.
246proc check_effective_target_adx { } {
247    return [check_no_compiler_messages adx object {
248	unsigned char
249	_adxcarry_u32 (unsigned char __CF, unsigned int __X,
250		   unsigned int __Y, unsigned int *__P)
251	{
252	    return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
253	}
254    } "-madx" ]
255}
256
257# Return 1 if rtm instructions can be compiled.
258proc check_effective_target_rtm { } {
259    return [check_no_compiler_messages rtm object {
260	void
261	_rtm_xend (void)
262	{
263	    return __builtin_ia32_xend ();
264	}
265    } "-mrtm" ]
266}
267
268# If the linker used understands -M <mapfile>, pass it to clear hardware
269# capabilities set by the Sun assembler.
270# Try mapfile syntax v2 first which is the only way to clear hwcap_2 flags.
271set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcapv2.map"
272
273if ![check_no_compiler_messages mapfilev2 executable {
274    int main (void) { return 0; }
275} $clearcap_ldflags ] {
276    # If this doesn't work, fall back to the less capable v1 syntax.
277    set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcap.map"
278
279    if ![check_no_compiler_messages mapfile executable {
280	int main (void) { return 0; }
281    } $clearcap_ldflags ] {
282	unset clearcap_ldflags
283    }
284}
285
286if [info exists clearcap_ldflags] {
287  if { [info procs gcc_target_compile] != [list] \
288	&& [info procs saved_gcc_target_compile] == [list] } {
289    rename gcc_target_compile saved_gcc_target_compile
290
291    proc gcc_target_compile { source dest type options } {
292      global clearcap_ldflags
293      # Always pass -Wl,-M,<mapfile>, but don't let it show up in gcc.sum.
294      lappend options "additional_flags=$clearcap_ldflags"
295
296      return [saved_gcc_target_compile $source $dest $type $options]
297    }
298  }
299}
300
301# If a testcase doesn't have special options, use these.
302global DEFAULT_CFLAGS
303if ![info exists DEFAULT_CFLAGS] then {
304    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
305}
306
307# Initialize `dg'.
308dg-init
309
310# Special case compilation of vect-args.c so we don't have to
311# replicate it 10 times.
312foreach type { "" -mmmx -m3dnow -msse -msse2 } {
313  foreach level { "" -O } {
314    set flags "$type $level"
315    verbose -log "Testing vect-args, $flags" 1
316    dg-test $srcdir/$subdir/vect-args.c $flags ""
317  }
318}
319
320# Everything else.
321set tests [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]]
322set tests [prune $tests $srcdir/$subdir/vect-args.c]
323
324# Main loop.
325dg-runtest $tests "" $DEFAULT_CFLAGS
326
327# All done.
328dg-finish
329