OSDN Git Service

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