OSDN Git Service

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