OSDN Git Service

Add -mlzcnt.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / i386.exp
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.
21 if { ![istarget i?86*-*-*] && ![istarget x86_64-*-*] } then {
22   return
23 }
24
25 # Load support procs.
26 load_lib gcc-dg.exp
27
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 ();
32          } ""] } {
33         return 1
34     } else {
35         return 0
36     }
37 }
38
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)));
44
45         __m64 _m_pfadd (__m64 __A, __m64 __B)
46         {
47             return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
48         }
49     } "-O2 -m3dnow" ]
50 }
51
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)));
57
58         __m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
59         {
60             return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
61         }
62     } "-O2 -msse3" ]
63 }
64
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)));
70
71         __m128i _mm_abs_epi32 (__m128i __X)
72         {
73             return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
74         }
75     } "-O2 -mssse3" ]
76 }
77
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)));
83
84         __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
85         {
86             return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
87                                                        (__v4si)__Y);
88         }
89     } "-O2 -msse4.1" ]
90 }
91
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)));
97
98         __m128i _mm_aesimc_si128 (__m128i __X)
99         {
100             return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
101         }
102     } "-O2 -maes" ]
103 }
104
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)));
110
111         __m128i _mm_aesimc_si128 (__m128i __X)
112         {
113             return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
114         }
115     } "-O2 -maes -mavx" ]
116 }
117
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)));
123
124         __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
125         {
126             return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
127                                                           (__v2di)__Y,
128                                                           1);
129         }
130     } "-O2 -mpclmul" ]
131 }
132
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)));
138
139         __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
140         {
141             return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
142                                                           (__v2di)__Y,
143                                                           1);
144         }
145     } "-O2 -mpclmul -mavx" ]
146 }
147
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)));
153
154         __m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
155         {
156             return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
157         }
158     } "-O2 -msse4a" ]
159 }
160
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)
167         {
168             return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
169                                                      (__v4sf)__B,
170                                                      (__v4sf)__C);
171         }
172     } "-O2 -mfma4" ]
173 }
174
175 # Return 1 if xop instructions can be compiled.
176 proc check_effective_target_xop { } {
177     return [check_no_compiler_messages xop object {
178         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
179         typedef short __v8hi __attribute__ ((__vector_size__ (16)));
180         __m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
181         {
182             return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
183                                                        (__v8hi)__B,
184                                                        (__v8hi)__C);
185         }
186     } "-O2 -mxop" ]
187 }
188
189 # Return 1 if lzcnt instruction can be compiled.
190 proc check_effective_target_lzcnt { } {
191     return [check_no_compiler_messages lzcnt object {
192         unsigned short _lzcnt (unsigned short __X)
193         {
194            return __builtin_clzs (__X);
195         }
196     } "-mlzcnt" ]
197 }
198
199 # Return 1 if bmi instructions can be compiled.
200 proc check_effective_target_bmi { } {
201     return [check_no_compiler_messages bmi object {
202         unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
203         {
204           return __builtin_ia32_bextr_u32 (__X, __Y);
205         }
206     } "-mbmi" ]
207 }
208
209 # If the linker used understands -M <mapfile>, pass it to clear hardware
210 # capabilities set by the Sun assembler.
211 set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcap.map"
212
213 if [check_no_compiler_messages mapfile executable {
214         int main (void) { return 0; }
215   } $clearcap_ldflags ] {
216
217   if { [info procs gcc_target_compile] != [list] \
218         && [info procs saved_gcc_target_compile] == [list] } {
219     rename gcc_target_compile saved_gcc_target_compile
220
221     proc gcc_target_compile { source dest type options } {
222       global clearcap_ldflags
223       # Always pass -Wl,-M,<mapfile>, but don't let it show up in gcc.sum.
224       lappend options "additional_flags=$clearcap_ldflags"
225
226       return [saved_gcc_target_compile $source $dest $type $options]
227     }
228   }
229 }
230
231 # If a testcase doesn't have special options, use these.
232 global DEFAULT_CFLAGS
233 if ![info exists DEFAULT_CFLAGS] then {
234     set DEFAULT_CFLAGS " -ansi -pedantic-errors"
235 }
236
237 # Initialize `dg'.
238 dg-init
239
240 # Special case compilation of vect-args.c so we don't have to
241 # replicate it 10 times.
242 foreach type { "" -mmmx -m3dnow -msse -msse2 } {
243   foreach level { "" -O } {
244     set flags "$type $level"
245     verbose -log "Testing vect-args, $flags" 1
246     dg-test $srcdir/$subdir/vect-args.c $flags ""
247   }
248 }
249
250 # Everything else.
251 set tests [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]]
252 set tests [prune $tests $srcdir/$subdir/vect-args.c]
253
254 # Main loop.
255 dg-runtest $tests "" $DEFAULT_CFLAGS
256
257 # All done.
258 dg-finish