OSDN Git Service

* lib/target-supports.exp
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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_weak_override_available { }
255 ###############################
256
257 # Like check_weak_available, but return 0 if weak symbol definitions
258 # cannot be overridden.
259
260 proc check_weak_override_available { } {
261     if { [istarget "*-*-mingw*"] } {
262         return 0
263     }
264     return [check_weak_available]
265 }
266
267 ###############################
268 # proc check_visibility_available { what_kind }
269 ###############################
270
271 # The visibility attribute is only support in some object formats
272 # This proc returns 1 if it is supported, 0 if not.
273 # The argument is the kind of visibility, default/protected/hidden/internal.
274
275 proc check_visibility_available { what_kind } {
276     global tool
277     global target_triplet
278
279     # On NetWare, support makes no sense.
280     if { [istarget *-*-netware*] } {
281         return 0
282     }
283
284     if [string match "" $what_kind] { set what_kind "hidden" }
285
286     return [check_no_compiler_messages visibility_available_$what_kind object "
287         void f() __attribute__((visibility(\"$what_kind\")));
288         void f() {}
289     "]
290 }
291
292 ###############################
293 # proc check_alias_available { }
294 ###############################
295
296 # Determine if the target toolchain supports the alias attribute.
297
298 # Returns 2 if the target supports aliases.  Returns 1 if the target
299 # only supports weak aliased.  Returns 0 if the target does not
300 # support aliases at all.  Returns -1 if support for aliases could not
301 # be determined.
302
303 proc check_alias_available { } {
304     global alias_available_saved
305     global tool
306
307     if [info exists alias_available_saved] {
308         verbose "check_alias_available  returning saved $alias_available_saved" 2
309     } else {
310         set src alias[pid].c
311         set obj alias[pid].o
312         verbose "check_alias_available  compiling testfile $src" 2
313         set f [open $src "w"]
314         # Compile a small test program.  The definition of "g" is
315         # necessary to keep the Solaris assembler from complaining
316         # about the program.
317         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
318         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
319         close $f
320         set lines [${tool}_target_compile $src $obj object ""]
321         file delete $src
322         remote_file build delete $obj
323
324         if [string match "" $lines] then {
325             # No error messages, everything is OK.
326             set alias_available_saved 2
327         } else {
328             if [regexp "alias definitions not supported" $lines] {
329                 verbose "check_alias_available  target does not support aliases" 2
330
331                 set objformat [gcc_target_object_format]
332
333                 if { $objformat == "elf" } {
334                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
335                     set alias_available_saved -1
336                 } else {
337                     set alias_available_saved 0
338                 }
339             } else {
340                 if [regexp "only weak aliases are supported" $lines] {
341                 verbose "check_alias_available  target supports only weak aliases" 2
342                 set alias_available_saved 1
343                 } else {
344                     set alias_available_saved -1
345                 }
346             }
347         }
348
349         verbose "check_alias_available  returning $alias_available_saved" 2
350     }
351
352     return $alias_available_saved
353 }
354
355 # Returns true if --gc-sections is supported on the target.
356
357 proc check_gc_sections_available { } {
358     global gc_sections_available_saved
359     global tool
360
361     if {![info exists gc_sections_available_saved]} {
362         # Some targets don't support gc-sections despite whatever's
363         # advertised by ld's options.
364         if { [istarget alpha*-*-*]
365              || [istarget ia64-*-*] } {
366             set gc_sections_available_saved 0
367             return 0
368         }
369
370         # elf2flt uses -q (--emit-relocs), which is incompatible with
371         # --gc-sections.
372         if { [board_info target exists ldflags]
373              && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
374             set gc_sections_available_saved 0
375             return 0
376         }
377
378         # VxWorks kernel modules are relocatable objects linked with -r,
379         # while RTP executables are linked with -q (--emit-relocs).
380         # Both of these options are incompatible with --gc-sections.
381         if { [istarget *-*-vxworks*] } {
382             set gc_sections_available_saved 0
383             return 0
384         }
385
386         # Check if the ld used by gcc supports --gc-sections.
387         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
388         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
389         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
390         set ld_output [remote_exec host "$gcc_ld" "--help"]
391         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
392             set gc_sections_available_saved 1
393         } else {
394             set gc_sections_available_saved 0
395         }
396     }
397     return $gc_sections_available_saved
398 }
399
400 # Return 1 if according to target_info struct and explicit target list
401 # target is supposed to support trampolines.
402  
403 proc check_effective_target_trampolines { } {
404     if [target_info exists no_trampolines] {
405       return 0
406     }
407     if { [istarget avr-*-*]
408          || [istarget hppa2.0w-hp-hpux11.23]
409         || [istarget hppa64-hp-hpux11.23] } {
410         return 0;   
411     }
412     return 1
413 }
414
415 # Return 1 if according to target_info struct and explicit target list
416 # target is supposed to keep null pointer checks. This could be due to 
417 # use of option fno-delete-null-pointer-checks or hardwired in target.
418  
419 proc check_effective_target_keeps_null_pointer_checks { } {
420     if [target_info exists keeps_null_pointer_checks] {
421       return 1
422     }
423     if { [istarget avr-*-*] } {
424         return 1;   
425     }
426     return 0
427 }
428
429 # Return true if profiling is supported on the target.
430
431 proc check_profiling_available { test_what } {
432     global profiling_available_saved
433
434     verbose "Profiling argument is <$test_what>" 1
435
436     # These conditions depend on the argument so examine them before
437     # looking at the cache variable.
438
439     # Support for -p on solaris2 relies on mcrt1.o which comes with the
440     # vendor compiler.  We cannot reliably predict the directory where the
441     # vendor compiler (and thus mcrt1.o) is installed so we can't
442     # necessarily find mcrt1.o even if we have it.
443     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
444         return 0
445     }
446
447     # Support for -p on irix relies on libprof1.a which doesn't appear to
448     # exist on any irix6 system currently posting testsuite results.
449     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
450     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
451     if { [istarget mips*-*-irix*]
452     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
453         return 0
454     }
455
456     # We don't yet support profiling for MIPS16.
457     if { [istarget mips*-*-*]
458          && ![check_effective_target_nomips16]
459          && ([lindex $test_what 1] == "-p"
460              || [lindex $test_what 1] == "-pg") } {
461         return 0
462     }
463
464     # MinGW does not support -p.
465     if { [istarget *-*-mingw*] && [lindex $test_what 1] == "-p" } {
466         return 0
467     }
468
469     # cygwin does not support -p.
470     if { [istarget *-*-cygwin*] && [lindex $test_what 1] == "-p" } {
471         return 0
472     }
473
474     # uClibc does not have gcrt1.o.
475     if { [check_effective_target_uclibc]
476          && ([lindex $test_what 1] == "-p"
477              || [lindex $test_what 1] == "-pg") } {
478         return 0
479     }
480
481     # Now examine the cache variable.
482     if {![info exists profiling_available_saved]} {
483         # Some targets don't have any implementation of __bb_init_func or are
484         # missing other needed machinery.
485         if { [istarget mmix-*-*]
486              || [istarget arm*-*-eabi*]
487              || [istarget picochip-*-*]
488              || [istarget *-*-netware*]
489              || [istarget arm*-*-elf]
490              || [istarget arm*-*-symbianelf*]
491              || [istarget avr-*-*]
492              || [istarget bfin-*-*]
493              || [istarget powerpc-*-eabi*]
494              || [istarget cris-*-*]
495              || [istarget crisv32-*-*]
496              || [istarget fido-*-elf]
497              || [istarget h8300-*-*]
498              || [istarget m32c-*-elf]
499              || [istarget m68k-*-elf]
500              || [istarget m68k-*-uclinux*]
501              || [istarget mep-*-elf]
502              || [istarget mips*-*-elf*]
503              || [istarget moxie-*-elf*]
504              || [istarget xstormy16-*]
505              || [istarget xtensa*-*-elf]
506              || [istarget *-*-rtems*]
507              || [istarget *-*-vxworks*] } {
508             set profiling_available_saved 0
509         } else {
510             set profiling_available_saved 1
511         }
512     }
513
514     return $profiling_available_saved
515 }
516
517 # Check to see if a target is "freestanding". This is as per the definition
518 # in Section 4 of C99 standard. Effectively, it is a target which supports no
519 # extra headers or libraries other than what is considered essential.
520 proc check_effective_target_freestanding { } {
521     if { [istarget picochip-*-*] } then {
522         return 1
523     } else {
524         return 0
525     }
526 }
527
528 # Return 1 if target has packed layout of structure members by
529 # default, 0 otherwise.  Note that this is slightly different than
530 # whether the target has "natural alignment": both attributes may be
531 # false.
532
533 proc check_effective_target_default_packed { } {
534     return [check_no_compiler_messages default_packed assembly {
535         struct x { char a; long b; } c;
536         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
537     }]
538 }
539
540 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
541 # documentation, where the test also comes from.
542
543 proc check_effective_target_pcc_bitfield_type_matters { } {
544     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
545     # bitfields, but let's stick to the example code from the docs.
546     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
547         struct foo1 { char x; char :0; char y; };
548         struct foo2 { char x; int :0; char y; };
549         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
550     }]
551 }
552
553 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
554
555 proc check_effective_target_tls {} {
556     return [check_no_compiler_messages tls assembly {
557         __thread int i;
558         int f (void) { return i; }
559         void g (int j) { i = j; }
560     }]
561 }
562
563 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
564
565 proc check_effective_target_tls_native {} {
566     # VxWorks uses emulated TLS machinery, but with non-standard helper
567     # functions, so we fail to automatically detect it.
568     global target_triplet
569     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
570         return 0
571     }
572     
573     return [check_no_messages_and_pattern tls_native "!emutls" assembly {
574         __thread int i;
575         int f (void) { return i; }
576         void g (int j) { i = j; }
577     }]
578 }
579
580 # Return 1 if TLS executables can run correctly, 0 otherwise.
581
582 proc check_effective_target_tls_runtime {} {
583     return [check_runtime tls_runtime {
584         __thread int thr = 0;
585         int main (void) { return thr; }
586     }]
587 }
588
589 # Return 1 if compilation with -fgraphite is error-free for trivial 
590 # code, 0 otherwise.
591
592 proc check_effective_target_fgraphite {} {
593     return [check_no_compiler_messages fgraphite object {
594         void foo (void) { }
595     } "-O1 -fgraphite"]
596 }
597
598 # Return 1 if compilation with -fopenmp is error-free for trivial
599 # code, 0 otherwise.
600
601 proc check_effective_target_fopenmp {} {
602     return [check_no_compiler_messages fopenmp object {
603         void foo (void) { }
604     } "-fopenmp"]
605 }
606
607 # Return 1 if compilation with -pthread is error-free for trivial
608 # code, 0 otherwise.
609
610 proc check_effective_target_pthread {} {
611     return [check_no_compiler_messages pthread object {
612         void foo (void) { }
613     } "-pthread"]
614 }
615
616 # Return 1 if compilation with -mpe-aligned-commons is error-free
617 # for trivial code, 0 otherwise.
618
619 proc check_effective_target_pe_aligned_commons {} {
620     if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
621         return [check_no_compiler_messages pe_aligned_commons object {
622             int foo;
623         } "-mpe-aligned-commons"]
624     }
625     return 0
626 }
627
628 # Return 1 if the target supports -static
629 proc check_effective_target_static {} {
630     return [check_no_compiler_messages static executable {
631         int main (void) { return 0; }
632     } "-static"]
633 }
634
635 # Return 1 if the target supports -fstack-protector
636 proc check_effective_target_fstack_protector {} {
637     return [check_runtime fstack_protector {
638         int main (void) { return 0; }
639     } "-fstack-protector"]
640 }
641
642 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
643 # for trivial code, 0 otherwise.
644
645 proc check_effective_target_freorder {} {
646     return [check_no_compiler_messages freorder object {
647         void foo (void) { }
648     } "-freorder-blocks-and-partition"]
649 }
650
651 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
652 # emitted, 0 otherwise.  Whether a shared library can actually be built is
653 # out of scope for this test.
654
655 proc check_effective_target_fpic { } {
656     # Note that M68K has a multilib that supports -fpic but not
657     # -fPIC, so we need to check both.  We test with a program that
658     # requires GOT references.
659     foreach arg {fpic fPIC} {
660         if [check_no_compiler_messages $arg object {
661             extern int foo (void); extern int bar;
662             int baz (void) { return foo () + bar; }
663         } "-$arg"] {
664             return 1
665         }
666     }
667     return 0
668 }
669
670 # Return true if the target supports -mpaired-single (as used on MIPS).
671
672 proc check_effective_target_mpaired_single { } {
673     return [check_no_compiler_messages mpaired_single object {
674         void foo (void) { }
675     } "-mpaired-single"]
676 }
677
678 # Return true if the target has access to FPU instructions.
679
680 proc check_effective_target_hard_float { } {
681     if { [istarget mips*-*-*] } {
682         return [check_no_compiler_messages hard_float assembly {
683                 #if (defined __mips_soft_float || defined __mips16)
684                 #error FOO
685                 #endif
686         }]
687     }
688
689     # The generic test equates hard_float with "no call for adding doubles".
690     return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
691         double a (double b, double c) { return b + c; }
692     }]
693 }
694
695 # Return true if the target is a 64-bit MIPS target.
696
697 proc check_effective_target_mips64 { } {
698     return [check_no_compiler_messages mips64 assembly {
699         #ifndef __mips64
700         #error FOO
701         #endif
702     }]
703 }
704
705 # Return true if the target is a MIPS target that does not produce
706 # MIPS16 code.
707
708 proc check_effective_target_nomips16 { } {
709     return [check_no_compiler_messages nomips16 object {
710         #ifndef __mips
711         #error FOO
712         #else
713         /* A cheap way of testing for -mflip-mips16.  */
714         void foo (void) { asm ("addiu $20,$20,1"); }
715         void bar (void) { asm ("addiu $20,$20,1"); }
716         #endif
717     }]
718 }
719
720 # Add the options needed for MIPS16 function attributes.  At the moment,
721 # we don't support MIPS16 PIC.
722
723 proc add_options_for_mips16_attribute { flags } {
724     return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
725 }
726
727 # Return true if we can force a mode that allows MIPS16 code generation.
728 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
729 # for o32 and o64.
730
731 proc check_effective_target_mips16_attribute { } {
732     return [check_no_compiler_messages mips16_attribute assembly {
733         #ifdef PIC
734         #error FOO
735         #endif
736         #if defined __mips_hard_float \
737             && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
738             && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
739         #error FOO
740         #endif
741     } [add_options_for_mips16_attribute ""]]
742 }
743
744 # Return 1 if the target supports long double larger than double when
745 # using the new ABI, 0 otherwise.
746
747 proc check_effective_target_mips_newabi_large_long_double { } {
748     return [check_no_compiler_messages mips_newabi_large_long_double object {
749         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
750     } "-mabi=64"]
751 }
752
753 # Return 1 if the current multilib does not generate PIC by default.
754
755 proc check_effective_target_nonpic { } {
756     return [check_no_compiler_messages nonpic assembly {
757         #if __PIC__
758         #error FOO
759         #endif
760     }]
761 }
762
763 # Return 1 if the target does not use a status wrapper.
764
765 proc check_effective_target_unwrapped { } {
766     if { [target_info needs_status_wrapper] != "" \
767              && [target_info needs_status_wrapper] != "0" } {
768         return 0
769     }
770     return 1
771 }
772
773 # Return true if iconv is supported on the target. In particular IBM1047.
774
775 proc check_iconv_available { test_what } {
776     global libiconv
777
778     # If the tool configuration file has not set libiconv, try "-liconv"
779     if { ![info exists libiconv] } {
780         set libiconv "-liconv"
781     }
782     set test_what [lindex $test_what 1]
783     return [check_runtime_nocache $test_what [subst {
784         #include <iconv.h>
785         int main (void)
786         {
787           iconv_t cd;
788
789           cd = iconv_open ("$test_what", "UTF-8");
790           if (cd == (iconv_t) -1)
791             return 1;
792           return 0;
793         }
794     }] $libiconv]
795 }
796
797 # Return true if named sections are supported on this target.
798
799 proc check_named_sections_available { } {
800     return [check_no_compiler_messages named_sections assembly {
801         int __attribute__ ((section("whatever"))) foo;
802     }]
803 }
804
805 # Return 1 if the target supports Fortran real kinds larger than real(8),
806 # 0 otherwise.
807 #
808 # When the target name changes, replace the cached result.
809
810 proc check_effective_target_fortran_large_real { } {
811     return [check_no_compiler_messages fortran_large_real executable {
812         ! Fortran
813         integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
814         real(kind=k) :: x
815         x = cos (x)
816         end
817     }]
818 }
819
820 # Return 1 if the target supports Fortran integer kinds larger than
821 # integer(8), 0 otherwise.
822 #
823 # When the target name changes, replace the cached result.
824
825 proc check_effective_target_fortran_large_int { } {
826     return [check_no_compiler_messages fortran_large_int executable {
827         ! Fortran
828         integer,parameter :: k = selected_int_kind (range (0_8) + 1)
829         integer(kind=k) :: i
830         end
831     }]
832 }
833
834 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
835 #
836 # When the target name changes, replace the cached result.
837
838 proc check_effective_target_fortran_integer_16 { } {
839     return [check_no_compiler_messages fortran_integer_16 executable {
840         ! Fortran
841         integer(16) :: i
842         end
843     }]
844 }
845
846 # Return 1 if we can statically link libgfortran, 0 otherwise.
847 #
848 # When the target name changes, replace the cached result.
849
850 proc check_effective_target_static_libgfortran { } {
851     return [check_no_compiler_messages static_libgfortran executable {
852         ! Fortran
853         print *, 'test'
854         end
855     } "-static"]
856 }
857
858 # Return 1 if the target supports executing 750CL paired-single instructions, 0
859 # otherwise.  Cache the result.
860
861 proc check_750cl_hw_available { } {
862     return [check_cached_effective_target 750cl_hw_available {
863         # If this is not the right target then we can skip the test.
864         if { ![istarget powerpc-*paired*] } {
865             expr 0
866         } else {
867             check_runtime_nocache 750cl_hw_available {
868                  int main()
869                  {
870                  #ifdef __MACH__
871                    asm volatile ("ps_mul v0,v0,v0");
872                  #else
873                    asm volatile ("ps_mul 0,0,0");
874                  #endif
875                    return 0;
876                  }
877             } "-mpaired"
878         }
879     }]
880 }
881
882 # Return 1 if the target supports executing SSE2 instructions, 0
883 # otherwise.  Cache the result.
884
885 proc check_sse2_hw_available { } {
886     return [check_cached_effective_target sse2_hw_available {
887         # If this is not the right target then we can skip the test.
888         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
889             expr 0
890         } else {
891             check_runtime_nocache sse2_hw_available {
892                 #include "cpuid.h"
893                 int main ()
894                 {
895                   unsigned int eax, ebx, ecx, edx = 0;
896                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
897                     return !(edx & bit_SSE2);
898                   return 1;
899                 }
900             } ""
901         }
902     }]
903 }
904
905 # Return 1 if the target supports executing VSX instructions, 0
906 # otherwise.  Cache the result.
907
908 proc check_vsx_hw_available { } {
909     return [check_cached_effective_target vsx_hw_available {
910         # Some simulators are known to not support VSX instructions.
911         # For now, disable on Darwin
912         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
913             expr 0
914         } else {
915             set options "-mvsx"
916             check_runtime_nocache vsx_hw_available {
917                 int main()
918                 {
919                 #ifdef __MACH__
920                   asm volatile ("xxlor vs0,vs0,vs0");
921                 #else
922                   asm volatile ("xxlor 0,0,0");
923                 #endif
924                   return 0;
925                 }
926             } $options
927         }
928     }]
929 }
930
931 # Return 1 if the target supports executing AltiVec instructions, 0
932 # otherwise.  Cache the result.
933
934 proc check_vmx_hw_available { } {
935     return [check_cached_effective_target vmx_hw_available {
936         # Some simulators are known to not support VMX instructions.
937         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
938             expr 0
939         } else {
940             # Most targets don't require special flags for this test case, but
941             # Darwin does.  Just to be sure, make sure VSX is not enabled for
942             # the altivec tests.
943             if { [istarget *-*-darwin*]
944                  || [istarget *-*-aix*] } {
945                 set options "-maltivec -mno-vsx"
946             } else {
947                 set options "-mno-vsx"
948             }
949             check_runtime_nocache vmx_hw_available {
950                 int main()
951                 {
952                 #ifdef __MACH__
953                   asm volatile ("vor v0,v0,v0");
954                 #else
955                   asm volatile ("vor 0,0,0");
956                 #endif
957                   return 0;
958                 }
959             } $options
960         }
961     }]
962 }
963
964 # Return 1 if the target supports executing AltiVec and Cell PPU
965 # instructions, 0 otherwise.  Cache the result.
966
967 proc check_effective_target_cell_hw { } {
968     return [check_cached_effective_target cell_hw_available {
969         # Some simulators are known to not support VMX and PPU instructions.
970         if { [istarget powerpc-*-eabi*] } {
971             expr 0
972         } else {
973             # Most targets don't require special flags for this test
974             # case, but Darwin and AIX do.
975             if { [istarget *-*-darwin*]
976                  || [istarget *-*-aix*] } {
977                 set options "-maltivec -mcpu=cell"
978             } else {
979                 set options "-mcpu=cell"
980             }
981             check_runtime_nocache cell_hw_available {
982                 int main()
983                 {
984                 #ifdef __MACH__
985                   asm volatile ("vor v0,v0,v0");
986                   asm volatile ("lvlx v0,r0,r0");
987                 #else
988                   asm volatile ("vor 0,0,0");
989                   asm volatile ("lvlx 0,0,0");
990                 #endif
991                   return 0;
992                 }
993             } $options
994         }
995     }]
996 }
997
998 # Return 1 if the target supports executing 64-bit instructions, 0
999 # otherwise.  Cache the result.
1000
1001 proc check_effective_target_powerpc64 { } {
1002     global powerpc64_available_saved
1003     global tool
1004
1005     if [info exists powerpc64_available_saved] {
1006         verbose "check_effective_target_powerpc64 returning saved $powerpc64_available_saved" 2
1007     } else {
1008         set powerpc64_available_saved 0
1009
1010         # Some simulators are known to not support powerpc64 instructions.
1011         if { [istarget powerpc-*-eabi*] || [istarget powerpc-ibm-aix*] } {
1012             verbose "check_effective_target_powerpc64 returning 0" 2
1013             return $powerpc64_available_saved
1014         }
1015
1016         # Set up, compile, and execute a test program containing a 64-bit
1017         # instruction.  Include the current process ID in the file
1018         # names to prevent conflicts with invocations for multiple
1019         # testsuites.
1020         set src ppc[pid].c
1021         set exe ppc[pid].x
1022
1023         set f [open $src "w"]
1024         puts $f "int main() {"
1025         puts $f "#ifdef __MACH__"
1026         puts $f "  asm volatile (\"extsw r0,r0\");"
1027         puts $f "#else"
1028         puts $f "  asm volatile (\"extsw 0,0\");"
1029         puts $f "#endif"
1030         puts $f "  return 0; }"
1031         close $f
1032
1033         set opts "additional_flags=-mcpu=G5"
1034
1035         verbose "check_effective_target_powerpc64 compiling testfile $src" 2
1036         set lines [${tool}_target_compile $src $exe executable "$opts"]
1037         file delete $src
1038
1039         if [string match "" $lines] then {
1040             # No error message, compilation succeeded.
1041             set result [${tool}_load "./$exe" "" ""]
1042             set status [lindex $result 0]
1043             remote_file build delete $exe
1044             verbose "check_effective_target_powerpc64 testfile status is <$status>" 2
1045
1046             if { $status == "pass" } then {
1047                 set powerpc64_available_saved 1
1048             }
1049         } else {
1050             verbose "check_effective_target_powerpc64 testfile compilation failed" 2
1051         }
1052     }
1053
1054     return $powerpc64_available_saved
1055 }
1056
1057 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
1058 # complex float arguments.  This affects gfortran tests that call cabsf
1059 # in libm built by an earlier compiler.  Return 1 if libm uses the same
1060 # argument passing as the compiler under test, 0 otherwise.
1061 #
1062 # When the target name changes, replace the cached result.
1063
1064 proc check_effective_target_broken_cplxf_arg { } {
1065     return [check_cached_effective_target broken_cplxf_arg {
1066         # Skip the work for targets known not to be affected.
1067         if { ![istarget powerpc64-*-linux*] } {
1068             expr 0
1069         } elseif { ![is-effective-target lp64] } {
1070             expr 0
1071         } else {
1072             check_runtime_nocache broken_cplxf_arg {
1073                 #include <complex.h>
1074                 extern void abort (void);
1075                 float fabsf (float);
1076                 float cabsf (_Complex float);
1077                 int main ()
1078                 {
1079                   _Complex float cf;
1080                   float f;
1081                   cf = 3 + 4.0fi;
1082                   f = cabsf (cf);
1083                   if (fabsf (f - 5.0) > 0.0001)
1084                     abort ();
1085                   return 0;
1086                 }
1087             } "-lm"
1088         }
1089     }]
1090 }
1091
1092 proc check_alpha_max_hw_available { } {
1093     return [check_runtime alpha_max_hw_available {
1094         int main() { return __builtin_alpha_amask(1<<8) != 0; }
1095     }]
1096 }
1097
1098 # Returns true iff the FUNCTION is available on the target system.
1099 # (This is essentially a Tcl implementation of Autoconf's
1100 # AC_CHECK_FUNC.)
1101
1102 proc check_function_available { function } {
1103     return [check_no_compiler_messages ${function}_available \
1104                 executable [subst {
1105         #ifdef __cplusplus
1106         extern "C"
1107         #endif
1108         char $function ();
1109         int main () { $function (); }
1110     }]]
1111 }
1112
1113 # Returns true iff "fork" is available on the target system.
1114
1115 proc check_fork_available {} {
1116     return [check_function_available "fork"]
1117 }
1118
1119 # Returns true iff "mkfifo" is available on the target system.
1120
1121 proc check_mkfifo_available {} {
1122     if {[istarget *-*-cygwin*]} {
1123        # Cygwin has mkfifo, but support is incomplete.
1124        return 0
1125      }
1126
1127     return [check_function_available "mkfifo"]
1128 }
1129
1130 # Returns true iff "__cxa_atexit" is used on the target system.
1131
1132 proc check_cxa_atexit_available { } {
1133     return [check_cached_effective_target cxa_atexit_available {
1134         if { [istarget "hppa*-*-hpux10*"] } {
1135             # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1136             expr 0
1137         } elseif { [istarget "*-*-vxworks"] } {
1138             # vxworks doesn't have __cxa_atexit but subsequent test passes.
1139             expr 0
1140         } else {
1141             check_runtime_nocache cxa_atexit_available {
1142                 // C++
1143                 #include <stdlib.h>
1144                 static unsigned int count;
1145                 struct X
1146                 {
1147                   X() { count = 1; }
1148                   ~X()
1149                   {
1150                     if (count != 3)
1151                       exit(1);
1152                     count = 4;
1153                   }
1154                 };
1155                 void f()
1156                 {
1157                   static X x;
1158                 }
1159                 struct Y
1160                 {
1161                   Y() { f(); count = 2; }
1162                   ~Y()
1163                   {
1164                     if (count != 2)
1165                       exit(1);
1166                     count = 3;
1167                   }
1168                 };
1169                 Y y;
1170                 int main() { return 0; }
1171             }
1172         }
1173     }]
1174 }
1175
1176
1177 # Return 1 if we're generating 32-bit code using default options, 0
1178 # otherwise.
1179
1180 proc check_effective_target_ilp32 { } {
1181     return [check_no_compiler_messages ilp32 object {
1182         int dummy[sizeof (int) == 4
1183                   && sizeof (void *) == 4
1184                   && sizeof (long) == 4 ? 1 : -1];
1185     }]
1186 }
1187
1188 # Return 1 if we're generating 32-bit or larger integers using default
1189 # options, 0 otherwise.
1190
1191 proc check_effective_target_int32plus { } {
1192     return [check_no_compiler_messages int32plus object {
1193         int dummy[sizeof (int) >= 4 ? 1 : -1];
1194     }]
1195 }
1196
1197 # Return 1 if we're generating 32-bit or larger pointers using default
1198 # options, 0 otherwise.
1199
1200 proc check_effective_target_ptr32plus { } {
1201     return [check_no_compiler_messages ptr32plus object {
1202         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1203     }]
1204 }
1205
1206 # Return 1 if we support 32-bit or larger array and structure sizes
1207 # using default options, 0 otherwise.
1208
1209 proc check_effective_target_size32plus { } {
1210     return [check_no_compiler_messages size32plus object {
1211         char dummy[65537];
1212     }]
1213 }
1214
1215 # Returns 1 if we're generating 16-bit or smaller integers with the
1216 # default options, 0 otherwise.
1217
1218 proc check_effective_target_int16 { } {
1219     return [check_no_compiler_messages int16 object {
1220         int dummy[sizeof (int) < 4 ? 1 : -1];
1221     }]
1222 }
1223
1224 # Return 1 if we're generating 64-bit code using default options, 0
1225 # otherwise.
1226
1227 proc check_effective_target_lp64 { } {
1228     return [check_no_compiler_messages lp64 object {
1229         int dummy[sizeof (int) == 4
1230                   && sizeof (void *) == 8
1231                   && sizeof (long) == 8 ? 1 : -1];
1232     }]
1233 }
1234
1235 # Return 1 if we're generating 64-bit code using default llp64 options,
1236 # 0 otherwise.
1237
1238 proc check_effective_target_llp64 { } {
1239     return [check_no_compiler_messages llp64 object {
1240         int dummy[sizeof (int) == 4
1241                   && sizeof (void *) == 8
1242                   && sizeof (long long) == 8
1243                   && sizeof (long) == 4 ? 1 : -1];
1244     }]
1245 }
1246
1247 # Return 1 if the target supports long double larger than double,
1248 # 0 otherwise.
1249
1250 proc check_effective_target_large_long_double { } {
1251     return [check_no_compiler_messages large_long_double object {
1252         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1253     }]
1254 }
1255
1256 # Return 1 if the target supports double larger than float,
1257 # 0 otherwise.
1258
1259 proc check_effective_target_large_double { } {
1260     return [check_no_compiler_messages large_double object {
1261         int dummy[sizeof(double) > sizeof(float) ? 1 : -1];
1262     }]
1263 }
1264
1265 # Return 1 if the target supports double of 64 bits,
1266 # 0 otherwise.
1267
1268 proc check_effective_target_double64 { } {
1269     return [check_no_compiler_messages double64 object {
1270         int dummy[sizeof(double) == 8 ? 1 : -1];
1271     }]
1272 }
1273
1274 # Return 1 if the target supports double of at least 64 bits,
1275 # 0 otherwise.
1276
1277 proc check_effective_target_double64plus { } {
1278     return [check_no_compiler_messages double64plus object {
1279         int dummy[sizeof(double) >= 8 ? 1 : -1];
1280     }]
1281 }
1282
1283 # Return 1 if the target supports compiling fixed-point,
1284 # 0 otherwise.
1285
1286 proc check_effective_target_fixed_point { } {
1287     return [check_no_compiler_messages fixed_point object {
1288         _Sat _Fract x; _Sat _Accum y;
1289     }]
1290 }
1291
1292 # Return 1 if the target supports compiling decimal floating point,
1293 # 0 otherwise.
1294
1295 proc check_effective_target_dfp_nocache { } {
1296     verbose "check_effective_target_dfp_nocache: compiling source" 2
1297     set ret [check_no_compiler_messages_nocache dfp object {
1298         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1299     }]
1300     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1301     return $ret
1302 }
1303
1304 proc check_effective_target_dfprt_nocache { } {
1305     return [check_runtime_nocache dfprt {
1306         _Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;
1307         int main () { z = x + y; return 0; }
1308     }]
1309 }
1310
1311 # Return 1 if the target supports compiling Decimal Floating Point,
1312 # 0 otherwise.
1313 #
1314 # This won't change for different subtargets so cache the result.
1315
1316 proc check_effective_target_dfp { } {
1317     return [check_cached_effective_target dfp {
1318         check_effective_target_dfp_nocache
1319     }]
1320 }
1321
1322 # Return 1 if the target supports linking and executing Decimal Floating
1323 # Point, # 0 otherwise.
1324 #
1325 # This won't change for different subtargets so cache the result.
1326
1327 proc check_effective_target_dfprt { } {
1328     return [check_cached_effective_target dfprt {
1329         check_effective_target_dfprt_nocache
1330     }]
1331 }
1332
1333 # Return 1 if the target needs a command line argument to enable a SIMD
1334 # instruction set.
1335
1336 proc check_effective_target_vect_cmdline_needed { } {
1337     global et_vect_cmdline_needed_saved
1338     global et_vect_cmdline_needed_target_name
1339
1340     if { ![info exists et_vect_cmdline_needed_target_name] } {
1341         set et_vect_cmdline_needed_target_name ""
1342     }
1343
1344     # If the target has changed since we set the cached value, clear it.
1345     set current_target [current_target_name]
1346     if { $current_target != $et_vect_cmdline_needed_target_name } {
1347         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1348         set et_vect_cmdline_needed_target_name $current_target
1349         if { [info exists et_vect_cmdline_needed_saved] } {
1350             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1351             unset et_vect_cmdline_needed_saved
1352         }
1353     }
1354
1355     if [info exists et_vect_cmdline_needed_saved] {
1356         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1357     } else {
1358         set et_vect_cmdline_needed_saved 1
1359         if { [istarget alpha*-*-*]
1360              || [istarget ia64-*-*]
1361              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1362                  && [check_effective_target_lp64])
1363              || ([istarget powerpc*-*-*]
1364                  && ([check_effective_target_powerpc_spe]
1365                      || [check_effective_target_powerpc_altivec]))
1366              || [istarget spu-*-*]
1367              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
1368            set et_vect_cmdline_needed_saved 0
1369         }
1370     }
1371
1372     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1373     return $et_vect_cmdline_needed_saved
1374 }
1375
1376 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1377 #
1378 # This won't change for different subtargets so cache the result.
1379
1380 proc check_effective_target_vect_int { } {
1381     global et_vect_int_saved
1382
1383     if [info exists et_vect_int_saved] {
1384         verbose "check_effective_target_vect_int: using cached result" 2
1385     } else {
1386         set et_vect_int_saved 0
1387         if { [istarget i?86-*-*]
1388              || ([istarget powerpc*-*-*]
1389                   && ![istarget powerpc-*-linux*paired*])
1390               || [istarget spu-*-*]
1391               || [istarget x86_64-*-*]
1392               || [istarget sparc*-*-*]
1393               || [istarget alpha*-*-*]
1394               || [istarget ia64-*-*] 
1395               || [check_effective_target_arm32] } {
1396            set et_vect_int_saved 1
1397         }
1398     }
1399
1400     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1401     return $et_vect_int_saved
1402 }
1403
1404 # Return 1 if the target supports signed int->float conversion 
1405 #
1406
1407 proc check_effective_target_vect_intfloat_cvt { } {
1408     global et_vect_intfloat_cvt_saved
1409
1410     if [info exists et_vect_intfloat_cvt_saved] {
1411         verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1412     } else {
1413         set et_vect_intfloat_cvt_saved 0
1414         if { [istarget i?86-*-*]
1415               || ([istarget powerpc*-*-*]
1416                    && ![istarget powerpc-*-linux*paired*])
1417               || [istarget x86_64-*-*] } {
1418            set et_vect_intfloat_cvt_saved 1
1419         }
1420     }
1421
1422     verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1423     return $et_vect_intfloat_cvt_saved
1424 }
1425
1426
1427 # Return 1 if the target supports unsigned int->float conversion 
1428 #
1429
1430 proc check_effective_target_vect_uintfloat_cvt { } {
1431     global et_vect_uintfloat_cvt_saved
1432
1433     if [info exists et_vect_uintfloat_cvt_saved] {
1434         verbose "check_effective_target_vect_uintfloat_cvt: using cached result" 2
1435     } else {
1436         set et_vect_uintfloat_cvt_saved 0
1437         if { [istarget i?86-*-*]
1438               || ([istarget powerpc*-*-*]
1439                   && ![istarget powerpc-*-linux*paired*])
1440               || [istarget x86_64-*-*] } {
1441            set et_vect_uintfloat_cvt_saved 1
1442         }
1443     }
1444
1445     verbose "check_effective_target_vect_uintfloat_cvt: returning $et_vect_uintfloat_cvt_saved" 2
1446     return $et_vect_uintfloat_cvt_saved
1447 }
1448
1449
1450 # Return 1 if the target supports signed float->int conversion
1451 #
1452
1453 proc check_effective_target_vect_floatint_cvt { } {
1454     global et_vect_floatint_cvt_saved
1455
1456     if [info exists et_vect_floatint_cvt_saved] {
1457         verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1458     } else {
1459         set et_vect_floatint_cvt_saved 0
1460         if { [istarget i?86-*-*]
1461               || ([istarget powerpc*-*-*]
1462                    && ![istarget powerpc-*-linux*paired*])
1463               || [istarget x86_64-*-*] } {
1464            set et_vect_floatint_cvt_saved 1
1465         }
1466     }
1467
1468     verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1469     return $et_vect_floatint_cvt_saved
1470 }
1471
1472 # Return 1 if the target supports unsigned float->int conversion
1473 #
1474
1475 proc check_effective_target_vect_floatuint_cvt { } {
1476     global et_vect_floatuint_cvt_saved
1477
1478     if [info exists et_vect_floatuint_cvt_saved] {
1479         verbose "check_effective_target_vect_floatuint_cvt: using cached result" 2
1480     } else {
1481         set et_vect_floatuint_cvt_saved 0
1482         if { ([istarget powerpc*-*-*]
1483               && ![istarget powerpc-*-linux*paired*]) } {
1484            set et_vect_floatuint_cvt_saved 1
1485         }
1486     }
1487
1488     verbose "check_effective_target_vect_floatuint_cvt: returning $et_vect_floatuint_cvt_saved" 2
1489     return $et_vect_floatuint_cvt_saved
1490 }
1491
1492 # Return 1 is this is an arm target using 32-bit instructions
1493 proc check_effective_target_arm32 { } {
1494     return [check_no_compiler_messages arm32 assembly {
1495         #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1496         #error FOO
1497         #endif
1498     }]
1499 }
1500
1501 # Return 1 if this is an ARM target supporting -mfpu=vfp
1502 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1503 # options.
1504
1505 proc check_effective_target_arm_vfp_ok { } {
1506     if { [check_effective_target_arm32] } {
1507         return [check_no_compiler_messages arm_vfp_ok object {
1508             int dummy;
1509         } "-mfpu=vfp -mfloat-abi=softfp"]
1510     } else {
1511         return 0
1512     }
1513 }
1514
1515 # Return 1 if this is an ARM target supporting -mfpu=vfp
1516 # -mfloat-abi=hard.  Some multilibs may be incompatible with these
1517 # options.
1518
1519 proc check_effective_target_arm_hard_vfp_ok { } {
1520     if { [check_effective_target_arm32] } {
1521         return [check_no_compiler_messages arm_hard_vfp_ok executable {
1522             int main() { return 0;}
1523         } "-mfpu=vfp -mfloat-abi=hard"]
1524     } else {
1525         return 0
1526     }
1527 }
1528
1529 # Return 1 if this is an ARM target supporting -mfpu=neon
1530 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1531 # options.
1532
1533 proc check_effective_target_arm_neon_ok { } {
1534     if { [check_effective_target_arm32] } {
1535         return [check_no_compiler_messages arm_neon_ok object {
1536             #include "arm_neon.h"
1537             int dummy;
1538         } "-mfpu=neon -mfloat-abi=softfp"]
1539     } else {
1540         return 0
1541     }
1542 }
1543
1544 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
1545 # used.
1546
1547 proc check_effective_target_arm_thumb1_ok { } {
1548     return [check_no_compiler_messages arm_thumb1_ok assembly {
1549         #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
1550         #error FOO
1551         #endif
1552     } "-mthumb"]
1553 }
1554
1555 # Return 1 is this is an ARM target where -mthumb causes Thumb-2 to be
1556 # used.
1557
1558 proc check_effective_target_arm_thumb2_ok { } {
1559     return [check_no_compiler_messages arm_thumb2_ok assembly {
1560         #if !defined(__thumb2__)
1561         #error FOO
1562         #endif
1563     } "-mthumb"]
1564 }
1565
1566 # Return 1 if the target supports executing NEON instructions, 0
1567 # otherwise.  Cache the result.
1568
1569 proc check_effective_target_arm_neon_hw { } {
1570     return [check_runtime arm_neon_hw_available {
1571         int
1572         main (void)
1573         {
1574           long long a = 0, b = 1;
1575           asm ("vorr %P0, %P1, %P2"
1576                : "=w" (a)
1577                : "0" (a), "w" (b));
1578           return (a != 1);
1579         }
1580     } "-mfpu=neon -mfloat-abi=softfp"]
1581 }
1582
1583 # Return 1 if this is a ARM target with NEON enabled.
1584
1585 proc check_effective_target_arm_neon { } {
1586     if { [check_effective_target_arm32] } {
1587         return [check_no_compiler_messages arm_neon object {
1588             #ifndef __ARM_NEON__
1589             #error not NEON
1590             #else
1591             int dummy;
1592             #endif
1593         }]
1594     } else {
1595         return 0
1596     }
1597 }
1598
1599 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
1600 # the Loongson vector modes.
1601
1602 proc check_effective_target_mips_loongson { } {
1603     return [check_no_compiler_messages loongson assembly {
1604         #if !defined(__mips_loongson_vector_rev)
1605         #error FOO
1606         #endif
1607     }]
1608 }
1609
1610 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
1611 # Architecture.
1612
1613 proc check_effective_target_arm_eabi { } {
1614     return [check_no_compiler_messages arm_eabi object {
1615         #ifndef __ARM_EABI__
1616         #error not EABI
1617         #else
1618         int dummy;
1619         #endif
1620     }]
1621 }
1622
1623 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
1624 # Some multilibs may be incompatible with this option.
1625
1626 proc check_effective_target_arm_iwmmxt_ok { } {
1627     if { [check_effective_target_arm32] } {
1628         return [check_no_compiler_messages arm_iwmmxt_ok object {
1629             int dummy;
1630         } "-mcpu=iwmmxt"]
1631     } else {
1632         return 0
1633     }
1634 }
1635
1636 # Return 1 if this is a PowerPC target with floating-point registers.
1637
1638 proc check_effective_target_powerpc_fprs { } {
1639     if { [istarget powerpc*-*-*]
1640          || [istarget rs6000-*-*] } {
1641         return [check_no_compiler_messages powerpc_fprs object {
1642             #ifdef __NO_FPRS__
1643             #error no FPRs
1644             #else
1645             int dummy;
1646             #endif
1647         }]
1648     } else {
1649         return 0
1650     }
1651 }
1652
1653 # Return 1 if this is a PowerPC target with hardware double-precision
1654 # floating point.
1655
1656 proc check_effective_target_powerpc_hard_double { } {
1657     if { [istarget powerpc*-*-*]
1658          || [istarget rs6000-*-*] } {
1659         return [check_no_compiler_messages powerpc_hard_double object {
1660             #ifdef _SOFT_DOUBLE
1661             #error soft double
1662             #else
1663             int dummy;
1664             #endif
1665         }]
1666     } else {
1667         return 0
1668     }
1669 }
1670
1671 # Return 1 if this is a PowerPC target supporting -maltivec.
1672
1673 proc check_effective_target_powerpc_altivec_ok { } {
1674     if { ([istarget powerpc*-*-*]
1675          && ![istarget powerpc-*-linux*paired*])
1676          || [istarget rs6000-*-*] } {
1677         # AltiVec is not supported on AIX before 5.3.
1678         if { [istarget powerpc*-*-aix4*]
1679              || [istarget powerpc*-*-aix5.1*] 
1680              || [istarget powerpc*-*-aix5.2*] } {
1681             return 0
1682         }
1683         return [check_no_compiler_messages powerpc_altivec_ok object {
1684             int dummy;
1685         } "-maltivec"]
1686     } else {
1687         return 0
1688     }
1689 }
1690
1691 # Return 1 if this is a PowerPC target supporting -mvsx
1692
1693 proc check_effective_target_powerpc_vsx_ok { } {
1694     if { ([istarget powerpc*-*-*]
1695          && ![istarget powerpc-*-linux*paired*])
1696          || [istarget rs6000-*-*] } {
1697         # AltiVec is not supported on AIX before 5.3.
1698         if { [istarget powerpc*-*-aix4*]
1699              || [istarget powerpc*-*-aix5.1*] 
1700              || [istarget powerpc*-*-aix5.2*] } {
1701             return 0
1702         }
1703         return [check_no_compiler_messages powerpc_vsx_ok object {
1704             int main (void) {
1705 #ifdef __MACH__
1706                 asm volatile ("xxlor vs0,vs0,vs0");
1707 #else
1708                 asm volatile ("xxlor 0,0,0");
1709 #endif
1710                 return 0;
1711             }
1712         } "-mvsx"]
1713     } else {
1714         return 0
1715     }
1716 }
1717
1718 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
1719
1720 proc check_effective_target_powerpc_ppu_ok { } {
1721     if [check_effective_target_powerpc_altivec_ok] {
1722         return [check_no_compiler_messages cell_asm_available object {
1723             int main (void) {
1724 #ifdef __MACH__
1725                 asm volatile ("lvlx v0,v0,v0");
1726 #else
1727                 asm volatile ("lvlx 0,0,0");
1728 #endif
1729                 return 0;
1730             }
1731         }]
1732     } else {
1733         return 0
1734     }
1735 }
1736
1737 # Return 1 if this is a PowerPC target that supports SPU.
1738
1739 proc check_effective_target_powerpc_spu { } {
1740     if [istarget powerpc*-*-linux*] {
1741         return [check_effective_target_powerpc_altivec_ok]
1742     } else {
1743         return 0
1744     }
1745 }
1746
1747 # Return 1 if this is a PowerPC SPE target.  The check includes options
1748 # specified by dg-options for this test, so don't cache the result.
1749
1750 proc check_effective_target_powerpc_spe_nocache { } {
1751     if { [istarget powerpc*-*-*] } {
1752         return [check_no_compiler_messages_nocache powerpc_spe object {
1753             #ifndef __SPE__
1754             #error not SPE
1755             #else
1756             int dummy;
1757             #endif
1758         } [current_compiler_flags]]
1759     } else {
1760         return 0
1761     }
1762 }
1763
1764 # Return 1 if this is a PowerPC target with SPE enabled.
1765
1766 proc check_effective_target_powerpc_spe { } {
1767     if { [istarget powerpc*-*-*] } {
1768         return [check_no_compiler_messages powerpc_spe object {
1769             #ifndef __SPE__
1770             #error not SPE
1771             #else
1772             int dummy;
1773             #endif
1774         }]
1775     } else {
1776         return 0
1777     }
1778 }
1779
1780 # Return 1 if this is a PowerPC target with Altivec enabled.
1781
1782 proc check_effective_target_powerpc_altivec { } {
1783     if { [istarget powerpc*-*-*] } {
1784         return [check_no_compiler_messages powerpc_altivec object {
1785             #ifndef __ALTIVEC__
1786             #error not Altivec
1787             #else
1788             int dummy;
1789             #endif
1790         }]
1791     } else {
1792         return 0
1793     }
1794 }
1795
1796 # Return 1 if this is a PowerPC 405 target.  The check includes options
1797 # specified by dg-options for this test, so don't cache the result.
1798
1799 proc check_effective_target_powerpc_405_nocache { } {
1800     if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
1801         return [check_no_compiler_messages_nocache powerpc_405 object {
1802             #ifdef __PPC405__
1803             int dummy;
1804             #else
1805             #error not a PPC405
1806             #endif
1807         } [current_compiler_flags]]
1808     } else {
1809         return 0
1810     }
1811 }
1812
1813 # Return 1 if this is a SPU target with a toolchain that
1814 # supports automatic overlay generation.
1815
1816 proc check_effective_target_spu_auto_overlay { } {
1817     if { [istarget spu*-*-elf*] } {
1818         return [check_no_compiler_messages spu_auto_overlay executable {
1819                 int main (void) { }
1820                 } "-Wl,--auto-overlay" ]
1821     } else {
1822         return 0
1823     }
1824 }
1825
1826 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
1827 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables.  Return 1 if the
1828 # test environment appears to run executables on such a simulator.
1829
1830 proc check_effective_target_ultrasparc_hw { } {
1831     return [check_runtime ultrasparc_hw {
1832         int main() { return 0; }
1833     } "-mcpu=ultrasparc"]
1834 }
1835
1836 # Return 1 if the target supports hardware vector shift operation.
1837
1838 proc check_effective_target_vect_shift { } {
1839     global et_vect_shift_saved
1840
1841     if [info exists et_vect_shift_saved] {
1842         verbose "check_effective_target_vect_shift: using cached result" 2
1843     } else {
1844         set et_vect_shift_saved 0
1845         if { ([istarget powerpc*-*-*]
1846              && ![istarget powerpc-*-linux*paired*])
1847              || [istarget ia64-*-*]
1848              || [istarget i?86-*-*]
1849              || [istarget x86_64-*-*]
1850              || [check_effective_target_arm32] } {
1851            set et_vect_shift_saved 1
1852         }
1853     }
1854
1855     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1856     return $et_vect_shift_saved
1857 }
1858
1859 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1860 #
1861 # This can change for different subtargets so do not cache the result.
1862
1863 proc check_effective_target_vect_long { } {
1864     if { [istarget i?86-*-*]
1865          || (([istarget powerpc*-*-*] 
1866               && ![istarget powerpc-*-linux*paired*]) 
1867               && [check_effective_target_ilp32])
1868          || [istarget x86_64-*-*]
1869          || [check_effective_target_arm32]
1870          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1871         set answer 1
1872     } else {
1873         set answer 0
1874     }
1875
1876     verbose "check_effective_target_vect_long: returning $answer" 2
1877     return $answer
1878 }
1879
1880 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1881 #
1882 # This won't change for different subtargets so cache the result.
1883
1884 proc check_effective_target_vect_float { } {
1885     global et_vect_float_saved
1886
1887     if [info exists et_vect_float_saved] {
1888         verbose "check_effective_target_vect_float: using cached result" 2
1889     } else {
1890         set et_vect_float_saved 0
1891         if { [istarget i?86-*-*]
1892               || [istarget powerpc*-*-*]
1893               || [istarget spu-*-*]
1894               || [istarget mipsisa64*-*-*]
1895               || [istarget x86_64-*-*]
1896               || [istarget ia64-*-*]
1897               || [check_effective_target_arm32] } {
1898            set et_vect_float_saved 1
1899         }
1900     }
1901
1902     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1903     return $et_vect_float_saved
1904 }
1905
1906 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1907 #
1908 # This won't change for different subtargets so cache the result.
1909
1910 proc check_effective_target_vect_double { } {
1911     global et_vect_double_saved
1912
1913     if [info exists et_vect_double_saved] {
1914         verbose "check_effective_target_vect_double: using cached result" 2
1915     } else {
1916         set et_vect_double_saved 0
1917         if { [istarget i?86-*-*]
1918               || [istarget x86_64-*-*] 
1919               || [istarget spu-*-*] } {
1920            set et_vect_double_saved 1
1921         }
1922     }
1923
1924     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1925     return $et_vect_double_saved
1926 }
1927
1928 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
1929 #
1930 # This won't change for different subtargets so cache the result.
1931
1932 proc check_effective_target_vect_long_long { } {
1933     global et_vect_long_long_saved
1934
1935     if [info exists et_vect_long_long_saved] {
1936         verbose "check_effective_target_vect_long_long: using cached result" 2
1937     } else {
1938         set et_vect_long_long_saved 0
1939         if { [istarget i?86-*-*]
1940               || [istarget x86_64-*-*] } {
1941            set et_vect_long_long_saved 1
1942         }
1943     }
1944
1945     verbose "check_effective_target_vect_long_long: returning $et_vect_long_long_saved" 2
1946     return $et_vect_long_long_saved
1947 }
1948
1949
1950 # Return 1 if the target plus current options does not support a vector
1951 # max instruction on "int", 0 otherwise.
1952 #
1953 # This won't change for different subtargets so cache the result.
1954
1955 proc check_effective_target_vect_no_int_max { } {
1956     global et_vect_no_int_max_saved
1957
1958     if [info exists et_vect_no_int_max_saved] {
1959         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1960     } else {
1961         set et_vect_no_int_max_saved 0
1962         if { [istarget sparc*-*-*]
1963              || [istarget spu-*-*]
1964              || [istarget alpha*-*-*] } {
1965             set et_vect_no_int_max_saved 1
1966         }
1967     }
1968     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1969     return $et_vect_no_int_max_saved
1970 }
1971
1972 # Return 1 if the target plus current options does not support a vector
1973 # add instruction on "int", 0 otherwise.
1974 #
1975 # This won't change for different subtargets so cache the result.
1976
1977 proc check_effective_target_vect_no_int_add { } {
1978     global et_vect_no_int_add_saved
1979
1980     if [info exists et_vect_no_int_add_saved] {
1981         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1982     } else {
1983         set et_vect_no_int_add_saved 0
1984         # Alpha only supports vector add on V8QI and V4HI.
1985         if { [istarget alpha*-*-*] } {
1986             set et_vect_no_int_add_saved 1
1987         }
1988     }
1989     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1990     return $et_vect_no_int_add_saved
1991 }
1992
1993 # Return 1 if the target plus current options does not support vector
1994 # bitwise instructions, 0 otherwise.
1995 #
1996 # This won't change for different subtargets so cache the result.
1997
1998 proc check_effective_target_vect_no_bitwise { } {
1999     global et_vect_no_bitwise_saved
2000
2001     if [info exists et_vect_no_bitwise_saved] {
2002         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
2003     } else {
2004         set et_vect_no_bitwise_saved 0
2005     }
2006     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
2007     return $et_vect_no_bitwise_saved
2008 }
2009
2010 # Return 1 if the target plus current options supports vector permutation,
2011 # 0 otherwise.
2012 #
2013 # This won't change for different subtargets so cache the result.
2014
2015 proc check_effective_target_vect_perm { } {
2016     global et_vect_perm
2017
2018     if [info exists et_vect_perm_saved] {
2019         verbose "check_effective_target_vect_perm: using cached result" 2
2020     } else {
2021         set et_vect_perm_saved 0
2022         if { [istarget powerpc*-*-*]
2023              || [istarget spu-*-*] } {
2024             set et_vect_perm_saved 1
2025         }
2026     }
2027     verbose "check_effective_target_vect_perm: returning $et_vect_perm_saved" 2
2028     return $et_vect_perm_saved
2029 }
2030
2031
2032 # Return 1 if the target plus current options supports a vector
2033 # widening summation of *short* args into *int* result, 0 otherwise.
2034 # A target can also support this widening summation if it can support
2035 # promotion (unpacking) from shorts to ints.
2036 #
2037 # This won't change for different subtargets so cache the result.
2038                                                                                                 
2039 proc check_effective_target_vect_widen_sum_hi_to_si { } {
2040     global et_vect_widen_sum_hi_to_si
2041
2042     if [info exists et_vect_widen_sum_hi_to_si_saved] {
2043         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
2044     } else {
2045         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
2046         if { [istarget powerpc*-*-*] 
2047              || [istarget ia64-*-*] } {
2048             set et_vect_widen_sum_hi_to_si_saved 1
2049         }
2050     }
2051     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
2052     return $et_vect_widen_sum_hi_to_si_saved
2053 }
2054
2055 # Return 1 if the target plus current options supports a vector
2056 # widening summation of *char* args into *short* result, 0 otherwise.
2057 # A target can also support this widening summation if it can support
2058 # promotion (unpacking) from chars to shorts.
2059 #
2060 # This won't change for different subtargets so cache the result.
2061                                                                                                 
2062 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
2063     global et_vect_widen_sum_qi_to_hi
2064
2065     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
2066         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
2067     } else {
2068         set et_vect_widen_sum_qi_to_hi_saved 0
2069         if { [check_effective_target_vect_unpack] 
2070              || [istarget ia64-*-*] } {
2071             set et_vect_widen_sum_qi_to_hi_saved 1
2072         }
2073     }
2074     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
2075     return $et_vect_widen_sum_qi_to_hi_saved
2076 }
2077
2078 # Return 1 if the target plus current options supports a vector
2079 # widening summation of *char* args into *int* result, 0 otherwise.
2080 #
2081 # This won't change for different subtargets so cache the result.
2082                                                                                                 
2083 proc check_effective_target_vect_widen_sum_qi_to_si { } {
2084     global et_vect_widen_sum_qi_to_si
2085
2086     if [info exists et_vect_widen_sum_qi_to_si_saved] {
2087         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
2088     } else {
2089         set et_vect_widen_sum_qi_to_si_saved 0
2090         if { [istarget powerpc*-*-*] } {
2091             set et_vect_widen_sum_qi_to_si_saved 1
2092         }
2093     }
2094     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
2095     return $et_vect_widen_sum_qi_to_si_saved
2096 }
2097
2098 # Return 1 if the target plus current options supports a vector
2099 # widening multiplication of *char* args into *short* result, 0 otherwise.
2100 # A target can also support this widening multplication if it can support
2101 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
2102 # multiplication of shorts).
2103 #
2104 # This won't change for different subtargets so cache the result.
2105
2106
2107 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
2108     global et_vect_widen_mult_qi_to_hi
2109
2110     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
2111         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
2112     } else {
2113         if { [check_effective_target_vect_unpack]
2114              && [check_effective_target_vect_short_mult] } {
2115             set et_vect_widen_mult_qi_to_hi_saved 1
2116         } else {
2117             set et_vect_widen_mult_qi_to_hi_saved 0
2118         }
2119         if { [istarget powerpc*-*-*] } {
2120             set et_vect_widen_mult_qi_to_hi_saved 1
2121         }
2122     }
2123     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
2124     return $et_vect_widen_mult_qi_to_hi_saved
2125 }
2126
2127 # Return 1 if the target plus current options supports a vector
2128 # widening multiplication of *short* args into *int* result, 0 otherwise.
2129 # A target can also support this widening multplication if it can support
2130 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
2131 # multiplication of ints).
2132 #
2133 # This won't change for different subtargets so cache the result.
2134
2135
2136 proc check_effective_target_vect_widen_mult_hi_to_si { } {
2137     global et_vect_widen_mult_hi_to_si
2138
2139     if [info exists et_vect_widen_mult_hi_to_si_saved] {
2140         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
2141     } else {
2142         if { [check_effective_target_vect_unpack]
2143              && [check_effective_target_vect_int_mult] } {
2144           set et_vect_widen_mult_hi_to_si_saved 1
2145         } else {
2146           set et_vect_widen_mult_hi_to_si_saved 0
2147         }
2148         if { [istarget powerpc*-*-*]
2149               || [istarget spu-*-*]
2150               || [istarget i?86-*-*]
2151               || [istarget x86_64-*-*] } {
2152             set et_vect_widen_mult_hi_to_si_saved 1
2153         }
2154     }
2155     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
2156     return $et_vect_widen_mult_hi_to_si_saved
2157 }
2158
2159 # Return 1 if the target plus current options supports a vector
2160 # dot-product of signed chars, 0 otherwise.
2161 #
2162 # This won't change for different subtargets so cache the result.
2163
2164 proc check_effective_target_vect_sdot_qi { } {
2165     global et_vect_sdot_qi
2166
2167     if [info exists et_vect_sdot_qi_saved] {
2168         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
2169     } else {
2170         set et_vect_sdot_qi_saved 0
2171     }
2172     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
2173     return $et_vect_sdot_qi_saved
2174 }
2175
2176 # Return 1 if the target plus current options supports a vector
2177 # dot-product of unsigned chars, 0 otherwise.
2178 #
2179 # This won't change for different subtargets so cache the result.
2180
2181 proc check_effective_target_vect_udot_qi { } {
2182     global et_vect_udot_qi
2183
2184     if [info exists et_vect_udot_qi_saved] {
2185         verbose "check_effective_target_vect_udot_qi: using cached result" 2
2186     } else {
2187         set et_vect_udot_qi_saved 0
2188         if { [istarget powerpc*-*-*] } {
2189             set et_vect_udot_qi_saved 1
2190         }
2191     }
2192     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
2193     return $et_vect_udot_qi_saved
2194 }
2195
2196 # Return 1 if the target plus current options supports a vector
2197 # dot-product of signed shorts, 0 otherwise.
2198 #
2199 # This won't change for different subtargets so cache the result.
2200
2201 proc check_effective_target_vect_sdot_hi { } {
2202     global et_vect_sdot_hi
2203
2204     if [info exists et_vect_sdot_hi_saved] {
2205         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
2206     } else {
2207         set et_vect_sdot_hi_saved 0
2208         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2209              || [istarget i?86-*-*]
2210              || [istarget x86_64-*-*] } {
2211             set et_vect_sdot_hi_saved 1
2212         }
2213     }
2214     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
2215     return $et_vect_sdot_hi_saved
2216 }
2217
2218 # Return 1 if the target plus current options supports a vector
2219 # dot-product of unsigned shorts, 0 otherwise.
2220 #
2221 # This won't change for different subtargets so cache the result.
2222
2223 proc check_effective_target_vect_udot_hi { } {
2224     global et_vect_udot_hi
2225
2226     if [info exists et_vect_udot_hi_saved] {
2227         verbose "check_effective_target_vect_udot_hi: using cached result" 2
2228     } else {
2229         set et_vect_udot_hi_saved 0
2230         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*]) } {
2231             set et_vect_udot_hi_saved 1
2232         }
2233     }
2234     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
2235     return $et_vect_udot_hi_saved
2236 }
2237
2238
2239 # Return 1 if the target plus current options supports a vector
2240 # demotion (packing) of shorts (to chars) and ints (to shorts) 
2241 # using modulo arithmetic, 0 otherwise.
2242 #
2243 # This won't change for different subtargets so cache the result.
2244                                                                                 
2245 proc check_effective_target_vect_pack_trunc { } {
2246     global et_vect_pack_trunc
2247                                                                                 
2248     if [info exists et_vect_pack_trunc_saved] {
2249         verbose "check_effective_target_vect_pack_trunc: using cached result" 2
2250     } else {
2251         set et_vect_pack_trunc_saved 0
2252         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2253              || [istarget i?86-*-*]
2254              || [istarget x86_64-*-*]
2255              || [istarget spu-*-*] } {
2256             set et_vect_pack_trunc_saved 1
2257         }
2258     }
2259     verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
2260     return $et_vect_pack_trunc_saved
2261 }
2262
2263 # Return 1 if the target plus current options supports a vector
2264 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
2265 #
2266 # This won't change for different subtargets so cache the result.
2267                                    
2268 proc check_effective_target_vect_unpack { } {
2269     global et_vect_unpack
2270                                         
2271     if [info exists et_vect_unpack_saved] {
2272         verbose "check_effective_target_vect_unpack: using cached result" 2
2273     } else {
2274         set et_vect_unpack_saved 0
2275         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
2276              || [istarget i?86-*-*]
2277              || [istarget x86_64-*-*] 
2278              || [istarget spu-*-*] } {
2279             set et_vect_unpack_saved 1
2280         }
2281     }
2282     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
2283     return $et_vect_unpack_saved
2284 }
2285
2286 # Return 1 if the target plus current options does not guarantee
2287 # that its STACK_BOUNDARY is >= the reguired vector alignment.
2288 #
2289 # This won't change for different subtargets so cache the result.
2290
2291 proc check_effective_target_unaligned_stack { } {
2292     global et_unaligned_stack_saved
2293
2294     if [info exists et_unaligned_stack_saved] {
2295         verbose "check_effective_target_unaligned_stack: using cached result" 2
2296     } else {
2297         set et_unaligned_stack_saved 0
2298     }
2299     verbose "check_effective_target_unaligned_stack: returning $et_unaligned_stack_saved" 2
2300     return $et_unaligned_stack_saved
2301 }
2302
2303 # Return 1 if the target plus current options does not support a vector
2304 # alignment mechanism, 0 otherwise.
2305 #
2306 # This won't change for different subtargets so cache the result.
2307
2308 proc check_effective_target_vect_no_align { } {
2309     global et_vect_no_align_saved
2310
2311     if [info exists et_vect_no_align_saved] {
2312         verbose "check_effective_target_vect_no_align: using cached result" 2
2313     } else {
2314         set et_vect_no_align_saved 0
2315         if { [istarget mipsisa64*-*-*]
2316              || [istarget sparc*-*-*]
2317              || [istarget ia64-*-*]
2318              || [check_effective_target_arm32] } { 
2319             set et_vect_no_align_saved 1
2320         }
2321     }
2322     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
2323     return $et_vect_no_align_saved
2324 }
2325
2326 # Return 1 if the target supports a vector misalign access, 0 otherwise.
2327 #
2328 # This won't change for different subtargets so cache the result.
2329
2330 proc check_effective_target_vect_hw_misalign { } {
2331     global et_vect_hw_misalign_saved
2332
2333     if [info exists et_vect_hw_misalign_saved] {
2334         verbose "check_effective_target_vect_hw_misalign: using cached result" 2
2335     } else {
2336         set et_vect_hw_misalign_saved 0
2337        if { ([istarget x86_64-*-*] 
2338             || [istarget i?86-*-*]) } {
2339           set et_vect_hw_misalign_saved 1
2340        }
2341     }
2342     verbose "check_effective_target_vect_hw_misalign: returning $et_vect_hw_misalign_saved" 2
2343     return $et_vect_hw_misalign_saved
2344 }
2345
2346
2347 # Return 1 if arrays are aligned to the vector alignment
2348 # boundary, 0 otherwise.
2349 #
2350 # This won't change for different subtargets so cache the result.
2351
2352 proc check_effective_target_vect_aligned_arrays { } {
2353     global et_vect_aligned_arrays
2354
2355     if [info exists et_vect_aligned_arrays_saved] {
2356         verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
2357     } else {
2358         set et_vect_aligned_arrays_saved 0
2359         if { (([istarget x86_64-*-*]
2360               || [istarget i?86-*-*]) && [is-effective-target lp64])
2361               || [istarget spu-*-*] } {
2362             set et_vect_aligned_arrays_saved 1
2363         }
2364     }
2365     verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
2366     return $et_vect_aligned_arrays_saved
2367 }
2368
2369 # Return 1 if types of size 32 bit or less are naturally aligned
2370 # (aligned to their type-size), 0 otherwise.
2371 #
2372 # This won't change for different subtargets so cache the result.
2373
2374 proc check_effective_target_natural_alignment_32 { } {
2375     global et_natural_alignment_32
2376
2377     if [info exists et_natural_alignment_32_saved] {
2378         verbose "check_effective_target_natural_alignment_32: using cached result" 2
2379     } else {
2380         # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
2381         set et_natural_alignment_32_saved 1
2382         if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } {
2383             set et_natural_alignment_32_saved 0
2384         }
2385     }
2386     verbose "check_effective_target_natural_alignment_32: returning $et_natural_alignment_32_saved" 2
2387     return $et_natural_alignment_32_saved
2388 }
2389
2390 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
2391 # type-size), 0 otherwise.
2392 #
2393 # This won't change for different subtargets so cache the result.
2394
2395 proc check_effective_target_natural_alignment_64 { } {
2396     global et_natural_alignment_64
2397
2398     if [info exists et_natural_alignment_64_saved] {
2399         verbose "check_effective_target_natural_alignment_64: using cached result" 2
2400     } else {
2401         set et_natural_alignment_64_saved 0
2402         if { ([is-effective-target lp64] && ![istarget *-*-darwin*])
2403              || [istarget spu-*-*] } {
2404             set et_natural_alignment_64_saved 1
2405         }
2406     }
2407     verbose "check_effective_target_natural_alignment_64: returning $et_natural_alignment_64_saved" 2
2408     return $et_natural_alignment_64_saved
2409 }
2410
2411 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
2412 #
2413 # This won't change for different subtargets so cache the result.
2414
2415 proc check_effective_target_vector_alignment_reachable { } {
2416     global et_vector_alignment_reachable
2417
2418     if [info exists et_vector_alignment_reachable_saved] {
2419         verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
2420     } else {
2421         if { [check_effective_target_vect_aligned_arrays]
2422              || [check_effective_target_natural_alignment_32] } {
2423             set et_vector_alignment_reachable_saved 1
2424         } else {
2425             set et_vector_alignment_reachable_saved 0
2426         }
2427     }
2428     verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
2429     return $et_vector_alignment_reachable_saved
2430 }
2431
2432 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
2433 #
2434 # This won't change for different subtargets so cache the result.
2435
2436 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
2437     global et_vector_alignment_reachable_for_64bit
2438
2439     if [info exists et_vector_alignment_reachable_for_64bit_saved] {
2440         verbose "check_effective_target_vector_alignment_reachable_for_64bit: using cached result" 2
2441     } else {
2442         if { [check_effective_target_vect_aligned_arrays] 
2443              || [check_effective_target_natural_alignment_64] } {
2444             set et_vector_alignment_reachable_for_64bit_saved 1
2445         } else {
2446             set et_vector_alignment_reachable_for_64bit_saved 0
2447         }
2448     }
2449     verbose "check_effective_target_vector_alignment_reachable_for_64bit: returning $et_vector_alignment_reachable_for_64bit_saved" 2
2450     return $et_vector_alignment_reachable_for_64bit_saved
2451 }
2452
2453 # Return 1 if the target supports vector conditional operations, 0 otherwise.
2454
2455 proc check_effective_target_vect_condition { } {
2456     global et_vect_cond_saved
2457
2458     if [info exists et_vect_cond_saved] {
2459         verbose "check_effective_target_vect_cond: using cached result" 2
2460     } else {
2461         set et_vect_cond_saved 0
2462         if { [istarget powerpc*-*-*]
2463              || [istarget ia64-*-*]
2464              || [istarget i?86-*-*]
2465              || [istarget spu-*-*]
2466              || [istarget x86_64-*-*] } {
2467            set et_vect_cond_saved 1
2468         }
2469     }
2470
2471     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
2472     return $et_vect_cond_saved
2473 }
2474
2475 # Return 1 if the target supports vector char multiplication, 0 otherwise.
2476
2477 proc check_effective_target_vect_char_mult { } {
2478     global et_vect_char_mult_saved
2479
2480     if [info exists et_vect_char_mult_saved] {
2481         verbose "check_effective_target_vect_char_mult: using cached result" 2
2482     } else {
2483         set et_vect_char_mult_saved 0
2484         if { [istarget ia64-*-*]
2485              || [istarget i?86-*-*]
2486              || [istarget x86_64-*-*] } {
2487            set et_vect_char_mult_saved 1
2488         }
2489     }
2490
2491     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
2492     return $et_vect_char_mult_saved
2493 }
2494
2495 # Return 1 if the target supports vector short multiplication, 0 otherwise.
2496
2497 proc check_effective_target_vect_short_mult { } {
2498     global et_vect_short_mult_saved
2499
2500     if [info exists et_vect_short_mult_saved] {
2501         verbose "check_effective_target_vect_short_mult: using cached result" 2
2502     } else {
2503         set et_vect_short_mult_saved 0
2504         if { [istarget ia64-*-*]
2505              || [istarget spu-*-*]
2506              || [istarget i?86-*-*]
2507              || [istarget x86_64-*-*] 
2508              || [istarget powerpc*-*-*] 
2509              || [check_effective_target_arm32] } {
2510            set et_vect_short_mult_saved 1
2511         }
2512     }
2513
2514     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
2515     return $et_vect_short_mult_saved
2516 }
2517
2518 # Return 1 if the target supports vector int multiplication, 0 otherwise.
2519
2520 proc check_effective_target_vect_int_mult { } {
2521     global et_vect_int_mult_saved
2522
2523     if [info exists et_vect_int_mult_saved] {
2524         verbose "check_effective_target_vect_int_mult: using cached result" 2
2525     } else {
2526         set et_vect_int_mult_saved 0
2527         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2528              || [istarget spu-*-*]
2529              || [istarget i?86-*-*]
2530              || [istarget x86_64-*-*]
2531              || [check_effective_target_arm32] } {
2532            set et_vect_int_mult_saved 1
2533         }
2534     }
2535
2536     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
2537     return $et_vect_int_mult_saved
2538 }
2539
2540 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
2541
2542 proc check_effective_target_vect_extract_even_odd { } {
2543     global et_vect_extract_even_odd_saved
2544     
2545     if [info exists et_vect_extract_even_odd_saved] {
2546         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
2547     } else {
2548         set et_vect_extract_even_odd_saved 0 
2549         if { [istarget powerpc*-*-*]
2550              || [istarget spu-*-*] } {
2551            set et_vect_extract_even_odd_saved 1
2552         }
2553     }
2554
2555     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
2556     return $et_vect_extract_even_odd_saved
2557 }
2558
2559 # Return 1 if the target supports vector even/odd elements extraction of
2560 # vectors with SImode elements or larger, 0 otherwise.
2561
2562 proc check_effective_target_vect_extract_even_odd_wide { } {
2563     global et_vect_extract_even_odd_wide_saved
2564     
2565     if [info exists et_vect_extract_even_odd_wide_saved] {
2566         verbose "check_effective_target_vect_extract_even_odd_wide: using cached result" 2
2567     } else {
2568         set et_vect_extract_even_odd_wide_saved 0 
2569         if { [istarget powerpc*-*-*] 
2570              || [istarget i?86-*-*]
2571              || [istarget x86_64-*-*]
2572              || [istarget spu-*-*] } {
2573            set et_vect_extract_even_odd_wide_saved 1
2574         }
2575     }
2576
2577     verbose "check_effective_target_vect_extract_even_wide_odd: returning $et_vect_extract_even_odd_wide_saved" 2
2578     return $et_vect_extract_even_odd_wide_saved
2579 }
2580
2581 # Return 1 if the target supports vector interleaving, 0 otherwise.
2582
2583 proc check_effective_target_vect_interleave { } {
2584     global et_vect_interleave_saved
2585     
2586     if [info exists et_vect_interleave_saved] {
2587         verbose "check_effective_target_vect_interleave: using cached result" 2
2588     } else {
2589         set et_vect_interleave_saved 0
2590         if { [istarget powerpc*-*-*]
2591              || [istarget i?86-*-*]
2592              || [istarget x86_64-*-*]
2593              || [istarget spu-*-*] } {
2594            set et_vect_interleave_saved 1
2595         }
2596     }
2597
2598     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
2599     return $et_vect_interleave_saved
2600 }
2601
2602 # Return 1 if the target supports vector interleaving and extract even/odd, 0 otherwise.
2603 proc check_effective_target_vect_strided { } {
2604     global et_vect_strided_saved
2605
2606     if [info exists et_vect_strided_saved] {
2607         verbose "check_effective_target_vect_strided: using cached result" 2
2608     } else {
2609         set et_vect_strided_saved 0
2610         if { [check_effective_target_vect_interleave]
2611              && [check_effective_target_vect_extract_even_odd] } {
2612            set et_vect_strided_saved 1
2613         }
2614     }
2615
2616     verbose "check_effective_target_vect_strided: returning $et_vect_strided_saved" 2
2617     return $et_vect_strided_saved
2618 }
2619
2620 # Return 1 if the target supports vector interleaving and extract even/odd
2621 # for wide element types, 0 otherwise.
2622 proc check_effective_target_vect_strided_wide { } {
2623     global et_vect_strided_wide_saved
2624
2625     if [info exists et_vect_strided_wide_saved] {
2626         verbose "check_effective_target_vect_strided_wide: using cached result" 2
2627     } else {
2628         set et_vect_strided_wide_saved 0
2629         if { [check_effective_target_vect_interleave]
2630              && [check_effective_target_vect_extract_even_odd_wide] } {
2631            set et_vect_strided_wide_saved 1
2632         }
2633     }
2634
2635     verbose "check_effective_target_vect_strided_wide: returning $et_vect_strided_wide_saved" 2
2636     return $et_vect_strided_wide_saved
2637 }
2638
2639 # Return 1 if the target supports section-anchors
2640
2641 proc check_effective_target_section_anchors { } {
2642     global et_section_anchors_saved
2643
2644     if [info exists et_section_anchors_saved] {
2645         verbose "check_effective_target_section_anchors: using cached result" 2
2646     } else {
2647         set et_section_anchors_saved 0
2648         if { [istarget powerpc*-*-*] 
2649               || [istarget arm*-*-*] } {
2650            set et_section_anchors_saved 1
2651         }
2652     }
2653
2654     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
2655     return $et_section_anchors_saved
2656 }
2657
2658 # Return 1 if the target supports atomic operations on "int" and "long".
2659
2660 proc check_effective_target_sync_int_long { } {
2661     global et_sync_int_long_saved
2662
2663     if [info exists et_sync_int_long_saved] {
2664         verbose "check_effective_target_sync_int_long: using cached result" 2
2665     } else {
2666         set et_sync_int_long_saved 0
2667 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2668 # load-reserved/store-conditional instructions.
2669         if { [istarget ia64-*-*]
2670              || [istarget i?86-*-*]
2671              || [istarget x86_64-*-*]
2672              || [istarget alpha*-*-*] 
2673              || [istarget s390*-*-*] 
2674              || [istarget powerpc*-*-*]
2675              || [istarget sparc64-*-*]
2676              || [istarget sparcv9-*-*]
2677              || [istarget mips*-*-*] } {
2678            set et_sync_int_long_saved 1
2679         }
2680     }
2681
2682     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2683     return $et_sync_int_long_saved
2684 }
2685
2686 # Return 1 if the target supports atomic operations on "char" and "short".
2687
2688 proc check_effective_target_sync_char_short { } {
2689     global et_sync_char_short_saved
2690
2691     if [info exists et_sync_char_short_saved] {
2692         verbose "check_effective_target_sync_char_short: using cached result" 2
2693     } else {
2694         set et_sync_char_short_saved 0
2695 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2696 # load-reserved/store-conditional instructions.
2697         if { [istarget ia64-*-*]
2698              || [istarget i?86-*-*]
2699              || [istarget x86_64-*-*]
2700              || [istarget alpha*-*-*] 
2701              || [istarget s390*-*-*] 
2702              || [istarget powerpc*-*-*]
2703              || [istarget sparc64-*-*]
2704              || [istarget sparcv9-*-*]
2705              || [istarget mips*-*-*] } {
2706            set et_sync_char_short_saved 1
2707         }
2708     }
2709
2710     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2711     return $et_sync_char_short_saved
2712 }
2713
2714 # Return 1 if the target uses a ColdFire FPU.
2715
2716 proc check_effective_target_coldfire_fpu { } {
2717     return [check_no_compiler_messages coldfire_fpu assembly {
2718         #ifndef __mcffpu__
2719         #error FOO
2720         #endif
2721     }]
2722 }
2723
2724 # Return true if this is a uClibc target.
2725
2726 proc check_effective_target_uclibc {} {
2727     return [check_no_compiler_messages uclibc object {
2728         #include <features.h>
2729         #if !defined (__UCLIBC__)
2730         #error FOO
2731         #endif
2732     }]
2733 }
2734
2735 # Return true if this is a uclibc target and if the uclibc feature
2736 # described by __$feature__ is not present.
2737
2738 proc check_missing_uclibc_feature {feature} {
2739     return [check_no_compiler_messages $feature object "
2740         #include <features.h>
2741         #if !defined (__UCLIBC) || defined (__${feature}__)
2742         #error FOO
2743         #endif
2744     "]
2745 }
2746
2747 # Return true if this is a Newlib target.
2748
2749 proc check_effective_target_newlib {} {
2750     return [check_no_compiler_messages newlib object {
2751         #include <newlib.h>
2752     }]
2753 }
2754
2755 # Return 1 if
2756 #   (a) an error of a few ULP is expected in string to floating-point
2757 #       conversion functions; and
2758 #   (b) overflow is not always detected correctly by those functions.
2759
2760 proc check_effective_target_lax_strtofp {} {
2761     # By default, assume that all uClibc targets suffer from this.
2762     return [check_effective_target_uclibc]
2763 }
2764
2765 # Return 1 if this is a target for which wcsftime is a dummy
2766 # function that always returns 0.
2767
2768 proc check_effective_target_dummy_wcsftime {} {
2769     # By default, assume that all uClibc targets suffer from this.
2770     return [check_effective_target_uclibc]
2771 }
2772
2773 # Return 1 if constructors with initialization priority arguments are
2774 # supposed on this target.
2775
2776 proc check_effective_target_init_priority {} {
2777     return [check_no_compiler_messages init_priority assembly "
2778         void f() __attribute__((constructor (1000)));
2779         void f() \{\}
2780     "]
2781 }
2782
2783 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2784 # This can be used with any check_* proc that takes no argument and
2785 # returns only 1 or 0.  It could be used with check_* procs that take
2786 # arguments with keywords that pass particular arguments.
2787
2788 proc is-effective-target { arg } {
2789     set selected 0
2790     if { [info procs check_effective_target_${arg}] != [list] } {
2791         set selected [check_effective_target_${arg}]
2792     } else {
2793         switch $arg {
2794           "vmx_hw"         { set selected [check_vmx_hw_available] }
2795           "named_sections" { set selected [check_named_sections_available] }
2796           "gc_sections"    { set selected [check_gc_sections_available] }
2797           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
2798           default          { error "unknown effective target keyword `$arg'" }
2799         }
2800     }
2801     verbose "is-effective-target: $arg $selected" 2
2802     return $selected
2803 }
2804
2805 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2806
2807 proc is-effective-target-keyword { arg } {
2808     if { [info procs check_effective_target_${arg}] != [list] } {
2809         return 1
2810     } else {
2811         # These have different names for their check_* procs.
2812         switch $arg {
2813           "vmx_hw"         { return 1 }
2814           "named_sections" { return 1 }
2815           "gc_sections"    { return 1 }
2816           "cxa_atexit"     { return 1 }
2817           default          { return 0 }
2818         }
2819     }
2820 }
2821
2822 # Return 1 if target default to short enums
2823
2824 proc check_effective_target_short_enums { } {
2825     return [check_no_compiler_messages short_enums assembly {
2826         enum foo { bar };
2827         int s[sizeof (enum foo) == 1 ? 1 : -1];
2828     }]
2829 }
2830
2831 # Return 1 if target supports merging string constants at link time.
2832
2833 proc check_effective_target_string_merging { } {
2834     return [check_no_messages_and_pattern string_merging \
2835                 "rodata\\.str" assembly {
2836                     const char *var = "String";
2837                 } {-O2}]
2838 }
2839
2840 # Return 1 if target has the basic signed and unsigned types in
2841 # <stdint.h>, 0 otherwise.  This will be obsolete when GCC ensures a
2842 # working <stdint.h> for all targets.
2843
2844 proc check_effective_target_stdint_types { } {
2845     return [check_no_compiler_messages stdint_types assembly {
2846         #include <stdint.h>
2847         int8_t a; int16_t b; int32_t c; int64_t d;
2848         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2849     }]
2850 }
2851
2852 # Return 1 if target has the basic signed and unsigned types in
2853 # <inttypes.h>, 0 otherwise.  This is for tests that GCC's notions of
2854 # these types agree with those in the header, as some systems have
2855 # only <inttypes.h>.
2856
2857 proc check_effective_target_inttypes_types { } {
2858     return [check_no_compiler_messages inttypes_types assembly {
2859         #include <inttypes.h>
2860         int8_t a; int16_t b; int32_t c; int64_t d;
2861         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2862     }]
2863 }
2864
2865 # Return 1 if programs are intended to be run on a simulator
2866 # (i.e. slowly) rather than hardware (i.e. fast).
2867
2868 proc check_effective_target_simulator { } {
2869
2870     # All "src/sim" simulators set this one.
2871     if [board_info target exists is_simulator] {
2872         return [board_info target is_simulator]
2873     }
2874
2875     # The "sid" simulators don't set that one, but at least they set
2876     # this one.
2877     if [board_info target exists slow_simulator] {
2878         return [board_info target slow_simulator]
2879     }
2880
2881     return 0
2882 }
2883
2884 # Return 1 if the target is a VxWorks kernel.
2885
2886 proc check_effective_target_vxworks_kernel { } {
2887     return [check_no_compiler_messages vxworks_kernel assembly {
2888         #if !defined __vxworks || defined __RTP__
2889         #error NO
2890         #endif
2891     }]
2892 }
2893
2894 # Return 1 if the target is a VxWorks RTP.
2895
2896 proc check_effective_target_vxworks_rtp { } {
2897     return [check_no_compiler_messages vxworks_rtp assembly {
2898         #if !defined __vxworks || !defined __RTP__
2899         #error NO
2900         #endif
2901     }]
2902 }
2903
2904 # Return 1 if the target is expected to provide wide character support.
2905
2906 proc check_effective_target_wchar { } {
2907     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2908         return 0
2909     }
2910     return [check_no_compiler_messages wchar assembly {
2911         #include <wchar.h>
2912     }]
2913 }
2914
2915 # Return 1 if the target has <pthread.h>.
2916
2917 proc check_effective_target_pthread_h { } {
2918     return [check_no_compiler_messages pthread_h assembly {
2919         #include <pthread.h>
2920     }]
2921 }
2922
2923 # Return 1 if the target can truncate a file from a file-descriptor,
2924 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
2925 # chsize.  We test for a trivially functional truncation; no stubs.
2926 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
2927 # different function to be used.
2928
2929 proc check_effective_target_fd_truncate { } {
2930     set prog {
2931         #define _FILE_OFFSET_BITS 64
2932         #include <unistd.h>
2933         #include <stdio.h>
2934         #include <stdlib.h>
2935         int main ()
2936         {
2937           FILE *f = fopen ("tst.tmp", "wb");
2938           int fd;
2939           const char t[] = "test writing more than ten characters";
2940           char s[11];
2941           fd =  fileno (f);
2942           write (fd, t, sizeof (t) - 1);
2943           lseek (fd, 0, 0);
2944           if (ftruncate (fd, 10) != 0)
2945             exit (1);
2946           close (fd);
2947           f = fopen ("tst.tmp", "rb");
2948           if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
2949             exit (1);
2950           exit (0);
2951         }
2952     }
2953
2954     if { [check_runtime ftruncate $prog] } {
2955       return 1;
2956     }
2957
2958     regsub "ftruncate" $prog "chsize" prog
2959     return [check_runtime chsize $prog]
2960 }
2961
2962 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
2963
2964 proc add_options_for_c99_runtime { flags } {
2965     if { [istarget *-*-solaris2*] } {
2966         return "$flags -std=c99"
2967     }
2968     if { [istarget powerpc-*-darwin*] } {
2969         return "$flags -mmacosx-version-min=10.3"
2970     }
2971     return $flags
2972 }
2973
2974 # Return 1 if the target provides a full C99 runtime.
2975
2976 proc check_effective_target_c99_runtime { } {
2977     return [check_cached_effective_target c99_runtime {
2978         global srcdir
2979
2980         set file [open "$srcdir/gcc.dg/builtins-config.h"]
2981         set contents [read $file]
2982         close $file
2983         append contents {
2984             #ifndef HAVE_C99_RUNTIME
2985             #error FOO
2986             #endif
2987         }
2988         check_no_compiler_messages_nocache c99_runtime assembly \
2989             $contents [add_options_for_c99_runtime ""]
2990     }]
2991 }
2992
2993 # Return 1 if  target wchar_t is at least 4 bytes.
2994
2995 proc check_effective_target_4byte_wchar_t { } {
2996     return [check_no_compiler_messages 4byte_wchar_t object {
2997         int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
2998     }]
2999 }
3000
3001 # Return 1 if the target supports automatic stack alignment.
3002
3003 proc check_effective_target_automatic_stack_alignment  { } {
3004     if { [istarget i?86*-*-*]
3005          || [istarget x86_64-*-*] } then {
3006         return 1
3007     } else {
3008         return 0
3009     }
3010 }
3011
3012 # Return 1 if avx instructions can be compiled.
3013
3014 proc check_effective_target_avx { } {
3015     return [check_no_compiler_messages avx object {
3016         void _mm256_zeroall (void)
3017         {
3018            __builtin_ia32_vzeroall ();
3019         }
3020     } "-O2 -mavx" ]
3021 }
3022
3023 # Return 1 if C wchar_t type is compatible with char16_t.
3024
3025 proc check_effective_target_wchar_t_char16_t_compatible { } {
3026     return [check_no_compiler_messages wchar_t_char16_t object {
3027         __WCHAR_TYPE__ wc;
3028         __CHAR16_TYPE__ *p16 = &wc;
3029         char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
3030     }]
3031 }
3032
3033 # Return 1 if C wchar_t type is compatible with char32_t.
3034
3035 proc check_effective_target_wchar_t_char32_t_compatible { } {
3036     return [check_no_compiler_messages wchar_t_char32_t object {
3037         __WCHAR_TYPE__ wc;
3038         __CHAR32_TYPE__ *p32 = &wc;
3039         char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
3040     }]
3041 }
3042
3043 # Return 1 if pow10 function exists.
3044
3045 proc check_effective_target_pow10 { } {
3046     return [check_runtime pow10 {
3047         #include <math.h>
3048         int main () {
3049         double x;
3050         x = pow10 (1);
3051         return 0;
3052         }
3053     } "-lm" ]
3054 }
3055
3056 # Return 1 if current options generate DFP instructions, 0 otherwise.
3057
3058 proc check_effective_target_hard_dfp {} {
3059     return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
3060         _Decimal64 x, y, z;
3061         void foo (void) { z = x + y; }
3062     }]
3063 }
3064
3065 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
3066 # for strchr etc. functions.
3067
3068 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
3069     return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
3070         #include <string.h>
3071         #include <wchar.h>
3072         #if !defined(__cplusplus) \
3073             || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
3074             || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
3075         ISO C++ correct string.h and wchar.h protos not supported.
3076         #else
3077         int i;
3078         #endif
3079     }]
3080 }
3081
3082 # Return 1 if the MPC library is integrated with GCC, 0 otherwise.
3083
3084 proc check_effective_target_mpc { } {
3085     return [check_no_compiler_messages mpc executable {
3086         extern void link_error(void);
3087         int main ()
3088         {
3089           if (__builtin_csin(0) != 0)
3090             link_error();
3091         }
3092     }]
3093 }
3094
3095 # Return 1 if the MPC library with mpc_pow is integrated with GCC, 0 otherwise.
3096
3097 proc check_effective_target_mpc_pow { } {
3098     return [check_no_compiler_messages mpc_pow executable {
3099         extern void link_error(void);
3100         int main ()
3101         {
3102           if (__builtin_cpow(1,1) != 1)
3103             link_error();
3104         }
3105     }]
3106 }
3107
3108 # Return 1 if the language for the compiler under test is C.
3109
3110 proc check_effective_target_c { } {
3111  global tool
3112     if [string match $tool "gcc"] {
3113    return 1
3114     }
3115  return 0
3116 }
3117
3118 # Return 1 if the language for the compiler under test is C++.
3119
3120 proc check_effective_target_c++ { } {
3121  global tool
3122     if [string match $tool "g++"] {
3123    return 1
3124     }
3125  return 0
3126 }