OSDN Git Service

2007-09-18 Sandra Loosemore <sandra@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007
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 # 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
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.
26 #
27 # BASENAME is a basename to use for temporary files.
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.
32 # TYPE is the type of compilation to perform (see target_compile).
33 # CONTENTS gives the contents of the input file.
34 # The rest is optional:
35 # OPTIONS: additional compiler options to use.
36 proc get_compiler_messages {basename want_output type contents args} {
37     global tool
38
39     if { [llength $args] > 0 } {
40         set options [list "additional_flags=[lindex $args 0]"]
41     } else {
42         set options ""
43     }
44
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
53     set lines [${tool}_target_compile $src $output $type "$options"]
54     file delete $src
55
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
77 }
78
79 proc 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
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.
93 proc 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} {
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.
111 proc 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
118         set et_cache($prop,target) $target
119         set results [eval get_compiler_messages $prop 1 $args]
120         set et_cache($prop,value) \
121             [expr [string match "" [lindex $results 0]] \
122                  && [regexp $pattern [lindex $results 1]]]
123     }
124     set value $et_cache($prop,value)
125     verbose "check_no_messages_and_pattern $prop: returning $value for $target" 2
126     return $value
127 }
128
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
136 proc check_weak_available { } {
137     global target_triplet
138     global target_cpu
139
140     # All mips targets should support it
141
142     if { [ string first "mips" $target_cpu ] >= 0 } {
143         return 1
144     }
145
146     # All solaris2 targets should support it
147
148     if { [regexp ".*-solaris2.*" $target_triplet] } {
149         return 1
150     }
151
152     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
153
154     if { [regexp "alpha.*osf.*" $target_triplet] } {
155         return 1
156     }
157
158     # Windows targets Cygwin and MingW32 support it
159
160     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
161         return 1
162     }
163
164     # HP-UX 10.X doesn't support it
165
166     if { [istarget "hppa*-*-hpux10*"] } {
167         return 0
168     }
169
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 }
179         mach-o   { return 1 }
180         som      { return 1 }
181         unknown  { return -1 }
182         default  { return 0 }
183     }
184 }
185
186 ###############################
187 # proc check_visibility_available { what_kind }
188 ###############################
189
190 # The visibility attribute is only support in some object formats
191 # This proc returns 1 if it is supported, 0 if not.
192 # The argument is the kind of visibility, default/protected/hidden/internal.
193
194 proc check_visibility_available { what_kind } {
195     global tool
196     global target_triplet
197
198     # On NetWare, support makes no sense.
199     if { [istarget *-*-netware*] } {
200         return 0
201     }
202
203     if [string match "" $what_kind] { set what_kind "hidden" }
204
205     return [check_no_compiler_messages visibility_available_$what_kind object "
206         void f() __attribute__((visibility(\"$what_kind\")));
207         void f() {}
208     "]
209 }
210
211 ###############################
212 # proc check_alias_available { }
213 ###############################
214
215 # Determine if the target toolchain supports the alias attribute.
216
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
222 proc check_alias_available { } {
223     global alias_available_saved
224     global tool
225
226     if [info exists alias_available_saved] {
227         verbose "check_alias_available  returning saved $alias_available_saved" 2
228     } else {
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"]
233         # Compile a small test program.  The definition of "g" is
234         # necessary to keep the Solaris assembler from complaining
235         # about the program.
236         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
237         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
238         close $f
239         set lines [${tool}_target_compile $src $obj object ""]
240         file delete $src
241         remote_file build delete $obj
242
243         if [string match "" $lines] then {
244             # No error messages, everything is OK.
245             set alias_available_saved 2
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
254                     set alias_available_saved -1
255                 } else {
256                     set alias_available_saved 0
257                 }
258             } else {
259                 if [regexp "only weak aliases are supported" $lines] {
260                 verbose "check_alias_available  target supports only weak aliases" 2
261                 set alias_available_saved 1
262                 } else {
263                     set alias_available_saved -1
264                 }
265             }
266         }
267
268         verbose "check_alias_available  returning $alias_available_saved" 2
269     }
270
271     return $alias_available_saved
272 }
273
274 # Returns true if --gc-sections is supported on the target.
275
276 proc check_gc_sections_available { } {
277     global gc_sections_available_saved
278     global tool
279
280     if {![info exists gc_sections_available_saved]} {
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
289         # elf2flt uses -q (--emit-relocs), which is incompatible with
290         # --gc-sections.
291         if { [board_info target exists ldflags]
292              && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
293             set gc_sections_available_saved 0
294             return 0
295         }
296
297         # VxWorks kernel modules are relocatable objects linked with -r,
298         # while RTP executables are linked with -q (--emit-relocs).
299         # Both of these options are incompatible with --gc-sections.
300         if { [istarget *-*-vxworks*] } {
301             set gc_sections_available_saved 0
302             return 0
303         }
304
305         # Check if the ld used by gcc supports --gc-sections.
306         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
307         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
308         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
309         set ld_output [remote_exec host "$gcc_ld" "--help"]
310         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
311             set gc_sections_available_saved 1
312         } else {
313             set gc_sections_available_saved 0
314         }
315     }
316     return $gc_sections_available_saved
317 }
318
319 # Return true if profiling is supported on the target.
320
321 proc check_profiling_available { test_what } {
322     global profiling_available_saved
323
324     verbose "Profiling argument is <$test_what>" 1
325
326     # These conditions depend on the argument so examine them before
327     # looking at the cache variable.
328
329     # Support for -p on solaris2 relies on mcrt1.o which comes with the
330     # vendor compiler.  We cannot reliably predict the directory where the
331     # vendor compiler (and thus mcrt1.o) is installed so we can't
332     # necessarily find mcrt1.o even if we have it.
333     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
334         return 0
335     }
336
337     # Support for -p on irix relies on libprof1.a which doesn't appear to
338     # exist on any irix6 system currently posting testsuite results.
339     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
340     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
341     if { [istarget mips*-*-irix*]
342     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
343         return 0
344     }
345
346     # At present, there is no profiling support on NetWare.
347     if { [istarget *-*-netware*] } {
348         return 0
349     }
350
351     # uClibc does not have gcrt1.o.
352     if { [check_effective_target_uclibc]
353          && ([lindex $test_what 1] == "-p"
354              || [lindex $test_what 1] == "-pg") } {
355         return 0
356     }
357
358     # Now examine the cache variable.
359     if {![info exists profiling_available_saved]} {
360         # Some targets don't have any implementation of __bb_init_func or are
361         # missing other needed machinery.
362         if { [istarget mmix-*-*]
363              || [istarget arm*-*-eabi*]
364              || [istarget arm*-*-elf]
365              || [istarget arm*-*-symbianelf*]
366              || [istarget bfin-*-*]
367              || [istarget powerpc-*-eabi*]
368              || [istarget strongarm*-*-elf]
369              || [istarget xscale*-*-elf]
370              || [istarget cris-*-*]
371              || [istarget fido-*-elf]
372              || [istarget h8300-*-*]
373              || [istarget m32c-*-elf]
374              || [istarget m68k-*-elf]
375              || [istarget m68k-*-uclinux*]
376              || [istarget mips*-*-elf*]
377              || [istarget xtensa-*-elf]
378              || [istarget *-*-vxworks*]
379              || [istarget *-*-windiss] } {
380             set profiling_available_saved 0
381         } else {
382             set profiling_available_saved 1
383         }
384     }
385
386     return $profiling_available_saved
387 }
388
389 # Return 1 if target has packed layout of structure members by
390 # default, 0 otherwise.  Note that this is slightly different than
391 # whether the target has "natural alignment": both attributes may be
392 # false.
393
394 proc check_effective_target_default_packed { } {
395     return [check_no_compiler_messages default_packed assembly {
396         struct x { char a; long b; } c;
397         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
398     }]
399 }
400
401 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
402 # documentation, where the test also comes from.
403
404 proc check_effective_target_pcc_bitfield_type_matters { } {
405     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
406     # bitfields, but let's stick to the example code from the docs.
407     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
408         struct foo1 { char x; char :0; char y; };
409         struct foo2 { char x; int :0; char y; };
410         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
411     }]
412 }
413
414 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
415 #
416 # This won't change for different subtargets so cache the result.
417
418 proc check_effective_target_tls {} {
419     global et_tls_saved
420     global tool
421
422     if [info exists et_tls_saved] {
423         verbose "check_effective_target_tls: using cached result" 2
424     } else {
425         set et_tls_saved 0
426
427         set src tls[pid].c
428         set asm tls[pid].S
429         verbose "check_effective_target_tls: compiling testfile $src" 2
430         set f [open $src "w"]
431         # Compile a small test program.  Make sure that we test accesses
432         # as well as declarations.  
433         puts $f "__thread int i;\n"
434         puts $f "int f (void) { return i; }\n"
435         puts $f "void g (int j) { i = j; }\n"
436         close $f
437
438         # Test for thread-local data supported by the platform.
439         set comp_output \
440             [${tool}_target_compile $src $asm assembly ""]
441         file delete $src
442         if { [string match "" $comp_output] } {
443             # No error messages, everything is OK.
444             set et_tls_saved 1
445         }
446         remove-build-file $asm
447     }
448     verbose "check_effective_target_tls: returning $et_tls_saved" 2
449     return $et_tls_saved
450 }
451
452 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
453 #
454 # This won't change for different subtargets so cache the result.
455
456 proc check_effective_target_tls_native {} {
457     global et_tls_native_saved
458     global tool
459
460     if [info exists et_tls_saved] {
461         verbose "check_effective_target_tls_native: using cached result" 2
462     } else {
463         set et_tls_native_saved 0
464
465         set src tls[pid].c
466         set asm tls[pid].S
467         verbose "check_effective_target_tls_native: compiling testfile $src" 2
468         set f [open $src "w"]
469         # Compile a small test program.  Make sure that we test accesses
470         # as well as declarations.  
471         puts $f "__thread int i;\n"
472         puts $f "int f (void) { return i; }\n"
473         puts $f "void g (int j) { i = j; }\n"
474         close $f
475
476         # Test for thread-local data supported by the platform.
477         set comp_output [${tool}_target_compile $src $asm assembly ""]
478         file delete $src
479         if { [string match "" $comp_output] } {
480             # No error messages, everything is OK.
481             set fd [open $asm r]
482             set text [read $fd]
483             close $fd
484             if { [string match "*emutls*" $text]} {
485                 set et_tls_native_saved 0
486             } else {
487                 set et_tls_native_saved 1
488             }
489         }
490         remove-build-file $asm
491     }
492     verbose "check_effective_target_tls_native: returning $et_tls_native_saved" 2
493     return $et_tls_native_saved
494 }
495
496 # Return 1 if TLS executables can run correctly, 0 otherwise.
497 #
498 # This won't change for different subtargets so cache the result.
499
500 proc check_effective_target_tls_runtime {} {
501     global et_tls_runtime_saved
502     global tool
503
504     if [info exists et_tls_runtime_saved] {
505         verbose "check_effective_target_tls_runtime: using cached result" 2
506     } else {
507         set et_tls_runtime_saved 0
508
509         set src tls_runtime[pid].c
510         set exe tls_runtime[pid].x
511         verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
512         set f [open $src "w"]
513         # Compile a small test program.
514         puts $f "__thread int thr = 0;\n"
515         puts $f "int main(void)\n {\n return thr;\n}"
516         close $f
517
518         set comp_output \
519             [${tool}_target_compile $src $exe executable ""]
520         file delete $src
521
522         if [string match "" $comp_output] then {
523             # No error messages, everything is OK.
524
525             set result [remote_load target "./$exe" "" ""]
526             set status [lindex $result 0]
527             remote_file build delete $exe
528
529             verbose "check_effective_target_tls_runtime status is <$status>" 2
530
531             if { $status == "pass" } {
532                 set et_tls_runtime_saved 1
533             }
534
535             verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
536         }
537     }
538
539     return $et_tls_runtime_saved
540 }
541
542 # Return 1 if compilation with -fopenmp is error-free for trivial
543 # code, 0 otherwise.
544
545 proc check_effective_target_fopenmp {} {
546     return [check_no_compiler_messages fopenmp object {
547         void foo (void) { }
548     } "-fopenmp"]
549 }
550
551 # Return 1 if the target supports -fstack-protector
552 proc check_effective_target_fstack_protector {} {
553     global tool
554     set result ""
555
556     set src stack_prot[pid].c
557     set exe stack_prot[pid].x
558
559     verbose "check_effective_target_fstack_protector compiling testfile $src" 2
560
561     set f [open $src "w"]
562     # Compile a small test program.
563     puts $f "int main (void)\n { return 0; }\n"
564     close $f
565
566     set opts "additional_flags=-fstack-protector"
567     set lines [${tool}_target_compile $src $exe executable "$opts" ]
568     file delete $src
569
570     if [string match "" $lines] then {
571         # No error messages, everything is OK.
572         set result [${tool}_load "./$exe" "" ""]
573         set status [lindex $result 0]
574         remote_file build delete $exe
575         verbose "check_iconv_available status is <$status>" 2
576
577         if { $status == "pass" } then {
578             return 1
579         }
580     }
581     return 0
582 }
583
584 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
585 # for trivial code, 0 otherwise.
586
587 proc check_effective_target_freorder {} {
588     return [check_no_compiler_messages freorder object {
589         void foo (void) { }
590     } "-freorder-blocks-and-partition"]
591 }
592
593 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
594 # emitted, 0 otherwise.  Whether a shared library can actually be built is
595 # out of scope for this test.
596
597 proc check_effective_target_fpic { } {
598     # Note that M68K has a multilib that supports -fpic but not
599     # -fPIC, so we need to check both.  We test with a program that
600     # requires GOT references.
601     foreach arg {fpic fPIC} {
602         if [check_no_compiler_messages $arg object {
603             extern int foo (void); extern int bar;
604             int baz (void) { return foo () + bar; }
605         } "-$arg"] {
606             return 1
607         }
608     }
609     return 0
610 }
611
612 # Return true if the target supports -mpaired-single (as used on MIPS).
613
614 proc check_effective_target_mpaired_single { } {
615     return [check_no_compiler_messages mpaired_single object {
616         void foo (void) { }
617     } "-mpaired-single"]
618 }
619
620 # Return 1 if the current multilib does not generate PIC by default.
621
622 proc check_effective_target_nonpic { } {
623     return [check_no_compiler_messages nonpic assembly {
624         #if __PIC__
625         #error FOO
626         #endif
627     }]
628 }
629
630 # Return 1 if the target does not use a status wrapper.
631
632 proc check_effective_target_unwrapped { } {
633     if { [target_info needs_status_wrapper] != "" \
634              && [target_info needs_status_wrapper] != "0" } {
635         return 0
636     }
637     return 1
638 }
639
640 # Return true if iconv is supported on the target. In particular IBM1047.
641
642 proc check_iconv_available { test_what } {
643     global tool
644     global libiconv
645
646     set result ""
647
648     set src iconv[pid].c
649     set exe iconv[pid].x
650     verbose "check_iconv_available compiling testfile $src" 2
651     set f [open $src "w"]
652     # Compile a small test program.
653     puts $f "#include <iconv.h>\n"
654     puts $f "int main (void)\n {\n iconv_t cd; \n"
655     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
656     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
657     puts $f "return 0;\n}"
658     close $f
659
660     # If the tool configuration file has not set libiconv, try "-liconv"
661     if { ![info exists libiconv] } {
662         set libiconv "-liconv"
663     }
664     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
665     file delete $src
666
667     if [string match "" $lines] then {
668         # No error messages, everything is OK.
669
670         set result [${tool}_load "./$exe" "" ""]
671         set status [lindex $result 0]
672         remote_file build delete $exe
673
674         verbose "check_iconv_available status is <$status>" 2
675
676         if { $status == "pass" } then {
677             return 1
678         }
679     }
680
681     return 0
682 }
683
684 # Return true if named sections are supported on this target.
685
686 proc check_named_sections_available { } {
687     return [check_no_compiler_messages named_sections assembly {
688         int __attribute__ ((section("whatever"))) foo;
689     }]
690 }
691
692 # Return 1 if the target supports Fortran real kinds larger than real(8),
693 # 0 otherwise.
694 #
695 # When the target name changes, replace the cached result.
696
697 proc check_effective_target_fortran_large_real { } {
698     global et_fortran_large_real_saved
699     global et_fortran_large_real_target_name
700     global tool
701
702     if { ![info exists et_fortran_large_real_target_name] } {
703         set et_fortran_large_real_target_name ""
704     }
705
706     # If the target has changed since we set the cached value, clear it.
707     set current_target [current_target_name]
708     if { $current_target != $et_fortran_large_real_target_name } {
709         verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
710         set et_fortran_large_real_target_name $current_target
711         if [info exists et_fortran_large_real_saved] {
712             verbose "check_effective_target_fortran_large_real: removing cached result" 2
713             unset et_fortran_large_real_saved
714         }
715     }
716
717     if [info exists et_fortran_large_real_saved] {
718         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
719     } else {
720         set et_fortran_large_real_saved 0
721
722         # Set up, compile, and execute a test program using large real
723         # kinds.  Include the current process ID in the file names to
724         # prevent conflicts with invocations for multiple testsuites.
725         set src real[pid].f90
726         set exe real[pid].x
727
728         set f [open $src "w"]
729         puts $f "integer,parameter :: k = &"
730         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
731         puts $f "real(kind=k) :: x"
732         puts $f "x = cos (x);"
733         puts $f "end"
734         close $f
735
736         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
737         set lines [${tool}_target_compile $src $exe executable ""]
738         file delete $src
739
740         if [string match "" $lines] then {
741             # No error message, compilation succeeded.
742             remote_file build delete $exe
743             set et_fortran_large_real_saved 1
744         }
745     }
746
747     return $et_fortran_large_real_saved
748 }
749
750 # Return 1 if the target supports Fortran integer kinds larger than
751 # integer(8), 0 otherwise.
752 #
753 # When the target name changes, replace the cached result.
754
755 proc check_effective_target_fortran_large_int { } {
756     global et_fortran_large_int_saved
757     global et_fortran_large_int_target_name
758     global tool
759
760     if { ![info exists et_fortran_large_int_target_name] } {
761         set et_fortran_large_int_target_name ""
762     }
763
764     # If the target has changed since we set the cached value, clear it.
765     set current_target [current_target_name]
766     if { $current_target != $et_fortran_large_int_target_name } {
767         verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
768         set et_fortran_large_int_target_name $current_target
769         if [info exists et_fortran_large_int_saved] {
770             verbose "check_effective_target_fortran_large_int: removing cached result" 2
771             unset et_fortran_large_int_saved
772         }
773     }
774
775     if [info exists et_fortran_large_int_saved] {
776         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
777     } else {
778         set et_fortran_large_int_saved 0
779
780         # Set up, compile, and execute a test program using large integer
781         # kinds.  Include the current process ID in the file names to
782         # prevent conflicts with invocations for multiple testsuites.
783         set src int[pid].f90
784         set exe int[pid].x
785
786         set f [open $src "w"]
787         puts $f "integer,parameter :: k = &"
788         puts $f "  selected_int_kind (range (0_8) + 1)"
789         puts $f "integer(kind=k) :: i"
790         puts $f "end"
791         close $f
792
793         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
794         set lines [${tool}_target_compile $src $exe executable ""]
795         file delete $src
796
797         if [string match "" $lines] then {
798             # No error message, compilation succeeded.
799             remote_file build delete $exe
800             set et_fortran_large_int_saved 1
801         }
802     }
803
804     return $et_fortran_large_int_saved
805 }
806
807 # Return 1 if we can statically link libgfortran, 0 otherwise.
808 #
809 # When the target name changes, replace the cached result.
810
811 proc check_effective_target_static_libgfortran { } {
812     global et_static_libgfortran
813     global et_static_libgfortran_target_name
814     global tool
815
816     if { ![info exists et_static_libgfortran_target_name] } {
817        set et_static_libgfortran_target_name ""
818     }
819
820     # If the target has changed since we set the cached value, clear it.
821     set current_target [current_target_name]
822     if { $current_target != $et_static_libgfortran_target_name } {
823        verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
824        set et_static_libgfortran_target_name $current_target
825        if [info exists et_static_libgfortran_saved] {
826            verbose "check_effective_target_static_libgfortran: removing cached result" 2
827            unset et_static_libgfortran_saved
828        }
829     }
830
831     if [info exists et_static_libgfortran_saved] {
832        verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
833     } else {
834        set et_static_libgfortran_saved 0
835
836        # Set up, compile, and execute a test program using static linking.
837        # Include the current process ID in the file names to prevent
838        # conflicts with invocations for multiple testsuites.
839        set opts "additional_flags=-static"
840        set src static[pid].f
841        set exe static[pid].x
842
843        set f [open $src "w"]
844        puts $f "      print *, 'test'"
845        puts $f "      end"
846        close $f
847
848        verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
849        set lines [${tool}_target_compile $src $exe executable "$opts"]
850        file delete $src
851
852        if [string match "" $lines] then {
853            # No error message, compilation succeeded.
854            remote_file build delete $exe
855            set et_static_libgfortran_saved 1
856        }
857     }
858
859     return $et_static_libgfortran_saved
860 }
861
862 # Return 1 if the target supports executing AltiVec instructions, 0
863 # otherwise.  Cache the result.
864
865 proc check_vmx_hw_available { } {
866     global vmx_hw_available_saved
867     global tool
868
869     if [info exists vmx_hw_available_saved] {
870         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
871     } else {
872         set vmx_hw_available_saved 0
873
874         # Some simulators are known to not support VMX instructions.
875         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
876             verbose "check_hw_available  returning 0" 2
877             return $vmx_hw_available_saved
878         }
879
880         # Set up, compile, and execute a test program containing VMX
881         # instructions.  Include the current process ID in the file
882         # names to prevent conflicts with invocations for multiple
883         # testsuites.
884         set src vmx[pid].c
885         set exe vmx[pid].x
886
887         set f [open $src "w"]
888         puts $f "int main() {"
889         puts $f "#ifdef __MACH__"
890         puts $f "  asm volatile (\"vor v0,v0,v0\");"
891         puts $f "#else"
892         puts $f "  asm volatile (\"vor 0,0,0\");"
893         puts $f "#endif"
894         puts $f "  return 0; }"
895         close $f
896
897         # Most targets don't require special flags for this test case, but
898         # Darwin does.
899         if [istarget *-*-darwin*] {
900           set opts "additional_flags=-maltivec"
901         } else {
902           set opts ""
903         }
904
905         verbose "check_vmx_hw_available  compiling testfile $src" 2
906         set lines [${tool}_target_compile $src $exe executable "$opts"]
907         file delete $src
908
909         if [string match "" $lines] then {
910             # No error message, compilation succeeded.
911             set result [${tool}_load "./$exe" "" ""]
912             set status [lindex $result 0]
913             remote_file build delete $exe
914             verbose "check_vmx_hw_available testfile status is <$status>" 2
915
916             if { $status == "pass" } then {
917                 set vmx_hw_available_saved 1
918             }
919         } else {
920             verbose "check_vmx_hw_availalble testfile compilation failed" 2
921         }
922     }
923
924     return $vmx_hw_available_saved
925 }
926
927 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
928 # complex float arguments.  This affects gfortran tests that call cabsf
929 # in libm built by an earlier compiler.  Return 1 if libm uses the same
930 # argument passing as the compiler under test, 0 otherwise.
931 #
932 # When the target name changes, replace the cached result.
933
934 proc check_effective_target_broken_cplxf_arg { } {
935     global et_broken_cplxf_arg_saved
936     global et_broken_cplxf_arg_target_name
937     global tool
938
939     # Skip the work for targets known not to be affected.
940     if { ![istarget powerpc64-*-linux*] } {
941         return 0
942     } elseif { [is-effective-target ilp32] } {
943         return 0
944     }
945
946     if { ![info exists et_broken_cplxf_arg_target_name] } {
947         set et_broken_cplxf_arg_target_name ""
948     }
949
950     # If the target has changed since we set the cached value, clear it.
951     set current_target [current_target_name]
952     if { $current_target != $et_broken_cplxf_arg_target_name } {
953         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
954         set et_broken_cplxf_arg_target_name $current_target
955         if [info exists et_broken_cplxf_arg_saved] {
956             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
957             unset et_broken_cplxf_arg_saved
958         }
959     }
960
961     if [info exists et_broken_cplxf_arg_saved] {
962         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
963     } else {
964         set et_broken_cplxf_arg_saved 0
965         # This is only known to affect one target.
966         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
967             set et_broken_cplxf_arg_saved 0
968             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
969             return $et_broken_cplxf_arg_saved
970         }
971
972         # Set up, compile, and execute a C test program that calls cabsf.
973         set src cabsf[pid].c
974         set exe cabsf[pid].x
975
976         set f [open $src "w"]
977         puts $f "#include <complex.h>"
978         puts $f "extern void abort (void);"
979         puts $f "float fabsf (float);"
980         puts $f "float cabsf (_Complex float);"
981         puts $f "int main ()"
982         puts $f "{"
983         puts $f "  _Complex float cf;"
984         puts $f "  float f;"
985         puts $f "  cf = 3 + 4.0fi;"
986         puts $f "  f = cabsf (cf);"
987         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
988         puts $f "  return 0;"
989         puts $f "}"
990         close $f
991
992         set lines [${tool}_target_compile $src $exe executable "-lm"]
993         file delete $src
994
995         if [string match "" $lines] {
996             # No error message, compilation succeeded.
997             set result [${tool}_load "./$exe" "" ""]
998             set status [lindex $result 0]
999             remote_file build delete $exe
1000
1001             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
1002
1003             if { $status != "pass" } {
1004                 set et_broken_cplxf_arg_saved 1
1005             }
1006         } else {
1007             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
1008         }
1009     }
1010     return $et_broken_cplxf_arg_saved
1011 }
1012
1013 proc check_alpha_max_hw_available { } {
1014     global alpha_max_hw_available_saved
1015     global tool
1016
1017     if [info exists alpha_max_hw_available_saved] {
1018         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
1019     } else {
1020         set alpha_max_hw_available_saved 0
1021
1022         # Set up, compile, and execute a test program probing bit 8 of the
1023         # architecture mask, which indicates presence of MAX instructions.
1024         set src max[pid].c
1025         set exe max[pid].x
1026
1027         set f [open $src "w"]
1028         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
1029         close $f
1030
1031         verbose "check_alpha_max_hw_available compiling testfile $src" 2
1032         set lines [${tool}_target_compile $src $exe executable ""]
1033         file delete $src
1034
1035         if [string match "" $lines] then {
1036             # No error message, compilation succeeded.
1037             set result [${tool}_load "./$exe" "" ""]
1038             set status [lindex $result 0]
1039             remote_file build delete $exe
1040             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
1041
1042             if { $status == "pass" } then {
1043                 set alpha_max_hw_available_saved 1
1044             }
1045         } else {
1046             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
1047         }
1048     }
1049
1050     return $alpha_max_hw_available_saved
1051 }
1052
1053 # Returns true iff the FUNCTION is available on the target system.
1054 # (This is essentially a Tcl implementation of Autoconf's
1055 # AC_CHECK_FUNC.)
1056
1057 proc check_function_available { function } {
1058     set var "${function}_available_saved"
1059     global $var
1060     global tool
1061
1062     if {![info exists $var]} {
1063         # Assume it exists.
1064         set $var 1
1065         # Check to make sure.
1066         set src "function[pid].c"
1067         set exe "function[pid].exe"
1068
1069         set f [open $src "w"]
1070         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
1071         puts $f "char $function ();\n"
1072         puts $f "int main () { $function (); }"
1073         close $f
1074
1075         set lines [${tool}_target_compile $src $exe executable ""]
1076         file delete $src
1077         file delete $exe
1078
1079         if {![string match "" $lines]} then {
1080             set $var 0
1081             verbose -log "$function is not available"
1082         } else {
1083             verbose -log "$function is available"
1084         }
1085     }
1086
1087     eval return \$$var
1088 }
1089
1090 # Returns true iff "fork" is available on the target system.
1091
1092 proc check_fork_available {} {
1093     return [check_function_available "fork"]
1094 }
1095
1096 # Returns true iff "mkfifo" is available on the target system.
1097
1098 proc check_mkfifo_available {} {
1099     if {[istarget *-*-cygwin*]} {
1100        # Cygwin has mkfifo, but support is incomplete.
1101        return 0
1102      }
1103
1104     return [check_function_available "mkfifo"]
1105 }
1106
1107 # Returns true iff "__cxa_atexit" is used on the target system.
1108
1109 proc check_cxa_atexit_available { } {
1110     global et_cxa_atexit
1111     global et_cxa_atexit_target_name
1112     global tool 
1113
1114     if { ![info exists et_cxa_atexit_target_name] } {
1115         set et_cxa_atexit_target_name ""
1116     }
1117
1118     # If the target has changed since we set the cached value, clear it.
1119     set current_target [current_target_name]
1120     if { $current_target != $et_cxa_atexit_target_name } {
1121         verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
1122         set et_cxa_atexit_target_name $current_target
1123         if [info exists et_cxa_atexit] {
1124             verbose "check_cxa_atexit_available: removing cached result" 2
1125             unset et_cxa_atexit
1126         }
1127     }
1128
1129     if [info exists et_cxa_atexit] {
1130         verbose "check_cxa_atexit_available: using cached result" 2
1131     } elseif { [istarget "hppa*-*-hpux10*"] } {
1132         # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1133         set et_cxa_atexit 0
1134     } else {
1135         set et_cxa_atexit 0
1136
1137         # Set up, compile, and execute a C++ test program that depends
1138         # on correct ordering of static object destructors. This is
1139         # indicative of the presence and use of __cxa_atexit.
1140         set src cxaatexit[pid].cc
1141         set exe cxaatexit[pid].x
1142
1143         set f [open $src "w"]
1144         puts $f "#include <stdlib.h>"
1145         puts $f "static unsigned int count;"
1146         puts $f "struct X"
1147         puts $f "{"
1148         puts $f "  X() { count = 1; }"
1149         puts $f "  ~X()"
1150         puts $f "  {"
1151         puts $f "    if (count != 3)"
1152         puts $f "      exit(1);"
1153         puts $f "    count = 4;"
1154         puts $f "  }"
1155         puts $f "};"
1156         puts $f "void f()"
1157         puts $f "{"
1158         puts $f "  static X x;"
1159         puts $f "}"
1160         puts $f "struct Y"
1161         puts $f "{"
1162         puts $f "  Y() { f(); count = 2; }"
1163         puts $f "  ~Y()"
1164         puts $f "  {"
1165         puts $f "    if (count != 2)"
1166         puts $f "      exit(1);"
1167         puts $f "    count = 3;"
1168         puts $f "  }"
1169         puts $f "};"
1170         puts $f "Y y;"
1171         puts $f "int main()"
1172         puts $f "{ return 0; }"
1173         close $f
1174
1175         set lines [${tool}_target_compile $src $exe executable ""]
1176         file delete $src
1177
1178         if [string match "" $lines] {
1179             # No error message, compilation succeeded.
1180             set result [${tool}_load "./$exe" "" ""]
1181             set status [lindex $result 0]
1182             remote_file build delete $exe
1183
1184             verbose "check_cxa_atexit_available: status is <$status>" 2
1185
1186             if { $status == "pass" } {
1187                 set et_cxa_atexit 1
1188             }
1189         } else {
1190             verbose "check_cxa_atexit_available: compilation failed" 2
1191         }
1192     }
1193     return $et_cxa_atexit
1194 }
1195
1196
1197 # Return 1 if we're generating 32-bit code using default options, 0
1198 # otherwise.
1199
1200 proc check_effective_target_ilp32 { } {
1201     return [check_no_compiler_messages ilp32 object {
1202         int dummy[sizeof (int) == 4
1203                   && sizeof (void *) == 4
1204                   && sizeof (long) == 4 ? 1 : -1];
1205     }]
1206 }
1207
1208 # Return 1 if we're generating 32-bit or larger integers using default
1209 # options, 0 otherwise.
1210
1211 proc check_effective_target_int32plus { } {
1212     return [check_no_compiler_messages int32plus object {
1213         int dummy[sizeof (int) >= 4 ? 1 : -1];
1214     }]
1215 }
1216
1217 # Return 1 if we're generating 32-bit or larger pointers using default
1218 # options, 0 otherwise.
1219
1220 proc check_effective_target_ptr32plus { } {
1221     return [check_no_compiler_messages ptr32plus object {
1222         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1223     }]
1224 }
1225
1226 # Return 1 if we support 32-bit or larger array and structure sizes
1227 # using default options, 0 otherwise.
1228
1229 proc check_effective_target_size32plus { } {
1230     return [check_no_compiler_messages size32plus object {
1231         char dummy[65537];
1232     }]
1233 }
1234
1235 # Returns 1 if we're generating 16-bit or smaller integers with the
1236 # default options, 0 otherwise.
1237
1238 proc check_effective_target_int16 { } {
1239     return [check_no_compiler_messages int16 object {
1240         int dummy[sizeof (int) < 4 ? 1 : -1];
1241     }]
1242 }
1243
1244 # Return 1 if we're generating 64-bit code using default options, 0
1245 # otherwise.
1246
1247 proc check_effective_target_lp64 { } {
1248     return [check_no_compiler_messages lp64 object {
1249         int dummy[sizeof (int) == 4
1250                   && sizeof (void *) == 8
1251                   && sizeof (long) == 8 ? 1 : -1];
1252     }]
1253 }
1254
1255 # Return 1 if the target supports long double larger than double,
1256 # 0 otherwise.
1257
1258 proc check_effective_target_large_long_double { } {
1259     return [check_no_compiler_messages large_long_double object {
1260         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1261     }]
1262 }
1263
1264
1265 # Return 1 if the target supports compiling decimal floating point,
1266 # 0 otherwise.
1267
1268 proc check_effective_target_dfp_nocache { } {
1269     verbose "check_effective_target_dfp_nocache: compiling source" 2
1270     set ret [string match "" [get_compiler_messages dfp 0 object {
1271         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1272     }]]
1273     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1274     return $ret
1275 }
1276
1277 proc check_effective_target_dfprt_nocache { } {
1278     global tool
1279
1280     set ret 0
1281
1282     verbose "check_effective_target_dfprt_nocache: compiling source" 2
1283     # Set up, compile, and execute a test program containing decimal
1284     # float operations.
1285     set src dfprt[pid].c
1286     set exe dfprt[pid].x
1287
1288     set f [open $src "w"]
1289     puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1290     puts $f "int main () { z = x + y; return 0; }"
1291     close $f
1292
1293     verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1294     set lines [${tool}_target_compile $src $exe executable ""]
1295     file delete $src
1296
1297     if [string match "" $lines] then {
1298         # No error message, compilation succeeded.
1299         set result [${tool}_load "./$exe" "" ""]
1300         set status [lindex $result 0]
1301         remote_file build delete $exe
1302         verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1303         if { $status == "pass" } then {
1304             set ret 1
1305         }
1306     }
1307     return $ret
1308     verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1309 }
1310
1311 # Return 1 if the target supports compiling Decimal Floating Point,
1312 # 0 otherwise.
1313 #
1314 # This won't change for different subtargets so cache the result.
1315
1316 proc check_effective_target_dfp { } {
1317     global et_dfp_saved
1318
1319     if [info exists et_dfp_saved] {
1320         verbose "check_effective_target_dfp: using cached result" 2
1321     } else {
1322         set et_dfp_saved [check_effective_target_dfp_nocache]
1323     }
1324     verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1325     return $et_dfp_saved
1326 }
1327
1328 # Return 1 if the target supports linking and executing Decimal Floating
1329 # Point, # 0 otherwise.
1330 #
1331 # This won't change for different subtargets so cache the result.
1332
1333 proc check_effective_target_dfprt { } {
1334     global et_dfprt_saved
1335     global tool
1336
1337     if [info exists et_dfprt_saved] {
1338         verbose "check_effective_target_dfprt: using cached result" 2
1339     } else {
1340         set et_dfprt_saved [check_effective_target_dfprt_nocache]
1341     }
1342     verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1343     return $et_dfprt_saved
1344 }
1345
1346 # Return 1 if the target needs a command line argument to enable a SIMD
1347 # instruction set.
1348
1349 proc check_effective_target_vect_cmdline_needed { } {
1350     global et_vect_cmdline_needed_saved
1351     global et_vect_cmdline_needed_target_name
1352
1353     if { ![info exists et_vect_cmdline_needed_target_name] } {
1354         set et_vect_cmdline_needed_target_name ""
1355     }
1356
1357     # If the target has changed since we set the cached value, clear it.
1358     set current_target [current_target_name]
1359     if { $current_target != $et_vect_cmdline_needed_target_name } {
1360         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1361         set et_vect_cmdline_needed_target_name $current_target
1362         if { [info exists et_vect_cmdline_needed_saved] } {
1363             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1364             unset et_vect_cmdline_needed_saved
1365         }
1366     }
1367
1368     if [info exists et_vect_cmdline_needed_saved] {
1369         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1370     } else {
1371         set et_vect_cmdline_needed_saved 1
1372         if { [istarget ia64-*-*]
1373              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1374                  && [check_effective_target_lp64])
1375              || ([istarget powerpc*-*-*]
1376                  && ([check_effective_target_powerpc_spe]
1377                      || [check_effective_target_powerpc_altivec]))} {
1378            set et_vect_cmdline_needed_saved 0
1379         }
1380     }
1381
1382     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1383     return $et_vect_cmdline_needed_saved
1384 }
1385
1386 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1387 #
1388 # This won't change for different subtargets so cache the result.
1389
1390 proc check_effective_target_vect_int { } {
1391     global et_vect_int_saved
1392
1393     if [info exists et_vect_int_saved] {
1394         verbose "check_effective_target_vect_int: using cached result" 2
1395     } else {
1396         set et_vect_int_saved 0
1397         if { [istarget i?86-*-*]
1398               || [istarget powerpc*-*-*]
1399               || [istarget spu-*-*]
1400               || [istarget x86_64-*-*]
1401               || [istarget sparc*-*-*]
1402               || [istarget alpha*-*-*]
1403               || [istarget ia64-*-*] } {
1404            set et_vect_int_saved 1
1405         }
1406     }
1407
1408     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1409     return $et_vect_int_saved
1410 }
1411
1412 # Return 1 if the target supports int->float conversion 
1413 #
1414
1415 proc check_effective_target_vect_intfloat_cvt { } {
1416     global et_vect_intfloat_cvt_saved
1417
1418     if [info exists et_vect_intfloat_cvt_saved] {
1419         verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1420     } else {
1421         set et_vect_intfloat_cvt_saved 0
1422         if { [istarget i?86-*-*]
1423               || [istarget powerpc*-*-*]
1424               || [istarget x86_64-*-*] } {
1425            set et_vect_intfloat_cvt_saved 1
1426         }
1427     }
1428
1429     verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1430     return $et_vect_intfloat_cvt_saved
1431 }
1432
1433
1434 # Return 1 if the target supports float->int conversion
1435 #
1436
1437 proc check_effective_target_vect_floatint_cvt { } {
1438     global et_vect_floatint_cvt_saved
1439
1440     if [info exists et_vect_floatint_cvt_saved] {
1441         verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1442     } else {
1443         set et_vect_floatint_cvt_saved 0
1444         if { [istarget i?86-*-*]
1445               || [istarget x86_64-*-*] } {
1446            set et_vect_floatint_cvt_saved 1
1447         }
1448     }
1449
1450     verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1451     return $et_vect_floatint_cvt_saved
1452 }
1453
1454
1455 # Return 1 is this is an arm target using 32-bit instructions
1456 proc check_effective_target_arm32 { } {
1457     return [check_no_compiler_messages arm32 assembly {
1458         #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1459         #error FOO
1460         #endif
1461     }]
1462 }
1463
1464 # Return 1 if this is an ARM target supporting -mfpu=vfp
1465 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1466 # options.
1467
1468 proc check_effective_target_arm_vfp_ok { } {
1469     if { [check_effective_target_arm32] } {
1470         return [check_no_compiler_messages arm_vfp_ok object {
1471             int dummy;
1472         } "-mfpu=vfp -mfloat-abi=softfp"]
1473     } else {
1474         return 0
1475     }
1476 }
1477
1478 # Return 1 if this is an ARM target supporting -mfpu=neon
1479 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1480 # options.
1481
1482 proc check_effective_target_arm_neon_ok { } {
1483     if { [check_effective_target_arm32] } {
1484         return [check_no_compiler_messages arm_neon_ok object {
1485             int dummy;
1486         } "-mfpu=neon -mfloat-abi=softfp"]
1487     } else {
1488         return 0
1489     }
1490 }
1491
1492 # Return 1 if the target supports executing NEON instructions, 0
1493 # otherwise.  Cache the result.
1494
1495 proc check_effective_target_arm_neon_hw { } {
1496     global arm_neon_hw_available_saved
1497     global tool
1498
1499     if [info exists arm_neon_hw_available_saved] {
1500         verbose "check_arm_neon_hw_available  returning saved $arm_neon_hw_avail
1501 able_saved" 2
1502     } else {
1503         set arm_neon_hw_available_saved 0
1504
1505         # Set up, compile, and execute a test program containing NEON
1506         # instructions.  Include the current process ID in the file
1507         # names to prevent conflicts with invocations for multiple
1508         # testsuites.
1509         set src neon[pid].c
1510         set exe neon[pid].x
1511
1512         set f [open $src "w"]
1513         puts $f "int main() {"
1514         puts $f "  long long a = 0, b = 1;"
1515         puts $f "  asm (\"vorr %P0, %P1, %P2\""
1516         puts $f "       : \"=w\" (a)"
1517         puts $f "       : \"0\" (a), \"w\" (b));"
1518         puts $f "  return (a != 1);"
1519         puts $f "}"
1520         close $f
1521
1522         set opts "additional_flags=-mfpu=neon additional_flags=-mfloat-abi=softfp"
1523
1524         verbose "check_arm_neon_hw_available  compiling testfile $src" 2
1525         set lines [${tool}_target_compile $src $exe executable "$opts"]
1526         file delete $src
1527
1528         if [string match "" $lines] then {
1529             # No error message, compilation succeeded.
1530             set result [${tool}_load "./$exe" "" ""]
1531             set status [lindex $result 0]
1532             remote_file build delete $exe
1533             verbose "check_arm_neon_hw_available testfile status is <$status>" 2
1534
1535             if { $status == "pass" } then {
1536                 set arm_neon_hw_available_saved 1
1537             }
1538         } else {
1539             verbose "check_arm_neon_hw_available testfile compilation failed" 2
1540         }
1541     }
1542
1543     return $arm_neon_hw_available_saved
1544 }
1545
1546 # Return 1 if this is a PowerPC target with floating-point registers.
1547
1548 proc check_effective_target_powerpc_fprs { } {
1549     if { [istarget powerpc*-*-*]
1550          || [istarget rs6000-*-*] } {
1551         return [check_no_compiler_messages powerpc_fprs object {
1552             #ifdef __NO_FPRS__
1553             #error no FPRs
1554             #else
1555             int dummy;
1556             #endif
1557         }]
1558     } else {
1559         return 0
1560     }
1561 }
1562
1563 # Return 1 if this is a PowerPC target supporting -maltivec.
1564
1565 proc check_effective_target_powerpc_altivec_ok { } {
1566     if { [istarget powerpc*-*-*]
1567          || [istarget rs6000-*-*] } {
1568         # AltiVec is not supported on Aix.
1569         if { [istarget powerpc*-*-aix*] } {
1570             return 0
1571         }
1572         return [check_no_compiler_messages powerpc_altivec_ok object {
1573             int dummy;
1574         } "-maltivec"]
1575     } else {
1576         return 0
1577     }
1578 }
1579
1580 # Return 1 if this is a PowerPC target with SPE enabled.
1581
1582 proc check_effective_target_powerpc_spe { } {
1583     if { [istarget powerpc*-*-*] } {
1584         return [check_no_compiler_messages powerpc_spe object {
1585             #ifndef __SPE__
1586             #error not SPE
1587             #else
1588             int dummy;
1589             #endif
1590         }]
1591     } else {
1592         return 0
1593     }
1594 }
1595
1596 # Return 1 if this is a PowerPC target with Altivec enabled.
1597
1598 proc check_effective_target_powerpc_altivec { } {
1599     if { [istarget powerpc*-*-*] } {
1600         return [check_no_compiler_messages powerpc_altivec object {
1601             #ifndef __ALTIVEC__
1602             #error not Altivec
1603             #else
1604             int dummy;
1605             #endif
1606         }]
1607     } else {
1608         return 0
1609     }
1610 }
1611
1612 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
1613 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables.  Return 1 if the
1614 # test environment appears to run executables on such a simulator.
1615
1616 proc check_effective_target_ultrasparc_hw { } {
1617     global et_ultrasparc_hw_saved
1618     global tool
1619
1620     if [info exists et_ultrasparc_hw_saved] {
1621         verbose "check_ultrasparc_hw_available returning saved $et_ultrasparc_hw_saved" 2
1622     } else {
1623         set et_ultrasparc_hw_saved 0
1624
1625         # Set up, compile, and execute a simple test program.  The
1626         # program will be compiled with -mcpu=ultrasparc to instruct the
1627         # assembler to produce EM_SPARC32PLUS executables.
1628         set src svect[pid].c
1629         set exe svect[pid].x
1630
1631         set f [open $src "w"]
1632         puts $f "int main() { return 0; }"
1633         close $f
1634
1635         verbose "check_ultrasparc_hw_available compiling testfile $src" 2
1636         set lines [${tool}_target_compile $src $exe executable "additional_flags=-mcpu=ultrasparc"]
1637         file delete $src
1638
1639         if [string match "" $lines] then {
1640             # No error message, compilation succeeded.
1641             set result [${tool}_load "./$exe" "" ""]
1642             set status [lindex $result 0]
1643             remote_file build delete $exe
1644             verbose "check_ultrasparc_hw_available testfile status is <$status>" 2
1645
1646             if { $status == "pass" } then {
1647                 set et_ultrasparc_hw_saved 1
1648             }
1649         } else {
1650             verbose "check_ultrasparc_hw_available testfile compilation failed" 2
1651         }
1652     }
1653
1654     return $et_ultrasparc_hw_saved
1655 }
1656
1657 # Return 1 if the target supports hardware vector shift operation.
1658
1659 proc check_effective_target_vect_shift { } {
1660     global et_vect_shift_saved
1661
1662     if [info exists et_vect_shift_saved] {
1663         verbose "check_effective_target_vect_shift: using cached result" 2
1664     } else {
1665         set et_vect_shift_saved 0
1666         if { [istarget powerpc*-*-*]
1667              || [istarget ia64-*-*]
1668              || [istarget i?86-*-*]
1669              || [istarget x86_64-*-*] } {
1670            set et_vect_shift_saved 1
1671         }
1672     }
1673
1674     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1675     return $et_vect_shift_saved
1676 }
1677
1678 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1679 #
1680 # This can change for different subtargets so do not cache the result.
1681
1682 proc check_effective_target_vect_long { } {
1683     if { [istarget i?86-*-*]
1684          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1685          || [istarget x86_64-*-*]
1686          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1687         set answer 1
1688     } else {
1689         set answer 0
1690     }
1691
1692     verbose "check_effective_target_vect_long: returning $answer" 2
1693     return $answer
1694 }
1695
1696 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1697 #
1698 # This won't change for different subtargets so cache the result.
1699
1700 proc check_effective_target_vect_float { } {
1701     global et_vect_float_saved
1702
1703     if [info exists et_vect_float_saved] {
1704         verbose "check_effective_target_vect_float: using cached result" 2
1705     } else {
1706         set et_vect_float_saved 0
1707         if { [istarget i?86-*-*]
1708               || [istarget powerpc*-*-*]
1709               || [istarget spu-*-*]
1710               || [istarget mipsisa64*-*-*]
1711               || [istarget x86_64-*-*]
1712               || [istarget ia64-*-*] } {
1713            set et_vect_float_saved 1
1714         }
1715     }
1716
1717     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1718     return $et_vect_float_saved
1719 }
1720
1721 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1722 #
1723 # This won't change for different subtargets so cache the result.
1724
1725 proc check_effective_target_vect_double { } {
1726     global et_vect_double_saved
1727
1728     if [info exists et_vect_double_saved] {
1729         verbose "check_effective_target_vect_double: using cached result" 2
1730     } else {
1731         set et_vect_double_saved 0
1732         if { [istarget i?86-*-*]
1733               || [istarget x86_64-*-*] 
1734               || [istarget spu-*-*] } {
1735            set et_vect_double_saved 1
1736         }
1737     }
1738
1739     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1740     return $et_vect_double_saved
1741 }
1742
1743 # Return 1 if the target plus current options does not support a vector
1744 # max instruction on "int", 0 otherwise.
1745 #
1746 # This won't change for different subtargets so cache the result.
1747
1748 proc check_effective_target_vect_no_int_max { } {
1749     global et_vect_no_int_max_saved
1750
1751     if [info exists et_vect_no_int_max_saved] {
1752         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1753     } else {
1754         set et_vect_no_int_max_saved 0
1755         if { [istarget sparc*-*-*]
1756              || [istarget spu-*-*]
1757              || [istarget alpha*-*-*] } {
1758             set et_vect_no_int_max_saved 1
1759         }
1760     }
1761     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1762     return $et_vect_no_int_max_saved
1763 }
1764
1765 # Return 1 if the target plus current options does not support a vector
1766 # add instruction on "int", 0 otherwise.
1767 #
1768 # This won't change for different subtargets so cache the result.
1769
1770 proc check_effective_target_vect_no_int_add { } {
1771     global et_vect_no_int_add_saved
1772
1773     if [info exists et_vect_no_int_add_saved] {
1774         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1775     } else {
1776         set et_vect_no_int_add_saved 0
1777         # Alpha only supports vector add on V8QI and V4HI.
1778         if { [istarget alpha*-*-*] } {
1779             set et_vect_no_int_add_saved 1
1780         }
1781     }
1782     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1783     return $et_vect_no_int_add_saved
1784 }
1785
1786 # Return 1 if the target plus current options does not support vector
1787 # bitwise instructions, 0 otherwise.
1788 #
1789 # This won't change for different subtargets so cache the result.
1790
1791 proc check_effective_target_vect_no_bitwise { } {
1792     global et_vect_no_bitwise_saved
1793
1794     if [info exists et_vect_no_bitwise_saved] {
1795         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1796     } else {
1797         set et_vect_no_bitwise_saved 0
1798     }
1799     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1800     return $et_vect_no_bitwise_saved
1801 }
1802
1803 # Return 1 if the target plus current options supports a vector
1804 # widening summation of *short* args into *int* result, 0 otherwise.
1805 # A target can also support this widening summation if it can support
1806 # promotion (unpacking) from shorts to ints.
1807 #
1808 # This won't change for different subtargets so cache the result.
1809                                                                                                 
1810 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1811     global et_vect_widen_sum_hi_to_si
1812
1813     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1814         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1815     } else {
1816         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1817         if { [istarget powerpc*-*-*] 
1818              || [istarget ia64-*-*] } {
1819             set et_vect_widen_sum_hi_to_si_saved 1
1820         }
1821     }
1822     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1823     return $et_vect_widen_sum_hi_to_si_saved
1824 }
1825
1826 # Return 1 if the target plus current options supports a vector
1827 # widening summation of *char* args into *short* result, 0 otherwise.
1828 # A target can also support this widening summation if it can support
1829 # promotion (unpacking) from chars to shorts.
1830 #
1831 # This won't change for different subtargets so cache the result.
1832                                                                                                 
1833 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1834     global et_vect_widen_sum_qi_to_hi
1835
1836     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1837         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1838     } else {
1839         set et_vect_widen_sum_qi_to_hi_saved 0
1840         if { [check_effective_target_vect_unpack] 
1841              || [istarget ia64-*-*] } {
1842             set et_vect_widen_sum_qi_to_hi_saved 1
1843         }
1844     }
1845     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1846     return $et_vect_widen_sum_qi_to_hi_saved
1847 }
1848
1849 # Return 1 if the target plus current options supports a vector
1850 # widening summation of *char* args into *int* result, 0 otherwise.
1851 #
1852 # This won't change for different subtargets so cache the result.
1853                                                                                                 
1854 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1855     global et_vect_widen_sum_qi_to_si
1856
1857     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1858         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1859     } else {
1860         set et_vect_widen_sum_qi_to_si_saved 0
1861         if { [istarget powerpc*-*-*] } {
1862             set et_vect_widen_sum_qi_to_si_saved 1
1863         }
1864     }
1865     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1866     return $et_vect_widen_sum_qi_to_si_saved
1867 }
1868
1869 # Return 1 if the target plus current options supports a vector
1870 # widening multiplication of *char* args into *short* result, 0 otherwise.
1871 # A target can also support this widening multplication if it can support
1872 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1873 # multiplication of shorts).
1874 #
1875 # This won't change for different subtargets so cache the result.
1876
1877
1878 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1879     global et_vect_widen_mult_qi_to_hi
1880
1881     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1882         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
1883     } else {
1884         if { [check_effective_target_vect_unpack]
1885              && [check_effective_target_vect_short_mult] } {
1886             set et_vect_widen_mult_qi_to_hi_saved 1
1887         } else {
1888             set et_vect_widen_mult_qi_to_hi_saved 0
1889         }
1890         if { [istarget powerpc*-*-*] } {
1891             set et_vect_widen_mult_qi_to_hi_saved 1
1892         }
1893     }
1894     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1895     return $et_vect_widen_mult_qi_to_hi_saved
1896 }
1897
1898 # Return 1 if the target plus current options supports a vector
1899 # widening multiplication of *short* args into *int* result, 0 otherwise.
1900 # A target can also support this widening multplication if it can support
1901 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1902 # multiplication of ints).
1903 #
1904 # This won't change for different subtargets so cache the result.
1905
1906
1907 proc check_effective_target_vect_widen_mult_hi_to_si { } {
1908     global et_vect_widen_mult_hi_to_si
1909
1910     if [info exists et_vect_widen_mult_hi_to_si_saved] {
1911         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1912     } else {
1913         if { [check_effective_target_vect_unpack]
1914              && [check_effective_target_vect_int_mult] } {
1915           set et_vect_widen_mult_hi_to_si_saved 1
1916         } else {
1917           set et_vect_widen_mult_hi_to_si_saved 0
1918         }
1919         if { [istarget powerpc*-*-*]
1920               || [istarget spu-*-*]
1921               || [istarget i?86-*-*]
1922               || [istarget x86_64-*-*] } {
1923             set et_vect_widen_mult_hi_to_si_saved 1
1924         }
1925     }
1926     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1927     return $et_vect_widen_mult_hi_to_si_saved
1928 }
1929
1930 # Return 1 if the target plus current options supports a vector
1931 # dot-product of signed chars, 0 otherwise.
1932 #
1933 # This won't change for different subtargets so cache the result.
1934
1935 proc check_effective_target_vect_sdot_qi { } {
1936     global et_vect_sdot_qi
1937
1938     if [info exists et_vect_sdot_qi_saved] {
1939         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1940     } else {
1941         set et_vect_sdot_qi_saved 0
1942     }
1943     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1944     return $et_vect_sdot_qi_saved
1945 }
1946
1947 # Return 1 if the target plus current options supports a vector
1948 # dot-product of unsigned chars, 0 otherwise.
1949 #
1950 # This won't change for different subtargets so cache the result.
1951
1952 proc check_effective_target_vect_udot_qi { } {
1953     global et_vect_udot_qi
1954
1955     if [info exists et_vect_udot_qi_saved] {
1956         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1957     } else {
1958         set et_vect_udot_qi_saved 0
1959         if { [istarget powerpc*-*-*] } {
1960             set et_vect_udot_qi_saved 1
1961         }
1962     }
1963     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1964     return $et_vect_udot_qi_saved
1965 }
1966
1967 # Return 1 if the target plus current options supports a vector
1968 # dot-product of signed shorts, 0 otherwise.
1969 #
1970 # This won't change for different subtargets so cache the result.
1971
1972 proc check_effective_target_vect_sdot_hi { } {
1973     global et_vect_sdot_hi
1974
1975     if [info exists et_vect_sdot_hi_saved] {
1976         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1977     } else {
1978         set et_vect_sdot_hi_saved 0
1979         if { [istarget powerpc*-*-*] 
1980              || [istarget i?86-*-*]
1981              || [istarget x86_64-*-*] } {
1982             set et_vect_sdot_hi_saved 1
1983         }
1984     }
1985     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1986     return $et_vect_sdot_hi_saved
1987 }
1988
1989 # Return 1 if the target plus current options supports a vector
1990 # dot-product of unsigned shorts, 0 otherwise.
1991 #
1992 # This won't change for different subtargets so cache the result.
1993
1994 proc check_effective_target_vect_udot_hi { } {
1995     global et_vect_udot_hi
1996
1997     if [info exists et_vect_udot_hi_saved] {
1998         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1999     } else {
2000         set et_vect_udot_hi_saved 0
2001         if { [istarget powerpc*-*-*] } {
2002             set et_vect_udot_hi_saved 1
2003         }
2004     }
2005     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
2006     return $et_vect_udot_hi_saved
2007 }
2008
2009
2010 # Return 1 if the target plus current options supports a vector
2011 # demotion (packing) of shorts (to chars) and ints (to shorts) 
2012 # using modulo arithmetic, 0 otherwise.
2013 #
2014 # This won't change for different subtargets so cache the result.
2015                                                                                 
2016 proc check_effective_target_vect_pack_trunc { } {
2017     global et_vect_pack_trunc
2018                                                                                 
2019     if [info exists et_vect_pack_trunc_saved] {
2020         verbose "check_effective_target_vect_pack_trunc: using cached result" 2
2021     } else {
2022         set et_vect_pack_trunc_saved 0
2023         if { [istarget powerpc*-*-*]
2024              || [istarget i?86-*-*]
2025              || [istarget x86_64-*-*] } {
2026             set et_vect_pack_trunc_saved 1
2027         }
2028     }
2029     verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
2030     return $et_vect_pack_trunc_saved
2031 }
2032
2033 # Return 1 if the target plus current options supports a vector
2034 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
2035 #
2036 # This won't change for different subtargets so cache the result.
2037                                    
2038 proc check_effective_target_vect_unpack { } {
2039     global et_vect_unpack
2040                                         
2041     if [info exists et_vect_unpack_saved] {
2042         verbose "check_effective_target_vect_unpack: using cached result" 2
2043     } else {
2044         set et_vect_unpack_saved 0
2045         if { [istarget powerpc*-*-*]
2046              || [istarget i?86-*-*]
2047              || [istarget x86_64-*-*] } {
2048             set et_vect_unpack_saved 1
2049         }
2050     }
2051     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
2052     return $et_vect_unpack_saved
2053 }
2054
2055 # Return 1 if the target plus current options does not support a vector
2056 # alignment mechanism, 0 otherwise.
2057 #
2058 # This won't change for different subtargets so cache the result.
2059
2060 proc check_effective_target_vect_no_align { } {
2061     global et_vect_no_align_saved
2062
2063     if [info exists et_vect_no_align_saved] {
2064         verbose "check_effective_target_vect_no_align: using cached result" 2
2065     } else {
2066         set et_vect_no_align_saved 0
2067         if { [istarget mipsisa64*-*-*]
2068              || [istarget sparc*-*-*]
2069              || [istarget ia64-*-*] } { 
2070             set et_vect_no_align_saved 1
2071         }
2072     }
2073     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
2074     return $et_vect_no_align_saved
2075 }
2076
2077 # Return 1 if arrays are aligned to the vector alignment
2078 # boundary, 0 otherwise.
2079 #
2080 # This won't change for different subtargets so cache the result.
2081
2082 proc check_effective_target_vect_aligned_arrays { } {
2083     global et_vect_aligned_arrays
2084
2085     if [info exists et_vect_aligned_arrays_saved] {
2086         verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
2087     } else {
2088         set et_vect_aligned_arrays_saved 0
2089         if { ([istarget x86_64-*-*]
2090               || [istarget i?86-*-*]) && [is-effective-target lp64] } {
2091             set et_vect_aligned_arrays_saved 1
2092         }
2093     }
2094     verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
2095     return $et_vect_aligned_arrays_saved
2096 }
2097
2098 # Return 1 if types are naturally aligned (aligned to their type-size),
2099 # 0 otherwise.
2100 #
2101 # This won't change for different subtargets so cache the result.
2102
2103 proc check_effective_target_natural_alignment { } {
2104     global et_natural_alignment
2105
2106     if [info exists et_natural_alignment_saved] {
2107         verbose "check_effective_target_natural_alignment: using cached result" 2
2108     } else {
2109         # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
2110         set et_natural_alignment_saved 1
2111         if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } { 
2112             set et_natural_alignment_saved 0
2113         }
2114     }
2115     verbose "check_effective_target_natural_alignment: returning $et_natural_alignment_saved" 2
2116     return $et_natural_alignment_saved
2117 }
2118
2119 # Return 1 if vector alignment is reachable, 0 otherwise.
2120 #
2121 # This won't change for different subtargets so cache the result.
2122
2123 proc check_effective_target_vector_alignment_reachable { } {
2124     global et_vector_alignment_reachable
2125
2126     if [info exists et_vector_alignment_reachable_saved] {
2127         verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
2128     } else {
2129         if { [check_effective_target_vect_aligned_arrays]
2130              || [check_effective_target_natural_alignment] } {
2131             set et_vector_alignment_reachable_saved 1
2132         } else {
2133             set et_vector_alignment_reachable_saved 0
2134         }
2135     }
2136     verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
2137     return $et_vector_alignment_reachable_saved
2138 }
2139
2140 # Return 1 if vector alignment for soubles  is reachable, 0 otherwise.
2141 #
2142 # This won't change for different subtargets so cache the result.
2143
2144 proc check_effective_target_vector_alignment_reachable_for_double { } {
2145     global et_vector_alignment_reachable_for_double
2146
2147     if [info exists et_vector_alignment_reachable_for_double_saved] {
2148         verbose "check_effective_target_vector_alignment_reachable_for_double: using cached result" 2
2149     } else {
2150         if { [check_effective_target_vect_aligned_arrays] } {
2151             set et_vector_alignment_reachable_for_double_saved 1
2152         } else {
2153             set et_vector_alignment_reachable_for_double_saved 0
2154         }
2155     }
2156     verbose "check_effective_target_vector_alignment_reachable_for_double: returning $et_vector_alignment_reachable_for_double_saved" 2
2157     return $et_vector_alignment_reachable_for_double_saved
2158 }
2159
2160 # Return 1 if the target supports vector conditional operations, 0 otherwise.
2161
2162 proc check_effective_target_vect_condition { } {
2163     global et_vect_cond_saved
2164
2165     if [info exists et_vect_cond_saved] {
2166         verbose "check_effective_target_vect_cond: using cached result" 2
2167     } else {
2168         set et_vect_cond_saved 0
2169         if { [istarget powerpc*-*-*]
2170              || [istarget ia64-*-*]
2171              || [istarget i?86-*-*]
2172              || [istarget spu-*-*]
2173              || [istarget x86_64-*-*] } {
2174            set et_vect_cond_saved 1
2175         }
2176     }
2177
2178     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
2179     return $et_vect_cond_saved
2180 }
2181
2182 # Return 1 if the target supports vector char multiplication, 0 otherwise.
2183
2184 proc check_effective_target_vect_char_mult { } {
2185     global et_vect_char_mult_saved
2186
2187     if [info exists et_vect_char_mult_saved] {
2188         verbose "check_effective_target_vect_char_mult: using cached result" 2
2189     } else {
2190         set et_vect_char_mult_saved 0
2191         if { [istarget ia64-*-*]
2192              || [istarget i?86-*-*]
2193              || [istarget x86_64-*-*] } {
2194            set et_vect_char_mult_saved 1
2195         }
2196     }
2197
2198     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
2199     return $et_vect_char_mult_saved
2200 }
2201
2202 # Return 1 if the target supports vector short multiplication, 0 otherwise.
2203
2204 proc check_effective_target_vect_short_mult { } {
2205     global et_vect_short_mult_saved
2206
2207     if [info exists et_vect_short_mult_saved] {
2208         verbose "check_effective_target_vect_short_mult: using cached result" 2
2209     } else {
2210         set et_vect_short_mult_saved 0
2211         if { [istarget ia64-*-*]
2212              || [istarget i?86-*-*]
2213              || [istarget x86_64-*-*] } {
2214            set et_vect_short_mult_saved 1
2215         }
2216     }
2217
2218     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
2219     return $et_vect_short_mult_saved
2220 }
2221
2222 # Return 1 if the target supports vector int multiplication, 0 otherwise.
2223
2224 proc check_effective_target_vect_int_mult { } {
2225     global et_vect_int_mult_saved
2226
2227     if [info exists et_vect_int_mult_saved] {
2228         verbose "check_effective_target_vect_int_mult: using cached result" 2
2229     } else {
2230         set et_vect_int_mult_saved 0
2231         if { [istarget powerpc*-*-*]
2232              || [istarget spu-*-*]
2233              || [istarget i?86-*-*]
2234              || [istarget x86_64-*-*] } {
2235            set et_vect_int_mult_saved 1
2236         }
2237     }
2238
2239     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
2240     return $et_vect_int_mult_saved
2241 }
2242
2243 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
2244
2245 proc check_effective_target_vect_extract_even_odd { } {
2246     global et_vect_extract_even_odd_saved
2247     
2248     if [info exists et_vect_extract_even_odd_saved] {
2249         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
2250     } else {
2251         set et_vect_extract_even_odd_saved 0 
2252         if { [istarget powerpc*-*-*] } {
2253            set et_vect_extract_even_odd_saved 1
2254         }
2255     }
2256
2257     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
2258     return $et_vect_extract_even_odd_saved
2259 }
2260
2261 # Return 1 if the target supports vector interleaving, 0 otherwise.
2262
2263 proc check_effective_target_vect_interleave { } {
2264     global et_vect_interleave_saved
2265     
2266     if [info exists et_vect_interleave_saved] {
2267         verbose "check_effective_target_vect_interleave: using cached result" 2
2268     } else {
2269         set et_vect_interleave_saved 0
2270         if { [istarget powerpc*-*-*]
2271              || [istarget i?86-*-*]
2272              || [istarget x86_64-*-*] } {
2273            set et_vect_interleave_saved 1
2274         }
2275     }
2276
2277     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
2278     return $et_vect_interleave_saved
2279 }
2280
2281 # Return 1 if the target supports vector interleaving and extract even/odd, 0 otherwise.
2282 proc check_effective_target_vect_strided { } {
2283     global et_vect_strided_saved
2284
2285     if [info exists et_vect_strided_saved] {
2286         verbose "check_effective_target_vect_strided: using cached result" 2
2287     } else {
2288         set et_vect_strided_saved 0
2289         if { [check_effective_target_vect_interleave]
2290              && [check_effective_target_vect_extract_even_odd] } {
2291            set et_vect_strided_saved 1
2292         }
2293     }
2294
2295     verbose "check_effective_target_vect_strided: returning $et_vect_strided_saved" 2
2296     return $et_vect_strided_saved
2297 }
2298
2299 # Return 1 if the target supports section-anchors
2300
2301 proc check_effective_target_section_anchors { } {
2302     global et_section_anchors_saved
2303
2304     if [info exists et_section_anchors_saved] {
2305         verbose "check_effective_target_section_anchors: using cached result" 2
2306     } else {
2307         set et_section_anchors_saved 0
2308         if { [istarget powerpc*-*-*] } {
2309            set et_section_anchors_saved 1
2310         }
2311     }
2312
2313     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
2314     return $et_section_anchors_saved
2315 }
2316
2317 # Return 1 if the target supports atomic operations on "int" and "long".
2318
2319 proc check_effective_target_sync_int_long { } {
2320     global et_sync_int_long_saved
2321
2322     if [info exists et_sync_int_long_saved] {
2323         verbose "check_effective_target_sync_int_long: using cached result" 2
2324     } else {
2325         set et_sync_int_long_saved 0
2326 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2327 # load-reserved/store-conditional instructions.
2328         if { [istarget ia64-*-*]
2329              || [istarget i?86-*-*]
2330              || [istarget x86_64-*-*]
2331              || [istarget alpha*-*-*] 
2332              || [istarget s390*-*-*] 
2333              || [istarget powerpc*-*-*]
2334              || [istarget sparc64-*-*]
2335              || [istarget sparcv9-*-*] } {
2336            set et_sync_int_long_saved 1
2337         }
2338     }
2339
2340     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2341     return $et_sync_int_long_saved
2342 }
2343
2344 # Return 1 if the target supports atomic operations on "char" and "short".
2345
2346 proc check_effective_target_sync_char_short { } {
2347     global et_sync_char_short_saved
2348
2349     if [info exists et_sync_char_short_saved] {
2350         verbose "check_effective_target_sync_char_short: using cached result" 2
2351     } else {
2352         set et_sync_char_short_saved 0
2353 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2354 # load-reserved/store-conditional instructions.
2355         if { [istarget ia64-*-*]
2356              || [istarget i?86-*-*]
2357              || [istarget x86_64-*-*]
2358              || [istarget alpha*-*-*] 
2359              || [istarget s390*-*-*] 
2360              || [istarget powerpc*-*-*]
2361              || [istarget sparc64-*-*]
2362              || [istarget sparcv9-*-*] } {
2363            set et_sync_char_short_saved 1
2364         }
2365     }
2366
2367     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2368     return $et_sync_char_short_saved
2369 }
2370
2371 # Return 1 if the target uses a ColdFire FPU.
2372
2373 proc check_effective_target_coldfire_fpu { } {
2374     return [check_no_compiler_messages coldfire_fpu assembly {
2375         #ifndef __mcffpu__
2376         #error FOO
2377         #endif
2378     }]
2379 }
2380
2381 # Return true if this is a uClibc target.
2382
2383 proc check_effective_target_uclibc {} {
2384     return [check_no_compiler_messages uclibc object {
2385         #include <features.h>
2386         #if !defined (__UCLIBC__)
2387         #error FOO
2388         #endif
2389     }]
2390 }
2391
2392 # Return true if this is a uclibc target and if the uclibc feature
2393 # described by __$feature__ is not present.
2394
2395 proc check_missing_uclibc_feature {feature} {
2396     return [check_no_compiler_messages $feature object "
2397         #include <features.h>
2398         #if !defined (__UCLIBC) || defined (__${feature}__)
2399         #error FOO
2400         #endif
2401     "]
2402 }
2403
2404 # Return true if this is a Newlib target.
2405
2406 proc check_effective_target_newlib {} {
2407     return [check_no_compiler_messages newlib object {
2408         #include <newlib.h>
2409     }]
2410 }
2411
2412 # Return 1 if
2413 #   (a) an error of a few ULP is expected in string to floating-point
2414 #       conversion functions; and
2415 #   (b) overflow is not always detected correctly by those functions.
2416
2417 proc check_effective_target_lax_strtofp {} {
2418     # By default, assume that all uClibc targets suffer from this.
2419     return [check_effective_target_uclibc]
2420 }
2421
2422 # Return 1 if this is a target for which wcsftime is a dummy
2423 # function that always returns 0.
2424
2425 proc check_effective_target_dummy_wcsftime {} {
2426     # By default, assume that all uClibc targets suffer from this.
2427     return [check_effective_target_uclibc]
2428 }
2429
2430 # Return 1 if constructors with initialization priority arguments are
2431 # supposed on this target.
2432
2433 proc check_effective_target_init_priority {} {
2434     return [check_no_compiler_messages init_priority assembly "
2435         void f() __attribute__((constructor (1000)));
2436         void f() \{\}
2437     "]
2438 }
2439
2440 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2441 # This can be used with any check_* proc that takes no argument and
2442 # returns only 1 or 0.  It could be used with check_* procs that take
2443 # arguments with keywords that pass particular arguments.
2444
2445 proc is-effective-target { arg } {
2446     set selected 0
2447     if { [info procs check_effective_target_${arg}] != [list] } {
2448         set selected [check_effective_target_${arg}]
2449     } else {
2450         switch $arg {
2451           "vmx_hw"         { set selected [check_vmx_hw_available] }
2452           "named_sections" { set selected [check_named_sections_available] }
2453           "gc_sections"    { set selected [check_gc_sections_available] }
2454           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
2455           default          { error "unknown effective target keyword `$arg'" }
2456         }
2457     }
2458     verbose "is-effective-target: $arg $selected" 2
2459     return $selected
2460 }
2461
2462 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2463
2464 proc is-effective-target-keyword { arg } {
2465     if { [info procs check_effective_target_${arg}] != [list] } {
2466         return 1
2467     } else {
2468         # These have different names for their check_* procs.
2469         switch $arg {
2470           "vmx_hw"         { return 1 }
2471           "named_sections" { return 1 }
2472           "gc_sections"    { return 1 }
2473           "cxa_atexit"     { return 1 }
2474           default          { return 0 }
2475         }
2476     }
2477 }
2478
2479 # Return 1 if target default to short enums
2480
2481 proc check_effective_target_short_enums { } {
2482     return [check_no_compiler_messages short_enums assembly {
2483         enum foo { bar };
2484         int s[sizeof (enum foo) == 1 ? 1 : -1];
2485     }]
2486 }
2487
2488 # Return 1 if target supports merging string constants at link time.
2489
2490 proc check_effective_target_string_merging { } {
2491     return [check_no_messages_and_pattern string_merging \
2492                 "rodata\\.str" assembly {
2493                     const char *var = "String";
2494                 } {-O2}]
2495 }
2496
2497 # Return 1 if target has the basic signed and unsigned types in
2498 # <stdint.h>, 0 otherwise.
2499
2500 proc check_effective_target_stdint_types { } {
2501     return [check_no_compiler_messages stdint_types assembly {
2502         #include <stdint.h>
2503         int8_t a; int16_t b; int32_t c; int64_t d;
2504         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2505     }]
2506 }
2507
2508 # Return 1 if programs are intended to be run on a simulator
2509 # (i.e. slowly) rather than hardware (i.e. fast).
2510
2511 proc check_effective_target_simulator { } {
2512
2513     # All "src/sim" simulators set this one.
2514     if [board_info target exists is_simulator] {
2515         return [board_info target is_simulator]
2516     }
2517
2518     # The "sid" simulators don't set that one, but at least they set
2519     # this one.
2520     if [board_info target exists slow_simulator] {
2521         return [board_info target slow_simulator]
2522     }
2523
2524     return 0
2525 }
2526
2527 # Return 1 if the target is a VxWorks RTP.
2528
2529 proc check_effective_target_vxworks_kernel { } {
2530     return [check_no_compiler_messages vxworks_kernel assembly {
2531         #if !defined __vxworks || defined __RTP__
2532         #error NO
2533         #endif
2534     }]
2535 }
2536
2537 # Return 1 if the target is expected to provide wide character support.
2538
2539 proc check_effective_target_wchar { } {
2540     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2541         return 0
2542     }
2543     return [check_no_compiler_messages wchar assembly {
2544         #include <wchar.h>
2545     }]
2546 }