OSDN Git Service

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