1# Copyright (C) 1997, 2004, 2007, 2008, 2009, 2010
2# Free Software Foundation, Inc.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with GCC; see the file COPYING3.  If not see
16# <http://www.gnu.org/licenses/>.
17
18# GCC testsuite that uses the `dg.exp' driver.
19
20# Exit immediately if this isn't a x86 target.
21if { ![istarget i?86*-*-*] && ![istarget x86_64-*-*] } then {
22  return
23}
24
25# Load support procs.
26load_lib gcc-dg.exp
27
28# Return 1 if attribute ms_hook_prologue is supported.
29proc check_effective_target_ms_hook_prologue { } {
30    if { [check_effective_target_ilp32]
31	 && [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	void _m_pfadd (void)
44	{
45	    __builtin_ia32_pfadd();
46	}
47    } "-O2 -m3dnow" ]
48}
49
50# Return 1 if sse3 instructions can be compiled.
51proc check_effective_target_sse3 { } {
52    return [check_no_compiler_messages sse3 object {
53	typedef double __m128d __attribute__ ((__vector_size__ (16)));
54	typedef double __v2df __attribute__ ((__vector_size__ (16)));
55
56	__m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
57	{
58	    return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
59	}
60    } "-O2 -msse3" ]
61}
62
63# Return 1 if ssse3 instructions can be compiled.
64proc check_effective_target_ssse3 { } {
65    return [check_no_compiler_messages ssse3 object {
66	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
67	typedef int __v4si __attribute__ ((__vector_size__ (16)));
68
69	__m128i _mm_abs_epi32 (__m128i __X)
70	{
71	    return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
72	}
73    } "-O2 -mssse3" ]
74}
75
76# Return 1 if sse4 instructions can be compiled.
77proc check_effective_target_sse4 { } {
78    return [check_no_compiler_messages sse4.1 object {
79	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
80	typedef int __v4si __attribute__ ((__vector_size__ (16)));
81
82	__m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
83	{
84	    return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
85						       (__v4si)__Y);
86	}
87    } "-O2 -msse4.1" ]
88}
89
90# Return 1 if aes instructions can be compiled.
91proc check_effective_target_aes { } {
92    return [check_no_compiler_messages aes object {
93	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
94	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
95
96	__m128i _mm_aesimc_si128 (__m128i __X)
97	{
98	    return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
99	}
100    } "-O2 -maes" ]
101}
102
103# Return 1 if vaes instructions can be compiled.
104proc check_effective_target_vaes { } {
105    return [check_no_compiler_messages vaes object {
106	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
107	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
108
109	__m128i _mm_aesimc_si128 (__m128i __X)
110	{
111	    return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
112	}
113    } "-O2 -maes -mavx" ]
114}
115
116# Return 1 if pclmul instructions can be compiled.
117proc check_effective_target_pclmul { } {
118    return [check_no_compiler_messages pclmul object {
119	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
120	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
121
122	__m128i pclmulqdq_test (__m128i __X, __m128i __Y)
123	{
124	    return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
125							  (__v2di)__Y,
126							  1);
127	}
128    } "-O2 -mpclmul" ]
129}
130
131# Return 1 if vpclmul instructions can be compiled.
132proc check_effective_target_vpclmul { } {
133    return [check_no_compiler_messages vpclmul object {
134	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
135	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
136
137	__m128i pclmulqdq_test (__m128i __X, __m128i __Y)
138	{
139	    return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
140							  (__v2di)__Y,
141							  1);
142	}
143    } "-O2 -mpclmul -mavx" ]
144}
145
146# Return 1 if sse4a instructions can be compiled.
147proc check_effective_target_sse4a { } {
148    return [check_no_compiler_messages sse4a object {
149	typedef long long __m128i __attribute__ ((__vector_size__ (16)));
150	typedef long long __v2di __attribute__ ((__vector_size__ (16)));
151
152	__m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
153	{
154	    return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
155	}
156    } "-O2 -msse4a" ]
157}
158
159# Return 1 if fma4 instructions can be compiled.
160proc check_effective_target_fma4 { } {
161    return [check_no_compiler_messages fma4 object {
162        typedef float __m128 __attribute__ ((__vector_size__ (16)));
163	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
164	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
165	{
166	    return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
167						     (__v4sf)__B,
168						     (__v4sf)__C);
169	}
170    } "-O2 -mfma4" ]
171}
172
173# Return 1 if xop instructions can be compiled.
174proc check_effective_target_xop { } {
175    return [check_no_compiler_messages xop object {
176	typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
177	typedef short __v8hi __attribute__ ((__vector_size__ (16)));
178	__m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
179	{
180	    return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
181						       (__v8hi)__B,
182						       (__v8hi)__C);
183	}
184    } "-O2 -mxop" ]
185}
186
187# If the linker used understands -M <mapfile>, pass it to clear hardware
188# capabilities set by the Sun assembler.
189set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcap.map"
190
191if [check_no_compiler_messages mapfile executable {
192	int main (void) { return 0; }
193  } $clearcap_ldflags ] {
194
195  if { [info procs gcc_target_compile] != [list] \
196	&& [info procs saved_gcc_target_compile] == [list] } {
197    rename gcc_target_compile saved_gcc_target_compile
198
199    proc gcc_target_compile { source dest type options } {
200      global clearcap_ldflags
201      # Always pass -Wl,-M,<mapfile>, but don't let it show up in gcc.sum.
202      lappend options "additional_flags=$clearcap_ldflags"
203
204      return [saved_gcc_target_compile $source $dest $type $options]
205    }
206  }
207}
208
209# If a testcase doesn't have special options, use these.
210global DEFAULT_CFLAGS
211if ![info exists DEFAULT_CFLAGS] then {
212    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
213}
214
215# Initialize `dg'.
216dg-init
217
218# Special case compilation of vect-args.c so we don't have to
219# replicate it 10 times.
220foreach type { "" -mmmx -m3dnow -msse -msse2 } {
221  foreach level { "" -O } {
222    set flags "$type $level"
223    verbose -log "Testing vect-args, $flags" 1
224    dg-test $srcdir/$subdir/vect-args.c $flags ""
225  }
226}
227
228# Everything else.
229set tests [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]]
230set tests [prune $tests $srcdir/$subdir/vect-args.c]
231
232# Main loop.
233dg-runtest $tests "" $DEFAULT_CFLAGS
234
235# All done.
236dg-finish
237