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