OSDN Git Service

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