OSDN Git Service

2011-05-24 Uros Bizjak <ubizjak@gmail.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2 #   2011 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.  
33 # Otherwise, code should contain:
34 # "// C++" for c++,
35 # "! Fortran" for Fortran code,
36 # "/* ObjC", for ObjC
37 # "// ObjC++" for ObjC++
38 # and "// Go" for Go
39 # If the tool is ObjC/ObjC++ then we overide the extension to .m/.mm to 
40 # allow for ObjC/ObjC++ specific flags.
41 proc check_compile {basename type contents args} {
42     global tool
43     verbose "check_compile tool: $tool for $basename" 
44
45     if { [llength $args] > 0 } {
46         set options [list "additional_flags=[lindex $args 0]"]
47     } else {
48         set options ""
49     }
50     switch -glob -- $contents {
51         "*! Fortran*" { set src ${basename}[pid].f90 }
52         "*// C++*" { set src ${basename}[pid].cc }
53         "*// ObjC++*" { set src ${basename}[pid].mm }
54         "*/* ObjC*" { set src ${basename}[pid].m }
55         "*// Go*" { set src ${basename}[pid].go }
56         default {
57             switch -- $tool {
58                 "objc" { set src ${basename}[pid].m }
59                 "obj-c++" { set src ${basename}[pid].mm }
60                 default { set src ${basename}[pid].c }
61             }
62         }
63     }
64
65     set compile_type $type
66     switch -glob $type {
67         assembly { set output ${basename}[pid].s }
68         object { set output ${basename}[pid].o }
69         executable { set output ${basename}[pid].exe }
70         "rtl-*" {
71             set output ${basename}[pid].s
72             lappend options "additional_flags=-fdump-$type"
73             set compile_type assembly
74         }
75     }
76     set f [open $src "w"]
77     puts $f $contents
78     close $f
79     set lines [${tool}_target_compile $src $output $compile_type "$options"]
80     file delete $src
81
82     set scan_output $output
83     # Don't try folding this into the switch above; calling "glob" before the
84     # file is created won't work.
85     if [regexp "rtl-(.*)" $type dummy rtl_type] {
86         set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
87         file delete $output
88     }
89
90     return [list $lines $scan_output]
91 }
92
93 proc current_target_name { } {
94     global target_info
95     if [info exists target_info(target,name)] {
96         set answer $target_info(target,name)
97     } else {
98         set answer ""
99     }
100     return $answer
101 }
102
103 # Implement an effective-target check for property PROP by invoking
104 # the Tcl command ARGS and seeing if it returns true.
105
106 proc check_cached_effective_target { prop args } {
107     global et_cache
108
109     set target [current_target_name]
110     if {![info exists et_cache($prop,target)]
111         || $et_cache($prop,target) != $target} {
112         verbose "check_cached_effective_target $prop: checking $target" 2
113         set et_cache($prop,target) $target
114         set et_cache($prop,value) [uplevel eval $args]
115     }
116     set value $et_cache($prop,value)
117     verbose "check_cached_effective_target $prop: returning $value for $target" 2
118     return $value
119 }
120
121 # Like check_compile, but delete the output file and return true if the
122 # compiler printed no messages.
123 proc check_no_compiler_messages_nocache {args} {
124     set result [eval check_compile $args]
125     set lines [lindex $result 0]
126     set output [lindex $result 1]
127     remote_file build delete $output
128     return [string match "" $lines]
129 }
130
131 # Like check_no_compiler_messages_nocache, but cache the result.
132 # PROP is the property we're checking, and doubles as a prefix for
133 # temporary filenames.
134 proc check_no_compiler_messages {prop args} {
135     return [check_cached_effective_target $prop {
136         eval [list check_no_compiler_messages_nocache $prop] $args
137     }]
138 }
139
140 # Like check_compile, but return true if the compiler printed no
141 # messages and if the contents of the output file satisfy PATTERN.
142 # If PATTERN has the form "!REGEXP", the contents satisfy it if they
143 # don't match regular expression REGEXP, otherwise they satisfy it
144 # if they do match regular expression PATTERN.  (PATTERN can start
145 # with something like "[!]" if the regular expression needs to match
146 # "!" as the first character.)
147 #
148 # Delete the output file before returning.  The other arguments are
149 # as for check_compile.
150 proc check_no_messages_and_pattern_nocache {basename pattern args} {
151     global tool
152
153     set result [eval [list check_compile $basename] $args]
154     set lines [lindex $result 0]
155     set output [lindex $result 1]
156
157     set ok 0
158     if { [string match "" $lines] } {
159         set chan [open "$output"]
160         set invert [regexp {^!(.*)} $pattern dummy pattern]
161         set ok [expr { [regexp $pattern [read $chan]] != $invert }]
162         close $chan
163     }
164
165     remote_file build delete $output
166     return $ok
167 }
168
169 # Like check_no_messages_and_pattern_nocache, but cache the result.
170 # PROP is the property we're checking, and doubles as a prefix for
171 # temporary filenames.
172 proc check_no_messages_and_pattern {prop pattern args} {
173     return [check_cached_effective_target $prop {
174         eval [list check_no_messages_and_pattern_nocache $prop $pattern] $args
175     }]
176 }
177
178 # Try to compile and run an executable from code CONTENTS.  Return true
179 # if the compiler reports no messages and if execution "passes" in the
180 # usual DejaGNU sense.  The arguments are as for check_compile, with
181 # TYPE implicitly being "executable".
182 proc check_runtime_nocache {basename contents args} {
183     global tool
184
185     set result [eval [list check_compile $basename executable $contents] $args]
186     set lines [lindex $result 0]
187     set output [lindex $result 1]
188
189     set ok 0
190     if { [string match "" $lines] } {
191         # No error messages, everything is OK.
192         set result [remote_load target "./$output" "" ""]
193         set status [lindex $result 0]
194         verbose "check_runtime_nocache $basename: status is <$status>" 2
195         if { $status == "pass" } {
196             set ok 1
197         }
198     }
199     remote_file build delete $output
200     return $ok
201 }
202
203 # Like check_runtime_nocache, but cache the result.  PROP is the
204 # property we're checking, and doubles as a prefix for temporary
205 # filenames.
206 proc check_runtime {prop args} {
207     global tool
208
209     return [check_cached_effective_target $prop {
210         eval [list check_runtime_nocache $prop] $args
211     }]
212 }
213
214 ###############################
215 # proc check_weak_available { }
216 ###############################
217
218 # weak symbols are only supported in some configs/object formats
219 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
220
221 proc check_weak_available { } {
222     global target_triplet
223     global target_cpu
224
225     # All mips targets should support it
226
227     if { [ string first "mips" $target_cpu ] >= 0 } {
228         return 1
229     }
230
231     # All solaris2 targets should support it
232
233     if { [regexp ".*-solaris2.*" $target_triplet] } {
234         return 1
235     }
236
237     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
238
239     if { [regexp "alpha.*osf.*" $target_triplet] } {
240         return 1
241     }
242
243     # Windows targets Cygwin and MingW32 support it
244
245     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
246         return 1
247     }
248
249     # HP-UX 10.X doesn't support it
250
251     if { [istarget "hppa*-*-hpux10*"] } {
252         return 0
253     }
254
255     # ELF and ECOFF support it. a.out does with gas/gld but may also with
256     # other linkers, so we should try it
257
258     set objformat [gcc_target_object_format]
259
260     switch $objformat {
261         elf      { return 1 }
262         ecoff    { return 1 }
263         a.out    { return 1 }
264         mach-o   { return 1 }
265         som      { return 1 }
266         unknown  { return -1 }
267         default  { return 0 }
268     }
269 }
270
271 ###############################
272 # proc check_weak_override_available { }
273 ###############################
274
275 # Like check_weak_available, but return 0 if weak symbol definitions
276 # cannot be overridden.
277
278 proc check_weak_override_available { } {
279     if { [istarget "*-*-mingw*"] } {
280         return 0
281     }
282     return [check_weak_available]
283 }
284
285 ###############################
286 # proc check_visibility_available { what_kind }
287 ###############################
288
289 # The visibility attribute is only support in some object formats
290 # This proc returns 1 if it is supported, 0 if not.
291 # The argument is the kind of visibility, default/protected/hidden/internal.
292
293 proc check_visibility_available { what_kind } {
294     global tool
295     global target_triplet
296
297     # On NetWare, support makes no sense.
298     if { [istarget *-*-netware*] } {
299         return 0
300     }
301
302     if [string match "" $what_kind] { set what_kind "hidden" }
303
304     return [check_no_compiler_messages visibility_available_$what_kind object "
305         void f() __attribute__((visibility(\"$what_kind\")));
306         void f() {}
307     "]
308 }
309
310 ###############################
311 # proc check_alias_available { }
312 ###############################
313
314 # Determine if the target toolchain supports the alias attribute.
315
316 # Returns 2 if the target supports aliases.  Returns 1 if the target
317 # only supports weak aliased.  Returns 0 if the target does not
318 # support aliases at all.  Returns -1 if support for aliases could not
319 # be determined.
320
321 proc check_alias_available { } {
322     global alias_available_saved
323     global tool
324
325     if [info exists alias_available_saved] {
326         verbose "check_alias_available  returning saved $alias_available_saved" 2
327     } else {
328         set src alias[pid].c
329         set obj alias[pid].o
330         verbose "check_alias_available  compiling testfile $src" 2
331         set f [open $src "w"]
332         # Compile a small test program.  The definition of "g" is
333         # necessary to keep the Solaris assembler from complaining
334         # about the program.
335         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
336         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
337         close $f
338         set lines [${tool}_target_compile $src $obj object ""]
339         file delete $src
340         remote_file build delete $obj
341
342         if [string match "" $lines] then {
343             # No error messages, everything is OK.
344             set alias_available_saved 2
345         } else {
346             if [regexp "alias definitions not supported" $lines] {
347                 verbose "check_alias_available  target does not support aliases" 2
348
349                 set objformat [gcc_target_object_format]
350
351                 if { $objformat == "elf" } {
352                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
353                     set alias_available_saved -1
354                 } else {
355                     set alias_available_saved 0
356                 }
357             } else {
358                 if [regexp "only weak aliases are supported" $lines] {
359                 verbose "check_alias_available  target supports only weak aliases" 2
360                 set alias_available_saved 1
361                 } else {
362                     set alias_available_saved -1
363                 }
364             }
365         }
366
367         verbose "check_alias_available  returning $alias_available_saved" 2
368     }
369
370     return $alias_available_saved
371 }
372
373 ###############################
374 # proc check_ifunc_available { }
375 ###############################
376
377 # Determine if the target toolchain supports the ifunc attribute.
378
379 # Returns 1 if the target supports ifunc.  Returns 0 if the target
380 # does not support ifunc.
381
382 proc check_ifunc_available { } {
383     global ifunc_available_saved
384     global tool
385
386     if [info exists ifunc_available_saved] {
387         verbose "check_ifunc_available  returning saved $ifunc_available_saved" 2
388     } else {
389         set src ifunc[pid].c
390         set obj ifunc[pid].o
391         verbose "check_ifunc_available  compiling testfile $src" 2
392         set f [open $src "w"]
393         puts $f "#endif"
394         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif"
395         puts $f "void g() {}"
396         puts $f "void f() __attribute__((ifunc(\"g\")));"
397         close $f
398         set lines [${tool}_target_compile $src $obj object ""]
399         file delete $src
400         remote_file build delete $obj
401
402         if [string match "" $lines] then {
403             set ifunc_available_saved 1
404         } else {
405             set ifunc_available_saved 0
406         }
407
408         verbose "check_ifunc_available  returning $ifunc_available_saved" 2
409     }
410
411     return $ifunc_available_saved
412 }
413
414 # Returns true if --gc-sections is supported on the target.
415
416 proc check_gc_sections_available { } {
417     global gc_sections_available_saved
418     global tool
419
420     if {![info exists gc_sections_available_saved]} {
421         # Some targets don't support gc-sections despite whatever's
422         # advertised by ld's options.
423         if { [istarget alpha*-*-*]
424              || [istarget ia64-*-*] } {
425             set gc_sections_available_saved 0
426             return 0
427         }
428
429         # elf2flt uses -q (--emit-relocs), which is incompatible with
430         # --gc-sections.
431         if { [board_info target exists ldflags]
432              && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
433             set gc_sections_available_saved 0
434             return 0
435         }
436
437         # VxWorks kernel modules are relocatable objects linked with -r,
438         # while RTP executables are linked with -q (--emit-relocs).
439         # Both of these options are incompatible with --gc-sections.
440         if { [istarget *-*-vxworks*] } {
441             set gc_sections_available_saved 0
442             return 0
443         }
444
445         # Check if the ld used by gcc supports --gc-sections.
446         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
447         regsub ".*\n\\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
448         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
449         set ld_output [remote_exec host "$gcc_ld" "--help"]
450         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
451             set gc_sections_available_saved 1
452         } else {
453             set gc_sections_available_saved 0
454         }
455     }
456     return $gc_sections_available_saved
457 }
458
459 # Return 1 if according to target_info struct and explicit target list
460 # target is supposed to support trampolines.
461  
462 proc check_effective_target_trampolines { } {
463     if [target_info exists no_trampolines] {
464       return 0
465     }
466     if { [istarget avr-*-*]
467          || [istarget hppa2.0w-hp-hpux11.23]
468         || [istarget hppa64-hp-hpux11.23] } {
469         return 0;   
470     }
471     return 1
472 }
473
474 # Return 1 if according to target_info struct and explicit target list
475 # target is supposed to keep null pointer checks. This could be due to 
476 # use of option fno-delete-null-pointer-checks or hardwired in target.
477  
478 proc check_effective_target_keeps_null_pointer_checks { } {
479     if [target_info exists keeps_null_pointer_checks] {
480       return 1
481     }
482     if { [istarget avr-*-*] } {
483         return 1;   
484     }
485     return 0
486 }
487
488 # Return true if profiling is supported on the target.
489
490 proc check_profiling_available { test_what } {
491     global profiling_available_saved
492
493     verbose "Profiling argument is <$test_what>" 1
494
495     # These conditions depend on the argument so examine them before
496     # looking at the cache variable.
497
498     # Support for -p on solaris2 relies on mcrt1.o which comes with the
499     # vendor compiler.  We cannot reliably predict the directory where the
500     # vendor compiler (and thus mcrt1.o) is installed so we can't
501     # necessarily find mcrt1.o even if we have it.
502     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
503         return 0
504     }
505
506     # Support for -p on irix relies on libprof1.a which doesn't appear to
507     # exist on any irix6 system currently posting testsuite results.
508     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
509     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
510     if { [istarget mips*-*-irix*]
511     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
512         return 0
513     }
514
515     # We don't yet support profiling for MIPS16.
516     if { [istarget mips*-*-*]
517          && ![check_effective_target_nomips16]
518          && ([lindex $test_what 1] == "-p"
519              || [lindex $test_what 1] == "-pg") } {
520         return 0
521     }
522
523     # MinGW does not support -p.
524     if { [istarget *-*-mingw*] && [lindex $test_what 1] == "-p" } {
525         return 0
526     }
527
528     # cygwin does not support -p.
529     if { [istarget *-*-cygwin*] && [lindex $test_what 1] == "-p" } {
530         return 0
531     }
532
533     # uClibc does not have gcrt1.o.
534     if { [check_effective_target_uclibc]
535          && ([lindex $test_what 1] == "-p"
536              || [lindex $test_what 1] == "-pg") } {
537         return 0
538     }
539
540     # Now examine the cache variable.
541     if {![info exists profiling_available_saved]} {
542         # Some targets don't have any implementation of __bb_init_func or are
543         # missing other needed machinery.
544         if {    [istarget am3*-*-linux*]
545              || [istarget arm*-*-eabi*]
546              || [istarget arm*-*-elf]
547              || [istarget arm*-*-symbianelf*]
548              || [istarget avr-*-*]
549              || [istarget bfin-*-*]
550              || [istarget cris-*-*]
551              || [istarget crisv32-*-*]
552              || [istarget fido-*-elf]
553              || [istarget h8300-*-*]
554              || [istarget lm32-*-*]
555              || [istarget m32c-*-elf]
556              || [istarget m68k-*-elf]
557              || [istarget m68k-*-uclinux*]
558              || [istarget mep-*-elf]
559              || [istarget mips*-*-elf*]
560              || [istarget mmix-*-*]
561              || [istarget mn10300-*-elf*]
562              || [istarget moxie-*-elf*]
563              || [istarget picochip-*-*]
564              || [istarget powerpc-*-eabi*]
565              || [istarget powerpc-*-elf]
566              || [istarget rx-*-*]       
567              || [istarget xstormy16-*]
568              || [istarget xtensa*-*-elf]
569              || [istarget *-*-netware*]
570              || [istarget *-*-rtems*]
571              || [istarget *-*-vxworks*] } {
572             set profiling_available_saved 0
573         } else {
574             set profiling_available_saved 1
575         }
576     }
577
578     return $profiling_available_saved
579 }
580
581 # Check to see if a target is "freestanding". This is as per the definition
582 # in Section 4 of C99 standard. Effectively, it is a target which supports no
583 # extra headers or libraries other than what is considered essential.
584 proc check_effective_target_freestanding { } {
585     if { [istarget picochip-*-*] } then {
586         return 1
587     } else {
588         return 0
589     }
590 }
591
592 # Return 1 if target has packed layout of structure members by
593 # default, 0 otherwise.  Note that this is slightly different than
594 # whether the target has "natural alignment": both attributes may be
595 # false.
596
597 proc check_effective_target_default_packed { } {
598     return [check_no_compiler_messages default_packed assembly {
599         struct x { char a; long b; } c;
600         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
601     }]
602 }
603
604 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
605 # documentation, where the test also comes from.
606
607 proc check_effective_target_pcc_bitfield_type_matters { } {
608     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
609     # bitfields, but let's stick to the example code from the docs.
610     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
611         struct foo1 { char x; char :0; char y; };
612         struct foo2 { char x; int :0; char y; };
613         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
614     }]
615 }
616
617 # Add to FLAGS all the target-specific flags needed to use thread-local storage.
618
619 proc add_options_for_tls { flags } {
620     # Tru64 UNIX uses emutls, which relies on a couple of pthread functions
621     # which only live in libpthread, so always pass -pthread for TLS.
622     if { [istarget *-*-osf*] } {
623         return "$flags -pthread"
624     }
625     # On Solaris 8 and 9, __tls_get_addr/___tls_get_addr only lives in
626     # libthread, so always pass -pthread for native TLS.
627     # Need to duplicate native TLS check from
628     # check_effective_target_tls_native to avoid recursion.
629     if { [istarget *-*-solaris2.\[89\]*] &&
630          [check_no_messages_and_pattern tls_native "!emutls" assembly {
631              __thread int i;
632              int f (void) { return i; }
633              void g (int j) { i = j; }
634          }] } {
635         return "$flags -pthread"
636     }
637     return $flags
638 }
639
640 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
641
642 proc check_effective_target_tls {} {
643     return [check_no_compiler_messages tls assembly {
644         __thread int i;
645         int f (void) { return i; }
646         void g (int j) { i = j; }
647     }]
648 }
649
650 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
651
652 proc check_effective_target_tls_native {} {
653     # VxWorks uses emulated TLS machinery, but with non-standard helper
654     # functions, so we fail to automatically detect it.
655     global target_triplet
656     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
657         return 0
658     }
659     
660     return [check_no_messages_and_pattern tls_native "!emutls" assembly {
661         __thread int i;
662         int f (void) { return i; }
663         void g (int j) { i = j; }
664     }]
665 }
666
667 # Return 1 if *emulated* thread local storage (TLS) is supported, 0 otherwise.
668
669 proc check_effective_target_tls_emulated {} {
670     # VxWorks uses emulated TLS machinery, but with non-standard helper
671     # functions, so we fail to automatically detect it.
672     global target_triplet
673     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
674         return 1
675     }
676     
677     return [check_no_messages_and_pattern tls_emulated "emutls" assembly {
678         __thread int i;
679         int f (void) { return i; }
680         void g (int j) { i = j; }
681     }]
682 }
683
684 # Return 1 if TLS executables can run correctly, 0 otherwise.
685
686 proc check_effective_target_tls_runtime {} {
687     return [check_runtime tls_runtime {
688         __thread int thr = 0;
689         int main (void) { return thr; }
690     } [add_options_for_tls ""]]
691 }
692
693 # Return 1 if -ffunction-sections is supported, 0 otherwise.
694
695 proc check_effective_target_function_sections {} {
696     # Darwin has its own scheme and silently accepts -ffunction-sections.
697     global target_triplet
698     if { [regexp ".*-.*-darwin.*" $target_triplet] } {
699         return 0
700     }
701     
702     return [check_no_compiler_messages functionsections assembly {
703         void foo (void) { }
704     } "-ffunction-sections"]
705 }
706
707 # Return 1 if compilation with -fgraphite is error-free for trivial 
708 # code, 0 otherwise.
709
710 proc check_effective_target_fgraphite {} {
711     return [check_no_compiler_messages fgraphite object {
712         void foo (void) { }
713     } "-O1 -fgraphite"]
714 }
715
716 # Return 1 if compilation with -fopenmp is error-free for trivial
717 # code, 0 otherwise.
718
719 proc check_effective_target_fopenmp {} {
720     return [check_no_compiler_messages fopenmp object {
721         void foo (void) { }
722     } "-fopenmp"]
723 }
724
725 # Return 1 if compilation with -pthread is error-free for trivial
726 # code, 0 otherwise.
727
728 proc check_effective_target_pthread {} {
729     return [check_no_compiler_messages pthread object {
730         void foo (void) { }
731     } "-pthread"]
732 }
733
734 # Return 1 if compilation with -mpe-aligned-commons is error-free
735 # for trivial code, 0 otherwise.
736
737 proc check_effective_target_pe_aligned_commons {} {
738     if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
739         return [check_no_compiler_messages pe_aligned_commons object {
740             int foo;
741         } "-mpe-aligned-commons"]
742     }
743     return 0
744 }
745
746 # Return 1 if the target supports -static
747 proc check_effective_target_static {} {
748     return [check_no_compiler_messages static executable {
749         int main (void) { return 0; }
750     } "-static"]
751 }
752
753 # Return 1 if the target supports -fstack-protector
754 proc check_effective_target_fstack_protector {} {
755     return [check_runtime fstack_protector {
756         int main (void) { return 0; }
757     } "-fstack-protector"]
758 }
759
760 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
761 # for trivial code, 0 otherwise.
762
763 proc check_effective_target_freorder {} {
764     return [check_no_compiler_messages freorder object {
765         void foo (void) { }
766     } "-freorder-blocks-and-partition"]
767 }
768
769 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
770 # emitted, 0 otherwise.  Whether a shared library can actually be built is
771 # out of scope for this test.
772
773 proc check_effective_target_fpic { } {
774     # Note that M68K has a multilib that supports -fpic but not
775     # -fPIC, so we need to check both.  We test with a program that
776     # requires GOT references.
777     foreach arg {fpic fPIC} {
778         if [check_no_compiler_messages $arg object {
779             extern int foo (void); extern int bar;
780             int baz (void) { return foo () + bar; }
781         } "-$arg"] {
782             return 1
783         }
784     }
785     return 0
786 }
787
788 # Return true if the target supports -mpaired-single (as used on MIPS).
789
790 proc check_effective_target_mpaired_single { } {
791     return [check_no_compiler_messages mpaired_single object {
792         void foo (void) { }
793     } "-mpaired-single"]
794 }
795
796 # Return true if the target has access to FPU instructions.
797
798 proc check_effective_target_hard_float { } {
799     if { [istarget mips*-*-*] } {
800         return [check_no_compiler_messages hard_float assembly {
801                 #if (defined __mips_soft_float || defined __mips16)
802                 #error FOO
803                 #endif
804         }]
805     }
806
807     # This proc is actually checking the availabilty of FPU
808     # support for doubles, so on the RX we must fail if the
809     # 64-bit double multilib has been selected.
810     if { [istarget rx-*-*] } {
811         return 0
812         # return [check_no_compiler_messages hard_float assembly {
813                 #if defined __RX_64_BIT_DOUBLES__
814                 #error FOO
815                 #endif
816         # }]
817     }
818
819     # The generic test equates hard_float with "no call for adding doubles".
820     return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
821         double a (double b, double c) { return b + c; }
822     }]
823 }
824
825 # Return true if the target is a 64-bit MIPS target.
826
827 proc check_effective_target_mips64 { } {
828     return [check_no_compiler_messages mips64 assembly {
829         #ifndef __mips64
830         #error FOO
831         #endif
832     }]
833 }
834
835 # Return true if the target is a MIPS target that does not produce
836 # MIPS16 code.
837
838 proc check_effective_target_nomips16 { } {
839     return [check_no_compiler_messages nomips16 object {
840         #ifndef __mips
841         #error FOO
842         #else
843         /* A cheap way of testing for -mflip-mips16.  */
844         void foo (void) { asm ("addiu $20,$20,1"); }
845         void bar (void) { asm ("addiu $20,$20,1"); }
846         #endif
847     }]
848 }
849
850 # Add the options needed for MIPS16 function attributes.  At the moment,
851 # we don't support MIPS16 PIC.
852
853 proc add_options_for_mips16_attribute { flags } {
854     return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
855 }
856
857 # Return true if we can force a mode that allows MIPS16 code generation.
858 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
859 # for o32 and o64.
860
861 proc check_effective_target_mips16_attribute { } {
862     return [check_no_compiler_messages mips16_attribute assembly {
863         #ifdef PIC
864         #error FOO
865         #endif
866         #if defined __mips_hard_float \
867             && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
868             && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
869         #error FOO
870         #endif
871     } [add_options_for_mips16_attribute ""]]
872 }
873
874 # Return 1 if the target supports long double larger than double when
875 # using the new ABI, 0 otherwise.
876
877 proc check_effective_target_mips_newabi_large_long_double { } {
878     return [check_no_compiler_messages mips_newabi_large_long_double object {
879         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
880     } "-mabi=64"]
881 }
882
883 # Return 1 if the current multilib does not generate PIC by default.
884
885 proc check_effective_target_nonpic { } {
886     return [check_no_compiler_messages nonpic assembly {
887         #if __PIC__
888         #error FOO
889         #endif
890     }]
891 }
892
893 # Return 1 if the target does not use a status wrapper.
894
895 proc check_effective_target_unwrapped { } {
896     if { [target_info needs_status_wrapper] != "" \
897              && [target_info needs_status_wrapper] != "0" } {
898         return 0
899     }
900     return 1
901 }
902
903 # Return true if iconv is supported on the target. In particular IBM1047.
904
905 proc check_iconv_available { test_what } {
906     global libiconv
907
908     # If the tool configuration file has not set libiconv, try "-liconv"
909     if { ![info exists libiconv] } {
910         set libiconv "-liconv"
911     }
912     set test_what [lindex $test_what 1]
913     return [check_runtime_nocache $test_what [subst {
914         #include <iconv.h>
915         int main (void)
916         {
917           iconv_t cd;
918
919           cd = iconv_open ("$test_what", "UTF-8");
920           if (cd == (iconv_t) -1)
921             return 1;
922           return 0;
923         }
924     }] $libiconv]
925 }
926
927 # Return 1 if an ASCII locale is supported on this host, 0 otherwise.
928
929 proc check_ascii_locale_available { } {
930     if { ([ishost alpha*-dec-osf*] || [ishost mips-sgi-irix*]) } {
931         # Neither Tru64 UNIX nor IRIX support an ASCII locale.
932         return 0
933     } else {
934         return 1
935     }
936 }
937
938 # Return true if named sections are supported on this target.
939
940 proc check_named_sections_available { } {
941     return [check_no_compiler_messages named_sections assembly {
942         int __attribute__ ((section("whatever"))) foo;
943     }]
944 }
945
946 # Return 1 if the target supports Fortran real kinds larger than real(8),
947 # 0 otherwise.
948 #
949 # When the target name changes, replace the cached result.
950
951 proc check_effective_target_fortran_large_real { } {
952     return [check_no_compiler_messages fortran_large_real executable {
953         ! Fortran
954         integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
955         real(kind=k) :: x
956         x = cos (x)
957         end
958     }]
959 }
960
961 # Return 1 if the target supports Fortran real kind real(16),
962 # 0 otherwise. Contrary to check_effective_target_fortran_large_real
963 # this checks for Real(16) only; the other returned real(10) if
964 # both real(10) and real(16) are available.
965 #
966 # When the target name changes, replace the cached result.
967
968 proc check_effective_target_fortran_real_16 { } {
969     return [check_no_compiler_messages fortran_real_16 executable {
970         ! Fortran
971         real(kind=16) :: x
972         x = cos (x)
973         end
974     }]
975 }
976
977 # Return 1 if the target supports Fortran integer kinds larger than
978 # integer(8), 0 otherwise.
979 #
980 # When the target name changes, replace the cached result.
981
982 proc check_effective_target_fortran_large_int { } {
983     return [check_no_compiler_messages fortran_large_int executable {
984         ! Fortran
985         integer,parameter :: k = selected_int_kind (range (0_8) + 1)
986         integer(kind=k) :: i
987         end
988     }]
989 }
990
991 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
992 #
993 # When the target name changes, replace the cached result.
994
995 proc check_effective_target_fortran_integer_16 { } {
996     return [check_no_compiler_messages fortran_integer_16 executable {
997         ! Fortran
998         integer(16) :: i
999         end
1000     }]
1001 }
1002
1003 # Return 1 if we can statically link libgfortran, 0 otherwise.
1004 #
1005 # When the target name changes, replace the cached result.
1006
1007 proc check_effective_target_static_libgfortran { } {
1008     return [check_no_compiler_messages static_libgfortran executable {
1009         ! Fortran
1010         print *, 'test'
1011         end
1012     } "-static"]
1013 }
1014
1015 proc check_linker_plugin_available { } {
1016   return [check_no_compiler_messages_nocache linker_plugin executable {
1017      int main() { return 0; }
1018   } "-flto -fuse-linker-plugin"]
1019 }
1020
1021 # Return 1 if the target supports executing 750CL paired-single instructions, 0
1022 # otherwise.  Cache the result.
1023
1024 proc check_750cl_hw_available { } {
1025     return [check_cached_effective_target 750cl_hw_available {
1026         # If this is not the right target then we can skip the test.
1027         if { ![istarget powerpc-*paired*] } {
1028             expr 0
1029         } else {
1030             check_runtime_nocache 750cl_hw_available {
1031                  int main()
1032                  {
1033                  #ifdef __MACH__
1034                    asm volatile ("ps_mul v0,v0,v0");
1035                  #else
1036                    asm volatile ("ps_mul 0,0,0");
1037                  #endif
1038                    return 0;
1039                  }
1040             } "-mpaired"
1041         }
1042     }]
1043 }
1044
1045 # Return 1 if the target OS supports running SSE executables, 0
1046 # otherwise.  Cache the result.
1047
1048 proc check_sse_os_support_available { } {
1049     return [check_cached_effective_target sse_os_support_available {
1050         # If this is not the right target then we can skip the test.
1051         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1052             expr 0
1053         } elseif { [istarget i?86-*-solaris2*] } {
1054             # The Solaris 2 kernel doesn't save and restore SSE registers
1055             # before Solaris 9 4/04.  Before that, executables die with SIGILL.
1056             check_runtime_nocache sse_os_support_available {
1057                 int main ()
1058                 {
1059                     __asm__ volatile ("movss %xmm2,%xmm1");
1060                     return 0;
1061                 }
1062             } "-msse"
1063         } else {
1064             expr 1
1065         }
1066     }]
1067 }
1068
1069 # Return 1 if the target supports executing SSE instructions, 0
1070 # otherwise.  Cache the result.
1071
1072 proc check_sse_hw_available { } {
1073     return [check_cached_effective_target sse_hw_available {
1074         # If this is not the right target then we can skip the test.
1075         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1076             expr 0
1077         } else {
1078             check_runtime_nocache sse_hw_available {
1079                 #include "cpuid.h"
1080                 int main ()
1081                 {
1082                   unsigned int eax, ebx, ecx, edx;
1083                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1084                     return !(edx & bit_SSE);
1085                   return 1;
1086                 }
1087             } ""
1088         }
1089     }]
1090 }
1091
1092 # Return 1 if the target supports executing SSE2 instructions, 0
1093 # otherwise.  Cache the result.
1094
1095 proc check_sse2_hw_available { } {
1096     return [check_cached_effective_target sse2_hw_available {
1097         # If this is not the right target then we can skip the test.
1098         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1099             expr 0
1100         } else {
1101             check_runtime_nocache sse2_hw_available {
1102                 #include "cpuid.h"
1103                 int main ()
1104                 {
1105                   unsigned int eax, ebx, ecx, edx;
1106                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1107                     return !(edx & bit_SSE2);
1108                   return 1;
1109                 }
1110             } ""
1111         }
1112     }]
1113 }
1114
1115 # Return 1 if the target supports executing AVX instructions, 0
1116 # otherwise.  Cache the result.
1117
1118 proc check_avx_hw_available { } {
1119     return [check_cached_effective_target avx_hw_available {
1120         # If this is not the right target then we can skip the test.
1121         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1122             expr 0
1123         } else {
1124             check_runtime_nocache avx_hw_available {
1125                 #include "cpuid.h"
1126                 int main ()
1127                 {
1128                   unsigned int eax, ebx, ecx, edx;
1129                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1130                     return ((ecx & (bit_AVX | bit_OSXSAVE))
1131                             != (bit_AVX | bit_OSXSAVE));
1132                   return 1;
1133                 }
1134             } ""
1135         }
1136     }]
1137 }
1138
1139 # Return 1 if the target supports running SSE executables, 0 otherwise.
1140
1141 proc check_effective_target_sse_runtime { } {
1142     if { [check_effective_target_sse]
1143          && [check_sse_hw_available]
1144          && [check_sse_os_support_available] } {
1145         return 1
1146     }
1147     return 0
1148 }
1149
1150 # Return 1 if the target supports running SSE2 executables, 0 otherwise.
1151
1152 proc check_effective_target_sse2_runtime { } {
1153     if { [check_effective_target_sse2]
1154          && [check_sse2_hw_available]
1155          && [check_sse_os_support_available] } {
1156         return 1
1157     }
1158     return 0
1159 }
1160
1161 # Return 1 if the target supports running AVX executables, 0 otherwise.
1162
1163 proc check_effective_target_avx_runtime { } {
1164     if { [check_effective_target_avx]
1165          && [check_avx_hw_available] } {
1166         return 1
1167     }
1168     return 0
1169 }
1170
1171 # Return 1 if the target supports executing VSX instructions, 0
1172 # otherwise.  Cache the result.
1173
1174 proc check_vsx_hw_available { } {
1175     return [check_cached_effective_target vsx_hw_available {
1176         # Some simulators are known to not support VSX instructions.
1177         # For now, disable on Darwin
1178         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
1179             expr 0
1180         } else {
1181             set options "-mvsx"
1182             check_runtime_nocache vsx_hw_available {
1183                 int main()
1184                 {
1185                 #ifdef __MACH__
1186                   asm volatile ("xxlor vs0,vs0,vs0");
1187                 #else
1188                   asm volatile ("xxlor 0,0,0");
1189                 #endif
1190                   return 0;
1191                 }
1192             } $options
1193         }
1194     }]
1195 }
1196
1197 # Return 1 if the target supports executing AltiVec instructions, 0
1198 # otherwise.  Cache the result.
1199
1200 proc check_vmx_hw_available { } {
1201     return [check_cached_effective_target vmx_hw_available {
1202         # Some simulators are known to not support VMX instructions.
1203         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1204             expr 0
1205         } else {
1206             # Most targets don't require special flags for this test case, but
1207             # Darwin does.  Just to be sure, make sure VSX is not enabled for
1208             # the altivec tests.
1209             if { [istarget *-*-darwin*]
1210                  || [istarget *-*-aix*] } {
1211                 set options "-maltivec -mno-vsx"
1212             } else {
1213                 set options "-mno-vsx"
1214             }
1215             check_runtime_nocache vmx_hw_available {
1216                 int main()
1217                 {
1218                 #ifdef __MACH__
1219                   asm volatile ("vor v0,v0,v0");
1220                 #else
1221                   asm volatile ("vor 0,0,0");
1222                 #endif
1223                   return 0;
1224                 }
1225             } $options
1226         }
1227     }]
1228 }
1229
1230 proc check_ppc_recip_hw_available { } {
1231     return [check_cached_effective_target ppc_recip_hw_available {
1232         # Some simulators may not support FRE/FRES/FRSQRTE/FRSQRTES
1233         # For now, disable on Darwin
1234         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
1235             expr 0
1236         } else {
1237             set options "-mpowerpc-gfxopt -mpowerpc-gpopt -mpopcntb"
1238             check_runtime_nocache ppc_recip_hw_available {
1239                 volatile double d_recip, d_rsqrt, d_four = 4.0;
1240                 volatile float f_recip, f_rsqrt, f_four = 4.0f;
1241                 int main()
1242                 {
1243                   asm volatile ("fres %0,%1" : "=f" (f_recip) : "f" (f_four));
1244                   asm volatile ("fre %0,%1" : "=d" (d_recip) : "d" (d_four));
1245                   asm volatile ("frsqrtes %0,%1" : "=f" (f_rsqrt) : "f" (f_four));
1246                   asm volatile ("frsqrte %0,%1" : "=f" (d_rsqrt) : "d" (d_four));
1247                   return 0;
1248                 }
1249             } $options
1250         }
1251     }]
1252 }
1253
1254 # Return 1 if the target supports executing AltiVec and Cell PPU
1255 # instructions, 0 otherwise.  Cache the result.
1256
1257 proc check_effective_target_cell_hw { } {
1258     return [check_cached_effective_target cell_hw_available {
1259         # Some simulators are known to not support VMX and PPU instructions.
1260         if { [istarget powerpc-*-eabi*] } {
1261             expr 0
1262         } else {
1263             # Most targets don't require special flags for this test
1264             # case, but Darwin and AIX do.
1265             if { [istarget *-*-darwin*]
1266                  || [istarget *-*-aix*] } {
1267                 set options "-maltivec -mcpu=cell"
1268             } else {
1269                 set options "-mcpu=cell"
1270             }
1271             check_runtime_nocache cell_hw_available {
1272                 int main()
1273                 {
1274                 #ifdef __MACH__
1275                   asm volatile ("vor v0,v0,v0");
1276                   asm volatile ("lvlx v0,r0,r0");
1277                 #else
1278                   asm volatile ("vor 0,0,0");
1279                   asm volatile ("lvlx 0,0,0");
1280                 #endif
1281                   return 0;
1282                 }
1283             } $options
1284         }
1285     }]
1286 }
1287
1288 # Return 1 if the target supports executing 64-bit instructions, 0
1289 # otherwise.  Cache the result.
1290
1291 proc check_effective_target_powerpc64 { } {
1292     global powerpc64_available_saved
1293     global tool
1294
1295     if [info exists powerpc64_available_saved] {
1296         verbose "check_effective_target_powerpc64 returning saved $powerpc64_available_saved" 2
1297     } else {
1298         set powerpc64_available_saved 0
1299
1300         # Some simulators are known to not support powerpc64 instructions.
1301         if { [istarget powerpc-*-eabi*] || [istarget powerpc-ibm-aix*] } {
1302             verbose "check_effective_target_powerpc64 returning 0" 2
1303             return $powerpc64_available_saved
1304         }
1305
1306         # Set up, compile, and execute a test program containing a 64-bit
1307         # instruction.  Include the current process ID in the file
1308         # names to prevent conflicts with invocations for multiple
1309         # testsuites.
1310         set src ppc[pid].c
1311         set exe ppc[pid].x
1312
1313         set f [open $src "w"]
1314         puts $f "int main() {"
1315         puts $f "#ifdef __MACH__"
1316         puts $f "  asm volatile (\"extsw r0,r0\");"
1317         puts $f "#else"
1318         puts $f "  asm volatile (\"extsw 0,0\");"
1319         puts $f "#endif"
1320         puts $f "  return 0; }"
1321         close $f
1322
1323         set opts "additional_flags=-mcpu=G5"
1324
1325         verbose "check_effective_target_powerpc64 compiling testfile $src" 2
1326         set lines [${tool}_target_compile $src $exe executable "$opts"]
1327         file delete $src
1328
1329         if [string match "" $lines] then {
1330             # No error message, compilation succeeded.
1331             set result [${tool}_load "./$exe" "" ""]
1332             set status [lindex $result 0]
1333             remote_file build delete $exe
1334             verbose "check_effective_target_powerpc64 testfile status is <$status>" 2
1335
1336             if { $status == "pass" } then {
1337                 set powerpc64_available_saved 1
1338             }
1339         } else {
1340             verbose "check_effective_target_powerpc64 testfile compilation failed" 2
1341         }
1342     }
1343
1344     return $powerpc64_available_saved
1345 }
1346
1347 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
1348 # complex float arguments.  This affects gfortran tests that call cabsf
1349 # in libm built by an earlier compiler.  Return 1 if libm uses the same
1350 # argument passing as the compiler under test, 0 otherwise.
1351 #
1352 # When the target name changes, replace the cached result.
1353
1354 proc check_effective_target_broken_cplxf_arg { } {
1355     return [check_cached_effective_target broken_cplxf_arg {
1356         # Skip the work for targets known not to be affected.
1357         if { ![istarget powerpc64-*-linux*] } {
1358             expr 0
1359         } elseif { ![is-effective-target lp64] } {
1360             expr 0
1361         } else {
1362             check_runtime_nocache broken_cplxf_arg {
1363                 #include <complex.h>
1364                 extern void abort (void);
1365                 float fabsf (float);
1366                 float cabsf (_Complex float);
1367                 int main ()
1368                 {
1369                   _Complex float cf;
1370                   float f;
1371                   cf = 3 + 4.0fi;
1372                   f = cabsf (cf);
1373                   if (fabsf (f - 5.0) > 0.0001)
1374                     abort ();
1375                   return 0;
1376                 }
1377             } "-lm"
1378         }
1379     }]
1380 }
1381
1382 proc check_alpha_max_hw_available { } {
1383     return [check_runtime alpha_max_hw_available {
1384         int main() { return __builtin_alpha_amask(1<<8) != 0; }
1385     }]
1386 }
1387
1388 # Returns true iff the FUNCTION is available on the target system.
1389 # (This is essentially a Tcl implementation of Autoconf's
1390 # AC_CHECK_FUNC.)
1391
1392 proc check_function_available { function } {
1393     return [check_no_compiler_messages ${function}_available \
1394                 executable [subst {
1395         #ifdef __cplusplus
1396         extern "C"
1397         #endif
1398         char $function ();
1399         int main () { $function (); }
1400     }] "-fno-builtin" ]
1401 }
1402
1403 # Returns true iff "fork" is available on the target system.
1404
1405 proc check_fork_available {} {
1406     return [check_function_available "fork"]
1407 }
1408
1409 # Returns true iff "mkfifo" is available on the target system.
1410
1411 proc check_mkfifo_available {} {
1412     if {[istarget *-*-cygwin*]} {
1413        # Cygwin has mkfifo, but support is incomplete.
1414        return 0
1415      }
1416
1417     return [check_function_available "mkfifo"]
1418 }
1419
1420 # Returns true iff "__cxa_atexit" is used on the target system.
1421
1422 proc check_cxa_atexit_available { } {
1423     return [check_cached_effective_target cxa_atexit_available {
1424         if { [istarget "hppa*-*-hpux10*"] } {
1425             # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1426             expr 0
1427         } elseif { [istarget "*-*-vxworks"] } {
1428             # vxworks doesn't have __cxa_atexit but subsequent test passes.
1429             expr 0
1430         } else {
1431             check_runtime_nocache cxa_atexit_available {
1432                 // C++
1433                 #include <stdlib.h>
1434                 static unsigned int count;
1435                 struct X
1436                 {
1437                   X() { count = 1; }
1438                   ~X()
1439                   {
1440                     if (count != 3)
1441                       exit(1);
1442                     count = 4;
1443                   }
1444                 };
1445                 void f()
1446                 {
1447                   static X x;
1448                 }
1449                 struct Y
1450                 {
1451                   Y() { f(); count = 2; }
1452                   ~Y()
1453                   {
1454                     if (count != 2)
1455                       exit(1);
1456                     count = 3;
1457                   }
1458                 };
1459                 Y y;
1460                 int main() { return 0; }
1461             }
1462         }
1463     }]
1464 }
1465
1466 proc check_effective_target_objc2 { } {
1467     return [check_no_compiler_messages objc2 object {
1468         #ifdef __OBJC2__
1469         int dummy[1];
1470         #else
1471         #error
1472         #endif 
1473     }]
1474 }
1475
1476 proc check_effective_target_next_runtime { } {
1477     return [check_no_compiler_messages objc2 object {
1478         #ifdef __NEXT_RUNTIME__
1479         int dummy[1];
1480         #else
1481         #error
1482         #endif 
1483     }]
1484 }
1485
1486 # Return 1 if we're generating 32-bit code using default options, 0
1487 # otherwise.
1488
1489 proc check_effective_target_ilp32 { } {
1490     return [check_no_compiler_messages ilp32 object {
1491         int dummy[sizeof (int) == 4
1492                   && sizeof (void *) == 4
1493                   && sizeof (long) == 4 ? 1 : -1];
1494     }]
1495 }
1496
1497 # Return 1 if we're generating 32-bit or larger integers using default
1498 # options, 0 otherwise.
1499
1500 proc check_effective_target_int32plus { } {
1501     return [check_no_compiler_messages int32plus object {
1502         int dummy[sizeof (int) >= 4 ? 1 : -1];
1503     }]
1504 }
1505
1506 # Return 1 if we're generating 32-bit or larger pointers using default
1507 # options, 0 otherwise.
1508
1509 proc check_effective_target_ptr32plus { } {
1510     return [check_no_compiler_messages ptr32plus object {
1511         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1512     }]
1513 }
1514
1515 # Return 1 if we support 32-bit or larger array and structure sizes
1516 # using default options, 0 otherwise.
1517
1518 proc check_effective_target_size32plus { } {
1519     return [check_no_compiler_messages size32plus object {
1520         char dummy[65537];
1521     }]
1522 }
1523
1524 # Returns 1 if we're generating 16-bit or smaller integers with the
1525 # default options, 0 otherwise.
1526
1527 proc check_effective_target_int16 { } {
1528     return [check_no_compiler_messages int16 object {
1529         int dummy[sizeof (int) < 4 ? 1 : -1];
1530     }]
1531 }
1532
1533 # Return 1 if we're generating 64-bit code using default options, 0
1534 # otherwise.
1535
1536 proc check_effective_target_lp64 { } {
1537     return [check_no_compiler_messages lp64 object {
1538         int dummy[sizeof (int) == 4
1539                   && sizeof (void *) == 8
1540                   && sizeof (long) == 8 ? 1 : -1];
1541     }]
1542 }
1543
1544 # Return 1 if we're generating 64-bit code using default llp64 options,
1545 # 0 otherwise.
1546
1547 proc check_effective_target_llp64 { } {
1548     return [check_no_compiler_messages llp64 object {
1549         int dummy[sizeof (int) == 4
1550                   && sizeof (void *) == 8
1551                   && sizeof (long long) == 8
1552                   && sizeof (long) == 4 ? 1 : -1];
1553     }]
1554 }
1555
1556 # Return 1 if the target supports long double larger than double,
1557 # 0 otherwise.
1558
1559 proc check_effective_target_large_long_double { } {
1560     return [check_no_compiler_messages large_long_double object {
1561         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1562     }]
1563 }
1564
1565 # Return 1 if the target supports double larger than float,
1566 # 0 otherwise.
1567
1568 proc check_effective_target_large_double { } {
1569     return [check_no_compiler_messages large_double object {
1570         int dummy[sizeof(double) > sizeof(float) ? 1 : -1];
1571     }]
1572 }
1573
1574 # Return 1 if the target supports double of 64 bits,
1575 # 0 otherwise.
1576
1577 proc check_effective_target_double64 { } {
1578     return [check_no_compiler_messages double64 object {
1579         int dummy[sizeof(double) == 8 ? 1 : -1];
1580     }]
1581 }
1582
1583 # Return 1 if the target supports double of at least 64 bits,
1584 # 0 otherwise.
1585
1586 proc check_effective_target_double64plus { } {
1587     return [check_no_compiler_messages double64plus object {
1588         int dummy[sizeof(double) >= 8 ? 1 : -1];
1589     }]
1590 }
1591
1592 # Return 1 if the target supports compiling fixed-point,
1593 # 0 otherwise.
1594
1595 proc check_effective_target_fixed_point { } {
1596     return [check_no_compiler_messages fixed_point object {
1597         _Sat _Fract x; _Sat _Accum y;
1598     }]
1599 }
1600
1601 # Return 1 if the target supports compiling decimal floating point,
1602 # 0 otherwise.
1603
1604 proc check_effective_target_dfp_nocache { } {
1605     verbose "check_effective_target_dfp_nocache: compiling source" 2
1606     set ret [check_no_compiler_messages_nocache dfp object {
1607         float x __attribute__((mode(DD)));
1608     }]
1609     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1610     return $ret
1611 }
1612
1613 proc check_effective_target_dfprt_nocache { } {
1614     return [check_runtime_nocache dfprt {
1615         typedef float d64 __attribute__((mode(DD)));
1616         d64 x = 1.2df, y = 2.3dd, z;
1617         int main () { z = x + y; return 0; }
1618     }]
1619 }
1620
1621 # Return 1 if the target supports compiling Decimal Floating Point,
1622 # 0 otherwise.
1623 #
1624 # This won't change for different subtargets so cache the result.
1625
1626 proc check_effective_target_dfp { } {
1627     return [check_cached_effective_target dfp {
1628         check_effective_target_dfp_nocache
1629     }]
1630 }
1631
1632 # Return 1 if the target supports linking and executing Decimal Floating
1633 # Point, 0 otherwise.
1634 #
1635 # This won't change for different subtargets so cache the result.
1636
1637 proc check_effective_target_dfprt { } {
1638     return [check_cached_effective_target dfprt {
1639         check_effective_target_dfprt_nocache
1640     }]
1641 }
1642
1643 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
1644
1645 proc check_effective_target_ucn_nocache { } {
1646     # -std=c99 is only valid for C
1647     if [check_effective_target_c] {
1648         set ucnopts "-std=c99"
1649     }
1650     append ucnopts " -fextended-identifiers"
1651     verbose "check_effective_target_ucn_nocache: compiling source" 2
1652     set ret [check_no_compiler_messages_nocache ucn object {
1653         int \u00C0;
1654     } $ucnopts]
1655     verbose "check_effective_target_ucn_nocache: returning $ret" 2
1656     return $ret
1657 }
1658
1659 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
1660 #
1661 # This won't change for different subtargets, so cache the result.
1662
1663 proc check_effective_target_ucn { } {
1664     return [check_cached_effective_target ucn {
1665         check_effective_target_ucn_nocache
1666     }]
1667 }
1668
1669 # Return 1 if the target needs a command line argument to enable a SIMD
1670 # instruction set.
1671
1672 proc check_effective_target_vect_cmdline_needed { } {
1673     global et_vect_cmdline_needed_saved
1674     global et_vect_cmdline_needed_target_name
1675
1676     if { ![info exists et_vect_cmdline_needed_target_name] } {
1677         set et_vect_cmdline_needed_target_name ""
1678     }
1679
1680     # If the target has changed since we set the cached value, clear it.
1681     set current_target [current_target_name]
1682     if { $current_target != $et_vect_cmdline_needed_target_name } {
1683         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1684         set et_vect_cmdline_needed_target_name $current_target
1685         if { [info exists et_vect_cmdline_needed_saved] } {
1686             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1687             unset et_vect_cmdline_needed_saved
1688         }
1689     }
1690
1691     if [info exists et_vect_cmdline_needed_saved] {
1692         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1693     } else {
1694         set et_vect_cmdline_needed_saved 1
1695         if { [istarget alpha*-*-*]
1696              || [istarget ia64-*-*]
1697              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1698                  && [check_effective_target_lp64])
1699              || ([istarget powerpc*-*-*]
1700                  && ([check_effective_target_powerpc_spe]
1701                      || [check_effective_target_powerpc_altivec]))
1702              || [istarget spu-*-*]
1703              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
1704            set et_vect_cmdline_needed_saved 0
1705         }
1706     }
1707
1708     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1709     return $et_vect_cmdline_needed_saved
1710 }
1711
1712 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1713 #
1714 # This won't change for different subtargets so cache the result.
1715
1716 proc check_effective_target_vect_int { } {
1717     global et_vect_int_saved
1718
1719     if [info exists et_vect_int_saved] {
1720         verbose "check_effective_target_vect_int: using cached result" 2
1721     } else {
1722         set et_vect_int_saved 0
1723         if { [istarget i?86-*-*]
1724              || ([istarget powerpc*-*-*]
1725                   && ![istarget powerpc-*-linux*paired*])
1726               || [istarget spu-*-*]
1727               || [istarget x86_64-*-*]
1728               || [istarget sparc*-*-*]
1729               || [istarget alpha*-*-*]
1730               || [istarget ia64-*-*] 
1731               || [check_effective_target_arm32]
1732               || ([istarget mips*-*-*]
1733                   && [check_effective_target_mips_loongson]) } {
1734            set et_vect_int_saved 1
1735         }
1736     }
1737
1738     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1739     return $et_vect_int_saved
1740 }
1741
1742 # Return 1 if the target supports signed int->float conversion 
1743 #
1744
1745 proc check_effective_target_vect_intfloat_cvt { } {
1746     global et_vect_intfloat_cvt_saved
1747
1748     if [info exists et_vect_intfloat_cvt_saved] {
1749         verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1750     } else {
1751         set et_vect_intfloat_cvt_saved 0
1752         if { [istarget i?86-*-*]
1753               || ([istarget powerpc*-*-*]
1754                    && ![istarget powerpc-*-linux*paired*])
1755               || [istarget x86_64-*-*] } {
1756            set et_vect_intfloat_cvt_saved 1
1757         }
1758     }
1759
1760     verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1761     return $et_vect_intfloat_cvt_saved
1762 }
1763
1764 #Return 1 if we're supporting __int128 for target, 0 otherwise.
1765
1766 proc check_effective_target_int128 { } {
1767     return [check_no_compiler_messages int128 object {
1768         int dummy[
1769         #ifndef __SIZEOF_INT128__
1770         -1
1771         #else
1772         1
1773         #endif
1774         ];
1775     }]
1776 }
1777
1778 # Return 1 if the target supports unsigned int->float conversion 
1779 #
1780
1781 proc check_effective_target_vect_uintfloat_cvt { } {
1782     global et_vect_uintfloat_cvt_saved
1783
1784     if [info exists et_vect_uintfloat_cvt_saved] {
1785         verbose "check_effective_target_vect_uintfloat_cvt: using cached result" 2
1786     } else {
1787         set et_vect_uintfloat_cvt_saved 0
1788         if { [istarget i?86-*-*]
1789               || ([istarget powerpc*-*-*]
1790                   && ![istarget powerpc-*-linux*paired*])
1791               || [istarget x86_64-*-*] } {
1792            set et_vect_uintfloat_cvt_saved 1
1793         }
1794     }
1795
1796     verbose "check_effective_target_vect_uintfloat_cvt: returning $et_vect_uintfloat_cvt_saved" 2
1797     return $et_vect_uintfloat_cvt_saved
1798 }
1799
1800
1801 # Return 1 if the target supports signed float->int conversion
1802 #
1803
1804 proc check_effective_target_vect_floatint_cvt { } {
1805     global et_vect_floatint_cvt_saved
1806
1807     if [info exists et_vect_floatint_cvt_saved] {
1808         verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1809     } else {
1810         set et_vect_floatint_cvt_saved 0
1811         if { [istarget i?86-*-*]
1812               || ([istarget powerpc*-*-*]
1813                    && ![istarget powerpc-*-linux*paired*])
1814               || [istarget x86_64-*-*] } {
1815            set et_vect_floatint_cvt_saved 1
1816         }
1817     }
1818
1819     verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1820     return $et_vect_floatint_cvt_saved
1821 }
1822
1823 # Return 1 if the target supports unsigned float->int conversion
1824 #
1825
1826 proc check_effective_target_vect_floatuint_cvt { } {
1827     global et_vect_floatuint_cvt_saved
1828
1829     if [info exists et_vect_floatuint_cvt_saved] {
1830         verbose "check_effective_target_vect_floatuint_cvt: using cached result" 2
1831     } else {
1832         set et_vect_floatuint_cvt_saved 0
1833         if { ([istarget powerpc*-*-*]
1834               && ![istarget powerpc-*-linux*paired*]) } {
1835            set et_vect_floatuint_cvt_saved 1
1836         }
1837     }
1838
1839     verbose "check_effective_target_vect_floatuint_cvt: returning $et_vect_floatuint_cvt_saved" 2
1840     return $et_vect_floatuint_cvt_saved
1841 }
1842
1843 # Return 1 is this is an arm target using 32-bit instructions
1844 proc check_effective_target_arm32 { } {
1845     return [check_no_compiler_messages arm32 assembly {
1846         #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1847         #error FOO
1848         #endif
1849     }]
1850 }
1851
1852 # Return 1 if this is an ARM target that only supports aligned vector accesses
1853 proc check_effective_target_arm_vect_no_misalign { } {
1854     return [check_no_compiler_messages arm_vect_no_misalign assembly {
1855         #if !defined(__arm__) \
1856             || (defined(__ARMEL__) \
1857                 && (!defined(__thumb__) || defined(__thumb2__)))
1858         #error FOO
1859         #endif
1860     }]
1861 }
1862
1863
1864 # Return 1 if this is an ARM target supporting -mfpu=vfp
1865 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1866 # options.
1867
1868 proc check_effective_target_arm_vfp_ok { } {
1869     if { [check_effective_target_arm32] } {
1870         return [check_no_compiler_messages arm_vfp_ok object {
1871             int dummy;
1872         } "-mfpu=vfp -mfloat-abi=softfp"]
1873     } else {
1874         return 0
1875     }
1876 }
1877
1878 # Return 1 if this is an ARM target supporting -mfpu=vfp
1879 # -mfloat-abi=hard.  Some multilibs may be incompatible with these
1880 # options.
1881
1882 proc check_effective_target_arm_hard_vfp_ok { } {
1883     if { [check_effective_target_arm32] } {
1884         return [check_no_compiler_messages arm_hard_vfp_ok executable {
1885             int main() { return 0;}
1886         } "-mfpu=vfp -mfloat-abi=hard"]
1887     } else {
1888         return 0
1889     }
1890 }
1891
1892 # Add the options needed for NEON.  We need either -mfloat-abi=softfp
1893 # or -mfloat-abi=hard, but if one is already specified by the
1894 # multilib, use it.  Similarly, if a -mfpu option already enables
1895 # NEON, do not add -mfpu=neon.
1896
1897 proc add_options_for_arm_neon { flags } {
1898     if { ! [check_effective_target_arm_neon_ok] } {
1899         return "$flags"
1900     }
1901     global et_arm_neon_flags
1902     return "$flags $et_arm_neon_flags"
1903 }
1904
1905 # Return 1 if this is an ARM target supporting -mfpu=neon
1906 # -mfloat-abi=softfp or equivalent options.  Some multilibs may be
1907 # incompatible with these options.  Also set et_arm_neon_flags to the
1908 # best options to add.
1909
1910 proc check_effective_target_arm_neon_ok_nocache { } {
1911     global et_arm_neon_flags
1912     set et_arm_neon_flags ""
1913     if { [check_effective_target_arm32] } {
1914         foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon" "-mfpu=neon -mfloat-abi=softfp"} {
1915             if { [check_no_compiler_messages_nocache arm_neon_ok object {
1916                 #include "arm_neon.h"
1917                 int dummy;
1918             } "$flags"] } {
1919                 set et_arm_neon_flags $flags
1920                 return 1
1921             }
1922         }
1923     }
1924
1925     return 0
1926 }
1927
1928 proc check_effective_target_arm_neon_ok { } {
1929     return [check_cached_effective_target arm_neon_ok \
1930                 check_effective_target_arm_neon_ok_nocache]
1931 }
1932
1933 # Add the options needed for NEON.  We need either -mfloat-abi=softfp
1934 # or -mfloat-abi=hard, but if one is already specified by the
1935 # multilib, use it.
1936
1937 proc add_options_for_arm_neon_fp16 { flags } {
1938     if { ! [check_effective_target_arm_neon_fp16_ok] } {
1939         return "$flags"
1940     }
1941     global et_arm_neon_fp16_flags
1942     return "$flags $et_arm_neon_fp16_flags"
1943 }
1944
1945 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
1946 # -mfloat-abi=softfp or equivalent options.  Some multilibs may be
1947 # incompatible with these options.  Also set et_arm_neon_flags to the
1948 # best options to add.
1949
1950 proc check_effective_target_arm_neon_fp16_ok_nocache { } {
1951     global et_arm_neon_fp16_flags
1952     set et_arm_neon_fp16_flags ""
1953     if { [check_effective_target_arm32] } {
1954         # Always add -mfpu=neon-fp16, since there is no preprocessor
1955         # macro for FP16 support.
1956         foreach flags {"-mfpu=neon-fp16" "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
1957             if { [check_no_compiler_messages_nocache arm_neon_fp16_ok object {
1958                 #include "arm_neon.h"
1959                 int dummy;
1960             } "$flags"] } {
1961                 set et_arm_neon_fp16_flags $flags
1962                 return 1
1963             }
1964         }
1965     }
1966
1967     return 0
1968 }
1969
1970 proc check_effective_target_arm_neon_fp16_ok { } {
1971     return [check_cached_effective_target arm_neon_fp16_ok \
1972                 check_effective_target_arm_neon_fp16_ok_nocache]
1973 }
1974
1975 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
1976 # used.
1977
1978 proc check_effective_target_arm_thumb1_ok { } {
1979     return [check_no_compiler_messages arm_thumb1_ok assembly {
1980         #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
1981         #error FOO
1982         #endif
1983     } "-mthumb"]
1984 }
1985
1986 # Return 1 is this is an ARM target where -mthumb causes Thumb-2 to be
1987 # used.
1988
1989 proc check_effective_target_arm_thumb2_ok { } {
1990     return [check_no_compiler_messages arm_thumb2_ok assembly {
1991         #if !defined(__thumb2__)
1992         #error FOO
1993         #endif
1994     } "-mthumb"]
1995 }
1996
1997 # Return 1 if the target supports executing NEON instructions, 0
1998 # otherwise.  Cache the result.
1999
2000 proc check_effective_target_arm_neon_hw { } {
2001     return [check_runtime arm_neon_hw_available {
2002         int
2003         main (void)
2004         {
2005           long long a = 0, b = 1;
2006           asm ("vorr %P0, %P1, %P2"
2007                : "=w" (a)
2008                : "0" (a), "w" (b));
2009           return (a != 1);
2010         }
2011     } [add_options_for_arm_neon ""]]
2012 }
2013
2014 # Return 1 if this is a ARM target with NEON enabled.
2015
2016 proc check_effective_target_arm_neon { } {
2017     if { [check_effective_target_arm32] } {
2018         return [check_no_compiler_messages arm_neon object {
2019             #ifndef __ARM_NEON__
2020             #error not NEON
2021             #else
2022             int dummy;
2023             #endif
2024         }]
2025     } else {
2026         return 0
2027     }
2028 }
2029
2030 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
2031 # the Loongson vector modes.
2032
2033 proc check_effective_target_mips_loongson { } {
2034     return [check_no_compiler_messages loongson assembly {
2035         #if !defined(__mips_loongson_vector_rev)
2036         #error FOO
2037         #endif
2038     }]
2039 }
2040
2041 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
2042 # Architecture.
2043
2044 proc check_effective_target_arm_eabi { } {
2045     return [check_no_compiler_messages arm_eabi object {
2046         #ifndef __ARM_EABI__
2047         #error not EABI
2048         #else
2049         int dummy;
2050         #endif
2051     }]
2052 }
2053
2054 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
2055 # Some multilibs may be incompatible with this option.
2056
2057 proc check_effective_target_arm_iwmmxt_ok { } {
2058     if { [check_effective_target_arm32] } {
2059         return [check_no_compiler_messages arm_iwmmxt_ok object {
2060             int dummy;
2061         } "-mcpu=iwmmxt"]
2062     } else {
2063         return 0
2064     }
2065 }
2066
2067 # Return 1 if this is a PowerPC target with floating-point registers.
2068
2069 proc check_effective_target_powerpc_fprs { } {
2070     if { [istarget powerpc*-*-*]
2071          || [istarget rs6000-*-*] } {
2072         return [check_no_compiler_messages powerpc_fprs object {
2073             #ifdef __NO_FPRS__
2074             #error no FPRs
2075             #else
2076             int dummy;
2077             #endif
2078         }]
2079     } else {
2080         return 0
2081     }
2082 }
2083
2084 # Return 1 if this is a PowerPC target with hardware double-precision
2085 # floating point.
2086
2087 proc check_effective_target_powerpc_hard_double { } {
2088     if { [istarget powerpc*-*-*]
2089          || [istarget rs6000-*-*] } {
2090         return [check_no_compiler_messages powerpc_hard_double object {
2091             #ifdef _SOFT_DOUBLE
2092             #error soft double
2093             #else
2094             int dummy;
2095             #endif
2096         }]
2097     } else {
2098         return 0
2099     }
2100 }
2101
2102 # Return 1 if this is a PowerPC target supporting -maltivec.
2103
2104 proc check_effective_target_powerpc_altivec_ok { } {
2105     if { ([istarget powerpc*-*-*]
2106          && ![istarget powerpc-*-linux*paired*])
2107          || [istarget rs6000-*-*] } {
2108         # AltiVec is not supported on AIX before 5.3.
2109         if { [istarget powerpc*-*-aix4*]
2110              || [istarget powerpc*-*-aix5.1*] 
2111              || [istarget powerpc*-*-aix5.2*] } {
2112             return 0
2113         }
2114         return [check_no_compiler_messages powerpc_altivec_ok object {
2115             int dummy;
2116         } "-maltivec"]
2117     } else {
2118         return 0
2119     }
2120 }
2121
2122 # Return 1 if this is a PowerPC target supporting -mvsx
2123
2124 proc check_effective_target_powerpc_vsx_ok { } {
2125     if { ([istarget powerpc*-*-*]
2126          && ![istarget powerpc-*-linux*paired*])
2127          || [istarget rs6000-*-*] } {
2128         # AltiVec is not supported on AIX before 5.3.
2129         if { [istarget powerpc*-*-aix4*]
2130              || [istarget powerpc*-*-aix5.1*] 
2131              || [istarget powerpc*-*-aix5.2*] } {
2132             return 0
2133         }
2134         return [check_no_compiler_messages powerpc_vsx_ok object {
2135             int main (void) {
2136 #ifdef __MACH__
2137                 asm volatile ("xxlor vs0,vs0,vs0");
2138 #else
2139                 asm volatile ("xxlor 0,0,0");
2140 #endif
2141                 return 0;
2142             }
2143         } "-mvsx"]
2144     } else {
2145         return 0
2146     }
2147 }
2148
2149 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
2150
2151 proc check_effective_target_powerpc_ppu_ok { } {
2152     if [check_effective_target_powerpc_altivec_ok] {
2153         return [check_no_compiler_messages cell_asm_available object {
2154             int main (void) {
2155 #ifdef __MACH__
2156                 asm volatile ("lvlx v0,v0,v0");
2157 #else
2158                 asm volatile ("lvlx 0,0,0");
2159 #endif
2160                 return 0;
2161             }
2162         }]
2163     } else {
2164         return 0
2165     }
2166 }
2167
2168 # Return 1 if this is a PowerPC target that supports SPU.
2169
2170 proc check_effective_target_powerpc_spu { } {
2171     if [istarget powerpc*-*-linux*] {
2172         return [check_effective_target_powerpc_altivec_ok]
2173     } else {
2174         return 0
2175     }
2176 }
2177
2178 # Return 1 if this is a PowerPC SPE target.  The check includes options
2179 # specified by dg-options for this test, so don't cache the result.
2180
2181 proc check_effective_target_powerpc_spe_nocache { } {
2182     if { [istarget powerpc*-*-*] } {
2183         return [check_no_compiler_messages_nocache powerpc_spe object {
2184             #ifndef __SPE__
2185             #error not SPE
2186             #else
2187             int dummy;
2188             #endif
2189         } [current_compiler_flags]]
2190     } else {
2191         return 0
2192     }
2193 }
2194
2195 # Return 1 if this is a PowerPC target with SPE enabled.
2196
2197 proc check_effective_target_powerpc_spe { } {
2198     if { [istarget powerpc*-*-*] } {
2199         return [check_no_compiler_messages powerpc_spe object {
2200             #ifndef __SPE__
2201             #error not SPE
2202             #else
2203             int dummy;
2204             #endif
2205         }]
2206     } else {
2207         return 0
2208     }
2209 }
2210
2211 # Return 1 if this is a PowerPC target with Altivec enabled.
2212
2213 proc check_effective_target_powerpc_altivec { } {
2214     if { [istarget powerpc*-*-*] } {
2215         return [check_no_compiler_messages powerpc_altivec object {
2216             #ifndef __ALTIVEC__
2217             #error not Altivec
2218             #else
2219             int dummy;
2220             #endif
2221         }]
2222     } else {
2223         return 0
2224     }
2225 }
2226
2227 # Return 1 if this is a PowerPC 405 target.  The check includes options
2228 # specified by dg-options for this test, so don't cache the result.
2229
2230 proc check_effective_target_powerpc_405_nocache { } {
2231     if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
2232         return [check_no_compiler_messages_nocache powerpc_405 object {
2233             #ifdef __PPC405__
2234             int dummy;
2235             #else
2236             #error not a PPC405
2237             #endif
2238         } [current_compiler_flags]]
2239     } else {
2240         return 0
2241     }
2242 }
2243
2244 # Return 1 if this is a SPU target with a toolchain that
2245 # supports automatic overlay generation.
2246
2247 proc check_effective_target_spu_auto_overlay { } {
2248     if { [istarget spu*-*-elf*] } {
2249         return [check_no_compiler_messages spu_auto_overlay executable {
2250                 int main (void) { }
2251                 } "-Wl,--auto-overlay" ]
2252     } else {
2253         return 0
2254     }
2255 }
2256
2257 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
2258 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables.  Return 1 if the
2259 # test environment appears to run executables on such a simulator.
2260
2261 proc check_effective_target_ultrasparc_hw { } {
2262     return [check_runtime ultrasparc_hw {
2263         int main() { return 0; }
2264     } "-mcpu=ultrasparc"]
2265 }
2266
2267 # Return 1 if the target supports hardware vector shift operation.
2268
2269 proc check_effective_target_vect_shift { } {
2270     global et_vect_shift_saved
2271
2272     if [info exists et_vect_shift_saved] {
2273         verbose "check_effective_target_vect_shift: using cached result" 2
2274     } else {
2275         set et_vect_shift_saved 0
2276         if { ([istarget powerpc*-*-*]
2277              && ![istarget powerpc-*-linux*paired*])
2278              || [istarget ia64-*-*]
2279              || [istarget i?86-*-*]
2280              || [istarget x86_64-*-*]
2281              || [check_effective_target_arm32]
2282              || ([istarget mips*-*-*]
2283                  && [check_effective_target_mips_loongson]) } {
2284            set et_vect_shift_saved 1
2285         }
2286     }
2287
2288     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
2289     return $et_vect_shift_saved
2290 }
2291
2292 # Return 1 if the target supports hardware vector shift operation with
2293 # scalar shift argument.
2294
2295 proc check_effective_target_vect_shift_scalar { } {
2296     global et_vect_shift_scalar_saved
2297
2298     if [info exists et_vect_shift_scalar_saved] {
2299         verbose "check_effective_target_vect_shift_scalar: using cached result" 2
2300     } else {
2301         set et_vect_shift_scalar_saved 0
2302         if { [istarget x86_64-*-*]
2303              || [istarget i?86-*-*] } {
2304            set et_vect_shift_scalar_saved 1
2305         }
2306     }
2307
2308     verbose "check_effective_target_vect_shift_scalar: returning $et_vect_shift_scalar_saved" 2
2309     return $et_vect_shift_scalar_saved
2310 }
2311
2312
2313 # Return 1 if the target supports hardware vector shift operation for char.
2314
2315 proc check_effective_target_vect_shift_char { } {
2316     global et_vect_shift_char_saved
2317
2318     if [info exists et_vect_shift_char_saved] {
2319         verbose "check_effective_target_vect_shift_char: using cached result" 2
2320     } else {
2321         set et_vect_shift_char_saved 0
2322         if { ([istarget powerpc*-*-*]
2323              && ![istarget powerpc-*-linux*paired*])
2324              || [check_effective_target_arm32] } {
2325            set et_vect_shift_char_saved 1
2326         }
2327     }
2328
2329     verbose "check_effective_target_vect_shift_char: returning $et_vect_shift_char_saved" 2
2330     return $et_vect_shift_char_saved
2331 }
2332
2333 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
2334 #
2335 # This can change for different subtargets so do not cache the result.
2336
2337 proc check_effective_target_vect_long { } {
2338     if { [istarget i?86-*-*]
2339          || (([istarget powerpc*-*-*] 
2340               && ![istarget powerpc-*-linux*paired*]) 
2341               && [check_effective_target_ilp32])
2342          || [istarget x86_64-*-*]
2343          || [check_effective_target_arm32]
2344          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
2345         set answer 1
2346     } else {
2347         set answer 0
2348     }
2349
2350     verbose "check_effective_target_vect_long: returning $answer" 2
2351     return $answer
2352 }
2353
2354 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
2355 #
2356 # This won't change for different subtargets so cache the result.
2357
2358 proc check_effective_target_vect_float { } {
2359     global et_vect_float_saved
2360
2361     if [info exists et_vect_float_saved] {
2362         verbose "check_effective_target_vect_float: using cached result" 2
2363     } else {
2364         set et_vect_float_saved 0
2365         if { [istarget i?86-*-*]
2366               || [istarget powerpc*-*-*]
2367               || [istarget spu-*-*]
2368               || [istarget mipsisa64*-*-*]
2369               || [istarget x86_64-*-*]
2370               || [istarget ia64-*-*]
2371               || [check_effective_target_arm32] } {
2372            set et_vect_float_saved 1
2373         }
2374     }
2375
2376     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
2377     return $et_vect_float_saved
2378 }
2379
2380 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
2381 #
2382 # This won't change for different subtargets so cache the result.
2383
2384 proc check_effective_target_vect_double { } {
2385     global et_vect_double_saved
2386
2387     if [info exists et_vect_double_saved] {
2388         verbose "check_effective_target_vect_double: using cached result" 2
2389     } else {
2390         set et_vect_double_saved 0
2391         if { [istarget i?86-*-*]
2392               || [istarget x86_64-*-*] } {
2393            if { [check_no_compiler_messages vect_double assembly {
2394                  #ifdef __tune_atom__
2395                  # error No double vectorizer support.
2396                  #endif
2397                 }] } {
2398                 set et_vect_double_saved 1
2399             } else {
2400                 set et_vect_double_saved 0
2401             }
2402         } elseif { [istarget spu-*-*] } {
2403            set et_vect_double_saved 1
2404         }
2405     }
2406
2407     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
2408     return $et_vect_double_saved
2409 }
2410
2411 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
2412 #
2413 # This won't change for different subtargets so cache the result.
2414
2415 proc check_effective_target_vect_long_long { } {
2416     global et_vect_long_long_saved
2417
2418     if [info exists et_vect_long_long_saved] {
2419         verbose "check_effective_target_vect_long_long: using cached result" 2
2420     } else {
2421         set et_vect_long_long_saved 0
2422         if { [istarget i?86-*-*]
2423               || [istarget x86_64-*-*] } {
2424            set et_vect_long_long_saved 1
2425         }
2426     }
2427
2428     verbose "check_effective_target_vect_long_long: returning $et_vect_long_long_saved" 2
2429     return $et_vect_long_long_saved
2430 }
2431
2432
2433 # Return 1 if the target plus current options does not support a vector
2434 # max instruction on "int", 0 otherwise.
2435 #
2436 # This won't change for different subtargets so cache the result.
2437
2438 proc check_effective_target_vect_no_int_max { } {
2439     global et_vect_no_int_max_saved
2440
2441     if [info exists et_vect_no_int_max_saved] {
2442         verbose "check_effective_target_vect_no_int_max: using cached result" 2
2443     } else {
2444         set et_vect_no_int_max_saved 0
2445         if { [istarget sparc*-*-*]
2446              || [istarget spu-*-*]
2447              || [istarget alpha*-*-*]
2448              || ([istarget mips*-*-*]
2449                  && [check_effective_target_mips_loongson]) } {
2450             set et_vect_no_int_max_saved 1
2451         }
2452     }
2453     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
2454     return $et_vect_no_int_max_saved
2455 }
2456
2457 # Return 1 if the target plus current options does not support a vector
2458 # add instruction on "int", 0 otherwise.
2459 #
2460 # This won't change for different subtargets so cache the result.
2461
2462 proc check_effective_target_vect_no_int_add { } {
2463     global et_vect_no_int_add_saved
2464
2465     if [info exists et_vect_no_int_add_saved] {
2466         verbose "check_effective_target_vect_no_int_add: using cached result" 2
2467     } else {
2468         set et_vect_no_int_add_saved 0
2469         # Alpha only supports vector add on V8QI and V4HI.
2470         if { [istarget alpha*-*-*] } {
2471             set et_vect_no_int_add_saved 1
2472         }
2473     }
2474     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
2475     return $et_vect_no_int_add_saved
2476 }
2477
2478 # Return 1 if the target plus current options does not support vector
2479 # bitwise instructions, 0 otherwise.
2480 #
2481 # This won't change for different subtargets so cache the result.
2482
2483 proc check_effective_target_vect_no_bitwise { } {
2484     global et_vect_no_bitwise_saved
2485
2486     if [info exists et_vect_no_bitwise_saved] {
2487         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
2488     } else {
2489         set et_vect_no_bitwise_saved 0
2490     }
2491     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
2492     return $et_vect_no_bitwise_saved
2493 }
2494
2495 # Return 1 if the target plus current options supports vector permutation,
2496 # 0 otherwise.
2497 #
2498 # This won't change for different subtargets so cache the result.
2499
2500 proc check_effective_target_vect_perm { } {
2501     global et_vect_perm
2502
2503     if [info exists et_vect_perm_saved] {
2504         verbose "check_effective_target_vect_perm: using cached result" 2
2505     } else {
2506         set et_vect_perm_saved 0
2507         if { [istarget powerpc*-*-*]
2508              || [istarget spu-*-*]
2509              || [istarget i?86-*-*]
2510              || [istarget x86_64-*-*] } {
2511             set et_vect_perm_saved 1
2512         }
2513     }
2514     verbose "check_effective_target_vect_perm: returning $et_vect_perm_saved" 2
2515     return $et_vect_perm_saved
2516 }
2517
2518 # Return 1 if the target plus current options supports vector permutation
2519 # on byte-sized elements, 0 otherwise.
2520 #
2521 # This won't change for different subtargets so cache the result.
2522
2523 proc check_effective_target_vect_perm_byte { } {
2524     global et_vect_perm_byte
2525
2526     if [info exists et_vect_perm_byte_saved] {
2527         verbose "check_effective_target_vect_perm_byte: using cached result" 2
2528     } else {
2529         set et_vect_perm_byte_saved 0
2530         if { [istarget powerpc*-*-*]
2531              || [istarget spu-*-*] } {
2532             set et_vect_perm_byte_saved 1
2533         }
2534     }
2535     verbose "check_effective_target_vect_perm_byte: returning $et_vect_perm_byte_saved" 2
2536     return $et_vect_perm_byte_saved
2537 }
2538
2539 # Return 1 if the target plus current options supports vector permutation
2540 # on short-sized elements, 0 otherwise.
2541 #
2542 # This won't change for different subtargets so cache the result.
2543
2544 proc check_effective_target_vect_perm_short { } {
2545     global et_vect_perm_short
2546
2547     if [info exists et_vect_perm_short_saved] {
2548         verbose "check_effective_target_vect_perm_short: using cached result" 2
2549     } else {
2550         set et_vect_perm_short_saved 0
2551         if { [istarget powerpc*-*-*]
2552              || [istarget spu-*-*] } {
2553             set et_vect_perm_short_saved 1
2554         }
2555     }
2556     verbose "check_effective_target_vect_perm_short: returning $et_vect_perm_short_saved" 2
2557     return $et_vect_perm_short_saved
2558 }
2559
2560 # Return 1 if the target plus current options supports a vector
2561 # widening summation of *short* args into *int* result, 0 otherwise.
2562 #
2563 # This won't change for different subtargets so cache the result.
2564
2565 proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
2566     global et_vect_widen_sum_hi_to_si_pattern
2567
2568     if [info exists et_vect_widen_sum_hi_to_si_pattern_saved] {
2569         verbose "check_effective_target_vect_widen_sum_hi_to_si_pattern: using cached result" 2
2570     } else {
2571         set et_vect_widen_sum_hi_to_si_pattern_saved 0
2572         if { [istarget powerpc*-*-*]
2573              || [istarget ia64-*-*] } {
2574             set et_vect_widen_sum_hi_to_si_pattern_saved 1
2575         }
2576     }
2577     verbose "check_effective_target_vect_widen_sum_hi_to_si_pattern: returning $et_vect_widen_sum_hi_to_si_pattern_saved" 2
2578     return $et_vect_widen_sum_hi_to_si_pattern_saved
2579 }
2580
2581 # Return 1 if the target plus current options supports a vector
2582 # widening summation of *short* args into *int* result, 0 otherwise.
2583 # A target can also support this widening summation if it can support
2584 # promotion (unpacking) from shorts to ints.
2585 #
2586 # This won't change for different subtargets so cache the result.
2587                                                                                                 
2588 proc check_effective_target_vect_widen_sum_hi_to_si { } {
2589     global et_vect_widen_sum_hi_to_si
2590
2591     if [info exists et_vect_widen_sum_hi_to_si_saved] {
2592         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
2593     } else {
2594         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
2595         if { [istarget powerpc*-*-*] 
2596              || [istarget ia64-*-*] } {
2597             set et_vect_widen_sum_hi_to_si_saved 1
2598         }
2599     }
2600     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
2601     return $et_vect_widen_sum_hi_to_si_saved
2602 }
2603
2604 # Return 1 if the target plus current options supports a vector
2605 # widening summation of *char* args into *short* result, 0 otherwise.
2606 # A target can also support this widening summation if it can support
2607 # promotion (unpacking) from chars to shorts.
2608 #
2609 # This won't change for different subtargets so cache the result.
2610                                                                                                 
2611 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
2612     global et_vect_widen_sum_qi_to_hi
2613
2614     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
2615         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
2616     } else {
2617         set et_vect_widen_sum_qi_to_hi_saved 0
2618         if { [check_effective_target_vect_unpack] 
2619              || [istarget ia64-*-*] } {
2620             set et_vect_widen_sum_qi_to_hi_saved 1
2621         }
2622     }
2623     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
2624     return $et_vect_widen_sum_qi_to_hi_saved
2625 }
2626
2627 # Return 1 if the target plus current options supports a vector
2628 # widening summation of *char* args into *int* result, 0 otherwise.
2629 #
2630 # This won't change for different subtargets so cache the result.
2631                                                                                                 
2632 proc check_effective_target_vect_widen_sum_qi_to_si { } {
2633     global et_vect_widen_sum_qi_to_si
2634
2635     if [info exists et_vect_widen_sum_qi_to_si_saved] {
2636         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
2637     } else {
2638         set et_vect_widen_sum_qi_to_si_saved 0
2639         if { [istarget powerpc*-*-*] } {
2640             set et_vect_widen_sum_qi_to_si_saved 1
2641         }
2642     }
2643     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
2644     return $et_vect_widen_sum_qi_to_si_saved
2645 }
2646
2647 # Return 1 if the target plus current options supports a vector
2648 # widening multiplication of *char* args into *short* result, 0 otherwise.
2649 # A target can also support this widening multplication if it can support
2650 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
2651 # multiplication of shorts).
2652 #
2653 # This won't change for different subtargets so cache the result.
2654
2655
2656 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
2657     global et_vect_widen_mult_qi_to_hi
2658
2659     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
2660         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
2661     } else {
2662         if { [check_effective_target_vect_unpack]
2663              && [check_effective_target_vect_short_mult] } {
2664             set et_vect_widen_mult_qi_to_hi_saved 1
2665         } else {
2666             set et_vect_widen_mult_qi_to_hi_saved 0
2667         }
2668         if { [istarget powerpc*-*-*] } {
2669             set et_vect_widen_mult_qi_to_hi_saved 1
2670         }
2671     }
2672     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
2673     return $et_vect_widen_mult_qi_to_hi_saved
2674 }
2675
2676 # Return 1 if the target plus current options supports a vector
2677 # widening multiplication of *short* args into *int* result, 0 otherwise.
2678 # A target can also support this widening multplication if it can support
2679 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
2680 # multiplication of ints).
2681 #
2682 # This won't change for different subtargets so cache the result.
2683
2684
2685 proc check_effective_target_vect_widen_mult_hi_to_si { } {
2686     global et_vect_widen_mult_hi_to_si
2687
2688     if [info exists et_vect_widen_mult_hi_to_si_saved] {
2689         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
2690     } else {
2691         if { [check_effective_target_vect_unpack]
2692              && [check_effective_target_vect_int_mult] } {
2693           set et_vect_widen_mult_hi_to_si_saved 1
2694         } else {
2695           set et_vect_widen_mult_hi_to_si_saved 0
2696         }
2697         if { [istarget powerpc*-*-*]
2698               || [istarget spu-*-*]
2699               || [istarget ia64-*-*]
2700               || [istarget i?86-*-*]
2701               || [istarget x86_64-*-*] } {
2702             set et_vect_widen_mult_hi_to_si_saved 1
2703         }
2704     }
2705     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
2706     return $et_vect_widen_mult_hi_to_si_saved
2707 }
2708
2709 # Return 1 if the target plus current options supports a vector
2710 # dot-product of signed chars, 0 otherwise.
2711 #
2712 # This won't change for different subtargets so cache the result.
2713
2714 proc check_effective_target_vect_sdot_qi { } {
2715     global et_vect_sdot_qi
2716
2717     if [info exists et_vect_sdot_qi_saved] {
2718         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
2719     } else {
2720         set et_vect_sdot_qi_saved 0
2721         if { [istarget ia64-*-*] } {
2722             set et_vect_udot_qi_saved 1
2723         }
2724     }
2725     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
2726     return $et_vect_sdot_qi_saved
2727 }
2728
2729 # Return 1 if the target plus current options supports a vector
2730 # dot-product of unsigned chars, 0 otherwise.
2731 #
2732 # This won't change for different subtargets so cache the result.
2733
2734 proc check_effective_target_vect_udot_qi { } {
2735     global et_vect_udot_qi
2736
2737     if [info exists et_vect_udot_qi_saved] {
2738         verbose "check_effective_target_vect_udot_qi: using cached result" 2
2739     } else {
2740         set et_vect_udot_qi_saved 0
2741         if { [istarget powerpc*-*-*]
2742              || [istarget ia64-*-*] } {
2743             set et_vect_udot_qi_saved 1
2744         }
2745     }
2746     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
2747     return $et_vect_udot_qi_saved
2748 }
2749
2750 # Return 1 if the target plus current options supports a vector
2751 # dot-product of signed shorts, 0 otherwise.
2752 #
2753 # This won't change for different subtargets so cache the result.
2754
2755 proc check_effective_target_vect_sdot_hi { } {
2756     global et_vect_sdot_hi
2757
2758     if [info exists et_vect_sdot_hi_saved] {
2759         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
2760     } else {
2761         set et_vect_sdot_hi_saved 0
2762         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2763              || [istarget ia64-*-*]
2764              || [istarget i?86-*-*]
2765              || [istarget x86_64-*-*] } {
2766             set et_vect_sdot_hi_saved 1
2767         }
2768     }
2769     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
2770     return $et_vect_sdot_hi_saved
2771 }
2772
2773 # Return 1 if the target plus current options supports a vector
2774 # dot-product of unsigned shorts, 0 otherwise.
2775 #
2776 # This won't change for different subtargets so cache the result.
2777
2778 proc check_effective_target_vect_udot_hi { } {
2779     global et_vect_udot_hi
2780
2781     if [info exists et_vect_udot_hi_saved] {
2782         verbose "check_effective_target_vect_udot_hi: using cached result" 2
2783     } else {
2784         set et_vect_udot_hi_saved 0
2785         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*]) } {
2786             set et_vect_udot_hi_saved 1
2787         }
2788     }
2789     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
2790     return $et_vect_udot_hi_saved
2791 }
2792
2793
2794 # Return 1 if the target plus current options supports a vector
2795 # demotion (packing) of shorts (to chars) and ints (to shorts) 
2796 # using modulo arithmetic, 0 otherwise.
2797 #
2798 # This won't change for different subtargets so cache the result.
2799                                                                                 
2800 proc check_effective_target_vect_pack_trunc { } {
2801     global et_vect_pack_trunc
2802                                                                                 
2803     if [info exists et_vect_pack_trunc_saved] {
2804         verbose "check_effective_target_vect_pack_trunc: using cached result" 2
2805     } else {
2806         set et_vect_pack_trunc_saved 0
2807         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2808              || [istarget i?86-*-*]
2809              || [istarget x86_64-*-*]
2810              || [istarget spu-*-*]
2811              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
2812             set et_vect_pack_trunc_saved 1
2813         }
2814     }
2815     verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
2816     return $et_vect_pack_trunc_saved
2817 }
2818
2819 # Return 1 if the target plus current options supports a vector
2820 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
2821 #
2822 # This won't change for different subtargets so cache the result.
2823                                    
2824 proc check_effective_target_vect_unpack { } {
2825     global et_vect_unpack
2826                                         
2827     if [info exists et_vect_unpack_saved] {
2828         verbose "check_effective_target_vect_unpack: using cached result" 2
2829     } else {
2830         set et_vect_unpack_saved 0
2831         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
2832              || [istarget i?86-*-*]
2833              || [istarget x86_64-*-*] 
2834              || [istarget spu-*-*]
2835              || [istarget ia64-*-*]
2836              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
2837             set et_vect_unpack_saved 1
2838         }
2839     }
2840     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
2841     return $et_vect_unpack_saved
2842 }
2843
2844 # Return 1 if the target plus current options does not guarantee
2845 # that its STACK_BOUNDARY is >= the reguired vector alignment.
2846 #
2847 # This won't change for different subtargets so cache the result.
2848
2849 proc check_effective_target_unaligned_stack { } {
2850     global et_unaligned_stack_saved
2851
2852     if [info exists et_unaligned_stack_saved] {
2853         verbose "check_effective_target_unaligned_stack: using cached result" 2
2854     } else {
2855         set et_unaligned_stack_saved 0
2856     }
2857     verbose "check_effective_target_unaligned_stack: returning $et_unaligned_stack_saved" 2
2858     return $et_unaligned_stack_saved
2859 }
2860
2861 # Return 1 if the target plus current options does not support a vector
2862 # alignment mechanism, 0 otherwise.
2863 #
2864 # This won't change for different subtargets so cache the result.
2865
2866 proc check_effective_target_vect_no_align { } {
2867     global et_vect_no_align_saved
2868
2869     if [info exists et_vect_no_align_saved] {
2870         verbose "check_effective_target_vect_no_align: using cached result" 2
2871     } else {
2872         set et_vect_no_align_saved 0
2873         if { [istarget mipsisa64*-*-*]
2874              || [istarget sparc*-*-*]
2875              || [istarget ia64-*-*]
2876              || [check_effective_target_arm_vect_no_misalign]
2877              || ([istarget mips*-*-*]
2878                  && [check_effective_target_mips_loongson]) } {
2879             set et_vect_no_align_saved 1
2880         }
2881     }
2882     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
2883     return $et_vect_no_align_saved
2884 }
2885
2886 # Return 1 if the target supports a vector misalign access, 0 otherwise.
2887 #
2888 # This won't change for different subtargets so cache the result.
2889
2890 proc check_effective_target_vect_hw_misalign { } {
2891     global et_vect_hw_misalign_saved
2892
2893     if [info exists et_vect_hw_misalign_saved] {
2894         verbose "check_effective_target_vect_hw_misalign: using cached result" 2
2895     } else {
2896         set et_vect_hw_misalign_saved 0
2897        if { ([istarget x86_64-*-*] 
2898             || [istarget i?86-*-*]) } {
2899           set et_vect_hw_misalign_saved 1
2900        }
2901     }
2902     verbose "check_effective_target_vect_hw_misalign: returning $et_vect_hw_misalign_saved" 2
2903     return $et_vect_hw_misalign_saved
2904 }
2905
2906
2907 # Return 1 if arrays are aligned to the vector alignment
2908 # boundary, 0 otherwise.
2909 #
2910 # This won't change for different subtargets so cache the result.
2911
2912 proc check_effective_target_vect_aligned_arrays { } {
2913     global et_vect_aligned_arrays
2914
2915     if [info exists et_vect_aligned_arrays_saved] {
2916         verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
2917     } else {
2918         set et_vect_aligned_arrays_saved 0
2919         if { (([istarget x86_64-*-*]
2920               || [istarget i?86-*-*]) && [is-effective-target lp64])
2921               || [istarget spu-*-*] } {
2922             set et_vect_aligned_arrays_saved 1
2923         }
2924     }
2925     verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
2926     return $et_vect_aligned_arrays_saved
2927 }
2928
2929 # Return 1 if types of size 32 bit or less are naturally aligned
2930 # (aligned to their type-size), 0 otherwise.
2931 #
2932 # This won't change for different subtargets so cache the result.
2933
2934 proc check_effective_target_natural_alignment_32 { } {
2935     global et_natural_alignment_32
2936
2937     if [info exists et_natural_alignment_32_saved] {
2938         verbose "check_effective_target_natural_alignment_32: using cached result" 2
2939     } else {
2940         # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
2941         set et_natural_alignment_32_saved 1
2942         if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } {
2943             set et_natural_alignment_32_saved 0
2944         }
2945     }
2946     verbose "check_effective_target_natural_alignment_32: returning $et_natural_alignment_32_saved" 2
2947     return $et_natural_alignment_32_saved
2948 }
2949
2950 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
2951 # type-size), 0 otherwise.
2952 #
2953 # This won't change for different subtargets so cache the result.
2954
2955 proc check_effective_target_natural_alignment_64 { } {
2956     global et_natural_alignment_64
2957
2958     if [info exists et_natural_alignment_64_saved] {
2959         verbose "check_effective_target_natural_alignment_64: using cached result" 2
2960     } else {
2961         set et_natural_alignment_64_saved 0
2962         if { ([is-effective-target lp64] && ![istarget *-*-darwin*])
2963              || [istarget spu-*-*] } {
2964             set et_natural_alignment_64_saved 1
2965         }
2966     }
2967     verbose "check_effective_target_natural_alignment_64: returning $et_natural_alignment_64_saved" 2
2968     return $et_natural_alignment_64_saved
2969 }
2970
2971 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
2972 #
2973 # This won't change for different subtargets so cache the result.
2974
2975 proc check_effective_target_vector_alignment_reachable { } {
2976     global et_vector_alignment_reachable
2977
2978     if [info exists et_vector_alignment_reachable_saved] {
2979         verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
2980     } else {
2981         if { [check_effective_target_vect_aligned_arrays]
2982              || [check_effective_target_natural_alignment_32] } {
2983             set et_vector_alignment_reachable_saved 1
2984         } else {
2985             set et_vector_alignment_reachable_saved 0
2986         }
2987     }
2988     verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
2989     return $et_vector_alignment_reachable_saved
2990 }
2991
2992 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
2993 #
2994 # This won't change for different subtargets so cache the result.
2995
2996 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
2997     global et_vector_alignment_reachable_for_64bit
2998
2999     if [info exists et_vector_alignment_reachable_for_64bit_saved] {
3000         verbose "check_effective_target_vector_alignment_reachable_for_64bit: using cached result" 2
3001     } else {
3002         if { [check_effective_target_vect_aligned_arrays] 
3003              || [check_effective_target_natural_alignment_64] } {
3004             set et_vector_alignment_reachable_for_64bit_saved 1
3005         } else {
3006             set et_vector_alignment_reachable_for_64bit_saved 0
3007         }
3008     }
3009     verbose "check_effective_target_vector_alignment_reachable_for_64bit: returning $et_vector_alignment_reachable_for_64bit_saved" 2
3010     return $et_vector_alignment_reachable_for_64bit_saved
3011 }
3012
3013 # Return 1 if the target only requires element alignment for vector accesses
3014
3015 proc check_effective_target_vect_element_align { } {
3016     global et_vect_element_align
3017
3018     if [info exists et_vect_element_align] {
3019         verbose "check_effective_target_vect_element_align: using cached result" 2
3020     } else {
3021         set et_vect_element_align 0
3022         if { [istarget arm*-*-*]
3023              || [check_effective_target_vect_hw_misalign] } {
3024            set et_vect_element_align 1
3025         }
3026     }
3027
3028     verbose "check_effective_target_vect_element_align: returning $et_vect_element_align" 2
3029     return $et_vect_element_align
3030 }
3031
3032 # Return 1 if the target supports vector conditional operations, 0 otherwise.
3033
3034 proc check_effective_target_vect_condition { } {
3035     global et_vect_cond_saved
3036
3037     if [info exists et_vect_cond_saved] {
3038         verbose "check_effective_target_vect_cond: using cached result" 2
3039     } else {
3040         set et_vect_cond_saved 0
3041         if { [istarget powerpc*-*-*]
3042              || [istarget ia64-*-*]
3043              || [istarget i?86-*-*]
3044              || [istarget spu-*-*]
3045              || [istarget x86_64-*-*] } {
3046            set et_vect_cond_saved 1
3047         }
3048     }
3049
3050     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
3051     return $et_vect_cond_saved
3052 }
3053
3054 # Return 1 if the target supports vector char multiplication, 0 otherwise.
3055
3056 proc check_effective_target_vect_char_mult { } {
3057     global et_vect_char_mult_saved
3058
3059     if [info exists et_vect_char_mult_saved] {
3060         verbose "check_effective_target_vect_char_mult: using cached result" 2
3061     } else {
3062         set et_vect_char_mult_saved 0
3063         if { [istarget ia64-*-*]
3064              || [istarget i?86-*-*]
3065              || [istarget x86_64-*-*] } {
3066            set et_vect_char_mult_saved 1
3067         }
3068     }
3069
3070     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
3071     return $et_vect_char_mult_saved
3072 }
3073
3074 # Return 1 if the target supports vector short multiplication, 0 otherwise.
3075
3076 proc check_effective_target_vect_short_mult { } {
3077     global et_vect_short_mult_saved
3078
3079     if [info exists et_vect_short_mult_saved] {
3080         verbose "check_effective_target_vect_short_mult: using cached result" 2
3081     } else {
3082         set et_vect_short_mult_saved 0
3083         if { [istarget ia64-*-*]
3084              || [istarget spu-*-*]
3085              || [istarget i?86-*-*]
3086              || [istarget x86_64-*-*]
3087              || [istarget powerpc*-*-*]
3088              || [check_effective_target_arm32]
3089              || ([istarget mips*-*-*]
3090                  && [check_effective_target_mips_loongson]) } {
3091            set et_vect_short_mult_saved 1
3092         }
3093     }
3094
3095     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
3096     return $et_vect_short_mult_saved
3097 }
3098
3099 # Return 1 if the target supports vector int multiplication, 0 otherwise.
3100
3101 proc check_effective_target_vect_int_mult { } {
3102     global et_vect_int_mult_saved
3103
3104     if [info exists et_vect_int_mult_saved] {
3105         verbose "check_effective_target_vect_int_mult: using cached result" 2
3106     } else {
3107         set et_vect_int_mult_saved 0
3108         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
3109              || [istarget spu-*-*]
3110              || [istarget i?86-*-*]
3111              || [istarget x86_64-*-*]
3112              || [istarget ia64-*-*]
3113              || [check_effective_target_arm32] } {
3114            set et_vect_int_mult_saved 1
3115         }
3116     }
3117
3118     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
3119     return $et_vect_int_mult_saved
3120 }
3121
3122 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
3123
3124 proc check_effective_target_vect_extract_even_odd { } {
3125     global et_vect_extract_even_odd_saved
3126     
3127     if [info exists et_vect_extract_even_odd_saved] {
3128         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
3129     } else {
3130         set et_vect_extract_even_odd_saved 0 
3131         if { [istarget powerpc*-*-*] 
3132              || [istarget i?86-*-*]
3133              || [istarget x86_64-*-*]
3134              || [istarget ia64-*-*]
3135              || [istarget spu-*-*] } {
3136            set et_vect_extract_even_odd_saved 1
3137         }
3138     }
3139
3140     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
3141     return $et_vect_extract_even_odd_saved
3142 }
3143
3144 # Return 1 if the target supports vector interleaving, 0 otherwise.
3145
3146 proc check_effective_target_vect_interleave { } {
3147     global et_vect_interleave_saved
3148     
3149     if [info exists et_vect_interleave_saved] {
3150         verbose "check_effective_target_vect_interleave: using cached result" 2
3151     } else {
3152         set et_vect_interleave_saved 0
3153         if { [istarget powerpc*-*-*]
3154              || [istarget i?86-*-*]
3155              || [istarget x86_64-*-*]
3156              || [istarget ia64-*-*]
3157              || [istarget spu-*-*] } {
3158            set et_vect_interleave_saved 1
3159         }
3160     }
3161
3162     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
3163     return $et_vect_interleave_saved
3164 }
3165
3166 foreach N {2 3 4 8} {
3167     eval [string map [list N $N] {
3168         # Return 1 if the target supports 2-vector interleaving
3169         proc check_effective_target_vect_stridedN { } {
3170             global et_vect_stridedN_saved
3171
3172             if [info exists et_vect_stridedN_saved] {
3173                 verbose "check_effective_target_vect_stridedN: using cached result" 2
3174             } else {
3175                 set et_vect_stridedN_saved 0
3176                 if { (N & -N) == N
3177                      && [check_effective_target_vect_interleave]
3178                      && [check_effective_target_vect_extract_even_odd] } {
3179                     set et_vect_stridedN_saved 1
3180                 }
3181                 if { [istarget arm*-*-*] && N >= 2 && N <= 4 } {
3182                     set et_vect_stridedN_saved 1
3183                 }
3184             }
3185
3186             verbose "check_effective_target_vect_stridedN: returning $et_vect_stridedN_saved" 2
3187             return $et_vect_stridedN_saved
3188         }
3189     }]
3190 }
3191
3192 # Return 1 if the target supports section-anchors
3193
3194 proc check_effective_target_section_anchors { } {
3195     global et_section_anchors_saved
3196
3197     if [info exists et_section_anchors_saved] {
3198         verbose "check_effective_target_section_anchors: using cached result" 2
3199     } else {
3200         set et_section_anchors_saved 0
3201         if { [istarget powerpc*-*-*]
3202               || [istarget arm*-*-*] } {
3203            set et_section_anchors_saved 1
3204         }
3205     }
3206
3207     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
3208     return $et_section_anchors_saved
3209 }
3210
3211 # Return 1 if the target supports atomic operations on "int" and "long".
3212
3213 proc check_effective_target_sync_int_long { } {
3214     global et_sync_int_long_saved
3215
3216     if [info exists et_sync_int_long_saved] {
3217         verbose "check_effective_target_sync_int_long: using cached result" 2
3218     } else {
3219         set et_sync_int_long_saved 0
3220 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
3221 # load-reserved/store-conditional instructions.
3222         if { [istarget ia64-*-*]
3223              || [istarget i?86-*-*]
3224              || [istarget x86_64-*-*]
3225              || [istarget alpha*-*-*] 
3226              || [istarget arm*-*-linux-gnueabi] 
3227              || [istarget bfin*-*linux*]
3228              || [istarget hppa*-*linux*]
3229              || [istarget s390*-*-*] 
3230              || [istarget powerpc*-*-*]
3231              || [istarget sparc64-*-*]
3232              || [istarget sparcv9-*-*]
3233              || [istarget mips*-*-*] } {
3234            set et_sync_int_long_saved 1
3235         }
3236     }
3237
3238     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
3239     return $et_sync_int_long_saved
3240 }
3241
3242 # Return 1 if the target supports atomic operations on "char" and "short".
3243
3244 proc check_effective_target_sync_char_short { } {
3245     global et_sync_char_short_saved
3246
3247     if [info exists et_sync_char_short_saved] {
3248         verbose "check_effective_target_sync_char_short: using cached result" 2
3249     } else {
3250         set et_sync_char_short_saved 0
3251 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
3252 # load-reserved/store-conditional instructions.
3253         if { [istarget ia64-*-*]
3254              || [istarget i?86-*-*]
3255              || [istarget x86_64-*-*]
3256              || [istarget alpha*-*-*] 
3257              || [istarget arm*-*-linux-gnueabi] 
3258              || [istarget hppa*-*linux*]
3259              || [istarget s390*-*-*] 
3260              || [istarget powerpc*-*-*]
3261              || [istarget sparc64-*-*]
3262              || [istarget sparcv9-*-*]
3263              || [istarget mips*-*-*] } {
3264            set et_sync_char_short_saved 1
3265         }
3266     }
3267
3268     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
3269     return $et_sync_char_short_saved
3270 }
3271
3272 # Return 1 if the target uses a ColdFire FPU.
3273
3274 proc check_effective_target_coldfire_fpu { } {
3275     return [check_no_compiler_messages coldfire_fpu assembly {
3276         #ifndef __mcffpu__
3277         #error FOO
3278         #endif
3279     }]
3280 }
3281
3282 # Return true if this is a uClibc target.
3283
3284 proc check_effective_target_uclibc {} {
3285     return [check_no_compiler_messages uclibc object {
3286         #include <features.h>
3287         #if !defined (__UCLIBC__)
3288         #error FOO
3289         #endif
3290     }]
3291 }
3292
3293 # Return true if this is a uclibc target and if the uclibc feature
3294 # described by __$feature__ is not present.
3295
3296 proc check_missing_uclibc_feature {feature} {
3297     return [check_no_compiler_messages $feature object "
3298         #include <features.h>
3299         #if !defined (__UCLIBC) || defined (__${feature}__)
3300         #error FOO
3301         #endif
3302     "]
3303 }
3304
3305 # Return true if this is a Newlib target.
3306
3307 proc check_effective_target_newlib {} {
3308     return [check_no_compiler_messages newlib object {
3309         #include <newlib.h>
3310     }]
3311 }
3312
3313 # Return 1 if
3314 #   (a) an error of a few ULP is expected in string to floating-point
3315 #       conversion functions; and
3316 #   (b) overflow is not always detected correctly by those functions.
3317
3318 proc check_effective_target_lax_strtofp {} {
3319     # By default, assume that all uClibc targets suffer from this.
3320     return [check_effective_target_uclibc]
3321 }
3322
3323 # Return 1 if this is a target for which wcsftime is a dummy
3324 # function that always returns 0.
3325
3326 proc check_effective_target_dummy_wcsftime {} {
3327     # By default, assume that all uClibc targets suffer from this.
3328     return [check_effective_target_uclibc]
3329 }
3330
3331 # Return 1 if constructors with initialization priority arguments are
3332 # supposed on this target.
3333
3334 proc check_effective_target_init_priority {} {
3335     return [check_no_compiler_messages init_priority assembly "
3336         void f() __attribute__((constructor (1000)));
3337         void f() \{\}
3338     "]
3339 }
3340
3341 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
3342 # This can be used with any check_* proc that takes no argument and
3343 # returns only 1 or 0.  It could be used with check_* procs that take
3344 # arguments with keywords that pass particular arguments.
3345
3346 proc is-effective-target { arg } {
3347     set selected 0
3348     if { [info procs check_effective_target_${arg}] != [list] } {
3349         set selected [check_effective_target_${arg}]
3350     } else {
3351         switch $arg {
3352           "vmx_hw"         { set selected [check_vmx_hw_available] }
3353           "vsx_hw"         { set selected [check_vsx_hw_available] }
3354           "ppc_recip_hw"   { set selected [check_ppc_recip_hw_available] }
3355           "named_sections" { set selected [check_named_sections_available] }
3356           "gc_sections"    { set selected [check_gc_sections_available] }
3357           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
3358           default          { error "unknown effective target keyword `$arg'" }
3359         }
3360     }
3361     verbose "is-effective-target: $arg $selected" 2
3362     return $selected
3363 }
3364
3365 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
3366
3367 proc is-effective-target-keyword { arg } {
3368     if { [info procs check_effective_target_${arg}] != [list] } {
3369         return 1
3370     } else {
3371         # These have different names for their check_* procs.
3372         switch $arg {
3373           "vmx_hw"         { return 1 }
3374           "vsx_hw"         { return 1 }
3375           "ppc_recip_hw"   { return 1 }
3376           "named_sections" { return 1 }
3377           "gc_sections"    { return 1 }
3378           "cxa_atexit"     { return 1 }
3379           default          { return 0 }
3380         }
3381     }
3382 }
3383
3384 # Return 1 if target default to short enums
3385
3386 proc check_effective_target_short_enums { } {
3387     return [check_no_compiler_messages short_enums assembly {
3388         enum foo { bar };
3389         int s[sizeof (enum foo) == 1 ? 1 : -1];
3390     }]
3391 }
3392
3393 # Return 1 if target supports merging string constants at link time.
3394
3395 proc check_effective_target_string_merging { } {
3396     return [check_no_messages_and_pattern string_merging \
3397                 "rodata\\.str" assembly {
3398                     const char *var = "String";
3399                 } {-O2}]
3400 }
3401
3402 # Return 1 if target has the basic signed and unsigned types in
3403 # <stdint.h>, 0 otherwise.  This will be obsolete when GCC ensures a
3404 # working <stdint.h> for all targets.
3405
3406 proc check_effective_target_stdint_types { } {
3407     return [check_no_compiler_messages stdint_types assembly {
3408         #include <stdint.h>
3409         int8_t a; int16_t b; int32_t c; int64_t d;
3410         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
3411     }]
3412 }
3413
3414 # Return 1 if target has the basic signed and unsigned types in
3415 # <inttypes.h>, 0 otherwise.  This is for tests that GCC's notions of
3416 # these types agree with those in the header, as some systems have
3417 # only <inttypes.h>.
3418
3419 proc check_effective_target_inttypes_types { } {
3420     return [check_no_compiler_messages inttypes_types assembly {
3421         #include <inttypes.h>
3422         int8_t a; int16_t b; int32_t c; int64_t d;
3423         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
3424     }]
3425 }
3426
3427 # Return 1 if programs are intended to be run on a simulator
3428 # (i.e. slowly) rather than hardware (i.e. fast).
3429
3430 proc check_effective_target_simulator { } {
3431
3432     # All "src/sim" simulators set this one.
3433     if [board_info target exists is_simulator] {
3434         return [board_info target is_simulator]
3435     }
3436
3437     # The "sid" simulators don't set that one, but at least they set
3438     # this one.
3439     if [board_info target exists slow_simulator] {
3440         return [board_info target slow_simulator]
3441     }
3442
3443     return 0
3444 }
3445
3446 # Return 1 if the target is a VxWorks kernel.
3447
3448 proc check_effective_target_vxworks_kernel { } {
3449     return [check_no_compiler_messages vxworks_kernel assembly {
3450         #if !defined __vxworks || defined __RTP__
3451         #error NO
3452         #endif
3453     }]
3454 }
3455
3456 # Return 1 if the target is a VxWorks RTP.
3457
3458 proc check_effective_target_vxworks_rtp { } {
3459     return [check_no_compiler_messages vxworks_rtp assembly {
3460         #if !defined __vxworks || !defined __RTP__
3461         #error NO
3462         #endif
3463     }]
3464 }
3465
3466 # Return 1 if the target is expected to provide wide character support.
3467
3468 proc check_effective_target_wchar { } {
3469     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
3470         return 0
3471     }
3472     return [check_no_compiler_messages wchar assembly {
3473         #include <wchar.h>
3474     }]
3475 }
3476
3477 # Return 1 if the target has <pthread.h>.
3478
3479 proc check_effective_target_pthread_h { } {
3480     return [check_no_compiler_messages pthread_h assembly {
3481         #include <pthread.h>
3482     }]
3483 }
3484
3485 # Return 1 if the target can truncate a file from a file-descriptor,
3486 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
3487 # chsize.  We test for a trivially functional truncation; no stubs.
3488 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
3489 # different function to be used.
3490
3491 proc check_effective_target_fd_truncate { } {
3492     set prog {
3493         #define _FILE_OFFSET_BITS 64
3494         #include <unistd.h>
3495         #include <stdio.h>
3496         #include <stdlib.h>
3497         int main ()
3498         {
3499           FILE *f = fopen ("tst.tmp", "wb");
3500           int fd;
3501           const char t[] = "test writing more than ten characters";
3502           char s[11];
3503           fd =  fileno (f);
3504           write (fd, t, sizeof (t) - 1);
3505           lseek (fd, 0, 0);
3506           if (ftruncate (fd, 10) != 0)
3507             exit (1);
3508           close (fd);
3509           f = fopen ("tst.tmp", "rb");
3510           if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
3511             exit (1);
3512           exit (0);
3513         }
3514     }
3515
3516     if { [check_runtime ftruncate $prog] } {
3517       return 1;
3518     }
3519
3520     regsub "ftruncate" $prog "chsize" prog
3521     return [check_runtime chsize $prog]
3522 }
3523
3524 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
3525
3526 proc add_options_for_c99_runtime { flags } {
3527     if { [istarget *-*-solaris2*] } {
3528         return "$flags -std=c99"
3529     }
3530     if { [istarget mips-sgi-irix6.5*] } {
3531         return "$flags -std=c99"
3532     }
3533     if { [istarget powerpc-*-darwin*] } {
3534         return "$flags -mmacosx-version-min=10.3"
3535     }
3536     return $flags
3537 }
3538
3539 # Add to FLAGS all the target-specific flags needed to enable
3540 # full IEEE compliance mode.
3541
3542 proc add_options_for_ieee { flags } {
3543     if { [istarget "alpha*-*-*"]
3544          || [istarget "sh*-*-*"] } {
3545        return "$flags -mieee"
3546     }
3547     if { [istarget "rx-*-*"] } {
3548        return "$flags -mnofpu"
3549     }
3550     return $flags
3551 }
3552
3553 # Add to FLAGS the flags needed to enable functions to bind locally
3554 # when using pic/PIC passes in the testsuite.
3555
3556 proc add_options_for_bind_pic_locally { flags } {
3557     if {[check_no_compiler_messages using_pic2 assembly {
3558         #if __PIC__ != 2
3559         #error FOO
3560         #endif
3561     }]} {
3562         return "$flags -fPIE"
3563     }
3564     if {[check_no_compiler_messages using_pic1 assembly {
3565         #if __PIC__ != 1
3566         #error FOO
3567         #endif
3568     }]} {
3569         return "$flags -fpie"
3570     }
3571
3572     return $flags
3573 }
3574
3575 # Add to FLAGS the flags needed to enable 128-bit vectors.
3576
3577 proc add_options_for_quad_vectors { flags } {
3578     if [is-effective-target arm_neon_ok] {
3579         return "$flags -mvectorize-with-neon-quad"
3580     }
3581
3582     return $flags
3583 }
3584
3585 # Return 1 if the target provides a full C99 runtime.
3586
3587 proc check_effective_target_c99_runtime { } {
3588     return [check_cached_effective_target c99_runtime {
3589         global srcdir
3590
3591         set file [open "$srcdir/gcc.dg/builtins-config.h"]
3592         set contents [read $file]
3593         close $file
3594         append contents {
3595             #ifndef HAVE_C99_RUNTIME
3596             #error FOO
3597             #endif
3598         }
3599         check_no_compiler_messages_nocache c99_runtime assembly \
3600             $contents [add_options_for_c99_runtime ""]
3601     }]
3602 }
3603
3604 # Return 1 if  target wchar_t is at least 4 bytes.
3605
3606 proc check_effective_target_4byte_wchar_t { } {
3607     return [check_no_compiler_messages 4byte_wchar_t object {
3608         int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
3609     }]
3610 }
3611
3612 # Return 1 if the target supports automatic stack alignment.
3613
3614 proc check_effective_target_automatic_stack_alignment  { } {
3615     # Ordinarily x86 supports automatic stack alignment ...
3616     if { [istarget i?86*-*-*] || [istarget x86_64-*-*] } then {
3617         if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
3618             # ... except Win64 SEH doesn't.  Succeed for Win32 though.
3619             return [check_effective_target_ilp32];
3620         }
3621         return 1;
3622     }
3623     return 0;
3624 }
3625
3626 # Return 1 if avx instructions can be compiled.
3627
3628 proc check_effective_target_avx { } {
3629     return [check_no_compiler_messages avx object {
3630         void _mm256_zeroall (void)
3631         {
3632            __builtin_ia32_vzeroall ();
3633         }
3634     } "-O2 -mavx" ]
3635 }
3636
3637 # Return 1 if sse instructions can be compiled.
3638 proc check_effective_target_sse { } {
3639     return [check_no_compiler_messages sse object {
3640         int main ()
3641         {
3642             __builtin_ia32_stmxcsr ();
3643             return 0;
3644         }
3645     } "-O2 -msse" ]
3646 }
3647
3648 # Return 1 if sse2 instructions can be compiled.
3649 proc check_effective_target_sse2 { } {
3650     return [check_no_compiler_messages sse2 object {
3651         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
3652         
3653         __m128i _mm_srli_si128 (__m128i __A, int __N)
3654         {
3655             return (__m128i)__builtin_ia32_psrldqi128 (__A, 8);
3656         }
3657     } "-O2 -msse2" ]
3658 }
3659
3660 # Return 1 if F16C instructions can be compiled.
3661
3662 proc check_effective_target_f16c { } {
3663     return [check_no_compiler_messages f16c object {
3664         #include "immintrin.h"
3665         float
3666         foo (unsigned short val)
3667         {
3668           return _cvtsh_ss (val);
3669         }
3670     } "-O2 -mf16c" ]
3671 }
3672
3673 # Return 1 if C wchar_t type is compatible with char16_t.
3674
3675 proc check_effective_target_wchar_t_char16_t_compatible { } {
3676     return [check_no_compiler_messages wchar_t_char16_t object {
3677         __WCHAR_TYPE__ wc;
3678         __CHAR16_TYPE__ *p16 = &wc;
3679         char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
3680     }]
3681 }
3682
3683 # Return 1 if C wchar_t type is compatible with char32_t.
3684
3685 proc check_effective_target_wchar_t_char32_t_compatible { } {
3686     return [check_no_compiler_messages wchar_t_char32_t object {
3687         __WCHAR_TYPE__ wc;
3688         __CHAR32_TYPE__ *p32 = &wc;
3689         char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
3690     }]
3691 }
3692
3693 # Return 1 if pow10 function exists.
3694
3695 proc check_effective_target_pow10 { } {
3696     return [check_runtime pow10 {
3697         #include <math.h>
3698         int main () {
3699         double x;
3700         x = pow10 (1);
3701         return 0;
3702         }
3703     } "-lm" ]
3704 }
3705
3706 # Return 1 if current options generate DFP instructions, 0 otherwise.
3707
3708 proc check_effective_target_hard_dfp {} {
3709     return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
3710         typedef float d64 __attribute__((mode(DD)));
3711         d64 x, y, z;
3712         void foo (void) { z = x + y; }
3713     }]
3714 }
3715
3716 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
3717 # for strchr etc. functions.
3718
3719 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
3720     return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
3721         #include <string.h>
3722         #include <wchar.h>
3723         #if !defined(__cplusplus) \
3724             || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
3725             || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
3726         ISO C++ correct string.h and wchar.h protos not supported.
3727         #else
3728         int i;
3729         #endif
3730     }]
3731 }
3732
3733 # Return 1 if GNU as is used.
3734
3735 proc check_effective_target_gas { } {
3736     global use_gas_saved
3737     global tool
3738
3739     if {![info exists use_gas_saved]} {
3740         # Check if the as used by gcc is GNU as.
3741         set gcc_as [lindex [${tool}_target_compile "-print-prog-name=as" "" "none" ""] 0]
3742         # Provide /dev/null as input, otherwise gas times out reading from
3743         # stdin.
3744         set status [remote_exec host "$gcc_as" "-v /dev/null"]
3745         set as_output [lindex $status 1]
3746         if { [ string first "GNU" $as_output ] >= 0 } {
3747             set use_gas_saved 1
3748         } else {
3749             set use_gas_saved 0
3750         }
3751     }
3752     return $use_gas_saved
3753 }
3754
3755 # Return 1 if the compiler has been configure with link-time optimization
3756 # (LTO) support.
3757
3758 proc check_effective_target_lto { } {
3759     global ENABLE_LTO
3760     return [info exists ENABLE_LTO]
3761 }
3762
3763 # Return 1 if this target supports the -fsplit-stack option, 0
3764 # otherwise.
3765
3766 proc check_effective_target_split_stack {} {
3767     return [check_no_compiler_messages split_stack object {
3768         void foo (void) { }
3769     } "-fsplit-stack"]
3770 }
3771
3772 # Return 1 if the language for the compiler under test is C.
3773
3774 proc check_effective_target_c { } {
3775  global tool
3776     if [string match $tool "gcc"] {
3777    return 1
3778     }
3779  return 0
3780 }
3781
3782 # Return 1 if the language for the compiler under test is C++.
3783
3784 proc check_effective_target_c++ { } {
3785  global tool
3786     if [string match $tool "g++"] {
3787    return 1
3788     }
3789  return 0
3790 }
3791
3792 # Return 1 if expensive testcases should be run.
3793
3794 proc check_effective_target_run_expensive_tests { } {
3795     if { [getenv GCC_TEST_RUN_EXPENSIVE] != "" } {
3796         return 1
3797     }
3798     return 0
3799 }
3800
3801 # Returns 1 if "mempcpy" is available on the target system.
3802
3803 proc check_effective_target_mempcpy {} {
3804     return [check_function_available "mempcpy"]
3805 }
3806
3807 # Check whether the vectorizer tests are supported by the target and
3808 # append additional target-dependent compile flags to DEFAULT_VECTCFLAGS.
3809 # Set dg-do-what-default to either compile or run, depending on target
3810 # capabilities.  Return 1 if vectorizer tests are supported by
3811 # target, 0 otherwise.
3812
3813 proc check_vect_support_and_set_flags { } {
3814     global DEFAULT_VECTCFLAGS
3815     global dg-do-what-default
3816
3817     if  [istarget "powerpc-*paired*"]  {
3818         lappend DEFAULT_VECTCFLAGS "-mpaired"
3819         if [check_750cl_hw_available] {
3820             set dg-do-what-default run
3821         } else {
3822             set dg-do-what-default compile
3823         }
3824     } elseif [istarget "powerpc*-*-*"] {
3825         # Skip targets not supporting -maltivec.
3826         if ![is-effective-target powerpc_altivec_ok] {
3827             return 0
3828         }
3829
3830         lappend DEFAULT_VECTCFLAGS "-maltivec"
3831         if [check_vsx_hw_available]  {
3832             lappend DEFAULT_VECTCFLAGS "-mvsx" "-mno-allow-movmisalign"
3833         }
3834
3835         if [check_vmx_hw_available] {
3836             set dg-do-what-default run
3837         } else {
3838             if [is-effective-target ilp32] {
3839                 # Specify a cpu that supports VMX for compile-only tests.
3840                 lappend DEFAULT_VECTCFLAGS "-mcpu=970"
3841             }
3842             set dg-do-what-default compile
3843         }
3844     } elseif { [istarget  "spu-*-*"] } {
3845         set dg-do-what-default run
3846     } elseif { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
3847         lappend DEFAULT_VECTCFLAGS "-msse2"
3848         if { [check_effective_target_sse2_runtime] } {
3849             set dg-do-what-default run
3850         } else {
3851             set dg-do-what-default compile
3852         }
3853     } elseif { [istarget "mips*-*-*"]
3854                && ([check_effective_target_mpaired_single]
3855                     || [check_effective_target_mips_loongson])
3856                && [check_effective_target_nomips16] } {
3857         if { [check_effective_target_mpaired_single] } {
3858             lappend DEFAULT_VECTCFLAGS "-mpaired-single"
3859         }
3860         set dg-do-what-default run
3861     } elseif [istarget "sparc*-*-*"] {
3862         lappend DEFAULT_VECTCFLAGS "-mcpu=ultrasparc" "-mvis"
3863         if [check_effective_target_ultrasparc_hw] {
3864             set dg-do-what-default run
3865         } else {
3866             set dg-do-what-default compile
3867         }
3868     } elseif [istarget "alpha*-*-*"] {
3869         # Alpha's vectorization capabilities are extremely limited.
3870         # It's more effort than its worth disabling all of the tests
3871         # that it cannot pass.  But if you actually want to see what
3872         # does work, command out the return.
3873         return 0
3874
3875         lappend DEFAULT_VECTCFLAGS "-mmax"
3876         if [check_alpha_max_hw_available] {
3877             set dg-do-what-default run
3878         } else {
3879             set dg-do-what-default compile
3880         }
3881     } elseif [istarget "ia64-*-*"] {
3882         set dg-do-what-default run
3883     } elseif [is-effective-target arm_neon_ok] {
3884         eval lappend DEFAULT_VECTCFLAGS [add_options_for_arm_neon ""]
3885         # NEON does not support denormals, so is not used for vectorization by
3886         # default to avoid loss of precision.  We must pass -ffast-math to test
3887         # vectorization of float operations.
3888         lappend DEFAULT_VECTCFLAGS "-ffast-math"
3889         if [is-effective-target arm_neon_hw] {
3890             set dg-do-what-default run
3891         } else {
3892             set dg-do-what-default compile
3893         }
3894     } else {
3895         return 0
3896     }
3897
3898     return 1
3899 }
3900