i386.c (ix86_adjust_stack_and_probe_stack_clash): New.
[gcc.git] / gcc / testsuite / lib / target-supports.exp
1 # Copyright (C) 1999-2017 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-patches@gcc.gnu.org
19
20 # This file defines procs for determining features supported by the target.
21
22 # Try to compile the code given by CONTENTS into an output file of
23 # type TYPE, where TYPE is as for target_compile. Return a list
24 # whose first element contains the compiler messages and whose
25 # second element is the name of the output file.
26 #
27 # BASENAME is a prefix to use for source and output files.
28 # If ARGS is not empty, its first element is a string that
29 # should be added to the command line.
30 #
31 # Assume by default that CONTENTS is C code.
32 # Otherwise, code should contain:
33 # "// C++" for c++,
34 # "! Fortran" for Fortran code,
35 # "/* ObjC", for ObjC
36 # "// ObjC++" for ObjC++
37 # and "// Go" for Go
38 # If the tool is ObjC/ObjC++ then we overide the extension to .m/.mm to
39 # allow for ObjC/ObjC++ specific flags.
40 proc check_compile {basename type contents args} {
41 global tool
42 verbose "check_compile tool: $tool for $basename"
43
44 # Save additional_sources to avoid compiling testsuite's sources
45 # against check_compile's source.
46 global additional_sources
47 if [info exists additional_sources] {
48 set tmp_additional_sources "$additional_sources"
49 set additional_sources ""
50 }
51
52 if { [llength $args] > 0 } {
53 set options [list "additional_flags=[lindex $args 0]"]
54 } else {
55 set options ""
56 }
57 switch -glob -- $contents {
58 "*! Fortran*" { set src ${basename}[pid].f90 }
59 "*// C++*" { set src ${basename}[pid].cc }
60 "*// ObjC++*" { set src ${basename}[pid].mm }
61 "*/* ObjC*" { set src ${basename}[pid].m }
62 "*// Go*" { set src ${basename}[pid].go }
63 default {
64 switch -- $tool {
65 "objc" { set src ${basename}[pid].m }
66 "obj-c++" { set src ${basename}[pid].mm }
67 default { set src ${basename}[pid].c }
68 }
69 }
70 }
71
72 set compile_type $type
73 switch -glob $type {
74 assembly { set output ${basename}[pid].s }
75 object { set output ${basename}[pid].o }
76 executable { set output ${basename}[pid].exe }
77 "rtl-*" {
78 set output ${basename}[pid].s
79 lappend options "additional_flags=-fdump-$type"
80 set compile_type assembly
81 }
82 }
83 set f [open $src "w"]
84 puts $f $contents
85 close $f
86 set lines [${tool}_target_compile $src $output $compile_type "$options"]
87 file delete $src
88
89 set scan_output $output
90 # Don't try folding this into the switch above; calling "glob" before the
91 # file is created won't work.
92 if [regexp "rtl-(.*)" $type dummy rtl_type] {
93 set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
94 file delete $output
95 }
96
97 # Restore additional_sources.
98 if [info exists additional_sources] {
99 set additional_sources "$tmp_additional_sources"
100 }
101
102 return [list $lines $scan_output]
103 }
104
105 proc current_target_name { } {
106 global target_info
107 if [info exists target_info(target,name)] {
108 set answer $target_info(target,name)
109 } else {
110 set answer ""
111 }
112 return $answer
113 }
114
115 # Implement an effective-target check for property PROP by invoking
116 # the Tcl command ARGS and seeing if it returns true.
117
118 proc check_cached_effective_target { prop args } {
119 global et_cache
120 global et_prop_list
121
122 set target [current_target_name]
123 if {![info exists et_cache($prop,target)]
124 || $et_cache($prop,target) != $target} {
125 verbose "check_cached_effective_target $prop: checking $target" 2
126 set et_cache($prop,target) $target
127 set et_cache($prop,value) [uplevel eval $args]
128 if {![info exists et_prop_list]
129 || [lsearch $et_prop_list $prop] < 0} {
130 lappend et_prop_list $prop
131 }
132 verbose "check_cached_effective_target cached list is now: $et_prop_list" 2
133 }
134 set value $et_cache($prop,value)
135 verbose "check_cached_effective_target $prop: returning $value for $target" 2
136 return $value
137 }
138
139 # Clear effective-target cache. This is useful after testing
140 # effective-target features and overriding TEST_ALWAYS_FLAGS and/or
141 # ALWAYS_CXXFLAGS.
142 # If one changes ALWAYS_CXXFLAGS or TEST_ALWAYS_FLAGS then they should
143 # do a clear_effective_target_cache at the end as the target cache can
144 # make decisions based upon the flags, and those decisions need to be
145 # redone when the flags change. An example of this is the
146 # asan_init/asan_finish pair.
147
148 proc clear_effective_target_cache { } {
149 global et_cache
150 global et_prop_list
151
152 if {[info exists et_prop_list]} {
153 verbose "clear_effective_target_cache: $et_prop_list" 2
154 foreach prop $et_prop_list {
155 unset et_cache($prop,value)
156 unset et_cache($prop,target)
157 }
158 unset et_prop_list
159 }
160 }
161
162 # Like check_compile, but delete the output file and return true if the
163 # compiler printed no messages.
164 proc check_no_compiler_messages_nocache {args} {
165 set result [eval check_compile $args]
166 set lines [lindex $result 0]
167 set output [lindex $result 1]
168 remote_file build delete $output
169 return [string match "" $lines]
170 }
171
172 # Like check_no_compiler_messages_nocache, but cache the result.
173 # PROP is the property we're checking, and doubles as a prefix for
174 # temporary filenames.
175 proc check_no_compiler_messages {prop args} {
176 return [check_cached_effective_target $prop {
177 eval [list check_no_compiler_messages_nocache $prop] $args
178 }]
179 }
180
181 # Like check_compile, but return true if the compiler printed no
182 # messages and if the contents of the output file satisfy PATTERN.
183 # If PATTERN has the form "!REGEXP", the contents satisfy it if they
184 # don't match regular expression REGEXP, otherwise they satisfy it
185 # if they do match regular expression PATTERN. (PATTERN can start
186 # with something like "[!]" if the regular expression needs to match
187 # "!" as the first character.)
188 #
189 # Delete the output file before returning. The other arguments are
190 # as for check_compile.
191 proc check_no_messages_and_pattern_nocache {basename pattern args} {
192 global tool
193
194 set result [eval [list check_compile $basename] $args]
195 set lines [lindex $result 0]
196 set output [lindex $result 1]
197
198 set ok 0
199 if { [string match "" $lines] } {
200 set chan [open "$output"]
201 set invert [regexp {^!(.*)} $pattern dummy pattern]
202 set ok [expr { [regexp $pattern [read $chan]] != $invert }]
203 close $chan
204 }
205
206 remote_file build delete $output
207 return $ok
208 }
209
210 # Like check_no_messages_and_pattern_nocache, but cache the result.
211 # PROP is the property we're checking, and doubles as a prefix for
212 # temporary filenames.
213 proc check_no_messages_and_pattern {prop pattern args} {
214 return [check_cached_effective_target $prop {
215 eval [list check_no_messages_and_pattern_nocache $prop $pattern] $args
216 }]
217 }
218
219 # Try to compile and run an executable from code CONTENTS. Return true
220 # if the compiler reports no messages and if execution "passes" in the
221 # usual DejaGNU sense. The arguments are as for check_compile, with
222 # TYPE implicitly being "executable".
223 proc check_runtime_nocache {basename contents args} {
224 global tool
225
226 set result [eval [list check_compile $basename executable $contents] $args]
227 set lines [lindex $result 0]
228 set output [lindex $result 1]
229
230 set ok 0
231 if { [string match "" $lines] } {
232 # No error messages, everything is OK.
233 set result [remote_load target "./$output" "" ""]
234 set status [lindex $result 0]
235 verbose "check_runtime_nocache $basename: status is <$status>" 2
236 if { $status == "pass" } {
237 set ok 1
238 }
239 }
240 remote_file build delete $output
241 return $ok
242 }
243
244 # Like check_runtime_nocache, but cache the result. PROP is the
245 # property we're checking, and doubles as a prefix for temporary
246 # filenames.
247 proc check_runtime {prop args} {
248 global tool
249
250 return [check_cached_effective_target $prop {
251 eval [list check_runtime_nocache $prop] $args
252 }]
253 }
254
255 # Return 1 if GCC was configured with $pattern.
256 proc check_configured_with { pattern } {
257 global tool
258
259 set gcc_output [${tool}_target_compile "-v" "" "none" ""]
260 if { [ regexp "Configured with: \[^\n\]*$pattern" $gcc_output ] } {
261 verbose "Matched: $pattern" 2
262 return 1
263 }
264
265 verbose "Failed to match: $pattern" 2
266 return 0
267 }
268
269 ###############################
270 # proc check_weak_available { }
271 ###############################
272
273 # weak symbols are only supported in some configs/object formats
274 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
275
276 proc check_weak_available { } {
277 global target_cpu
278
279 # All mips targets should support it
280
281 if { [ string first "mips" $target_cpu ] >= 0 } {
282 return 1
283 }
284
285 # All AIX targets should support it
286
287 if { [istarget *-*-aix*] } {
288 return 1
289 }
290
291 # All solaris2 targets should support it
292
293 if { [istarget *-*-solaris2*] } {
294 return 1
295 }
296
297 # Windows targets Cygwin and MingW32 support it
298
299 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
300 return 1
301 }
302
303 # HP-UX 10.X doesn't support it
304
305 if { [istarget hppa*-*-hpux10*] } {
306 return 0
307 }
308
309 # nvptx (nearly) supports it
310
311 if { [istarget nvptx-*-*] } {
312 return 1
313 }
314
315 # ELF and ECOFF support it. a.out does with gas/gld but may also with
316 # other linkers, so we should try it
317
318 set objformat [gcc_target_object_format]
319
320 switch $objformat {
321 elf { return 1 }
322 ecoff { return 1 }
323 a.out { return 1 }
324 mach-o { return 1 }
325 som { return 1 }
326 unknown { return -1 }
327 default { return 0 }
328 }
329 }
330
331 ###############################
332 # proc check_weak_override_available { }
333 ###############################
334
335 # Like check_weak_available, but return 0 if weak symbol definitions
336 # cannot be overridden.
337
338 proc check_weak_override_available { } {
339 if { [istarget *-*-mingw*] } {
340 return 0
341 }
342 return [check_weak_available]
343 }
344
345 ###############################
346 # proc check_visibility_available { what_kind }
347 ###############################
348
349 # The visibility attribute is only support in some object formats
350 # This proc returns 1 if it is supported, 0 if not.
351 # The argument is the kind of visibility, default/protected/hidden/internal.
352
353 proc check_visibility_available { what_kind } {
354 if [string match "" $what_kind] { set what_kind "hidden" }
355
356 return [check_no_compiler_messages visibility_available_$what_kind object "
357 void f() __attribute__((visibility(\"$what_kind\")));
358 void f() {}
359 "]
360 }
361
362 ###############################
363 # proc check_alias_available { }
364 ###############################
365
366 # Determine if the target toolchain supports the alias attribute.
367
368 # Returns 2 if the target supports aliases. Returns 1 if the target
369 # only supports weak aliased. Returns 0 if the target does not
370 # support aliases at all. Returns -1 if support for aliases could not
371 # be determined.
372
373 proc check_alias_available { } {
374 global alias_available_saved
375 global tool
376
377 if [info exists alias_available_saved] {
378 verbose "check_alias_available returning saved $alias_available_saved" 2
379 } else {
380 set src alias[pid].c
381 set obj alias[pid].o
382 verbose "check_alias_available compiling testfile $src" 2
383 set f [open $src "w"]
384 # Compile a small test program. The definition of "g" is
385 # necessary to keep the Solaris assembler from complaining
386 # about the program.
387 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
388 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
389 close $f
390 set lines [${tool}_target_compile $src $obj object ""]
391 file delete $src
392 remote_file build delete $obj
393
394 if [string match "" $lines] then {
395 # No error messages, everything is OK.
396 set alias_available_saved 2
397 } else {
398 if [regexp "alias definitions not supported" $lines] {
399 verbose "check_alias_available target does not support aliases" 2
400
401 set objformat [gcc_target_object_format]
402
403 if { $objformat == "elf" } {
404 verbose "check_alias_available but target uses ELF format, so it ought to" 2
405 set alias_available_saved -1
406 } else {
407 set alias_available_saved 0
408 }
409 } else {
410 if [regexp "only weak aliases are supported" $lines] {
411 verbose "check_alias_available target supports only weak aliases" 2
412 set alias_available_saved 1
413 } else {
414 set alias_available_saved -1
415 }
416 }
417 }
418
419 verbose "check_alias_available returning $alias_available_saved" 2
420 }
421
422 return $alias_available_saved
423 }
424
425 # Returns 1 if the target toolchain supports strong aliases, 0 otherwise.
426
427 proc check_effective_target_alias { } {
428 if { [check_alias_available] < 2 } {
429 return 0
430 } else {
431 return 1
432 }
433 }
434
435 # Returns 1 if the target toolchain supports ifunc, 0 otherwise.
436
437 proc check_ifunc_available { } {
438 return [check_no_compiler_messages ifunc_available object {
439 #ifdef __cplusplus
440 extern "C"
441 #endif
442 void g() {}
443 void f() __attribute__((ifunc("g")));
444 }]
445 }
446
447 # Returns true if --gc-sections is supported on the target.
448
449 proc check_gc_sections_available { } {
450 global gc_sections_available_saved
451 global tool
452
453 if {![info exists gc_sections_available_saved]} {
454 # Some targets don't support gc-sections despite whatever's
455 # advertised by ld's options.
456 if { [istarget alpha*-*-*]
457 || [istarget ia64-*-*] } {
458 set gc_sections_available_saved 0
459 return 0
460 }
461
462 # elf2flt uses -q (--emit-relocs), which is incompatible with
463 # --gc-sections.
464 if { [board_info target exists ldflags]
465 && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
466 set gc_sections_available_saved 0
467 return 0
468 }
469
470 # VxWorks kernel modules are relocatable objects linked with -r,
471 # while RTP executables are linked with -q (--emit-relocs).
472 # Both of these options are incompatible with --gc-sections.
473 if { [istarget *-*-vxworks*] } {
474 set gc_sections_available_saved 0
475 return 0
476 }
477
478 # Check if the ld used by gcc supports --gc-sections.
479 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
480 set ld_output [remote_exec host "$gcc_ld" "--help"]
481 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
482 set gc_sections_available_saved 1
483 } else {
484 set gc_sections_available_saved 0
485 }
486 }
487 return $gc_sections_available_saved
488 }
489
490 # Return 1 if according to target_info struct and explicit target list
491 # target is supposed to support trampolines.
492
493 proc check_effective_target_trampolines { } {
494 if [target_info exists gcc,no_trampolines] {
495 return 0
496 }
497 if { [istarget avr-*-*]
498 || [istarget msp430-*-*]
499 || [istarget nvptx-*-*]
500 || [istarget hppa2.0w-hp-hpux11.23]
501 || [istarget hppa64-hp-hpux11.23] } {
502 return 0;
503 }
504 return 1
505 }
506
507 # Return 1 if target has limited stack size.
508
509 proc check_effective_target_stack_size { } {
510 if [target_info exists gcc,stack_size] {
511 return 1
512 }
513 return 0
514 }
515
516 # Return the value attribute of an effective target, otherwise return 0.
517
518 proc dg-effective-target-value { effective_target } {
519 if { "$effective_target" == "stack_size" } {
520 if [check_effective_target_stack_size] {
521 return [target_info gcc,stack_size]
522 }
523 }
524
525 return 0
526 }
527
528 # Return 1 if signal.h is supported.
529
530 proc check_effective_target_signal { } {
531 if [target_info exists gcc,signal_suppress] {
532 return 0
533 }
534 return 1
535 }
536
537 # Return 1 if according to target_info struct and explicit target list
538 # target disables -fdelete-null-pointer-checks. Targets should return 0
539 # if they simply default to -fno-delete-null-pointer-checks but obey
540 # -fdelete-null-pointer-checks when passed explicitly (and tests that
541 # depend on this option should do that).
542
543 proc check_effective_target_keeps_null_pointer_checks { } {
544 if [target_info exists keeps_null_pointer_checks] {
545 return 1
546 }
547 if { [istarget avr-*-*] } {
548 return 1;
549 }
550 return 0
551 }
552
553 # Return the autofdo profile wrapper
554
555 # Linux by default allows 516KB of perf event buffers
556 # in /proc/sys/kernel/perf_event_mlock_kb
557 # Each individual perf tries to grab it
558 # This causes problems with parallel test suite runs. Instead
559 # limit us to 8 pages (32K), which should be good enough
560 # for the small test programs. With the default settings
561 # this allows parallelism of 16 and higher of parallel gcc-auto-profile
562 proc profopt-perf-wrapper { } {
563 global srcdir
564 return "$srcdir/../config/i386/gcc-auto-profile -o perf.data -m8 "
565 }
566
567 # Return true if profiling is supported on the target.
568
569 proc check_profiling_available { test_what } {
570 global profiling_available_saved
571
572 verbose "Profiling argument is <$test_what>" 1
573
574 # These conditions depend on the argument so examine them before
575 # looking at the cache variable.
576
577 # Tree profiling requires TLS runtime support.
578 if { $test_what == "-fprofile-generate" } {
579 if { ![check_effective_target_tls_runtime] } {
580 return 0
581 }
582 }
583
584 if { $test_what == "-fauto-profile" } {
585 if { !([istarget i?86-*-linux*] || [istarget x86_64-*-linux*]) } {
586 verbose "autofdo only supported on linux"
587 return 0
588 }
589 # not cross compiling?
590 if { ![isnative] } {
591 verbose "autofdo not supported for non native builds"
592 return 0
593 }
594 set event [profopt-perf-wrapper]
595 if {$event == "" } {
596 verbose "autofdo not supported"
597 return 0
598 }
599 global srcdir
600 set status [remote_exec host "$srcdir/../config/i386/gcc-auto-profile" "true -v >/dev/null"]
601 if { [lindex $status 0] != 0 } {
602 verbose "autofdo not supported because perf does not work"
603 return 0
604 }
605
606 # no good way to check this in advance -- check later instead.
607 #set status [remote_exec host "create_gcov" "2>/dev/null"]
608 #if { [lindex $status 0] != 255 } {
609 # verbose "autofdo not supported due to missing create_gcov"
610 # return 0
611 #}
612 }
613
614 # Support for -p on solaris2 relies on mcrt1.o which comes with the
615 # vendor compiler. We cannot reliably predict the directory where the
616 # vendor compiler (and thus mcrt1.o) is installed so we can't
617 # necessarily find mcrt1.o even if we have it.
618 if { [istarget *-*-solaris2*] && $test_what == "-p" } {
619 return 0
620 }
621
622 # We don't yet support profiling for MIPS16.
623 if { [istarget mips*-*-*]
624 && ![check_effective_target_nomips16]
625 && ($test_what == "-p" || $test_what == "-pg") } {
626 return 0
627 }
628
629 # MinGW does not support -p.
630 if { [istarget *-*-mingw*] && $test_what == "-p" } {
631 return 0
632 }
633
634 # cygwin does not support -p.
635 if { [istarget *-*-cygwin*] && $test_what == "-p" } {
636 return 0
637 }
638
639 # uClibc does not have gcrt1.o.
640 if { [check_effective_target_uclibc]
641 && ($test_what == "-p" || $test_what == "-pg") } {
642 return 0
643 }
644
645 # Now examine the cache variable.
646 if {![info exists profiling_available_saved]} {
647 # Some targets don't have any implementation of __bb_init_func or are
648 # missing other needed machinery.
649 if {[istarget aarch64*-*-elf]
650 || [istarget am3*-*-linux*]
651 || [istarget arm*-*-eabi*]
652 || [istarget arm*-*-elf]
653 || [istarget arm*-*-symbianelf*]
654 || [istarget avr-*-*]
655 || [istarget bfin-*-*]
656 || [istarget cris-*-*]
657 || [istarget crisv32-*-*]
658 || [istarget fido-*-elf]
659 || [istarget h8300-*-*]
660 || [istarget lm32-*-*]
661 || [istarget m32c-*-elf]
662 || [istarget m68k-*-elf]
663 || [istarget m68k-*-uclinux*]
664 || [istarget mips*-*-elf*]
665 || [istarget mmix-*-*]
666 || [istarget mn10300-*-elf*]
667 || [istarget moxie-*-elf*]
668 || [istarget msp430-*-*]
669 || [istarget nds32*-*-elf]
670 || [istarget nios2-*-elf]
671 || [istarget nvptx-*-*]
672 || [istarget powerpc-*-eabi*]
673 || [istarget powerpc-*-elf]
674 || [istarget rx-*-*]
675 || [istarget tic6x-*-elf]
676 || [istarget visium-*-*]
677 || [istarget xstormy16-*]
678 || [istarget xtensa*-*-elf]
679 || [istarget *-*-rtems*]
680 || [istarget *-*-vxworks*] } {
681 set profiling_available_saved 0
682 } else {
683 set profiling_available_saved 1
684 }
685 }
686
687 # -pg link test result can't be cached since it may change between
688 # runs.
689 set profiling_working $profiling_available_saved
690 if { $profiling_available_saved == 1
691 && ![check_no_compiler_messages_nocache profiling executable {
692 int main() { return 0; } } "-pg"] } {
693 set profiling_working 0
694 }
695
696 return $profiling_working
697 }
698
699 # Check to see if a target is "freestanding". This is as per the definition
700 # in Section 4 of C99 standard. Effectively, it is a target which supports no
701 # extra headers or libraries other than what is considered essential.
702 proc check_effective_target_freestanding { } {
703 if { [istarget nvptx-*-*] } {
704 return 1
705 }
706 return 0
707 }
708
709 # Return 1 if target has packed layout of structure members by
710 # default, 0 otherwise. Note that this is slightly different than
711 # whether the target has "natural alignment": both attributes may be
712 # false.
713
714 proc check_effective_target_default_packed { } {
715 return [check_no_compiler_messages default_packed assembly {
716 struct x { char a; long b; } c;
717 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
718 }]
719 }
720
721 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
722 # documentation, where the test also comes from.
723
724 proc check_effective_target_pcc_bitfield_type_matters { } {
725 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
726 # bitfields, but let's stick to the example code from the docs.
727 return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
728 struct foo1 { char x; char :0; char y; };
729 struct foo2 { char x; int :0; char y; };
730 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
731 }]
732 }
733
734 # Add to FLAGS all the target-specific flags needed to use thread-local storage.
735
736 proc add_options_for_tls { flags } {
737 # On Solaris 9, __tls_get_addr/___tls_get_addr only lives in
738 # libthread, so always pass -pthread for native TLS. Same for AIX.
739 # Need to duplicate native TLS check from
740 # check_effective_target_tls_native to avoid recursion.
741 if { ([istarget powerpc-ibm-aix*]) &&
742 [check_no_messages_and_pattern tls_native "!emutls" assembly {
743 __thread int i;
744 int f (void) { return i; }
745 void g (int j) { i = j; }
746 }] } {
747 return "-pthread [g++_link_flags [get_multilibs "-pthread"] ] $flags "
748 }
749 return $flags
750 }
751
752 # Return 1 if indirect jumps are supported, 0 otherwise.
753
754 proc check_effective_target_indirect_jumps {} {
755 if { [istarget nvptx-*-*] } {
756 return 0
757 }
758 return 1
759 }
760
761 # Return 1 if nonlocal goto is supported, 0 otherwise.
762
763 proc check_effective_target_nonlocal_goto {} {
764 if { [istarget nvptx-*-*] } {
765 return 0
766 }
767 return 1
768 }
769
770 # Return 1 if global constructors are supported, 0 otherwise.
771
772 proc check_effective_target_global_constructor {} {
773 if { [istarget nvptx-*-*] } {
774 return 0
775 }
776 return 1
777 }
778
779 # Return 1 if taking label values is supported, 0 otherwise.
780
781 proc check_effective_target_label_values {} {
782 if { [istarget nvptx-*-*] || [target_info exists gcc,no_label_values] } {
783 return 0
784 }
785
786 return 1
787 }
788
789 # Return 1 if builtin_return_address and builtin_frame_address are
790 # supported, 0 otherwise.
791
792 proc check_effective_target_return_address {} {
793 if { [istarget nvptx-*-*] } {
794 return 0
795 }
796 return 1
797 }
798
799 # Return 1 if the assembler does not verify function types against
800 # calls, 0 otherwise. Such verification will typically show up problems
801 # with K&R C function declarations.
802
803 proc check_effective_target_untyped_assembly {} {
804 if { [istarget nvptx-*-*] } {
805 return 0
806 }
807 return 1
808 }
809
810 # Return 1 if alloca is supported, 0 otherwise.
811
812 proc check_effective_target_alloca {} {
813 if { [istarget nvptx-*-*] } {
814 return [check_no_compiler_messages alloca assembly {
815 void f (void*);
816 void g (int n) { f (__builtin_alloca (n)); }
817 }]
818 }
819 return 1
820 }
821
822 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
823
824 proc check_effective_target_tls {} {
825 return [check_no_compiler_messages tls assembly {
826 __thread int i;
827 int f (void) { return i; }
828 void g (int j) { i = j; }
829 }]
830 }
831
832 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
833
834 proc check_effective_target_tls_native {} {
835 # VxWorks uses emulated TLS machinery, but with non-standard helper
836 # functions, so we fail to automatically detect it.
837 if { [istarget *-*-vxworks*] } {
838 return 0
839 }
840
841 return [check_no_messages_and_pattern tls_native "!emutls" assembly {
842 __thread int i;
843 int f (void) { return i; }
844 void g (int j) { i = j; }
845 }]
846 }
847
848 # Return 1 if *emulated* thread local storage (TLS) is supported, 0 otherwise.
849
850 proc check_effective_target_tls_emulated {} {
851 # VxWorks uses emulated TLS machinery, but with non-standard helper
852 # functions, so we fail to automatically detect it.
853 if { [istarget *-*-vxworks*] } {
854 return 1
855 }
856
857 return [check_no_messages_and_pattern tls_emulated "emutls" assembly {
858 __thread int i;
859 int f (void) { return i; }
860 void g (int j) { i = j; }
861 }]
862 }
863
864 # Return 1 if TLS executables can run correctly, 0 otherwise.
865
866 proc check_effective_target_tls_runtime {} {
867 # The runtime does not have TLS support, but just
868 # running the test below is insufficient to show this.
869 if { [istarget msp430-*-*] || [istarget visium-*-*] } {
870 return 0
871 }
872 return [check_runtime tls_runtime {
873 __thread int thr = 0;
874 int main (void) { return thr; }
875 } [add_options_for_tls ""]]
876 }
877
878 # Return 1 if atomic compare-and-swap is supported on 'int'
879
880 proc check_effective_target_cas_char {} {
881 return [check_no_compiler_messages cas_char assembly {
882 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
883 #error unsupported
884 #endif
885 } ""]
886 }
887
888 proc check_effective_target_cas_int {} {
889 return [check_no_compiler_messages cas_int assembly {
890 #if __INT_MAX__ == 0x7fff && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
891 /* ok */
892 #elif __INT_MAX__ == 0x7fffffff && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
893 /* ok */
894 #else
895 #error unsupported
896 #endif
897 } ""]
898 }
899
900 # Return 1 if -ffunction-sections is supported, 0 otherwise.
901
902 proc check_effective_target_function_sections {} {
903 # Darwin has its own scheme and silently accepts -ffunction-sections.
904 if { [istarget *-*-darwin*] } {
905 return 0
906 }
907
908 return [check_no_compiler_messages functionsections assembly {
909 void foo (void) { }
910 } "-ffunction-sections"]
911 }
912
913 # Return 1 if instruction scheduling is available, 0 otherwise.
914
915 proc check_effective_target_scheduling {} {
916 return [check_no_compiler_messages scheduling object {
917 void foo (void) { }
918 } "-fschedule-insns"]
919 }
920
921 # Return 1 if trapping arithmetic is available, 0 otherwise.
922
923 proc check_effective_target_trapping {} {
924 return [check_no_compiler_messages trapping object {
925 int add (int a, int b) { return a + b; }
926 } "-ftrapv"]
927 }
928
929 # Return 1 if compilation with -fgraphite is error-free for trivial
930 # code, 0 otherwise.
931
932 proc check_effective_target_fgraphite {} {
933 return [check_no_compiler_messages fgraphite object {
934 void foo (void) { }
935 } "-O1 -fgraphite"]
936 }
937
938 # Return 1 if compilation with -fopenacc is error-free for trivial
939 # code, 0 otherwise.
940
941 proc check_effective_target_fopenacc {} {
942 # nvptx can be built with the device-side bits of openacc, but it
943 # does not make sense to test it as an openacc host.
944 if [istarget nvptx-*-*] { return 0 }
945
946 return [check_no_compiler_messages fopenacc object {
947 void foo (void) { }
948 } "-fopenacc"]
949 }
950
951 # Return 1 if compilation with -fopenmp is error-free for trivial
952 # code, 0 otherwise.
953
954 proc check_effective_target_fopenmp {} {
955 # nvptx can be built with the device-side bits of libgomp, but it
956 # does not make sense to test it as an openmp host.
957 if [istarget nvptx-*-*] { return 0 }
958
959 return [check_no_compiler_messages fopenmp object {
960 void foo (void) { }
961 } "-fopenmp"]
962 }
963
964 # Return 1 if compilation with -fgnu-tm is error-free for trivial
965 # code, 0 otherwise.
966
967 proc check_effective_target_fgnu_tm {} {
968 return [check_no_compiler_messages fgnu_tm object {
969 void foo (void) { }
970 } "-fgnu-tm"]
971 }
972
973 # Return 1 if the target supports mmap, 0 otherwise.
974
975 proc check_effective_target_mmap {} {
976 return [check_function_available "mmap"]
977 }
978
979 # Return 1 if the target supports dlopen, 0 otherwise.
980 proc check_effective_target_dlopen {} {
981 return [check_no_compiler_messages dlopen executable {
982 #include <dlfcn.h>
983 int main(void) { dlopen ("dummy.so", RTLD_NOW); }
984 } [add_options_for_dlopen ""]]
985 }
986
987 proc add_options_for_dlopen { flags } {
988 return "$flags -ldl"
989 }
990
991 # Return 1 if the target supports clone, 0 otherwise.
992 proc check_effective_target_clone {} {
993 return [check_function_available "clone"]
994 }
995
996 # Return 1 if the target supports setrlimit, 0 otherwise.
997 proc check_effective_target_setrlimit {} {
998 # Darwin has non-posix compliant RLIMIT_AS
999 if { [istarget *-*-darwin*] } {
1000 return 0
1001 }
1002 return [check_function_available "setrlimit"]
1003 }
1004
1005 # Return 1 if the target supports gettimeofday, 0 otherwise.
1006 proc check_effective_target_gettimeofday {} {
1007 return [check_function_available "gettimeofday"]
1008 }
1009
1010 # Return 1 if the target supports swapcontext, 0 otherwise.
1011 proc check_effective_target_swapcontext {} {
1012 return [check_no_compiler_messages swapcontext executable {
1013 #include <ucontext.h>
1014 int main (void)
1015 {
1016 ucontext_t orig_context,child_context;
1017 if (swapcontext(&child_context, &orig_context) < 0) { }
1018 }
1019 }]
1020 }
1021
1022 # Return 1 if compilation with -pthread is error-free for trivial
1023 # code, 0 otherwise.
1024
1025 proc check_effective_target_pthread {} {
1026 return [check_no_compiler_messages pthread object {
1027 void foo (void) { }
1028 } "-pthread"]
1029 }
1030
1031 # Return 1 if compilation with -gstabs is error-free for trivial
1032 # code, 0 otherwise.
1033
1034 proc check_effective_target_stabs {} {
1035 return [check_no_compiler_messages stabs object {
1036 void foo (void) { }
1037 } "-gstabs"]
1038 }
1039
1040 # Return 1 if compilation with -mpe-aligned-commons is error-free
1041 # for trivial code, 0 otherwise.
1042
1043 proc check_effective_target_pe_aligned_commons {} {
1044 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
1045 return [check_no_compiler_messages pe_aligned_commons object {
1046 int foo;
1047 } "-mpe-aligned-commons"]
1048 }
1049 return 0
1050 }
1051
1052 # Return 1 if the target supports -static
1053 proc check_effective_target_static {} {
1054 return [check_no_compiler_messages static executable {
1055 int main (void) { return 0; }
1056 } "-static"]
1057 }
1058
1059 # Return 1 if the target supports -fstack-protector
1060 proc check_effective_target_fstack_protector {} {
1061 return [check_runtime fstack_protector {
1062 int main (void) { return 0; }
1063 } "-fstack-protector"]
1064 }
1065
1066 # Return 1 if the target supports -fstack-check or -fstack-check=$stack_kind
1067 proc check_stack_check_available { stack_kind } {
1068 if [string match "" $stack_kind] then {
1069 set stack_opt "-fstack-check"
1070 } else { set stack_opt "-fstack-check=$stack_kind" }
1071
1072 return [check_no_compiler_messages stack_check_$stack_kind executable {
1073 int main (void) { return 0; }
1074 } "$stack_opt"]
1075 }
1076
1077 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
1078 # for trivial code, 0 otherwise. As some targets (ARM for example) only
1079 # warn when -fprofile-use is also supplied we test that combination too.
1080
1081 proc check_effective_target_freorder {} {
1082 if { [check_no_compiler_messages freorder object {
1083 void foo (void) { }
1084 } "-freorder-blocks-and-partition"]
1085 && [check_no_compiler_messages fprofile_use_freorder object {
1086 void foo (void) { }
1087 } "-fprofile-use -freorder-blocks-and-partition"] } {
1088 return 1
1089 }
1090 return 0
1091 }
1092
1093 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
1094 # emitted, 0 otherwise. Whether a shared library can actually be built is
1095 # out of scope for this test.
1096
1097 proc check_effective_target_fpic { } {
1098 # Note that M68K has a multilib that supports -fpic but not
1099 # -fPIC, so we need to check both. We test with a program that
1100 # requires GOT references.
1101 foreach arg {fpic fPIC} {
1102 if [check_no_compiler_messages $arg object {
1103 extern int foo (void); extern int bar;
1104 int baz (void) { return foo () + bar; }
1105 } "-$arg"] {
1106 return 1
1107 }
1108 }
1109 return 0
1110 }
1111
1112 # On AArch64, if -fpic is not supported, then we will fall back to -fPIC
1113 # silently. So, we can't rely on above "check_effective_target_fpic" as it
1114 # assumes compiler will give warning if -fpic not supported. Here we check
1115 # whether binutils supports those new -fpic relocation modifiers, and assume
1116 # -fpic is supported if there is binutils support. GCC configuration will
1117 # enable -fpic for AArch64 in this case.
1118 #
1119 # "check_effective_target_aarch64_small_fpic" is dedicated for checking small
1120 # memory model -fpic relocation types.
1121
1122 proc check_effective_target_aarch64_small_fpic { } {
1123 if { [istarget aarch64*-*-*] } {
1124 return [check_no_compiler_messages aarch64_small_fpic object {
1125 void foo (void) { asm ("ldr x0, [x2, #:gotpage_lo15:globalsym]"); }
1126 }]
1127 } else {
1128 return 0
1129 }
1130 }
1131
1132 # On AArch64, instruction sequence for TLS LE under -mtls-size=32 will utilize
1133 # the relocation modifier "tprel_g0_nc" together with MOVK, it's only supported
1134 # in binutils since 2015-03-04 as PR gas/17843.
1135 #
1136 # This test directive make sure binutils support all features needed by TLS LE
1137 # under -mtls-size=32 on AArch64.
1138
1139 proc check_effective_target_aarch64_tlsle32 { } {
1140 if { [istarget aarch64*-*-*] } {
1141 return [check_no_compiler_messages aarch64_tlsle32 object {
1142 void foo (void) { asm ("movk x1,#:tprel_g0_nc:t1"); }
1143 }]
1144 } else {
1145 return 0
1146 }
1147 }
1148
1149 # Return 1 if -shared is supported, as in no warnings or errors
1150 # emitted, 0 otherwise.
1151
1152 proc check_effective_target_shared { } {
1153 # Note that M68K has a multilib that supports -fpic but not
1154 # -fPIC, so we need to check both. We test with a program that
1155 # requires GOT references.
1156 return [check_no_compiler_messages shared executable {
1157 extern int foo (void); extern int bar;
1158 int baz (void) { return foo () + bar; }
1159 } "-shared -fpic"]
1160 }
1161
1162 # Return 1 if -pie, -fpie and -fPIE are supported, 0 otherwise.
1163
1164 proc check_effective_target_pie { } {
1165 if { [istarget *-*-darwin\[912\]*]
1166 || [istarget *-*-dragonfly*]
1167 || [istarget *-*-freebsd*]
1168 || [istarget *-*-linux*]
1169 || [istarget *-*-gnu*] } {
1170 return 1;
1171 }
1172 if { [istarget *-*-solaris2.1\[1-9\]*] } {
1173 # Full PIE support was added in Solaris 11.x and Solaris 12, but gcc
1174 # errors out if missing, so check for that.
1175 return [check_no_compiler_messages pie executable {
1176 int main (void) { return 0; }
1177 } "-pie -fpie"]
1178 }
1179 return 0
1180 }
1181
1182 # Return true if the target supports -mpaired-single (as used on MIPS).
1183
1184 proc check_effective_target_mpaired_single { } {
1185 return [check_no_compiler_messages mpaired_single object {
1186 void foo (void) { }
1187 } "-mpaired-single"]
1188 }
1189
1190 # Return true if the target has access to FPU instructions.
1191
1192 proc check_effective_target_hard_float { } {
1193 if { [istarget mips*-*-*] } {
1194 return [check_no_compiler_messages hard_float assembly {
1195 #if (defined __mips_soft_float || defined __mips16)
1196 #error __mips_soft_float || __mips16
1197 #endif
1198 }]
1199 }
1200
1201 # This proc is actually checking the availabilty of FPU
1202 # support for doubles, so on the RX we must fail if the
1203 # 64-bit double multilib has been selected.
1204 if { [istarget rx-*-*] } {
1205 return 0
1206 # return [check_no_compiler_messages hard_float assembly {
1207 #if defined __RX_64_BIT_DOUBLES__
1208 #error __RX_64_BIT_DOUBLES__
1209 #endif
1210 # }]
1211 }
1212
1213 # The generic test equates hard_float with "no call for adding doubles".
1214 return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
1215 double a (double b, double c) { return b + c; }
1216 }]
1217 }
1218
1219 # Return true if the target is a 64-bit MIPS target.
1220
1221 proc check_effective_target_mips64 { } {
1222 return [check_no_compiler_messages mips64 assembly {
1223 #ifndef __mips64
1224 #error !__mips64
1225 #endif
1226 }]
1227 }
1228
1229 # Return true if the target is a MIPS target that does not produce
1230 # MIPS16 code.
1231
1232 proc check_effective_target_nomips16 { } {
1233 return [check_no_compiler_messages nomips16 object {
1234 #ifndef __mips
1235 #error !__mips
1236 #else
1237 /* A cheap way of testing for -mflip-mips16. */
1238 void foo (void) { asm ("addiu $20,$20,1"); }
1239 void bar (void) { asm ("addiu $20,$20,1"); }
1240 #endif
1241 }]
1242 }
1243
1244 # Add the options needed for MIPS16 function attributes. At the moment,
1245 # we don't support MIPS16 PIC.
1246
1247 proc add_options_for_mips16_attribute { flags } {
1248 return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
1249 }
1250
1251 # Return true if we can force a mode that allows MIPS16 code generation.
1252 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
1253 # for o32 and o64.
1254
1255 proc check_effective_target_mips16_attribute { } {
1256 return [check_no_compiler_messages mips16_attribute assembly {
1257 #ifdef PIC
1258 #error PIC
1259 #endif
1260 #if defined __mips_hard_float \
1261 && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
1262 && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
1263 #error __mips_hard_float && (!_ABIO32 || !_ABIO64)
1264 #endif
1265 } [add_options_for_mips16_attribute ""]]
1266 }
1267
1268 # Return 1 if the target supports long double larger than double when
1269 # using the new ABI, 0 otherwise.
1270
1271 proc check_effective_target_mips_newabi_large_long_double { } {
1272 return [check_no_compiler_messages mips_newabi_large_long_double object {
1273 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1274 } "-mabi=64"]
1275 }
1276
1277 # Return true if the target is a MIPS target that has access
1278 # to the LL and SC instructions.
1279
1280 proc check_effective_target_mips_llsc { } {
1281 if { ![istarget mips*-*-*] } {
1282 return 0
1283 }
1284 # Assume that these instructions are always implemented for
1285 # non-elf* targets, via emulation if necessary.
1286 if { ![istarget *-*-elf*] } {
1287 return 1
1288 }
1289 # Otherwise assume LL/SC support for everything but MIPS I.
1290 return [check_no_compiler_messages mips_llsc assembly {
1291 #if __mips == 1
1292 #error __mips == 1
1293 #endif
1294 }]
1295 }
1296
1297 # Return true if the target is a MIPS target that uses in-place relocations.
1298
1299 proc check_effective_target_mips_rel { } {
1300 if { ![istarget mips*-*-*] } {
1301 return 0
1302 }
1303 return [check_no_compiler_messages mips_rel object {
1304 #if (defined _ABIN32 && _MIPS_SIM == _ABIN32) \
1305 || (defined _ABI64 && _MIPS_SIM == _ABI64)
1306 #error _ABIN32 && (_ABIN32 || _ABI64)
1307 #endif
1308 }]
1309 }
1310
1311 # Return true if the target is a MIPS target that uses the EABI.
1312
1313 proc check_effective_target_mips_eabi { } {
1314 if { ![istarget mips*-*-*] } {
1315 return 0
1316 }
1317 return [check_no_compiler_messages mips_eabi object {
1318 #ifndef __mips_eabi
1319 #error !__mips_eabi
1320 #endif
1321 }]
1322 }
1323
1324 # Return 1 if the current multilib does not generate PIC by default.
1325
1326 proc check_effective_target_nonpic { } {
1327 return [check_no_compiler_messages nonpic assembly {
1328 #if __PIC__
1329 #error __PIC__
1330 #endif
1331 }]
1332 }
1333
1334 # Return 1 if the current multilib generates PIE by default.
1335
1336 proc check_effective_target_pie_enabled { } {
1337 return [check_no_compiler_messages pie_enabled assembly {
1338 #ifndef __PIE__
1339 #error unsupported
1340 #endif
1341 }]
1342 }
1343
1344 # Return 1 if the target generates -fstack-protector by default.
1345
1346 proc check_effective_target_fstack_protector_enabled {} {
1347 return [ check_no_compiler_messages fstack_protector_enabled assembly {
1348 #if !defined(__SSP__) && !defined(__SSP_ALL__) && \
1349 !defined(__SSP_STRONG__) && !defined(__SSP_EXPICIT__)
1350 #error unsupported
1351 #endif
1352 }]
1353 }
1354
1355 # Return 1 if the target does not use a status wrapper.
1356
1357 proc check_effective_target_unwrapped { } {
1358 if { [target_info needs_status_wrapper] != "" \
1359 && [target_info needs_status_wrapper] != "0" } {
1360 return 0
1361 }
1362 return 1
1363 }
1364
1365 # Return true if iconv is supported on the target. In particular IBM1047.
1366
1367 proc check_iconv_available { test_what } {
1368 global libiconv
1369
1370 # If the tool configuration file has not set libiconv, try "-liconv"
1371 if { ![info exists libiconv] } {
1372 set libiconv "-liconv"
1373 }
1374 set test_what [lindex $test_what 1]
1375 return [check_runtime_nocache $test_what [subst {
1376 #include <iconv.h>
1377 int main (void)
1378 {
1379 iconv_t cd;
1380
1381 cd = iconv_open ("$test_what", "UTF-8");
1382 if (cd == (iconv_t) -1)
1383 return 1;
1384 return 0;
1385 }
1386 }] $libiconv]
1387 }
1388
1389 # Return true if Cilk Library is supported on the target.
1390 proc check_effective_target_cilkplus_runtime { } {
1391 return [ check_no_compiler_messages_nocache cilkplus_runtime executable {
1392 #ifdef __cplusplus
1393 extern "C"
1394 #endif
1395 int __cilkrts_set_param (const char *, const char *);
1396 int main (void) {
1397 int x = __cilkrts_set_param ("nworkers", "0");
1398 return x;
1399 }
1400 } "-fcilkplus -lcilkrts" ]
1401 }
1402
1403 # Return true if the atomic library is supported on the target.
1404 proc check_effective_target_libatomic_available { } {
1405 return [check_no_compiler_messages libatomic_available executable {
1406 int main (void) { return 0; }
1407 } "-latomic"]
1408 }
1409
1410 # Return 1 if an ASCII locale is supported on this host, 0 otherwise.
1411
1412 proc check_ascii_locale_available { } {
1413 return 1
1414 }
1415
1416 # Return true if named sections are supported on this target.
1417
1418 proc check_named_sections_available { } {
1419 return [check_no_compiler_messages named_sections assembly {
1420 int __attribute__ ((section("whatever"))) foo;
1421 }]
1422 }
1423
1424 # Return true if the "naked" function attribute is supported on this target.
1425
1426 proc check_effective_target_naked_functions { } {
1427 return [check_no_compiler_messages naked_functions assembly {
1428 void f() __attribute__((naked));
1429 }]
1430 }
1431
1432 # Return 1 if the target supports Fortran real kinds larger than real(8),
1433 # 0 otherwise.
1434 #
1435 # When the target name changes, replace the cached result.
1436
1437 proc check_effective_target_fortran_large_real { } {
1438 return [check_no_compiler_messages fortran_large_real executable {
1439 ! Fortran
1440 integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
1441 real(kind=k) :: x
1442 x = cos (x)
1443 end
1444 }]
1445 }
1446
1447 # Return 1 if the target supports Fortran real kind real(16),
1448 # 0 otherwise. Contrary to check_effective_target_fortran_large_real
1449 # this checks for Real(16) only; the other returned real(10) if
1450 # both real(10) and real(16) are available.
1451 #
1452 # When the target name changes, replace the cached result.
1453
1454 proc check_effective_target_fortran_real_16 { } {
1455 return [check_no_compiler_messages fortran_real_16 executable {
1456 ! Fortran
1457 real(kind=16) :: x
1458 x = cos (x)
1459 end
1460 }]
1461 }
1462
1463
1464 # Return 1 if the target supports Fortran's IEEE modules,
1465 # 0 otherwise.
1466 #
1467 # When the target name changes, replace the cached result.
1468
1469 proc check_effective_target_fortran_ieee { flags } {
1470 return [check_no_compiler_messages fortran_ieee executable {
1471 ! Fortran
1472 use, intrinsic :: ieee_features
1473 end
1474 } $flags ]
1475 }
1476
1477
1478 # Return 1 if the target supports SQRT for the largest floating-point
1479 # type. (Some targets lack the libm support for this FP type.)
1480 # On most targets, this check effectively checks either whether sqrtl is
1481 # available or on __float128 systems whether libquadmath is installed,
1482 # which provides sqrtq.
1483 #
1484 # When the target name changes, replace the cached result.
1485
1486 proc check_effective_target_fortran_largest_fp_has_sqrt { } {
1487 return [check_no_compiler_messages fortran_largest_fp_has_sqrt executable {
1488 ! Fortran
1489 use iso_fortran_env, only: real_kinds
1490 integer,parameter:: maxFP = real_kinds(ubound(real_kinds,dim=1))
1491 real(kind=maxFP), volatile :: x
1492 x = 2.0_maxFP
1493 x = sqrt (x)
1494 end
1495 }]
1496 }
1497
1498
1499 # Return 1 if the target supports Fortran integer kinds larger than
1500 # integer(8), 0 otherwise.
1501 #
1502 # When the target name changes, replace the cached result.
1503
1504 proc check_effective_target_fortran_large_int { } {
1505 return [check_no_compiler_messages fortran_large_int executable {
1506 ! Fortran
1507 integer,parameter :: k = selected_int_kind (range (0_8) + 1)
1508 integer(kind=k) :: i
1509 end
1510 }]
1511 }
1512
1513 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
1514 #
1515 # When the target name changes, replace the cached result.
1516
1517 proc check_effective_target_fortran_integer_16 { } {
1518 return [check_no_compiler_messages fortran_integer_16 executable {
1519 ! Fortran
1520 integer(16) :: i
1521 end
1522 }]
1523 }
1524
1525 # Return 1 if we can statically link libgfortran, 0 otherwise.
1526 #
1527 # When the target name changes, replace the cached result.
1528
1529 proc check_effective_target_static_libgfortran { } {
1530 return [check_no_compiler_messages static_libgfortran executable {
1531 ! Fortran
1532 print *, 'test'
1533 end
1534 } "-static"]
1535 }
1536
1537 # Return 1 if we can use the -rdynamic option, 0 otherwise.
1538
1539 proc check_effective_target_rdynamic { } {
1540 return [check_no_compiler_messages rdynamic executable {
1541 int main() { return 0; }
1542 } "-rdynamic"]
1543 }
1544
1545 # Return 1 if cilk-plus is supported by the target, 0 otherwise.
1546
1547 proc check_effective_target_cilkplus { } {
1548 # Skip cilk-plus tests on int16 and size16 targets for now.
1549 # The cilk-plus tests are not generic enough to cover these
1550 # cases and would throw hundreds of FAILs.
1551 if { [check_effective_target_int16]
1552 || ![check_effective_target_size32plus] } {
1553 return 0;
1554 }
1555
1556 # Skip AVR, its RAM is too small and too many tests would fail.
1557 if { [istarget avr-*-*] } {
1558 return 0;
1559 }
1560
1561 if { ! [check_effective_target_pthread] } {
1562 return 0;
1563 }
1564
1565 return 1
1566 }
1567
1568 proc check_linker_plugin_available { } {
1569 return [check_no_compiler_messages_nocache linker_plugin executable {
1570 int main() { return 0; }
1571 } "-flto -fuse-linker-plugin"]
1572 }
1573
1574 # Return 1 if the target OS supports running SSE executables, 0
1575 # otherwise. Cache the result.
1576
1577 proc check_sse_os_support_available { } {
1578 return [check_cached_effective_target sse_os_support_available {
1579 # If this is not the right target then we can skip the test.
1580 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1581 expr 0
1582 } elseif { [istarget i?86-*-solaris2*] } {
1583 # The Solaris 2 kernel doesn't save and restore SSE registers
1584 # before Solaris 9 4/04. Before that, executables die with SIGILL.
1585 check_runtime_nocache sse_os_support_available {
1586 int main ()
1587 {
1588 asm volatile ("movaps %xmm0,%xmm0");
1589 return 0;
1590 }
1591 } "-msse"
1592 } else {
1593 expr 1
1594 }
1595 }]
1596 }
1597
1598 # Return 1 if the target OS supports running AVX executables, 0
1599 # otherwise. Cache the result.
1600
1601 proc check_avx_os_support_available { } {
1602 return [check_cached_effective_target avx_os_support_available {
1603 # If this is not the right target then we can skip the test.
1604 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1605 expr 0
1606 } else {
1607 # Check that OS has AVX and SSE saving enabled.
1608 check_runtime_nocache avx_os_support_available {
1609 int main ()
1610 {
1611 unsigned int eax, edx;
1612
1613 asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
1614 return (eax & 0x06) != 0x06;
1615 }
1616 } ""
1617 }
1618 }]
1619 }
1620
1621 # Return 1 if the target OS supports running AVX executables, 0
1622 # otherwise. Cache the result.
1623
1624 proc check_avx512_os_support_available { } {
1625 return [check_cached_effective_target avx512_os_support_available {
1626 # If this is not the right target then we can skip the test.
1627 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1628 expr 0
1629 } else {
1630 # Check that OS has AVX512, AVX and SSE saving enabled.
1631 check_runtime_nocache avx512_os_support_available {
1632 int main ()
1633 {
1634 unsigned int eax, edx;
1635
1636 asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
1637 return (eax & 0xe6) != 0xe6;
1638 }
1639 } ""
1640 }
1641 }]
1642 }
1643
1644 # Return 1 if the target supports executing SSE instructions, 0
1645 # otherwise. Cache the result.
1646
1647 proc check_sse_hw_available { } {
1648 return [check_cached_effective_target sse_hw_available {
1649 # If this is not the right target then we can skip the test.
1650 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1651 expr 0
1652 } else {
1653 check_runtime_nocache sse_hw_available {
1654 #include "cpuid.h"
1655 int main ()
1656 {
1657 unsigned int eax, ebx, ecx, edx;
1658 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1659 return 1;
1660
1661 return !(edx & bit_SSE);
1662 }
1663 } ""
1664 }
1665 }]
1666 }
1667
1668 # Return 1 if the target supports executing SSE2 instructions, 0
1669 # otherwise. Cache the result.
1670
1671 proc check_sse2_hw_available { } {
1672 return [check_cached_effective_target sse2_hw_available {
1673 # If this is not the right target then we can skip the test.
1674 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1675 expr 0
1676 } else {
1677 check_runtime_nocache sse2_hw_available {
1678 #include "cpuid.h"
1679 int main ()
1680 {
1681 unsigned int eax, ebx, ecx, edx;
1682 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1683 return 1;
1684
1685 return !(edx & bit_SSE2);
1686 }
1687 } ""
1688 }
1689 }]
1690 }
1691
1692 # Return 1 if the target supports executing SSE4 instructions, 0
1693 # otherwise. Cache the result.
1694
1695 proc check_sse4_hw_available { } {
1696 return [check_cached_effective_target sse4_hw_available {
1697 # If this is not the right target then we can skip the test.
1698 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1699 expr 0
1700 } else {
1701 check_runtime_nocache sse4_hw_available {
1702 #include "cpuid.h"
1703 int main ()
1704 {
1705 unsigned int eax, ebx, ecx, edx;
1706 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1707 return 1;
1708
1709 return !(ecx & bit_SSE4_2);
1710 }
1711 } ""
1712 }
1713 }]
1714 }
1715
1716 # Return 1 if the target supports executing AVX instructions, 0
1717 # otherwise. Cache the result.
1718
1719 proc check_avx_hw_available { } {
1720 return [check_cached_effective_target avx_hw_available {
1721 # If this is not the right target then we can skip the test.
1722 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1723 expr 0
1724 } else {
1725 check_runtime_nocache avx_hw_available {
1726 #include "cpuid.h"
1727 int main ()
1728 {
1729 unsigned int eax, ebx, ecx, edx;
1730 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1731 return 1;
1732
1733 return ((ecx & (bit_AVX | bit_OSXSAVE))
1734 != (bit_AVX | bit_OSXSAVE));
1735 }
1736 } ""
1737 }
1738 }]
1739 }
1740
1741 # Return 1 if the target supports executing AVX2 instructions, 0
1742 # otherwise. Cache the result.
1743
1744 proc check_avx2_hw_available { } {
1745 return [check_cached_effective_target avx2_hw_available {
1746 # If this is not the right target then we can skip the test.
1747 if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1748 expr 0
1749 } else {
1750 check_runtime_nocache avx2_hw_available {
1751 #include <stddef.h>
1752 #include "cpuid.h"
1753 int main ()
1754 {
1755 unsigned int eax, ebx, ecx, edx;
1756
1757 if (__get_cpuid_max (0, NULL) < 7)
1758 return 1;
1759
1760 __cpuid (1, eax, ebx, ecx, edx);
1761
1762 if (!(ecx & bit_OSXSAVE))
1763 return 1;
1764
1765 __cpuid_count (7, 0, eax, ebx, ecx, edx);
1766
1767 return !(ebx & bit_AVX2);
1768 }
1769 } ""
1770 }
1771 }]
1772 }
1773
1774 # Return 1 if the target supports executing AVX512 foundation instructions, 0
1775 # otherwise. Cache the result.
1776
1777 proc check_avx512f_hw_available { } {
1778 return [check_cached_effective_target avx512f_hw_available {
1779 # If this is not the right target then we can skip the test.
1780 if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1781 expr 0
1782 } else {
1783 check_runtime_nocache avx512f_hw_available {
1784 #include <stddef.h>
1785 #include "cpuid.h"
1786 int main ()
1787 {
1788 unsigned int eax, ebx, ecx, edx;
1789
1790 if (__get_cpuid_max (0, NULL) < 7)
1791 return 1;
1792
1793 __cpuid (1, eax, ebx, ecx, edx);
1794
1795 if (!(ecx & bit_OSXSAVE))
1796 return 1;
1797
1798 __cpuid_count (7, 0, eax, ebx, ecx, edx);
1799
1800 return !(ebx & bit_AVX512F);
1801 }
1802 } ""
1803 }
1804 }]
1805 }
1806
1807 # Return 1 if the target supports running SSE executables, 0 otherwise.
1808
1809 proc check_effective_target_sse_runtime { } {
1810 if { [check_effective_target_sse]
1811 && [check_sse_hw_available]
1812 && [check_sse_os_support_available] } {
1813 return 1
1814 }
1815 return 0
1816 }
1817
1818 # Return 1 if the target supports running SSE2 executables, 0 otherwise.
1819
1820 proc check_effective_target_sse2_runtime { } {
1821 if { [check_effective_target_sse2]
1822 && [check_sse2_hw_available]
1823 && [check_sse_os_support_available] } {
1824 return 1
1825 }
1826 return 0
1827 }
1828
1829 # Return 1 if the target supports running SSE4 executables, 0 otherwise.
1830
1831 proc check_effective_target_sse4_runtime { } {
1832 if { [check_effective_target_sse4]
1833 && [check_sse4_hw_available]
1834 && [check_sse_os_support_available] } {
1835 return 1
1836 }
1837 return 0
1838 }
1839
1840 # Return 1 if the target supports running AVX executables, 0 otherwise.
1841
1842 proc check_effective_target_avx_runtime { } {
1843 if { [check_effective_target_avx]
1844 && [check_avx_hw_available]
1845 && [check_avx_os_support_available] } {
1846 return 1
1847 }
1848 return 0
1849 }
1850
1851 # Return 1 if the target supports running AVX2 executables, 0 otherwise.
1852
1853 proc check_effective_target_avx2_runtime { } {
1854 if { [check_effective_target_avx2]
1855 && [check_avx2_hw_available]
1856 && [check_avx_os_support_available] } {
1857 return 1
1858 }
1859 return 0
1860 }
1861
1862 # Return 1 if the target supports running AVX512f executables, 0 otherwise.
1863
1864 proc check_effective_target_avx512f_runtime { } {
1865 if { [check_effective_target_avx512f]
1866 && [check_avx512f_hw_available]
1867 && [check_avx512_os_support_available] } {
1868 return 1
1869 }
1870 return 0
1871 }
1872
1873 # Return 1 if the target supports executing MIPS Paired-Single instructions,
1874 # 0 otherwise. Cache the result.
1875
1876 proc check_mpaired_single_hw_available { } {
1877 return [check_cached_effective_target mpaired_single_hw_available {
1878 # If this is not the right target then we can skip the test.
1879 if { !([istarget mips*-*-*]) } {
1880 expr 0
1881 } else {
1882 check_runtime_nocache mpaired_single_hw_available {
1883 int main()
1884 {
1885 asm volatile ("pll.ps $f2,$f4,$f6");
1886 return 0;
1887 }
1888 } ""
1889 }
1890 }]
1891 }
1892
1893 # Return 1 if the target supports executing Loongson vector instructions,
1894 # 0 otherwise. Cache the result.
1895
1896 proc check_mips_loongson_hw_available { } {
1897 return [check_cached_effective_target mips_loongson_hw_available {
1898 # If this is not the right target then we can skip the test.
1899 if { !([istarget mips*-*-*]) } {
1900 expr 0
1901 } else {
1902 check_runtime_nocache mips_loongson_hw_available {
1903 #include <loongson.h>
1904 int main()
1905 {
1906 asm volatile ("paddw $f2,$f4,$f6");
1907 return 0;
1908 }
1909 } ""
1910 }
1911 }]
1912 }
1913
1914 # Return 1 if the target supports executing MIPS MSA instructions, 0
1915 # otherwise. Cache the result.
1916
1917 proc check_mips_msa_hw_available { } {
1918 return [check_cached_effective_target mips_msa_hw_available {
1919 # If this is not the right target then we can skip the test.
1920 if { !([istarget mips*-*-*]) } {
1921 expr 0
1922 } else {
1923 check_runtime_nocache mips_msa_hw_available {
1924 #if !defined(__mips_msa)
1925 #error "MSA NOT AVAIL"
1926 #else
1927 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
1928 #error "MSA NOT AVAIL FOR ISA REV < 2"
1929 #endif
1930 #if !defined(__mips_hard_float)
1931 #error "MSA HARD_FLOAT REQUIRED"
1932 #endif
1933 #if __mips_fpr != 64
1934 #error "MSA 64-bit FPR REQUIRED"
1935 #endif
1936 #include <msa.h>
1937
1938 int main()
1939 {
1940 v8i16 v = __builtin_msa_ldi_h (0);
1941 v[0] = 0;
1942 return v[0];
1943 }
1944 #endif
1945 } "-mmsa"
1946 }
1947 }]
1948 }
1949
1950 # Return 1 if the target supports running MIPS Paired-Single
1951 # executables, 0 otherwise.
1952
1953 proc check_effective_target_mpaired_single_runtime { } {
1954 if { [check_effective_target_mpaired_single]
1955 && [check_mpaired_single_hw_available] } {
1956 return 1
1957 }
1958 return 0
1959 }
1960
1961 # Return 1 if the target supports running Loongson executables, 0 otherwise.
1962
1963 proc check_effective_target_mips_loongson_runtime { } {
1964 if { [check_effective_target_mips_loongson]
1965 && [check_mips_loongson_hw_available] } {
1966 return 1
1967 }
1968 return 0
1969 }
1970
1971 # Return 1 if the target supports running MIPS MSA executables, 0 otherwise.
1972
1973 proc check_effective_target_mips_msa_runtime { } {
1974 if { [check_effective_target_mips_msa]
1975 && [check_mips_msa_hw_available] } {
1976 return 1
1977 }
1978 return 0
1979 }
1980
1981 # Return 1 if we are compiling for 64-bit PowerPC but we do not use direct
1982 # move instructions for moves from GPR to FPR.
1983
1984 proc check_effective_target_powerpc64_no_dm { } {
1985 # The "mulld" checks if we are generating PowerPC64 code. The "lfd"
1986 # checks if we do not use direct moves, but use the old-fashioned
1987 # slower move-via-the-stack.
1988 return [check_no_messages_and_pattern powerpc64_no_dm \
1989 {\mmulld\M.*\mlfd} assembly {
1990 double f(long long x) { return x*x; }
1991 } {-O2}]
1992 }
1993
1994 # Return 1 if the target supports the __builtin_cpu_supports built-in,
1995 # including having a new enough library to support the test. Cache the result.
1996 # Require at least a power7 to run on.
1997
1998 proc check_ppc_cpu_supports_hw_available { } {
1999 return [check_cached_effective_target ppc_cpu_supports_hw_available {
2000 # Some simulators are known to not support VSX/power8 instructions.
2001 # For now, disable on Darwin
2002 if { [istarget powerpc-*-eabi]
2003 || [istarget powerpc*-*-eabispe]
2004 || [istarget *-*-darwin*]} {
2005 expr 0
2006 } else {
2007 set options "-mvsx"
2008 check_runtime_nocache ppc_cpu_supports_hw_available {
2009 int main()
2010 {
2011 #ifdef __MACH__
2012 asm volatile ("xxlor vs0,vs0,vs0");
2013 #else
2014 asm volatile ("xxlor 0,0,0");
2015 #endif
2016 if (!__builtin_cpu_supports ("vsx"))
2017 return 1;
2018 return 0;
2019 }
2020 } $options
2021 }
2022 }]
2023 }
2024
2025 # Return 1 if the target supports executing 750CL paired-single instructions, 0
2026 # otherwise. Cache the result.
2027
2028 proc check_750cl_hw_available { } {
2029 return [check_cached_effective_target 750cl_hw_available {
2030 # If this is not the right target then we can skip the test.
2031 if { ![istarget powerpc-*paired*] } {
2032 expr 0
2033 } else {
2034 check_runtime_nocache 750cl_hw_available {
2035 int main()
2036 {
2037 #ifdef __MACH__
2038 asm volatile ("ps_mul v0,v0,v0");
2039 #else
2040 asm volatile ("ps_mul 0,0,0");
2041 #endif
2042 return 0;
2043 }
2044 } "-mpaired"
2045 }
2046 }]
2047 }
2048
2049 # Return 1 if the target supports executing power8 vector instructions, 0
2050 # otherwise. Cache the result.
2051
2052 proc check_p8vector_hw_available { } {
2053 return [check_cached_effective_target p8vector_hw_available {
2054 # Some simulators are known to not support VSX/power8 instructions.
2055 # For now, disable on Darwin
2056 if { [istarget powerpc-*-eabi]
2057 || [istarget powerpc*-*-eabispe]
2058 || [istarget *-*-darwin*]} {
2059 expr 0
2060 } else {
2061 set options "-mpower8-vector"
2062 check_runtime_nocache p8vector_hw_available {
2063 int main()
2064 {
2065 #ifdef __MACH__
2066 asm volatile ("xxlorc vs0,vs0,vs0");
2067 #else
2068 asm volatile ("xxlorc 0,0,0");
2069 #endif
2070 return 0;
2071 }
2072 } $options
2073 }
2074 }]
2075 }
2076
2077 # Return 1 if the target supports executing power9 vector instructions, 0
2078 # otherwise. Cache the result.
2079
2080 proc check_p9vector_hw_available { } {
2081 return [check_cached_effective_target p9vector_hw_available {
2082 # Some simulators are known to not support VSX/power8/power9
2083 # instructions. For now, disable on Darwin.
2084 if { [istarget powerpc-*-eabi]
2085 || [istarget powerpc*-*-eabispe]
2086 || [istarget *-*-darwin*]} {
2087 expr 0
2088 } else {
2089 set options "-mpower9-vector"
2090 check_runtime_nocache p9vector_hw_available {
2091 int main()
2092 {
2093 long e = -1;
2094 vector double v = (vector double) { 0.0, 0.0 };
2095 asm ("xsxexpdp %0,%1" : "+r" (e) : "wa" (v));
2096 return e;
2097 }
2098 } $options
2099 }
2100 }]
2101 }
2102
2103 # Return 1 if the target supports executing power9 modulo instructions, 0
2104 # otherwise. Cache the result.
2105
2106 proc check_p9modulo_hw_available { } {
2107 return [check_cached_effective_target p9modulo_hw_available {
2108 # Some simulators are known to not support VSX/power8/power9
2109 # instructions. For now, disable on Darwin.
2110 if { [istarget powerpc-*-eabi]
2111 || [istarget powerpc*-*-eabispe]
2112 || [istarget *-*-darwin*]} {
2113 expr 0
2114 } else {
2115 set options "-mmodulo"
2116 check_runtime_nocache p9modulo_hw_available {
2117 int main()
2118 {
2119 int i = 5, j = 3, r = -1;
2120 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
2121 return (r == 2);
2122 }
2123 } $options
2124 }
2125 }]
2126 }
2127
2128 # Return 1 if the target supports executing __float128 on PowerPC via software
2129 # emulation, 0 otherwise. Cache the result.
2130
2131 proc check_ppc_float128_sw_available { } {
2132 return [check_cached_effective_target ppc_float128_sw_available {
2133 # Some simulators are known to not support VSX/power8/power9
2134 # instructions. For now, disable on Darwin.
2135 if { [istarget powerpc-*-eabi]
2136 || [istarget powerpc*-*-eabispe]
2137 || [istarget *-*-darwin*]} {
2138 expr 0
2139 } else {
2140 set options "-mfloat128 -mvsx"
2141 check_runtime_nocache ppc_float128_sw_available {
2142 volatile __float128 x = 1.0q;
2143 volatile __float128 y = 2.0q;
2144 int main()
2145 {
2146 __float128 z = x + y;
2147 return (z != 3.0q);
2148 }
2149 } $options
2150 }
2151 }]
2152 }
2153
2154 # Return 1 if the target supports executing __float128 on PowerPC via power9
2155 # hardware instructions, 0 otherwise. Cache the result.
2156
2157 proc check_ppc_float128_hw_available { } {
2158 return [check_cached_effective_target ppc_float128_hw_available {
2159 # Some simulators are known to not support VSX/power8/power9
2160 # instructions. For now, disable on Darwin.
2161 if { [istarget powerpc-*-eabi]
2162 || [istarget powerpc*-*-eabispe]
2163 || [istarget *-*-darwin*]} {
2164 expr 0
2165 } else {
2166 set options "-mfloat128 -mvsx -mfloat128-hardware -mpower9-vector"
2167 check_runtime_nocache ppc_float128_hw_available {
2168 volatile __float128 x = 1.0q;
2169 volatile __float128 y = 2.0q;
2170 int main()
2171 {
2172 __float128 z = x + y;
2173 __float128 w = -1.0q;
2174
2175 __asm__ ("xsaddqp %0,%1,%2" : "+v" (w) : "v" (x), "v" (y));
2176 return ((z != 3.0q) || (z != w);
2177 }
2178 } $options
2179 }
2180 }]
2181 }
2182
2183 # Return 1 if the target supports executing VSX instructions, 0
2184 # otherwise. Cache the result.
2185
2186 proc check_vsx_hw_available { } {
2187 return [check_cached_effective_target vsx_hw_available {
2188 # Some simulators are known to not support VSX instructions.
2189 # For now, disable on Darwin
2190 if { [istarget powerpc-*-eabi]
2191 || [istarget powerpc*-*-eabispe]
2192 || [istarget *-*-darwin*]} {
2193 expr 0
2194 } else {
2195 set options "-mvsx"
2196 check_runtime_nocache vsx_hw_available {
2197 int main()
2198 {
2199 #ifdef __MACH__
2200 asm volatile ("xxlor vs0,vs0,vs0");
2201 #else
2202 asm volatile ("xxlor 0,0,0");
2203 #endif
2204 return 0;
2205 }
2206 } $options
2207 }
2208 }]
2209 }
2210
2211 # Return 1 if the target supports executing AltiVec instructions, 0
2212 # otherwise. Cache the result.
2213
2214 proc check_vmx_hw_available { } {
2215 return [check_cached_effective_target vmx_hw_available {
2216 # Some simulators are known to not support VMX instructions.
2217 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2218 expr 0
2219 } else {
2220 # Most targets don't require special flags for this test case, but
2221 # Darwin does. Just to be sure, make sure VSX is not enabled for
2222 # the altivec tests.
2223 if { [istarget *-*-darwin*]
2224 || [istarget *-*-aix*] } {
2225 set options "-maltivec -mno-vsx"
2226 } else {
2227 set options "-mno-vsx"
2228 }
2229 check_runtime_nocache vmx_hw_available {
2230 int main()
2231 {
2232 #ifdef __MACH__
2233 asm volatile ("vor v0,v0,v0");
2234 #else
2235 asm volatile ("vor 0,0,0");
2236 #endif
2237 return 0;
2238 }
2239 } $options
2240 }
2241 }]
2242 }
2243
2244 proc check_ppc_recip_hw_available { } {
2245 return [check_cached_effective_target ppc_recip_hw_available {
2246 # Some simulators may not support FRE/FRES/FRSQRTE/FRSQRTES
2247 # For now, disable on Darwin
2248 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
2249 expr 0
2250 } else {
2251 set options "-mpowerpc-gfxopt -mpowerpc-gpopt -mpopcntb"
2252 check_runtime_nocache ppc_recip_hw_available {
2253 volatile double d_recip, d_rsqrt, d_four = 4.0;
2254 volatile float f_recip, f_rsqrt, f_four = 4.0f;
2255 int main()
2256 {
2257 asm volatile ("fres %0,%1" : "=f" (f_recip) : "f" (f_four));
2258 asm volatile ("fre %0,%1" : "=d" (d_recip) : "d" (d_four));
2259 asm volatile ("frsqrtes %0,%1" : "=f" (f_rsqrt) : "f" (f_four));
2260 asm volatile ("frsqrte %0,%1" : "=f" (d_rsqrt) : "d" (d_four));
2261 return 0;
2262 }
2263 } $options
2264 }
2265 }]
2266 }
2267
2268 # Return 1 if the target supports executing AltiVec and Cell PPU
2269 # instructions, 0 otherwise. Cache the result.
2270
2271 proc check_effective_target_cell_hw { } {
2272 return [check_cached_effective_target cell_hw_available {
2273 # Some simulators are known to not support VMX and PPU instructions.
2274 if { [istarget powerpc-*-eabi*] } {
2275 expr 0
2276 } else {
2277 # Most targets don't require special flags for this test
2278 # case, but Darwin and AIX do.
2279 if { [istarget *-*-darwin*]
2280 || [istarget *-*-aix*] } {
2281 set options "-maltivec -mcpu=cell"
2282 } else {
2283 set options "-mcpu=cell"
2284 }
2285 check_runtime_nocache cell_hw_available {
2286 int main()
2287 {
2288 #ifdef __MACH__
2289 asm volatile ("vor v0,v0,v0");
2290 asm volatile ("lvlx v0,r0,r0");
2291 #else
2292 asm volatile ("vor 0,0,0");
2293 asm volatile ("lvlx 0,0,0");
2294 #endif
2295 return 0;
2296 }
2297 } $options
2298 }
2299 }]
2300 }
2301
2302 # Return 1 if the target supports executing 64-bit instructions, 0
2303 # otherwise. Cache the result.
2304
2305 proc check_effective_target_powerpc64 { } {
2306 global powerpc64_available_saved
2307 global tool
2308
2309 if [info exists powerpc64_available_saved] {
2310 verbose "check_effective_target_powerpc64 returning saved $powerpc64_available_saved" 2
2311 } else {
2312 set powerpc64_available_saved 0
2313
2314 # Some simulators are known to not support powerpc64 instructions.
2315 if { [istarget powerpc-*-eabi*] || [istarget powerpc-ibm-aix*] } {
2316 verbose "check_effective_target_powerpc64 returning 0" 2
2317 return $powerpc64_available_saved
2318 }
2319
2320 # Set up, compile, and execute a test program containing a 64-bit
2321 # instruction. Include the current process ID in the file
2322 # names to prevent conflicts with invocations for multiple
2323 # testsuites.
2324 set src ppc[pid].c
2325 set exe ppc[pid].x
2326
2327 set f [open $src "w"]
2328 puts $f "int main() {"
2329 puts $f "#ifdef __MACH__"
2330 puts $f " asm volatile (\"extsw r0,r0\");"
2331 puts $f "#else"
2332 puts $f " asm volatile (\"extsw 0,0\");"
2333 puts $f "#endif"
2334 puts $f " return 0; }"
2335 close $f
2336
2337 set opts "additional_flags=-mcpu=G5"
2338
2339 verbose "check_effective_target_powerpc64 compiling testfile $src" 2
2340 set lines [${tool}_target_compile $src $exe executable "$opts"]
2341 file delete $src
2342
2343 if [string match "" $lines] then {
2344 # No error message, compilation succeeded.
2345 set result [${tool}_load "./$exe" "" ""]
2346 set status [lindex $result 0]
2347 remote_file build delete $exe
2348 verbose "check_effective_target_powerpc64 testfile status is <$status>" 2
2349
2350 if { $status == "pass" } then {
2351 set powerpc64_available_saved 1
2352 }
2353 } else {
2354 verbose "check_effective_target_powerpc64 testfile compilation failed" 2
2355 }
2356 }
2357
2358 return $powerpc64_available_saved
2359 }
2360
2361 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
2362 # complex float arguments. This affects gfortran tests that call cabsf
2363 # in libm built by an earlier compiler. Return 0 if libm uses the same
2364 # argument passing as the compiler under test, 1 otherwise.
2365
2366 proc check_effective_target_broken_cplxf_arg { } {
2367 # Skip the work for targets known not to be affected.
2368 if { ![istarget powerpc*-*-linux*] || ![is-effective-target lp64] } {
2369 return 0
2370 }
2371
2372 return [check_cached_effective_target broken_cplxf_arg {
2373 check_runtime_nocache broken_cplxf_arg {
2374 #include <complex.h>
2375 extern void abort (void);
2376 float fabsf (float);
2377 float cabsf (_Complex float);
2378 int main ()
2379 {
2380 _Complex float cf;
2381 float f;
2382 cf = 3 + 4.0fi;
2383 f = cabsf (cf);
2384 if (fabsf (f - 5.0) > 0.0001)
2385 /* Yes, it's broken. */
2386 return 0;
2387 /* All fine, not broken. */
2388 return 1;
2389 }
2390 } "-lm"
2391 }]
2392 }
2393
2394 # Return 1 is this is a TI C6X target supporting C67X instructions
2395 proc check_effective_target_ti_c67x { } {
2396 return [check_no_compiler_messages ti_c67x assembly {
2397 #if !defined(_TMS320C6700)
2398 #error !_TMS320C6700
2399 #endif
2400 }]
2401 }
2402
2403 # Return 1 is this is a TI C6X target supporting C64X+ instructions
2404 proc check_effective_target_ti_c64xp { } {
2405 return [check_no_compiler_messages ti_c64xp assembly {
2406 #if !defined(_TMS320C6400_PLUS)
2407 #error !_TMS320C6400_PLUS
2408 #endif
2409 }]
2410 }
2411
2412
2413 proc check_alpha_max_hw_available { } {
2414 return [check_runtime alpha_max_hw_available {
2415 int main() { return __builtin_alpha_amask(1<<8) != 0; }
2416 }]
2417 }
2418
2419 # Returns true iff the FUNCTION is available on the target system.
2420 # (This is essentially a Tcl implementation of Autoconf's
2421 # AC_CHECK_FUNC.)
2422
2423 proc check_function_available { function } {
2424 return [check_no_compiler_messages ${function}_available \
2425 executable [subst {
2426 #ifdef __cplusplus
2427 extern "C"
2428 #endif
2429 char $function ();
2430 int main () { $function (); }
2431 }] "-fno-builtin" ]
2432 }
2433
2434 # Returns true iff "fork" is available on the target system.
2435
2436 proc check_fork_available {} {
2437 return [check_function_available "fork"]
2438 }
2439
2440 # Returns true iff "mkfifo" is available on the target system.
2441
2442 proc check_mkfifo_available {} {
2443 if { [istarget *-*-cygwin*] } {
2444 # Cygwin has mkfifo, but support is incomplete.
2445 return 0
2446 }
2447
2448 return [check_function_available "mkfifo"]
2449 }
2450
2451 # Returns true iff "__cxa_atexit" is used on the target system.
2452
2453 proc check_cxa_atexit_available { } {
2454 return [check_cached_effective_target cxa_atexit_available {
2455 if { [istarget hppa*-*-hpux10*] } {
2456 # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
2457 expr 0
2458 } elseif { [istarget *-*-vxworks] } {
2459 # vxworks doesn't have __cxa_atexit but subsequent test passes.
2460 expr 0
2461 } else {
2462 check_runtime_nocache cxa_atexit_available {
2463 // C++
2464 #include <stdlib.h>
2465 static unsigned int count;
2466 struct X
2467 {
2468 X() { count = 1; }
2469 ~X()
2470 {
2471 if (count != 3)
2472 exit(1);
2473 count = 4;
2474 }
2475 };
2476 void f()
2477 {
2478 static X x;
2479 }
2480 struct Y
2481 {
2482 Y() { f(); count = 2; }
2483 ~Y()
2484 {
2485 if (count != 2)
2486 exit(1);
2487 count = 3;
2488 }
2489 };
2490 Y y;
2491 int main() { return 0; }
2492 }
2493 }
2494 }]
2495 }
2496
2497 proc check_effective_target_objc2 { } {
2498 return [check_no_compiler_messages objc2 object {
2499 #ifdef __OBJC2__
2500 int dummy[1];
2501 #else
2502 #error !__OBJC2__
2503 #endif
2504 }]
2505 }
2506
2507 proc check_effective_target_next_runtime { } {
2508 return [check_no_compiler_messages objc2 object {
2509 #ifdef __NEXT_RUNTIME__
2510 int dummy[1];
2511 #else
2512 #error !__NEXT_RUNTIME__
2513 #endif
2514 }]
2515 }
2516
2517 # Return 1 if we're generating 32-bit code using default options, 0
2518 # otherwise.
2519
2520 proc check_effective_target_ilp32 { } {
2521 return [check_no_compiler_messages ilp32 object {
2522 int dummy[sizeof (int) == 4
2523 && sizeof (void *) == 4
2524 && sizeof (long) == 4 ? 1 : -1];
2525 }]
2526 }
2527
2528 # Return 1 if we're generating ia32 code using default options, 0
2529 # otherwise.
2530
2531 proc check_effective_target_ia32 { } {
2532 return [check_no_compiler_messages ia32 object {
2533 int dummy[sizeof (int) == 4
2534 && sizeof (void *) == 4
2535 && sizeof (long) == 4 ? 1 : -1] = { __i386__ };
2536 }]
2537 }
2538
2539 # Return 1 if we're generating x32 code using default options, 0
2540 # otherwise.
2541
2542 proc check_effective_target_x32 { } {
2543 return [check_no_compiler_messages x32 object {
2544 int dummy[sizeof (int) == 4
2545 && sizeof (void *) == 4
2546 && sizeof (long) == 4 ? 1 : -1] = { __x86_64__ };
2547 }]
2548 }
2549
2550 # Return 1 if we're generating 32-bit integers using default
2551 # options, 0 otherwise.
2552
2553 proc check_effective_target_int32 { } {
2554 return [check_no_compiler_messages int32 object {
2555 int dummy[sizeof (int) == 4 ? 1 : -1];
2556 }]
2557 }
2558
2559 # Return 1 if we're generating 32-bit or larger integers using default
2560 # options, 0 otherwise.
2561
2562 proc check_effective_target_int32plus { } {
2563 return [check_no_compiler_messages int32plus object {
2564 int dummy[sizeof (int) >= 4 ? 1 : -1];
2565 }]
2566 }
2567
2568 # Return 1 if we're generating 32-bit or larger pointers using default
2569 # options, 0 otherwise.
2570
2571 proc check_effective_target_ptr32plus { } {
2572 # The msp430 has 16-bit or 20-bit pointers. The 20-bit pointer is stored
2573 # in a 32-bit slot when in memory, so sizeof(void *) returns 4, but it
2574 # cannot really hold a 32-bit address, so we always return false here.
2575 if { [istarget msp430-*-*] } {
2576 return 0
2577 }
2578
2579 return [check_no_compiler_messages ptr32plus object {
2580 int dummy[sizeof (void *) >= 4 ? 1 : -1];
2581 }]
2582 }
2583
2584 # Return 1 if we support 32-bit or larger array and structure sizes
2585 # using default options, 0 otherwise. Avoid false positive on
2586 # targets with 20 or 24 bit address spaces.
2587
2588 proc check_effective_target_size32plus { } {
2589 return [check_no_compiler_messages size32plus object {
2590 char dummy[16777217L];
2591 }]
2592 }
2593
2594 # Returns 1 if we're generating 16-bit or smaller integers with the
2595 # default options, 0 otherwise.
2596
2597 proc check_effective_target_int16 { } {
2598 return [check_no_compiler_messages int16 object {
2599 int dummy[sizeof (int) < 4 ? 1 : -1];
2600 }]
2601 }
2602
2603 # Return 1 if we're generating 64-bit code using default options, 0
2604 # otherwise.
2605
2606 proc check_effective_target_lp64 { } {
2607 return [check_no_compiler_messages lp64 object {
2608 int dummy[sizeof (int) == 4
2609 && sizeof (void *) == 8
2610 && sizeof (long) == 8 ? 1 : -1];
2611 }]
2612 }
2613
2614 # Return 1 if we're generating 64-bit code using default llp64 options,
2615 # 0 otherwise.
2616
2617 proc check_effective_target_llp64 { } {
2618 return [check_no_compiler_messages llp64 object {
2619 int dummy[sizeof (int) == 4
2620 && sizeof (void *) == 8
2621 && sizeof (long long) == 8
2622 && sizeof (long) == 4 ? 1 : -1];
2623 }]
2624 }
2625
2626 # Return 1 if long and int have different sizes,
2627 # 0 otherwise.
2628
2629 proc check_effective_target_long_neq_int { } {
2630 return [check_no_compiler_messages long_ne_int object {
2631 int dummy[sizeof (int) != sizeof (long) ? 1 : -1];
2632 }]
2633 }
2634
2635 # Return 1 if the target supports long double larger than double,
2636 # 0 otherwise.
2637
2638 proc check_effective_target_large_long_double { } {
2639 return [check_no_compiler_messages large_long_double object {
2640 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
2641 }]
2642 }
2643
2644 # Return 1 if the target supports double larger than float,
2645 # 0 otherwise.
2646
2647 proc check_effective_target_large_double { } {
2648 return [check_no_compiler_messages large_double object {
2649 int dummy[sizeof(double) > sizeof(float) ? 1 : -1];
2650 }]
2651 }
2652
2653 # Return 1 if the target supports long double of 128 bits,
2654 # 0 otherwise.
2655
2656 proc check_effective_target_longdouble128 { } {
2657 return [check_no_compiler_messages longdouble128 object {
2658 int dummy[sizeof(long double) == 16 ? 1 : -1];
2659 }]
2660 }
2661
2662 # Return 1 if the target supports double of 64 bits,
2663 # 0 otherwise.
2664
2665 proc check_effective_target_double64 { } {
2666 return [check_no_compiler_messages double64 object {
2667 int dummy[sizeof(double) == 8 ? 1 : -1];
2668 }]
2669 }
2670
2671 # Return 1 if the target supports double of at least 64 bits,
2672 # 0 otherwise.
2673
2674 proc check_effective_target_double64plus { } {
2675 return [check_no_compiler_messages double64plus object {
2676 int dummy[sizeof(double) >= 8 ? 1 : -1];
2677 }]
2678 }
2679
2680 # Return 1 if the target supports 'w' suffix on floating constant
2681 # 0 otherwise.
2682
2683 proc check_effective_target_has_w_floating_suffix { } {
2684 set opts ""
2685 if [check_effective_target_c++] {
2686 append opts "-std=gnu++03"
2687 }
2688 return [check_no_compiler_messages w_fp_suffix object {
2689 float dummy = 1.0w;
2690 } "$opts"]
2691 }
2692
2693 # Return 1 if the target supports 'q' suffix on floating constant
2694 # 0 otherwise.
2695
2696 proc check_effective_target_has_q_floating_suffix { } {
2697 set opts ""
2698 if [check_effective_target_c++] {
2699 append opts "-std=gnu++03"
2700 }
2701 return [check_no_compiler_messages q_fp_suffix object {
2702 float dummy = 1.0q;
2703 } "$opts"]
2704 }
2705
2706 # Return 1 if the target supports the _FloatN / _FloatNx type
2707 # indicated in the function name, 0 otherwise.
2708
2709 proc check_effective_target_float16 {} {
2710 return [check_no_compiler_messages_nocache float16 object {
2711 _Float16 x;
2712 } [add_options_for_float16 ""]]
2713 }
2714
2715 proc check_effective_target_float32 {} {
2716 return [check_no_compiler_messages_nocache float32 object {
2717 _Float32 x;
2718 } [add_options_for_float32 ""]]
2719 }
2720
2721 proc check_effective_target_float64 {} {
2722 return [check_no_compiler_messages_nocache float64 object {
2723 _Float64 x;
2724 } [add_options_for_float64 ""]]
2725 }
2726
2727 proc check_effective_target_float128 {} {
2728 return [check_no_compiler_messages_nocache float128 object {
2729 _Float128 x;
2730 } [add_options_for_float128 ""]]
2731 }
2732
2733 proc check_effective_target_float32x {} {
2734 return [check_no_compiler_messages_nocache float32x object {
2735 _Float32x x;
2736 } [add_options_for_float32x ""]]
2737 }
2738
2739 proc check_effective_target_float64x {} {
2740 return [check_no_compiler_messages_nocache float64x object {
2741 _Float64x x;
2742 } [add_options_for_float64x ""]]
2743 }
2744
2745 proc check_effective_target_float128x {} {
2746 return [check_no_compiler_messages_nocache float128x object {
2747 _Float128x x;
2748 } [add_options_for_float128x ""]]
2749 }
2750
2751 # Likewise, but runtime support for any special options used as well
2752 # as compile-time support is required.
2753
2754 proc check_effective_target_float16_runtime {} {
2755 return [check_effective_target_float16]
2756 }
2757
2758 proc check_effective_target_float32_runtime {} {
2759 return [check_effective_target_float32]
2760 }
2761
2762 proc check_effective_target_float64_runtime {} {
2763 return [check_effective_target_float64]
2764 }
2765
2766 proc check_effective_target_float128_runtime {} {
2767 if { ![check_effective_target_float128] } {
2768 return 0
2769 }
2770 if { [istarget powerpc*-*-*] } {
2771 return [check_effective_target_base_quadfloat_support]
2772 }
2773 return 1
2774 }
2775
2776 proc check_effective_target_float32x_runtime {} {
2777 return [check_effective_target_float32x]
2778 }
2779
2780 proc check_effective_target_float64x_runtime {} {
2781 if { ![check_effective_target_float64x] } {
2782 return 0
2783 }
2784 if { [istarget powerpc*-*-*] } {
2785 return [check_effective_target_base_quadfloat_support]
2786 }
2787 return 1
2788 }
2789
2790 proc check_effective_target_float128x_runtime {} {
2791 return [check_effective_target_float128x]
2792 }
2793
2794 # Return 1 if the target hardware supports any options added for
2795 # _FloatN and _FloatNx types, 0 otherwise.
2796
2797 proc check_effective_target_floatn_nx_runtime {} {
2798 if { [istarget powerpc*-*-aix*] } {
2799 return 0
2800 }
2801 if { [istarget powerpc*-*-*] } {
2802 return [check_effective_target_base_quadfloat_support]
2803 }
2804 return 1
2805 }
2806
2807 # Add options needed to use the _FloatN / _FloatNx type indicated in
2808 # the function name.
2809
2810 proc add_options_for_float16 { flags } {
2811 if { [istarget arm*-*-*] } {
2812 return "$flags -mfp16-format=ieee"
2813 }
2814 return "$flags"
2815 }
2816
2817 proc add_options_for_float32 { flags } {
2818 return "$flags"
2819 }
2820
2821 proc add_options_for_float64 { flags } {
2822 return "$flags"
2823 }
2824
2825 proc add_options_for_float128 { flags } {
2826 return [add_options_for___float128 "$flags"]
2827 }
2828
2829 proc add_options_for_float32x { flags } {
2830 return "$flags"
2831 }
2832
2833 proc add_options_for_float64x { flags } {
2834 return [add_options_for___float128 "$flags"]
2835 }
2836
2837 proc add_options_for_float128x { flags } {
2838 return "$flags"
2839 }
2840
2841 # Return 1 if the target supports __float128,
2842 # 0 otherwise.
2843
2844 proc check_effective_target___float128 { } {
2845 if { [istarget powerpc*-*-*] } {
2846 return [check_ppc_float128_sw_available]
2847 }
2848 if { [istarget ia64-*-*]
2849 || [istarget i?86-*-*] || [istarget x86_64-*-*] } {
2850 return 1
2851 }
2852 return 0
2853 }
2854
2855 proc add_options_for___float128 { flags } {
2856 if { [istarget powerpc*-*-*] } {
2857 return "$flags -mfloat128 -mvsx"
2858 }
2859 return "$flags"
2860 }
2861
2862 # Return 1 if the target supports any special run-time requirements
2863 # for __float128 or _Float128,
2864 # 0 otherwise.
2865
2866 proc check_effective_target_base_quadfloat_support { } {
2867 if { [istarget powerpc*-*-*] } {
2868 return [check_vsx_hw_available]
2869 }
2870 return 1
2871 }
2872
2873 # Return 1 if the target supports compiling fixed-point,
2874 # 0 otherwise.
2875
2876 proc check_effective_target_fixed_point { } {
2877 return [check_no_compiler_messages fixed_point object {
2878 _Sat _Fract x; _Sat _Accum y;
2879 }]
2880 }
2881
2882 # Return 1 if the target supports compiling decimal floating point,
2883 # 0 otherwise.
2884
2885 proc check_effective_target_dfp_nocache { } {
2886 verbose "check_effective_target_dfp_nocache: compiling source" 2
2887 set ret [check_no_compiler_messages_nocache dfp object {
2888 float x __attribute__((mode(DD)));
2889 }]
2890 verbose "check_effective_target_dfp_nocache: returning $ret" 2
2891 return $ret
2892 }
2893
2894 proc check_effective_target_dfprt_nocache { } {
2895 return [check_runtime_nocache dfprt {
2896 typedef float d64 __attribute__((mode(DD)));
2897 d64 x = 1.2df, y = 2.3dd, z;
2898 int main () { z = x + y; return 0; }
2899 }]
2900 }
2901
2902 # Return 1 if the target supports compiling Decimal Floating Point,
2903 # 0 otherwise.
2904 #
2905 # This won't change for different subtargets so cache the result.
2906
2907 proc check_effective_target_dfp { } {
2908 return [check_cached_effective_target dfp {
2909 check_effective_target_dfp_nocache
2910 }]
2911 }
2912
2913 # Return 1 if the target supports linking and executing Decimal Floating
2914 # Point, 0 otherwise.
2915 #
2916 # This won't change for different subtargets so cache the result.
2917
2918 proc check_effective_target_dfprt { } {
2919 return [check_cached_effective_target dfprt {
2920 check_effective_target_dfprt_nocache
2921 }]
2922 }
2923
2924 proc check_effective_target_powerpc_popcntb_ok { } {
2925 return [check_cached_effective_target powerpc_popcntb_ok {
2926
2927 # Disable on Darwin.
2928 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
2929 expr 0
2930 } else {
2931 check_runtime_nocache powerpc_popcntb_ok {
2932 volatile int r;
2933 volatile int a = 0x12345678;
2934 int main()
2935 {
2936 asm volatile ("popcntb %0,%1" : "=r" (r) : "r" (a));
2937 return 0;
2938 }
2939 } "-mcpu=power5"
2940 }
2941 }]
2942 }
2943
2944 # Return 1 if the target supports executing DFP hardware instructions,
2945 # 0 otherwise. Cache the result.
2946
2947 proc check_dfp_hw_available { } {
2948 return [check_cached_effective_target dfp_hw_available {
2949 # For now, disable on Darwin
2950 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
2951 expr 0
2952 } else {
2953 check_runtime_nocache dfp_hw_available {
2954 volatile _Decimal64 r;
2955 volatile _Decimal64 a = 4.0DD;
2956 volatile _Decimal64 b = 2.0DD;
2957 int main()
2958 {
2959 asm volatile ("dadd %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
2960 asm volatile ("dsub %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
2961 asm volatile ("dmul %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
2962 asm volatile ("ddiv %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
2963 return 0;
2964 }
2965 } "-mcpu=power6 -mhard-float"
2966 }
2967 }]
2968 }
2969
2970 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
2971
2972 proc check_effective_target_ucn_nocache { } {
2973 # -std=c99 is only valid for C
2974 if [check_effective_target_c] {
2975 set ucnopts "-std=c99"
2976 } else {
2977 set ucnopts ""
2978 }
2979 verbose "check_effective_target_ucn_nocache: compiling source" 2
2980 set ret [check_no_compiler_messages_nocache ucn object {
2981 int \u00C0;
2982 } $ucnopts]
2983 verbose "check_effective_target_ucn_nocache: returning $ret" 2
2984 return $ret
2985 }
2986
2987 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
2988 #
2989 # This won't change for different subtargets, so cache the result.
2990
2991 proc check_effective_target_ucn { } {
2992 return [check_cached_effective_target ucn {
2993 check_effective_target_ucn_nocache
2994 }]
2995 }
2996
2997 # Return 1 if the target needs a command line argument to enable a SIMD
2998 # instruction set.
2999
3000 proc check_effective_target_vect_cmdline_needed { } {
3001 global et_vect_cmdline_needed_saved
3002 global et_vect_cmdline_needed_target_name
3003
3004 if { ![info exists et_vect_cmdline_needed_target_name] } {
3005 set et_vect_cmdline_needed_target_name ""
3006 }
3007
3008 # If the target has changed since we set the cached value, clear it.
3009 set current_target [current_target_name]
3010 if { $current_target != $et_vect_cmdline_needed_target_name } {
3011 verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
3012 set et_vect_cmdline_needed_target_name $current_target
3013 if { [info exists et_vect_cmdline_needed_saved] } {
3014 verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
3015 unset et_vect_cmdline_needed_saved
3016 }
3017 }
3018
3019 if [info exists et_vect_cmdline_needed_saved] {
3020 verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
3021 } else {
3022 set et_vect_cmdline_needed_saved 1
3023 if { [istarget alpha*-*-*]
3024 || [istarget ia64-*-*]
3025 || (([istarget i?86-*-*] || [istarget x86_64-*-*])
3026 && ![is-effective-target ia32])
3027 || ([istarget powerpc*-*-*]
3028 && ([check_effective_target_powerpc_spe]
3029 || [check_effective_target_powerpc_altivec]))
3030 || ([istarget sparc*-*-*] && [check_effective_target_sparc_vis])
3031 || [istarget spu-*-*]
3032 || ([istarget arm*-*-*] && [check_effective_target_arm_neon])
3033 || [istarget aarch64*-*-*] } {
3034 set et_vect_cmdline_needed_saved 0
3035 }
3036 }
3037
3038 verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
3039 return $et_vect_cmdline_needed_saved
3040 }
3041
3042 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
3043 #
3044 # This won't change for different subtargets so cache the result.
3045
3046 proc check_effective_target_vect_int { } {
3047 global et_vect_int_saved
3048 global et_index
3049
3050 if [info exists et_vect_int_saved($et_index)] {
3051 verbose "check_effective_target_vect_int: using cached result" 2
3052 } else {
3053 set et_vect_int_saved($et_index) 0
3054 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
3055 || ([istarget powerpc*-*-*]
3056 && ![istarget powerpc-*-linux*paired*])
3057 || [istarget spu-*-*]
3058 || [istarget sparc*-*-*]
3059 || [istarget alpha*-*-*]
3060 || [istarget ia64-*-*]
3061 || [istarget aarch64*-*-*]
3062 || [is-effective-target arm_neon]
3063 || ([istarget mips*-*-*]
3064 && ([et-is-effective-target mips_loongson]
3065 || [et-is-effective-target mips_msa])) } {
3066 set et_vect_int_saved($et_index) 1
3067 }
3068 }
3069
3070 verbose "check_effective_target_vect_int:\
3071 returning $et_vect_int_saved($et_index)" 2
3072 return $et_vect_int_saved($et_index)
3073 }
3074
3075 # Return 1 if the target supports signed int->float conversion
3076 #
3077
3078 proc check_effective_target_vect_intfloat_cvt { } {
3079 global et_vect_intfloat_cvt_saved
3080 global et_index
3081
3082 if [info exists et_vect_intfloat_cvt_saved($et_index)] {
3083 verbose "check_effective_target_vect_intfloat_cvt:\
3084 using cached result" 2
3085 } else {
3086 set et_vect_intfloat_cvt_saved($et_index) 0
3087 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
3088 || ([istarget powerpc*-*-*]
3089 && ![istarget powerpc-*-linux*paired*])
3090 || [is-effective-target arm_neon]
3091 || ([istarget mips*-*-*]
3092 && [et-is-effective-target mips_msa]) } {
3093 set et_vect_intfloat_cvt_saved($et_index) 1
3094 }
3095 }
3096
3097 verbose "check_effective_target_vect_intfloat_cvt:\
3098 returning $et_vect_intfloat_cvt_saved($et_index)" 2
3099 return $et_vect_intfloat_cvt_saved($et_index)
3100 }
3101
3102 #Return 1 if we're supporting __int128 for target, 0 otherwise.
3103
3104 proc check_effective_target_int128 { } {
3105 return [check_no_compiler_messages int128 object {
3106 int dummy[
3107 #ifndef __SIZEOF_INT128__
3108 -1
3109 #else
3110 1
3111 #endif
3112 ];
3113 }]
3114 }
3115
3116 # Return 1 if the target supports unsigned int->float conversion
3117 #
3118
3119 proc check_effective_target_vect_uintfloat_cvt { } {
3120 global et_vect_uintfloat_cvt_saved
3121 global et_index
3122
3123 if [info exists et_vect_uintfloat_cvt_saved($et_index)] {
3124 verbose "check_effective_target_vect_uintfloat_cvt:\
3125 using cached result" 2
3126 } else {
3127 set et_vect_uintfloat_cvt_saved($et_index) 0
3128 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
3129 || ([istarget powerpc*-*-*]
3130 && ![istarget powerpc-*-linux*paired*])
3131 || [istarget aarch64*-*-*]
3132 || [is-effective-target arm_neon]
3133 || ([istarget mips*-*-*]
3134 && [et-is-effective-target mips_msa]) } {
3135 set et_vect_uintfloat_cvt_saved($et_index) 1
3136 }
3137 }
3138
3139 verbose "check_effective_target_vect_uintfloat_cvt:\
3140 returning $et_vect_uintfloat_cvt_saved($et_index)" 2
3141 return $et_vect_uintfloat_cvt_saved($et_index)
3142 }
3143
3144
3145 # Return 1 if the target supports signed float->int conversion
3146 #
3147
3148 proc check_effective_target_vect_floatint_cvt { } {
3149 global et_vect_floatint_cvt_saved
3150 global et_index
3151
3152 if [info exists et_vect_floatint_cvt_saved($et_index)] {
3153 verbose "check_effective_target_vect_floatint_cvt:\
3154 using cached result" 2
3155 } else {
3156 set et_vect_floatint_cvt_saved($et_index) 0
3157 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
3158 || ([istarget powerpc*-*-*]
3159 && ![istarget powerpc-*-linux*paired*])
3160 || [is-effective-target arm_neon]
3161 || ([istarget mips*-*-*]
3162 && [et-is-effective-target mips_msa]) } {
3163 set et_vect_floatint_cvt_saved($et_index) 1
3164 }
3165 }
3166
3167 verbose "check_effective_target_vect_floatint_cvt:\
3168 returning $et_vect_floatint_cvt_saved($et_index)" 2
3169 return $et_vect_floatint_cvt_saved($et_index)
3170 }
3171
3172 # Return 1 if the target supports unsigned float->int conversion
3173 #
3174
3175 proc check_effective_target_vect_floatuint_cvt { } {
3176 global et_vect_floatuint_cvt_saved
3177 global et_index
3178
3179 if [info exists et_vect_floatuint_cvt_saved($et_index)] {
3180 verbose "check_effective_target_vect_floatuint_cvt:\
3181 using cached result" 2
3182 } else {
3183 set et_vect_floatuint_cvt_saved($et_index) 0
3184 if { ([istarget powerpc*-*-*]
3185 && ![istarget powerpc-*-linux*paired*])
3186 || [is-effective-target arm_neon]
3187 || ([istarget mips*-*-*]
3188 && [et-is-effective-target mips_msa]) } {
3189 set et_vect_floatuint_cvt_saved($et_index) 1
3190 }
3191 }
3192
3193 verbose "check_effective_target_vect_floatuint_cvt:\
3194 returning $et_vect_floatuint_cvt_saved($et_index)" 2
3195 return $et_vect_floatuint_cvt_saved($et_index)
3196 }
3197
3198 # Return 1 if the target supports #pragma omp declare simd, 0 otherwise.
3199 #
3200 # This won't change for different subtargets so cache the result.
3201
3202 proc check_effective_target_vect_simd_clones { } {
3203 global et_vect_simd_clones_saved
3204 global et_index
3205
3206 if [info exists et_vect_simd_clones_saved($et_index)] {
3207 verbose "check_effective_target_vect_simd_clones: using cached result" 2
3208 } else {
3209 set et_vect_simd_clones_saved($et_index) 0
3210 # On i?86/x86_64 #pragma omp declare simd builds a sse2, avx,
3211 # avx2 and avx512f clone. Only the right clone for the
3212 # specified arch will be chosen, but still we need to at least
3213 # be able to assemble avx512f.
3214 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
3215 && [check_effective_target_avx512f]) } {
3216 set et_vect_simd_clones_saved($et_index) 1
3217 }
3218 }
3219
3220 verbose "check_effective_target_vect_simd_clones:\
3221 returning $et_vect_simd_clones_saved($et_index)" 2
3222 return $et_vect_simd_clones_saved($et_index)
3223 }
3224
3225 # Return 1 if this is a AArch64 target supporting big endian
3226 proc check_effective_target_aarch64_big_endian { } {
3227 return [check_no_compiler_messages aarch64_big_endian assembly {
3228 #if !defined(__aarch64__) || !defined(__AARCH64EB__)
3229 #error !__aarch64__ || !__AARCH64EB__
3230 #endif
3231 }]
3232 }
3233
3234 # Return 1 if this is a AArch64 target supporting little endian
3235 proc check_effective_target_aarch64_little_endian { } {
3236 if { ![istarget aarch64*-*-*] } {
3237 return 0
3238 }
3239
3240 return [check_no_compiler_messages aarch64_little_endian assembly {
3241 #if !defined(__aarch64__) || defined(__AARCH64EB__)
3242 #error FOO
3243 #endif
3244 }]
3245 }
3246
3247 # Return 1 if this is a compiler supporting ARC atomic operations
3248 proc check_effective_target_arc_atomic { } {
3249 return [check_no_compiler_messages arc_atomic assembly {
3250 #if !defined(__ARC_ATOMIC__)
3251 #error FOO
3252 #endif
3253 }]
3254 }
3255
3256 # Return 1 if this is an arm target using 32-bit instructions
3257 proc check_effective_target_arm32 { } {
3258 if { ![istarget arm*-*-*] } {
3259 return 0
3260 }
3261
3262 return [check_no_compiler_messages arm32 assembly {
3263 #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
3264 #error !__arm || __thumb__ && !__thumb2__
3265 #endif
3266 }]
3267 }
3268
3269 # Return 1 if this is an arm target not using Thumb
3270 proc check_effective_target_arm_nothumb { } {
3271 if { ![istarget arm*-*-*] } {
3272 return 0
3273 }
3274
3275 return [check_no_compiler_messages arm_nothumb assembly {
3276 #if !defined(__arm__) || (defined(__thumb__) || defined(__thumb2__))
3277 #error !__arm__ || __thumb || __thumb2__
3278 #endif
3279 }]
3280 }
3281
3282 # Return 1 if this is a little-endian ARM target
3283 proc check_effective_target_arm_little_endian { } {
3284 if { ![istarget arm*-*-*] } {
3285 return 0
3286 }
3287
3288 return [check_no_compiler_messages arm_little_endian assembly {
3289 #if !defined(__arm__) || !defined(__ARMEL__)
3290 #error !__arm__ || !__ARMEL__
3291 #endif
3292 }]
3293 }
3294
3295 # Return 1 if this is an ARM target that only supports aligned vector accesses
3296 proc check_effective_target_arm_vect_no_misalign { } {
3297 if { ![istarget arm*-*-*] } {
3298 return 0
3299 }
3300
3301 return [check_no_compiler_messages arm_vect_no_misalign assembly {
3302 #if !defined(__arm__) \
3303 || (defined(__ARM_FEATURE_UNALIGNED) \
3304 && defined(__ARMEL__))
3305 #error !__arm__ || (__ARMEL__ && __ARM_FEATURE_UNALIGNED)
3306 #endif
3307 }]
3308 }
3309
3310
3311 # Return 1 if this is an ARM target supporting -mfpu=vfp
3312 # -mfloat-abi=softfp. Some multilibs may be incompatible with these
3313 # options.
3314
3315 proc check_effective_target_arm_vfp_ok { } {
3316 if { [check_effective_target_arm32] } {
3317 return [check_no_compiler_messages arm_vfp_ok object {
3318 int dummy;
3319 } "-mfpu=vfp -mfloat-abi=softfp"]
3320 } else {
3321 return 0
3322 }
3323 }
3324
3325 # Return 1 if this is an ARM target supporting -mfpu=vfp3
3326 # -mfloat-abi=softfp.
3327
3328 proc check_effective_target_arm_vfp3_ok { } {
3329 if { [check_effective_target_arm32] } {
3330 return [check_no_compiler_messages arm_vfp3_ok object {
3331 int dummy;
3332 } "-mfpu=vfp3 -mfloat-abi=softfp"]
3333 } else {
3334 return 0
3335 }
3336 }
3337
3338 # Return 1 if this is an ARM target supporting -mfpu=fp-armv8
3339 # -mfloat-abi=softfp.
3340 proc check_effective_target_arm_v8_vfp_ok {} {
3341 if { [check_effective_target_arm32] } {
3342 return [check_no_compiler_messages arm_v8_vfp_ok object {
3343 int foo (void)
3344 {
3345 __asm__ volatile ("vrinta.f32.f32 s0, s0");
3346 return 0;
3347 }
3348 } "-mfpu=fp-armv8 -mfloat-abi=softfp"]
3349 } else {
3350 return 0
3351 }
3352 }
3353
3354 # Return 1 if this is an ARM target supporting -mfpu=vfp
3355 # -mfloat-abi=hard. Some multilibs may be incompatible with these
3356 # options.
3357
3358 proc check_effective_target_arm_hard_vfp_ok { } {
3359 if { [check_effective_target_arm32]
3360 && ! [check-flags [list "" { *-*-* } { "-mfloat-abi=*" } { "-mfloat-abi=hard" }]] } {
3361 return [check_no_compiler_messages arm_hard_vfp_ok executable {
3362 int main() { return 0;}
3363 } "-mfpu=vfp -mfloat-abi=hard"]
3364 } else {
3365 return 0
3366 }
3367 }
3368
3369 # Return 1 if this is an ARM target defining __ARM_FP. We may need
3370 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3371 # incompatible with these options. Also set et_arm_fp_flags to the
3372 # best options to add.
3373
3374 proc check_effective_target_arm_fp_ok_nocache { } {
3375 global et_arm_fp_flags
3376 set et_arm_fp_flags ""
3377 if { [check_effective_target_arm32] } {
3378 foreach flags {"" "-mfloat-abi=softfp" "-mfloat-abi=hard"} {
3379 if { [check_no_compiler_messages_nocache arm_fp_ok object {
3380 #ifndef __ARM_FP
3381 #error __ARM_FP not defined
3382 #endif
3383 } "$flags"] } {
3384 set et_arm_fp_flags $flags
3385 return 1
3386 }
3387 }
3388 }
3389
3390 return 0
3391 }
3392
3393 proc check_effective_target_arm_fp_ok { } {
3394 return [check_cached_effective_target arm_fp_ok \
3395 check_effective_target_arm_fp_ok_nocache]
3396 }
3397
3398 # Add the options needed to define __ARM_FP. We need either
3399 # -mfloat-abi=softfp or -mfloat-abi=hard, but if one is already
3400 # specified by the multilib, use it.
3401
3402 proc add_options_for_arm_fp { flags } {
3403 if { ! [check_effective_target_arm_fp_ok] } {
3404 return "$flags"
3405 }
3406 global et_arm_fp_flags
3407 return "$flags $et_arm_fp_flags"
3408 }
3409
3410 # Return 1 if this is an ARM target that supports DSP multiply with
3411 # current multilib flags.
3412
3413 proc check_effective_target_arm_dsp { } {
3414 return [check_no_compiler_messages arm_dsp assembly {
3415 #ifndef __ARM_FEATURE_DSP
3416 #error not DSP
3417 #endif
3418 int i;
3419 }]
3420 }
3421
3422 # Return 1 if this is an ARM target that supports unaligned word/halfword
3423 # load/store instructions.
3424
3425 proc check_effective_target_arm_unaligned { } {
3426 return [check_no_compiler_messages arm_unaligned assembly {
3427 #ifndef __ARM_FEATURE_UNALIGNED
3428 #error no unaligned support
3429 #endif
3430 int i;
3431 }]
3432 }
3433
3434 # Return 1 if this is an ARM target supporting -mfpu=crypto-neon-fp-armv8
3435 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3436 # incompatible with these options. Also set et_arm_crypto_flags to the
3437 # best options to add.
3438
3439 proc check_effective_target_arm_crypto_ok_nocache { } {
3440 global et_arm_crypto_flags
3441 set et_arm_crypto_flags ""
3442 if { [check_effective_target_arm_v8_neon_ok] } {
3443 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=crypto-neon-fp-armv8" "-mfpu=crypto-neon-fp-armv8 -mfloat-abi=softfp"} {
3444 if { [check_no_compiler_messages_nocache arm_crypto_ok object {
3445 #include "arm_neon.h"
3446 uint8x16_t
3447 foo (uint8x16_t a, uint8x16_t b)
3448 {
3449 return vaeseq_u8 (a, b);
3450 }
3451 } "$flags"] } {
3452 set et_arm_crypto_flags $flags
3453 return 1
3454 }
3455 }
3456 }
3457
3458 return 0
3459 }
3460
3461 # Return 1 if this is an ARM target supporting -mfpu=crypto-neon-fp-armv8
3462
3463 proc check_effective_target_arm_crypto_ok { } {
3464 return [check_cached_effective_target arm_crypto_ok \
3465 check_effective_target_arm_crypto_ok_nocache]
3466 }
3467
3468 # Add options for crypto extensions.
3469 proc add_options_for_arm_crypto { flags } {
3470 if { ! [check_effective_target_arm_crypto_ok] } {
3471 return "$flags"
3472 }
3473 global et_arm_crypto_flags
3474 return "$flags $et_arm_crypto_flags"
3475 }
3476
3477 # Add the options needed for NEON. We need either -mfloat-abi=softfp
3478 # or -mfloat-abi=hard, but if one is already specified by the
3479 # multilib, use it. Similarly, if a -mfpu option already enables
3480 # NEON, do not add -mfpu=neon.
3481
3482 proc add_options_for_arm_neon { flags } {
3483 if { ! [check_effective_target_arm_neon_ok] } {
3484 return "$flags"
3485 }
3486 global et_arm_neon_flags
3487 return "$flags $et_arm_neon_flags"
3488 }
3489
3490 proc add_options_for_arm_v8_vfp { flags } {
3491 if { ! [check_effective_target_arm_v8_vfp_ok] } {
3492 return "$flags"
3493 }
3494 return "$flags -mfpu=fp-armv8 -mfloat-abi=softfp"
3495 }
3496
3497 proc add_options_for_arm_v8_neon { flags } {
3498 if { ! [check_effective_target_arm_v8_neon_ok] } {
3499 return "$flags"
3500 }
3501 global et_arm_v8_neon_flags
3502 return "$flags $et_arm_v8_neon_flags -march=armv8-a"
3503 }
3504
3505 # Add the options needed for ARMv8.1 Adv.SIMD. Also adds the ARMv8 NEON
3506 # options for AArch64 and for ARM.
3507
3508 proc add_options_for_arm_v8_1a_neon { flags } {
3509 if { ! [check_effective_target_arm_v8_1a_neon_ok] } {
3510 return "$flags"
3511 }
3512 global et_arm_v8_1a_neon_flags
3513 return "$flags $et_arm_v8_1a_neon_flags"
3514 }
3515
3516 # Add the options needed for ARMv8.2 with the scalar FP16 extension.
3517 # Also adds the ARMv8 FP options for ARM and for AArch64.
3518
3519 proc add_options_for_arm_v8_2a_fp16_scalar { flags } {
3520 if { ! [check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
3521 return "$flags"
3522 }
3523 global et_arm_v8_2a_fp16_scalar_flags
3524 return "$flags $et_arm_v8_2a_fp16_scalar_flags"
3525 }
3526
3527 # Add the options needed for ARMv8.2 with the FP16 extension. Also adds
3528 # the ARMv8 NEON options for ARM and for AArch64.
3529
3530 proc add_options_for_arm_v8_2a_fp16_neon { flags } {
3531 if { ! [check_effective_target_arm_v8_2a_fp16_neon_ok] } {
3532 return "$flags"
3533 }
3534 global et_arm_v8_2a_fp16_neon_flags
3535 return "$flags $et_arm_v8_2a_fp16_neon_flags"
3536 }
3537
3538 proc add_options_for_arm_crc { flags } {
3539 if { ! [check_effective_target_arm_crc_ok] } {
3540 return "$flags"
3541 }
3542 global et_arm_crc_flags
3543 return "$flags $et_arm_crc_flags"
3544 }
3545
3546 # Add the options needed for NEON. We need either -mfloat-abi=softfp
3547 # or -mfloat-abi=hard, but if one is already specified by the
3548 # multilib, use it. Similarly, if a -mfpu option already enables
3549 # NEON, do not add -mfpu=neon.
3550
3551 proc add_options_for_arm_neonv2 { flags } {
3552 if { ! [check_effective_target_arm_neonv2_ok] } {
3553 return "$flags"
3554 }
3555 global et_arm_neonv2_flags
3556 return "$flags $et_arm_neonv2_flags"
3557 }
3558
3559 # Add the options needed for vfp3.
3560 proc add_options_for_arm_vfp3 { flags } {
3561 if { ! [check_effective_target_arm_vfp3_ok] } {
3562 return "$flags"
3563 }
3564 return "$flags -mfpu=vfp3 -mfloat-abi=softfp"
3565 }
3566
3567 # Return 1 if this is an ARM target supporting -mfpu=neon
3568 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3569 # incompatible with these options. Also set et_arm_neon_flags to the
3570 # best options to add.
3571
3572 proc check_effective_target_arm_neon_ok_nocache { } {
3573 global et_arm_neon_flags
3574 set et_arm_neon_flags ""
3575 if { [check_effective_target_arm32] } {
3576 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon" "-mfpu=neon -mfloat-abi=softfp" "-mfpu=neon -mfloat-abi=softfp -march=armv7-a" "-mfloat-abi=hard" "-mfpu=neon -mfloat-abi=hard" "-mfpu=neon -mfloat-abi=hard -march=armv7-a"} {
3577 if { [check_no_compiler_messages_nocache arm_neon_ok object {
3578 #include <arm_neon.h>
3579 int dummy;
3580 #ifndef __ARM_NEON__
3581 #error not NEON
3582 #endif
3583 /* Avoid the case where a test adds -mfpu=neon, but the toolchain is
3584 configured for -mcpu=arm926ej-s, for example. */
3585 #if __ARM_ARCH < 7 || __ARM_ARCH_PROFILE == 'M'
3586 #error Architecture does not support NEON.
3587 #endif
3588 } "$flags"] } {
3589 set et_arm_neon_flags $flags
3590 return 1
3591 }
3592 }
3593 }
3594
3595 return 0
3596 }
3597
3598 proc check_effective_target_arm_neon_ok { } {
3599 return [check_cached_effective_target arm_neon_ok \
3600 check_effective_target_arm_neon_ok_nocache]
3601 }
3602
3603 # Return 1 if this is an ARM target supporting -mfpu=neon without any
3604 # -mfloat-abi= option. Useful in tests where add_options is not
3605 # supported (such as lto tests).
3606
3607 proc check_effective_target_arm_neon_ok_no_float_abi_nocache { } {
3608 if { [check_effective_target_arm32] } {
3609 foreach flags {"-mfpu=neon"} {
3610 if { [check_no_compiler_messages_nocache arm_neon_ok_no_float_abi object {
3611 #include <arm_neon.h>
3612 int dummy;
3613 #ifndef __ARM_NEON__
3614 #error not NEON
3615 #endif
3616 /* Avoid the case where a test adds -mfpu=neon, but the toolchain is
3617 configured for -mcpu=arm926ej-s, for example. */
3618 #if __ARM_ARCH < 7 || __ARM_ARCH_PROFILE == 'M'
3619 #error Architecture does not support NEON.
3620 #endif
3621 } "$flags"] } {
3622 return 1
3623 }
3624 }
3625 }
3626
3627 return 0
3628 }
3629
3630 proc check_effective_target_arm_neon_ok_no_float_abi { } {
3631 return [check_cached_effective_target arm_neon_ok_no_float_abi \
3632 check_effective_target_arm_neon_ok_no_float_abi_nocache]
3633 }
3634
3635 proc check_effective_target_arm_crc_ok_nocache { } {
3636 global et_arm_crc_flags
3637 set et_arm_crc_flags "-march=armv8-a+crc"
3638 return [check_no_compiler_messages_nocache arm_crc_ok object {
3639 #if !defined (__ARM_FEATURE_CRC32)
3640 #error FOO
3641 #endif
3642 } "$et_arm_crc_flags"]
3643 }
3644
3645 proc check_effective_target_arm_crc_ok { } {
3646 return [check_cached_effective_target arm_crc_ok \
3647 check_effective_target_arm_crc_ok_nocache]
3648 }
3649
3650 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
3651 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3652 # incompatible with these options. Also set et_arm_neon_fp16_flags to
3653 # the best options to add.
3654
3655 proc check_effective_target_arm_neon_fp16_ok_nocache { } {
3656 global et_arm_neon_fp16_flags
3657 global et_arm_neon_flags
3658 set et_arm_neon_fp16_flags ""
3659 if { [check_effective_target_arm32]
3660 && [check_effective_target_arm_neon_ok] } {
3661 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
3662 "-mfpu=neon-fp16 -mfloat-abi=softfp"
3663 "-mfp16-format=ieee"
3664 "-mfloat-abi=softfp -mfp16-format=ieee"
3665 "-mfpu=neon-fp16 -mfp16-format=ieee"
3666 "-mfpu=neon-fp16 -mfloat-abi=softfp -mfp16-format=ieee"} {
3667 if { [check_no_compiler_messages_nocache arm_neon_fp16_ok object {
3668 #include "arm_neon.h"
3669 float16x4_t
3670 foo (float32x4_t arg)
3671 {
3672 return vcvt_f16_f32 (arg);
3673 }
3674 } "$et_arm_neon_flags $flags"] } {
3675 set et_arm_neon_fp16_flags [concat $et_arm_neon_flags $flags]
3676 return 1
3677 }
3678 }
3679 }
3680
3681 return 0
3682 }
3683
3684 proc check_effective_target_arm_neon_fp16_ok { } {
3685 return [check_cached_effective_target arm_neon_fp16_ok \
3686 check_effective_target_arm_neon_fp16_ok_nocache]
3687 }
3688
3689 proc check_effective_target_arm_neon_fp16_hw { } {
3690 if {! [check_effective_target_arm_neon_fp16_ok] } {
3691 return 0
3692 }
3693 global et_arm_neon_fp16_flags
3694 check_runtime_nocache arm_neon_fp16_hw {
3695 int
3696 main (int argc, char **argv)
3697 {
3698 asm ("vcvt.f32.f16 q1, d0");
3699 return 0;
3700 }
3701 } $et_arm_neon_fp16_flags
3702 }
3703
3704 proc add_options_for_arm_neon_fp16 { flags } {
3705 if { ! [check_effective_target_arm_neon_fp16_ok] } {
3706 return "$flags"
3707 }
3708 global et_arm_neon_fp16_flags
3709 return "$flags $et_arm_neon_fp16_flags"
3710 }
3711
3712 # Return 1 if this is an ARM target supporting the FP16 alternative
3713 # format. Some multilibs may be incompatible with the options needed. Also
3714 # set et_arm_neon_fp16_flags to the best options to add.
3715
3716 proc check_effective_target_arm_fp16_alternative_ok_nocache { } {
3717 global et_arm_neon_fp16_flags
3718 set et_arm_neon_fp16_flags ""
3719 if { [check_effective_target_arm32] } {
3720 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
3721 "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
3722 if { [check_no_compiler_messages_nocache \
3723 arm_fp16_alternative_ok object {
3724 #if !defined (__ARM_FP16_FORMAT_ALTERNATIVE)
3725 #error __ARM_FP16_FORMAT_ALTERNATIVE not defined
3726 #endif
3727 } "$flags -mfp16-format=alternative"] } {
3728 set et_arm_neon_fp16_flags "$flags -mfp16-format=alternative"
3729 return 1
3730 }
3731 }
3732 }
3733
3734 return 0
3735 }
3736
3737 proc check_effective_target_arm_fp16_alternative_ok { } {
3738 return [check_cached_effective_target arm_fp16_alternative_ok \
3739 check_effective_target_arm_fp16_alternative_ok_nocache]
3740 }
3741
3742 # Return 1 if this is an ARM target supports specifying the FP16 none
3743 # format. Some multilibs may be incompatible with the options needed.
3744
3745 proc check_effective_target_arm_fp16_none_ok_nocache { } {
3746 if { [check_effective_target_arm32] } {
3747 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
3748 "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
3749 if { [check_no_compiler_messages_nocache \
3750 arm_fp16_none_ok object {
3751 #if defined (__ARM_FP16_FORMAT_ALTERNATIVE)
3752 #error __ARM_FP16_FORMAT_ALTERNATIVE defined
3753 #endif
3754 #if defined (__ARM_FP16_FORMAT_IEEE)
3755 #error __ARM_FP16_FORMAT_IEEE defined
3756 #endif
3757 } "$flags -mfp16-format=none"] } {
3758 return 1
3759 }
3760 }
3761 }
3762
3763 return 0
3764 }
3765
3766 proc check_effective_target_arm_fp16_none_ok { } {
3767 return [check_cached_effective_target arm_fp16_none_ok \
3768 check_effective_target_arm_fp16_none_ok_nocache]
3769 }
3770
3771 # Return 1 if this is an ARM target supporting -mfpu=neon-fp-armv8
3772 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3773 # incompatible with these options. Also set et_arm_v8_neon_flags to the
3774 # best options to add.
3775
3776 proc check_effective_target_arm_v8_neon_ok_nocache { } {
3777 global et_arm_v8_neon_flags
3778 set et_arm_v8_neon_flags ""
3779 if { [check_effective_target_arm32] } {
3780 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp-armv8" "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
3781 if { [check_no_compiler_messages_nocache arm_v8_neon_ok object {
3782 #if __ARM_ARCH < 8
3783 #error not armv8 or later
3784 #endif
3785 #include "arm_neon.h"
3786 void
3787 foo ()
3788 {
3789 __asm__ volatile ("vrintn.f32 q0, q0");
3790 }
3791 } "$flags -march=armv8-a"] } {
3792 set et_arm_v8_neon_flags $flags
3793 return 1
3794 }
3795 }
3796 }
3797
3798 return 0
3799 }
3800
3801 proc check_effective_target_arm_v8_neon_ok { } {
3802 return [check_cached_effective_target arm_v8_neon_ok \
3803 check_effective_target_arm_v8_neon_ok_nocache]
3804 }
3805
3806 # Return 1 if this is an ARM target supporting -mfpu=neon-vfpv4
3807 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3808 # incompatible with these options. Also set et_arm_neonv2_flags to the
3809 # best options to add.
3810
3811 proc check_effective_target_arm_neonv2_ok_nocache { } {
3812 global et_arm_neonv2_flags
3813 global et_arm_neon_flags
3814 set et_arm_neonv2_flags ""
3815 if { [check_effective_target_arm32]
3816 && [check_effective_target_arm_neon_ok] } {
3817 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-vfpv4" "-mfpu=neon-vfpv4 -mfloat-abi=softfp"} {
3818 if { [check_no_compiler_messages_nocache arm_neonv2_ok object {
3819 #include "arm_neon.h"
3820 float32x2_t
3821 foo (float32x2_t a, float32x2_t b, float32x2_t c)
3822 {
3823 return vfma_f32 (a, b, c);
3824 }
3825 } "$et_arm_neon_flags $flags"] } {
3826 set et_arm_neonv2_flags [concat $et_arm_neon_flags $flags]
3827 return 1
3828 }
3829 }
3830 }
3831
3832 return 0
3833 }
3834
3835 proc check_effective_target_arm_neonv2_ok { } {
3836 return [check_cached_effective_target arm_neonv2_ok \
3837 check_effective_target_arm_neonv2_ok_nocache]
3838 }
3839
3840 # Add the options needed for VFP FP16 support. We need either
3841 # -mfloat-abi=softfp or -mfloat-abi=hard. If one is already specified by
3842 # the multilib, use it.
3843
3844 proc add_options_for_arm_fp16 { flags } {
3845 if { ! [check_effective_target_arm_fp16_ok] } {
3846 return "$flags"
3847 }
3848 global et_arm_fp16_flags
3849 return "$flags $et_arm_fp16_flags"
3850 }
3851
3852 # Add the options needed to enable support for IEEE format
3853 # half-precision support. This is valid for ARM targets.
3854
3855 proc add_options_for_arm_fp16_ieee { flags } {
3856 if { ! [check_effective_target_arm_fp16_ok] } {
3857 return "$flags"
3858 }
3859 global et_arm_fp16_flags
3860 return "$flags $et_arm_fp16_flags -mfp16-format=ieee"
3861 }
3862
3863 # Add the options needed to enable support for ARM Alternative format
3864 # half-precision support. This is valid for ARM targets.
3865
3866 proc add_options_for_arm_fp16_alternative { flags } {
3867 if { ! [check_effective_target_arm_fp16_ok] } {
3868 return "$flags"
3869 }
3870 global et_arm_fp16_flags
3871 return "$flags $et_arm_fp16_flags -mfp16-format=alternative"
3872 }
3873
3874 # Return 1 if this is an ARM target that can support a VFP fp16 variant.
3875 # Skip multilibs that are incompatible with these options and set
3876 # et_arm_fp16_flags to the best options to add. This test is valid for
3877 # ARM only.
3878
3879 proc check_effective_target_arm_fp16_ok_nocache { } {
3880 global et_arm_fp16_flags
3881 set et_arm_fp16_flags ""
3882 if { ! [check_effective_target_arm32] } {
3883 return 0;
3884 }
3885 if [check-flags \
3886 [list "" { *-*-* } { "-mfpu=*" } \
3887 { "-mfpu=*fp16*" "-mfpu=*fpv[4-9]*" \
3888 "-mfpu=*fpv[1-9][0-9]*" "-mfpu=*fp-armv8*" } ]] {
3889 # Multilib flags would override -mfpu.
3890 return 0
3891 }
3892 if [check-flags [list "" { *-*-* } { "-mfloat-abi=soft" } { "" } ]] {
3893 # Must generate floating-point instructions.
3894 return 0
3895 }
3896 if [check_effective_target_arm_hf_eabi] {
3897 # Use existing float-abi and force an fpu which supports fp16
3898 set et_arm_fp16_flags "-mfpu=vfpv4"
3899 return 1;
3900 }
3901 if [check-flags [list "" { *-*-* } { "-mfpu=*" } { "" } ]] {
3902 # The existing -mfpu value is OK; use it, but add softfp.
3903 set et_arm_fp16_flags "-mfloat-abi=softfp"
3904 return 1;
3905 }
3906 # Add -mfpu for a VFP fp16 variant since there is no preprocessor
3907 # macro to check for this support.
3908 set flags "-mfpu=vfpv4 -mfloat-abi=softfp"
3909 if { [check_no_compiler_messages_nocache arm_fp16_ok assembly {
3910 int dummy;
3911 } "$flags"] } {
3912 set et_arm_fp16_flags "$flags"
3913 return 1
3914 }
3915
3916 return 0
3917 }
3918
3919 proc check_effective_target_arm_fp16_ok { } {
3920 return [check_cached_effective_target arm_fp16_ok \
3921 check_effective_target_arm_fp16_ok_nocache]
3922 }
3923
3924 # Return 1 if the target supports executing VFP FP16 instructions, 0
3925 # otherwise. This test is valid for ARM only.
3926
3927 proc check_effective_target_arm_fp16_hw { } {
3928 if {! [check_effective_target_arm_fp16_ok] } {
3929 return 0
3930 }
3931 global et_arm_fp16_flags
3932 check_runtime_nocache arm_fp16_hw {
3933 int
3934 main (int argc, char **argv)
3935 {
3936 __fp16 a = 1.0;
3937 float r;
3938 asm ("vcvtb.f32.f16 %0, %1"
3939 : "=w" (r) : "w" (a)
3940 : /* No clobbers. */);
3941 return (r == 1.0) ? 0 : 1;
3942 }
3943 } "$et_arm_fp16_flags -mfp16-format=ieee"
3944 }
3945
3946 # Creates a series of routines that return 1 if the given architecture
3947 # can be selected and a routine to give the flags to select that architecture
3948 # Note: Extra flags may be added to disable options from newer compilers
3949 # (Thumb in particular - but others may be added in the future).
3950 # Warning: Do not use check_effective_target_arm_arch_*_ok for architecture
3951 # extension (eg. ARMv8.1-A) since there is no macro defined for them. See
3952 # how only __ARM_ARCH_8A__ is checked for ARMv8.1-A.
3953 # Usage: /* { dg-require-effective-target arm_arch_v5_ok } */
3954 # /* { dg-add-options arm_arch_v5 } */
3955 # /* { dg-require-effective-target arm_arch_v5_multilib } */
3956 foreach { armfunc armflag armdefs } {
3957 v4 "-march=armv4 -marm" __ARM_ARCH_4__
3958 v4t "-march=armv4t" __ARM_ARCH_4T__
3959 v5 "-march=armv5 -marm" __ARM_ARCH_5__
3960 v5t "-march=armv5t" __ARM_ARCH_5T__
3961 v5te "-march=armv5te" __ARM_ARCH_5TE__
3962 v6 "-march=armv6" __ARM_ARCH_6__
3963 v6k "-march=armv6k" __ARM_ARCH_6K__
3964 v6t2 "-march=armv6t2" __ARM_ARCH_6T2__
3965 v6z "-march=armv6z" __ARM_ARCH_6Z__
3966 v6m "-march=armv6-m -mthumb -mfloat-abi=soft" __ARM_ARCH_6M__
3967 v7a "-march=armv7-a" __ARM_ARCH_7A__
3968 v7r "-march=armv7-r" __ARM_ARCH_7R__
3969 v7m "-march=armv7-m -mthumb" __ARM_ARCH_7M__
3970 v7em "-march=armv7e-m -mthumb" __ARM_ARCH_7EM__
3971 v7ve "-march=armv7ve -marm"
3972 "__ARM_ARCH_7A__ && __ARM_FEATURE_IDIV"
3973 v8a "-march=armv8-a" __ARM_ARCH_8A__
3974 v8_1a "-march=armv8.1a" __ARM_ARCH_8A__
3975 v8_2a "-march=armv8.2a" __ARM_ARCH_8A__
3976 v8m_base "-march=armv8-m.base -mthumb -mfloat-abi=soft"
3977 __ARM_ARCH_8M_BASE__
3978 v8m_main "-march=armv8-m.main -mthumb" __ARM_ARCH_8M_MAIN__
3979 v8r "-march=armv8-r" __ARM_ARCH_8R__ } {
3980 eval [string map [list FUNC $armfunc FLAG $armflag DEFS $armdefs ] {
3981 proc check_effective_target_arm_arch_FUNC_ok { } {
3982 if { [ string match "*-marm*" "FLAG" ] &&
3983 ![check_effective_target_arm_arm_ok] } {
3984 return 0
3985 }
3986 return [check_no_compiler_messages arm_arch_FUNC_ok assembly {
3987 #if !(DEFS)
3988 #error !(DEFS)
3989 #endif
3990 } "FLAG" ]
3991 }
3992
3993 proc add_options_for_arm_arch_FUNC { flags } {
3994 return "$flags FLAG"
3995 }
3996
3997 proc check_effective_target_arm_arch_FUNC_multilib { } {
3998 return [check_runtime arm_arch_FUNC_multilib {
3999 int
4000 main (void)
4001 {
4002 return 0;
4003 }
4004 } [add_options_for_arm_arch_FUNC ""]]
4005 }
4006 }]
4007 }
4008
4009 # Return 1 if GCC was configured with --with-mode=
4010 proc check_effective_target_default_mode { } {
4011
4012 return [check_configured_with "with-mode="]
4013 }
4014
4015 # Return 1 if this is an ARM target where -marm causes ARM to be
4016 # used (not Thumb)
4017
4018 proc check_effective_target_arm_arm_ok { } {
4019 return [check_no_compiler_messages arm_arm_ok assembly {
4020 #if !defined (__arm__) || defined (__thumb__) || defined (__thumb2__)
4021 #error !__arm__ || __thumb__ || __thumb2__
4022 #endif
4023 } "-marm"]
4024 }
4025
4026
4027 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
4028 # used.
4029
4030 proc check_effective_target_arm_thumb1_ok { } {
4031 return [check_no_compiler_messages arm_thumb1_ok assembly {
4032 #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
4033 #error !__arm__ || !__thumb__ || __thumb2__
4034 #endif
4035 int foo (int i) { return i; }
4036 } "-mthumb"]
4037 }
4038
4039 # Return 1 is this is an ARM target where -mthumb causes Thumb-2 to be
4040 # used.
4041
4042 proc check_effective_target_arm_thumb2_ok { } {
4043 return [check_no_compiler_messages arm_thumb2_ok assembly {
4044 #if !defined(__thumb2__)
4045 #error !__thumb2__
4046 #endif
4047 int foo (int i) { return i; }
4048 } "-mthumb"]
4049 }
4050
4051 # Return 1 if this is an ARM target where Thumb-1 is used without options
4052 # added by the test.
4053
4054 proc check_effective_target_arm_thumb1 { } {
4055 return [check_no_compiler_messages arm_thumb1 assembly {
4056 #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
4057 #error !__arm__ || !__thumb__ || __thumb2__
4058 #endif
4059 int i;
4060 } ""]
4061 }
4062
4063 # Return 1 if this is an ARM target where Thumb-2 is used without options
4064 # added by the test.
4065
4066 proc check_effective_target_arm_thumb2 { } {
4067 return [check_no_compiler_messages arm_thumb2 assembly {
4068 #if !defined(__thumb2__)
4069 #error !__thumb2__
4070 #endif
4071 int i;
4072 } ""]
4073 }
4074
4075 # Return 1 if this is an ARM target where conditional execution is available.
4076
4077 proc check_effective_target_arm_cond_exec { } {
4078 return [check_no_compiler_messages arm_cond_exec assembly {
4079 #if defined(__arm__) && defined(__thumb__) && !defined(__thumb2__)
4080 #error FOO
4081 #endif
4082 int i;
4083 } ""]
4084 }
4085
4086 # Return 1 if this is an ARM cortex-M profile cpu
4087
4088 proc check_effective_target_arm_cortex_m { } {
4089 if { ![istarget arm*-*-*] } {
4090 return 0
4091 }
4092 return [check_no_compiler_messages arm_cortex_m assembly {
4093 #if defined(__ARM_ARCH_ISA_ARM)
4094 #error __ARM_ARCH_ISA_ARM is defined
4095 #endif
4096 int i;
4097 } "-mthumb"]
4098 }
4099
4100 # Return 1 if this is an ARM target where -mthumb causes Thumb-1 to be
4101 # used and MOVT/MOVW instructions to be available.
4102
4103 proc check_effective_target_arm_thumb1_movt_ok {} {
4104 if [check_effective_target_arm_thumb1_ok] {
4105 return [check_no_compiler_messages arm_movt object {
4106 int
4107 foo (void)
4108 {
4109 asm ("movt r0, #42");
4110 }
4111 } "-mthumb"]
4112 } else {
4113 return 0
4114 }
4115 }
4116
4117 # Return 1 if this is an ARM target where -mthumb causes Thumb-1 to be
4118 # used and CBZ and CBNZ instructions are available.
4119
4120 proc check_effective_target_arm_thumb1_cbz_ok {} {
4121 if [check_effective_target_arm_thumb1_ok] {
4122 return [check_no_compiler_messages arm_movt object {
4123 int
4124 foo (void)
4125 {
4126 asm ("cbz r0, 2f\n2:");
4127 }
4128 } "-mthumb"]
4129 } else {
4130 return 0
4131 }
4132 }
4133
4134 # Return 1 if this is an ARM target where ARMv8-M Security Extensions is
4135 # available.
4136
4137 proc check_effective_target_arm_cmse_ok {} {
4138 return [check_no_compiler_messages arm_cmse object {
4139 int
4140 foo (void)
4141 {
4142 asm ("bxns r0");
4143 }
4144 } "-mcmse"];
4145 }
4146
4147 # Return 1 if this compilation turns on string_ops_prefer_neon on.
4148
4149 proc check_effective_target_arm_tune_string_ops_prefer_neon { } {
4150 return [check_no_messages_and_pattern arm_tune_string_ops_prefer_neon "@string_ops_prefer_neon:\t1" assembly {
4151 int foo (void) { return 0; }
4152 } "-O2 -mprint-tune-info" ]
4153 }
4154
4155 # Return 1 if the target supports executing NEON instructions, 0
4156 # otherwise. Cache the result.
4157
4158 proc check_effective_target_arm_neon_hw { } {
4159 return [check_runtime arm_neon_hw_available {
4160 int
4161 main (void)
4162 {
4163 long long a = 0, b = 1;
4164 asm ("vorr %P0, %P1, %P2"
4165 : "=w" (a)
4166 : "0" (a), "w" (b));
4167 return (a != 1);
4168 }
4169 } [add_options_for_arm_neon ""]]
4170 }
4171
4172 proc check_effective_target_arm_neonv2_hw { } {
4173 return [check_runtime arm_neon_hwv2_available {
4174 #include "arm_neon.h"
4175 int
4176 main (void)
4177 {
4178 float32x2_t a, b, c;
4179 asm ("vfma.f32 %P0, %P1, %P2"
4180 : "=w" (a)
4181 : "w" (b), "w" (c));
4182 return 0;
4183 }
4184 } [add_options_for_arm_neonv2 ""]]
4185 }
4186
4187 # Return 1 if the target supports the ARMv8.1 Adv.SIMD extension, 0
4188 # otherwise. The test is valid for AArch64 and ARM. Record the command
4189 # line options needed.
4190
4191 proc check_effective_target_arm_v8_1a_neon_ok_nocache { } {
4192 global et_arm_v8_1a_neon_flags
4193 set et_arm_v8_1a_neon_flags ""
4194
4195 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
4196 return 0;
4197 }
4198
4199 # Iterate through sets of options to find the compiler flags that
4200 # need to be added to the -march option. Start with the empty set
4201 # since AArch64 only needs the -march setting.
4202 foreach flags {"" "-mfpu=neon-fp-armv8" "-mfloat-abi=softfp" \
4203 "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
4204 foreach arches { "-march=armv8-a+rdma" "-march=armv8.1-a" } {
4205 if { [check_no_compiler_messages_nocache arm_v8_1a_neon_ok object {
4206 #if !defined (__ARM_FEATURE_QRDMX)
4207 #error "__ARM_FEATURE_QRDMX not defined"
4208 #endif
4209 } "$flags $arches"] } {
4210 set et_arm_v8_1a_neon_flags "$flags $arches"
4211 return 1
4212 }
4213 }
4214 }
4215
4216 return 0;
4217 }
4218
4219 proc check_effective_target_arm_v8_1a_neon_ok { } {
4220 return [check_cached_effective_target arm_v8_1a_neon_ok \
4221 check_effective_target_arm_v8_1a_neon_ok_nocache]
4222 }
4223
4224 # Return 1 if the target supports ARMv8.2 scalar FP16 arithmetic
4225 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
4226 # Record the command line options needed.
4227
4228 proc check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache { } {
4229 global et_arm_v8_2a_fp16_scalar_flags
4230 set et_arm_v8_2a_fp16_scalar_flags ""
4231
4232 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
4233 return 0;
4234 }
4235
4236 # Iterate through sets of options to find the compiler flags that
4237 # need to be added to the -march option.
4238 foreach flags {"" "-mfpu=fp-armv8" "-mfloat-abi=softfp" \
4239 "-mfpu=fp-armv8 -mfloat-abi=softfp"} {
4240 if { [check_no_compiler_messages_nocache \
4241 arm_v8_2a_fp16_scalar_ok object {
4242 #if !defined (__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
4243 #error "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC not defined"
4244 #endif
4245 } "$flags -march=armv8.2-a+fp16"] } {
4246 set et_arm_v8_2a_fp16_scalar_flags "$flags -march=armv8.2-a+fp16"
4247 return 1
4248 }
4249 }
4250
4251 return 0;
4252 }
4253
4254 proc check_effective_target_arm_v8_2a_fp16_scalar_ok { } {
4255 return [check_cached_effective_target arm_v8_2a_fp16_scalar_ok \
4256 check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache]
4257 }
4258
4259 # Return 1 if the target supports ARMv8.2 Adv.SIMD FP16 arithmetic
4260 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
4261 # Record the command line options needed.
4262
4263 proc check_effective_target_arm_v8_2a_fp16_neon_ok_nocache { } {
4264 global et_arm_v8_2a_fp16_neon_flags
4265 set et_arm_v8_2a_fp16_neon_flags ""
4266
4267 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
4268 return 0;
4269 }
4270
4271 # Iterate through sets of options to find the compiler flags that
4272 # need to be added to the -march option.
4273 foreach flags {"" "-mfpu=neon-fp-armv8" "-mfloat-abi=softfp" \
4274 "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
4275 if { [check_no_compiler_messages_nocache \
4276 arm_v8_2a_fp16_neon_ok object {
4277 #if !defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
4278 #error "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC not defined"
4279 #endif
4280 } "$flags -march=armv8.2-a+fp16"] } {
4281 set et_arm_v8_2a_fp16_neon_flags "$flags -march=armv8.2-a+fp16"
4282 return 1
4283 }
4284 }
4285
4286 return 0;
4287 }
4288
4289 proc check_effective_target_arm_v8_2a_fp16_neon_ok { } {
4290 return [check_cached_effective_target arm_v8_2a_fp16_neon_ok \
4291 check_effective_target_arm_v8_2a_fp16_neon_ok_nocache]
4292 }
4293
4294 # Return 1 if the target supports executing ARMv8 NEON instructions, 0
4295 # otherwise.
4296
4297 proc check_effective_target_arm_v8_neon_hw { } {
4298 return [check_runtime arm_v8_neon_hw_available {
4299 #include "arm_neon.h"
4300 int
4301 main (void)
4302 {
4303 float32x2_t a = { 1.0f, 2.0f };
4304 #ifdef __ARM_ARCH_ISA_A64
4305 asm ("frinta %0.2s, %1.2s"
4306 : "=w" (a)
4307 : "w" (a));
4308 #else
4309 asm ("vrinta.f32 %P0, %P1"
4310 : "=w" (a)
4311 : "0" (a));
4312 #endif
4313 return a[0] == 2.0f;
4314 }
4315 } [add_options_for_arm_v8_neon ""]]
4316 }
4317
4318 # Return 1 if the target supports executing the ARMv8.1 Adv.SIMD extension, 0
4319 # otherwise. The test is valid for AArch64 and ARM.
4320
4321 proc check_effective_target_arm_v8_1a_neon_hw { } {
4322 if { ![check_effective_target_arm_v8_1a_neon_ok] } {
4323 return 0;
4324 }
4325 return [check_runtime arm_v8_1a_neon_hw_available {
4326 int
4327 main (void)
4328 {
4329 #ifdef __ARM_ARCH_ISA_A64
4330 __Int32x2_t a = {0, 1};
4331 __Int32x2_t b = {0, 2};
4332 __Int32x2_t result;
4333
4334 asm ("sqrdmlah %0.2s, %1.2s, %2.2s"
4335 : "=w"(result)
4336 : "w"(a), "w"(b)
4337 : /* No clobbers. */);
4338
4339 #else
4340
4341 __simd64_int32_t a = {0, 1};
4342 __simd64_int32_t b = {0, 2};
4343 __simd64_int32_t result;
4344
4345 asm ("vqrdmlah.s32 %P0, %P1, %P2"
4346 : "=w"(result)
4347 : "w"(a), "w"(b)
4348 : /* No clobbers. */);
4349 #endif
4350
4351 return result[0];
4352 }
4353 } [add_options_for_arm_v8_1a_neon ""]]
4354 }
4355
4356 # Return 1 if the target supports executing floating point instructions from
4357 # ARMv8.2 with the FP16 extension, 0 otherwise. The test is valid for ARM and
4358 # for AArch64.
4359
4360 proc check_effective_target_arm_v8_2a_fp16_scalar_hw { } {
4361 if { ![check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
4362 return 0;
4363 }
4364 return [check_runtime arm_v8_2a_fp16_scalar_hw_available {
4365 int
4366 main (void)
4367 {
4368 __fp16 a = 1.0;
4369 __fp16 result;
4370
4371 #ifdef __ARM_ARCH_ISA_A64
4372
4373 asm ("fabs %h0, %h1"
4374 : "=w"(result)
4375 : "w"(a)
4376 : /* No clobbers. */);
4377
4378 #else
4379
4380 asm ("vabs.f16 %0, %1"
4381 : "=w"(result)
4382 : "w"(a)
4383 : /* No clobbers. */);
4384
4385 #endif
4386
4387 return (result == 1.0) ? 0 : 1;
4388 }
4389 } [add_options_for_arm_v8_2a_fp16_scalar ""]]
4390 }
4391
4392 # Return 1 if the target supports executing Adv.SIMD instructions from ARMv8.2
4393 # with the FP16 extension, 0 otherwise. The test is valid for ARM and for
4394 # AArch64.
4395
4396 proc check_effective_target_arm_v8_2a_fp16_neon_hw { } {
4397 if { ![check_effective_target_arm_v8_2a_fp16_neon_ok] } {
4398 return 0;
4399 }
4400 return [check_runtime arm_v8_2a_fp16_neon_hw_available {
4401 int
4402 main (void)
4403 {
4404 #ifdef __ARM_ARCH_ISA_A64
4405
4406 __Float16x4_t a = {1.0, -1.0, 1.0, -1.0};
4407 __Float16x4_t result;
4408
4409 asm ("fabs %0.4h, %1.4h"
4410 : "=w"(result)
4411 : "w"(a)
4412 : /* No clobbers. */);
4413
4414 #else
4415
4416 __simd64_float16_t a = {1.0, -1.0, 1.0, -1.0};
4417 __simd64_float16_t result;
4418
4419 asm ("vabs.f16 %P0, %P1"
4420 : "=w"(result)
4421 : "w"(a)
4422 : /* No clobbers. */);
4423
4424 #endif
4425
4426 return (result[0] == 1.0) ? 0 : 1;
4427 }
4428 } [add_options_for_arm_v8_2a_fp16_neon ""]]
4429 }
4430
4431 # Return 1 if this is a ARM target with NEON enabled.
4432
4433 proc check_effective_target_arm_neon { } {
4434 if { [check_effective_target_arm32] } {
4435 return [check_no_compiler_messages arm_neon object {
4436 #ifndef __ARM_NEON__
4437 #error not NEON
4438 #else
4439 int dummy;
4440 #endif
4441 }]
4442 } else {
4443 return 0
4444 }
4445 }
4446
4447 proc check_effective_target_arm_neonv2 { } {
4448 if { [check_effective_target_arm32] } {
4449 return [check_no_compiler_messages arm_neon object {
4450 #ifndef __ARM_NEON__
4451 #error not NEON
4452 #else
4453 #ifndef __ARM_FEATURE_FMA
4454 #error not NEONv2
4455 #else
4456 int dummy;
4457 #endif
4458 #endif
4459 }]
4460 } else {
4461 return 0
4462 }
4463 }
4464
4465 # Return 1 if this is an ARM target with load acquire and store release
4466 # instructions for 8-, 16- and 32-bit types.
4467
4468 proc check_effective_target_arm_acq_rel { } {
4469 return [check_no_compiler_messages arm_acq_rel object {
4470 void
4471 load_acquire_store_release (void)
4472 {
4473 asm ("lda r0, [r1]\n\t"
4474 "stl r0, [r1]\n\t"
4475 "ldah r0, [r1]\n\t"
4476 "stlh r0, [r1]\n\t"
4477 "ldab r0, [r1]\n\t"
4478 "stlb r0, [r1]"
4479 : : : "r0", "memory");
4480 }
4481 }]
4482 }
4483
4484 # Add the options needed for MIPS Paired-Single.
4485
4486 proc add_options_for_mpaired_single { flags } {
4487 if { ! [check_effective_target_mpaired_single] } {
4488 return "$flags"
4489 }
4490 return "$flags -mpaired-single"
4491 }
4492
4493 # Add the options needed for MIPS SIMD Architecture.
4494
4495 proc add_options_for_mips_msa { flags } {
4496 if { ! [check_effective_target_mips_msa] } {
4497 return "$flags"
4498 }
4499 return "$flags -mmsa"
4500 }
4501
4502 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
4503 # the Loongson vector modes.
4504
4505 proc check_effective_target_mips_loongson { } {
4506 return [check_no_compiler_messages loongson assembly {
4507 #if !defined(__mips_loongson_vector_rev)
4508 #error !__mips_loongson_vector_rev
4509 #endif
4510 }]
4511 }
4512
4513 # Return 1 if this is a MIPS target that supports the legacy NAN.
4514
4515 proc check_effective_target_mips_nanlegacy { } {
4516 return [check_no_compiler_messages nanlegacy assembly {
4517 #include <stdlib.h>
4518 int main () { return 0; }
4519 } "-mnan=legacy"]
4520 }
4521
4522 # Return 1 if an MSA program can be compiled to object
4523
4524 proc check_effective_target_mips_msa { } {
4525 if ![check_effective_target_nomips16] {
4526 return 0
4527 }
4528 return [check_no_compiler_messages msa object {
4529 #if !defined(__mips_msa)
4530 #error "MSA NOT AVAIL"
4531 #else
4532 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
4533 #error "MSA NOT AVAIL FOR ISA REV < 2"
4534 #endif
4535 #if !defined(__mips_hard_float)
4536 #error "MSA HARD_FLOAT REQUIRED"
4537 #endif
4538 #if __mips_fpr != 64
4539 #error "MSA 64-bit FPR REQUIRED"
4540 #endif
4541 #include <msa.h>
4542
4543 int main()
4544 {
4545 v8i16 v = __builtin_msa_ldi_h (1);
4546
4547 return v[0];
4548 }
4549 #endif
4550 } "-mmsa" ]
4551 }
4552
4553 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
4554 # Architecture.
4555
4556 proc check_effective_target_arm_eabi { } {
4557 return [check_no_compiler_messages arm_eabi object {
4558 #ifndef __ARM_EABI__
4559 #error not EABI
4560 #else
4561 int dummy;
4562 #endif
4563 }]
4564 }
4565
4566 # Return 1 if this is an ARM target that adheres to the hard-float variant of
4567 # the ABI for the ARM Architecture (e.g. -mfloat-abi=hard).
4568
4569 proc check_effective_target_arm_hf_eabi { } {
4570 return [check_no_compiler_messages arm_hf_eabi object {
4571 #if !defined(__ARM_EABI__) || !defined(__ARM_PCS_VFP)
4572 #error not hard-float EABI
4573 #else
4574 int dummy;
4575 #endif
4576 }]
4577 }
4578
4579 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
4580 # Some multilibs may be incompatible with this option.
4581
4582 proc check_effective_target_arm_iwmmxt_ok { } {
4583 if { [check_effective_target_arm32] } {
4584 return [check_no_compiler_messages arm_iwmmxt_ok object {
4585 int dummy;
4586 } "-mcpu=iwmmxt"]
4587 } else {
4588 return 0
4589 }
4590 }
4591
4592 # Return true if LDRD/STRD instructions are prefered over LDM/STM instructions
4593 # for an ARM target.
4594 proc check_effective_target_arm_prefer_ldrd_strd { } {
4595 if { ![check_effective_target_arm32] } {
4596 return 0;
4597 }
4598
4599 return [check_no_messages_and_pattern arm_prefer_ldrd_strd "strd\tr" assembly {
4600 void foo (void) { __asm__ ("" ::: "r4", "r5"); }
4601 } "-O2 -mthumb" ]
4602 }
4603
4604 # Return 1 if this is a PowerPC target supporting -meabi.
4605
4606 proc check_effective_target_powerpc_eabi_ok { } {
4607 if { [istarget powerpc*-*-*] } {
4608 return [check_no_compiler_messages powerpc_eabi_ok object {
4609 int dummy;
4610 } "-meabi"]
4611 } else {
4612 return 0
4613 }
4614 }
4615
4616 # Return 1 if this is a PowerPC target with floating-point registers.
4617
4618 proc check_effective_target_powerpc_fprs { } {
4619 if { [istarget powerpc*-*-*]
4620 || [istarget rs6000-*-*] } {
4621 return [check_no_compiler_messages powerpc_fprs object {
4622 #ifdef __NO_FPRS__
4623 #error no FPRs
4624 #else
4625 int dummy;
4626 #endif
4627 }]
4628 } else {
4629 return 0
4630 }
4631 }
4632
4633 # Return 1 if this is a PowerPC target with hardware double-precision
4634 # floating point.
4635
4636 proc check_effective_target_powerpc_hard_double { } {
4637 if { [istarget powerpc*-*-*]
4638 || [istarget rs6000-*-*] } {
4639 return [check_no_compiler_messages powerpc_hard_double object {
4640 #ifdef _SOFT_DOUBLE
4641 #error soft double
4642 #else
4643 int dummy;
4644 #endif
4645 }]
4646 } else {
4647 return 0
4648 }
4649 }
4650
4651 # Return 1 if this is a PowerPC target supporting -maltivec.
4652
4653 proc check_effective_target_powerpc_altivec_ok { } {
4654 if { ([istarget powerpc*-*-*]
4655 && ![istarget powerpc-*-linux*paired*])
4656 || [istarget rs6000-*-*] } {
4657 # AltiVec is not supported on AIX before 5.3.
4658 if { [istarget powerpc*-*-aix4*]
4659 || [istarget powerpc*-*-aix5.1*]
4660 || [istarget powerpc*-*-aix5.2*] } {
4661 return 0
4662 }
4663 return [check_no_compiler_messages powerpc_altivec_ok object {
4664 int dummy;
4665 } "-maltivec"]
4666 } else {
4667 return 0
4668 }
4669 }
4670
4671 # Return 1 if this is a PowerPC target supporting -mpower8-vector
4672
4673 proc check_effective_target_powerpc_p8vector_ok { } {
4674 if { ([istarget powerpc*-*-*]
4675 && ![istarget powerpc-*-linux*paired*])
4676 || [istarget rs6000-*-*] } {
4677 # AltiVec is not supported on AIX before 5.3.
4678 if { [istarget powerpc*-*-aix4*]
4679 || [istarget powerpc*-*-aix5.1*]
4680 || [istarget powerpc*-*-aix5.2*] } {
4681 return 0
4682 }
4683 return [check_no_compiler_messages powerpc_p8vector_ok object {
4684 int main (void) {
4685 #ifdef __MACH__
4686 asm volatile ("xxlorc vs0,vs0,vs0");
4687 #else
4688 asm volatile ("xxlorc 0,0,0");
4689 #endif
4690 return 0;
4691 }
4692 } "-mpower8-vector"]
4693 } else {
4694 return 0
4695 }
4696 }
4697
4698 # Return 1 if this is a PowerPC target supporting -mpower9-vector
4699
4700 proc check_effective_target_powerpc_p9vector_ok { } {
4701 if { ([istarget powerpc*-*-*]
4702 && ![istarget powerpc-*-linux*paired*])
4703 || [istarget rs6000-*-*] } {
4704 # AltiVec is not supported on AIX before 5.3.
4705 if { [istarget powerpc*-*-aix4*]
4706 || [istarget powerpc*-*-aix5.1*]
4707 || [istarget powerpc*-*-aix5.2*] } {
4708 return 0
4709 }
4710 return [check_no_compiler_messages powerpc_p9vector_ok object {
4711 int main (void) {
4712 long e = -1;
4713 vector double v = (vector double) { 0.0, 0.0 };
4714 asm ("xsxexpdp %0,%1" : "+r" (e) : "wa" (v));
4715 return e;
4716 }
4717 } "-mpower9-vector"]
4718 } else {
4719 return 0
4720 }
4721 }
4722
4723 # Return 1 if this is a PowerPC target supporting -mmodulo
4724
4725 proc check_effective_target_powerpc_p9modulo_ok { } {
4726 if { ([istarget powerpc*-*-*]
4727 && ![istarget powerpc-*-linux*paired*])
4728 || [istarget rs6000-*-*] } {
4729 # AltiVec is not supported on AIX before 5.3.
4730 if { [istarget powerpc*-*-aix4*]
4731 || [istarget powerpc*-*-aix5.1*]
4732 || [istarget powerpc*-*-aix5.2*] } {
4733 return 0
4734 }
4735 return [check_no_compiler_messages powerpc_p9modulo_ok object {
4736 int main (void) {
4737 int i = 5, j = 3, r = -1;
4738 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
4739 return (r == 2);
4740 }
4741 } "-mmodulo"]
4742 } else {
4743 return 0
4744 }
4745 }
4746
4747 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
4748 # software emulation on power7/power8 systems or hardware support on power9.
4749
4750 proc check_effective_target_powerpc_float128_sw_ok { } {
4751 if { ([istarget powerpc*-*-*]
4752 && ![istarget powerpc-*-linux*paired*])
4753 || [istarget rs6000-*-*] } {
4754 # AltiVec is not supported on AIX before 5.3.
4755 if { [istarget powerpc*-*-aix4*]
4756 || [istarget powerpc*-*-aix5.1*]
4757 || [istarget powerpc*-*-aix5.2*] } {
4758 return 0
4759 }
4760 return [check_no_compiler_messages powerpc_float128_sw_ok object {
4761 volatile __float128 x = 1.0q;
4762 volatile __float128 y = 2.0q;
4763 int main() {
4764 __float128 z = x + y;
4765 return (z == 3.0q);
4766 }
4767 } "-mfloat128 -mvsx"]
4768 } else {
4769 return 0
4770 }
4771 }
4772
4773 # Return 1 if this is a PowerPC target supporting -mfloat128 via hardware
4774 # support on power9.
4775
4776 proc check_effective_target_powerpc_float128_hw_ok { } {
4777 if { ([istarget powerpc*-*-*]
4778 && ![istarget powerpc-*-linux*paired*])
4779 || [istarget rs6000-*-*] } {
4780 # AltiVec is not supported on AIX before 5.3.
4781 if { [istarget powerpc*-*-aix4*]
4782 || [istarget powerpc*-*-aix5.1*]
4783 || [istarget powerpc*-*-aix5.2*] } {
4784 return 0
4785 }
4786 return [check_no_compiler_messages powerpc_float128_hw_ok object {
4787 volatile __float128 x = 1.0q;
4788 volatile __float128 y = 2.0q;
4789 int main() {
4790 __float128 z;
4791 __asm__ ("xsaddqp %0,%1,%2" : "=v" (z) : "v" (x), "v" (y));
4792 return (z == 3.0q);
4793 }
4794 } "-mfloat128-hardware"]
4795 } else {
4796 return 0
4797 }
4798 }
4799
4800 # Return 1 if this is a PowerPC target supporting -mvsx
4801
4802 proc check_effective_target_powerpc_vsx_ok { } {
4803 if { ([istarget powerpc*-*-*]
4804 && ![istarget powerpc-*-linux*paired*])
4805 || [istarget rs6000-*-*] } {
4806 # VSX is not supported on AIX before 7.1.
4807 if { [istarget powerpc*-*-aix4*]
4808 || [istarget powerpc*-*-aix5*]
4809 || [istarget powerpc*-*-aix6*] } {
4810 return 0
4811 }
4812 return [check_no_compiler_messages powerpc_vsx_ok object {
4813 int main (void) {
4814 #ifdef __MACH__
4815 asm volatile ("xxlor vs0,vs0,vs0");
4816 #else
4817 asm volatile ("xxlor 0,0,0");
4818 #endif
4819 return 0;
4820 }
4821 } "-mvsx"]
4822 } else {
4823 return 0
4824 }
4825 }
4826
4827 # Return 1 if this is a PowerPC target supporting -mhtm
4828
4829 proc check_effective_target_powerpc_htm_ok { } {
4830 if { ([istarget powerpc*-*-*]
4831 && ![istarget powerpc-*-linux*paired*])
4832 || [istarget rs6000-*-*] } {
4833 # HTM is not supported on AIX yet.
4834 if { [istarget powerpc*-*-aix*] } {
4835 return 0
4836 }
4837 return [check_no_compiler_messages powerpc_htm_ok object {
4838 int main (void) {
4839 asm volatile ("tbegin. 0");
4840 return 0;
4841 }
4842 } "-mhtm"]
4843 } else {
4844 return 0
4845 }
4846 }
4847
4848 # Return 1 if the target supports executing HTM hardware instructions,
4849 # 0 otherwise. Cache the result.
4850
4851 proc check_htm_hw_available { } {
4852 return [check_cached_effective_target htm_hw_available {
4853 # For now, disable on Darwin
4854 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
4855 expr 0
4856 } else {
4857 check_runtime_nocache htm_hw_available {
4858 int main()
4859 {
4860 __builtin_ttest ();
4861 return 0;
4862 }
4863 } "-mhtm"
4864 }
4865 }]
4866 }
4867 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
4868
4869 proc check_effective_target_powerpc_ppu_ok { } {
4870 if [check_effective_target_powerpc_altivec_ok] {
4871 return [check_no_compiler_messages cell_asm_available object {
4872 int main (void) {
4873 #ifdef __MACH__
4874 asm volatile ("lvlx v0,v0,v0");
4875 #else
4876 asm volatile ("lvlx 0,0,0");
4877 #endif
4878 return 0;
4879 }
4880 }]
4881 } else {
4882 return 0
4883 }
4884 }
4885
4886 # Return 1 if this is a PowerPC target that supports SPU.
4887
4888 proc check_effective_target_powerpc_spu { } {
4889 if { [istarget powerpc*-*-linux*] } {
4890 return [check_effective_target_powerpc_altivec_ok]
4891 } else {
4892 return 0
4893 }
4894 }
4895
4896 # Return 1 if this is a PowerPC SPE target. The check includes options
4897 # specified by dg-options for this test, so don't cache the result.
4898
4899 proc check_effective_target_powerpc_spe_nocache { } {
4900 if { [istarget powerpc*-*-*] } {
4901 return [check_no_compiler_messages_nocache powerpc_spe object {
4902 #ifndef __SPE__
4903 #error not SPE
4904 #else
4905 int dummy;
4906 #endif
4907 } [current_compiler_flags]]
4908 } else {
4909 return 0
4910 }
4911 }
4912
4913 # Return 1 if this is a PowerPC target with SPE enabled.
4914
4915 proc check_effective_target_powerpc_spe { } {
4916 if { [istarget powerpc*-*-*] } {
4917 return [check_no_compiler_messages powerpc_spe object {
4918 #ifndef __SPE__
4919 #error not SPE
4920 #else
4921 int dummy;
4922 #endif
4923 }]
4924 } else {
4925 return 0
4926 }
4927 }
4928
4929 # Return 1 if this is a PowerPC target with Altivec enabled.
4930
4931 proc check_effective_target_powerpc_altivec { } {
4932 if { [istarget powerpc*-*-*] } {
4933 return [check_no_compiler_messages powerpc_altivec object {
4934 #ifndef __ALTIVEC__
4935 #error not Altivec
4936 #else
4937 int dummy;
4938 #endif
4939 }]
4940 } else {
4941 return 0
4942 }
4943 }
4944
4945 # Return 1 if this is a PowerPC 405 target. The check includes options
4946 # specified by dg-options for this test, so don't cache the result.
4947
4948 proc check_effective_target_powerpc_405_nocache { } {
4949 if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
4950 return [check_no_compiler_messages_nocache powerpc_405 object {
4951 #ifdef __PPC405__
4952 int dummy;
4953 #else
4954 #error not a PPC405
4955 #endif
4956 } [current_compiler_flags]]
4957 } else {
4958 return 0
4959 }
4960 }
4961
4962 # Return 1 if this is a PowerPC target using the ELFv2 ABI.
4963
4964 proc check_effective_target_powerpc_elfv2 { } {
4965 if { [istarget powerpc*-*-*] } {
4966 return [check_no_compiler_messages powerpc_elfv2 object {
4967 #if _CALL_ELF != 2
4968 #error not ELF v2 ABI
4969 #else
4970 int dummy;
4971 #endif
4972 }]
4973 } else {
4974 return 0
4975 }
4976 }
4977
4978 # Return 1 if this is a SPU target with a toolchain that
4979 # supports automatic overlay generation.
4980
4981 proc check_effective_target_spu_auto_overlay { } {
4982 if { [istarget spu*-*-elf*] } {
4983 return [check_no_compiler_messages spu_auto_overlay executable {
4984 int main (void) { }
4985 } "-Wl,--auto-overlay" ]
4986 } else {
4987 return 0
4988 }
4989 }
4990
4991 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
4992 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables. Return 1 if the
4993 # test environment appears to run executables on such a simulator.
4994
4995 proc check_effective_target_ultrasparc_hw { } {
4996 return [check_runtime ultrasparc_hw {
4997 int main() { return 0; }
4998 } "-mcpu=ultrasparc"]
4999 }
5000
5001 # Return 1 if the test environment supports executing UltraSPARC VIS2
5002 # instructions. We check this by attempting: "bmask %g0, %g0, %g0"
5003
5004 proc check_effective_target_ultrasparc_vis2_hw { } {
5005 return [check_runtime ultrasparc_vis2_hw {
5006 int main() { __asm__(".word 0x81b00320"); return 0; }
5007 } "-mcpu=ultrasparc3"]
5008 }
5009
5010 # Return 1 if the test environment supports executing UltraSPARC VIS3
5011 # instructions. We check this by attempting: "addxc %g0, %g0, %g0"
5012
5013 proc check_effective_target_ultrasparc_vis3_hw { } {
5014 return [check_runtime ultrasparc_vis3_hw {
5015 int main() { __asm__(".word 0x81b00220"); return 0; }
5016 } "-mcpu=niagara3"]
5017 }
5018
5019 # Return 1 if this is a SPARC-V9 target.
5020
5021 proc check_effective_target_sparc_v9 { } {
5022 if { [istarget sparc*-*-*] } {
5023 return [check_no_compiler_messages sparc_v9 object {
5024 int main (void) {
5025 asm volatile ("return %i7+8");
5026 return 0;
5027 }
5028 }]
5029 } else {
5030 return 0
5031 }
5032 }
5033
5034 # Return 1 if this is a SPARC target with VIS enabled.
5035
5036 proc check_effective_target_sparc_vis { } {
5037 if { [istarget sparc*-*-*] } {
5038 return [check_no_compiler_messages sparc_vis object {
5039 #ifndef __VIS__
5040 #error not VIS
5041 #else
5042 int dummy;
5043 #endif
5044 }]
5045 } else {
5046 return 0
5047 }
5048 }
5049
5050 # Return 1 if the target supports hardware vector shift operation.
5051
5052 proc check_effective_target_vect_shift { } {
5053 global et_vect_shift_saved
5054 global et_index
5055
5056 if [info exists et_vect_shift_saved($et_index)] {
5057 verbose "check_effective_target_vect_shift: using cached result" 2
5058 } else {
5059 set et_vect_shift_saved($et_index) 0
5060 if { ([istarget powerpc*-*-*]
5061 && ![istarget powerpc-*-linux*paired*])
5062 || [istarget ia64-*-*]
5063 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5064 || [istarget aarch64*-*-*]
5065 || [is-effective-target arm_neon]
5066 || ([istarget mips*-*-*]
5067 && ([et-is-effective-target mips_msa]
5068 || [et-is-effective-target mips_loongson])) } {
5069 set et_vect_shift_saved($et_index) 1
5070 }
5071 }
5072
5073 verbose "check_effective_target_vect_shift:\
5074 returning $et_vect_shift_saved($et_index)" 2
5075 return $et_vect_shift_saved($et_index)
5076 }
5077
5078 proc check_effective_target_whole_vector_shift { } {
5079 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5080 || [istarget ia64-*-*]
5081 || [istarget aarch64*-*-*]
5082 || [istarget powerpc64*-*-*]
5083 || ([is-effective-target arm_neon]
5084 && [check_effective_target_arm_little_endian])
5085 || ([istarget mips*-*-*]
5086 && [et-is-effective-target mips_loongson]) } {
5087 set answer 1
5088 } else {
5089 set answer 0
5090 }
5091
5092 verbose "check_effective_target_vect_long: returning $answer" 2
5093 return $answer
5094 }
5095
5096 # Return 1 if the target supports vector bswap operations.
5097
5098 proc check_effective_target_vect_bswap { } {
5099 global et_vect_bswap_saved
5100 global et_index
5101
5102 if [info exists et_vect_bswap_saved($et_index)] {
5103 verbose "check_effective_target_vect_bswap: using cached result" 2
5104 } else {
5105 set et_vect_bswap_saved($et_index) 0
5106 if { [istarget aarch64*-*-*]
5107 || [is-effective-target arm_neon]
5108 } {
5109 set et_vect_bswap_saved($et_index) 1
5110 }
5111 }
5112
5113 verbose "check_effective_target_vect_bswap:\
5114 returning $et_vect_bswap_saved($et_index)" 2
5115 return $et_vect_bswap_saved($et_index)
5116 }
5117
5118 # Return 1 if the target supports hardware vector shift operation for char.
5119
5120 proc check_effective_target_vect_shift_char { } {
5121 global et_vect_shift_char_saved
5122 global et_index
5123
5124 if [info exists et_vect_shift_char_saved($et_index)] {
5125 verbose "check_effective_target_vect_shift_char: using cached result" 2
5126 } else {
5127 set et_vect_shift_char_saved($et_index) 0
5128 if { ([istarget powerpc*-*-*]
5129 && ![istarget powerpc-*-linux*paired*])
5130 || [is-effective-target arm_neon]
5131 || ([istarget mips*-*-*]
5132 && [et-is-effective-target mips_msa]) } {
5133 set et_vect_shift_char_saved($et_index) 1
5134 }
5135 }
5136
5137 verbose "check_effective_target_vect_shift_char:\
5138 returning $et_vect_shift_char_saved($et_index)" 2
5139 return $et_vect_shift_char_saved($et_index)
5140 }
5141
5142 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
5143 #
5144 # This can change for different subtargets so do not cache the result.
5145
5146 proc check_effective_target_vect_long { } {
5147 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5148 || (([istarget powerpc*-*-*]
5149 && ![istarget powerpc-*-linux*paired*])
5150 && [check_effective_target_ilp32])
5151 || [is-effective-target arm_neon]
5152 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
5153 || [istarget aarch64*-*-*]
5154 || ([istarget mips*-*-*]
5155 && [et-is-effective-target mips_msa]) } {
5156 set answer 1
5157 } else {
5158 set answer 0
5159 }
5160
5161 verbose "check_effective_target_vect_long: returning $answer" 2
5162 return $answer
5163 }
5164
5165 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
5166 #
5167 # This won't change for different subtargets so cache the result.
5168
5169 proc check_effective_target_vect_float { } {
5170 global et_vect_float_saved
5171 global et_index
5172
5173 if [info exists et_vect_float_saved($et_index)] {
5174 verbose "check_effective_target_vect_float: using cached result" 2
5175 } else {
5176 set et_vect_float_saved($et_index) 0
5177 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5178 || [istarget powerpc*-*-*]
5179 || [istarget spu-*-*]
5180 || [istarget mips-sde-elf]
5181 || [istarget mipsisa64*-*-*]
5182 || [istarget ia64-*-*]
5183 || [istarget aarch64*-*-*]
5184 || ([istarget mips*-*-*]
5185 && [et-is-effective-target mips_msa])
5186 || [is-effective-target arm_neon] } {
5187 set et_vect_float_saved($et_index) 1
5188 }
5189 }
5190
5191 verbose "check_effective_target_vect_float:\
5192 returning $et_vect_float_saved($et_index)" 2
5193 return $et_vect_float_saved($et_index)
5194 }
5195
5196 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
5197 #
5198 # This won't change for different subtargets so cache the result.
5199
5200 proc check_effective_target_vect_double { } {
5201 global et_vect_double_saved
5202 global et_index
5203
5204 if [info exists et_vect_double_saved($et_index)] {
5205 verbose "check_effective_target_vect_double: using cached result" 2
5206 } else {
5207 set et_vect_double_saved($et_index) 0
5208 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
5209 && [check_no_compiler_messages vect_double assembly {
5210 #ifdef __tune_atom__
5211 # error No double vectorizer support.
5212 #endif
5213 }])
5214 || [istarget aarch64*-*-*]
5215 || [istarget spu-*-*]
5216 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
5217 || ([istarget mips*-*-*]
5218 && [et-is-effective-target mips_msa]) } {
5219 set et_vect_double_saved($et_index) 1
5220 }
5221 }
5222
5223 verbose "check_effective_target_vect_double:\
5224 returning $et_vect_double_saved($et_index)" 2
5225 return $et_vect_double_saved($et_index)
5226 }
5227
5228 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
5229 #
5230 # This won't change for different subtargets so cache the result.
5231
5232 proc check_effective_target_vect_long_long { } {
5233 global et_vect_long_long_saved
5234 global et_index
5235
5236 if [info exists et_vect_long_long_saved($et_index)] {
5237 verbose "check_effective_target_vect_long_long: using cached result" 2
5238 } else {
5239 set et_vect_long_long_saved($et_index) 0
5240 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5241 || ([istarget mips*-*-*]
5242 && [et-is-effective-target mips_msa]) } {
5243 set et_vect_long_long_saved($et_index) 1
5244 }
5245 }
5246
5247 verbose "check_effective_target_vect_long_long:\
5248 returning $et_vect_long_long_saved($et_index)" 2
5249 return $et_vect_long_long_saved($et_index)
5250 }
5251
5252
5253 # Return 1 if the target plus current options does not support a vector
5254 # max instruction on "int", 0 otherwise.
5255 #
5256 # This won't change for different subtargets so cache the result.
5257
5258 proc check_effective_target_vect_no_int_min_max { } {
5259 global et_vect_no_int_min_max_saved
5260 global et_index
5261
5262 if [info exists et_vect_no_int_min_max_saved($et_index)] {
5263 verbose "check_effective_target_vect_no_int_min_max:\
5264 using cached result" 2
5265 } else {
5266 set et_vect_no_int_min_max_saved($et_index) 0
5267 if { [istarget sparc*-*-*]
5268 || [istarget spu-*-*]
5269 || [istarget alpha*-*-*]
5270 || ([istarget mips*-*-*]
5271 && [et-is-effective-target mips_loongson]) } {
5272 set et_vect_no_int_min_max_saved($et_index) 1
5273 }
5274 }
5275 verbose "check_effective_target_vect_no_int_min_max:\
5276 returning $et_vect_no_int_min_max_saved($et_index)" 2
5277 return $et_vect_no_int_min_max_saved($et_index)
5278 }
5279
5280 # Return 1 if the target plus current options does not support a vector
5281 # add instruction on "int", 0 otherwise.
5282 #
5283 # This won't change for different subtargets so cache the result.
5284
5285 proc check_effective_target_vect_no_int_add { } {
5286 global et_vect_no_int_add_saved
5287 global et_index
5288
5289 if [info exists et_vect_no_int_add_saved($et_index)] {
5290 verbose "check_effective_target_vect_no_int_add: using cached result" 2
5291 } else {
5292 set et_vect_no_int_add_saved($et_index) 0
5293 # Alpha only supports vector add on V8QI and V4HI.
5294 if { [istarget alpha*-*-*] } {
5295 set et_vect_no_int_add_saved($et_index) 1
5296 }
5297 }
5298 verbose "check_effective_target_vect_no_int_add:\
5299 returning $et_vect_no_int_add_saved($et_index)" 2
5300 return $et_vect_no_int_add_saved($et_index)
5301 }
5302
5303 # Return 1 if the target plus current options does not support vector
5304 # bitwise instructions, 0 otherwise.
5305 #
5306 # This won't change for different subtargets so cache the result.
5307
5308 proc check_effective_target_vect_no_bitwise { } {
5309 global et_vect_no_bitwise_saved
5310 global et_index
5311
5312 if [info exists et_vect_no_bitwise_saved($et_index)] {
5313 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
5314 } else {
5315 set et_vect_no_bitwise_saved($et_index) 0
5316 }
5317 verbose "check_effective_target_vect_no_bitwise:\
5318 returning $et_vect_no_bitwise_saved($et_index)" 2
5319 return $et_vect_no_bitwise_saved($et_index)
5320 }
5321
5322 # Return 1 if the target plus current options supports vector permutation,
5323 # 0 otherwise.
5324 #
5325 # This won't change for different subtargets so cache the result.
5326
5327 proc check_effective_target_vect_perm { } {
5328 global et_vect_perm_saved
5329 global et_index
5330
5331 if [info exists et_vect_perm_saved($et_index)] {
5332 verbose "check_effective_target_vect_perm: using cached result" 2
5333 } else {
5334 set et_vect_perm_saved($et_index) 0
5335 if { [is-effective-target arm_neon]
5336 || [istarget aarch64*-*-*]
5337 || [istarget powerpc*-*-*]
5338 || [istarget spu-*-*]
5339 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5340 || ([istarget mips*-*-*]
5341 && ([et-is-effective-target mpaired_single]
5342 || [et-is-effective-target mips_msa])) } {
5343 set et_vect_perm_saved($et_index) 1
5344 }
5345 }
5346 verbose "check_effective_target_vect_perm:\
5347 returning $et_vect_perm_saved($et_index)" 2
5348 return $et_vect_perm_saved($et_index)
5349 }
5350
5351 # Return 1 if the target plus current options supports vector permutation
5352 # on byte-sized elements, 0 otherwise.
5353 #
5354 # This won't change for different subtargets so cache the result.
5355
5356 proc check_effective_target_vect_perm_byte { } {
5357 global et_vect_perm_byte_saved
5358 global et_index
5359
5360 if [info exists et_vect_perm_byte_saved($et_index)] {
5361 verbose "check_effective_target_vect_perm_byte: using cached result" 2
5362 } else {
5363 set et_vect_perm_byte_saved($et_index) 0
5364 if { ([is-effective-target arm_neon]
5365 && [is-effective-target arm_little_endian])
5366 || ([istarget aarch64*-*-*]
5367 && [is-effective-target aarch64_little_endian])
5368 || [istarget powerpc*-*-*]
5369 || [istarget spu-*-*]
5370 || ([istarget mips-*.*]
5371 && [et-is-effective-target mips_msa]) } {
5372 set et_vect_perm_byte_saved($et_index) 1
5373 }
5374 }
5375 verbose "check_effective_target_vect_perm_byte:\
5376 returning $et_vect_perm_byte_saved($et_index)" 2
5377 return $et_vect_perm_byte_saved($et_index)
5378 }
5379
5380 # Return 1 if the target plus current options supports vector permutation
5381 # on short-sized elements, 0 otherwise.
5382 #
5383 # This won't change for different subtargets so cache the result.
5384
5385 proc check_effective_target_vect_perm_short { } {
5386 global et_vect_perm_short_saved
5387 global et_index
5388
5389 if [info exists et_vect_perm_short_saved($et_index)] {
5390 verbose "check_effective_target_vect_perm_short: using cached result" 2
5391 } else {
5392 set et_vect_perm_short_saved($et_index) 0
5393 if { ([is-effective-target arm_neon]
5394 && [is-effective-target arm_little_endian])
5395 || ([istarget aarch64*-*-*]
5396 && [is-effective-target aarch64_little_endian])
5397 || [istarget powerpc*-*-*]
5398 || [istarget spu-*-*]
5399 || ([istarget mips*-*-*]
5400 && [et-is-effective-target mips_msa]) } {
5401 set et_vect_perm_short_saved($et_index) 1
5402 }
5403 }
5404 verbose "check_effective_target_vect_perm_short:\
5405 returning $et_vect_perm_short_saved($et_index)" 2
5406 return $et_vect_perm_short_saved($et_index)
5407 }
5408
5409 # Return 1 if the target plus current options supports folding of
5410 # copysign into XORSIGN.
5411 #
5412 # This won't change for different subtargets so cache the result.
5413
5414 proc check_effective_target_xorsign { } {
5415 global et_xorsign_saved
5416 global et_index
5417
5418 if [info exists et_xorsign_saved($et_index)] {
5419 verbose "check_effective_target_xorsign: using cached result" 2
5420 } else {
5421 set et_xorsign_saved($et_index) 0
5422 if { [istarget aarch64*-*-*] || [istarget arm*-*-*] } {
5423 set et_xorsign_saved($et_index) 1
5424 }
5425 }
5426 verbose "check_effective_target_xorsign:\
5427 returning $et_xorsign_saved($et_index)" 2
5428 return $et_xorsign_saved($et_index)
5429 }
5430
5431 # Return 1 if the target plus current options supports a vector
5432 # widening summation of *short* args into *int* result, 0 otherwise.
5433 #
5434 # This won't change for different subtargets so cache the result.
5435
5436 proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
5437 global et_vect_widen_sum_hi_to_si_pattern_saved
5438 global et_index
5439
5440 if [info exists et_vect_widen_sum_hi_to_si_pattern_saved($et_index)] {
5441 verbose "check_effective_target_vect_widen_sum_hi_to_si_pattern:\
5442 using cached result" 2
5443 } else {
5444 set et_vect_widen_sum_hi_to_si_pattern_saved($et_index) 0
5445 if { [istarget powerpc*-*-*]
5446 || [istarget aarch64*-*-*]
5447 || [is-effective-target arm_neon]
5448 || [istarget ia64-*-*] } {
5449 set et_vect_widen_sum_hi_to_si_pattern_saved($et_index) 1
5450 }
5451 }
5452 verbose "check_effective_target_vect_widen_sum_hi_to_si_pattern:\
5453 returning $et_vect_widen_sum_hi_to_si_pattern_saved($et_index)" 2
5454 return $et_vect_widen_sum_hi_to_si_pattern_saved($et_index)
5455 }
5456
5457 # Return 1 if the target plus current options supports a vector
5458 # widening summation of *short* args into *int* result, 0 otherwise.
5459 # A target can also support this widening summation if it can support
5460 # promotion (unpacking) from shorts to ints.
5461 #
5462 # This won't change for different subtargets so cache the result.
5463
5464 proc check_effective_target_vect_widen_sum_hi_to_si { } {
5465 global et_vect_widen_sum_hi_to_si_saved
5466 global et_index
5467
5468 if [info exists et_vect_widen_sum_hi_to_si_saved($et_index)] {
5469 verbose "check_effective_target_vect_widen_sum_hi_to_si:\
5470 using cached result" 2
5471 } else {
5472 set et_vect_widen_sum_hi_to_si_saved($et_index) \
5473 [check_effective_target_vect_unpack]
5474 if { [istarget powerpc*-*-*]
5475 || [istarget ia64-*-*] } {
5476 set et_vect_widen_sum_hi_to_si_saved($et_index) 1
5477 }
5478 }
5479 verbose "check_effective_target_vect_widen_sum_hi_to_si:\
5480 returning $et_vect_widen_sum_hi_to_si_saved($et_index)" 2
5481 return $et_vect_widen_sum_hi_to_si_saved($et_index)
5482 }
5483
5484 # Return 1 if the target plus current options supports a vector
5485 # widening summation of *char* args into *short* result, 0 otherwise.
5486 # A target can also support this widening summation if it can support
5487 # promotion (unpacking) from chars to shorts.
5488 #
5489 # This won't change for different subtargets so cache the result.
5490
5491 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
5492 global et_vect_widen_sum_qi_to_hi_saved
5493 global et_index
5494
5495 if [info exists et_vect_widen_sum_qi_to_hi_saved($et_index)] {
5496 verbose "check_effective_target_vect_widen_sum_qi_to_hi:\
5497 using cached result" 2
5498 } else {
5499 set et_vect_widen_sum_qi_to_hi_saved($et_index) 0
5500 if { [check_effective_target_vect_unpack]
5501 || [is-effective-target arm_neon]
5502 || [istarget ia64-*-*] } {
5503 set et_vect_widen_sum_qi_to_hi_saved($et_index) 1
5504 }
5505 }
5506 verbose "check_effective_target_vect_widen_sum_qi_to_hi:\
5507 returning $et_vect_widen_sum_qi_to_hi_saved($et_index)" 2
5508 return $et_vect_widen_sum_qi_to_hi_saved($et_index)
5509 }
5510
5511 # Return 1 if the target plus current options supports a vector
5512 # widening summation of *char* args into *int* result, 0 otherwise.
5513 #
5514 # This won't change for different subtargets so cache the result.
5515
5516 proc check_effective_target_vect_widen_sum_qi_to_si { } {
5517 global et_vect_widen_sum_qi_to_si_saved
5518 global et_index
5519
5520 if [info exists et_vect_widen_sum_qi_to_si_saved($et_index)] {
5521 verbose "check_effective_target_vect_widen_sum_qi_to_si:\
5522 using cached result" 2
5523 } else {
5524 set et_vect_widen_sum_qi_to_si_saved($et_index) 0
5525 if { [istarget powerpc*-*-*] } {
5526 set et_vect_widen_sum_qi_to_si_saved($et_index) 1
5527 }
5528 }
5529 verbose "check_effective_target_vect_widen_sum_qi_to_si:\
5530 returning $et_vect_widen_sum_qi_to_si_saved($et_index)" 2
5531 return $et_vect_widen_sum_qi_to_si_saved($et_index)
5532 }
5533
5534 # Return 1 if the target plus current options supports a vector
5535 # widening multiplication of *char* args into *short* result, 0 otherwise.
5536 # A target can also support this widening multplication if it can support
5537 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
5538 # multiplication of shorts).
5539 #
5540 # This won't change for different subtargets so cache the result.
5541
5542
5543 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
5544 global et_vect_widen_mult_qi_to_hi_saved
5545 global et_index
5546
5547 if [info exists et_vect_widen_mult_qi_to_hi_saved($et_index)] {
5548 verbose "check_effective_target_vect_widen_mult_qi_to_hi:\
5549 using cached result" 2
5550 } else {
5551 if { [check_effective_target_vect_unpack]
5552 && [check_effective_target_vect_short_mult] } {
5553 set et_vect_widen_mult_qi_to_hi_saved($et_index) 1
5554 } else {
5555 set et_vect_widen_mult_qi_to_hi_saved($et_index) 0
5556 }
5557 if { [istarget powerpc*-*-*]
5558 || [istarget aarch64*-*-*]
5559 || [is-effective-target arm_neon] } {
5560 set et_vect_widen_mult_qi_to_hi_saved($et_index) 1
5561 }
5562 }
5563 verbose "check_effective_target_vect_widen_mult_qi_to_hi:\
5564 returning $et_vect_widen_mult_qi_to_hi_saved($et_index)" 2
5565 return $et_vect_widen_mult_qi_to_hi_saved($et_index)
5566 }
5567
5568 # Return 1 if the target plus current options supports a vector
5569 # widening multiplication of *short* args into *int* result, 0 otherwise.
5570 # A target can also support this widening multplication if it can support
5571 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
5572 # multiplication of ints).
5573 #
5574 # This won't change for different subtargets so cache the result.
5575
5576
5577 proc check_effective_target_vect_widen_mult_hi_to_si { } {
5578 global et_vect_widen_mult_hi_to_si_saved
5579 global et_index
5580
5581 if [info exists et_vect_widen_mult_hi_to_si_saved($et_index)] {
5582 verbose "check_effective_target_vect_widen_mult_hi_to_si:\
5583 using cached result" 2
5584 } else {
5585 if { [check_effective_target_vect_unpack]
5586 && [check_effective_target_vect_int_mult] } {
5587 set et_vect_widen_mult_hi_to_si_saved($et_index) 1
5588 } else {
5589 set et_vect_widen_mult_hi_to_si_saved($et_index) 0
5590 }
5591 if { [istarget powerpc*-*-*]
5592 || [istarget spu-*-*]
5593 || [istarget ia64-*-*]
5594 || [istarget aarch64*-*-*]
5595 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5596 || [is-effective-target arm_neon] } {
5597 set et_vect_widen_mult_hi_to_si_saved($et_index) 1
5598 }
5599 }
5600 verbose "check_effective_target_vect_widen_mult_hi_to_si:\
5601 returning $et_vect_widen_mult_hi_to_si_saved($et_index)" 2
5602 return $et_vect_widen_mult_hi_to_si_saved($et_index)
5603 }
5604
5605 # Return 1 if the target plus current options supports a vector
5606 # widening multiplication of *char* args into *short* result, 0 otherwise.
5607 #
5608 # This won't change for different subtargets so cache the result.
5609
5610 proc check_effective_target_vect_widen_mult_qi_to_hi_pattern { } {
5611 global et_vect_widen_mult_qi_to_hi_pattern_saved
5612 global et_index
5613
5614 if [info exists et_vect_widen_mult_qi_to_hi_pattern_saved($et_index)] {
5615 verbose "check_effective_target_vect_widen_mult_qi_to_hi_pattern:\
5616 using cached result" 2
5617 } else {
5618 set et_vect_widen_mult_qi_to_hi_pattern_saved($et_index) 0
5619 if { [istarget powerpc*-*-*]
5620 || ([is-effective-target arm_neon]
5621 && [check_effective_target_arm_little_endian]) } {
5622 set et_vect_widen_mult_qi_to_hi_pattern_saved($et_index) 1
5623 }
5624 }
5625 verbose "check_effective_target_vect_widen_mult_qi_to_hi_pattern:\
5626 returning $et_vect_widen_mult_qi_to_hi_pattern_saved($et_index)" 2
5627 return $et_vect_widen_mult_qi_to_hi_pattern_saved($et_index)
5628 }
5629
5630 # Return 1 if the target plus current options supports a vector
5631 # widening multiplication of *short* args into *int* result, 0 otherwise.
5632 #
5633 # This won't change for different subtargets so cache the result.
5634
5635 proc check_effective_target_vect_widen_mult_hi_to_si_pattern { } {
5636 global et_vect_widen_mult_hi_to_si_pattern_saved
5637 global et_index
5638
5639 if [info exists et_vect_widen_mult_hi_to_si_pattern_saved($et_index)] {
5640 verbose "check_effective_target_vect_widen_mult_hi_to_si_pattern:\
5641 using cached result" 2
5642 } else {
5643 set et_vect_widen_mult_hi_to_si_pattern_saved($et_index) 0
5644 if { [istarget powerpc*-*-*]
5645 || [istarget spu-*-*]
5646 || [istarget ia64-*-*]
5647 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5648 || ([is-effective-target arm_neon]
5649 && [check_effective_target_arm_little_endian]) } {
5650 set et_vect_widen_mult_hi_to_si_pattern_saved($et_index) 1
5651 }
5652 }
5653 verbose "check_effective_target_vect_widen_mult_hi_to_si_pattern:\
5654 returning $et_vect_widen_mult_hi_to_si_pattern_saved($et_index)" 2
5655 return $et_vect_widen_mult_hi_to_si_pattern_saved($et_index)
5656 }
5657
5658 # Return 1 if the target plus current options supports a vector
5659 # widening multiplication of *int* args into *long* result, 0 otherwise.
5660 #
5661 # This won't change for different subtargets so cache the result.
5662
5663 proc check_effective_target_vect_widen_mult_si_to_di_pattern { } {
5664 global et_vect_widen_mult_si_to_di_pattern_saved
5665 global et_index
5666
5667 if [info exists et_vect_widen_mult_si_to_di_pattern_saved($et_index)] {
5668 verbose "check_effective_target_vect_widen_mult_si_to_di_pattern:\
5669 using cached result" 2
5670 } else {
5671 set et_vect_widen_mult_si_to_di_pattern_saved($et_index) 0
5672 if {[istarget ia64-*-*]
5673 || [istarget i?86-*-*] || [istarget x86_64-*-*] } {
5674 set et_vect_widen_mult_si_to_di_pattern_saved($et_index) 1
5675 }
5676 }
5677 verbose "check_effective_target_vect_widen_mult_si_to_di_pattern:\
5678 returning $et_vect_widen_mult_si_to_di_pattern_saved($et_index)" 2
5679 return $et_vect_widen_mult_si_to_di_pattern_saved($et_index)
5680 }
5681
5682 # Return 1 if the target plus current options supports a vector
5683 # widening shift, 0 otherwise.
5684 #
5685 # This won't change for different subtargets so cache the result.
5686
5687 proc check_effective_target_vect_widen_shift { } {
5688 global et_vect_widen_shift_saved
5689 global et_index
5690
5691 if [info exists et_vect_shift_saved($et_index)] {
5692 verbose "check_effective_target_vect_widen_shift: using cached result" 2
5693 } else {
5694 set et_vect_widen_shift_saved($et_index) 0
5695 if { [is-effective-target arm_neon] } {
5696 set et_vect_widen_shift_saved($et_index) 1
5697 }
5698 }
5699 verbose "check_effective_target_vect_widen_shift:\
5700 returning $et_vect_widen_shift_saved($et_index)" 2
5701 return $et_vect_widen_shift_saved($et_index)
5702 }
5703
5704 # Return 1 if the target plus current options supports a vector
5705 # dot-product of signed chars, 0 otherwise.
5706 #
5707 # This won't change for different subtargets so cache the result.
5708
5709 proc check_effective_target_vect_sdot_qi { } {
5710 global et_vect_sdot_qi_saved
5711 global et_index
5712
5713 if [info exists et_vect_sdot_qi_saved($et_index)] {
5714 verbose "check_effective_target_vect_sdot_qi: using cached result" 2
5715 } else {
5716 set et_vect_sdot_qi_saved($et_index) 0
5717 if { [istarget ia64-*-*]
5718 || ([istarget mips*-*-*]
5719 && [et-is-effective-target mips_msa]) } {
5720 set et_vect_udot_qi_saved 1
5721 }
5722 }
5723 verbose "check_effective_target_vect_sdot_qi:\
5724 returning $et_vect_sdot_qi_saved($et_index)" 2
5725 return $et_vect_sdot_qi_saved($et_index)
5726 }
5727
5728 # Return 1 if the target plus current options supports a vector
5729 # dot-product of unsigned chars, 0 otherwise.
5730 #
5731 # This won't change for different subtargets so cache the result.
5732
5733 proc check_effective_target_vect_udot_qi { } {
5734 global et_vect_udot_qi_saved
5735 global et_index
5736
5737 if [info exists et_vect_udot_qi_saved($et_index)] {
5738 verbose "check_effective_target_vect_udot_qi: using cached result" 2
5739 } else {
5740 set et_vect_udot_qi_saved($et_index) 0
5741 if { [istarget powerpc*-*-*]
5742 || [istarget ia64-*-*]
5743 || ([istarget mips*-*-*]
5744 && [et-is-effective-target mips_msa]) } {
5745 set et_vect_udot_qi_saved($et_index) 1
5746 }
5747 }
5748 verbose "check_effective_target_vect_udot_qi:\
5749 returning $et_vect_udot_qi_saved($et_index)" 2
5750 return $et_vect_udot_qi_saved($et_index)
5751 }
5752
5753 # Return 1 if the target plus current options supports a vector
5754 # dot-product of signed shorts, 0 otherwise.
5755 #
5756 # This won't change for different subtargets so cache the result.
5757
5758 proc check_effective_target_vect_sdot_hi { } {
5759 global et_vect_sdot_hi_saved
5760 global et_index
5761
5762 if [info exists et_vect_sdot_hi_saved($et_index)] {
5763 verbose "check_effective_target_vect_sdot_hi: using cached result" 2
5764 } else {
5765 set et_vect_sdot_hi_saved($et_index) 0
5766 if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
5767 || [istarget ia64-*-*]
5768 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5769 || ([istarget mips*-*-*]
5770 && [et-is-effective-target mips_msa]) } {
5771 set et_vect_sdot_hi_saved($et_index) 1
5772 }
5773 }
5774 verbose "check_effective_target_vect_sdot_hi:\
5775 returning $et_vect_sdot_hi_saved($et_index)" 2
5776 return $et_vect_sdot_hi_saved($et_index)
5777 }
5778
5779 # Return 1 if the target plus current options supports a vector
5780 # dot-product of unsigned shorts, 0 otherwise.
5781 #
5782 # This won't change for different subtargets so cache the result.
5783
5784 proc check_effective_target_vect_udot_hi { } {
5785 global et_vect_udot_hi_saved
5786 global et_index
5787
5788 if [info exists et_vect_udot_hi_saved($et_index)] {
5789 verbose "check_effective_target_vect_udot_hi: using cached result" 2
5790 } else {
5791 set et_vect_udot_hi_saved($et_index) 0
5792 if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
5793 || ([istarget mips*-*-*]
5794 && [et-is-effective-target mips_msa]) } {
5795 set et_vect_udot_hi_saved($et_index) 1
5796 }
5797 }
5798 verbose "check_effective_target_vect_udot_hi:\
5799 returning $et_vect_udot_hi_saved($et_index)" 2
5800 return $et_vect_udot_hi_saved($et_index)
5801 }
5802
5803 # Return 1 if the target plus current options supports a vector
5804 # sad operation of unsigned chars, 0 otherwise.
5805 #
5806 # This won't change for different subtargets so cache the result.
5807
5808 proc check_effective_target_vect_usad_char { } {
5809 global et_vect_usad_char_saved
5810 global et_index
5811
5812 if [info exists et_vect_usad_char_saved($et_index)] {
5813 verbose "check_effective_target_vect_usad_char: using cached result" 2
5814 } else {
5815 set et_vect_usad_char_saved($et_index) 0
5816 if { [istarget i?86-*-*] || [istarget x86_64-*-*] } {
5817 set et_vect_usad_char_saved($et_index) 1
5818 }
5819 }
5820 verbose "check_effective_target_vect_usad_char:\
5821 returning $et_vect_usad_char_saved($et_index)" 2
5822 return $et_vect_usad_char_saved($et_index)
5823 }
5824
5825 # Return 1 if the target plus current options supports a vector
5826 # demotion (packing) of shorts (to chars) and ints (to shorts)
5827 # using modulo arithmetic, 0 otherwise.
5828 #
5829 # This won't change for different subtargets so cache the result.
5830
5831 proc check_effective_target_vect_pack_trunc { } {
5832 global et_vect_pack_trunc_saved
5833 global et_index
5834
5835 if [info exists et_vect_pack_trunc_saved($et_index)] {
5836 verbose "check_effective_target_vect_pack_trunc: using cached result" 2
5837 } else {
5838 set et_vect_pack_trunc_saved($et_index) 0
5839 if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
5840 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5841 || [istarget aarch64*-*-*]
5842 || [istarget spu-*-*]
5843 || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok]
5844 && [check_effective_target_arm_little_endian])
5845 || ([istarget mips*-*-*]
5846 && [et-is-effective-target mips_msa]) } {
5847 set et_vect_pack_trunc_saved($et_index) 1
5848 }
5849 }
5850 verbose "check_effective_target_vect_pack_trunc:\
5851 returning $et_vect_pack_trunc_saved($et_index)" 2
5852 return $et_vect_pack_trunc_saved($et_index)
5853 }
5854
5855 # Return 1 if the target plus current options supports a vector
5856 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
5857 #
5858 # This won't change for different subtargets so cache the result.
5859
5860 proc check_effective_target_vect_unpack { } {
5861 global et_vect_unpack_saved
5862 global et_index
5863
5864 if [info exists et_vect_unpack_saved($et_index)] {
5865 verbose "check_effective_target_vect_unpack: using cached result" 2
5866 } else {
5867 set et_vect_unpack_saved($et_index) 0
5868 if { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
5869 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5870 || [istarget spu-*-*]
5871 || [istarget ia64-*-*]
5872 || [istarget aarch64*-*-*]
5873 || ([istarget mips*-*-*]
5874 && [et-is-effective-target mips_msa])
5875 || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok]
5876 && [check_effective_target_arm_little_endian]) } {
5877 set et_vect_unpack_saved($et_index) 1
5878 }
5879 }
5880 verbose "check_effective_target_vect_unpack:\
5881 returning $et_vect_unpack_saved($et_index)" 2
5882 return $et_vect_unpack_saved($et_index)
5883 }
5884
5885 # Return 1 if the target plus current options does not guarantee
5886 # that its STACK_BOUNDARY is >= the reguired vector alignment.
5887 #
5888 # This won't change for different subtargets so cache the result.
5889
5890 proc check_effective_target_unaligned_stack { } {
5891 global et_unaligned_stack_saved
5892
5893 if [info exists et_unaligned_stack_saved] {
5894 verbose "check_effective_target_unaligned_stack: using cached result" 2
5895 } else {
5896 set et_unaligned_stack_saved 0
5897 }
5898 verbose "check_effective_target_unaligned_stack: returning $et_unaligned_stack_saved" 2
5899 return $et_unaligned_stack_saved
5900 }
5901
5902 # Return 1 if the target plus current options does not support a vector
5903 # alignment mechanism, 0 otherwise.
5904 #
5905 # This won't change for different subtargets so cache the result.
5906
5907 proc check_effective_target_vect_no_align { } {
5908 global et_vect_no_align_saved
5909 global et_index
5910
5911 if [info exists et_vect_no_align_saved($et_index)] {
5912 verbose "check_effective_target_vect_no_align: using cached result" 2
5913 } else {
5914 set et_vect_no_align_saved($et_index) 0
5915 if { [istarget mipsisa64*-*-*]
5916 || [istarget mips-sde-elf]
5917 || [istarget sparc*-*-*]
5918 || [istarget ia64-*-*]
5919 || [check_effective_target_arm_vect_no_misalign]
5920 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
5921 || ([istarget mips*-*-*]
5922 && [et-is-effective-target mips_loongson]) } {
5923 set et_vect_no_align_saved($et_index) 1
5924 }
5925 }
5926 verbose "check_effective_target_vect_no_align:\
5927 returning $et_vect_no_align_saved($et_index)" 2
5928 return $et_vect_no_align_saved($et_index)
5929 }
5930
5931 # Return 1 if the target supports a vector misalign access, 0 otherwise.
5932 #
5933 # This won't change for different subtargets so cache the result.
5934
5935 proc check_effective_target_vect_hw_misalign { } {
5936 global et_vect_hw_misalign_saved
5937 global et_index
5938
5939 if [info exists et_vect_hw_misalign_saved($et_index)] {
5940 verbose "check_effective_target_vect_hw_misalign: using cached result" 2
5941 } else {
5942 set et_vect_hw_misalign_saved($et_index) 0
5943 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5944 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
5945 || [istarget aarch64*-*-*]
5946 || ([istarget mips*-*-*] && [et-is-effective-target mips_msa]) } {
5947 set et_vect_hw_misalign_saved($et_index) 1
5948 }
5949 if { [istarget arm*-*-*] } {
5950 set et_vect_hw_misalign_saved($et_index) [check_effective_target_arm_vect_no_misalign]
5951 }
5952 }
5953 verbose "check_effective_target_vect_hw_misalign:\
5954 returning $et_vect_hw_misalign_saved($et_index)" 2
5955 return $et_vect_hw_misalign_saved($et_index)
5956 }
5957
5958
5959 # Return 1 if arrays are aligned to the vector alignment
5960 # boundary, 0 otherwise.
5961
5962 proc check_effective_target_vect_aligned_arrays { } {
5963 set et_vect_aligned_arrays 0
5964 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
5965 && !([is-effective-target ia32]
5966 || ([check_avx_available] && ![check_prefer_avx128])))
5967 || [istarget spu-*-*] } {
5968 set et_vect_aligned_arrays 1
5969 }
5970
5971 verbose "check_effective_target_vect_aligned_arrays:\
5972 returning $et_vect_aligned_arrays" 2
5973 return $et_vect_aligned_arrays
5974 }
5975
5976 # Return 1 if types of size 32 bit or less are naturally aligned
5977 # (aligned to their type-size), 0 otherwise.
5978 #
5979 # This won't change for different subtargets so cache the result.
5980
5981 proc check_effective_target_natural_alignment_32 { } {
5982 global et_natural_alignment_32
5983
5984 if [info exists et_natural_alignment_32_saved] {
5985 verbose "check_effective_target_natural_alignment_32: using cached result" 2
5986 } else {
5987 # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
5988 set et_natural_alignment_32_saved 1
5989 if { ([istarget *-*-darwin*] && [is-effective-target lp64])
5990 || [istarget avr-*-*] } {
5991 set et_natural_alignment_32_saved 0
5992 }
5993 }
5994 verbose "check_effective_target_natural_alignment_32: returning $et_natural_alignment_32_saved" 2
5995 return $et_natural_alignment_32_saved
5996 }
5997
5998 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
5999 # type-size), 0 otherwise.
6000 #
6001 # This won't change for different subtargets so cache the result.
6002
6003 proc check_effective_target_natural_alignment_64 { } {
6004 global et_natural_alignment_64
6005
6006 if [info exists et_natural_alignment_64_saved] {
6007 verbose "check_effective_target_natural_alignment_64: using cached result" 2
6008 } else {
6009 set et_natural_alignment_64_saved 0
6010 if { ([is-effective-target lp64] && ![istarget *-*-darwin*])
6011 || [istarget spu-*-*] } {
6012 set et_natural_alignment_64_saved 1
6013 }
6014 }
6015 verbose "check_effective_target_natural_alignment_64: returning $et_natural_alignment_64_saved" 2
6016 return $et_natural_alignment_64_saved
6017 }
6018
6019 # Return 1 if all vector types are naturally aligned (aligned to their
6020 # type-size), 0 otherwise.
6021
6022 proc check_effective_target_vect_natural_alignment { } {
6023 set et_vect_natural_alignment 1
6024 if { [check_effective_target_arm_eabi]
6025 || [istarget nvptx-*-*]
6026 || [istarget s390*-*-*] } {
6027 set et_vect_natural_alignment 0
6028 }
6029 verbose "check_effective_target_vect_natural_alignment:\
6030 returning $et_vect_natural_alignment" 2
6031 return $et_vect_natural_alignment
6032 }
6033
6034 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
6035
6036 proc check_effective_target_vector_alignment_reachable { } {
6037 set et_vector_alignment_reachable 0
6038 if { [check_effective_target_vect_aligned_arrays]
6039 || [check_effective_target_natural_alignment_32] } {
6040 set et_vector_alignment_reachable 1
6041 }
6042 verbose "check_effective_target_vector_alignment_reachable:\
6043 returning $et_vector_alignment_reachable" 2
6044 return $et_vector_alignment_reachable
6045 }
6046
6047 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
6048
6049 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
6050 set et_vector_alignment_reachable_for_64bit 0
6051 if { [check_effective_target_vect_aligned_arrays]
6052 || [check_effective_target_natural_alignment_64] } {
6053 set et_vector_alignment_reachable_for_64bit 1
6054 }
6055 verbose "check_effective_target_vector_alignment_reachable_for_64bit:\
6056 returning $et_vector_alignment_reachable_for_64bit" 2
6057 return $et_vector_alignment_reachable_for_64bit
6058 }
6059
6060 # Return 1 if the target only requires element alignment for vector accesses
6061
6062 proc check_effective_target_vect_element_align { } {
6063 global et_vect_element_align
6064 global et_index
6065
6066 if [info exists et_vect_element_align($et_index)] {
6067 verbose "check_effective_target_vect_element_align:\
6068 using cached result" 2
6069 } else {
6070 set et_vect_element_align($et_index) 0
6071 if { ([istarget arm*-*-*]
6072 && ![check_effective_target_arm_vect_no_misalign])
6073 || [check_effective_target_vect_hw_misalign] } {
6074 set et_vect_element_align($et_index) 1
6075 }
6076 }
6077
6078 verbose "check_effective_target_vect_element_align:\
6079 returning $et_vect_element_align($et_index)" 2
6080 return $et_vect_element_align($et_index)
6081 }
6082
6083 # Return 1 if the target supports vector LOAD_LANES operations, 0 otherwise.
6084
6085 proc check_effective_target_vect_load_lanes { } {
6086 global et_vect_load_lanes
6087
6088 if [info exists et_vect_load_lanes] {
6089 verbose "check_effective_target_vect_load_lanes: using cached result" 2
6090 } else {
6091 set et_vect_load_lanes 0
6092 if { ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok])
6093 || [istarget aarch64*-*-*] } {
6094 set et_vect_load_lanes 1
6095 }
6096 }
6097
6098 verbose "check_effective_target_vect_load_lanes: returning $et_vect_load_lanes" 2
6099 return $et_vect_load_lanes
6100 }
6101
6102 # Return 1 if the target supports vector conditional operations, 0 otherwise.
6103
6104 proc check_effective_target_vect_condition { } {
6105 global et_vect_cond_saved
6106 global et_index
6107
6108 if [info exists et_vect_cond_saved($et_index)] {
6109 verbose "check_effective_target_vect_cond: using cached result" 2
6110 } else {
6111 set et_vect_cond_saved($et_index) 0
6112 if { [istarget aarch64*-*-*]
6113 || [istarget powerpc*-*-*]
6114 || [istarget ia64-*-*]
6115 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6116 || [istarget spu-*-*]
6117 || ([istarget mips*-*-*]
6118 && [et-is-effective-target mips_msa])
6119 || ([istarget arm*-*-*]
6120 && [check_effective_target_arm_neon_ok]) } {
6121 set et_vect_cond_saved($et_index) 1
6122 }
6123 }
6124
6125 verbose "check_effective_target_vect_cond:\
6126 returning $et_vect_cond_saved($et_index)" 2
6127 return $et_vect_cond_saved($et_index)
6128 }
6129
6130 # Return 1 if the target supports vector conditional operations where
6131 # the comparison has different type from the lhs, 0 otherwise.
6132
6133 proc check_effective_target_vect_cond_mixed { } {
6134 global et_vect_cond_mixed_saved
6135 global et_index
6136
6137 if [info exists et_vect_cond_mixed_saved($et_index)] {
6138 verbose "check_effective_target_vect_cond_mixed: using cached result" 2
6139 } else {
6140 set et_vect_cond_mixed_saved($et_index) 0
6141 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6142 || [istarget aarch64*-*-*]
6143 || [istarget powerpc*-*-*]
6144 || ([istarget mips*-*-*]
6145 && [et-is-effective-target mips_msa]) } {
6146 set et_vect_cond_mixed_saved($et_index) 1
6147 }
6148 }
6149
6150 verbose "check_effective_target_vect_cond_mixed:\
6151 returning $et_vect_cond_mixed_saved($et_index)" 2
6152 return $et_vect_cond_mixed_saved($et_index)
6153 }
6154
6155 # Return 1 if the target supports vector char multiplication, 0 otherwise.
6156
6157 proc check_effective_target_vect_char_mult { } {
6158 global et_vect_char_mult_saved
6159 global et_index
6160
6161 if [info exists et_vect_char_mult_saved($et_index)] {
6162 verbose "check_effective_target_vect_char_mult: using cached result" 2
6163 } else {
6164 set et_vect_char_mult_saved($et_index) 0
6165 if { [istarget aarch64*-*-*]
6166 || [istarget ia64-*-*]
6167 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6168 || [check_effective_target_arm32]
6169 || [check_effective_target_powerpc_altivec]
6170 || ([istarget mips*-*-*]
6171 && [et-is-effective-target mips_msa]) } {
6172 set et_vect_char_mult_saved($et_index) 1
6173 }
6174 }
6175
6176 verbose "check_effective_target_vect_char_mult:\
6177 returning $et_vect_char_mult_saved($et_index)" 2
6178 return $et_vect_char_mult_saved($et_index)
6179 }
6180
6181 # Return 1 if the target supports vector short multiplication, 0 otherwise.
6182
6183 proc check_effective_target_vect_short_mult { } {
6184 global et_vect_short_mult_saved
6185 global et_index
6186
6187 if [info exists et_vect_short_mult_saved($et_index)] {
6188 verbose "check_effective_target_vect_short_mult: using cached result" 2
6189 } else {
6190 set et_vect_short_mult_saved($et_index) 0
6191 if { [istarget ia64-*-*]
6192 || [istarget spu-*-*]
6193 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6194 || [istarget powerpc*-*-*]
6195 || [istarget aarch64*-*-*]
6196 || [check_effective_target_arm32]
6197 || ([istarget mips*-*-*]
6198 && ([et-is-effective-target mips_msa]
6199 || [et-is-effective-target mips_loongson])) } {
6200 set et_vect_short_mult_saved($et_index) 1
6201 }
6202 }
6203
6204 verbose "check_effective_target_vect_short_mult:\
6205 returning $et_vect_short_mult_saved($et_index)" 2
6206 return $et_vect_short_mult_saved($et_index)
6207 }
6208
6209 # Return 1 if the target supports vector int multiplication, 0 otherwise.
6210
6211 proc check_effective_target_vect_int_mult { } {
6212 global et_vect_int_mult_saved
6213 global et_index
6214
6215 if [info exists et_vect_int_mult_saved($et_index)] {
6216 verbose "check_effective_target_vect_int_mult: using cached result" 2
6217 } else {
6218 set et_vect_int_mult_saved($et_index) 0
6219 if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
6220 || [istarget spu-*-*]
6221 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6222 || [istarget ia64-*-*]
6223 || [istarget aarch64*-*-*]
6224 || ([istarget mips*-*-*]
6225 && [et-is-effective-target mips_msa])
6226 || [check_effective_target_arm32] } {
6227 set et_vect_int_mult_saved($et_index) 1
6228 }
6229 }
6230
6231 verbose "check_effective_target_vect_int_mult:\
6232 returning $et_vect_int_mult_saved($et_index)" 2
6233 return $et_vect_int_mult_saved($et_index)
6234 }
6235
6236 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
6237
6238 proc check_effective_target_vect_extract_even_odd { } {
6239 global et_vect_extract_even_odd_saved
6240 global et_index
6241
6242 if [info exists et_vect_extract_even_odd_saved($et_index)] {
6243 verbose "check_effective_target_vect_extract_even_odd:\
6244 using cached result" 2
6245 } else {
6246 set et_vect_extract_even_odd_saved($et_index) 0
6247 if { [istarget aarch64*-*-*]
6248 || [istarget powerpc*-*-*]
6249 || [is-effective-target arm_neon]
6250 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6251 || [istarget ia64-*-*]
6252 || [istarget spu-*-*]
6253 || ([istarget mips*-*-*]
6254 && ([et-is-effective-target mips_msa]
6255 || [et-is-effective-target mpaired_single])) } {
6256 set et_vect_extract_even_odd_saved($et_index) 1
6257 }
6258 }
6259
6260 verbose "check_effective_target_vect_extract_even_odd:\
6261 returning $et_vect_extract_even_odd_saved($et_index)" 2
6262 return $et_vect_extract_even_odd_saved($et_index)
6263 }
6264
6265 # Return 1 if the target supports vector interleaving, 0 otherwise.
6266
6267 proc check_effective_target_vect_interleave { } {
6268 global et_vect_interleave_saved
6269 global et_index
6270
6271 if [info exists et_vect_interleave_saved($et_index)] {
6272 verbose "check_effective_target_vect_interleave: using cached result" 2
6273 } else {
6274 set et_vect_interleave_saved($et_index) 0
6275 if { [istarget aarch64*-*-*]
6276 || [istarget powerpc*-*-*]
6277 || [is-effective-target arm_neon]
6278 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6279 || [istarget ia64-*-*]
6280 || [istarget spu-*-*]
6281 || ([istarget mips*-*-*]
6282 && ([et-is-effective-target mpaired_single]
6283 || [et-is-effective-target mips_msa])) } {
6284 set et_vect_interleave_saved($et_index) 1
6285 }
6286 }
6287
6288 verbose "check_effective_target_vect_interleave:\
6289 returning $et_vect_interleave_saved($et_index)" 2
6290 return $et_vect_interleave_saved($et_index)
6291 }
6292
6293 foreach N {2 3 4 8} {
6294 eval [string map [list N $N] {
6295 # Return 1 if the target supports 2-vector interleaving
6296 proc check_effective_target_vect_stridedN { } {
6297 global et_vect_stridedN_saved
6298 global et_index
6299
6300 if [info exists et_vect_stridedN_saved($et_index)] {
6301 verbose "check_effective_target_vect_stridedN:\
6302 using cached result" 2
6303 } else {
6304 set et_vect_stridedN_saved($et_index) 0
6305 if { (N & -N) == N
6306 && [check_effective_target_vect_interleave]
6307 && [check_effective_target_vect_extract_even_odd] } {
6308 set et_vect_stridedN_saved($et_index) 1
6309 }
6310 if { ([istarget arm*-*-*]
6311 || [istarget aarch64*-*-*]) && N >= 2 && N <= 4 } {
6312 set et_vect_stridedN_saved($et_index) 1
6313 }
6314 }
6315
6316 verbose "check_effective_target_vect_stridedN:\
6317 returning $et_vect_stridedN_saved($et_index)" 2
6318 return $et_vect_stridedN_saved($et_index)
6319 }
6320 }]
6321 }
6322
6323 # Return 1 if the target supports multiple vector sizes
6324
6325 proc check_effective_target_vect_multiple_sizes { } {
6326 global et_vect_multiple_sizes_saved
6327 global et_index
6328
6329 set et_vect_multiple_sizes_saved($et_index) 0
6330 if { [istarget aarch64*-*-*]
6331 || [is-effective-target arm_neon]
6332 || (([istarget i?86-*-*] || [istarget x86_64-*-*])
6333 && ([check_avx_available] && ![check_prefer_avx128])) } {
6334 set et_vect_multiple_sizes_saved($et_index) 1
6335 }
6336
6337 verbose "check_effective_target_vect_multiple_sizes:\
6338 returning $et_vect_multiple_sizes_saved($et_index)" 2
6339 return $et_vect_multiple_sizes_saved($et_index)
6340 }
6341
6342 # Return 1 if the target supports vectors of 64 bits.
6343
6344 proc check_effective_target_vect64 { } {
6345 global et_vect64_saved
6346 global et_index
6347
6348 if [info exists et_vect64_saved($et_index)] {
6349 verbose "check_effective_target_vect64: using cached result" 2
6350 } else {
6351 set et_vect64_saved($et_index) 0
6352 if { ([is-effective-target arm_neon]
6353 && [check_effective_target_arm_little_endian])
6354 || [istarget aarch64*-*-*]
6355 || [istarget sparc*-*-*] } {
6356 set et_vect64_saved($et_index) 1
6357 }
6358 }
6359
6360 verbose "check_effective_target_vect64:\
6361 returning $et_vect64_saved($et_index)" 2
6362 return $et_vect64_saved($et_index)
6363 }
6364
6365 # Return 1 if the target supports vector copysignf calls.
6366
6367 proc check_effective_target_vect_call_copysignf { } {
6368 global et_vect_call_copysignf_saved
6369 global et_index
6370
6371 if [info exists et_vect_call_copysignf_saved($et_index)] {
6372 verbose "check_effective_target_vect_call_copysignf:\
6373 using cached result" 2
6374 } else {
6375 set et_vect_call_copysignf_saved($et_index) 0
6376 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6377 || [istarget powerpc*-*-*]
6378 || [istarget aarch64*-*-*] } {
6379 set et_vect_call_copysignf_saved($et_index) 1
6380 }
6381 }
6382
6383 verbose "check_effective_target_vect_call_copysignf:\
6384 returning $et_vect_call_copysignf_saved($et_index)" 2
6385 return $et_vect_call_copysignf_saved($et_index)
6386 }
6387
6388 # Return 1 if the target supports hardware square root instructions.
6389
6390 proc check_effective_target_sqrt_insn { } {
6391 global et_sqrt_insn_saved
6392
6393 if [info exists et_sqrt_insn_saved] {
6394 verbose "check_effective_target_hw_sqrt: using cached result" 2
6395 } else {
6396 set et_sqrt_insn_saved 0
6397 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6398 || [istarget powerpc*-*-*]
6399 || [istarget aarch64*-*-*]
6400 || ([istarget arm*-*-*] && [check_effective_target_arm_vfp_ok]) } {
6401 set et_sqrt_insn_saved 1
6402 }
6403 }
6404
6405 verbose "check_effective_target_hw_sqrt: returning et_sqrt_insn_saved" 2
6406 return $et_sqrt_insn_saved
6407 }
6408
6409 # Return 1 if the target supports vector sqrtf calls.
6410
6411 proc check_effective_target_vect_call_sqrtf { } {
6412 global et_vect_call_sqrtf_saved
6413 global et_index
6414
6415 if [info exists et_vect_call_sqrtf_saved($et_index)] {
6416 verbose "check_effective_target_vect_call_sqrtf: using cached result" 2
6417 } else {
6418 set et_vect_call_sqrtf_saved($et_index) 0
6419 if { [istarget aarch64*-*-*]
6420 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6421 || ([istarget powerpc*-*-*] && [check_vsx_hw_available]) } {
6422 set et_vect_call_sqrtf_saved($et_index) 1
6423 }
6424 }
6425
6426 verbose "check_effective_target_vect_call_sqrtf:\
6427 returning $et_vect_call_sqrtf_saved($et_index)" 2
6428 return $et_vect_call_sqrtf_saved($et_index)
6429 }
6430
6431 # Return 1 if the target supports vector lrint calls.
6432
6433 proc check_effective_target_vect_call_lrint { } {
6434 set et_vect_call_lrint 0
6435 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
6436 && [check_effective_target_ilp32]) } {
6437 set et_vect_call_lrint 1
6438 }
6439
6440 verbose "check_effective_target_vect_call_lrint: returning $et_vect_call_lrint" 2
6441 return $et_vect_call_lrint
6442 }
6443
6444 # Return 1 if the target supports vector btrunc calls.
6445
6446 proc check_effective_target_vect_call_btrunc { } {
6447 global et_vect_call_btrunc_saved
6448 global et_index
6449
6450 if [info exists et_vect_call_btrunc_saved($et_index)] {
6451 verbose "check_effective_target_vect_call_btrunc:\
6452 using cached result" 2
6453 } else {
6454 set et_vect_call_btrunc_saved($et_index) 0
6455 if { [istarget aarch64*-*-*] } {
6456 set et_vect_call_btrunc_saved($et_index) 1
6457 }
6458 }
6459
6460 verbose "check_effective_target_vect_call_btrunc:\
6461 returning $et_vect_call_btrunc_saved($et_index)" 2
6462 return $et_vect_call_btrunc_saved($et_index)
6463 }
6464
6465 # Return 1 if the target supports vector btruncf calls.
6466
6467 proc check_effective_target_vect_call_btruncf { } {
6468 global et_vect_call_btruncf_saved
6469 global et_index
6470
6471 if [info exists et_vect_call_btruncf_saved($et_index)] {
6472 verbose "check_effective_target_vect_call_btruncf:\
6473 using cached result" 2
6474 } else {
6475 set et_vect_call_btruncf_saved($et_index) 0
6476 if { [istarget aarch64*-*-*] } {
6477 set et_vect_call_btruncf_saved($et_index) 1
6478 }
6479 }
6480
6481 verbose "check_effective_target_vect_call_btruncf:\
6482 returning $et_vect_call_btruncf_saved($et_index)" 2
6483 return $et_vect_call_btruncf_saved($et_index)
6484 }
6485
6486 # Return 1 if the target supports vector ceil calls.
6487
6488 proc check_effective_target_vect_call_ceil { } {
6489 global et_vect_call_ceil_saved
6490 global et_index
6491
6492 if [info exists et_vect_call_ceil_saved($et_index)] {
6493 verbose "check_effective_target_vect_call_ceil: using cached result" 2
6494 } else {
6495 set et_vect_call_ceil_saved($et_index) 0
6496 if { [istarget aarch64*-*-*] } {
6497 set et_vect_call_ceil_saved($et_index) 1
6498 }
6499 }
6500
6501 verbose "check_effective_target_vect_call_ceil:\
6502 returning $et_vect_call_ceil_saved($et_index)" 2
6503 return $et_vect_call_ceil_saved($et_index)
6504 }
6505
6506 # Return 1 if the target supports vector ceilf calls.
6507
6508 proc check_effective_target_vect_call_ceilf { } {
6509 global et_vect_call_ceilf_saved
6510 global et_index
6511
6512 if [info exists et_vect_call_ceilf_saved($et_index)] {
6513 verbose "check_effective_target_vect_call_ceilf: using cached result" 2
6514 } else {
6515 set et_vect_call_ceilf_saved($et_index) 0
6516 if { [istarget aarch64*-*-*] } {
6517 set et_vect_call_ceilf_saved($et_index) 1
6518 }
6519 }
6520
6521 verbose "check_effective_target_vect_call_ceilf:\
6522 returning $et_vect_call_ceilf_saved($et_index)" 2
6523 return $et_vect_call_ceilf_saved($et_index)
6524 }
6525
6526 # Return 1 if the target supports vector floor calls.
6527
6528 proc check_effective_target_vect_call_floor { } {
6529 global et_vect_call_floor_saved
6530 global et_index
6531
6532 if [info exists et_vect_call_floor_saved($et_index)] {
6533 verbose "check_effective_target_vect_call_floor: using cached result" 2
6534 } else {
6535 set et_vect_call_floor_saved($et_index) 0
6536 if { [istarget aarch64*-*-*] } {
6537 set et_vect_call_floor_saved($et_index) 1
6538 }
6539 }
6540
6541 verbose "check_effective_target_vect_call_floor:\
6542 returning $et_vect_call_floor_saved($et_index)" 2
6543 return $et_vect_call_floor_saved($et_index)
6544 }
6545
6546 # Return 1 if the target supports vector floorf calls.
6547
6548 proc check_effective_target_vect_call_floorf { } {
6549 global et_vect_call_floorf_saved
6550 global et_index
6551
6552 if [info exists et_vect_call_floorf_saved($et_index)] {
6553 verbose "check_effective_target_vect_call_floorf: using cached result" 2
6554 } else {
6555 set et_vect_call_floorf_saved($et_index) 0
6556 if { [istarget aarch64*-*-*] } {
6557 set et_vect_call_floorf_saved($et_index) 1
6558 }
6559 }
6560
6561 verbose "check_effective_target_vect_call_floorf:\
6562 returning $et_vect_call_floorf_saved($et_index)" 2
6563 return $et_vect_call_floorf_saved($et_index)
6564 }
6565
6566 # Return 1 if the target supports vector lceil calls.
6567
6568 proc check_effective_target_vect_call_lceil { } {
6569 global et_vect_call_lceil_saved
6570 global et_index
6571
6572 if [info exists et_vect_call_lceil_saved($et_index)] {
6573 verbose "check_effective_target_vect_call_lceil: using cached result" 2
6574 } else {
6575 set et_vect_call_lceil_saved($et_index) 0
6576 if { [istarget aarch64*-*-*] } {
6577 set et_vect_call_lceil_saved($et_index) 1
6578 }
6579 }
6580
6581 verbose "check_effective_target_vect_call_lceil:\
6582 returning $et_vect_call_lceil_saved($et_index)" 2
6583 return $et_vect_call_lceil_saved($et_index)
6584 }
6585
6586 # Return 1 if the target supports vector lfloor calls.
6587
6588 proc check_effective_target_vect_call_lfloor { } {
6589 global et_vect_call_lfloor_saved
6590 global et_index
6591
6592 if [info exists et_vect_call_lfloor_saved($et_index)] {
6593 verbose "check_effective_target_vect_call_lfloor: using cached result" 2
6594 } else {
6595 set et_vect_call_lfloor_saved($et_index) 0
6596 if { [istarget aarch64*-*-*] } {
6597 set et_vect_call_lfloor_saved($et_index) 1
6598 }
6599 }
6600
6601 verbose "check_effective_target_vect_call_lfloor:\
6602 returning $et_vect_call_lfloor_saved($et_index)" 2
6603 return $et_vect_call_lfloor_saved($et_index)
6604 }
6605
6606 # Return 1 if the target supports vector nearbyint calls.
6607
6608 proc check_effective_target_vect_call_nearbyint { } {
6609 global et_vect_call_nearbyint_saved
6610 global et_index
6611
6612 if [info exists et_vect_call_nearbyint_saved($et_index)] {
6613 verbose "check_effective_target_vect_call_nearbyint: using cached result" 2
6614 } else {
6615 set et_vect_call_nearbyint_saved($et_index) 0
6616 if { [istarget aarch64*-*-*] } {
6617 set et_vect_call_nearbyint_saved($et_index) 1
6618 }
6619 }
6620
6621 verbose "check_effective_target_vect_call_nearbyint:\
6622 returning $et_vect_call_nearbyint_saved($et_index)" 2
6623 return $et_vect_call_nearbyint_saved($et_index)
6624 }
6625
6626 # Return 1 if the target supports vector nearbyintf calls.
6627
6628 proc check_effective_target_vect_call_nearbyintf { } {
6629 global et_vect_call_nearbyintf_saved
6630 global et_index
6631
6632 if [info exists et_vect_call_nearbyintf_saved($et_index)] {
6633 verbose "check_effective_target_vect_call_nearbyintf:\
6634 using cached result" 2
6635 } else {
6636 set et_vect_call_nearbyintf_saved($et_index) 0
6637 if { [istarget aarch64*-*-*] } {
6638 set et_vect_call_nearbyintf_saved($et_index) 1
6639 }
6640 }
6641
6642 verbose "check_effective_target_vect_call_nearbyintf:\
6643 returning $et_vect_call_nearbyintf_saved($et_index)" 2
6644 return $et_vect_call_nearbyintf_saved($et_index)
6645 }
6646
6647 # Return 1 if the target supports vector round calls.
6648
6649 proc check_effective_target_vect_call_round { } {
6650 global et_vect_call_round_saved
6651 global et_index
6652
6653 if [info exists et_vect_call_round_saved($et_index)] {
6654 verbose "check_effective_target_vect_call_round: using cached result" 2
6655 } else {
6656 set et_vect_call_round_saved($et_index) 0
6657 if { [istarget aarch64*-*-*] } {
6658 set et_vect_call_round_saved($et_index) 1
6659 }
6660 }
6661
6662 verbose "check_effective_target_vect_call_round:\
6663 returning $et_vect_call_round_saved($et_index)" 2
6664 return $et_vect_call_round_saved($et_index)
6665 }
6666
6667 # Return 1 if the target supports vector roundf calls.
6668
6669 proc check_effective_target_vect_call_roundf { } {
6670 global et_vect_call_roundf_saved
6671 global et_index
6672
6673 if [info exists et_vect_call_roundf_saved($et_index)] {
6674 verbose "check_effective_target_vect_call_roundf: using cached result" 2
6675 } else {
6676 set et_vect_call_roundf_saved($et_index) 0
6677 if { [istarget aarch64*-*-*] } {
6678 set et_vect_call_roundf_saved($et_index) 1
6679 }
6680 }
6681
6682 verbose "check_effective_target_vect_call_roundf:\
6683 returning $et_vect_call_roundf_saved($et_index)" 2
6684 return $et_vect_call_roundf_saved($et_index)
6685 }
6686
6687 # Return 1 if the target supports section-anchors
6688
6689 proc check_effective_target_section_anchors { } {
6690 global et_section_anchors_saved
6691
6692 if [info exists et_section_anchors_saved] {
6693 verbose "check_effective_target_section_anchors: using cached result" 2
6694 } else {
6695 set et_section_anchors_saved 0
6696 if { [istarget powerpc*-*-*]
6697 || [istarget arm*-*-*]
6698 || [istarget aarch64*-*-*] } {
6699 set et_section_anchors_saved 1
6700 }
6701 }
6702
6703 verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
6704 return $et_section_anchors_saved
6705 }
6706
6707 # Return 1 if the target supports atomic operations on "int_128" values.
6708
6709 proc check_effective_target_sync_int_128 { } {
6710 if { [istarget spu-*-*] } {
6711 return 1
6712 } else {
6713 return 0
6714 }
6715 }
6716
6717 # Return 1 if the target supports atomic operations on "int_128" values
6718 # and can execute them.
6719 # This requires support for both compare-and-swap and true atomic loads.
6720
6721 proc check_effective_target_sync_int_128_runtime { } {
6722 if { [istarget spu-*-*] } {
6723 return 1
6724 } else {
6725 return 0
6726 }
6727 }
6728
6729 # Return 1 if the target supports atomic operations on "long long".
6730 #
6731 # Note: 32bit x86 targets require -march=pentium in dg-options.
6732 # Note: 32bit s390 targets require -mzarch in dg-options.
6733
6734 proc check_effective_target_sync_long_long { } {
6735 if { [istarget i?86-*-*] || [istarget x86_64-*-*])
6736 || [istarget aarch64*-*-*]
6737 || [istarget arm*-*-*]
6738 || [istarget alpha*-*-*]
6739 || ([istarget sparc*-*-*] && [check_effective_target_lp64])
6740 || [istarget s390*-*-*]
6741 || [istarget spu-*-*] } {
6742 return 1
6743 } else {
6744 return 0
6745 }
6746 }
6747
6748 # Return 1 if the target supports atomic operations on "long long"
6749 # and can execute them.
6750 #
6751 # Note: 32bit x86 targets require -march=pentium in dg-options.
6752
6753 proc check_effective_target_sync_long_long_runtime { } {
6754 if { (([istarget x86_64-*-*] || [istarget i?86-*-*])
6755 && [check_cached_effective_target sync_long_long_available {
6756 check_runtime_nocache sync_long_long_available {
6757 #include "cpuid.h"
6758 int main ()
6759 {
6760 unsigned int eax, ebx, ecx, edx;
6761 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
6762 return !(edx & bit_CMPXCHG8B);
6763 return 1;
6764 }
6765 } ""
6766 }])
6767 || [istarget aarch64*-*-*]
6768 || ([istarget arm*-*-linux-*]
6769 && [check_runtime sync_longlong_runtime {
6770 #include <stdlib.h>
6771 int main ()
6772 {
6773 long long l1;
6774
6775 if (sizeof (long long) != 8)
6776 exit (1);
6777
6778 /* Just check for native;
6779 checking for kernel fallback is tricky. */
6780 asm volatile ("ldrexd r0,r1, [%0]"
6781 : : "r" (&l1) : "r0", "r1");
6782 exit (0);
6783 }
6784 } "" ])
6785 || [istarget alpha*-*-*]
6786 || ([istarget sparc*-*-*]
6787 && [check_effective_target_lp64]
6788 && [check_effective_target_ultrasparc_hw])
6789 || [istarget spu-*-*]
6790 || ([istarget powerpc*-*-*] && [check_effective_target_lp64]) } {
6791 return 1
6792 } else {
6793 return 0
6794 }
6795 }
6796
6797 # Return 1 if the target supports byte swap instructions.
6798
6799 proc check_effective_target_bswap { } {
6800 global et_bswap_saved
6801
6802 if [info exists et_bswap_saved] {
6803 verbose "check_effective_target_bswap: using cached result" 2
6804 } else {
6805 set et_bswap_saved 0
6806 if { [istarget aarch64*-*-*]
6807 || [istarget alpha*-*-*]
6808 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6809 || [istarget m68k-*-*]
6810 || [istarget powerpc*-*-*]
6811 || [istarget rs6000-*-*]
6812 || [istarget s390*-*-*]
6813 || ([istarget arm*-*-*]
6814 && [check_no_compiler_messages_nocache arm_v6_or_later object {
6815 #if __ARM_ARCH < 6
6816 #error not armv6 or later
6817 #endif
6818 int i;
6819 } ""]) } {
6820 set et_bswap_saved 1
6821 }
6822 }
6823
6824 verbose "check_effective_target_bswap: returning $et_bswap_saved" 2
6825 return $et_bswap_saved
6826 }
6827
6828 # Return 1 if the target supports 16-bit byte swap instructions.
6829
6830 proc check_effective_target_bswap16 { } {
6831 global et_bswap16_saved
6832
6833 if [info exists et_bswap16_saved] {
6834 verbose "check_effective_target_bswap16: using cached result" 2
6835 } else {
6836 set et_bswap16_saved 0
6837 if { [is-effective-target bswap]
6838 && ![istarget alpha*-*-*]
6839 && !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
6840 set et_bswap16_saved 1
6841 }
6842 }
6843
6844 verbose "check_effective_target_bswap16: returning $et_bswap16_saved" 2
6845 return $et_bswap16_saved
6846 }
6847
6848 # Return 1 if the target supports 32-bit byte swap instructions.
6849
6850 proc check_effective_target_bswap32 { } {
6851 global et_bswap32_saved
6852
6853 if [info exists et_bswap32_saved] {
6854 verbose "check_effective_target_bswap32: using cached result" 2
6855 } else {
6856 set et_bswap32_saved 0
6857 if { [is-effective-target bswap] } {
6858 set et_bswap32_saved 1
6859 }
6860 }
6861
6862 verbose "check_effective_target_bswap32: returning $et_bswap32_saved" 2
6863 return $et_bswap32_saved
6864 }
6865
6866 # Return 1 if the target supports 64-bit byte swap instructions.
6867 #
6868 # Note: 32bit s390 targets require -mzarch in dg-options.
6869
6870 proc check_effective_target_bswap64 { } {
6871 global et_bswap64_saved
6872
6873 # expand_unop can expand 64-bit byte swap on 32-bit targets
6874 if { [is-effective-target bswap] && [is-effective-target int32plus] } {
6875 return 1
6876 }
6877 return 0
6878 }
6879
6880 # Return 1 if the target supports atomic operations on "int" and "long".
6881
6882 proc check_effective_target_sync_int_long { } {
6883 global et_sync_int_long_saved
6884
6885 if [info exists et_sync_int_long_saved] {
6886 verbose "check_effective_target_sync_int_long: using cached result" 2
6887 } else {
6888 set et_sync_int_long_saved 0
6889 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
6890 # load-reserved/store-conditional instructions.
6891 if { [istarget ia64-*-*]
6892 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6893 || [istarget aarch64*-*-*]
6894 || [istarget alpha*-*-*]
6895 || [istarget arm*-*-linux-*]
6896 || ([istarget arm*-*-*]
6897 && [check_effective_target_arm_acq_rel])
6898 || [istarget bfin*-*linux*]
6899 || [istarget hppa*-*linux*]
6900 || [istarget s390*-*-*]
6901 || [istarget powerpc*-*-*]
6902 || [istarget crisv32-*-*] || [istarget cris-*-*]
6903 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
6904 || [istarget spu-*-*]
6905 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
6906 || [check_effective_target_mips_llsc] } {
6907 set et_sync_int_long_saved 1
6908 }
6909 }
6910
6911 verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
6912 return $et_sync_int_long_saved
6913 }
6914
6915 # Return 1 if the target supports atomic operations on "char" and "short".
6916
6917 proc check_effective_target_sync_char_short { } {
6918 global et_sync_char_short_saved
6919
6920 if [info exists et_sync_char_short_saved] {
6921 verbose "check_effective_target_sync_char_short: using cached result" 2
6922 } else {
6923 set et_sync_char_short_saved 0
6924 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
6925 # load-reserved/store-conditional instructions.
6926 if { [istarget aarch64*-*-*]
6927 || [istarget ia64-*-*]
6928 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6929 || [istarget alpha*-*-*]
6930 || [istarget arm*-*-linux-*]
6931 || ([istarget arm*-*-*]
6932 && [check_effective_target_arm_acq_rel])
6933 || [istarget hppa*-*linux*]
6934 || [istarget s390*-*-*]
6935 || [istarget powerpc*-*-*]
6936 || [istarget crisv32-*-*] || [istarget cris-*-*]
6937 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
6938 || [istarget spu-*-*]
6939 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
6940 || [check_effective_target_mips_llsc] } {
6941 set et_sync_char_short_saved 1
6942 }
6943 }
6944
6945 verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
6946 return $et_sync_char_short_saved
6947 }
6948
6949 # Return 1 if the target uses a ColdFire FPU.
6950
6951 proc check_effective_target_coldfire_fpu { } {
6952 return [check_no_compiler_messages coldfire_fpu assembly {
6953 #ifndef __mcffpu__
6954 #error !__mcffpu__
6955 #endif
6956 }]
6957 }
6958
6959 # Return true if this is a uClibc target.
6960
6961 proc check_effective_target_uclibc {} {
6962 return [check_no_compiler_messages uclibc object {
6963 #include <features.h>
6964 #if !defined (__UCLIBC__)
6965 #error !__UCLIBC__
6966 #endif
6967 }]
6968 }
6969
6970 # Return true if this is a uclibc target and if the uclibc feature
6971 # described by __$feature__ is not present.
6972
6973 proc check_missing_uclibc_feature {feature} {
6974 return [check_no_compiler_messages $feature object "
6975 #include <features.h>
6976 #if !defined (__UCLIBC) || defined (__${feature}__)
6977 #error FOO
6978 #endif
6979 "]
6980 }
6981
6982 # Return true if this is a Newlib target.
6983
6984 proc check_effective_target_newlib {} {
6985 return [check_no_compiler_messages newlib object {
6986 #include <newlib.h>
6987 }]
6988 }
6989
6990 # Some newlib versions don't provide a frexpl and instead depend
6991 # on frexp to implement long double conversions in their printf-like
6992 # functions. This leads to broken results. Detect such versions here.
6993
6994 proc check_effective_target_newlib_broken_long_double_io {} {
6995 if { [is-effective-target newlib] && ![is-effective-target frexpl] } {
6996 return 1
6997 }
6998 return 0
6999 }
7000
7001 # Return true if this is NOT a Bionic target.
7002
7003 proc check_effective_target_non_bionic {} {
7004 return [check_no_compiler_messages non_bionic object {
7005 #include <ctype.h>
7006 #if defined (__BIONIC__)
7007 #error FOO
7008 #endif
7009 }]
7010 }
7011
7012 # Return true if this target has error.h header.
7013
7014 proc check_effective_target_error_h {} {
7015 return [check_no_compiler_messages error_h object {
7016 #include <error.h>
7017 }]
7018 }
7019
7020 # Return true if this target has tgmath.h header.
7021
7022 proc check_effective_target_tgmath_h {} {
7023 return [check_no_compiler_messages tgmath_h object {
7024 #include <tgmath.h>
7025 }]
7026 }
7027
7028 # Return true if target's libc supports complex functions.
7029
7030 proc check_effective_target_libc_has_complex_functions {} {
7031 return [check_no_compiler_messages libc_has_complex_functions object {
7032 #include <complex.h>
7033 }]
7034 }
7035
7036 # Return 1 if
7037 # (a) an error of a few ULP is expected in string to floating-point
7038 # conversion functions; and
7039 # (b) overflow is not always detected correctly by those functions.
7040
7041 proc check_effective_target_lax_strtofp {} {
7042 # By default, assume that all uClibc targets suffer from this.
7043 return [check_effective_target_uclibc]
7044 }
7045
7046 # Return 1 if this is a target for which wcsftime is a dummy
7047 # function that always returns 0.
7048
7049 proc check_effective_target_dummy_wcsftime {} {
7050 # By default, assume that all uClibc targets suffer from this.
7051 return [check_effective_target_uclibc]
7052 }
7053
7054 # Return 1 if constructors with initialization priority arguments are
7055 # supposed on this target.
7056
7057 proc check_effective_target_init_priority {} {
7058 return [check_no_compiler_messages init_priority assembly "
7059 void f() __attribute__((constructor (1000)));
7060 void f() \{\}
7061 "]
7062 }
7063
7064 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
7065 # This can be used with any check_* proc that takes no argument and
7066 # returns only 1 or 0. It could be used with check_* procs that take
7067 # arguments with keywords that pass particular arguments.
7068
7069 proc is-effective-target { arg } {
7070 global et_index
7071 set selected 0
7072 if { ![info exists et_index] } {
7073 # Initialize the effective target index that is used in some
7074 # check_effective_target_* procs.
7075 set et_index 0
7076 }
7077 if { [info procs check_effective_target_${arg}] != [list] } {
7078 set selected [check_effective_target_${arg}]
7079 } else {
7080 switch $arg {
7081 "vmx_hw" { set selected [check_vmx_hw_available] }
7082 "vsx_hw" { set selected [check_vsx_hw_available] }
7083 "p8vector_hw" { set selected [check_p8vector_hw_available] }
7084 "p9vector_hw" { set selected [check_p9vector_hw_available] }
7085 "p9modulo_hw" { set selected [check_p9modulo_hw_available] }
7086 "ppc_float128_sw" { set selected [check_ppc_float128_sw_available] }
7087 "ppc_float128_hw" { set selected [check_ppc_float128_hw_available] }
7088 "ppc_recip_hw" { set selected [check_ppc_recip_hw_available] }
7089 "ppc_cpu_supports_hw" { set selected [check_ppc_cpu_supports_hw_available] }
7090 "dfp_hw" { set selected [check_dfp_hw_available] }
7091 "htm_hw" { set selected [check_htm_hw_available] }
7092 "named_sections" { set selected [check_named_sections_available] }
7093 "gc_sections" { set selected [check_gc_sections_available] }
7094 "cxa_atexit" { set selected [check_cxa_atexit_available] }
7095 default { error "unknown effective target keyword `$arg'" }
7096 }
7097 }
7098 verbose "is-effective-target: $arg $selected" 2
7099 return $selected
7100 }
7101
7102 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
7103
7104 proc is-effective-target-keyword { arg } {
7105 if { [info procs check_effective_target_${arg}] != [list] } {
7106 return 1
7107 } else {
7108 # These have different names for their check_* procs.
7109 switch $arg {
7110 "vmx_hw" { return 1 }
7111 "vsx_hw" { return 1 }
7112 "p8vector_hw" { return 1 }
7113 "p9vector_hw" { return 1 }
7114 "p9modulo_hw" { return 1 }
7115 "ppc_float128_sw" { return 1 }
7116 "ppc_float128_hw" { return 1 }
7117 "ppc_recip_hw" { return 1 }
7118 "dfp_hw" { return 1 }
7119 "htm_hw" { return 1 }
7120 "named_sections" { return 1 }
7121 "gc_sections" { return 1 }
7122 "cxa_atexit" { return 1 }
7123 default { return 0 }
7124 }
7125 }
7126 }
7127
7128 # Execute tests for all targets in EFFECTIVE_TARGETS list. Set et_index to
7129 # indicate what target is currently being processed. This is for
7130 # the vectorizer tests, e.g. vect_int, to keep track what target supports
7131 # a given feature.
7132
7133 proc et-dg-runtest { runtest testcases flags default-extra-flags } {
7134 global dg-do-what-default
7135 global EFFECTIVE_TARGETS
7136 global et_index
7137
7138 if { [llength $EFFECTIVE_TARGETS] > 0 } {
7139 foreach target $EFFECTIVE_TARGETS {
7140 set target_flags $flags
7141 set dg-do-what-default compile
7142 set et_index [lsearch -exact $EFFECTIVE_TARGETS $target]
7143 if { [info procs add_options_for_${target}] != [list] } {
7144 set target_flags [add_options_for_${target} "$flags"]
7145 }
7146 if { [info procs check_effective_target_${target}_runtime]
7147 != [list] && [check_effective_target_${target}_runtime] } {
7148 set dg-do-what-default run
7149 }
7150 $runtest $testcases $target_flags ${default-extra-flags}
7151 }
7152 } else {
7153 set et_index 0
7154 $runtest $testcases $flags ${default-extra-flags}
7155 }
7156 }
7157
7158 # Return 1 if a target matches the target in EFFECTIVE_TARGETS at index
7159 # et_index, 0 otherwise.
7160
7161 proc et-is-effective-target { target } {
7162 global EFFECTIVE_TARGETS
7163 global et_index
7164
7165 if { [llength $EFFECTIVE_TARGETS] > $et_index
7166 && [lindex $EFFECTIVE_TARGETS $et_index] == $target } {
7167 return 1
7168 }
7169 return 0
7170 }
7171
7172 # Return 1 if target default to short enums
7173
7174 proc check_effective_target_short_enums { } {
7175 return [check_no_compiler_messages short_enums assembly {
7176 enum foo { bar };
7177 int s[sizeof (enum foo) == 1 ? 1 : -1];
7178 }]
7179 }
7180
7181 # Return 1 if target supports merging string constants at link time.
7182
7183 proc check_effective_target_string_merging { } {
7184 return [check_no_messages_and_pattern string_merging \
7185 "rodata\\.str" assembly {
7186 const char *var = "String";
7187 } {-O2}]
7188 }
7189
7190 # Return 1 if target has the basic signed and unsigned types in
7191 # <stdint.h>, 0 otherwise. This will be obsolete when GCC ensures a
7192 # working <stdint.h> for all targets.
7193
7194 proc check_effective_target_stdint_types { } {
7195 return [check_no_compiler_messages stdint_types assembly {
7196 #include <stdint.h>
7197 int8_t a; int16_t b; int32_t c; int64_t d;
7198 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
7199 }]
7200 }
7201
7202 # Return 1 if target has the basic signed and unsigned types in
7203 # <inttypes.h>, 0 otherwise. This is for tests that GCC's notions of
7204 # these types agree with those in the header, as some systems have
7205 # only <inttypes.h>.
7206
7207 proc check_effective_target_inttypes_types { } {
7208 return [check_no_compiler_messages inttypes_types assembly {
7209 #include <inttypes.h>
7210 int8_t a; int16_t b; int32_t c; int64_t d;
7211 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
7212 }]
7213 }
7214
7215 # Return 1 if programs are intended to be run on a simulator
7216 # (i.e. slowly) rather than hardware (i.e. fast).
7217
7218 proc check_effective_target_simulator { } {
7219
7220 # All "src/sim" simulators set this one.
7221 if [board_info target exists is_simulator] {
7222 return [board_info target is_simulator]
7223 }
7224
7225 # The "sid" simulators don't set that one, but at least they set
7226 # this one.
7227 if [board_info target exists slow_simulator] {
7228 return [board_info target slow_simulator]
7229 }
7230
7231 return 0
7232 }
7233
7234 # Return 1 if programs are intended to be run on hardware rather than
7235 # on a simulator
7236
7237 proc check_effective_target_hw { } {
7238
7239 # All "src/sim" simulators set this one.
7240 if [board_info target exists is_simulator] {
7241 if [board_info target is_simulator] {
7242 return 0
7243 } else {
7244 return 1
7245 }
7246 }
7247
7248 # The "sid" simulators don't set that one, but at least they set
7249 # this one.
7250 if [board_info target exists slow_simulator] {
7251 if [board_info target slow_simulator] {
7252 return 0
7253 } else {
7254 return 1
7255 }
7256 }
7257
7258 return 1
7259 }
7260
7261 # Return 1 if the target is a VxWorks kernel.
7262
7263 proc check_effective_target_vxworks_kernel { } {
7264 return [check_no_compiler_messages vxworks_kernel assembly {
7265 #if !defined __vxworks || defined __RTP__
7266 #error NO
7267 #endif
7268 }]
7269 }
7270
7271 # Return 1 if the target is a VxWorks RTP.
7272
7273 proc check_effective_target_vxworks_rtp { } {
7274 return [check_no_compiler_messages vxworks_rtp assembly {
7275 #if !defined __vxworks || !defined __RTP__
7276 #error NO
7277 #endif
7278 }]
7279 }
7280
7281 # Return 1 if the target is expected to provide wide character support.
7282
7283 proc check_effective_target_wchar { } {
7284 if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
7285 return 0
7286 }
7287 return [check_no_compiler_messages wchar assembly {
7288 #include <wchar.h>
7289 }]
7290 }
7291
7292 # Return 1 if the target has <pthread.h>.
7293
7294 proc check_effective_target_pthread_h { } {
7295 return [check_no_compiler_messages pthread_h assembly {
7296 #include <pthread.h>
7297 }]
7298 }
7299
7300 # Return 1 if the target can truncate a file from a file-descriptor,
7301 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
7302 # chsize. We test for a trivially functional truncation; no stubs.
7303 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
7304 # different function to be used.
7305
7306 proc check_effective_target_fd_truncate { } {
7307 set prog {
7308 #define _FILE_OFFSET_BITS 64
7309 #include <unistd.h>
7310 #include <stdio.h>
7311 #include <stdlib.h>
7312 #include <string.h>
7313 int main ()
7314 {
7315 FILE *f = fopen ("tst.tmp", "wb");
7316 int fd;
7317 const char t[] = "test writing more than ten characters";
7318 char s[11];
7319 int status = 0;
7320 fd = fileno (f);
7321 write (fd, t, sizeof (t) - 1);
7322 lseek (fd, 0, 0);
7323 if (ftruncate (fd, 10) != 0)
7324 status = 1;
7325 close (fd);
7326 fclose (f);
7327 if (status)
7328 {
7329 unlink ("tst.tmp");
7330 exit (status);
7331 }
7332 f = fopen ("tst.tmp", "rb");
7333 if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
7334 status = 1;
7335 fclose (f);
7336 unlink ("tst.tmp");
7337 exit (status);
7338 }
7339 }
7340
7341 if { [check_runtime ftruncate $prog] } {
7342 return 1;
7343 }
7344
7345 regsub "ftruncate" $prog "chsize" prog
7346 return [check_runtime chsize $prog]
7347 }
7348
7349 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
7350
7351 proc add_options_for_c99_runtime { flags } {
7352 if { [istarget *-*-solaris2*] } {
7353 return "$flags -std=c99"
7354 }
7355 if { [istarget powerpc-*-darwin*] } {
7356 return "$flags -mmacosx-version-min=10.3"
7357 }
7358 return $flags
7359 }
7360
7361 # Add to FLAGS all the target-specific flags needed to enable
7362 # full IEEE compliance mode.
7363
7364 proc add_options_for_ieee { flags } {
7365 if { [istarget alpha*-*-*]
7366 || [istarget sh*-*-*] } {
7367 return "$flags -mieee"
7368 }
7369 if { [istarget rx-*-*] } {
7370 return "$flags -mnofpu"
7371 }
7372 return $flags
7373 }
7374
7375 if {![info exists flags_to_postpone]} {
7376 set flags_to_postpone ""
7377 }
7378
7379 # Add to FLAGS the flags needed to enable functions to bind locally
7380 # when using pic/PIC passes in the testsuite.
7381 proc add_options_for_bind_pic_locally { flags } {
7382 global flags_to_postpone
7383
7384 # Instead of returning 'flags' with the -fPIE or -fpie appended, we save it
7385 # in 'flags_to_postpone' and append it later in gcc_target_compile procedure in
7386 # order to make sure that the multilib_flags doesn't override this.
7387
7388 if {[check_no_compiler_messages using_pic2 assembly {
7389 #if __PIC__ != 2
7390 #error __PIC__ != 2
7391 #endif
7392 }]} {
7393 set flags_to_postpone "-fPIE"
7394 return $flags
7395 }
7396 if {[check_no_compiler_messages using_pic1 assembly {
7397 #if __PIC__ != 1
7398 #error __PIC__ != 1
7399 #endif
7400 }]} {
7401 set flags_to_postpone "-fpie"
7402 return $flags
7403 }
7404 return $flags
7405 }
7406
7407 # Add to FLAGS the flags needed to enable 64-bit vectors.
7408
7409 proc add_options_for_double_vectors { flags } {
7410 if [is-effective-target arm_neon_ok] {
7411 return "$flags -mvectorize-with-neon-double"
7412 }
7413
7414 return $flags
7415 }
7416
7417 # Add to FLAGS the flags needed to define the STACK_SIZE macro.
7418
7419 proc add_options_for_stack_size { flags } {
7420 if [is-effective-target stack_size] {
7421 set stack_size [dg-effective-target-value stack_size]
7422 return "$flags -DSTACK_SIZE=$stack_size"
7423 }
7424
7425 return $flags
7426 }
7427
7428 # Return 1 if the target provides a full C99 runtime.
7429
7430 proc check_effective_target_c99_runtime { } {
7431 return [check_cached_effective_target c99_runtime {
7432 global srcdir
7433
7434 set file [open "$srcdir/gcc.dg/builtins-config.h"]
7435 set contents [read $file]
7436 close $file
7437 append contents {
7438 #ifndef HAVE_C99_RUNTIME
7439 #error !HAVE_C99_RUNTIME
7440 #endif
7441 }
7442 check_no_compiler_messages_nocache c99_runtime assembly \
7443 $contents [add_options_for_c99_runtime ""]
7444 }]
7445 }
7446
7447 # Return 1 if target wchar_t is at least 4 bytes.
7448
7449 proc check_effective_target_4byte_wchar_t { } {
7450 return [check_no_compiler_messages 4byte_wchar_t object {
7451 int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
7452 }]
7453 }
7454
7455 # Return 1 if the target supports automatic stack alignment.
7456
7457 proc check_effective_target_automatic_stack_alignment { } {
7458 # Ordinarily x86 supports automatic stack alignment ...
7459 if { [istarget i?86*-*-*] || [istarget x86_64-*-*] } then {
7460 if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
7461 # ... except Win64 SEH doesn't. Succeed for Win32 though.
7462 return [check_effective_target_ilp32];
7463 }
7464 return 1;
7465 }
7466 return 0;
7467 }
7468
7469 # Return true if we are compiling for AVX target.
7470
7471 proc check_avx_available { } {
7472 if { [check_no_compiler_messages avx_available assembly {
7473 #ifndef __AVX__
7474 #error unsupported
7475 #endif
7476 } ""] } {
7477 return 1;
7478 }
7479 return 0;
7480 }
7481
7482 # Return true if 32- and 16-bytes vectors are available.
7483
7484 proc check_effective_target_vect_sizes_32B_16B { } {
7485 if { [check_avx_available] && ![check_prefer_avx128] } {
7486 return 1;
7487 } else {
7488 return 0;
7489 }
7490 }
7491
7492 # Return true if 128-bits vectors are preferred even if 256-bits vectors
7493 # are available.
7494
7495 proc check_prefer_avx128 { } {
7496 if ![check_avx_available] {
7497 return 0;
7498 }
7499 return [check_no_messages_and_pattern avx_explicit "xmm" assembly {
7500 float a[1024],b[1024],c[1024];
7501 void foo (void) { int i; for (i = 0; i < 1024; i++) a[i]=b[i]+c[i];}
7502 } "-O2 -ftree-vectorize"]
7503 }
7504
7505
7506 # Return 1 if avx512f instructions can be compiled.
7507
7508 proc check_effective_target_avx512f { } {
7509 return [check_no_compiler_messages avx512f object {
7510 typedef double __m512d __attribute__ ((__vector_size__ (64)));
7511
7512 __m512d _mm512_add (__m512d a)
7513 {
7514 return __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
7515 }
7516 } "-O2 -mavx512f" ]
7517 }
7518
7519 # Return 1 if avx instructions can be compiled.
7520
7521 proc check_effective_target_avx { } {
7522 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
7523 return 0
7524 }
7525 return [check_no_compiler_messages avx object {
7526 void _mm256_zeroall (void)
7527 {
7528 __builtin_ia32_vzeroall ();
7529 }
7530 } "-O2 -mavx" ]
7531 }
7532
7533 # Return 1 if avx2 instructions can be compiled.
7534 proc check_effective_target_avx2 { } {
7535 return [check_no_compiler_messages avx2 object {
7536 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
7537 __v4di
7538 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
7539 {
7540 return __builtin_ia32_andnotsi256 (__X, __Y);
7541 }
7542 } "-O0 -mavx2" ]
7543 }
7544
7545 # Return 1 if sse instructions can be compiled.
7546 proc check_effective_target_sse { } {
7547 return [check_no_compiler_messages sse object {
7548 int main ()
7549 {
7550 __builtin_ia32_stmxcsr ();
7551 return 0;
7552 }
7553 } "-O2 -msse" ]
7554 }
7555
7556 # Return 1 if sse2 instructions can be compiled.
7557 proc check_effective_target_sse2 { } {
7558 return [check_no_compiler_messages sse2 object {
7559 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7560
7561 __m128i _mm_srli_si128 (__m128i __A, int __N)
7562 {
7563 return (__m128i)__builtin_ia32_psrldqi128 (__A, 8);
7564 }
7565 } "-O2 -msse2" ]
7566 }
7567
7568 # Return 1 if sse4.1 instructions can be compiled.
7569 proc check_effective_target_sse4 { } {
7570 return [check_no_compiler_messages sse4.1 object {
7571 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7572 typedef int __v4si __attribute__ ((__vector_size__ (16)));
7573
7574 __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
7575 {
7576 return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
7577 (__v4si)__Y);
7578 }
7579 } "-O2 -msse4.1" ]
7580 }
7581
7582 # Return 1 if F16C instructions can be compiled.
7583
7584 proc check_effective_target_f16c { } {
7585 return [check_no_compiler_messages f16c object {
7586 #include "immintrin.h"
7587 float
7588 foo (unsigned short val)
7589 {
7590 return _cvtsh_ss (val);
7591 }
7592 } "-O2 -mf16c" ]
7593 }
7594
7595 # Return 1 if C wchar_t type is compatible with char16_t.
7596
7597 proc check_effective_target_wchar_t_char16_t_compatible { } {
7598 return [check_no_compiler_messages wchar_t_char16_t object {
7599 __WCHAR_TYPE__ wc;
7600 __CHAR16_TYPE__ *p16 = &wc;
7601 char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
7602 }]
7603 }
7604
7605 # Return 1 if C wchar_t type is compatible with char32_t.
7606
7607 proc check_effective_target_wchar_t_char32_t_compatible { } {
7608 return [check_no_compiler_messages wchar_t_char32_t object {
7609 __WCHAR_TYPE__ wc;
7610 __CHAR32_TYPE__ *p32 = &wc;
7611 char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
7612 }]
7613 }
7614
7615 # Return 1 if pow10 function exists.
7616
7617 proc check_effective_target_pow10 { } {
7618 return [check_runtime pow10 {
7619 #include <math.h>
7620 int main () {
7621 double x;
7622 x = pow10 (1);
7623 return 0;
7624 }
7625 } "-lm" ]
7626 }
7627
7628 # Return 1 if frexpl function exists.
7629
7630 proc check_effective_target_frexpl { } {
7631 return [check_runtime frexpl {
7632 #include <math.h>
7633 int main () {
7634 long double x;
7635 int y;
7636 x = frexpl (5.0, &y);
7637 return 0;
7638 }
7639 } "-lm" ]
7640 }
7641
7642
7643 # Return 1 if issignaling function exists.
7644 proc check_effective_target_issignaling {} {
7645 return [check_runtime issignaling {
7646 #define _GNU_SOURCE
7647 #include <math.h>
7648 int main ()
7649 {
7650 return issignaling (0.0);
7651 }
7652 } "-lm" ]
7653 }
7654
7655 # Return 1 if current options generate DFP instructions, 0 otherwise.
7656 proc check_effective_target_hard_dfp {} {
7657 return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
7658 typedef float d64 __attribute__((mode(DD)));
7659 d64 x, y, z;
7660 void foo (void) { z = x + y; }
7661 }]
7662 }
7663
7664 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
7665 # for strchr etc. functions.
7666
7667 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
7668 return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
7669 #include <string.h>
7670 #include <wchar.h>
7671 #if !defined(__cplusplus) \
7672 || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
7673 || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
7674 ISO C++ correct string.h and wchar.h protos not supported.
7675 #else
7676 int i;
7677 #endif
7678 }]
7679 }
7680
7681 # Return 1 if GNU as is used.
7682
7683 proc check_effective_target_gas { } {
7684 global use_gas_saved
7685 global tool
7686
7687 if {![info exists use_gas_saved]} {
7688 # Check if the as used by gcc is GNU as.
7689 set gcc_as [lindex [${tool}_target_compile "-print-prog-name=as" "" "none" ""] 0]
7690 # Provide /dev/null as input, otherwise gas times out reading from
7691 # stdin.
7692 set status [remote_exec host "$gcc_as" "-v /dev/null"]
7693 set as_output [lindex $status 1]
7694 if { [ string first "GNU" $as_output ] >= 0 } {
7695 set use_gas_saved 1
7696 } else {
7697 set use_gas_saved 0
7698 }
7699 }
7700 return $use_gas_saved
7701 }
7702
7703 # Return 1 if GNU ld is used.
7704
7705 proc check_effective_target_gld { } {
7706 global use_gld_saved
7707 global tool
7708
7709 if {![info exists use_gld_saved]} {
7710 # Check if the ld used by gcc is GNU ld.
7711 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
7712 set status [remote_exec host "$gcc_ld" "--version"]
7713 set ld_output [lindex $status 1]
7714 if { [ string first "GNU" $ld_output ] >= 0 } {
7715 set use_gld_saved 1
7716 } else {
7717 set use_gld_saved 0
7718 }
7719 }
7720 return $use_gld_saved
7721 }
7722
7723 # Return 1 if the compiler has been configure with link-time optimization
7724 # (LTO) support.
7725
7726 proc check_effective_target_lto { } {
7727 if { [istarget nvptx-*-*] } {
7728 return 0;
7729 }
7730 return [check_no_compiler_messages lto object {
7731 void foo (void) { }
7732 } "-flto"]
7733 }
7734
7735 # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
7736
7737 proc check_effective_target_maybe_x32 { } {
7738 return [check_no_compiler_messages maybe_x32 object {
7739 void foo (void) {}
7740 } "-mx32 -maddress-mode=short"]
7741 }
7742
7743 # Return 1 if this target supports the -fsplit-stack option, 0
7744 # otherwise.
7745
7746 proc check_effective_target_split_stack {} {
7747 return [check_no_compiler_messages split_stack object {
7748 void foo (void) { }
7749 } "-fsplit-stack"]
7750 }
7751
7752 # Return 1 if this target supports the -masm=intel option, 0
7753 # otherwise
7754
7755 proc check_effective_target_masm_intel {} {
7756 return [check_no_compiler_messages masm_intel object {
7757 extern void abort (void);
7758 } "-masm=intel"]
7759 }
7760
7761 # Return 1 if the language for the compiler under test is C.
7762
7763 proc check_effective_target_c { } {
7764 global tool
7765 if [string match $tool "gcc"] {
7766 return 1
7767 }
7768 return 0
7769 }
7770
7771 # Return 1 if the language for the compiler under test is C++.
7772
7773 proc check_effective_target_c++ { } {
7774 global tool
7775 if { [string match $tool "g++"] || [string match $tool "libstdc++"] } {
7776 return 1
7777 }
7778 return 0
7779 }
7780
7781 set cxx_default "c++14"
7782 # Check whether the current active language standard supports the features
7783 # of C++11/C++14 by checking for the presence of one of the -std flags.
7784 # This assumes that the default for the compiler is $cxx_default, and that
7785 # there will never be multiple -std= arguments on the command line.
7786 proc check_effective_target_c++11_only { } {
7787 global cxx_default
7788 if ![check_effective_target_c++] {
7789 return 0
7790 }
7791 if [check-flags { { } { } { -std=c++0x -std=gnu++0x -std=c++11 -std=gnu++11 } }] {
7792 return 1
7793 }
7794 if { $cxx_default == "c++11" && [check-flags { { } { } { } { -std=* } }] } {
7795 return 1
7796 }
7797 return 0
7798 }
7799 proc check_effective_target_c++11 { } {
7800 if [check_effective_target_c++11_only] {
7801 return 1
7802 }
7803 return [check_effective_target_c++14]
7804 }
7805 proc check_effective_target_c++11_down { } {
7806 if ![check_effective_target_c++] {
7807 return 0
7808 }
7809 return [expr ![check_effective_target_c++14] ]
7810 }
7811
7812 proc check_effective_target_c++14_only { } {
7813 global cxx_default
7814 if ![check_effective_target_c++] {
7815 return 0
7816 }
7817 if [check-flags { { } { } { -std=c++14 -std=gnu++14 -std=c++14 -std=gnu++14 } }] {
7818 return 1
7819 }
7820 if { $cxx_default == "c++14" && [check-flags { { } { } { } { -std=* } }] } {
7821 return 1
7822 }
7823 return 0
7824 }
7825
7826 proc check_effective_target_c++14 { } {
7827 if [check_effective_target_c++14_only] {
7828 return 1
7829 }
7830 return [check_effective_target_c++17]
7831 }
7832 proc check_effective_target_c++14_down { } {
7833 if ![check_effective_target_c++] {
7834 return 0
7835 }
7836 return [expr ![check_effective_target_c++17] ]
7837 }
7838
7839 proc check_effective_target_c++98_only { } {
7840 global cxx_default
7841 if ![check_effective_target_c++] {
7842 return 0
7843 }
7844 if [check-flags { { } { } { -std=c++98 -std=gnu++98 -std=c++03 -std=gnu++03 } }] {
7845 return 1
7846 }
7847 if { $cxx_default == "c++98" && [check-flags { { } { } { } { -std=* } }] } {
7848 return 1
7849 }
7850 return 0
7851 }
7852
7853 proc check_effective_target_c++17_only { } {
7854 global cxx_default
7855 if ![check_effective_target_c++] {
7856 return 0
7857 }
7858 if [check-flags { { } { } { -std=c++17 -std=gnu++17 -std=c++1z -std=gnu++1z } }] {
7859 return 1
7860 }
7861 if { $cxx_default == "c++17" && [check-flags { { } { } { } { -std=* } }] } {
7862 return 1
7863 }
7864 return 0
7865 }
7866
7867 proc check_effective_target_c++17 { } {
7868 if [check_effective_target_c++17_only] {
7869 return 1
7870 }
7871 return [check_effective_target_c++2a]
7872 }
7873 proc check_effective_target_c++17_down { } {
7874 if ![check_effective_target_c++] {
7875 return 0
7876 }
7877 return [expr ![check_effective_target_c++2a] ]
7878 }
7879
7880 proc check_effective_target_c++2a_only { } {
7881 global cxx_default
7882 if ![check_effective_target_c++] {
7883 return 0
7884 }
7885 if [check-flags { { } { } { -std=c++2a -std=gnu++2a } }] {
7886 return 1
7887 }
7888 if { $cxx_default == "c++20" && [check-flags { { } { } { } { -std=* } }] } {
7889 return 1
7890 }
7891 return 0
7892 }
7893 proc check_effective_target_c++2a { } {
7894 return [check_effective_target_c++2a_only]
7895 }
7896
7897 # Check for C++ Concepts TS support, i.e. -fconcepts flag.
7898 proc check_effective_target_concepts { } {
7899 return [check-flags { "" { } { -fconcepts } }]
7900 }
7901
7902 # Return 1 if expensive testcases should be run.
7903
7904 proc check_effective_target_run_expensive_tests { } {
7905 if { [getenv GCC_TEST_RUN_EXPENSIVE] != "" } {
7906 return 1
7907 }
7908 return 0
7909 }
7910
7911 # Returns 1 if "mempcpy" is available on the target system.
7912
7913 proc check_effective_target_mempcpy {} {
7914 return [check_function_available "mempcpy"]
7915 }
7916
7917 # Returns 1 if "stpcpy" is available on the target system.
7918
7919 proc check_effective_target_stpcpy {} {
7920 return [check_function_available "stpcpy"]
7921 }
7922
7923 # Check whether the vectorizer tests are supported by the target and
7924 # append additional target-dependent compile flags to DEFAULT_VECTCFLAGS.
7925 # If a port wants to execute the tests more than once it should append
7926 # the supported target to EFFECTIVE_TARGETS instead, and the compile flags
7927 # will be added by a call to add_options_for_<target>.
7928 # Set dg-do-what-default to either compile or run, depending on target
7929 # capabilities. Do not set this if the supported target is appended to
7930 # EFFECTIVE_TARGETS. Flags and this variable will be set by et-dg-runtest
7931 # automatically. Return the number of effective targets if vectorizer tests
7932 # are supported, 0 otherwise.
7933
7934 proc check_vect_support_and_set_flags { } {
7935 global DEFAULT_VECTCFLAGS
7936 global dg-do-what-default
7937 global EFFECTIVE_TARGETS
7938
7939 if [istarget powerpc-*paired*] {
7940 lappend DEFAULT_VECTCFLAGS "-mpaired"
7941 if [check_750cl_hw_available] {
7942 set dg-do-what-default run
7943 } else {
7944 set dg-do-what-default compile
7945 }
7946 } elseif [istarget powerpc*-*-*] {
7947 # Skip targets not supporting -maltivec.
7948 if ![is-effective-target powerpc_altivec_ok] {
7949 return 0
7950 }
7951
7952 lappend DEFAULT_VECTCFLAGS "-maltivec"
7953 if [check_p9vector_hw_available] {
7954 lappend DEFAULT_VECTCFLAGS "-mpower9-vector"
7955 } elseif [check_p8vector_hw_available] {
7956 lappend DEFAULT_VECTCFLAGS "-mpower8-vector"
7957 } elseif [check_vsx_hw_available] {
7958 lappend DEFAULT_VECTCFLAGS "-mvsx" "-mno-allow-movmisalign"
7959 }
7960
7961 if [check_vmx_hw_available] {
7962 set dg-do-what-default run
7963 } else {
7964 if [is-effective-target ilp32] {
7965 # Specify a cpu that supports VMX for compile-only tests.
7966 lappend DEFAULT_VECTCFLAGS "-mcpu=970"
7967 }
7968 set dg-do-what-default compile
7969 }
7970 } elseif { [istarget spu-*-*] } {
7971 set dg-do-what-default run
7972 } elseif { [istarget i?86-*-*] || [istarget x86_64-*-*] } {
7973 lappend DEFAULT_VECTCFLAGS "-msse2"
7974 if { [check_effective_target_sse2_runtime] } {
7975 set dg-do-what-default run
7976 } else {
7977 set dg-do-what-default compile
7978 }
7979 } elseif { [istarget mips*-*-*]
7980 && [check_effective_target_nomips16] } {
7981 if { [check_effective_target_mpaired_single] } {
7982 lappend EFFECTIVE_TARGETS mpaired_single
7983 }
7984 if { [check_effective_target_mips_loongson] } {
7985 lappend EFFECTIVE_TARGETS mips_loongson
7986 }
7987 if { [check_effective_target_mips_msa] } {
7988 lappend EFFECTIVE_TARGETS mips_msa
7989 }
7990 return [llength $EFFECTIVE_TARGETS]
7991 } elseif [istarget sparc*-*-*] {
7992 lappend DEFAULT_VECTCFLAGS "-mcpu=ultrasparc" "-mvis"
7993 if [check_effective_target_ultrasparc_hw] {
7994 set dg-do-what-default run
7995 } else {
7996 set dg-do-what-default compile
7997 }
7998 } elseif [istarget alpha*-*-*] {
7999 # Alpha's vectorization capabilities are extremely limited.
8000 # It's more effort than its worth disabling all of the tests
8001 # that it cannot pass. But if you actually want to see what
8002 # does work, command out the return.
8003 return 0
8004
8005 lappend DEFAULT_VECTCFLAGS "-mmax"
8006 if [check_alpha_max_hw_available] {
8007 set dg-do-what-default run
8008 } else {
8009 set dg-do-what-default compile
8010 }
8011 } elseif [istarget ia64-*-*] {
8012 set dg-do-what-default run
8013 } elseif [is-effective-target arm_neon_ok] {
8014 eval lappend DEFAULT_VECTCFLAGS [add_options_for_arm_neon ""]
8015 # NEON does not support denormals, so is not used for vectorization by
8016 # default to avoid loss of precision. We must pass -ffast-math to test
8017 # vectorization of float operations.
8018 lappend DEFAULT_VECTCFLAGS "-ffast-math"
8019 if [is-effective-target arm_neon_hw] {
8020 set dg-do-what-default run
8021 } else {
8022 set dg-do-what-default compile
8023 }
8024 } elseif [istarget "aarch64*-*-*"] {
8025 set dg-do-what-default run
8026 } else {
8027 return 0
8028 }
8029
8030 return 1
8031 }
8032
8033 # Return 1 if the target does *not* require strict alignment.
8034
8035 proc check_effective_target_non_strict_align {} {
8036
8037 # On ARM, the default is to use STRICT_ALIGNMENT, but there
8038 # are interfaces defined for misaligned access and thus
8039 # depending on the architecture levels unaligned access is
8040 # available.
8041 if [istarget "arm*-*-*"] {
8042 return [check_effective_target_arm_unaligned]
8043 }
8044
8045 return [check_no_compiler_messages non_strict_align assembly {
8046 char *y;
8047 typedef char __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) c;
8048 c *z;
8049 void foo(void) { z = (c *) y; }
8050 } "-Wcast-align"]
8051 }
8052
8053 # Return 1 if the target has <ucontext.h>.
8054
8055 proc check_effective_target_ucontext_h { } {
8056 return [check_no_compiler_messages ucontext_h assembly {
8057 #include <ucontext.h>
8058 }]
8059 }
8060
8061 proc check_effective_target_aarch64_tiny { } {
8062 if { [istarget aarch64*-*-*] } {
8063 return [check_no_compiler_messages aarch64_tiny object {
8064 #ifdef __AARCH64_CMODEL_TINY__
8065 int dummy;
8066 #else
8067 #error target not AArch64 tiny code model
8068 #endif
8069 }]
8070 } else {
8071 return 0
8072 }
8073 }
8074
8075 # Create functions to check that the AArch64 assembler supports the
8076 # various architecture extensions via the .arch_extension pseudo-op.
8077
8078 foreach { aarch64_ext } { "fp" "simd" "crypto" "crc" "lse"} {
8079 eval [string map [list FUNC $aarch64_ext] {
8080 proc check_effective_target_aarch64_asm_FUNC_ok { } {
8081 if { [istarget aarch64*-*-*] } {
8082 return [check_no_compiler_messages aarch64_FUNC_assembler object {
8083 __asm__ (".arch_extension FUNC");
8084 } "-march=armv8-a+FUNC"]
8085 } else {
8086 return 0
8087 }
8088 }
8089 }]
8090 }
8091
8092 proc check_effective_target_aarch64_small { } {
8093 if { [istarget aarch64*-*-*] } {
8094 return [check_no_compiler_messages aarch64_small object {
8095 #ifdef __AARCH64_CMODEL_SMALL__
8096 int dummy;
8097 #else
8098 #error target not AArch64 small code model
8099 #endif
8100 }]
8101 } else {
8102 return 0
8103 }
8104 }
8105
8106 proc check_effective_target_aarch64_large { } {
8107 if { [istarget aarch64*-*-*] } {
8108 return [check_no_compiler_messages aarch64_large object {
8109 #ifdef __AARCH64_CMODEL_LARGE__
8110 int dummy;
8111 #else
8112 #error target not AArch64 large code model
8113 #endif
8114 }]
8115 } else {
8116 return 0
8117 }
8118 }
8119
8120
8121 # Return 1 if this is a reduced AVR Tiny core. Such cores have different
8122 # register set, instruction set, addressing capabilities and ABI.
8123
8124 proc check_effective_target_avr_tiny { } {
8125 if { [istarget avr*-*-*] } {
8126 return [check_no_compiler_messages avr_tiny object {
8127 #ifdef __AVR_TINY__
8128 int dummy;
8129 #else
8130 #error target not a reduced AVR Tiny core
8131 #endif
8132 }]
8133 } else {
8134 return 0
8135 }
8136 }
8137
8138 # Return 1 if <fenv.h> is available with all the standard IEEE
8139 # exceptions and floating-point exceptions are raised by arithmetic
8140 # operations. (If the target requires special options for "inexact"
8141 # exceptions, those need to be specified in the testcases.)
8142
8143 proc check_effective_target_fenv_exceptions {} {
8144 return [check_runtime fenv_exceptions {
8145 #include <fenv.h>
8146 #include <stdlib.h>
8147 #ifndef FE_DIVBYZERO
8148 # error Missing FE_DIVBYZERO
8149 #endif
8150 #ifndef FE_INEXACT
8151 # error Missing FE_INEXACT
8152 #endif
8153 #ifndef FE_INVALID
8154 # error Missing FE_INVALID
8155 #endif
8156 #ifndef FE_OVERFLOW
8157 # error Missing FE_OVERFLOW
8158 #endif
8159 #ifndef FE_UNDERFLOW
8160 # error Missing FE_UNDERFLOW
8161 #endif
8162 volatile float a = 0.0f, r;
8163 int
8164 main (void)
8165 {
8166 r = a / a;
8167 if (fetestexcept (FE_INVALID))
8168 exit (0);
8169 else
8170 abort ();
8171 }
8172 } [add_options_for_ieee "-std=gnu99"]]
8173 }
8174
8175 proc check_effective_target_tiny {} {
8176 global et_target_tiny_saved
8177
8178 if [info exists et_target_tiny_saved] {
8179 verbose "check_effective_target_tiny: using cached result" 2
8180 } else {
8181 set et_target_tiny_saved 0
8182 if { [istarget aarch64*-*-*]
8183 && [check_effective_target_aarch64_tiny] } {
8184 set et_target_tiny_saved 1
8185 }
8186 if { [istarget avr-*-*]
8187 && [check_effective_target_avr_tiny] } {
8188 set et_target_tiny_saved 1
8189 }
8190 }
8191
8192 return $et_target_tiny_saved
8193 }
8194
8195 # Return 1 if LOGICAL_OP_NON_SHORT_CIRCUIT is set to 0 for the current target.
8196
8197 proc check_effective_target_logical_op_short_circuit {} {
8198 if { [istarget mips*-*-*]
8199 || [istarget arc*-*-*]
8200 || [istarget avr*-*-*]
8201 || [istarget crisv32-*-*] || [istarget cris-*-*]
8202 || [istarget mmix-*-*]
8203 || [istarget s390*-*-*]
8204 || [istarget powerpc*-*-*]
8205 || [istarget nios2*-*-*]
8206 || [istarget riscv*-*-*]
8207 || [istarget visium-*-*]
8208 || [check_effective_target_arm_cortex_m] } {
8209 return 1
8210 }
8211 return 0
8212 }
8213
8214 # Record that dg-final test TEST requires convential compilation.
8215
8216 proc force_conventional_output_for { test } {
8217 if { [info proc $test] == "" } {
8218 perror "$test does not exist"
8219 exit 1
8220 }
8221 proc ${test}_required_options {} {
8222 global gcc_force_conventional_output
8223 return $gcc_force_conventional_output
8224 }
8225 }
8226
8227 # Return 1 if the x86-64 target supports PIE with copy reloc, 0
8228 # otherwise. Cache the result.
8229
8230 proc check_effective_target_pie_copyreloc { } {
8231 global pie_copyreloc_available_saved
8232 global tool
8233 global GCC_UNDER_TEST
8234
8235 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8236 return 0
8237 }
8238
8239 # Need auto-host.h to check linker support.
8240 if { ![file exists ../../auto-host.h ] } {
8241 return 0
8242 }
8243
8244 if [info exists pie_copyreloc_available_saved] {
8245 verbose "check_effective_target_pie_copyreloc returning saved $pie_copyreloc_available_saved" 2
8246 } else {
8247 # Set up and compile to see if linker supports PIE with copy
8248 # reloc. Include the current process ID in the file names to
8249 # prevent conflicts with invocations for multiple testsuites.
8250
8251 set src pie[pid].c
8252 set obj pie[pid].o
8253
8254 set f [open $src "w"]
8255 puts $f "#include \"../../auto-host.h\""
8256 puts $f "#if HAVE_LD_PIE_COPYRELOC == 0"
8257 puts $f "# error Linker does not support PIE with copy reloc."
8258 puts $f "#endif"
8259 close $f
8260
8261 verbose "check_effective_target_pie_copyreloc compiling testfile $src" 2
8262 set lines [${tool}_target_compile $src $obj object ""]
8263
8264 file delete $src
8265 file delete $obj
8266
8267 if [string match "" $lines] then {
8268 verbose "check_effective_target_pie_copyreloc testfile compilation passed" 2
8269 set pie_copyreloc_available_saved 1
8270 } else {
8271 verbose "check_effective_target_pie_copyreloc testfile compilation failed" 2
8272 set pie_copyreloc_available_saved 0
8273 }
8274 }
8275
8276 return $pie_copyreloc_available_saved
8277 }
8278
8279 # Return 1 if the x86 target supports R_386_GOT32X relocation, 0
8280 # otherwise. Cache the result.
8281
8282 proc check_effective_target_got32x_reloc { } {
8283 global got32x_reloc_available_saved
8284 global tool
8285 global GCC_UNDER_TEST
8286
8287 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8288 return 0
8289 }
8290
8291 # Need auto-host.h to check linker support.
8292 if { ![file exists ../../auto-host.h ] } {
8293 return 0
8294 }
8295
8296 if [info exists got32x_reloc_available_saved] {
8297 verbose "check_effective_target_got32x_reloc returning saved $got32x_reloc_available_saved" 2
8298 } else {
8299 # Include the current process ID in the file names to prevent
8300 # conflicts with invocations for multiple testsuites.
8301
8302 set src got32x[pid].c
8303 set obj got32x[pid].o
8304
8305 set f [open $src "w"]
8306 puts $f "#include \"../../auto-host.h\""
8307 puts $f "#if HAVE_AS_IX86_GOT32X == 0"
8308 puts $f "# error Assembler does not support R_386_GOT32X."
8309 puts $f "#endif"
8310 close $f
8311
8312 verbose "check_effective_target_got32x_reloc compiling testfile $src" 2
8313 set lines [${tool}_target_compile $src $obj object ""]
8314
8315 file delete $src
8316 file delete $obj
8317
8318 if [string match "" $lines] then {
8319 verbose "check_effective_target_got32x_reloc testfile compilation passed" 2
8320 set got32x_reloc_available_saved 1
8321 } else {
8322 verbose "check_effective_target_got32x_reloc testfile compilation failed" 2
8323 set got32x_reloc_available_saved 0
8324 }
8325 }
8326
8327 return $got32x_reloc_available_saved
8328 }
8329
8330 # Return 1 if the x86 target supports calling ___tls_get_addr via GOT,
8331 # 0 otherwise. Cache the result.
8332
8333 proc check_effective_target_tls_get_addr_via_got { } {
8334 global tls_get_addr_via_got_available_saved
8335 global tool
8336 global GCC_UNDER_TEST
8337
8338 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8339 return 0
8340 }
8341
8342 # Need auto-host.h to check linker support.
8343 if { ![file exists ../../auto-host.h ] } {
8344 return 0
8345 }
8346
8347 if [info exists tls_get_addr_via_got_available_saved] {
8348 verbose "check_effective_target_tls_get_addr_via_got returning saved $tls_get_addr_via_got_available_saved" 2
8349 } else {
8350 # Include the current process ID in the file names to prevent
8351 # conflicts with invocations for multiple testsuites.
8352
8353 set src tls_get_addr_via_got[pid].c
8354 set obj tls_get_addr_via_got[pid].o
8355
8356 set f [open $src "w"]
8357 puts $f "#include \"../../auto-host.h\""
8358 puts $f "#if HAVE_AS_IX86_TLS_GET_ADDR_GOT == 0"
8359 puts $f "# error Assembler/linker do not support calling ___tls_get_addr via GOT."
8360 puts $f "#endif"
8361 close $f
8362
8363 verbose "check_effective_target_tls_get_addr_via_got compiling testfile $src" 2
8364 set lines [${tool}_target_compile $src $obj object ""]
8365
8366 file delete $src
8367 file delete $obj
8368
8369 if [string match "" $lines] then {
8370 verbose "check_effective_target_tls_get_addr_via_got testfile compilation passed" 2
8371 set tls_get_addr_via_got_available_saved 1
8372 } else {
8373 verbose "check_effective_target_tls_get_addr_via_got testfile compilation failed" 2
8374 set tls_get_addr_via_got_available_saved 0
8375 }
8376 }
8377
8378 return $tls_get_addr_via_got_available_saved
8379 }
8380
8381 # Return 1 if the target uses comdat groups.
8382
8383 proc check_effective_target_comdat_group {} {
8384 return [check_no_messages_and_pattern comdat_group "\.section\[^\n\r]*,comdat" assembly {
8385 // C++
8386 inline int foo () { return 1; }
8387 int (*fn) () = foo;
8388 }]
8389 }
8390
8391 # Return 1 if target supports __builtin_eh_return
8392 proc check_effective_target_builtin_eh_return { } {
8393 return [check_no_compiler_messages builtin_eh_return object {
8394 void test (long l, void *p)
8395 {
8396 __builtin_eh_return (l, p);
8397 }
8398 } "" ]
8399 }
8400
8401 # Return 1 if the target supports max reduction for vectors.
8402
8403 proc check_effective_target_vect_max_reduc { } {
8404 if { [istarget aarch64*-*-*] || [is-effective-target arm_neon] } {
8405 return 1
8406 }
8407 return 0
8408 }
8409
8410 # Return 1 if there is an nvptx offload compiler.
8411
8412 proc check_effective_target_offload_nvptx { } {
8413 return [check_no_compiler_messages offload_nvptx object {
8414 int main () {return 0;}
8415 } "-foffload=nvptx-none" ]
8416 }
8417
8418 # Return 1 if the compiler has been configured with hsa offloading.
8419
8420 proc check_effective_target_offload_hsa { } {
8421 return [check_no_compiler_messages offload_hsa assembly {
8422 int main () {return 0;}
8423 } "-foffload=hsa" ]
8424 }
8425
8426 # Return 1 if the target support -fprofile-update=atomic
8427 proc check_effective_target_profile_update_atomic {} {
8428 return [check_no_compiler_messages profile_update_atomic assembly {
8429 int main (void) { return 0; }
8430 } "-fprofile-update=atomic -fprofile-generate"]
8431 }
8432
8433 # Return 1 if vector (va - vector add) instructions are understood by
8434 # the assembler and can be executed. This also covers checking for
8435 # the VX kernel feature. A kernel without that feature does not
8436 # enable the vector facility and the following check will die with a
8437 # signal.
8438 proc check_effective_target_s390_vx { } {
8439 if ![istarget s390*-*-*] then {
8440 return 0;
8441 }
8442
8443 return [check_runtime s390_check_vx {
8444 int main (void)
8445 {
8446 asm ("va %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
8447 return 0;
8448 }
8449 } "-march=z13 -mzarch" ]
8450 }
8451
8452 # Same as above but for the arch12 vector enhancement facility. Test
8453 # is performed with the vector nand instruction.
8454 proc check_effective_target_s390_vxe { } {
8455 if ![istarget s390*-*-*] then {
8456 return 0;
8457 }
8458
8459 return [check_runtime s390_check_vxe {
8460 int main (void)
8461 {
8462 asm ("vnn %%v24, %%v26, %%v28" : : : "v24", "v26", "v28");
8463 return 0;
8464 }
8465 } "-march=arch12 -mzarch" ]
8466 }
8467
8468 #For versions of ARM architectures that have hardware div insn,
8469 #disable the divmod transform
8470
8471 proc check_effective_target_arm_divmod_simode { } {
8472 return [check_no_compiler_messages arm_divmod assembly {
8473 #ifdef __ARM_ARCH_EXT_IDIV__
8474 #error has div insn
8475 #endif
8476 int i;
8477 }]
8478 }
8479
8480 # Return 1 if target supports divmod hardware insn or divmod libcall.
8481
8482 proc check_effective_target_divmod { } {
8483 #TODO: Add checks for all targets that have either hardware divmod insn
8484 # or define libfunc for divmod.
8485 if { [istarget arm*-*-*]
8486 || [istarget i?86-*-*] || [istarget x86_64-*-*] } {
8487 return 1
8488 }
8489 return 0
8490 }
8491
8492 # Return 1 if target supports divmod for SImode. The reason for
8493 # separating this from check_effective_target_divmod is that
8494 # some versions of ARM architecture define div instruction
8495 # only for simode, and for these archs, we do not want to enable
8496 # divmod transform for simode.
8497
8498 proc check_effective_target_divmod_simode { } {
8499 if { [istarget arm*-*-*] } {
8500 return [check_effective_target_arm_divmod_simode]
8501 }
8502
8503 return [check_effective_target_divmod]
8504 }
8505
8506 # Return 1 if store merging optimization is applicable for target.
8507 # Store merging is not profitable for targets like the avr which
8508 # can load/store only one byte at a time. Use int size as a proxy
8509 # for the number of bytes the target can write, and skip for targets
8510 # with a smallish (< 32) size.
8511
8512 proc check_effective_target_store_merge { } {
8513 if { [is-effective-target non_strict_align ] && [is-effective-target int32plus] } {
8514 return 1
8515 }
8516
8517 return 0
8518 }
8519
8520 # Return 1 if we're able to assemble rdrand
8521
8522 proc check_effective_target_rdrand { } {
8523 return [check_no_compiler_messages_nocache rdrand object {
8524 unsigned int
8525 __foo(void)
8526 {
8527 unsigned int val;
8528 __builtin_ia32_rdrand32_step(&val);
8529 return val;
8530 }
8531 } "-mrdrnd" ]
8532 }
8533
8534 # Return 1 if the target supports coprocessor instructions: cdp, ldc, ldcl,
8535 # stc, stcl, mcr and mrc.
8536 proc check_effective_target_arm_coproc1_ok_nocache { } {
8537 if { ![istarget arm*-*-*] } {
8538 return 0
8539 }
8540 return [check_no_compiler_messages_nocache arm_coproc1_ok assembly {
8541 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 4
8542 #error FOO
8543 #endif
8544 }]
8545 }
8546
8547 proc check_effective_target_arm_coproc1_ok { } {
8548 return [check_cached_effective_target arm_coproc1_ok \
8549 check_effective_target_arm_coproc1_ok_nocache]
8550 }
8551
8552 # Return 1 if the target supports all coprocessor instructions checked by
8553 # check_effective_target_arm_coproc1_ok in addition to the following: cdp2,
8554 # ldc2, ldc2l, stc2, stc2l, mcr2 and mrc2.
8555 proc check_effective_target_arm_coproc2_ok_nocache { } {
8556 if { ![check_effective_target_arm_coproc1_ok] } {
8557 return 0
8558 }
8559 return [check_no_compiler_messages_nocache arm_coproc2_ok assembly {
8560 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 5
8561 #error FOO
8562 #endif
8563 }]
8564 }
8565
8566 proc check_effective_target_arm_coproc2_ok { } {
8567 return [check_cached_effective_target arm_coproc2_ok \
8568 check_effective_target_arm_coproc2_ok_nocache]
8569 }
8570
8571 # Return 1 if the target supports all coprocessor instructions checked by
8572 # check_effective_target_arm_coproc2_ok in addition the following: mcrr and
8573 # mrrc.
8574 proc check_effective_target_arm_coproc3_ok_nocache { } {
8575 if { ![check_effective_target_arm_coproc2_ok] } {
8576 return 0
8577 }
8578 return [check_no_compiler_messages_nocache arm_coproc3_ok assembly {
8579 #if (__thumb__ && !__thumb2__) \
8580 || (__ARM_ARCH < 6 && !defined (__ARM_ARCH_5TE__))
8581 #error FOO
8582 #endif
8583 }]
8584 }
8585
8586 proc check_effective_target_arm_coproc3_ok { } {
8587 return [check_cached_effective_target arm_coproc3_ok \
8588 check_effective_target_arm_coproc3_ok_nocache]
8589 }
8590
8591 # Return 1 if the target supports all coprocessor instructions checked by
8592 # check_effective_target_arm_coproc3_ok in addition the following: mcrr2 and
8593 # mrcc2.
8594 proc check_effective_target_arm_coproc4_ok_nocache { } {
8595 if { ![check_effective_target_arm_coproc3_ok] } {
8596 return 0
8597 }
8598 return [check_no_compiler_messages_nocache arm_coproc4_ok assembly {
8599 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 6
8600 #error FOO
8601 #endif
8602 }]
8603 }
8604
8605 proc check_effective_target_arm_coproc4_ok { } {
8606 return [check_cached_effective_target arm_coproc4_ok \
8607 check_effective_target_arm_coproc4_ok_nocache]
8608 }
8609
8610 # Return 1 if the target supports the auto_inc_dec optimization pass.
8611 proc check_effective_target_autoincdec { } {
8612 if { ![check_no_compiler_messages auto_incdec assembly { void f () { }
8613 } "-O2 -fdump-rtl-auto_inc_dec" ] } {
8614 return 0
8615 }
8616
8617 set dumpfile [glob -nocomplain "auto_incdec[pid].c.\[0-9\]\[0-9\]\[0-9\]r.auto_inc_dec"]
8618 if { [file exists $dumpfile ] } {
8619 file delete $dumpfile
8620 return 1
8621 }
8622 return 0
8623 }
8624
8625 # Return 1 if the target has support for stack probing designed
8626 # to avoid stack-clash style attacks.
8627 #
8628 # This is used to restrict the stack-clash mitigation tests to
8629 # just those targets that have been explicitly supported.
8630 #
8631 # In addition to the prologue work on those targets, each target's
8632 # properties should be described in the functions below so that
8633 # tests do not become a mess of unreadable target conditions.
8634 #
8635 proc check_effective_target_supports_stack_clash_protection { } {
8636
8637 # Temporary until the target bits are fully ACK'd.
8638 # if { [istarget aarch*-*-*]
8639 # || [istarget s390*-*-*]
8640 # || [istarget powerpc*-*-*] || [istarget rs6000*-*-*] } {
8641 # return 1
8642 # }
8643
8644 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
8645 return 1
8646 }
8647 return 0
8648 }
8649
8650 # Return 1 if the target creates a frame pointer for non-leaf functions
8651 # Note we ignore cases where we apply tail call optimization here.
8652 proc check_effective_target_frame_pointer_for_non_leaf { } {
8653 if { [istarget aarch*-*-*] } {
8654 return 1
8655 }
8656 return 0
8657 }
8658
8659 # Return 1 if the target's calling sequence or its ABI
8660 # create implicit stack probes at or prior to function entry.
8661 proc check_effective_target_caller_implicit_probes { } {
8662
8663 # On x86/x86_64 the call instruction itself pushes the return
8664 # address onto the stack. That is an implicit probe of *sp.
8665 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
8666 return 1
8667 }
8668
8669 # On PPC, the ABI mandates that the address of the outer
8670 # frame be stored at *sp. Thus each allocation of stack
8671 # space is itself an implicit probe of *sp.
8672 if { [istarget powerpc*-*-*] || [istarget rs6000*-*-*] } {
8673 return 1
8674 }
8675
8676 # s390's ABI has a register save area allocated by the
8677 # caller for use by the callee. The mere existence does
8678 # not constitute a probe by the caller, but when the slots
8679 # used by the callee those stores are implicit probes.
8680 if { [istarget s390*-*-*] } {
8681 return 1
8682 }
8683
8684 # Not strictly true on aarch64, but we have agreed that we will
8685 # consider any function that pushes SP more than 3kbytes into
8686 # the guard page as broken. This essentially means that we can
8687 # consider the aarch64 as having a caller implicit probe at
8688 # *(sp + 1k).
8689 if { [istarget aarch64*-*-*] } {
8690 return 1;
8691 }
8692
8693 return 0
8694 }
8695
8696 # Targets that potentially realign the stack pointer often cause residual
8697 # stack allocations and make it difficult to elimination loops or residual
8698 # allocations for dynamic stack allocations
8699 proc check_effective_target_callee_realigns_stack { } {
8700 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
8701 return 1
8702 }
8703 return 0
8704 }