1 # Copyright (C) 1997, 2004, 2007, 2008, 2009, 2010, 2011, 2012
2 # Free Software Foundation, Inc.
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.
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.
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/>.
18 # GCC testsuite that uses the `dg.exp' driver.
20 # Exit immediately if this isn't a x86 target.
21 if { ![istarget i?86*-*-*] && ![istarget x86_64-*-*] } then {
28 # Return 1 if attribute ms_hook_prologue is supported.
29 proc check_effective_target_ms_hook_prologue { } {
30 if { [check_no_compiler_messages ms_hook_prologue object {
31 void __attribute__ ((__ms_hook_prologue__)) foo ();
39 # Return 1 if 3dnow instructions can be compiled.
40 proc check_effective_target_3dnow { } {
41 return [check_no_compiler_messages 3dnow object {
42 typedef int __m64 __attribute__ ((__vector_size__ (8)));
43 typedef float __v2sf __attribute__ ((__vector_size__ (8)));
45 __m64 _m_pfadd (__m64 __A, __m64 __B)
47 return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
52 # Return 1 if sse3 instructions can be compiled.
53 proc check_effective_target_sse3 { } {
54 return [check_no_compiler_messages sse3 object {
55 typedef double __m128d __attribute__ ((__vector_size__ (16)));
56 typedef double __v2df __attribute__ ((__vector_size__ (16)));
58 __m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
60 return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
65 # Return 1 if ssse3 instructions can be compiled.
66 proc check_effective_target_ssse3 { } {
67 return [check_no_compiler_messages ssse3 object {
68 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
69 typedef int __v4si __attribute__ ((__vector_size__ (16)));
71 __m128i _mm_abs_epi32 (__m128i __X)
73 return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
78 # Return 1 if sse4 instructions can be compiled.
79 proc check_effective_target_sse4 { } {
80 return [check_no_compiler_messages sse4.1 object {
81 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
82 typedef int __v4si __attribute__ ((__vector_size__ (16)));
84 __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
86 return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
92 # Return 1 if aes instructions can be compiled.
93 proc check_effective_target_aes { } {
94 return [check_no_compiler_messages aes object {
95 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
96 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
98 __m128i _mm_aesimc_si128 (__m128i __X)
100 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
105 # Return 1 if vaes instructions can be compiled.
106 proc check_effective_target_vaes { } {
107 return [check_no_compiler_messages vaes object {
108 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
109 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
111 __m128i _mm_aesimc_si128 (__m128i __X)
113 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
115 } "-O2 -maes -mavx" ]
118 # Return 1 if pclmul instructions can be compiled.
119 proc check_effective_target_pclmul { } {
120 return [check_no_compiler_messages pclmul object {
121 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
122 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
124 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
126 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
133 # Return 1 if vpclmul instructions can be compiled.
134 proc check_effective_target_vpclmul { } {
135 return [check_no_compiler_messages vpclmul object {
136 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
137 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
139 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
141 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
145 } "-O2 -mpclmul -mavx" ]
148 # Return 1 if sse4a instructions can be compiled.
149 proc check_effective_target_sse4a { } {
150 return [check_no_compiler_messages sse4a object {
151 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
152 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
154 __m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
156 return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
161 # Return 1 if fma4 instructions can be compiled.
162 proc check_effective_target_fma4 { } {
163 return [check_no_compiler_messages fma4 object {
164 typedef float __m128 __attribute__ ((__vector_size__ (16)));
165 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
166 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
168 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
175 # Return 1 if fma instructions can be compiled.
176 proc check_effective_target_fma { } {
177 return [check_no_compiler_messages fma object {
178 typedef float __m128 __attribute__ ((__vector_size__ (16)));
179 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
180 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
182 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
189 # Return 1 if xop instructions can be compiled.
190 proc check_effective_target_xop { } {
191 return [check_no_compiler_messages xop object {
192 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
193 typedef short __v8hi __attribute__ ((__vector_size__ (16)));
194 __m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
196 return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
203 # Return 1 if lzcnt instruction can be compiled.
204 proc check_effective_target_lzcnt { } {
205 return [check_no_compiler_messages lzcnt object {
206 unsigned short _lzcnt (unsigned short __X)
208 return __builtin_clzs (__X);
213 # Return 1 if avx2 instructions can be compiled.
214 proc check_effective_target_avx2 { } {
215 return [check_no_compiler_messages avx2 object {
216 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
218 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
220 return __builtin_ia32_andnotsi256 (__X, __Y);
225 # Return 1 if bmi instructions can be compiled.
226 proc check_effective_target_bmi { } {
227 return [check_no_compiler_messages bmi object {
228 unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
230 return __builtin_ia32_bextr_u32 (__X, __Y);
235 # Return 1 if bmi2 instructions can be compiled.
236 proc check_effective_target_bmi2 { } {
237 return [check_no_compiler_messages bmi2 object {
239 _bzhi_u32 (unsigned int __X, unsigned int __Y)
241 return __builtin_ia32_bzhi_si (__X, __Y);
246 # Return 1 if ADX instructions can be compiled.
247 proc check_effective_target_adx { } {
248 return [check_no_compiler_messages adx object {
250 _adxcarry_u32 (unsigned char __CF, unsigned int __X,
251 unsigned int __Y, unsigned int *__P)
253 return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
258 # Return 1 if rtm instructions can be compiled.
259 proc check_effective_target_rtm { } {
260 return [check_no_compiler_messages rtm object {
264 return __builtin_ia32_xend ();
269 # If the linker used understands -M <mapfile>, pass it to clear hardware
270 # capabilities set by the Sun assembler.
271 # Try mapfile syntax v2 first which is the only way to clear hwcap_2 flags.
272 set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcapv2.map"
274 if ![check_no_compiler_messages mapfilev2 executable {
275 int main (void) { return 0; }
276 } $clearcap_ldflags ] {
277 # If this doesn't work, fall back to the less capable v1 syntax.
278 set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcap.map"
280 if ![check_no_compiler_messages mapfile executable {
281 int main (void) { return 0; }
282 } $clearcap_ldflags ] {
283 unset clearcap_ldflags
287 if [info exists clearcap_ldflags] {
288 if { [info procs gcc_target_compile] != [list] \
289 && [info procs saved_gcc_target_compile] == [list] } {
290 rename gcc_target_compile saved_gcc_target_compile
292 proc gcc_target_compile { source dest type options } {
293 global clearcap_ldflags
294 # Always pass -Wl,-M,<mapfile>, but don't let it show up in gcc.sum.
295 lappend options "additional_flags=$clearcap_ldflags"
297 return [saved_gcc_target_compile $source $dest $type $options]
302 # If a testcase doesn't have special options, use these.
303 global DEFAULT_CFLAGS
304 if ![info exists DEFAULT_CFLAGS] then {
305 set DEFAULT_CFLAGS " -ansi -pedantic-errors"
311 # Special case compilation of vect-args.c so we don't have to
312 # replicate it 10 times.
313 foreach type { "" -mmmx -m3dnow -msse -msse2 } {
314 foreach level { "" -O } {
315 set flags "$type $level"
316 verbose -log "Testing vect-args, $flags" 1
317 dg-test $srcdir/$subdir/vect-args.c $flags ""
322 set tests [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]]
323 set tests [prune $tests $srcdir/$subdir/vect-args.c]
326 dg-runtest $tests "" $DEFAULT_CFLAGS