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