OSDN Git Service

2d14dde2ad5a4bc5f1fcfdf7ccf23298717c4480
[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 true if profiling is supported on the target.
402
403 proc check_profiling_available { test_what } {
404     global profiling_available_saved
405
406     verbose "Profiling argument is <$test_what>" 1
407
408     # These conditions depend on the argument so examine them before
409     # looking at the cache variable.
410
411     # Support for -p on solaris2 relies on mcrt1.o which comes with the
412     # vendor compiler.  We cannot reliably predict the directory where the
413     # vendor compiler (and thus mcrt1.o) is installed so we can't
414     # necessarily find mcrt1.o even if we have it.
415     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
416         return 0
417     }
418
419     # Support for -p on irix relies on libprof1.a which doesn't appear to
420     # exist on any irix6 system currently posting testsuite results.
421     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
422     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
423     if { [istarget mips*-*-irix*]
424     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
425         return 0
426     }
427
428     # MinGW does not support -p.
429     if { [istarget *-*-mingw*] && [lindex $test_what 1] == "-p" } {
430         return 0
431     }
432
433     # At present, there is no profiling support on NetWare.
434     if { [istarget *-*-netware*] } {
435         return 0
436     }
437
438     # uClibc does not have gcrt1.o.
439     if { [check_effective_target_uclibc]
440          && ([lindex $test_what 1] == "-p"
441              || [lindex $test_what 1] == "-pg") } {
442         return 0
443     }
444
445     # Now examine the cache variable.
446     if {![info exists profiling_available_saved]} {
447         # Some targets don't have any implementation of __bb_init_func or are
448         # missing other needed machinery.
449         if { [istarget mmix-*-*]
450              || [istarget arm*-*-eabi*]
451              || [istarget arm*-*-elf]
452              || [istarget arm*-*-symbianelf*]
453              || [istarget avr-*-*]
454              || [istarget bfin-*-*]
455              || [istarget powerpc-*-eabi*]
456              || [istarget strongarm*-*-elf]
457              || [istarget xscale*-*-elf]
458              || [istarget cris-*-*]
459              || [istarget crisv32-*-*]
460              || [istarget fido-*-elf]
461              || [istarget h8300-*-*]
462              || [istarget m32c-*-elf]
463              || [istarget m68k-*-elf]
464              || [istarget m68k-*-uclinux*]
465              || [istarget mips*-*-elf*]
466              || [istarget xstormy16-*]
467              || [istarget xtensa-*-elf]
468              || [istarget *-*-vxworks*]
469              || [istarget *-*-windiss] } {
470             set profiling_available_saved 0
471         } else {
472             set profiling_available_saved 1
473         }
474     }
475
476     return $profiling_available_saved
477 }
478
479 # Return 1 if target has packed layout of structure members by
480 # default, 0 otherwise.  Note that this is slightly different than
481 # whether the target has "natural alignment": both attributes may be
482 # false.
483
484 proc check_effective_target_default_packed { } {
485     return [check_no_compiler_messages default_packed assembly {
486         struct x { char a; long b; } c;
487         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
488     }]
489 }
490
491 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
492 # documentation, where the test also comes from.
493
494 proc check_effective_target_pcc_bitfield_type_matters { } {
495     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
496     # bitfields, but let's stick to the example code from the docs.
497     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
498         struct foo1 { char x; char :0; char y; };
499         struct foo2 { char x; int :0; char y; };
500         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
501     }]
502 }
503
504 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
505 #
506 # This won't change for different subtargets so cache the result.
507
508 proc check_effective_target_tls {} {
509     return [check_no_compiler_messages tls assembly {
510         __thread int i;
511         int f (void) { return i; }
512         void g (int j) { i = j; }
513     }]
514 }
515
516 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
517 #
518 # This won't change for different subtargets so cache the result.
519
520 proc check_effective_target_tls_native {} {
521     # VxWorks uses emulated TLS machinery, but with non-standard helper
522     # functions, so we fail to automatically detect it.
523     global target_triplet
524     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
525         return 0
526     }
527     
528     return [check_no_messages_and_pattern tls_native "!emutls" 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 TLS executables can run correctly, 0 otherwise.
536 #
537 # This won't change for different subtargets so cache the result.
538
539 proc check_effective_target_tls_runtime {} {
540     return [check_runtime tls_runtime {
541         __thread int thr = 0;
542         int main (void) { return thr; }
543     }]
544 }
545
546 # Return 1 if compilation with -fopenmp is error-free for trivial
547 # code, 0 otherwise.
548
549 proc check_effective_target_fopenmp {} {
550     return [check_no_compiler_messages fopenmp object {
551         void foo (void) { }
552     } "-fopenmp"]
553 }
554
555 # Return 1 if compilation with -pthread is error-free for trivial
556 # code, 0 otherwise.
557
558 proc check_effective_target_pthread {} {
559     return [check_no_compiler_messages pthread object {
560         void foo (void) { }
561     } "-pthread"]
562 }
563
564 # Return 1 if the target supports -fstack-protector
565 proc check_effective_target_fstack_protector {} {
566     return [check_runtime fstack_protector {
567         int main (void) { return 0; }
568     } "-fstack-protector"]
569 }
570
571 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
572 # for trivial code, 0 otherwise.
573
574 proc check_effective_target_freorder {} {
575     return [check_no_compiler_messages freorder object {
576         void foo (void) { }
577     } "-freorder-blocks-and-partition"]
578 }
579
580 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
581 # emitted, 0 otherwise.  Whether a shared library can actually be built is
582 # out of scope for this test.
583
584 proc check_effective_target_fpic { } {
585     # Note that M68K has a multilib that supports -fpic but not
586     # -fPIC, so we need to check both.  We test with a program that
587     # requires GOT references.
588     foreach arg {fpic fPIC} {
589         if [check_no_compiler_messages $arg object {
590             extern int foo (void); extern int bar;
591             int baz (void) { return foo () + bar; }
592         } "-$arg"] {
593             return 1
594         }
595     }
596     return 0
597 }
598
599 # Return true if the target supports -mpaired-single (as used on MIPS).
600
601 proc check_effective_target_mpaired_single { } {
602     return [check_no_compiler_messages mpaired_single object {
603         void foo (void) { }
604     } "-mpaired-single"]
605 }
606
607 # Return true if the target has access to FPU instructions.
608
609 proc check_effective_target_hard_float { } {
610     if { [istarget mips*-*-*] } {
611         return [check_no_compiler_messages hard_float assembly {
612                 #if (defined __mips_soft_float || defined __mips16)
613                 #error FOO
614                 #endif
615         }]
616     }
617
618     # The generic test equates hard_float with "no call for adding doubles".
619     return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
620         double a (double b, double c) { return b + c; }
621     }]
622 }
623
624 # Return true if the target is a 64-bit MIPS target.
625
626 proc check_effective_target_mips64 { } {
627     return [check_no_compiler_messages mips64 assembly {
628         #ifndef __mips64
629         #error FOO
630         #endif
631     }]
632 }
633
634 # Return true if the target is a MIPS target that does not produce
635 # MIPS16 code.
636
637 proc check_effective_target_nomips16 { } {
638     return [check_no_compiler_messages nomips16 object {
639         #ifndef __mips
640         #error FOO
641         #else
642         /* A cheap way of testing for -mflip-mips16.  */
643         void foo (void) { asm ("addiu $20,$20,1"); }
644         void bar (void) { asm ("addiu $20,$20,1"); }
645         #endif
646     }]
647 }
648
649 # Add the options needed for MIPS16 function attributes.  At the moment,
650 # we don't support MIPS16 PIC.
651
652 proc add_options_for_mips16_attribute { flags } {
653     return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
654 }
655
656 # Return true if we can force a mode that allows MIPS16 code generation.
657 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
658 # for o32 and o64.
659
660 proc check_effective_target_mips16_attribute { } {
661     return [check_no_compiler_messages mips16_attribute assembly {
662         #ifdef PIC
663         #error FOO
664         #endif
665         #if defined __mips_hard_float \
666             && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
667             && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
668         #error FOO
669         #endif
670     } [add_options_for_mips16_attribute ""]]
671 }
672
673 # Return 1 if the current multilib does not generate PIC by default.
674
675 proc check_effective_target_nonpic { } {
676     return [check_no_compiler_messages nonpic assembly {
677         #if __PIC__
678         #error FOO
679         #endif
680     }]
681 }
682
683 # Return 1 if the target does not use a status wrapper.
684
685 proc check_effective_target_unwrapped { } {
686     if { [target_info needs_status_wrapper] != "" \
687              && [target_info needs_status_wrapper] != "0" } {
688         return 0
689     }
690     return 1
691 }
692
693 # Return true if iconv is supported on the target. In particular IBM1047.
694
695 proc check_iconv_available { test_what } {
696     global libiconv
697
698     # If the tool configuration file has not set libiconv, try "-liconv"
699     if { ![info exists libiconv] } {
700         set libiconv "-liconv"
701     }
702     set test_what [lindex $test_what 1]
703     return [check_runtime_nocache $test_what [subst {
704         #include <iconv.h>
705         int main (void)
706         {
707           iconv_t cd;
708
709           cd = iconv_open ("$test_what", "UTF-8");
710           if (cd == (iconv_t) -1)
711             return 1;
712           return 0;
713         }
714     }] $libiconv]
715 }
716
717 # Return true if named sections are supported on this target.
718
719 proc check_named_sections_available { } {
720     return [check_no_compiler_messages named_sections assembly {
721         int __attribute__ ((section("whatever"))) foo;
722     }]
723 }
724
725 # Return 1 if the target supports Fortran real kinds larger than real(8),
726 # 0 otherwise.
727 #
728 # When the target name changes, replace the cached result.
729
730 proc check_effective_target_fortran_large_real { } {
731     return [check_no_compiler_messages fortran_large_real executable {
732         ! Fortran
733         integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
734         real(kind=k) :: x
735         x = cos (x)
736         end
737     }]
738 }
739
740 # Return 1 if the target supports Fortran integer kinds larger than
741 # integer(8), 0 otherwise.
742 #
743 # When the target name changes, replace the cached result.
744
745 proc check_effective_target_fortran_large_int { } {
746     return [check_no_compiler_messages fortran_large_int executable {
747         ! Fortran
748         integer,parameter :: k = selected_int_kind (range (0_8) + 1)
749         integer(kind=k) :: i
750         end
751     }]
752 }
753
754 # Return 1 if we can statically link libgfortran, 0 otherwise.
755 #
756 # When the target name changes, replace the cached result.
757
758 proc check_effective_target_static_libgfortran { } {
759     return [check_no_compiler_messages static_libgfortran executable {
760         ! Fortran
761         print *, 'test'
762         end
763     } "-static"]
764 }
765
766 # Return 1 if the target supports executing 750CL paired-single instructions, 0
767 # otherwise.  Cache the result.
768
769 proc check_750cl_hw_available { } {
770     return [check_cached_effective_target 750cl_hw_available {
771         # If this is not the right target then we can skip the test.
772         if { ![istarget powerpc-*paired*] } {
773             expr 0
774         } else {
775             check_runtime_nocache 750cl_hw_available {
776                  int main()
777                  {
778                  #ifdef __MACH__
779                    asm volatile ("ps_mul v0,v0,v0");
780                  #else
781                    asm volatile ("ps_mul 0,0,0");
782                  #endif
783                    return 0;
784                  }
785             } "-mpaired"
786         }
787     }]
788 }
789
790 # Return 1 if the target supports executing SSE2 instructions, 0
791 # otherwise.  Cache the result.
792
793 proc check_sse2_hw_available { } {
794     return [check_cached_effective_target sse2_hw_available {
795         # If this is not the right target then we can skip the test.
796         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
797             expr 0
798         } else {
799             check_runtime_nocache sse2_hw_available {
800                 #include "cpuid.h"
801                 int main ()
802                 {
803                   unsigned int eax, ebx, ecx, edx = 0;
804                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
805                     return !(edx & bit_SSE2);
806                   return 1;
807                 }
808             } ""
809         }
810     }]
811 }
812
813 # Return 1 if the target supports executing AltiVec instructions, 0
814 # otherwise.  Cache the result.
815
816 proc check_vmx_hw_available { } {
817     return [check_cached_effective_target vmx_hw_available {
818         # Some simulators are known to not support VMX instructions.
819         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
820             expr 0
821         } else {
822             # Most targets don't require special flags for this test case, but
823             # Darwin does.
824             if { [istarget *-*-darwin*]
825                  || [istarget *-*-aix*] } {
826                 set options "-maltivec"
827             } else {
828                 set options ""
829             }
830             check_runtime_nocache vmx_hw_available {
831                 int main()
832                 {
833                 #ifdef __MACH__
834                   asm volatile ("vor v0,v0,v0");
835                 #else
836                   asm volatile ("vor 0,0,0");
837                 #endif
838                   return 0;
839                 }
840             } $options
841         }
842     }]
843 }
844
845 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
846 # complex float arguments.  This affects gfortran tests that call cabsf
847 # in libm built by an earlier compiler.  Return 1 if libm uses the same
848 # argument passing as the compiler under test, 0 otherwise.
849 #
850 # When the target name changes, replace the cached result.
851
852 proc check_effective_target_broken_cplxf_arg { } {
853     return [check_cached_effective_target broken_cplxf_arg {
854         # Skip the work for targets known not to be affected.
855         if { ![istarget powerpc64-*-linux*] } {
856             expr 0
857         } elseif { ![is-effective-target lp64] } {
858             expr 0
859         } else {
860             check_runtime_nocache broken_cplxf_arg {
861                 #include <complex.h>
862                 extern void abort (void);
863                 float fabsf (float);
864                 float cabsf (_Complex float);
865                 int main ()
866                 {
867                   _Complex float cf;
868                   float f;
869                   cf = 3 + 4.0fi;
870                   f = cabsf (cf);
871                   if (fabsf (f - 5.0) > 0.0001)
872                     abort ();
873                   return 0;
874                 }
875             } "-lm"
876         }
877     }]
878 }
879
880 proc check_alpha_max_hw_available { } {
881     return [check_runtime alpha_max_hw_available {
882         int main() { return __builtin_alpha_amask(1<<8) != 0; }
883     }]
884 }
885
886 # Returns true iff the FUNCTION is available on the target system.
887 # (This is essentially a Tcl implementation of Autoconf's
888 # AC_CHECK_FUNC.)
889
890 proc check_function_available { function } {
891     return [check_no_compiler_messages ${function}_available \
892                 executable [subst {
893         #ifdef __cplusplus
894         extern "C"
895         #endif
896         char $function ();
897         int main () { $function (); }
898     }]]
899 }
900
901 # Returns true iff "fork" is available on the target system.
902
903 proc check_fork_available {} {
904     return [check_function_available "fork"]
905 }
906
907 # Returns true iff "mkfifo" is available on the target system.
908
909 proc check_mkfifo_available {} {
910     if {[istarget *-*-cygwin*]} {
911        # Cygwin has mkfifo, but support is incomplete.
912        return 0
913      }
914
915     return [check_function_available "mkfifo"]
916 }
917
918 # Returns true iff "__cxa_atexit" is used on the target system.
919
920 proc check_cxa_atexit_available { } {
921     return [check_cached_effective_target cxa_atexit_available {
922         if { [istarget "hppa*-*-hpux10*"] } {
923             # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
924             expr 0
925         } else {
926             check_runtime_nocache cxa_atexit_available {
927                 // C++
928                 #include <stdlib.h>
929                 static unsigned int count;
930                 struct X
931                 {
932                   X() { count = 1; }
933                   ~X()
934                   {
935                     if (count != 3)
936                       exit(1);
937                     count = 4;
938                   }
939                 };
940                 void f()
941                 {
942                   static X x;
943                 }
944                 struct Y
945                 {
946                   Y() { f(); count = 2; }
947                   ~Y()
948                   {
949                     if (count != 2)
950                       exit(1);
951                     count = 3;
952                   }
953                 };
954                 Y y;
955                 int main() { return 0; }
956             }
957         }
958     }]
959 }
960
961
962 # Return 1 if we're generating 32-bit code using default options, 0
963 # otherwise.
964
965 proc check_effective_target_ilp32 { } {
966     return [check_no_compiler_messages ilp32 object {
967         int dummy[sizeof (int) == 4
968                   && sizeof (void *) == 4
969                   && sizeof (long) == 4 ? 1 : -1];
970     }]
971 }
972
973 # Return 1 if we're generating 32-bit or larger integers using default
974 # options, 0 otherwise.
975
976 proc check_effective_target_int32plus { } {
977     return [check_no_compiler_messages int32plus object {
978         int dummy[sizeof (int) >= 4 ? 1 : -1];
979     }]
980 }
981
982 # Return 1 if we're generating 32-bit or larger pointers using default
983 # options, 0 otherwise.
984
985 proc check_effective_target_ptr32plus { } {
986     return [check_no_compiler_messages ptr32plus object {
987         int dummy[sizeof (void *) >= 4 ? 1 : -1];
988     }]
989 }
990
991 # Return 1 if we support 32-bit or larger array and structure sizes
992 # using default options, 0 otherwise.
993
994 proc check_effective_target_size32plus { } {
995     return [check_no_compiler_messages size32plus object {
996         char dummy[65537];
997     }]
998 }
999
1000 # Returns 1 if we're generating 16-bit or smaller integers with the
1001 # default options, 0 otherwise.
1002
1003 proc check_effective_target_int16 { } {
1004     return [check_no_compiler_messages int16 object {
1005         int dummy[sizeof (int) < 4 ? 1 : -1];
1006     }]
1007 }
1008
1009 # Return 1 if we're generating 64-bit code using default options, 0
1010 # otherwise.
1011
1012 proc check_effective_target_lp64 { } {
1013     return [check_no_compiler_messages lp64 object {
1014         int dummy[sizeof (int) == 4
1015                   && sizeof (void *) == 8
1016                   && sizeof (long) == 8 ? 1 : -1];
1017     }]
1018 }
1019
1020 # Return 1 if the target supports long double larger than double,
1021 # 0 otherwise.
1022
1023 proc check_effective_target_large_long_double { } {
1024     return [check_no_compiler_messages large_long_double object {
1025         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1026     }]
1027 }
1028
1029 # Return 1 if the target supports compiling fixed-point,
1030 # 0 otherwise.
1031
1032 proc check_effective_target_fixed_point { } {
1033     return [check_no_compiler_messages fixed_point object {
1034         _Sat _Fract x; _Sat _Accum y;
1035     }]
1036 }
1037
1038 # Return 1 if the target supports compiling decimal floating point,
1039 # 0 otherwise.
1040
1041 proc check_effective_target_dfp_nocache { } {
1042     verbose "check_effective_target_dfp_nocache: compiling source" 2
1043     set ret [check_no_compiler_messages_nocache dfp object {
1044         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1045     }]
1046     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1047     return $ret
1048 }
1049
1050 proc check_effective_target_dfprt_nocache { } {
1051     return [check_runtime_nocache dfprt {
1052         _Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;
1053         int main () { z = x + y; return 0; }
1054     }]
1055 }
1056
1057 # Return 1 if the target supports compiling Decimal Floating Point,
1058 # 0 otherwise.
1059 #
1060 # This won't change for different subtargets so cache the result.
1061
1062 proc check_effective_target_dfp { } {
1063     return [check_cached_effective_target dfp {
1064         check_effective_target_dfp_nocache
1065     }]
1066 }
1067
1068 # Return 1 if the target supports linking and executing Decimal Floating
1069 # Point, # 0 otherwise.
1070 #
1071 # This won't change for different subtargets so cache the result.
1072
1073 proc check_effective_target_dfprt { } {
1074     return [check_cached_effective_target dfprt {
1075         check_effective_target_dfprt_nocache
1076     }]
1077 }
1078
1079 # Return 1 if the target needs a command line argument to enable a SIMD
1080 # instruction set.
1081
1082 proc check_effective_target_vect_cmdline_needed { } {
1083     global et_vect_cmdline_needed_saved
1084     global et_vect_cmdline_needed_target_name
1085
1086     if { ![info exists et_vect_cmdline_needed_target_name] } {
1087         set et_vect_cmdline_needed_target_name ""
1088     }
1089
1090     # If the target has changed since we set the cached value, clear it.
1091     set current_target [current_target_name]
1092     if { $current_target != $et_vect_cmdline_needed_target_name } {
1093         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1094         set et_vect_cmdline_needed_target_name $current_target
1095         if { [info exists et_vect_cmdline_needed_saved] } {
1096             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1097             unset et_vect_cmdline_needed_saved
1098         }
1099     }
1100
1101     if [info exists et_vect_cmdline_needed_saved] {
1102         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1103     } else {
1104         set et_vect_cmdline_needed_saved 1
1105         if { [istarget ia64-*-*]
1106              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1107                  && [check_effective_target_lp64])
1108              || ([istarget powerpc*-*-*]
1109                  && ([check_effective_target_powerpc_spe]
1110                      || [check_effective_target_powerpc_altivec]))} {
1111            set et_vect_cmdline_needed_saved 0
1112         }
1113     }
1114
1115     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1116     return $et_vect_cmdline_needed_saved
1117 }
1118
1119 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1120 #
1121 # This won't change for different subtargets so cache the result.
1122
1123 proc check_effective_target_vect_int { } {
1124     global et_vect_int_saved
1125
1126     if [info exists et_vect_int_saved] {
1127         verbose "check_effective_target_vect_int: using cached result" 2
1128     } else {
1129         set et_vect_int_saved 0
1130         if { [istarget i?86-*-*]
1131              || ([istarget powerpc*-*-*]
1132                   && ![istarget powerpc-*-linux*paired*])
1133               || [istarget spu-*-*]
1134               || [istarget x86_64-*-*]
1135               || [istarget sparc*-*-*]
1136               || [istarget alpha*-*-*]
1137               || [istarget ia64-*-*] } {
1138            set et_vect_int_saved 1
1139         }
1140     }
1141
1142     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1143     return $et_vect_int_saved
1144 }
1145
1146 # Return 1 if the target supports int->float conversion 
1147 #
1148
1149 proc check_effective_target_vect_intfloat_cvt { } {
1150     global et_vect_intfloat_cvt_saved
1151
1152     if [info exists et_vect_intfloat_cvt_saved] {
1153         verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1154     } else {
1155         set et_vect_intfloat_cvt_saved 0
1156         if { [istarget i?86-*-*]
1157               || ([istarget powerpc*-*-*]
1158                    && ![istarget powerpc-*-linux*paired*])
1159               || [istarget x86_64-*-*] } {
1160            set et_vect_intfloat_cvt_saved 1
1161         }
1162     }
1163
1164     verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1165     return $et_vect_intfloat_cvt_saved
1166 }
1167
1168
1169 # Return 1 if the target supports float->int conversion
1170 #
1171
1172 proc check_effective_target_vect_floatint_cvt { } {
1173     global et_vect_floatint_cvt_saved
1174
1175     if [info exists et_vect_floatint_cvt_saved] {
1176         verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1177     } else {
1178         set et_vect_floatint_cvt_saved 0
1179         if { [istarget i?86-*-*]
1180               || [istarget x86_64-*-*] } {
1181            set et_vect_floatint_cvt_saved 1
1182         }
1183     }
1184
1185     verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1186     return $et_vect_floatint_cvt_saved
1187 }
1188
1189 # Return 1 is this is an arm target using 32-bit instructions
1190 proc check_effective_target_arm32 { } {
1191     return [check_no_compiler_messages arm32 assembly {
1192         #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1193         #error FOO
1194         #endif
1195     }]
1196 }
1197
1198 # Return 1 if this is an ARM target supporting -mfpu=vfp
1199 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1200 # options.
1201
1202 proc check_effective_target_arm_vfp_ok { } {
1203     if { [check_effective_target_arm32] } {
1204         return [check_no_compiler_messages arm_vfp_ok object {
1205             int dummy;
1206         } "-mfpu=vfp -mfloat-abi=softfp"]
1207     } else {
1208         return 0
1209     }
1210 }
1211
1212 # Return 1 if this is an ARM target supporting -mfpu=neon
1213 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1214 # options.
1215
1216 proc check_effective_target_arm_neon_ok { } {
1217     if { [check_effective_target_arm32] } {
1218         return [check_no_compiler_messages arm_neon_ok object {
1219             int dummy;
1220         } "-mfpu=neon -mfloat-abi=softfp"]
1221     } else {
1222         return 0
1223     }
1224 }
1225
1226 # Return 1 if the target supports executing NEON instructions, 0
1227 # otherwise.  Cache the result.
1228
1229 proc check_effective_target_arm_neon_hw { } {
1230     return [check_runtime arm_neon_hw_available {
1231         int
1232         main (void)
1233         {
1234           long long a = 0, b = 1;
1235           asm ("vorr %P0, %P1, %P2"
1236                : "=w" (a)
1237                : "0" (a), "w" (b));
1238           return (a != 1);
1239         }
1240     } "-mfpu=neon -mfloat-abi=softfp"]
1241 }
1242
1243 # Return 1 if this is a PowerPC target with floating-point registers.
1244
1245 proc check_effective_target_powerpc_fprs { } {
1246     if { [istarget powerpc*-*-*]
1247          || [istarget rs6000-*-*] } {
1248         return [check_no_compiler_messages powerpc_fprs object {
1249             #ifdef __NO_FPRS__
1250             #error no FPRs
1251             #else
1252             int dummy;
1253             #endif
1254         }]
1255     } else {
1256         return 0
1257     }
1258 }
1259
1260 # Return 1 if this is a PowerPC target supporting -maltivec.
1261
1262 proc check_effective_target_powerpc_altivec_ok { } {
1263     if { ([istarget powerpc*-*-*]
1264          && ![istarget powerpc-*-linux*paired*])
1265          || [istarget rs6000-*-*] } {
1266         # AltiVec is not supported on AIX before 5.3.
1267         if { [istarget powerpc*-*-aix4*]
1268              || [istarget powerpc*-*-aix5.1*] 
1269              || [istarget powerpc*-*-aix5.2*] } {
1270             return 0
1271         }
1272         return [check_no_compiler_messages powerpc_altivec_ok object {
1273             int dummy;
1274         } "-maltivec"]
1275     } else {
1276         return 0
1277     }
1278 }
1279
1280 # Return 1 if this is a PowerPC target that supports SPU.
1281
1282 proc check_effective_target_powerpc_spu { } {
1283     return [istarget powerpc*-*-linux*]
1284 }
1285
1286 # Return 1 if this is a PowerPC target with SPE enabled.
1287
1288 proc check_effective_target_powerpc_spe { } {
1289     if { [istarget powerpc*-*-*] } {
1290         return [check_no_compiler_messages powerpc_spe object {
1291             #ifndef __SPE__
1292             #error not SPE
1293             #else
1294             int dummy;
1295             #endif
1296         }]
1297     } else {
1298         return 0
1299     }
1300 }
1301
1302 # Return 1 if this is a PowerPC target with Altivec enabled.
1303
1304 proc check_effective_target_powerpc_altivec { } {
1305     if { [istarget powerpc*-*-*] } {
1306         return [check_no_compiler_messages powerpc_altivec object {
1307             #ifndef __ALTIVEC__
1308             #error not Altivec
1309             #else
1310             int dummy;
1311             #endif
1312         }]
1313     } else {
1314         return 0
1315     }
1316 }
1317
1318 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
1319 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables.  Return 1 if the
1320 # test environment appears to run executables on such a simulator.
1321
1322 proc check_effective_target_ultrasparc_hw { } {
1323     return [check_runtime ultrasparc_hw {
1324         int main() { return 0; }
1325     } "-mcpu=ultrasparc"]
1326 }
1327
1328 # Return 1 if the target supports hardware vector shift operation.
1329
1330 proc check_effective_target_vect_shift { } {
1331     global et_vect_shift_saved
1332
1333     if [info exists et_vect_shift_saved] {
1334         verbose "check_effective_target_vect_shift: using cached result" 2
1335     } else {
1336         set et_vect_shift_saved 0
1337         if { ([istarget powerpc*-*-*]
1338              && ![istarget powerpc-*-linux*paired*])
1339              || [istarget ia64-*-*]
1340              || [istarget i?86-*-*]
1341              || [istarget x86_64-*-*] } {
1342            set et_vect_shift_saved 1
1343         }
1344     }
1345
1346     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1347     return $et_vect_shift_saved
1348 }
1349
1350 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1351 #
1352 # This can change for different subtargets so do not cache the result.
1353
1354 proc check_effective_target_vect_long { } {
1355     if { [istarget i?86-*-*]
1356          || (([istarget powerpc*-*-*] 
1357               && ![istarget powerpc-*-linux*paired*]) 
1358               && [check_effective_target_ilp32])
1359          || [istarget x86_64-*-*]
1360          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1361         set answer 1
1362     } else {
1363         set answer 0
1364     }
1365
1366     verbose "check_effective_target_vect_long: returning $answer" 2
1367     return $answer
1368 }
1369
1370 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1371 #
1372 # This won't change for different subtargets so cache the result.
1373
1374 proc check_effective_target_vect_float { } {
1375     global et_vect_float_saved
1376
1377     if [info exists et_vect_float_saved] {
1378         verbose "check_effective_target_vect_float: using cached result" 2
1379     } else {
1380         set et_vect_float_saved 0
1381         if { [istarget i?86-*-*]
1382               || [istarget powerpc*-*-*]
1383               || [istarget spu-*-*]
1384               || [istarget mipsisa64*-*-*]
1385               || [istarget x86_64-*-*]
1386               || [istarget ia64-*-*] } {
1387            set et_vect_float_saved 1
1388         }
1389     }
1390
1391     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1392     return $et_vect_float_saved
1393 }
1394
1395 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1396 #
1397 # This won't change for different subtargets so cache the result.
1398
1399 proc check_effective_target_vect_double { } {
1400     global et_vect_double_saved
1401
1402     if [info exists et_vect_double_saved] {
1403         verbose "check_effective_target_vect_double: using cached result" 2
1404     } else {
1405         set et_vect_double_saved 0
1406         if { [istarget i?86-*-*]
1407               || [istarget x86_64-*-*] 
1408               || [istarget spu-*-*] } {
1409            set et_vect_double_saved 1
1410         }
1411     }
1412
1413     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1414     return $et_vect_double_saved
1415 }
1416
1417 # Return 1 if the target plus current options does not support a vector
1418 # max instruction on "int", 0 otherwise.
1419 #
1420 # This won't change for different subtargets so cache the result.
1421
1422 proc check_effective_target_vect_no_int_max { } {
1423     global et_vect_no_int_max_saved
1424
1425     if [info exists et_vect_no_int_max_saved] {
1426         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1427     } else {
1428         set et_vect_no_int_max_saved 0
1429         if { [istarget sparc*-*-*]
1430              || [istarget spu-*-*]
1431              || [istarget alpha*-*-*] } {
1432             set et_vect_no_int_max_saved 1
1433         }
1434     }
1435     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1436     return $et_vect_no_int_max_saved
1437 }
1438
1439 # Return 1 if the target plus current options does not support a vector
1440 # add instruction on "int", 0 otherwise.
1441 #
1442 # This won't change for different subtargets so cache the result.
1443
1444 proc check_effective_target_vect_no_int_add { } {
1445     global et_vect_no_int_add_saved
1446
1447     if [info exists et_vect_no_int_add_saved] {
1448         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1449     } else {
1450         set et_vect_no_int_add_saved 0
1451         # Alpha only supports vector add on V8QI and V4HI.
1452         if { [istarget alpha*-*-*] } {
1453             set et_vect_no_int_add_saved 1
1454         }
1455     }
1456     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1457     return $et_vect_no_int_add_saved
1458 }
1459
1460 # Return 1 if the target plus current options does not support vector
1461 # bitwise instructions, 0 otherwise.
1462 #
1463 # This won't change for different subtargets so cache the result.
1464
1465 proc check_effective_target_vect_no_bitwise { } {
1466     global et_vect_no_bitwise_saved
1467
1468     if [info exists et_vect_no_bitwise_saved] {
1469         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1470     } else {
1471         set et_vect_no_bitwise_saved 0
1472     }
1473     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1474     return $et_vect_no_bitwise_saved
1475 }
1476
1477 # Return 1 if the target plus current options supports a vector
1478 # widening summation of *short* args into *int* result, 0 otherwise.
1479 # A target can also support this widening summation if it can support
1480 # promotion (unpacking) from shorts to ints.
1481 #
1482 # This won't change for different subtargets so cache the result.
1483                                                                                                 
1484 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1485     global et_vect_widen_sum_hi_to_si
1486
1487     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1488         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1489     } else {
1490         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1491         if { [istarget powerpc*-*-*] 
1492              || [istarget ia64-*-*] } {
1493             set et_vect_widen_sum_hi_to_si_saved 1
1494         }
1495     }
1496     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1497     return $et_vect_widen_sum_hi_to_si_saved
1498 }
1499
1500 # Return 1 if the target plus current options supports a vector
1501 # widening summation of *char* args into *short* result, 0 otherwise.
1502 # A target can also support this widening summation if it can support
1503 # promotion (unpacking) from chars to shorts.
1504 #
1505 # This won't change for different subtargets so cache the result.
1506                                                                                                 
1507 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1508     global et_vect_widen_sum_qi_to_hi
1509
1510     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1511         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1512     } else {
1513         set et_vect_widen_sum_qi_to_hi_saved 0
1514         if { [check_effective_target_vect_unpack] 
1515              || [istarget ia64-*-*] } {
1516             set et_vect_widen_sum_qi_to_hi_saved 1
1517         }
1518     }
1519     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1520     return $et_vect_widen_sum_qi_to_hi_saved
1521 }
1522
1523 # Return 1 if the target plus current options supports a vector
1524 # widening summation of *char* args into *int* result, 0 otherwise.
1525 #
1526 # This won't change for different subtargets so cache the result.
1527                                                                                                 
1528 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1529     global et_vect_widen_sum_qi_to_si
1530
1531     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1532         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1533     } else {
1534         set et_vect_widen_sum_qi_to_si_saved 0
1535         if { [istarget powerpc*-*-*] } {
1536             set et_vect_widen_sum_qi_to_si_saved 1
1537         }
1538     }
1539     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1540     return $et_vect_widen_sum_qi_to_si_saved
1541 }
1542
1543 # Return 1 if the target plus current options supports a vector
1544 # widening multiplication of *char* args into *short* result, 0 otherwise.
1545 # A target can also support this widening multplication if it can support
1546 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1547 # multiplication of shorts).
1548 #
1549 # This won't change for different subtargets so cache the result.
1550
1551
1552 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1553     global et_vect_widen_mult_qi_to_hi
1554
1555     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1556         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
1557     } else {
1558         if { [check_effective_target_vect_unpack]
1559              && [check_effective_target_vect_short_mult] } {
1560             set et_vect_widen_mult_qi_to_hi_saved 1
1561         } else {
1562             set et_vect_widen_mult_qi_to_hi_saved 0
1563         }
1564         if { [istarget powerpc*-*-*] } {
1565             set et_vect_widen_mult_qi_to_hi_saved 1
1566         }
1567     }
1568     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1569     return $et_vect_widen_mult_qi_to_hi_saved
1570 }
1571
1572 # Return 1 if the target plus current options supports a vector
1573 # widening multiplication of *short* args into *int* result, 0 otherwise.
1574 # A target can also support this widening multplication if it can support
1575 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1576 # multiplication of ints).
1577 #
1578 # This won't change for different subtargets so cache the result.
1579
1580
1581 proc check_effective_target_vect_widen_mult_hi_to_si { } {
1582     global et_vect_widen_mult_hi_to_si
1583
1584     if [info exists et_vect_widen_mult_hi_to_si_saved] {
1585         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1586     } else {
1587         if { [check_effective_target_vect_unpack]
1588              && [check_effective_target_vect_int_mult] } {
1589           set et_vect_widen_mult_hi_to_si_saved 1
1590         } else {
1591           set et_vect_widen_mult_hi_to_si_saved 0
1592         }
1593         if { [istarget powerpc*-*-*]
1594               || [istarget spu-*-*]
1595               || [istarget i?86-*-*]
1596               || [istarget x86_64-*-*] } {
1597             set et_vect_widen_mult_hi_to_si_saved 1
1598         }
1599     }
1600     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1601     return $et_vect_widen_mult_hi_to_si_saved
1602 }
1603
1604 # Return 1 if the target plus current options supports a vector
1605 # dot-product of signed chars, 0 otherwise.
1606 #
1607 # This won't change for different subtargets so cache the result.
1608
1609 proc check_effective_target_vect_sdot_qi { } {
1610     global et_vect_sdot_qi
1611
1612     if [info exists et_vect_sdot_qi_saved] {
1613         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1614     } else {
1615         set et_vect_sdot_qi_saved 0
1616     }
1617     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1618     return $et_vect_sdot_qi_saved
1619 }
1620
1621 # Return 1 if the target plus current options supports a vector
1622 # dot-product of unsigned chars, 0 otherwise.
1623 #
1624 # This won't change for different subtargets so cache the result.
1625
1626 proc check_effective_target_vect_udot_qi { } {
1627     global et_vect_udot_qi
1628
1629     if [info exists et_vect_udot_qi_saved] {
1630         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1631     } else {
1632         set et_vect_udot_qi_saved 0
1633         if { [istarget powerpc*-*-*] } {
1634             set et_vect_udot_qi_saved 1
1635         }
1636     }
1637     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1638     return $et_vect_udot_qi_saved
1639 }
1640
1641 # Return 1 if the target plus current options supports a vector
1642 # dot-product of signed shorts, 0 otherwise.
1643 #
1644 # This won't change for different subtargets so cache the result.
1645
1646 proc check_effective_target_vect_sdot_hi { } {
1647     global et_vect_sdot_hi
1648
1649     if [info exists et_vect_sdot_hi_saved] {
1650         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1651     } else {
1652         set et_vect_sdot_hi_saved 0
1653         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
1654              || [istarget i?86-*-*]
1655              || [istarget x86_64-*-*] } {
1656             set et_vect_sdot_hi_saved 1
1657         }
1658     }
1659     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1660     return $et_vect_sdot_hi_saved
1661 }
1662
1663 # Return 1 if the target plus current options supports a vector
1664 # dot-product of unsigned shorts, 0 otherwise.
1665 #
1666 # This won't change for different subtargets so cache the result.
1667
1668 proc check_effective_target_vect_udot_hi { } {
1669     global et_vect_udot_hi
1670
1671     if [info exists et_vect_udot_hi_saved] {
1672         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1673     } else {
1674         set et_vect_udot_hi_saved 0
1675         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*]) } {
1676             set et_vect_udot_hi_saved 1
1677         }
1678     }
1679     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1680     return $et_vect_udot_hi_saved
1681 }
1682
1683
1684 # Return 1 if the target plus current options supports a vector
1685 # demotion (packing) of shorts (to chars) and ints (to shorts) 
1686 # using modulo arithmetic, 0 otherwise.
1687 #
1688 # This won't change for different subtargets so cache the result.
1689                                                                                 
1690 proc check_effective_target_vect_pack_trunc { } {
1691     global et_vect_pack_trunc
1692                                                                                 
1693     if [info exists et_vect_pack_trunc_saved] {
1694         verbose "check_effective_target_vect_pack_trunc: using cached result" 2
1695     } else {
1696         set et_vect_pack_trunc_saved 0
1697         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
1698              || [istarget i?86-*-*]
1699              || [istarget x86_64-*-*] } {
1700             set et_vect_pack_trunc_saved 1
1701         }
1702     }
1703     verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
1704     return $et_vect_pack_trunc_saved
1705 }
1706
1707 # Return 1 if the target plus current options supports a vector
1708 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
1709 #
1710 # This won't change for different subtargets so cache the result.
1711                                    
1712 proc check_effective_target_vect_unpack { } {
1713     global et_vect_unpack
1714                                         
1715     if [info exists et_vect_unpack_saved] {
1716         verbose "check_effective_target_vect_unpack: using cached result" 2
1717     } else {
1718         set et_vect_unpack_saved 0
1719         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
1720              || [istarget i?86-*-*]
1721              || [istarget x86_64-*-*] 
1722              || [istarget spu-*-*] } {
1723             set et_vect_unpack_saved 1
1724         }
1725     }
1726     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
1727     return $et_vect_unpack_saved
1728 }
1729
1730 # Return 1 if the target plus current options does not guarantee
1731 # that its STACK_BOUNDARY is >= the reguired vector alignment.
1732 #
1733 # This won't change for different subtargets so cache the result.
1734
1735 proc check_effective_target_unaligned_stack { } {
1736     global et_unaligned_stack_saved
1737
1738     if [info exists et_unaligned_stack_saved] {
1739         verbose "check_effective_target_unaligned_stack: using cached result" 2
1740     } else {
1741         set et_unaligned_stack_saved 0
1742         if { ( [istarget i?86-*-*] || [istarget x86_64-*-*] )
1743           && (! [istarget *-*-darwin*] ) } {
1744             set et_unaligned_stack_saved 1
1745         }
1746     }
1747     verbose "check_effective_target_unaligned_stack: returning $et_unaligned_stack_saved" 2
1748     return $et_unaligned_stack_saved
1749 }
1750
1751 # Return 1 if the target plus current options does not support a vector
1752 # alignment mechanism, 0 otherwise.
1753 #
1754 # This won't change for different subtargets so cache the result.
1755
1756 proc check_effective_target_vect_no_align { } {
1757     global et_vect_no_align_saved
1758
1759     if [info exists et_vect_no_align_saved] {
1760         verbose "check_effective_target_vect_no_align: using cached result" 2
1761     } else {
1762         set et_vect_no_align_saved 0
1763         if { [istarget mipsisa64*-*-*]
1764              || [istarget sparc*-*-*]
1765              || [istarget ia64-*-*] } { 
1766             set et_vect_no_align_saved 1
1767         }
1768     }
1769     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1770     return $et_vect_no_align_saved
1771 }
1772
1773 # Return 1 if arrays are aligned to the vector alignment
1774 # boundary, 0 otherwise.
1775 #
1776 # This won't change for different subtargets so cache the result.
1777
1778 proc check_effective_target_vect_aligned_arrays { } {
1779     global et_vect_aligned_arrays
1780
1781     if [info exists et_vect_aligned_arrays_saved] {
1782         verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
1783     } else {
1784         set et_vect_aligned_arrays_saved 0
1785         if { (([istarget x86_64-*-*]
1786               || [istarget i?86-*-*]) && [is-effective-target lp64])
1787               || [istarget spu-*-*] } {
1788             set et_vect_aligned_arrays_saved 1
1789         }
1790     }
1791     verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
1792     return $et_vect_aligned_arrays_saved
1793 }
1794
1795 # Return 1 if types of size 32 bit or less are naturally aligned
1796 # (aligned to their type-size), 0 otherwise.
1797 #
1798 # This won't change for different subtargets so cache the result.
1799
1800 proc check_effective_target_natural_alignment_32 { } {
1801     global et_natural_alignment_32
1802
1803     if [info exists et_natural_alignment_32_saved] {
1804         verbose "check_effective_target_natural_alignment_32: using cached result" 2
1805     } else {
1806         # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
1807         set et_natural_alignment_32_saved 1
1808         if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } {
1809             set et_natural_alignment_32_saved 0
1810         }
1811     }
1812     verbose "check_effective_target_natural_alignment_32: returning $et_natural_alignment_32_saved" 2
1813     return $et_natural_alignment_32_saved
1814 }
1815
1816 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
1817 # type-size), 0 otherwise.
1818 #
1819 # This won't change for different subtargets so cache the result.
1820
1821 proc check_effective_target_natural_alignment_64 { } {
1822     global et_natural_alignment_64
1823
1824     if [info exists et_natural_alignment_64_saved] {
1825         verbose "check_effective_target_natural_alignment_64: using cached result" 2
1826     } else {
1827         set et_natural_alignment_64_saved 0
1828         if { ([is-effective-target lp64] && ![istarget *-*-darwin*])
1829              || [istarget spu-*-*] } {
1830             set et_natural_alignment_64_saved 1
1831         }
1832     }
1833     verbose "check_effective_target_natural_alignment_64: returning $et_natural_alignment_64_saved" 2
1834     return $et_natural_alignment_64_saved
1835 }
1836
1837 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
1838 #
1839 # This won't change for different subtargets so cache the result.
1840
1841 proc check_effective_target_vector_alignment_reachable { } {
1842     global et_vector_alignment_reachable
1843
1844     if [info exists et_vector_alignment_reachable_saved] {
1845         verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
1846     } else {
1847         if { [check_effective_target_vect_aligned_arrays]
1848              || [check_effective_target_natural_alignment_32] } {
1849             set et_vector_alignment_reachable_saved 1
1850         } else {
1851             set et_vector_alignment_reachable_saved 0
1852         }
1853     }
1854     verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
1855     return $et_vector_alignment_reachable_saved
1856 }
1857
1858 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
1859 #
1860 # This won't change for different subtargets so cache the result.
1861
1862 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
1863     global et_vector_alignment_reachable_for_64bit
1864
1865     if [info exists et_vector_alignment_reachable_for_64bit_saved] {
1866         verbose "check_effective_target_vector_alignment_reachable_for_64bit: using cached result" 2
1867     } else {
1868         if { [check_effective_target_vect_aligned_arrays] 
1869              || [check_effective_target_natural_alignment_64] } {
1870             set et_vector_alignment_reachable_for_64bit_saved 1
1871         } else {
1872             set et_vector_alignment_reachable_for_64bit_saved 0
1873         }
1874     }
1875     verbose "check_effective_target_vector_alignment_reachable_for_64bit: returning $et_vector_alignment_reachable_for_64bit_saved" 2
1876     return $et_vector_alignment_reachable_for_64bit_saved
1877 }
1878
1879 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1880
1881 proc check_effective_target_vect_condition { } {
1882     global et_vect_cond_saved
1883
1884     if [info exists et_vect_cond_saved] {
1885         verbose "check_effective_target_vect_cond: using cached result" 2
1886     } else {
1887         set et_vect_cond_saved 0
1888         if { [istarget powerpc*-*-*]
1889              || [istarget ia64-*-*]
1890              || [istarget i?86-*-*]
1891              || [istarget spu-*-*]
1892              || [istarget x86_64-*-*] } {
1893            set et_vect_cond_saved 1
1894         }
1895     }
1896
1897     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1898     return $et_vect_cond_saved
1899 }
1900
1901 # Return 1 if the target supports vector char multiplication, 0 otherwise.
1902
1903 proc check_effective_target_vect_char_mult { } {
1904     global et_vect_char_mult_saved
1905
1906     if [info exists et_vect_char_mult_saved] {
1907         verbose "check_effective_target_vect_char_mult: using cached result" 2
1908     } else {
1909         set et_vect_char_mult_saved 0
1910         if { [istarget ia64-*-*]
1911              || [istarget i?86-*-*]
1912              || [istarget x86_64-*-*] } {
1913            set et_vect_char_mult_saved 1
1914         }
1915     }
1916
1917     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1918     return $et_vect_char_mult_saved
1919 }
1920
1921 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1922
1923 proc check_effective_target_vect_short_mult { } {
1924     global et_vect_short_mult_saved
1925
1926     if [info exists et_vect_short_mult_saved] {
1927         verbose "check_effective_target_vect_short_mult: using cached result" 2
1928     } else {
1929         set et_vect_short_mult_saved 0
1930         if { [istarget ia64-*-*]
1931              || [istarget spu-*-*]
1932              || [istarget i?86-*-*]
1933              || [istarget x86_64-*-*] } {
1934            set et_vect_short_mult_saved 1
1935         }
1936     }
1937
1938     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1939     return $et_vect_short_mult_saved
1940 }
1941
1942 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1943
1944 proc check_effective_target_vect_int_mult { } {
1945     global et_vect_int_mult_saved
1946
1947     if [info exists et_vect_int_mult_saved] {
1948         verbose "check_effective_target_vect_int_mult: using cached result" 2
1949     } else {
1950         set et_vect_int_mult_saved 0
1951         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
1952              || [istarget spu-*-*]
1953              || [istarget i?86-*-*]
1954              || [istarget x86_64-*-*] } {
1955            set et_vect_int_mult_saved 1
1956         }
1957     }
1958
1959     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1960     return $et_vect_int_mult_saved
1961 }
1962
1963 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
1964
1965 proc check_effective_target_vect_extract_even_odd { } {
1966     global et_vect_extract_even_odd_saved
1967     
1968     if [info exists et_vect_extract_even_odd_saved] {
1969         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
1970     } else {
1971         set et_vect_extract_even_odd_saved 0 
1972         if { [istarget powerpc*-*-*] } {
1973            set et_vect_extract_even_odd_saved 1
1974         }
1975     }
1976
1977     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
1978     return $et_vect_extract_even_odd_saved
1979 }
1980
1981 # Return 1 if the target supports vector interleaving, 0 otherwise.
1982
1983 proc check_effective_target_vect_interleave { } {
1984     global et_vect_interleave_saved
1985     
1986     if [info exists et_vect_interleave_saved] {
1987         verbose "check_effective_target_vect_interleave: using cached result" 2
1988     } else {
1989         set et_vect_interleave_saved 0
1990         if { [istarget powerpc*-*-*]
1991              || [istarget i?86-*-*]
1992              || [istarget x86_64-*-*] } {
1993            set et_vect_interleave_saved 1
1994         }
1995     }
1996
1997     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
1998     return $et_vect_interleave_saved
1999 }
2000
2001 # Return 1 if the target supports vector interleaving and extract even/odd, 0 otherwise.
2002 proc check_effective_target_vect_strided { } {
2003     global et_vect_strided_saved
2004
2005     if [info exists et_vect_strided_saved] {
2006         verbose "check_effective_target_vect_strided: using cached result" 2
2007     } else {
2008         set et_vect_strided_saved 0
2009         if { [check_effective_target_vect_interleave]
2010              && [check_effective_target_vect_extract_even_odd] } {
2011            set et_vect_strided_saved 1
2012         }
2013     }
2014
2015     verbose "check_effective_target_vect_strided: returning $et_vect_strided_saved" 2
2016     return $et_vect_strided_saved
2017 }
2018
2019 # Return 1 if the target supports section-anchors
2020
2021 proc check_effective_target_section_anchors { } {
2022     global et_section_anchors_saved
2023
2024     if [info exists et_section_anchors_saved] {
2025         verbose "check_effective_target_section_anchors: using cached result" 2
2026     } else {
2027         set et_section_anchors_saved 0
2028         if { [istarget powerpc*-*-*] } {
2029            set et_section_anchors_saved 1
2030         }
2031     }
2032
2033     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
2034     return $et_section_anchors_saved
2035 }
2036
2037 # Return 1 if the target supports atomic operations on "int" and "long".
2038
2039 proc check_effective_target_sync_int_long { } {
2040     global et_sync_int_long_saved
2041
2042     if [info exists et_sync_int_long_saved] {
2043         verbose "check_effective_target_sync_int_long: using cached result" 2
2044     } else {
2045         set et_sync_int_long_saved 0
2046 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2047 # load-reserved/store-conditional instructions.
2048         if { [istarget ia64-*-*]
2049              || [istarget i?86-*-*]
2050              || [istarget x86_64-*-*]
2051              || [istarget alpha*-*-*] 
2052              || [istarget s390*-*-*] 
2053              || [istarget powerpc*-*-*]
2054              || [istarget sparc64-*-*]
2055              || [istarget sparcv9-*-*]
2056              || [istarget mips*-*-*] } {
2057            set et_sync_int_long_saved 1
2058         }
2059     }
2060
2061     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2062     return $et_sync_int_long_saved
2063 }
2064
2065 # Return 1 if the target supports atomic operations on "char" and "short".
2066
2067 proc check_effective_target_sync_char_short { } {
2068     global et_sync_char_short_saved
2069
2070     if [info exists et_sync_char_short_saved] {
2071         verbose "check_effective_target_sync_char_short: using cached result" 2
2072     } else {
2073         set et_sync_char_short_saved 0
2074 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2075 # load-reserved/store-conditional instructions.
2076         if { [istarget ia64-*-*]
2077              || [istarget i?86-*-*]
2078              || [istarget x86_64-*-*]
2079              || [istarget alpha*-*-*] 
2080              || [istarget s390*-*-*] 
2081              || [istarget powerpc*-*-*]
2082              || [istarget sparc64-*-*]
2083              || [istarget sparcv9-*-*]
2084              || [istarget mips*-*-*] } {
2085            set et_sync_char_short_saved 1
2086         }
2087     }
2088
2089     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2090     return $et_sync_char_short_saved
2091 }
2092
2093 # Return 1 if the target uses a ColdFire FPU.
2094
2095 proc check_effective_target_coldfire_fpu { } {
2096     return [check_no_compiler_messages coldfire_fpu assembly {
2097         #ifndef __mcffpu__
2098         #error FOO
2099         #endif
2100     }]
2101 }
2102
2103 # Return true if this is a uClibc target.
2104
2105 proc check_effective_target_uclibc {} {
2106     return [check_no_compiler_messages uclibc object {
2107         #include <features.h>
2108         #if !defined (__UCLIBC__)
2109         #error FOO
2110         #endif
2111     }]
2112 }
2113
2114 # Return true if this is a uclibc target and if the uclibc feature
2115 # described by __$feature__ is not present.
2116
2117 proc check_missing_uclibc_feature {feature} {
2118     return [check_no_compiler_messages $feature object "
2119         #include <features.h>
2120         #if !defined (__UCLIBC) || defined (__${feature}__)
2121         #error FOO
2122         #endif
2123     "]
2124 }
2125
2126 # Return true if this is a Newlib target.
2127
2128 proc check_effective_target_newlib {} {
2129     return [check_no_compiler_messages newlib object {
2130         #include <newlib.h>
2131     }]
2132 }
2133
2134 # Return 1 if
2135 #   (a) an error of a few ULP is expected in string to floating-point
2136 #       conversion functions; and
2137 #   (b) overflow is not always detected correctly by those functions.
2138
2139 proc check_effective_target_lax_strtofp {} {
2140     # By default, assume that all uClibc targets suffer from this.
2141     return [check_effective_target_uclibc]
2142 }
2143
2144 # Return 1 if this is a target for which wcsftime is a dummy
2145 # function that always returns 0.
2146
2147 proc check_effective_target_dummy_wcsftime {} {
2148     # By default, assume that all uClibc targets suffer from this.
2149     return [check_effective_target_uclibc]
2150 }
2151
2152 # Return 1 if constructors with initialization priority arguments are
2153 # supposed on this target.
2154
2155 proc check_effective_target_init_priority {} {
2156     return [check_no_compiler_messages init_priority assembly "
2157         void f() __attribute__((constructor (1000)));
2158         void f() \{\}
2159     "]
2160 }
2161
2162 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2163 # This can be used with any check_* proc that takes no argument and
2164 # returns only 1 or 0.  It could be used with check_* procs that take
2165 # arguments with keywords that pass particular arguments.
2166
2167 proc is-effective-target { arg } {
2168     set selected 0
2169     if { [info procs check_effective_target_${arg}] != [list] } {
2170         set selected [check_effective_target_${arg}]
2171     } else {
2172         switch $arg {
2173           "vmx_hw"         { set selected [check_vmx_hw_available] }
2174           "named_sections" { set selected [check_named_sections_available] }
2175           "gc_sections"    { set selected [check_gc_sections_available] }
2176           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
2177           default          { error "unknown effective target keyword `$arg'" }
2178         }
2179     }
2180     verbose "is-effective-target: $arg $selected" 2
2181     return $selected
2182 }
2183
2184 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2185
2186 proc is-effective-target-keyword { arg } {
2187     if { [info procs check_effective_target_${arg}] != [list] } {
2188         return 1
2189     } else {
2190         # These have different names for their check_* procs.
2191         switch $arg {
2192           "vmx_hw"         { return 1 }
2193           "named_sections" { return 1 }
2194           "gc_sections"    { return 1 }
2195           "cxa_atexit"     { return 1 }
2196           default          { return 0 }
2197         }
2198     }
2199 }
2200
2201 # Return 1 if target default to short enums
2202
2203 proc check_effective_target_short_enums { } {
2204     return [check_no_compiler_messages short_enums assembly {
2205         enum foo { bar };
2206         int s[sizeof (enum foo) == 1 ? 1 : -1];
2207     }]
2208 }
2209
2210 # Return 1 if target supports merging string constants at link time.
2211
2212 proc check_effective_target_string_merging { } {
2213     return [check_no_messages_and_pattern string_merging \
2214                 "rodata\\.str" assembly {
2215                     const char *var = "String";
2216                 } {-O2}]
2217 }
2218
2219 # Return 1 if target has the basic signed and unsigned types in
2220 # <stdint.h>, 0 otherwise.
2221
2222 proc check_effective_target_stdint_types { } {
2223     return [check_no_compiler_messages stdint_types assembly {
2224         #include <stdint.h>
2225         int8_t a; int16_t b; int32_t c; int64_t d;
2226         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2227     }]
2228 }
2229
2230 # Return 1 if programs are intended to be run on a simulator
2231 # (i.e. slowly) rather than hardware (i.e. fast).
2232
2233 proc check_effective_target_simulator { } {
2234
2235     # All "src/sim" simulators set this one.
2236     if [board_info target exists is_simulator] {
2237         return [board_info target is_simulator]
2238     }
2239
2240     # The "sid" simulators don't set that one, but at least they set
2241     # this one.
2242     if [board_info target exists slow_simulator] {
2243         return [board_info target slow_simulator]
2244     }
2245
2246     return 0
2247 }
2248
2249 # Return 1 if the target is a VxWorks kernel.
2250
2251 proc check_effective_target_vxworks_kernel { } {
2252     return [check_no_compiler_messages vxworks_kernel assembly {
2253         #if !defined __vxworks || defined __RTP__
2254         #error NO
2255         #endif
2256     }]
2257 }
2258
2259 # Return 1 if the target is a VxWorks RTP.
2260
2261 proc check_effective_target_vxworks_rtp { } {
2262     return [check_no_compiler_messages vxworks_rtp assembly {
2263         #if !defined __vxworks || !defined __RTP__
2264         #error NO
2265         #endif
2266     }]
2267 }
2268
2269 # Return 1 if the target is expected to provide wide character support.
2270
2271 proc check_effective_target_wchar { } {
2272     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2273         return 0
2274     }
2275     return [check_no_compiler_messages wchar assembly {
2276         #include <wchar.h>
2277     }]
2278 }
2279
2280 # Return 1 if the target has <pthread.h>.
2281
2282 proc check_effective_target_pthread_h { } {
2283     return [check_no_compiler_messages pthread_h assembly {
2284         #include <pthread.h>
2285     }]
2286 }
2287
2288 # Return 1 if the target can truncate a file from a file-descriptor,
2289 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
2290 # chsize.  We test for a trivially functional truncation; no stubs.
2291 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
2292 # different function to be used.
2293
2294 proc check_effective_target_fd_truncate { } {
2295     set prog {
2296         #define _FILE_OFFSET_BITS 64
2297         #include <unistd.h>
2298         #include <stdio.h>
2299         #include <stdlib.h>
2300         int main ()
2301         {
2302           FILE *f = fopen ("tst.tmp", "wb");
2303           int fd;
2304           const char t[] = "test writing more than ten characters";
2305           char s[11];
2306           fd =  fileno (f);
2307           write (fd, t, sizeof (t) - 1);
2308           lseek (fd, 0, 0);
2309           if (ftruncate (fd, 10) != 0)
2310             exit (1);
2311           close (fd);
2312           f = fopen ("tst.tmp", "rb");
2313           if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
2314             exit (1);
2315           exit (0);
2316         }
2317     }
2318
2319     if { [check_runtime ftruncate $prog] } {
2320       return 1;
2321     }
2322
2323     regsub "ftruncate" $prog "chsize" prog
2324     return [check_runtime chsize $prog]
2325 }
2326
2327 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
2328
2329 proc add_options_for_c99_runtime { flags } {
2330     if { [istarget *-*-solaris2*] } {
2331         return "$flags -std=c99"
2332     }
2333     if { [istarget powerpc-*-darwin*] } {
2334         return "$flags -mmacosx-version-min=10.3"
2335     }
2336     return $flags
2337 }
2338
2339 # Return 1 if the target provides a full C99 runtime.
2340
2341 proc check_effective_target_c99_runtime { } {
2342     return [check_cached_effective_target c99_runtime {
2343         global srcdir
2344
2345         set file [open "$srcdir/gcc.dg/builtins-config.h"]
2346         set contents [read $file]
2347         close $file
2348         append contents {
2349             #ifndef HAVE_C99_RUNTIME
2350             #error FOO
2351             #endif
2352         }
2353         check_no_compiler_messages_nocache c99_runtime assembly \
2354             $contents [add_options_for_c99_runtime ""]
2355     }]
2356 }
2357
2358 # Return 1 if  target wchar_t is at least 4 bytes.
2359
2360 proc check_effective_target_4byte_wchar_t { } {
2361     return [check_no_compiler_messages 4byte_wchar_t object {
2362         int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
2363     }]
2364 }