OSDN Git Service

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