OSDN Git Service

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