OSDN Git Service

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