OSDN Git Service

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