]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/target-supports.exp
Makefile.in (libgcc-support, [...]): Add emutls.c.
[thirdparty/gcc.git] / gcc / testsuite / lib / target-supports.exp
CommitLineData
624168de 1# Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007
265e7d50 2# Free Software Foundation, Inc.
71152e6d
NC
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 2 of the License, or
7# (at your option) any later version.
21526606 8#
71152e6d
NC
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.
21526606 13#
71152e6d
NC
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
f115b653 16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
71152e6d
NC
17
18# Please email any bugs, comments, and/or additions to this file to:
19# gcc-patches@gcc.gnu.org
20
21# This file defines procs for determining features supported by the target.
22
19450f2b
DJ
23# Try to compile some code and return the messages printed by the compiler,
24# and optionally the contents for assembly files. Either a string or
25# a list of two strings are returned, depending on WANT_OUTPUT.
b6dc500c
JJ
26#
27# BASENAME is a basename to use for temporary files.
19450f2b
DJ
28# WANT_OUTPUT is a flag which is 0 to request returning just the
29# compiler messages, or 1 to return the messages and the contents
30# of the assembly file. TYPE should be "assembly" if WANT_OUTPUT
31# is set.
b6dc500c
JJ
32# TYPE is the type of compilation to perform (see target_compile).
33# CONTENTS gives the contents of the input file.
b6e3f572
HPN
34# The rest is optional:
35# OPTIONS: additional compiler options to use.
19450f2b 36proc get_compiler_messages {basename want_output type contents args} {
b6dc500c
JJ
37 global tool
38
b6e3f572 39 if { [llength $args] > 0 } {
c03b9206 40 set options [list "additional_flags=[lindex $args 0]"]
b6e3f572
HPN
41 } else {
42 set options ""
43 }
44
b6dc500c
JJ
45 set src ${basename}[pid].c
46 switch $type {
47 assembly { set output ${basename}[pid].s }
48 object { set output ${basename}[pid].o }
49 }
50 set f [open $src "w"]
51 puts $f $contents
52 close $f
b6e3f572 53 set lines [${tool}_target_compile $src $output $type "$options"]
b6dc500c 54 file delete $src
b6dc500c 55
19450f2b
DJ
56 if { $want_output } {
57 if { $type != "assembly" } {
58 error "WANT_OUTPUT can only be used with assembly output"
59 } elseif { ![string match "" $lines] } {
60 # An error occurred.
61 set result [list $lines ""]
62 } else {
63 set text ""
64 set chan [open "$output"]
65 while {[gets $chan line] >= 0} {
66 append text "$line\n"
67 }
68 close $chan
69 set result [list $lines $text]
70 }
71 } else {
72 set result $lines
73 }
74
75 remote_file build delete $output
76 return $result
b6dc500c
JJ
77}
78
635b0f2a
JJ
79proc current_target_name { } {
80 global target_info
81 if [info exists target_info(target,name)] {
82 set answer $target_info(target,name)
83 } else {
84 set answer ""
85 }
86 return $answer
87}
88
8ce1ac69
RS
89# Implement an effective-target check for property PROP by invoking
90# the compiler and seeing if it prints any messages. Assume that the
91# property holds if the compiler doesn't print anything. The other
92# arguments are as for get_compiler_messages, starting with TYPE.
93proc check_no_compiler_messages {prop args} {
94 global et_cache
95
96 set target [current_target_name]
97 if {![info exists et_cache($prop,target)]
98 || $et_cache($prop,target) != $target} {
19450f2b
DJ
99 verbose "check_no_compiler_messages $prop: compiling source for $target" 2
100 set et_cache($prop,target) $target
101 set et_cache($prop,value) \
102 [string match "" [eval get_compiler_messages $prop 0 $args]]
103 }
104 set value $et_cache($prop,value)
105 verbose "check_no_compiler_messages $prop: returning $value for $target" 2
106 return $value
107}
108
109# Similar to check_no_compiler_messages, but also verify that the regular
110# expression PATTERN matches the compiler's output.
111proc check_no_messages_and_pattern {prop pattern args} {
112 global et_cache
113
114 set target [current_target_name]
115 if {![info exists et_cache($prop,target)]
116 || $et_cache($prop,target) != $target} {
117 verbose "check_no_messages_and_pattern $prop: compiling source for $target" 2
8ce1ac69 118 set et_cache($prop,target) $target
19450f2b 119 set results [eval get_compiler_messages $prop 1 $args]
8ce1ac69 120 set et_cache($prop,value) \
19450f2b
DJ
121 [expr [string match "" [lindex $results 0]] \
122 && [regexp $pattern [lindex $results 1]]]
8ce1ac69
RS
123 }
124 set value $et_cache($prop,value)
19450f2b 125 verbose "check_no_messages_and_pattern $prop: returning $value for $target" 2
8ce1ac69
RS
126 return $value
127}
128
71152e6d
NC
129###############################
130# proc check_weak_available { }
131###############################
132
133# weak symbols are only supported in some configs/object formats
134# this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
135
136proc check_weak_available { } {
432fa9f2 137 global target_triplet
71152e6d
NC
138 global target_cpu
139
140 # All mips targets should support it
21526606 141
71152e6d
NC
142 if { [ string first "mips" $target_cpu ] >= 0 } {
143 return 1
144 }
145
fa4211cb 146 # All solaris2 targets should support it
21526606 147
fa4211cb
KG
148 if { [regexp ".*-solaris2.*" $target_triplet] } {
149 return 1
150 }
151
432fa9f2
RO
152 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
153
154 if { [regexp "alpha.*osf.*" $target_triplet] } {
155 return 1
156 }
157
c37780f5
AL
158 # Windows targets Cygwin and MingW32 support it
159
160 if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
161 return 1
162 }
163
6731e86d
JDA
164 # HP-UX 10.X doesn't support it
165
60784de8 166 if { [istarget "hppa*-*-hpux10*"] } {
6731e86d
JDA
167 return 0
168 }
169
71152e6d
NC
170 # ELF and ECOFF support it. a.out does with gas/gld but may also with
171 # other linkers, so we should try it
172
173 set objformat [gcc_target_object_format]
174
175 switch $objformat {
176 elf { return 1 }
177 ecoff { return 1 }
178 a.out { return 1 }
98f61f57 179 mach-o { return 1 }
6731e86d 180 som { return 1 }
71152e6d
NC
181 unknown { return -1 }
182 default { return 0 }
183 }
184}
185
facef326 186###############################
d3d9a67f 187# proc check_visibility_available { what_kind }
facef326
MA
188###############################
189
190# The visibility attribute is only support in some object formats
79c70e5a 191# This proc returns 1 if it is supported, 0 if not.
d3d9a67f 192# The argument is the kind of visibility, default/protected/hidden/internal.
facef326 193
d3d9a67f 194proc check_visibility_available { what_kind } {
79c70e5a 195 global tool
facef326 196 global target_triplet
facef326 197
61fec9ff 198 # On NetWare, support makes no sense.
345f13fe 199 if { [istarget *-*-netware*] } {
61fec9ff
JB
200 return 0
201 }
202
d3d9a67f
GK
203 if [string match "" $what_kind] { set what_kind "hidden" }
204
8ce1ac69 205 return [check_no_compiler_messages visibility_available_$what_kind object "
d3d9a67f
GK
206 void f() __attribute__((visibility(\"$what_kind\")));
207 void f() {}
208 "]
facef326
MA
209}
210
71152e6d
NC
211###############################
212# proc check_alias_available { }
213###############################
214
215# Determine if the target toolchain supports the alias attribute.
71152e6d 216
b4e0fcc3
MM
217# Returns 2 if the target supports aliases. Returns 1 if the target
218# only supports weak aliased. Returns 0 if the target does not
219# support aliases at all. Returns -1 if support for aliases could not
220# be determined.
221
222proc check_alias_available { } {
71152e6d 223 global alias_available_saved
bfa21a28
MM
224 global tool
225
71152e6d
NC
226 if [info exists alias_available_saved] {
227 verbose "check_alias_available returning saved $alias_available_saved" 2
228 } else {
8dc84ef1
JJ
229 set src alias[pid].c
230 set obj alias[pid].o
231 verbose "check_alias_available compiling testfile $src" 2
232 set f [open $src "w"]
3348ded5
MM
233 # Compile a small test program. The definition of "g" is
234 # necessary to keep the Solaris assembler from complaining
235 # about the program.
54a47870 236 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
3348ded5 237 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
b4e0fcc3 238 close $f
8dc84ef1
JJ
239 set lines [${tool}_target_compile $src $obj object ""]
240 file delete $src
241 remote_file build delete $obj
b4e0fcc3 242
71152e6d
NC
243 if [string match "" $lines] then {
244 # No error messages, everything is OK.
b4e0fcc3 245 set alias_available_saved 2
71152e6d
NC
246 } else {
247 if [regexp "alias definitions not supported" $lines] {
248 verbose "check_alias_available target does not support aliases" 2
249
250 set objformat [gcc_target_object_format]
251
252 if { $objformat == "elf" } {
253 verbose "check_alias_available but target uses ELF format, so it ought to" 2
b4e0fcc3 254 set alias_available_saved -1
71152e6d 255 } else {
b4e0fcc3 256 set alias_available_saved 0
71152e6d
NC
257 }
258 } else {
9ef6d39a
JO
259 if [regexp "only weak aliases are supported" $lines] {
260 verbose "check_alias_available target supports only weak aliases" 2
b4e0fcc3 261 set alias_available_saved 1
9ef6d39a 262 } else {
b4e0fcc3 263 set alias_available_saved -1
9ef6d39a 264 }
71152e6d
NC
265 }
266 }
21526606 267
71152e6d
NC
268 verbose "check_alias_available returning $alias_available_saved" 2
269 }
270
271 return $alias_available_saved
272}
b4e0fcc3
MM
273
274# Returns true if --gc-sections is supported on the target.
275
276proc check_gc_sections_available { } {
277 global gc_sections_available_saved
bfa21a28 278 global tool
b4e0fcc3 279
4293f7cb 280 if {![info exists gc_sections_available_saved]} {
8138dfe4
RH
281 # Some targets don't support gc-sections despite whatever's
282 # advertised by ld's options.
283 if { [istarget alpha*-*-*]
284 || [istarget ia64-*-*] } {
285 set gc_sections_available_saved 0
286 return 0
287 }
288
b4e0fcc3 289 # Check if the ld used by gcc supports --gc-sections.
61fec9ff
JB
290 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
291 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
292 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
b4e0fcc3
MM
293 set ld_output [remote_exec host "$gcc_ld" "--help"]
294 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
295 set gc_sections_available_saved 1
296 } else {
297 set gc_sections_available_saved 0
298 }
299 }
300 return $gc_sections_available_saved
301}
b8ee7f02
MM
302
303# Return true if profiling is supported on the target.
304
0d856ba2 305proc check_profiling_available { test_what } {
b8ee7f02
MM
306 global profiling_available_saved
307
0d856ba2
KG
308 verbose "Profiling argument is <$test_what>" 1
309
310 # These conditions depend on the argument so examine them before
311 # looking at the cache variable.
312
313 # Support for -p on solaris2 relies on mcrt1.o which comes with the
314 # vendor compiler. We cannot reliably predict the directory where the
315 # vendor compiler (and thus mcrt1.o) is installed so we can't
316 # necessarily find mcrt1.o even if we have it.
317 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
318 return 0
319 }
320
321 # Support for -p on irix relies on libprof1.a which doesn't appear to
322 # exist on any irix6 system currently posting testsuite results.
323 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
324 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
21526606 325 if { [istarget mips*-*-irix*]
0d856ba2
KG
326 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
327 return 0
328 }
329
345f13fe
JB
330 # At present, there is no profiling support on NetWare.
331 if { [istarget *-*-netware*] } {
332 return 0
333 }
334
0d856ba2 335 # Now examine the cache variable.
b8ee7f02
MM
336 if {![info exists profiling_available_saved]} {
337 # Some targets don't have any implementation of __bb_init_func or are
338 # missing other needed machinery.
339 if { [istarget mmix-*-*]
2e32707b 340 || [istarget arm*-*-eabi*]
b8ee7f02 341 || [istarget arm*-*-elf]
2e32707b 342 || [istarget arm*-*-symbianelf*]
9aba2a72 343 || [istarget powerpc-*-eabi*]
b8ee7f02
MM
344 || [istarget strongarm*-*-elf]
345 || [istarget xscale*-*-elf]
346 || [istarget cris-*-*]
21526606 347 || [istarget h8300-*-*]
a239aa95 348 || [istarget m32c-*-elf]
e3860a7d 349 || [istarget m68k-*-elf]
a49877d8 350 || [istarget mips*-*-elf]
dd2778f3 351 || [istarget xtensa-*-elf]
b8ee7f02
MM
352 || [istarget *-*-windiss] } {
353 set profiling_available_saved 0
354 } else {
355 set profiling_available_saved 1
356 }
357 }
21526606 358
b8ee7f02
MM
359 return $profiling_available_saved
360}
21526606 361
aa5c7673
HPN
362# Return 1 if target has packed layout of structure members by
363# default, 0 otherwise. Note that this is slightly different than
364# whether the target has "natural alignment": both attributes may be
365# false.
366
367proc check_effective_target_default_packed { } {
8ce1ac69
RS
368 return [check_no_compiler_messages default_packed assembly {
369 struct x { char a; long b; } c;
370 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
371 }]
aa5c7673
HPN
372}
373
edc5687e
HPN
374# Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
375# documentation, where the test also comes from.
376
377proc check_effective_target_pcc_bitfield_type_matters { } {
8ce1ac69
RS
378 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
379 # bitfields, but let's stick to the example code from the docs.
380 return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
381 struct foo1 { char x; char :0; char y; };
382 struct foo2 { char x; int :0; char y; };
383 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
384 }]
edc5687e
HPN
385}
386
8893239d 387# Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
ada80067
UB
388#
389# This won't change for different subtargets so cache the result.
390
391proc check_effective_target_tls {} {
392 global et_tls_saved
9b1f6e91 393 global tool
ada80067
UB
394
395 if [info exists et_tls_saved] {
396 verbose "check_effective_target_tls: using cached result" 2
397 } else {
398 set et_tls_saved 1
399
400 set src tls[pid].c
401 set asm tls[pid].S
402 verbose "check_effective_target_tls: compiling testfile $src" 2
403 set f [open $src "w"]
404 # Compile a small test program.
405 puts $f "__thread int i;\n"
406 close $f
407
408 # Test for thread-local data supported by the platform.
8893239d 409 set comp_output [${tool}_target_compile $src $asm assembly ""]
ada80067
UB
410 file delete $src
411 if { [string match "*not supported*" $comp_output] } {
412 set et_tls_saved 0
8893239d
RH
413 } else {
414 set fd [open $asm r]
415 set text [read $fd]
416 close $fd
417 if { [string match "*emutls*" $text]} {
418 set et_tls_saved 0
419 } else {
420 set et_tls_saved 1
421 }
ada80067
UB
422 }
423 remove-build-file $asm
424 }
425 verbose "check_effective_target_tls: returning $et_tls_saved" 2
426 return $et_tls_saved
427}
428
429# Return 1 if TLS executables can run correctly, 0 otherwise.
430#
431# This won't change for different subtargets so cache the result.
432
433proc check_effective_target_tls_runtime {} {
434 global et_tls_runtime_saved
9b1f6e91 435 global tool
ada80067
UB
436
437 if [info exists et_tls_runtime_saved] {
438 verbose "check_effective_target_tls_runtime: using cached result" 2
439 } else {
440 set et_tls_runtime_saved 0
441
442 set src tls_runtime[pid].c
443 set exe tls_runtime[pid].x
444 verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
445 set f [open $src "w"]
446 # Compile a small test program.
447 puts $f "__thread int thr = 0;\n"
448 puts $f "int main(void)\n {\n return thr;\n}"
449 close $f
450
451 set comp_output \
9b1f6e91 452 [${tool}_target_compile $src $exe executable ""]
ada80067
UB
453 file delete $src
454
455 if [string match "" $comp_output] then {
456 # No error messages, everything is OK.
457
458 set result [remote_load target "./$exe" "" ""]
459 set status [lindex $result 0]
460 remote_file build delete $exe
461
462 verbose "check_effective_target_tls_runtime status is <$status>" 2
463
464 if { $status == "pass" } {
465 set et_tls_runtime_saved 1
466 }
467
468 verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
469 }
470 }
471
472 return $et_tls_runtime_saved
473}
474
a782ee45
HPN
475# Return 1 if compilation with -fopenmp is error-free for trivial
476# code, 0 otherwise.
477
478proc check_effective_target_fopenmp {} {
8ce1ac69
RS
479 return [check_no_compiler_messages fopenmp object {
480 void foo (void) { }
481 } "-fopenmp"]
a782ee45
HPN
482}
483
3b1a6677
SE
484# Return 1 if compilation with -freorder-blocks-and-partition is error-free
485# for trivial code, 0 otherwise.
486
487proc check_effective_target_freorder {} {
8ce1ac69
RS
488 return [check_no_compiler_messages freorder object {
489 void foo (void) { }
490 } "-freorder-blocks-and-partition"]
3b1a6677
SE
491}
492
b6e3f572
HPN
493# Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
494# emitted, 0 otherwise. Whether a shared library can actually be built is
495# out of scope for this test.
b6e3f572
HPN
496
497proc check_effective_target_fpic { } {
8ce1ac69
RS
498 # Note that M68K has a multilib that supports -fpic but not
499 # -fPIC, so we need to check both. We test with a program that
500 # requires GOT references.
501 foreach arg {fpic fPIC} {
502 if [check_no_compiler_messages $arg object {
b6e3f572
HPN
503 extern int foo (void); extern int bar;
504 int baz (void) { return foo () + bar; }
8ce1ac69
RS
505 } "-$arg"] {
506 return 1
b6e3f572
HPN
507 }
508 }
8ce1ac69 509 return 0
b6e3f572
HPN
510}
511
245f0e1c
RS
512# Return true if the target supports -mpaired-single (as used on MIPS).
513
514proc check_effective_target_mpaired_single { } {
e9b1e828 515 return [check_no_compiler_messages mpaired_single object {
245f0e1c
RS
516 void foo (void) { }
517 } "-mpaired-single"]
518}
519
74231b0f 520# Return true if iconv is supported on the target. In particular IBM1047.
21526606
EC
521
522proc check_iconv_available { test_what } {
523 global tool
5340bbea 524 global libiconv
21526606
EC
525
526 set result ""
527
8dc84ef1
JJ
528 set src iconv[pid].c
529 set exe iconv[pid].x
530 verbose "check_iconv_available compiling testfile $src" 2
531 set f [open $src "w"]
21526606
EC
532 # Compile a small test program.
533 puts $f "#include <iconv.h>\n"
534 puts $f "int main (void)\n {\n iconv_t cd; \n"
535 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
536 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
537 puts $f "return 0;\n}"
538 close $f
539
0b3deaaf
MM
540 # If the tool configuration file has not set libiconv, try "-liconv"
541 if { ![info exists libiconv] } {
542 set libiconv "-liconv"
543 }
8dc84ef1
JJ
544 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
545 file delete $src
21526606 546
5340bbea
EC
547 if [string match "" $lines] then {
548 # No error messages, everything is OK.
21526606 549
0fb4f4b8 550 set result [${tool}_load "./$exe" "" ""]
11289ef9 551 set status [lindex $result 0]
0fb4f4b8 552 remote_file build delete $exe
21526606 553
8dc84ef1 554 verbose "check_iconv_available status is <$status>" 2
5340bbea
EC
555
556 if { $status == "pass" } then {
557 return 1
558 }
21526606
EC
559 }
560
561 return 0
562}
ab37d57e
ZW
563
564# Return true if named sections are supported on this target.
8ce1ac69 565
ab37d57e 566proc check_named_sections_available { } {
8ce1ac69 567 return [check_no_compiler_messages named_sections assembly {
b6dc500c 568 int __attribute__ ((section("whatever"))) foo;
8ce1ac69 569 }]
ab37d57e 570}
763ee179 571
32aa3bff 572# Return 1 if the target supports Fortran real kinds larger than real(8),
f6cf6841
JJ
573# 0 otherwise.
574#
575# When the target name changes, replace the cached result.
32aa3bff
FXC
576
577proc check_effective_target_fortran_large_real { } {
578 global et_fortran_large_real_saved
f6cf6841 579 global et_fortran_large_real_target_name
32aa3bff
FXC
580 global tool
581
f6cf6841
JJ
582 if { ![info exists et_fortran_large_real_target_name] } {
583 set et_fortran_large_real_target_name ""
584 }
585
586 # If the target has changed since we set the cached value, clear it.
587 set current_target [current_target_name]
588 if { $current_target != $et_fortran_large_real_target_name } {
589 verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
590 set et_fortran_large_real_target_name $current_target
591 if [info exists et_fortran_large_real_saved] {
592 verbose "check_effective_target_fortran_large_real: removing cached result" 2
593 unset et_fortran_large_real_saved
594 }
595 }
596
32aa3bff
FXC
597 if [info exists et_fortran_large_real_saved] {
598 verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
599 } else {
600 set et_fortran_large_real_saved 0
601
602 # Set up, compile, and execute a test program using large real
603 # kinds. Include the current process ID in the file names to
604 # prevent conflicts with invocations for multiple testsuites.
605 set src real[pid].f90
606 set exe real[pid].x
607
608 set f [open $src "w"]
609 puts $f "integer,parameter :: k = &"
610 puts $f " selected_real_kind (precision (0.0_8) + 1)"
611 puts $f "real(kind=k) :: x"
9cfda6fa 612 puts $f "x = cos (x);"
32aa3bff
FXC
613 puts $f "end"
614 close $f
615
616 verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
617 set lines [${tool}_target_compile $src $exe executable ""]
618 file delete $src
619
620 if [string match "" $lines] then {
621 # No error message, compilation succeeded.
622 set et_fortran_large_real_saved 1
623 }
624 }
625
626 return $et_fortran_large_real_saved
627}
628
629# Return 1 if the target supports Fortran integer kinds larger than
f6cf6841
JJ
630# integer(8), 0 otherwise.
631#
632# When the target name changes, replace the cached result.
32aa3bff
FXC
633
634proc check_effective_target_fortran_large_int { } {
635 global et_fortran_large_int_saved
f6cf6841 636 global et_fortran_large_int_target_name
32aa3bff
FXC
637 global tool
638
f6cf6841
JJ
639 if { ![info exists et_fortran_large_int_target_name] } {
640 set et_fortran_large_int_target_name ""
641 }
642
643 # If the target has changed since we set the cached value, clear it.
644 set current_target [current_target_name]
645 if { $current_target != $et_fortran_large_int_target_name } {
646 verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
647 set et_fortran_large_int_target_name $current_target
648 if [info exists et_fortran_large_int_saved] {
649 verbose "check_effective_target_fortran_large_int: removing cached result" 2
650 unset et_fortran_large_int_saved
651 }
652 }
653
32aa3bff
FXC
654 if [info exists et_fortran_large_int_saved] {
655 verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
656 } else {
657 set et_fortran_large_int_saved 0
658
659 # Set up, compile, and execute a test program using large integer
660 # kinds. Include the current process ID in the file names to
661 # prevent conflicts with invocations for multiple testsuites.
662 set src int[pid].f90
663 set exe int[pid].x
664
665 set f [open $src "w"]
666 puts $f "integer,parameter :: k = &"
667 puts $f " selected_int_kind (range (0_8) + 1)"
668 puts $f "integer(kind=k) :: i"
669 puts $f "end"
670 close $f
671
672 verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
673 set lines [${tool}_target_compile $src $exe executable ""]
674 file delete $src
675
676 if [string match "" $lines] then {
677 # No error message, compilation succeeded.
678 set et_fortran_large_int_saved 1
679 }
680 }
681
682 return $et_fortran_large_int_saved
683}
684
f2ae4b2b
FXC
685# Return 1 if we can statically link libgfortran, 0 otherwise.
686#
687# When the target name changes, replace the cached result.
688
689proc check_effective_target_static_libgfortran { } {
690 global et_static_libgfortran
691 global et_static_libgfortran_target_name
692 global tool
693
694 if { ![info exists et_static_libgfortran_target_name] } {
695 set et_static_libgfortran_target_name ""
696 }
697
698 # If the target has changed since we set the cached value, clear it.
699 set current_target [current_target_name]
700 if { $current_target != $et_static_libgfortran_target_name } {
701 verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
702 set et_static_libgfortran_target_name $current_target
703 if [info exists et_static_libgfortran_saved] {
704 verbose "check_effective_target_static_libgfortran: removing cached result" 2
705 unset et_static_libgfortran_saved
706 }
707 }
708
709 if [info exists et_static_libgfortran_saved] {
710 verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
711 } else {
712 set et_static_libgfortran_saved 0
713
714 # Set up, compile, and execute a test program using static linking.
715 # Include the current process ID in the file names to prevent
716 # conflicts with invocations for multiple testsuites.
5bd9e94d 717 set opts "additional_flags=-static"
f2ae4b2b 718 set src static[pid].f
5bd9e94d 719 set exe static[pid].x
f2ae4b2b
FXC
720
721 set f [open $src "w"]
722 puts $f " print *, 'test'"
723 puts $f " end"
724 close $f
725
726 verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
5bd9e94d 727 set lines [${tool}_target_compile $src $exe executable "$opts"]
f2ae4b2b
FXC
728 file delete $src
729
730 if [string match "" $lines] then {
731 # No error message, compilation succeeded.
732 set et_static_libgfortran_saved 1
733 }
734 }
735
736 return $et_static_libgfortran_saved
737}
738
763ee179
JJ
739# Return 1 if the target supports executing AltiVec instructions, 0
740# otherwise. Cache the result.
741
742proc check_vmx_hw_available { } {
743 global vmx_hw_available_saved
744 global tool
745
746 if [info exists vmx_hw_available_saved] {
747 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
748 } else {
749 set vmx_hw_available_saved 0
750
751 # Some simulators are known to not support VMX instructions.
752 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
753 verbose "check_hw_available returning 0" 2
754 return $vmx_hw_available_saved
755 }
756
757 # Set up, compile, and execute a test program containing VMX
758 # instructions. Include the current process ID in the file
759 # names to prevent conflicts with invocations for multiple
760 # testsuites.
761 set src vmx[pid].c
762 set exe vmx[pid].x
763
764 set f [open $src "w"]
765 puts $f "int main() {"
766 puts $f "#ifdef __MACH__"
767 puts $f " asm volatile (\"vor v0,v0,v0\");"
768 puts $f "#else"
769 puts $f " asm volatile (\"vor 0,0,0\");"
770 puts $f "#endif"
771 puts $f " return 0; }"
772 close $f
773
3562bc34
JJ
774 # Most targets don't require special flags for this test case, but
775 # Darwin does.
776 if [istarget *-*-darwin*] {
777 set opts "additional_flags=-maltivec"
778 } else {
779 set opts ""
780 }
781
763ee179 782 verbose "check_vmx_hw_available compiling testfile $src" 2
3562bc34 783 set lines [${tool}_target_compile $src $exe executable "$opts"]
763ee179
JJ
784 file delete $src
785
786 if [string match "" $lines] then {
787 # No error message, compilation succeeded.
788 set result [${tool}_load "./$exe" "" ""]
789 set status [lindex $result 0]
790 remote_file build delete $exe
791 verbose "check_vmx_hw_available testfile status is <$status>" 2
792
793 if { $status == "pass" } then {
794 set vmx_hw_available_saved 1
795 }
796 } else {
797 verbose "check_vmx_hw_availalble testfile compilation failed" 2
798 }
799 }
800
801 return $vmx_hw_available_saved
802}
b6dc500c 803
56afd7aa
JJ
804# GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
805# complex float arguments. This affects gfortran tests that call cabsf
806# in libm built by an earlier compiler. Return 1 if libm uses the same
807# argument passing as the compiler under test, 0 otherwise.
808#
809# When the target name changes, replace the cached result.
810
811proc check_effective_target_broken_cplxf_arg { } {
812 global et_broken_cplxf_arg_saved
813 global et_broken_cplxf_arg_target_name
814 global tool
815
816 # Skip the work for targets known not to be affected.
817 if { ![istarget powerpc64-*-linux*] } {
818 return 0
819 } elseif { [is-effective-target ilp32] } {
820 return 0
821 }
822
823 if { ![info exists et_broken_cplxf_arg_target_name] } {
824 set et_broken_cplxf_arg_target_name ""
825 }
826
827 # If the target has changed since we set the cached value, clear it.
828 set current_target [current_target_name]
829 if { $current_target != $et_broken_cplxf_arg_target_name } {
830 verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
831 set et_broken_cplxf_arg_target_name $current_target
832 if [info exists et_broken_cplxf_arg_saved] {
833 verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
834 unset et_broken_cplxf_arg_saved
835 }
836 }
837
838 if [info exists et_broken_cplxf_arg_saved] {
839 verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
840 } else {
841 set et_broken_cplxf_arg_saved 0
842 # This is only known to affect one target.
843 if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
844 set et_broken_cplxf_arg_saved 0
845 verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
846 return $et_broken_cplxf_arg_saved
847 }
848
849 # Set up, compile, and execute a C test program that calls cabsf.
850 set src cabsf[pid].c
851 set exe cabsf[pid].x
852
853 set f [open $src "w"]
854 puts $f "#include <complex.h>"
855 puts $f "extern void abort (void);"
856 puts $f "float fabsf (float);"
857 puts $f "float cabsf (_Complex float);"
858 puts $f "int main ()"
859 puts $f "{"
860 puts $f " _Complex float cf;"
861 puts $f " float f;"
862 puts $f " cf = 3 + 4.0fi;"
863 puts $f " f = cabsf (cf);"
864 puts $f " if (fabsf (f - 5.0) > 0.0001) abort ();"
865 puts $f " return 0;"
866 puts $f "}"
867 close $f
868
869 set lines [${tool}_target_compile $src $exe executable "-lm"]
870 file delete $src
871
872 if [string match "" $lines] {
873 # No error message, compilation succeeded.
874 set result [${tool}_load "./$exe" "" ""]
875 set status [lindex $result 0]
876 remote_file build delete $exe
877
878 verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
879
880 if { $status != "pass" } {
881 set et_broken_cplxf_arg_saved 1
882 }
883 } else {
884 verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
885 }
886 }
887 return $et_broken_cplxf_arg_saved
888}
889
31589ec6
RH
890proc check_alpha_max_hw_available { } {
891 global alpha_max_hw_available_saved
892 global tool
893
894 if [info exists alpha_max_hw_available_saved] {
895 verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
896 } else {
897 set alpha_max_hw_available_saved 0
898
899 # Set up, compile, and execute a test program probing bit 8 of the
900 # architecture mask, which indicates presence of MAX instructions.
901 set src max[pid].c
902 set exe max[pid].x
903
904 set f [open $src "w"]
905 puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
906 close $f
907
908 verbose "check_alpha_max_hw_available compiling testfile $src" 2
909 set lines [${tool}_target_compile $src $exe executable ""]
910 file delete $src
911
912 if [string match "" $lines] then {
913 # No error message, compilation succeeded.
914 set result [${tool}_load "./$exe" "" ""]
915 set status [lindex $result 0]
916 remote_file build delete $exe
917 verbose "check_alpha_max_hw_available testfile status is <$status>" 2
918
919 if { $status == "pass" } then {
920 set alpha_max_hw_available_saved 1
921 }
922 } else {
923 verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
924 }
925 }
926
927 return $alpha_max_hw_available_saved
928}
929
34f4edf8
MM
930# Returns true iff the FUNCTION is available on the target system.
931# (This is essentially a Tcl implementation of Autoconf's
932# AC_CHECK_FUNC.)
933
934proc check_function_available { function } {
935 set var "${function}_available_saved"
936 global $var
937 global tool
938
939 if {![info exists $var]} {
940 # Assume it exists.
941 set $var 1
942 # Check to make sure.
943 set src "function[pid].c"
944 set exe "function[pid].exe"
945
946 set f [open $src "w"]
709e1a1a
JM
947 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
948 puts $f "char $function ();\n"
34f4edf8
MM
949 puts $f "int main () { $function (); }"
950 close $f
951
952 set lines [${tool}_target_compile $src $exe executable ""]
953 file delete $src
954 file delete $exe
955
956 if {![string match "" $lines]} then {
957 set $var 0
958 verbose -log "$function is not available"
959 } else {
960 verbose -log "$function is available"
961 }
962 }
963
964 eval return \$$var
965}
966
cea02b6e 967# Returns true iff "fork" is available on the target system.
34f4edf8
MM
968
969proc check_fork_available {} {
970 return [check_function_available "fork"]
971}
972
cea02b6e 973# Returns true iff "mkfifo" is available on the target system.
34f4edf8
MM
974
975proc check_mkfifo_available {} {
cea02b6e
DB
976 if {[istarget *-*-cygwin*]} {
977 # Cygwin has mkfifo, but support is incomplete.
978 return 0
979 }
980
34f4edf8
MM
981 return [check_function_available "mkfifo"]
982}
983
21f638b9
SE
984# Returns true iff "__cxa_atexit" is used on the target system.
985
986proc check_cxa_atexit_available { } {
987 global et_cxa_atexit
988 global et_cxa_atexit_target_name
989 global tool
990
991 if { ![info exists et_cxa_atexit_target_name] } {
992 set et_cxa_atexit_target_name ""
993 }
994
995 # If the target has changed since we set the cached value, clear it.
996 set current_target [current_target_name]
997 if { $current_target != $et_cxa_atexit_target_name } {
998 verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
999 set et_cxa_atexit_target_name $current_target
1000 if [info exists et_cxa_atexit] {
1001 verbose "check_cxa_atexit_available: removing cached result" 2
1002 unset et_cxa_atexit
1003 }
1004 }
1005
1006 if [info exists et_cxa_atexit] {
1007 verbose "check_cxa_atexit_available: using cached result" 2
60784de8 1008 } elseif { [istarget "hppa*-*-hpux10*"] } {
c53fa174
JDA
1009 # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1010 set et_cxa_atexit 0
21f638b9
SE
1011 } else {
1012 set et_cxa_atexit 0
1013
1014 # Set up, compile, and execute a C++ test program that depends
1015 # on correct ordering of static object destructors. This is
1016 # indicative of the presence and use of __cxa_atexit.
1017 set src cxaatexit[pid].cc
1018 set exe cxaatexit[pid].x
1019
1020 set f [open $src "w"]
1021 puts $f "#include <stdlib.h>"
1022 puts $f "static unsigned int count;"
1023 puts $f "struct X"
1024 puts $f "{"
1025 puts $f " X() { count = 1; }"
1026 puts $f " ~X()"
1027 puts $f " {"
1028 puts $f " if (count != 3)"
1029 puts $f " exit(1);"
1030 puts $f " count = 4;"
1031 puts $f " }"
1032 puts $f "};"
1033 puts $f "void f()"
1034 puts $f "{"
1035 puts $f " static X x;"
1036 puts $f "}"
1037 puts $f "struct Y"
1038 puts $f "{"
1039 puts $f " Y() { f(); count = 2; }"
1040 puts $f " ~Y()"
1041 puts $f " {"
1042 puts $f " if (count != 2)"
1043 puts $f " exit(1);"
1044 puts $f " count = 3;"
1045 puts $f " }"
1046 puts $f "};"
1047 puts $f "Y y;"
1048 puts $f "int main()"
1049 puts $f "{ return 0; }"
1050 close $f
1051
38ccd98a 1052 set lines [${tool}_target_compile $src $exe executable ""]
21f638b9
SE
1053 file delete $src
1054
1055 if [string match "" $lines] {
1056 # No error message, compilation succeeded.
1057 set result [${tool}_load "./$exe" "" ""]
1058 set status [lindex $result 0]
1059 remote_file build delete $exe
1060
1061 verbose "check_cxa_atexit_available: status is <$status>" 2
1062
1063 if { $status == "pass" } {
1064 set et_cxa_atexit 1
1065 }
1066 } else {
1067 verbose "check_cxa_atexit_available: compilation failed" 2
1068 }
1069 }
1070 return $et_cxa_atexit
1071}
1072
1073
b6dc500c
JJ
1074# Return 1 if we're generating 32-bit code using default options, 0
1075# otherwise.
1076
1077proc check_effective_target_ilp32 { } {
8ce1ac69
RS
1078 return [check_no_compiler_messages ilp32 object {
1079 int dummy[sizeof (int) == 4
1080 && sizeof (void *) == 4
1081 && sizeof (long) == 4 ? 1 : -1];
1082 }]
b6dc500c
JJ
1083}
1084
a239aa95
DD
1085# Return 1 if we're generating 32-bit or larger integers using default
1086# options, 0 otherwise.
1087
1088proc check_effective_target_int32plus { } {
1089 return [check_no_compiler_messages int32plus object {
1090 int dummy[sizeof (int) >= 4 ? 1 : -1];
1091 }]
1092}
1093
1094# Return 1 if we're generating 32-bit or larger pointers using default
1095# options, 0 otherwise.
1096
1097proc check_effective_target_ptr32plus { } {
1098 return [check_no_compiler_messages ptr32plus object {
1099 int dummy[sizeof (void *) >= 4 ? 1 : -1];
1100 }]
1101}
1102
1103# Return 1 if we support 32-bit or larger array and structure sizes
1104# using default options, 0 otherwise.
1105
1106proc check_effective_target_size32plus { } {
1107 return [check_no_compiler_messages size32plus object {
1108 char dummy[65537];
1109 }]
1110}
1111
1112# Returns 1 if we're generating 16-bit or smaller integers with the
1113# default options, 0 otherwise.
1114
1115proc check_effective_target_int16 { } {
1116 return [check_no_compiler_messages int16 object {
1117 int dummy[sizeof (int) < 4 ? 1 : -1];
1118 }]
1119}
1120
b6dc500c
JJ
1121# Return 1 if we're generating 64-bit code using default options, 0
1122# otherwise.
1123
1124proc check_effective_target_lp64 { } {
8ce1ac69
RS
1125 return [check_no_compiler_messages lp64 object {
1126 int dummy[sizeof (int) == 4
1127 && sizeof (void *) == 8
1128 && sizeof (long) == 8 ? 1 : -1];
1129 }]
b6dc500c
JJ
1130}
1131
4efc447f
MLI
1132# Return 1 if the target supports long double larger than double,
1133# 0 otherwise.
1134
1135proc check_effective_target_large_long_double { } {
1136 return [check_no_compiler_messages large_long_double object {
1137 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1138 }]
1139}
1140
1141
265e7d50
JJ
1142# Return 1 if the target supports compiling decimal floating point,
1143# 0 otherwise.
1144
1145proc check_effective_target_dfp_nocache { } {
1146 verbose "check_effective_target_dfp_nocache: compiling source" 2
19450f2b 1147 set ret [string match "" [get_compiler_messages dfp 0 object {
265e7d50
JJ
1148 _Decimal32 x; _Decimal64 y; _Decimal128 z;
1149 }]]
1150 verbose "check_effective_target_dfp_nocache: returning $ret" 2
1151 return $ret
1152}
1153
1154proc check_effective_target_dfprt_nocache { } {
1155 global tool
1156
1157 set ret 0
1158
1159 verbose "check_effective_target_dfprt_nocache: compiling source" 2
1160 # Set up, compile, and execute a test program containing decimal
1161 # float operations.
1162 set src dfprt[pid].c
1163 set exe dfprt[pid].x
1164
1165 set f [open $src "w"]
1166 puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1167 puts $f "int main () { z = x + y; return 0; }"
1168 close $f
1169
1170 verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1171 set lines [${tool}_target_compile $src $exe executable ""]
1172 file delete $src
1173
1174 if [string match "" $lines] then {
1175 # No error message, compilation succeeded.
1176 set result [${tool}_load "./$exe" "" ""]
1177 set status [lindex $result 0]
1178 remote_file build delete $exe
1179 verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1180 if { $status == "pass" } then {
1181 set ret 1
1182 }
1183 }
1184 return $ret
1185 verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1186}
1187
1188# Return 1 if the target supports compiling Decimal Floating Point,
1189# 0 otherwise.
27a2694f
JJ
1190#
1191# This won't change for different subtargets so cache the result.
1192
1193proc check_effective_target_dfp { } {
1194 global et_dfp_saved
1195
1196 if [info exists et_dfp_saved] {
1197 verbose "check_effective_target_dfp: using cached result" 2
1198 } else {
265e7d50 1199 set et_dfp_saved [check_effective_target_dfp_nocache]
27a2694f
JJ
1200 }
1201 verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1202 return $et_dfp_saved
1203}
1204
265e7d50
JJ
1205# Return 1 if the target supports linking and executing Decimal Floating
1206# Point, # 0 otherwise.
1207#
1208# This won't change for different subtargets so cache the result.
1209
1210proc check_effective_target_dfprt { } {
1211 global et_dfprt_saved
1212 global tool
1213
1214 if [info exists et_dfprt_saved] {
1215 verbose "check_effective_target_dfprt: using cached result" 2
1216 } else {
1217 set et_dfprt_saved [check_effective_target_dfprt_nocache]
1218 }
1219 verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1220 return $et_dfprt_saved
1221}
1222
b956116e
PB
1223# Return 1 if the target needs a command line argument to enable a SIMD
1224# instruction set.
b956116e
PB
1225
1226proc check_effective_target_vect_cmdline_needed { } {
1227 global et_vect_cmdline_needed_saved
e87a56b4
JM
1228 global et_vect_cmdline_needed_target_name
1229
1230 if { ![info exists et_vect_cmdline_needed_target_name] } {
1231 set et_vect_cmdline_needed_target_name ""
1232 }
1233
1234 # If the target has changed since we set the cached value, clear it.
1235 set current_target [current_target_name]
1236 if { $current_target != $et_vect_cmdline_needed_target_name } {
1237 verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1238 set et_vect_cmdline_needed_target_name $current_target
1239 if { [info exists et_vect_cmdline_needed_saved] } {
1240 verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1241 unset et_vect_cmdline_needed_saved
1242 }
1243 }
b956116e
PB
1244
1245 if [info exists et_vect_cmdline_needed_saved] {
1246 verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1247 } else {
1248 set et_vect_cmdline_needed_saved 1
1249 if { [istarget ia64-*-*]
e87a56b4 1250 || (([istarget x86_64-*-*] || [istarget i?86-*-*])
624168de
JM
1251 && [check_effective_target_lp64])
1252 || ([istarget powerpc*-*-*]
5eb96b60
JM
1253 && ([check_effective_target_powerpc_spe]
1254 || [check_effective_target_powerpc_altivec]))} {
b956116e
PB
1255 set et_vect_cmdline_needed_saved 0
1256 }
1257 }
1258
1259 verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1260 return $et_vect_cmdline_needed_saved
1261}
1262
07d05ffd
JJ
1263# Return 1 if the target supports hardware vectors of int, 0 otherwise.
1264#
1265# This won't change for different subtargets so cache the result.
1266
1267proc check_effective_target_vect_int { } {
1268 global et_vect_int_saved
1269
1270 if [info exists et_vect_int_saved] {
1271 verbose "check_effective_target_vect_int: using cached result" 2
1272 } else {
1273 set et_vect_int_saved 0
1274 if { [istarget i?86-*-*]
1275 || [istarget powerpc*-*-*]
0f6909b9 1276 || [istarget spu-*-*]
07d05ffd 1277 || [istarget x86_64-*-*]
31589ec6 1278 || [istarget sparc*-*-*]
f61134e8
RH
1279 || [istarget alpha*-*-*]
1280 || [istarget ia64-*-*] } {
07d05ffd
JJ
1281 set et_vect_int_saved 1
1282 }
1283 }
1284
1285 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1286 return $et_vect_int_saved
1287}
1288
0d341a6a
PB
1289# Return 1 is this is an arm target using 32-bit instructions
1290proc check_effective_target_arm32 { } {
1291 global et_arm32_saved
1292 global et_arm32_target_name
1293 global compiler_flags
1294
1295 if { ![info exists et_arm32_target_name] } {
1296 set et_arm32_target_name ""
1297 }
1298
1299 # If the target has changed since we set the cached value, clear it.
1300 set current_target [current_target_name]
1301 if { $current_target != $et_arm32_target_name } {
1302 verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1303 set et_arm32_target_name $current_target
1304 if { [info exists et_arm32_saved] } {
1305 verbose "check_effective_target_arm32: removing cached result" 2
1306 unset et_arm32_saved
1307 }
1308 }
1309
1310 if [info exists et_arm32_saved] {
1311 verbose "check-effective_target_arm32: using cached result" 2
1312 } else {
1313 set et_arm32_saved 0
1314 if { [istarget arm-*-*]
1315 || [istarget strongarm*-*-*]
1316 || [istarget xscale-*-*] } {
1317 if ![string match "*-mthumb *" $compiler_flags] {
1318 set et_arm32_saved 1
1319 }
1320 }
1321 }
1322 verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1323 return $et_arm32_saved
1324}
1325
c03b9206
JM
1326# Return 1 if this is an ARM target supporting -mfpu=vfp
1327# -mfloat-abi=softfp. Some multilibs may be incompatible with these
1328# options.
1329
1330proc check_effective_target_arm_vfp_ok { } {
1331 if { [check_effective_target_arm32] } {
1332 return [check_no_compiler_messages arm_vfp_ok object {
1333 int dummy;
1334 } "-mfpu=vfp -mfloat-abi=softfp"]
1335 } else {
1336 return 0
1337 }
1338}
1339
1dbf8c24
JM
1340# Return 1 if this is a PowerPC target with floating-point registers.
1341
1342proc check_effective_target_powerpc_fprs { } {
1343 if { [istarget powerpc*-*-*]
1344 || [istarget rs6000-*-*] } {
1345 return [check_no_compiler_messages powerpc_fprs object {
1346 #ifdef __NO_FPRS__
1347 #error no FPRs
1348 #else
1349 int dummy;
1350 #endif
1351 }]
1352 } else {
1353 return 0
1354 }
1355}
1356
1357# Return 1 if this is a PowerPC target supporting -maltivec.
1358
1359proc check_effective_target_powerpc_altivec_ok { } {
1360 if { [istarget powerpc*-*-*]
1361 || [istarget rs6000-*-*] } {
1362 # AltiVec is not supported on Aix.
1363 if { [istarget powerpc*-*-aix*] } {
1364 return 0
1365 }
1366 return [check_no_compiler_messages powerpc_altivec_ok object {
1367 int dummy;
1368 } "-maltivec"]
1369 } else {
1370 return 0
1371 }
1372}
1373
624168de
JM
1374# Return 1 if this is a PowerPC target with SPE enabled.
1375
1376proc check_effective_target_powerpc_spe { } {
1377 if { [istarget powerpc*-*-*] } {
1378 return [check_no_compiler_messages powerpc_spe object {
1379 #ifndef __SPE__
1380 #error not SPE
1381 #else
1382 int dummy;
1383 #endif
1384 }]
1385 } else {
1386 return 0
1387 }
1388}
1389
5eb96b60
JM
1390# Return 1 if this is a PowerPC target with Altivec enabled.
1391
1392proc check_effective_target_powerpc_altivec { } {
1393 if { [istarget powerpc*-*-*] } {
1394 return [check_no_compiler_messages powerpc_altivec object {
1395 #ifndef __ALTIVEC__
1396 #error not Altivec
1397 #else
1398 int dummy;
1399 #endif
1400 }]
1401 } else {
1402 return 0
1403 }
1404}
1405
3e0de9d1
DP
1406# Return 1 if the target supports hardware vector shift operation.
1407
1408proc check_effective_target_vect_shift { } {
41a182c6
UB
1409 global et_vect_shift_saved
1410
1411 if [info exists et_vect_shift_saved] {
1412 verbose "check_effective_target_vect_shift: using cached result" 2
3e0de9d1 1413 } else {
41a182c6
UB
1414 set et_vect_shift_saved 0
1415 if { [istarget powerpc*-*-*]
1416 || [istarget ia64-*-*]
1417 || [istarget i?86-*-*]
1418 || [istarget x86_64-*-*] } {
1419 set et_vect_shift_saved 1
1420 }
3e0de9d1
DP
1421 }
1422
41a182c6
UB
1423 verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1424 return $et_vect_shift_saved
3e0de9d1
DP
1425}
1426
31589ec6
RH
1427# Return 1 if the target supports hardware vectors of long, 0 otherwise.
1428#
f470b1e5 1429# This can change for different subtargets so do not cache the result.
31589ec6
RH
1430
1431proc check_effective_target_vect_long { } {
f470b1e5
JJ
1432 if { [istarget i?86-*-*]
1433 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1434 || [istarget x86_64-*-*]
1435 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1436 set answer 1
31589ec6 1437 } else {
f470b1e5 1438 set answer 0
31589ec6
RH
1439 }
1440
f470b1e5
JJ
1441 verbose "check_effective_target_vect_long: returning $answer" 2
1442 return $answer
31589ec6
RH
1443}
1444
07d05ffd
JJ
1445# Return 1 if the target supports hardware vectors of float, 0 otherwise.
1446#
1447# This won't change for different subtargets so cache the result.
1448
1449proc check_effective_target_vect_float { } {
1450 global et_vect_float_saved
1451
1452 if [info exists et_vect_float_saved] {
1453 verbose "check_effective_target_vect_float: using cached result" 2
1454 } else {
1455 set et_vect_float_saved 0
1456 if { [istarget i?86-*-*]
1457 || [istarget powerpc*-*-*]
0f6909b9 1458 || [istarget spu-*-*]
07d05ffd 1459 || [istarget mipsisa64*-*-*]
f61134e8
RH
1460 || [istarget x86_64-*-*]
1461 || [istarget ia64-*-*] } {
07d05ffd
JJ
1462 set et_vect_float_saved 1
1463 }
1464 }
1465
1466 verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1467 return $et_vect_float_saved
1468}
1469
1470# Return 1 if the target supports hardware vectors of double, 0 otherwise.
1471#
1472# This won't change for different subtargets so cache the result.
1473
1474proc check_effective_target_vect_double { } {
1475 global et_vect_double_saved
1476
1477 if [info exists et_vect_double_saved] {
1478 verbose "check_effective_target_vect_double: using cached result" 2
1479 } else {
1480 set et_vect_double_saved 0
1481 if { [istarget i?86-*-*]
0f6909b9
DN
1482 || [istarget x86_64-*-*]
1483 || [istarget spu-*-*] } {
07d05ffd
JJ
1484 set et_vect_double_saved 1
1485 }
1486 }
1487
1488 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1489 return $et_vect_double_saved
1490}
1491
0f6909b9
DN
1492# Return 0 if the target supports hardware comparison of vectors of double, 0 otherwise.
1493#
1494# This won't change for different subtargets so cache the result.
1495
1496proc check_effective_target_vect_no_compare_double { } {
1497 global et_vect_no_compare_double_saved
1498
1499 if [info exists et_vect_no_compare_double_saved] {
1500 verbose "check_effective_target_vect_no_compare_double: using cached result" 2
1501 } else {
1502 set et_vect_no_compare_double_saved 0
1503 if { [istarget spu-*-*] } {
1504 set et_vect_no_compare_double_saved 1
1505 }
1506 }
1507
1508 verbose "check_effective_target_vect_no_compare_double: returning $et_vect_no_compare_double_saved" 2
1509 return $et_vect_no_compare_double_saved
1510}
1511
eeea13c2 1512# Return 1 if the target plus current options does not support a vector
d5dfe0b8 1513# max instruction on "int", 0 otherwise.
eeea13c2
JJ
1514#
1515# This won't change for different subtargets so cache the result.
1516
d5dfe0b8
RH
1517proc check_effective_target_vect_no_int_max { } {
1518 global et_vect_no_int_max_saved
eeea13c2 1519
d5dfe0b8
RH
1520 if [info exists et_vect_no_int_max_saved] {
1521 verbose "check_effective_target_vect_no_int_max: using cached result" 2
eeea13c2 1522 } else {
d5dfe0b8 1523 set et_vect_no_int_max_saved 0
9fb93f89 1524 if { [istarget sparc*-*-*]
0f6909b9 1525 || [istarget spu-*-*]
eeea13c2 1526 || [istarget alpha*-*-*] } {
d5dfe0b8 1527 set et_vect_no_int_max_saved 1
eeea13c2
JJ
1528 }
1529 }
d5dfe0b8
RH
1530 verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1531 return $et_vect_no_int_max_saved
1532}
1533
1534# Return 1 if the target plus current options does not support a vector
1535# add instruction on "int", 0 otherwise.
1536#
1537# This won't change for different subtargets so cache the result.
1538
1539proc check_effective_target_vect_no_int_add { } {
1540 global et_vect_no_int_add_saved
1541
1542 if [info exists et_vect_no_int_add_saved] {
1543 verbose "check_effective_target_vect_no_int_add: using cached result" 2
1544 } else {
1545 set et_vect_no_int_add_saved 0
1546 # Alpha only supports vector add on V8QI and V4HI.
1547 if { [istarget alpha*-*-*] } {
1548 set et_vect_no_int_add_saved 1
1549 }
1550 }
1551 verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1552 return $et_vect_no_int_add_saved
eeea13c2
JJ
1553}
1554
1555# Return 1 if the target plus current options does not support vector
1556# bitwise instructions, 0 otherwise.
1557#
1558# This won't change for different subtargets so cache the result.
1559
1560proc check_effective_target_vect_no_bitwise { } {
1561 global et_vect_no_bitwise_saved
1562
1563 if [info exists et_vect_no_bitwise_saved] {
1564 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1565 } else {
1566 set et_vect_no_bitwise_saved 0
eeea13c2
JJ
1567 }
1568 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1569 return $et_vect_no_bitwise_saved
1570}
1571
4035f245
VK
1572# Return 1 if the target plus current options supports a vector
1573# widening summation of *short* args into *int* result, 0 otherwise.
89d67cca
DN
1574# A target can also support this widening summation if it can support
1575# promotion (unpacking) from shorts to ints.
4035f245
VK
1576#
1577# This won't change for different subtargets so cache the result.
1578
1579proc check_effective_target_vect_widen_sum_hi_to_si { } {
1580 global et_vect_widen_sum_hi_to_si
89d67cca 1581
4035f245
VK
1582 if [info exists et_vect_widen_sum_hi_to_si_saved] {
1583 verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1584 } else {
89d67cca
DN
1585 set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1586 if { [istarget powerpc*-*-*] } {
4035f245
VK
1587 set et_vect_widen_sum_hi_to_si_saved 1
1588 }
1589 }
1590 verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1591 return $et_vect_widen_sum_hi_to_si_saved
1592}
1593
1594# Return 1 if the target plus current options supports a vector
1595# widening summation of *char* args into *short* result, 0 otherwise.
89d67cca
DN
1596# A target can also support this widening summation if it can support
1597# promotion (unpacking) from chars to shorts.
4035f245
VK
1598#
1599# This won't change for different subtargets so cache the result.
1600
1601proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1602 global et_vect_widen_sum_qi_to_hi
89d67cca 1603
4035f245
VK
1604 if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1605 verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1606 } else {
1607 set et_vect_widen_sum_qi_to_hi_saved 0
89d67cca 1608 if { [check_effective_target_vect_unpack] } {
4035f245 1609 set et_vect_widen_sum_qi_to_hi_saved 1
89d67cca 1610 }
4035f245
VK
1611 }
1612 verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1613 return $et_vect_widen_sum_qi_to_hi_saved
1614}
1615
1616# Return 1 if the target plus current options supports a vector
1617# widening summation of *char* args into *int* result, 0 otherwise.
1618#
1619# This won't change for different subtargets so cache the result.
1620
1621proc check_effective_target_vect_widen_sum_qi_to_si { } {
1622 global et_vect_widen_sum_qi_to_si
89d67cca 1623
4035f245
VK
1624 if [info exists et_vect_widen_sum_qi_to_si_saved] {
1625 verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1626 } else {
1627 set et_vect_widen_sum_qi_to_si_saved 0
1628 if { [istarget powerpc*-*-*] } {
1629 set et_vect_widen_sum_qi_to_si_saved 1
1630 }
1631 }
1632 verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1633 return $et_vect_widen_sum_qi_to_si_saved
1634}
1635
20f06221 1636# Return 1 if the target plus current options supports a vector
89d67cca
DN
1637# widening multiplication of *char* args into *short* result, 0 otherwise.
1638# A target can also support this widening multplication if it can support
1639# promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1640# multiplication of shorts).
20f06221
DN
1641#
1642# This won't change for different subtargets so cache the result.
89d67cca
DN
1643
1644
1645proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1646 global et_vect_widen_mult_qi_to_hi
1647
1648 if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1649 verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
20f06221 1650 } else {
89d67cca
DN
1651 if { [check_effective_target_vect_unpack]
1652 && [check_effective_target_vect_short_mult] } {
1653 set et_vect_widen_mult_qi_to_hi_saved 1
1654 } else {
1655 set et_vect_widen_mult_qi_to_hi_saved 0
1656 }
1657 if { [istarget powerpc*-*-*] } {
1658 set et_vect_widen_mult_qi_to_hi_saved 1
20f06221
DN
1659 }
1660 }
89d67cca
DN
1661 verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1662 return $et_vect_widen_mult_qi_to_hi_saved
1663}
1664
1665# Return 1 if the target plus current options supports a vector
1666# widening multiplication of *short* args into *int* result, 0 otherwise.
1667# A target can also support this widening multplication if it can support
1668# promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1669# multiplication of ints).
1670#
1671# This won't change for different subtargets so cache the result.
1672
1673
1674proc check_effective_target_vect_widen_mult_hi_to_si { } {
1675 global et_vect_widen_mult_hi_to_si
1676
1677 if [info exists et_vect_widen_mult_hi_to_si_saved] {
1678 verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1679 } else {
1680 if { [check_effective_target_vect_unpack]
1681 && [check_effective_target_vect_int_mult] } {
1682 set et_vect_widen_mult_hi_to_si_saved 1
1683 } else {
1684 set et_vect_widen_mult_hi_to_si_saved 0
1685 }
0e9dac9e 1686 if { [istarget powerpc*-*-*]
c882a2c2 1687 || [istarget spu-*-*]
0e9dac9e
UB
1688 || [istarget i?86-*-*]
1689 || [istarget x86_64-*-*] } {
89d67cca
DN
1690 set et_vect_widen_mult_hi_to_si_saved 1
1691 }
1692 }
1693 verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1694 return $et_vect_widen_mult_hi_to_si_saved
20f06221
DN
1695}
1696
1697# Return 1 if the target plus current options supports a vector
1698# dot-product of signed chars, 0 otherwise.
1699#
1700# This won't change for different subtargets so cache the result.
1701
1702proc check_effective_target_vect_sdot_qi { } {
1703 global et_vect_sdot_qi
1704
1705 if [info exists et_vect_sdot_qi_saved] {
1706 verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1707 } else {
1708 set et_vect_sdot_qi_saved 0
20f06221
DN
1709 }
1710 verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1711 return $et_vect_sdot_qi_saved
1712}
1713
1714# Return 1 if the target plus current options supports a vector
1715# dot-product of unsigned chars, 0 otherwise.
1716#
1717# This won't change for different subtargets so cache the result.
1718
1719proc check_effective_target_vect_udot_qi { } {
1720 global et_vect_udot_qi
1721
1722 if [info exists et_vect_udot_qi_saved] {
1723 verbose "check_effective_target_vect_udot_qi: using cached result" 2
1724 } else {
1725 set et_vect_udot_qi_saved 0
89d67cca 1726 if { [istarget powerpc*-*-*] } {
20f06221
DN
1727 set et_vect_udot_qi_saved 1
1728 }
1729 }
1730 verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1731 return $et_vect_udot_qi_saved
1732}
1733
1734# Return 1 if the target plus current options supports a vector
1735# dot-product of signed shorts, 0 otherwise.
1736#
1737# This won't change for different subtargets so cache the result.
1738
1739proc check_effective_target_vect_sdot_hi { } {
1740 global et_vect_sdot_hi
1741
1742 if [info exists et_vect_sdot_hi_saved] {
1743 verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1744 } else {
1745 set et_vect_sdot_hi_saved 0
1746 if { [istarget powerpc*-*-*]
1747 || [istarget i?86-*-*]
89d67cca 1748 || [istarget x86_64-*-*] } {
20f06221
DN
1749 set et_vect_sdot_hi_saved 1
1750 }
1751 }
1752 verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1753 return $et_vect_sdot_hi_saved
1754}
1755
1756# Return 1 if the target plus current options supports a vector
1757# dot-product of unsigned shorts, 0 otherwise.
1758#
1759# This won't change for different subtargets so cache the result.
1760
1761proc check_effective_target_vect_udot_hi { } {
1762 global et_vect_udot_hi
1763
1764 if [info exists et_vect_udot_hi_saved] {
1765 verbose "check_effective_target_vect_udot_hi: using cached result" 2
1766 } else {
1767 set et_vect_udot_hi_saved 0
1768 if { [istarget powerpc*-*-*] } {
1769 set et_vect_udot_hi_saved 1
1770 }
1771 }
1772 verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1773 return $et_vect_udot_hi_saved
1774}
1775
1776
89d67cca
DN
1777# Return 1 if the target plus current options supports a vector
1778# demotion (packing) of shorts (to chars) and ints (to shorts)
1779# using modulo arithmetic, 0 otherwise.
1780#
1781# This won't change for different subtargets so cache the result.
1782
1783proc check_effective_target_vect_pack_mod { } {
1784 global et_vect_pack_mod
1785
1786 if [info exists et_vect_pack_mod_saved] {
1787 verbose "check_effective_target_vect_pack_mod: using cached result" 2
1788 } else {
1789 set et_vect_pack_mod_saved 0
1790 if { [istarget powerpc*-*-*]
1791 || [istarget i?86-*-*]
1792 || [istarget x86_64-*-*] } {
1793 set et_vect_pack_mod_saved 1
1794 }
1795 }
1796 verbose "check_effective_target_vect_pack_mod: returning $et_vect_pack_mod_saved" 2
1797 return $et_vect_pack_mod_saved
1798}
1799
1800# Return 1 if the target plus current options supports a vector
1801# promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
1802#
1803# This won't change for different subtargets so cache the result.
1804
1805proc check_effective_target_vect_unpack { } {
1806 global et_vect_unpack
1807
1808 if [info exists et_vect_unpack_saved] {
1809 verbose "check_effective_target_vect_unpack: using cached result" 2
1810 } else {
1811 set et_vect_unpack_saved 0
1812 if { [istarget powerpc*-*-*]
1813 || [istarget i?86-*-*]
1814 || [istarget x86_64-*-*] } {
1815 set et_vect_unpack_saved 1
1816 }
1817 }
1818 verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2
1819 return $et_vect_unpack_saved
1820}
1821
eeea13c2
JJ
1822# Return 1 if the target plus current options does not support a vector
1823# alignment mechanism, 0 otherwise.
1824#
1825# This won't change for different subtargets so cache the result.
1826
1827proc check_effective_target_vect_no_align { } {
1828 global et_vect_no_align_saved
1829
1830 if [info exists et_vect_no_align_saved] {
1831 verbose "check_effective_target_vect_no_align: using cached result" 2
1832 } else {
1833 set et_vect_no_align_saved 0
3e8aba34 1834 if { [istarget mipsisa64*-*-*]
f61134e8
RH
1835 || [istarget sparc*-*-*]
1836 || [istarget ia64-*-*] } {
eeea13c2
JJ
1837 set et_vect_no_align_saved 1
1838 }
1839 }
1840 verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1841 return $et_vect_no_align_saved
1842}
1843
b52485c6
DP
1844# Return 1 if the target supports vector conditional operations, 0 otherwise.
1845
1846proc check_effective_target_vect_condition { } {
1847 global et_vect_cond_saved
1848
41a182c6 1849 if [info exists et_vect_cond_saved] {
b52485c6
DP
1850 verbose "check_effective_target_vect_cond: using cached result" 2
1851 } else {
1852 set et_vect_cond_saved 0
ae46a07a
RH
1853 if { [istarget powerpc*-*-*]
1854 || [istarget ia64-*-*]
1855 || [istarget i?86-*-*]
1856 || [istarget x86_64-*-*] } {
b52485c6
DP
1857 set et_vect_cond_saved 1
1858 }
1859 }
1860
1861 verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1862 return $et_vect_cond_saved
1863}
1864
4035f245
VK
1865# Return 1 if the target supports vector char multiplication, 0 otherwise.
1866
1867proc check_effective_target_vect_char_mult { } {
1868 global et_vect_char_mult_saved
1869
1870 if [info exists et_vect_char_mult_saved] {
1871 verbose "check_effective_target_vect_char_mult: using cached result" 2
1872 } else {
1873 set et_vect_char_mult_saved 0
1874 if { [istarget ia64-*-*]
1875 || [istarget i?86-*-*]
1876 || [istarget x86_64-*-*] } {
1877 set et_vect_char_mult_saved 1
1878 }
1879 }
1880
1881 verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1882 return $et_vect_char_mult_saved
1883}
1884
1885# Return 1 if the target supports vector short multiplication, 0 otherwise.
1886
1887proc check_effective_target_vect_short_mult { } {
1888 global et_vect_short_mult_saved
1889
1890 if [info exists et_vect_short_mult_saved] {
1891 verbose "check_effective_target_vect_short_mult: using cached result" 2
1892 } else {
1893 set et_vect_short_mult_saved 0
1894 if { [istarget ia64-*-*]
1895 || [istarget i?86-*-*]
1896 || [istarget x86_64-*-*] } {
1897 set et_vect_short_mult_saved 1
1898 }
1899 }
1900
1901 verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1902 return $et_vect_short_mult_saved
1903}
1904
a45f6936
DP
1905# Return 1 if the target supports vector int multiplication, 0 otherwise.
1906
1907proc check_effective_target_vect_int_mult { } {
1908 global et_vect_int_mult_saved
1909
f12b785d 1910 if [info exists et_vect_int_mult_saved] {
a45f6936
DP
1911 verbose "check_effective_target_vect_int_mult: using cached result" 2
1912 } else {
1913 set et_vect_int_mult_saved 0
2b5bf0e2
RH
1914 if { [istarget powerpc*-*-*]
1915 || [istarget i?86-*-*]
1916 || [istarget x86_64-*-*] } {
a45f6936
DP
1917 set et_vect_int_mult_saved 1
1918 }
1919 }
1920
1921 verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1922 return $et_vect_int_mult_saved
1923}
b52485c6 1924
98b44b0e
IR
1925# Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
1926
1927proc check_effective_target_vect_extract_even_odd { } {
1928 global et_vect_extract_even_odd_saved
1929
1930 if [info exists et_vect_extract_even_odd_saved] {
1931 verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
1932 } else {
1933 set et_vect_extract_even_odd_saved 0
1934 if { [istarget powerpc*-*-*] } {
1935 set et_vect_extract_even_odd_saved 1
1936 }
1937 }
1938
1939 verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
1940 return $et_vect_extract_even_odd_saved
1941}
1942
1943# Return 1 if the target supports vector interleaving, 0 otherwise.
1944
1945proc check_effective_target_vect_interleave { } {
1946 global et_vect_interleave_saved
1947
1948 if [info exists et_vect_interleave_saved] {
1949 verbose "check_effective_target_vect_interleave: using cached result" 2
1950 } else {
1951 set et_vect_interleave_saved 0
1952 if { [istarget powerpc*-*-*]
1953 || [istarget i?86-*-*]
1954 || [istarget x86_64-*-*] } {
1955 set et_vect_interleave_saved 1
1956 }
1957 }
1958
1959 verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
1960 return $et_vect_interleave_saved
1961}
1962
0be79f24
DN
1963# Return 1 if the target supports section-anchors
1964
1965proc check_effective_target_section_anchors { } {
1966 global et_section_anchors_saved
1967
1968 if [info exists et_section_anchors_saved] {
1969 verbose "check_effective_target_section_anchors: using cached result" 2
1970 } else {
1971 set et_section_anchors_saved 0
1972 if { [istarget powerpc*-*-*] } {
1973 set et_section_anchors_saved 1
1974 }
1975 }
1976
1977 verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
1978 return $et_section_anchors_saved
1979}
1980
f12b785d
RH
1981# Return 1 if the target supports atomic operations on "int" and "long".
1982
1983proc check_effective_target_sync_int_long { } {
1984 global et_sync_int_long_saved
1985
1986 if [info exists et_sync_int_long_saved] {
1987 verbose "check_effective_target_sync_int_long: using cached result" 2
1988 } else {
1989 set et_sync_int_long_saved 0
915167f5
GK
1990# This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1991# load-reserved/store-conditional instructions.
f12b785d
RH
1992 if { [istarget ia64-*-*]
1993 || [istarget i?86-*-*]
1994 || [istarget x86_64-*-*]
915167f5 1995 || [istarget alpha*-*-*]
89a590b3 1996 || [istarget s390*-*-*]
396b535a
JJ
1997 || [istarget powerpc*-*-*]
1998 || [istarget sparc64-*-*]
1999 || [istarget sparcv9-*-*] } {
f12b785d
RH
2000 set et_sync_int_long_saved 1
2001 }
2002 }
2003
2004 verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2005 return $et_sync_int_long_saved
2006}
2007
bc0f348e
GK
2008# Return 1 if the target supports atomic operations on "char" and "short".
2009
2010proc check_effective_target_sync_char_short { } {
2011 global et_sync_char_short_saved
2012
2013 if [info exists et_sync_char_short_saved] {
2014 verbose "check_effective_target_sync_char_short: using cached result" 2
2015 } else {
2016 set et_sync_char_short_saved 0
2017# This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2018# load-reserved/store-conditional instructions.
2019 if { [istarget ia64-*-*]
2020 || [istarget i?86-*-*]
2021 || [istarget x86_64-*-*]
38f31687 2022 || [istarget alpha*-*-*]
3093f076 2023 || [istarget s390*-*-*]
396b535a
JJ
2024 || [istarget powerpc*-*-*]
2025 || [istarget sparc64-*-*]
2026 || [istarget sparcv9-*-*] } {
bc0f348e
GK
2027 set et_sync_char_short_saved 1
2028 }
2029 }
2030
2031 verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2032 return $et_sync_char_short_saved
2033}
2034
7fc564b7
RS
2035# Return 1 if the target uses a ColdFire FPU.
2036
2037proc check_effective_target_coldfire_fpu { } {
2038 return [check_no_compiler_messages coldfire_fpu assembly {
2039 #ifndef __mcffpu__
2040 #error FOO
2041 #endif
2042 }]
2043}
2044
2755c056
RS
2045# Return true if this is a uClibc target.
2046
2047proc check_effective_target_uclibc {} {
2048 return [check_no_compiler_messages uclibc object {
2049 #include <features.h>
2050 #if !defined (__UCLIBC__)
2051 #error FOO
2052 #endif
2053 }]
2054}
2055
a5ea7a0b
RS
2056# Return 1 if
2057# (a) an error of a few ULP is expected in string to floating-point
2058# conversion functions; and
2059# (b) overflow is not always detected correctly by those functions.
2060
2061proc check_effective_target_lax_strtofp {} {
2062 # By default, assume that all uClibc targets suffer from this.
2063 return [check_effective_target_uclibc]
2064}
2065
2066# Return 1 if this is a target for which wcsftime is a dummy
2067# function that always returns 0.
2068
2069proc check_effective_target_dummy_wcsftime {} {
2070 # By default, assume that all uClibc targets suffer from this.
2071 return [check_effective_target_uclibc]
2072}
2073
b6dc500c
JJ
2074# Return 1 if the target matches the effective target 'arg', 0 otherwise.
2075# This can be used with any check_* proc that takes no argument and
2076# returns only 1 or 0. It could be used with check_* procs that take
2077# arguments with keywords that pass particular arguments.
2078
2079proc is-effective-target { arg } {
2080 set selected 0
68897708
JJ
2081 if { [info procs check_effective_target_${arg}] != [list] } {
2082 set selected [check_effective_target_${arg}]
2083 } else {
2084 switch $arg {
2085 "vmx_hw" { set selected [check_vmx_hw_available] }
2086 "named_sections" { set selected [check_named_sections_available] }
2087 "gc_sections" { set selected [check_gc_sections_available] }
294f1ce3 2088 "cxa_atexit" { set selected [check_cxa_atexit_available] }
68897708
JJ
2089 default { error "unknown effective target keyword `$arg'" }
2090 }
b6dc500c
JJ
2091 }
2092 verbose "is-effective-target: $arg $selected" 2
2093 return $selected
2094}
810838e7
JJ
2095
2096# Return 1 if the argument is an effective-target keyword, 0 otherwise.
2097
2098proc is-effective-target-keyword { arg } {
2099 if { [info procs check_effective_target_${arg}] != [list] } {
2100 return 1
2101 } else {
2102 # These have different names for their check_* procs.
2103 switch $arg {
2104 "vmx_hw" { return 1 }
2105 "named_sections" { return 1 }
2106 "gc_sections" { return 1 }
294f1ce3 2107 "cxa_atexit" { return 1 }
810838e7
JJ
2108 default { return 0 }
2109 }
2110 }
2111}
efe5e271
PB
2112
2113# Return 1 if target default to short enums
2114
2115proc check_effective_target_short_enums { } {
8ce1ac69
RS
2116 return [check_no_compiler_messages short_enums assembly {
2117 enum foo { bar };
2118 int s[sizeof (enum foo) == 1 ? 1 : -1];
2119 }]
efe5e271
PB
2120}
2121
19450f2b
DJ
2122# Return 1 if target supports merging string constants at link time.
2123
2124proc check_effective_target_string_merging { } {
2125 return [check_no_messages_and_pattern string_merging \
2126 "rodata\\.str" assembly {
2127 const char *var = "String";
2128 } {-O2}]
2129}
8f3fc4aa
JDA
2130
2131# Return 1 if target has the basic signed and unsigned types in
2132# <stdint.h>, 0 otherwise.
2133
2134proc check_effective_target_stdint_types { } {
2135 return [check_no_compiler_messages stdint_types assembly {
2136 #include <stdint.h>
2137 int8_t a; int16_t b; int32_t c; int64_t d;
2138 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2139 }]
2140}
3920f1fd
HPN
2141
2142# Return 1 if programs are intended to be run on a simulator
2143# (i.e. slowly) rather than hardware (i.e. fast).
2144
2145proc check_effective_target_simulator { } {
2146
2147 # All "src/sim" simulators set this one.
2148 if [board_info target exists is_simulator] {
2149 return [board_info target is_simulator]
2150 }
2151
2152 # The "sid" simulators don't set that one, but at least they set
2153 # this one.
2154 if [board_info target exists slow_simulator] {
2155 return [board_info target slow_simulator]
2156 }
2157
2158 return 0
2159}