]> gcc.gnu.org Git - gcc.git/blob - gcc/testsuite/lib/target-supports.exp
Revert patch.
[gcc.git] / gcc / testsuite / lib / target-supports.exp
1 # Copyright (C) 1999-2021 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 # "// D" for D,
35 # "! Fortran" for Fortran code,
36 # "/* ObjC", for ObjC
37 # "// ObjC++" for ObjC++
38 # and "// Go" for Go
39 # If the tool is ObjC/ObjC++ then we overide the extension to .m/.mm to
40 # allow for ObjC/ObjC++ specific flags.
41
42 proc check_compile {basename type contents args} {
43 global tool
44 verbose "check_compile tool: $tool for $basename"
45
46 # Save additional_sources to avoid compiling testsuite's sources
47 # against check_compile's source.
48 global additional_sources
49 if [info exists additional_sources] {
50 set tmp_additional_sources "$additional_sources"
51 set additional_sources ""
52 }
53
54 if { [llength $args] > 0 } {
55 set options [list "additional_flags=[lindex $args 0]"]
56 } else {
57 set options ""
58 }
59 switch -glob -- $contents {
60 "*! Fortran*" { set src ${basename}[pid].f90 }
61 "*// C++*" { set src ${basename}[pid].cc }
62 "*// D*" { set src ${basename}[pid].d }
63 "*// ObjC++*" { set src ${basename}[pid].mm }
64 "*/* ObjC*" { set src ${basename}[pid].m }
65 "*// Go*" { set src ${basename}[pid].go }
66 default {
67 switch -- $tool {
68 "objc" { set src ${basename}[pid].m }
69 "obj-c++" { set src ${basename}[pid].mm }
70 default { set src ${basename}[pid].c }
71 }
72 }
73 }
74
75 set compile_type $type
76 switch -glob $type {
77 assembly { set output ${basename}[pid].s }
78 object { set output ${basename}[pid].o }
79 executable { set output ${basename}[pid].exe }
80 "rtl-*" {
81 set output ${basename}[pid].s
82 lappend options "additional_flags=-fdump-$type"
83 set compile_type assembly
84 }
85 }
86 set f [open $src "w"]
87 puts $f $contents
88 close $f
89 global compiler_flags
90 set save_compiler_flags $compiler_flags
91 set lines [${tool}_target_compile $src $output $compile_type "$options"]
92 set compiler_flags $save_compiler_flags
93 file delete $src
94
95 set scan_output $output
96 # Don't try folding this into the switch above; calling "glob" before the
97 # file is created won't work.
98 if [regexp "rtl-(.*)" $type dummy rtl_type] {
99 set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
100 file delete $output
101 }
102
103 # Restore additional_sources.
104 if [info exists additional_sources] {
105 set additional_sources "$tmp_additional_sources"
106 }
107
108 return [list $lines $scan_output]
109 }
110
111 proc current_target_name { } {
112 global target_info
113 if [info exists target_info(target,name)] {
114 set answer $target_info(target,name)
115 } else {
116 set answer ""
117 }
118 return $answer
119 }
120
121 # Implement an effective-target check for property PROP by invoking
122 # the Tcl command ARGS and seeing if it returns true.
123
124 proc check_cached_effective_target { prop args } {
125 global et_cache
126
127 set target [current_target_name]
128 if {![info exists et_cache($prop,$target)]} {
129 verbose "check_cached_effective_target $prop: checking $target" 2
130 if {[string is true -strict $args] || [string is false -strict $args]} {
131 error {check_cached_effective_target condition already evaluated; did you pass [...] instead of the expected {...}?}
132 } else {
133 set code [catch {uplevel eval $args} result]
134 if {$code != 0 && $code != 2} {
135 return -code $code $result
136 }
137 set et_cache($prop,$target) $result
138 }
139 }
140 set value $et_cache($prop,$target)
141 verbose "check_cached_effective_target $prop: returning $value for $target" 2
142 return $value
143 }
144
145 # Implements a version of check_cached_effective_target that also takes et_index
146 # into account when creating the key for the cache.
147 proc check_cached_effective_target_indexed { prop args } {
148 global et_index
149 set key "$et_index $prop"
150 verbose "check_cached_effective_target_index $prop: returning $key" 2
151
152 return [check_cached_effective_target $key [list uplevel eval $args]]
153 }
154
155 # Clear effective-target cache. This is useful after testing
156 # effective-target features and overriding TEST_ALWAYS_FLAGS and/or
157 # ALWAYS_CXXFLAGS.
158 # If one changes ALWAYS_CXXFLAGS or TEST_ALWAYS_FLAGS then they should
159 # do a clear_effective_target_cache at the end as the target cache can
160 # make decisions based upon the flags, and those decisions need to be
161 # redone when the flags change. An example of this is the
162 # asan_init/asan_finish pair.
163
164 proc clear_effective_target_cache { } {
165 global et_cache
166 array unset et_cache
167 }
168
169 # Like check_compile, but delete the output file and return true if the
170 # compiler printed no messages.
171 proc check_no_compiler_messages_nocache {args} {
172 set result [eval check_compile $args]
173 set lines [lindex $result 0]
174 set output [lindex $result 1]
175 remote_file build delete $output
176 return [string match "" $lines]
177 }
178
179 # Like check_no_compiler_messages_nocache, but cache the result.
180 # PROP is the property we're checking, and doubles as a prefix for
181 # temporary filenames.
182 proc check_no_compiler_messages {prop args} {
183 return [check_cached_effective_target $prop {
184 eval [list check_no_compiler_messages_nocache $prop] $args
185 }]
186 }
187
188 # Like check_compile, but return true if the compiler printed no
189 # messages and if the contents of the output file satisfy PATTERN.
190 # If PATTERN has the form "!REGEXP", the contents satisfy it if they
191 # don't match regular expression REGEXP, otherwise they satisfy it
192 # if they do match regular expression PATTERN. (PATTERN can start
193 # with something like "[!]" if the regular expression needs to match
194 # "!" as the first character.)
195 #
196 # Delete the output file before returning. The other arguments are
197 # as for check_compile.
198 proc check_no_messages_and_pattern_nocache {basename pattern args} {
199 global tool
200
201 set result [eval [list check_compile $basename] $args]
202 set lines [lindex $result 0]
203 set output [lindex $result 1]
204
205 set ok 0
206 if { [string match "" $lines] } {
207 set chan [open "$output"]
208 set invert [regexp {^!(.*)} $pattern dummy pattern]
209 set ok [expr { [regexp $pattern [read $chan]] != $invert }]
210 close $chan
211 }
212
213 remote_file build delete $output
214 return $ok
215 }
216
217 # Like check_no_messages_and_pattern_nocache, but cache the result.
218 # PROP is the property we're checking, and doubles as a prefix for
219 # temporary filenames.
220 proc check_no_messages_and_pattern {prop pattern args} {
221 return [check_cached_effective_target $prop {
222 eval [list check_no_messages_and_pattern_nocache $prop $pattern] $args
223 }]
224 }
225
226 # Try to compile and run an executable from code CONTENTS. Return true
227 # if the compiler reports no messages and if execution "passes" in the
228 # usual DejaGNU sense. The arguments are as for check_compile, with
229 # TYPE implicitly being "executable".
230 proc check_runtime_nocache {basename contents args} {
231 global tool
232
233 set result [eval [list check_compile $basename executable $contents] $args]
234 set lines [lindex $result 0]
235 set output [lindex $result 1]
236
237 set ok 0
238 if { [string match "" $lines] } {
239 # No error messages, everything is OK.
240 set result [remote_load target "./$output" "" ""]
241 set status [lindex $result 0]
242 verbose "check_runtime_nocache $basename: status is <$status>" 2
243 if { $status == "pass" } {
244 set ok 1
245 }
246 }
247 remote_file build delete $output
248 return $ok
249 }
250
251 # Like check_runtime_nocache, but cache the result. PROP is the
252 # property we're checking, and doubles as a prefix for temporary
253 # filenames.
254 proc check_runtime {prop args} {
255 global tool
256
257 return [check_cached_effective_target $prop {
258 eval [list check_runtime_nocache $prop] $args
259 }]
260 }
261
262 # Return 1 if GCC was configured with $pattern.
263 proc check_configured_with { pattern } {
264 global tool
265
266 set options [list "additional_flags=-v"]
267 set gcc_output [${tool}_target_compile "" "" "none" $options]
268 if { [ regexp "Configured with: \[^\n\]*$pattern" $gcc_output ] } {
269 verbose "Matched: $pattern" 2
270 return 1
271 }
272
273 verbose "Failed to match: $pattern" 2
274 return 0
275 }
276
277 ###############################
278 # proc check_weak_available { }
279 ###############################
280
281 # weak symbols are only supported in some configs/object formats
282 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
283
284 proc check_weak_available { } {
285 global target_cpu
286
287 # All mips targets should support it
288
289 if { [ string first "mips" $target_cpu ] >= 0 } {
290 return 1
291 }
292
293 # All AIX targets should support it
294
295 if { [istarget *-*-aix*] } {
296 return 1
297 }
298
299 # All solaris2 targets should support it
300
301 if { [istarget *-*-solaris2*] } {
302 return 1
303 }
304
305 # Windows targets Cygwin and MingW32 support it
306
307 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
308 return 1
309 }
310
311 # HP-UX 10.X doesn't support it
312
313 if { [istarget hppa*-*-hpux10*] } {
314 return 0
315 }
316
317 # nvptx (nearly) supports it
318
319 if { [istarget nvptx-*-*] } {
320 return 1
321 }
322
323 # pdp11 doesn't support it
324
325 if { [istarget pdp11*-*-*] } {
326 return 0
327 }
328
329 # VxWorks hardly supports it (vx7 RTPs only)
330
331 if { [istarget *-*-vxworks*] } {
332 return 0
333 }
334
335 # ELF and ECOFF support it. a.out does with gas/gld but may also with
336 # other linkers, so we should try it
337
338 set objformat [gcc_target_object_format]
339
340 switch $objformat {
341 elf { return 1 }
342 ecoff { return 1 }
343 a.out { return 1 }
344 mach-o { return 1 }
345 som { return 1 }
346 unknown { return -1 }
347 default { return 0 }
348 }
349 }
350
351 # return 1 if weak undefined symbols are supported.
352
353 proc check_effective_target_weak_undefined { } {
354 if { [istarget hppa*-*-hpux*] } {
355 return 0
356 }
357 return [check_runtime weak_undefined {
358 extern void foo () __attribute__((weak));
359 int main (void) { if (foo) return 1; return 0; }
360 } ""]
361 }
362
363 ###############################
364 # proc check_weak_override_available { }
365 ###############################
366
367 # Like check_weak_available, but return 0 if weak symbol definitions
368 # cannot be overridden.
369
370 proc check_weak_override_available { } {
371 if { [istarget *-*-mingw*] } {
372 return 0
373 }
374 return [check_weak_available]
375 }
376
377 # The "noinit" attribute is only supported by some targets.
378 # This proc returns 1 if it's supported, 0 if it's not.
379
380 proc check_effective_target_noinit { } {
381 if { [istarget arm*-*-eabi]
382 || [istarget msp430-*-*] } {
383 return 1
384 }
385
386 return 0
387 }
388
389 # The "persistent" attribute is only supported by some targets.
390 # This proc returns 1 if it's supported, 0 if it's not.
391
392 proc check_effective_target_persistent { } {
393 if { [istarget arm*-*-eabi]
394 || [istarget msp430-*-*] } {
395 return 1
396 }
397
398 return 0
399 }
400
401 ###############################
402 # proc check_visibility_available { what_kind }
403 ###############################
404
405 # The visibility attribute is only support in some object formats
406 # This proc returns 1 if it is supported, 0 if not.
407 # The argument is the kind of visibility, default/protected/hidden/internal.
408
409 proc check_visibility_available { what_kind } {
410 if [string match "" $what_kind] { set what_kind "hidden" }
411
412 return [check_no_compiler_messages visibility_available_$what_kind object "
413 void f() __attribute__((visibility(\"$what_kind\")));
414 void f() {}
415 "]
416 }
417
418 ###############################
419 # proc check_alias_available { }
420 ###############################
421
422 # Determine if the target toolchain supports the alias attribute.
423
424 # Returns 2 if the target supports aliases. Returns 1 if the target
425 # only supports weak aliased. Returns 0 if the target does not
426 # support aliases at all. Returns -1 if support for aliases could not
427 # be determined.
428
429 proc check_alias_available { } {
430 global tool
431
432 return [check_cached_effective_target alias_available {
433 set src alias[pid].c
434 set obj alias[pid].o
435 verbose "check_alias_available compiling testfile $src" 2
436 set f [open $src "w"]
437 # Compile a small test program. The definition of "g" is
438 # necessary to keep the Solaris assembler from complaining
439 # about the program.
440 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
441 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
442 close $f
443 set lines [${tool}_target_compile $src $obj object ""]
444 file delete $src
445 remote_file build delete $obj
446
447 if [string match "" $lines] then {
448 # No error messages, everything is OK.
449 return 2
450 } else {
451 if [regexp "alias definitions not supported" $lines] {
452 verbose "check_alias_available target does not support aliases" 2
453
454 set objformat [gcc_target_object_format]
455
456 if { $objformat == "elf" } {
457 verbose "check_alias_available but target uses ELF format, so it ought to" 2
458 return -1
459 } else {
460 return 0
461 }
462 } else {
463 if [regexp "only weak aliases are supported" $lines] {
464 verbose "check_alias_available target supports only weak aliases" 2
465 return 1
466 } else {
467 return -1
468 }
469 }
470 }
471 }]
472 }
473
474 # Returns 1 if the target toolchain supports strong aliases, 0 otherwise.
475
476 proc check_effective_target_alias { } {
477 if { [check_alias_available] < 2 } {
478 return 0
479 } else {
480 return 1
481 }
482 }
483
484 # Returns 1 if the target toolchain supports ifunc, 0 otherwise.
485
486 proc check_ifunc_available { } {
487 return [check_no_compiler_messages ifunc_available object {
488 #ifdef __cplusplus
489 extern "C" {
490 #endif
491 extern void f_ ();
492 typedef void F (void);
493 F* g (void) { return &f_; }
494 void f () __attribute__ ((ifunc ("g")));
495 #ifdef __cplusplus
496 }
497 #endif
498 }]
499 }
500
501 # Returns true if --gc-sections is supported on the target.
502
503 proc check_gc_sections_available { } {
504 global tool
505
506 return [check_cached_effective_target gc_sections_available {
507 # Some targets don't support gc-sections despite whatever's
508 # advertised by ld's options.
509 if { [istarget alpha*-*-*]
510 || [istarget ia64-*-*] } {
511 return 0
512 }
513
514 # elf2flt uses -q (--emit-relocs), which is incompatible with
515 # --gc-sections.
516 if { [board_info target exists ldflags]
517 && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
518 return 0
519 }
520
521 # VxWorks kernel modules are relocatable objects linked with -r,
522 # while RTP executables are linked with -q (--emit-relocs).
523 # Both of these options are incompatible with --gc-sections.
524 if { [istarget *-*-vxworks*] } {
525 return 0
526 }
527
528 # Check if the ld used by gcc supports --gc-sections.
529 set options [list "additional_flags=-print-prog-name=ld"]
530 set gcc_ld [lindex [${tool}_target_compile "" "" "none" $options] 0]
531 set ld_output [remote_exec host "$gcc_ld" "--help"]
532 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
533 return 1
534 } else {
535 return 0
536 }
537 }]
538 }
539
540 # Returns 1 if "dot" is supported on the host.
541
542 proc check_dot_available { } {
543 verbose "check_dot_available" 2
544
545 set status [remote_exec host "dot" "-V"]
546 verbose " status: $status" 2
547 if { [lindex $status 0] != 0 } {
548 return 0
549 }
550 return 1
551 }
552
553 # Return 1 if according to target_info struct and explicit target list
554 # target is supposed to support trampolines.
555
556 proc check_effective_target_trampolines { } {
557 if [target_info exists gcc,no_trampolines] {
558 return 0
559 }
560 if { [istarget avr-*-*]
561 || [istarget msp430-*-*]
562 || [istarget nvptx-*-*]
563 || [istarget hppa2.0w-hp-hpux11.23]
564 || [istarget hppa64-hp-hpux11.23]
565 || [istarget pru-*-*]
566 || [istarget bpf-*-*] } {
567 return 0;
568 }
569 return 1
570 }
571
572 # Return 1 if target has limited stack size.
573
574 proc check_effective_target_stack_size { } {
575 if [target_info exists gcc,stack_size] {
576 return 1
577 }
578 return 0
579 }
580
581 # Return the value attribute of an effective target, otherwise return 0.
582
583 proc dg-effective-target-value { effective_target } {
584 if { "$effective_target" == "stack_size" } {
585 if [check_effective_target_stack_size] {
586 return [target_info gcc,stack_size]
587 }
588 }
589
590 return 0
591 }
592
593 # Return 1 if signal.h is supported.
594
595 proc check_effective_target_signal { } {
596 if [target_info exists gcc,signal_suppress] {
597 return 0
598 }
599 return 1
600 }
601
602 # Return 1 if according to target_info struct and explicit target list
603 # target disables -fdelete-null-pointer-checks. Targets should return 0
604 # if they simply default to -fno-delete-null-pointer-checks but obey
605 # -fdelete-null-pointer-checks when passed explicitly (and tests that
606 # depend on this option should do that).
607
608 proc check_effective_target_keeps_null_pointer_checks { } {
609 if [target_info exists keeps_null_pointer_checks] {
610 return 1
611 }
612 if { [istarget msp430-*-*] || [istarget cr16-*-*] } {
613 return 1;
614 }
615 return 0
616 }
617
618 # Return the autofdo profile wrapper
619
620 # Linux by default allows 516KB of perf event buffers
621 # in /proc/sys/kernel/perf_event_mlock_kb
622 # Each individual perf tries to grab it
623 # This causes problems with parallel test suite runs. Instead
624 # limit us to 8 pages (32K), which should be good enough
625 # for the small test programs. With the default settings
626 # this allows parallelism of 16 and higher of parallel gcc-auto-profile
627 proc profopt-perf-wrapper { } {
628 global srcdir
629 return "$srcdir/../config/i386/gcc-auto-profile -m8 "
630 }
631
632 # Return true if profiling is supported on the target.
633
634 proc check_profiling_available { test_what } {
635 verbose "Profiling argument is <$test_what>" 1
636
637 # These conditions depend on the argument so examine them before
638 # looking at the cache variable.
639
640 # Tree profiling requires TLS runtime support.
641 if { $test_what == "-fprofile-generate" } {
642 if { ![check_effective_target_tls_runtime] } {
643 return 0
644 }
645 }
646
647 if { $test_what == "-fauto-profile" } {
648 if { !([istarget i?86-*-linux*] || [istarget x86_64-*-linux*]) } {
649 verbose "autofdo only supported on linux"
650 return 0
651 }
652 # not cross compiling?
653 if { ![isnative] } {
654 verbose "autofdo not supported for non native builds"
655 return 0
656 }
657 set event [profopt-perf-wrapper]
658 if {$event == "" } {
659 verbose "autofdo not supported"
660 return 0
661 }
662 global srcdir
663 set status [remote_exec host "$srcdir/../config/i386/gcc-auto-profile" "-m8 true -v >/dev/null"]
664 if { [lindex $status 0] != 0 } {
665 verbose "autofdo not supported because perf does not work"
666 return 0
667 }
668
669 # no good way to check this in advance -- check later instead.
670 #set status [remote_exec host "create_gcov" "2>/dev/null"]
671 #if { [lindex $status 0] != 255 } {
672 # verbose "autofdo not supported due to missing create_gcov"
673 # return 0
674 #}
675 }
676
677 # Support for -p on solaris2 relies on mcrt1.o which comes with the
678 # vendor compiler. We cannot reliably predict the directory where the
679 # vendor compiler (and thus mcrt1.o) is installed so we can't
680 # necessarily find mcrt1.o even if we have it.
681 if { [istarget *-*-solaris2*] && $test_what == "-p" } {
682 return 0
683 }
684
685 # We don't yet support profiling for MIPS16.
686 if { [istarget mips*-*-*]
687 && ![check_effective_target_nomips16]
688 && ($test_what == "-p" || $test_what == "-pg") } {
689 return 0
690 }
691
692 # MinGW does not support -p.
693 if { [istarget *-*-mingw*] && $test_what == "-p" } {
694 return 0
695 }
696
697 # cygwin does not support -p.
698 if { [istarget *-*-cygwin*] && $test_what == "-p" } {
699 return 0
700 }
701
702 # uClibc does not have gcrt1.o.
703 if { [check_effective_target_uclibc]
704 && ($test_what == "-p" || $test_what == "-pg") } {
705 return 0
706 }
707
708 # Now examine the cache variable.
709 set profiling_working \
710 [check_cached_effective_target profiling_available {
711 # Some targets don't have any implementation of __bb_init_func or are
712 # missing other needed machinery.
713 if {[istarget aarch64*-*-elf]
714 || [istarget am3*-*-linux*]
715 || [istarget amdgcn-*-*]
716 || [istarget arm*-*-eabi*]
717 || [istarget arm*-*-elf]
718 || [istarget arm*-*-symbianelf*]
719 || [istarget avr-*-*]
720 || [istarget bfin-*-*]
721 || [istarget cris-*-*]
722 || [istarget csky-*-elf*]
723 || [istarget fido-*-elf]
724 || [istarget h8300-*-*]
725 || [istarget lm32-*-*]
726 || [istarget m32c-*-elf]
727 || [istarget m68k-*-elf]
728 || [istarget m68k-*-uclinux*]
729 || [istarget mips*-*-elf*]
730 || [istarget mmix-*-*]
731 || [istarget mn10300-*-elf*]
732 || [istarget moxie-*-elf*]
733 || [istarget msp430-*-*]
734 || [istarget nds32*-*-elf]
735 || [istarget nios2-*-elf]
736 || [istarget nvptx-*-*]
737 || [istarget powerpc-*-eabi*]
738 || [istarget powerpc-*-elf]
739 || [istarget pru-*-*]
740 || [istarget rx-*-*]
741 || [istarget tic6x-*-elf]
742 || [istarget visium-*-*]
743 || [istarget xstormy16-*]
744 || [istarget xtensa*-*-elf]
745 || [istarget *-*-rtems*]
746 || [istarget *-*-vxworks*] } {
747 return 0
748 } else {
749 return 1
750 }
751 }]
752
753 # -pg link test result can't be cached since it may change between
754 # runs.
755 if { $profiling_working == 1
756 && ![check_no_compiler_messages_nocache profiling executable {
757 int main() { return 0; } } "-pg"] } {
758 set profiling_working 0
759 }
760
761 return $profiling_working
762 }
763
764 # Check to see if a target is "freestanding". This is as per the definition
765 # in Section 4 of C99 standard. Effectively, it is a target which supports no
766 # extra headers or libraries other than what is considered essential.
767 proc check_effective_target_freestanding { } {
768 if { [istarget nvptx-*-*] } {
769 return 1
770 }
771 return 0
772 }
773
774 # Check to see that file I/O functions are available.
775 proc check_effective_target_fileio { } {
776 return [check_no_compiler_messages fileio_available executable {
777 #include <stdio.h>
778 int main() {
779 char *n = tmpnam (NULL);
780 FILE *f = fopen (n, "w");
781 fclose (f);
782 remove (n);
783 return 0;
784 } } ""]
785 }
786
787 # Return 1 if target has packed layout of structure members by
788 # default, 0 otherwise. Note that this is slightly different than
789 # whether the target has "natural alignment": both attributes may be
790 # false.
791
792 proc check_effective_target_default_packed { } {
793 return [check_no_compiler_messages default_packed assembly {
794 struct x { char a; long b; } c;
795 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
796 }]
797 }
798
799 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
800 # documentation, where the test also comes from.
801
802 proc check_effective_target_pcc_bitfield_type_matters { } {
803 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
804 # bitfields, but let's stick to the example code from the docs.
805 return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
806 struct foo1 { char x; char :0; char y; };
807 struct foo2 { char x; int :0; char y; };
808 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
809 }]
810 }
811
812 # Add to FLAGS all the target-specific flags needed to use thread-local storage.
813
814 proc add_options_for_tls { flags } {
815 # On Solaris 9, __tls_get_addr/___tls_get_addr only lives in
816 # libthread, so always pass -pthread for native TLS. Same for AIX.
817 # Need to duplicate native TLS check from
818 # check_effective_target_tls_native to avoid recursion.
819 if { ([istarget powerpc-ibm-aix*]) &&
820 [check_no_messages_and_pattern tls_native "!emutls" assembly {
821 __thread int i;
822 int f (void) { return i; }
823 void g (int j) { i = j; }
824 }] } {
825 return "-pthread [g++_link_flags [get_multilibs "-pthread"] ] $flags "
826 }
827 return $flags
828 }
829
830 # Return 1 if indirect jumps are supported, 0 otherwise.
831
832 proc check_effective_target_indirect_jumps {} {
833 if { [istarget nvptx-*-*] || [istarget bpf-*-*] } {
834 return 0
835 }
836 return 1
837 }
838
839 # Return 1 if nonlocal goto is supported, 0 otherwise.
840
841 proc check_effective_target_nonlocal_goto {} {
842 if { [istarget nvptx-*-*] || [istarget bpf-*-*] } {
843 return 0
844 }
845 return 1
846 }
847
848 # Return 1 if global constructors are supported, 0 otherwise.
849
850 proc check_effective_target_global_constructor {} {
851 if { [istarget nvptx-*-*]
852 || [istarget amdgcn-*-*]
853 || [istarget bpf-*-*] } {
854 return 0
855 }
856 return 1
857 }
858
859 # Return 1 if taking label values is supported, 0 otherwise.
860
861 proc check_effective_target_label_values {} {
862 if { [istarget nvptx-*-*] || [target_info exists gcc,no_label_values] } {
863 return 0
864 }
865
866 return 1
867 }
868
869 # Return 1 if builtin_return_address and builtin_frame_address are
870 # supported, 0 otherwise.
871
872 proc check_effective_target_return_address {} {
873 if { [istarget nvptx-*-*] } {
874 return 0
875 }
876 # No notion of return address in eBPF.
877 if { [istarget bpf-*-*] } {
878 return 0
879 }
880 # It could be supported on amdgcn, but isn't yet.
881 if { [istarget amdgcn*-*-*] } {
882 return 0
883 }
884 return 1
885 }
886
887 # Return 1 if the assembler does not verify function types against
888 # calls, 0 otherwise. Such verification will typically show up problems
889 # with K&R C function declarations.
890
891 proc check_effective_target_untyped_assembly {} {
892 if { [istarget nvptx-*-*] } {
893 return 0
894 }
895 return 1
896 }
897
898 # Return 1 if alloca is supported, 0 otherwise.
899
900 proc check_effective_target_alloca {} {
901 if { [istarget nvptx-*-*] } {
902 return [check_no_compiler_messages alloca assembly {
903 void f (void*);
904 void g (int n) { f (__builtin_alloca (n)); }
905 }]
906 }
907 return 1
908 }
909
910 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
911
912 proc check_effective_target_tls {} {
913 return [check_no_compiler_messages tls assembly {
914 __thread int i;
915 int f (void) { return i; }
916 void g (int j) { i = j; }
917 }]
918 }
919
920 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
921
922 proc check_effective_target_tls_native {} {
923 # VxWorks uses emulated TLS machinery, but with non-standard helper
924 # functions, so we fail to automatically detect it.
925 if { [istarget *-*-vxworks*] } {
926 return 0
927 }
928
929 return [check_no_messages_and_pattern tls_native "!emutls" assembly {
930 __thread int i;
931 int f (void) { return i; }
932 void g (int j) { i = j; }
933 }]
934 }
935
936 # Return 1 if *emulated* thread local storage (TLS) is supported, 0 otherwise.
937
938 proc check_effective_target_tls_emulated {} {
939 # VxWorks uses emulated TLS machinery, but with non-standard helper
940 # functions, so we fail to automatically detect it.
941 if { [istarget *-*-vxworks*] } {
942 return 1
943 }
944
945 return [check_no_messages_and_pattern tls_emulated "emutls" assembly {
946 __thread int i;
947 int f (void) { return i; }
948 void g (int j) { i = j; }
949 }]
950 }
951
952 # Return 1 if TLS executables can run correctly, 0 otherwise.
953
954 proc check_effective_target_tls_runtime {} {
955 return [check_runtime tls_runtime {
956 __thread int thr __attribute__((tls_model("global-dynamic"))) = 0;
957 int main (void) { return thr; }
958 } [add_options_for_tls ""]]
959 }
960
961 # Return 1 if atomic compare-and-swap is supported on 'int'
962
963 proc check_effective_target_cas_char {} {
964 return [check_no_compiler_messages cas_char assembly {
965 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
966 #error unsupported
967 #endif
968 } ""]
969 }
970
971 proc check_effective_target_cas_int {} {
972 return [check_no_compiler_messages cas_int assembly {
973 #if __INT_MAX__ == 0x7fff && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
974 /* ok */
975 #elif __INT_MAX__ == 0x7fffffff && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
976 /* ok */
977 #else
978 #error unsupported
979 #endif
980 } ""]
981 }
982
983 # Return 1 if -ffunction-sections is supported, 0 otherwise.
984
985 proc check_effective_target_function_sections {} {
986 # Darwin has its own scheme and silently accepts -ffunction-sections.
987 if { [istarget *-*-darwin*] } {
988 return 0
989 }
990
991 return [check_no_compiler_messages functionsections assembly {
992 void foo (void) { }
993 } "-ffunction-sections"]
994 }
995
996 # Return 1 if instruction scheduling is available, 0 otherwise.
997
998 proc check_effective_target_scheduling {} {
999 return [check_no_compiler_messages scheduling object {
1000 void foo (void) { }
1001 } "-fschedule-insns"]
1002 }
1003
1004 # Return 1 if trapping arithmetic is available, 0 otherwise.
1005
1006 proc check_effective_target_trapping {} {
1007 return [check_no_compiler_messages trapping object {
1008 int add (int a, int b) { return a + b; }
1009 } "-ftrapv"]
1010 }
1011
1012 # Return 1 if compilation with -fgraphite is error-free for trivial
1013 # code, 0 otherwise.
1014
1015 proc check_effective_target_fgraphite {} {
1016 return [check_no_compiler_messages fgraphite object {
1017 void foo (void) { }
1018 } "-O1 -fgraphite"]
1019 }
1020
1021 # Return 1 if compiled with --enable-offload-targets=
1022 # This affects host compilation as ENABLE_OFFLOAD then evaluates to true.
1023 proc check_effective_target_offloading_enabled {} {
1024 return [check_configured_with "--enable-offload-targets"]
1025 }
1026
1027 # Return 1 if compilation with -fopenacc is error-free for trivial
1028 # code, 0 otherwise.
1029
1030 proc check_effective_target_fopenacc {} {
1031 # nvptx/amdgcn can be built with the device-side bits of openacc, but it
1032 # does not make sense to test it as an openacc host.
1033 if [istarget nvptx-*-*] { return 0 }
1034 if [istarget amdgcn-*-*] { return 0 }
1035
1036 return [check_no_compiler_messages fopenacc object {
1037 void foo (void) { }
1038 } "-fopenacc"]
1039 }
1040
1041 # Return 1 if compilation with -fopenmp is error-free for trivial
1042 # code, 0 otherwise.
1043
1044 proc check_effective_target_fopenmp {} {
1045 # nvptx/amdgcn can be built with the device-side bits of libgomp, but it
1046 # does not make sense to test it as an openmp host.
1047 if [istarget nvptx-*-*] { return 0 }
1048 if [istarget amdgcn-*-*] { return 0 }
1049
1050 return [check_no_compiler_messages fopenmp object {
1051 void foo (void) { }
1052 } "-fopenmp"]
1053 }
1054
1055 # Return 1 if compilation with -fgnu-tm is error-free for trivial
1056 # code, 0 otherwise.
1057
1058 proc check_effective_target_fgnu_tm {} {
1059 return [check_no_compiler_messages fgnu_tm object {
1060 void foo (void) { }
1061 } "-fgnu-tm"]
1062 }
1063
1064 # Return 1 if the target supports mmap, 0 otherwise.
1065
1066 proc check_effective_target_mmap {} {
1067 return [check_function_available "mmap"]
1068 }
1069
1070 # Return 1 if the target supports sysconf, 0 otherwise.
1071
1072 proc check_effective_target_sysconf {} {
1073 return [check_function_available "sysconf"]
1074 }
1075
1076 # Return 1 if the target supports dlopen, 0 otherwise.
1077 proc check_effective_target_dlopen {} {
1078 return [check_no_compiler_messages dlopen executable {
1079 #include <dlfcn.h>
1080 int main(void) { dlopen ("dummy.so", RTLD_NOW); }
1081 } [add_options_for_dlopen ""]]
1082 }
1083
1084 proc add_options_for_dlopen { flags } {
1085 return "$flags -ldl"
1086 }
1087
1088 # Return 1 if the target supports clone, 0 otherwise.
1089 proc check_effective_target_clone {} {
1090 return [check_function_available "clone"]
1091 }
1092
1093 # Return 1 if the target supports setrlimit, 0 otherwise.
1094 proc check_effective_target_setrlimit {} {
1095 # Darwin has non-posix compliant RLIMIT_AS
1096 if { [istarget *-*-darwin*] } {
1097 return 0
1098 }
1099 return [check_function_available "setrlimit"]
1100 }
1101
1102 # Return 1 if the target supports gettimeofday, 0 otherwise.
1103 proc check_effective_target_gettimeofday {} {
1104 return [check_function_available "gettimeofday"]
1105 }
1106
1107 # Return 1 if the target supports swapcontext, 0 otherwise.
1108 proc check_effective_target_swapcontext {} {
1109 return [check_no_compiler_messages swapcontext executable {
1110 #include <ucontext.h>
1111 int main (void)
1112 {
1113 ucontext_t orig_context,child_context;
1114 if (swapcontext(&child_context, &orig_context) < 0) { }
1115 }
1116 }]
1117 }
1118
1119 # Return 1 if the target supports POSIX threads, 0 otherwise.
1120 proc check_effective_target_pthread {} {
1121 return [check_no_compiler_messages pthread object {
1122 #include <pthread.h>
1123 void foo (void) { }
1124 } "-pthread"]
1125 }
1126
1127 # Return 1 if compilation with -gstabs is error-free for trivial
1128 # code, 0 otherwise.
1129
1130 proc check_effective_target_stabs {} {
1131 return [check_no_compiler_messages stabs object {
1132 void foo (void) { }
1133 } "-gstabs"]
1134 }
1135
1136 # Return 1 if compilation with -mpe-aligned-commons is error-free
1137 # for trivial code, 0 otherwise.
1138
1139 proc check_effective_target_pe_aligned_commons {} {
1140 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
1141 return [check_no_compiler_messages pe_aligned_commons object {
1142 int foo;
1143 } "-mpe-aligned-commons"]
1144 }
1145 return 0
1146 }
1147
1148 # Return 1 if the target supports -static
1149 proc check_effective_target_static {} {
1150 if { [istarget arm*-*-uclinuxfdpiceabi] } {
1151 return 0;
1152 }
1153 return [check_no_compiler_messages static executable {
1154 int main (void) { return 0; }
1155 } "-static"]
1156 }
1157
1158 # Return 1 if the target supports -fstack-protector
1159 proc check_effective_target_fstack_protector {} {
1160 return [check_runtime fstack_protector {
1161 #include <string.h>
1162 int main (int argc, char *argv[]) {
1163 char buf[64];
1164 return !strcpy (buf, strrchr (argv[0], '/'));
1165 }
1166 } "-fstack-protector"]
1167 }
1168
1169 # Return 1 if the target supports -fstack-check or -fstack-check=$stack_kind
1170 proc check_stack_check_available { stack_kind } {
1171 if [string match "" $stack_kind] then {
1172 set stack_opt "-fstack-check"
1173 } else { set stack_opt "-fstack-check=$stack_kind" }
1174
1175 return [check_no_compiler_messages stack_check_$stack_kind executable {
1176 int main (void) { return 0; }
1177 } "$stack_opt"]
1178 }
1179
1180 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
1181 # for trivial code, 0 otherwise. As some targets (ARM for example) only
1182 # warn when -fprofile-use is also supplied we test that combination too.
1183
1184 proc check_effective_target_freorder {} {
1185 if { [check_no_compiler_messages freorder object {
1186 void foo (void) { }
1187 } "-freorder-blocks-and-partition"]
1188 && [check_no_compiler_messages fprofile_use_freorder object {
1189 void foo (void) { }
1190 } "-fprofile-use -freorder-blocks-and-partition -Wno-missing-profile"] } {
1191 return 1
1192 }
1193 return 0
1194 }
1195
1196 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
1197 # emitted, 0 otherwise. Whether a shared library can actually be built is
1198 # out of scope for this test.
1199
1200 proc check_effective_target_fpic { } {
1201 # Note that M68K has a multilib that supports -fpic but not
1202 # -fPIC, so we need to check both. We test with a program that
1203 # requires GOT references.
1204 foreach arg {fpic fPIC} {
1205 if [check_no_compiler_messages $arg object {
1206 extern int foo (void); extern int bar;
1207 int baz (void) { return foo () + bar; }
1208 } "-$arg"] {
1209 return 1
1210 }
1211 }
1212 return 0
1213 }
1214
1215 # On AArch64, if -fpic is not supported, then we will fall back to -fPIC
1216 # silently. So, we can't rely on above "check_effective_target_fpic" as it
1217 # assumes compiler will give warning if -fpic not supported. Here we check
1218 # whether binutils supports those new -fpic relocation modifiers, and assume
1219 # -fpic is supported if there is binutils support. GCC configuration will
1220 # enable -fpic for AArch64 in this case.
1221 #
1222 # "check_effective_target_aarch64_small_fpic" is dedicated for checking small
1223 # memory model -fpic relocation types.
1224
1225 proc check_effective_target_aarch64_small_fpic { } {
1226 if { [istarget aarch64*-*-*] } {
1227 return [check_no_compiler_messages aarch64_small_fpic object {
1228 void foo (void) { asm ("ldr x0, [x2, #:gotpage_lo15:globalsym]"); }
1229 }]
1230 } else {
1231 return 0
1232 }
1233 }
1234
1235 # On AArch64, instruction sequence for TLS LE under -mtls-size=32 will utilize
1236 # the relocation modifier "tprel_g0_nc" together with MOVK, it's only supported
1237 # in binutils since 2015-03-04 as PR gas/17843.
1238 #
1239 # This test directive make sure binutils support all features needed by TLS LE
1240 # under -mtls-size=32 on AArch64.
1241
1242 proc check_effective_target_aarch64_tlsle32 { } {
1243 if { [istarget aarch64*-*-*] } {
1244 return [check_no_compiler_messages aarch64_tlsle32 object {
1245 void foo (void) { asm ("movk x1,#:tprel_g0_nc:t1"); }
1246 }]
1247 } else {
1248 return 0
1249 }
1250 }
1251
1252 # Return 1 if -shared is supported, as in no warnings or errors
1253 # emitted, 0 otherwise.
1254
1255 proc check_effective_target_shared { } {
1256 # Note that M68K has a multilib that supports -fpic but not
1257 # -fPIC, so we need to check both. We test with a program that
1258 # requires GOT references.
1259 return [check_no_compiler_messages shared executable {
1260 extern int foo (void); extern int bar;
1261 int baz (void) { return foo () + bar; }
1262 } "-shared -fpic"]
1263 }
1264
1265 # Return 1 if -pie, -fpie and -fPIE are supported, 0 otherwise.
1266
1267 proc check_effective_target_pie { } {
1268 if { [istarget *-*-darwin\[912\]*]
1269 || [istarget *-*-dragonfly*]
1270 || [istarget *-*-freebsd*]
1271 || [istarget *-*-linux*]
1272 || [istarget arm*-*-uclinuxfdpiceabi]
1273 || [istarget *-*-gnu*]
1274 || [istarget *-*-amdhsa]} {
1275 return 1;
1276 }
1277 if { [istarget *-*-solaris2.1\[1-9\]*] } {
1278 # Full PIE support was added in Solaris 11.3, but gcc errors out
1279 # if missing, so check for that.
1280 return [check_no_compiler_messages pie executable {
1281 int main (void) { return 0; }
1282 } "-pie -fpie"]
1283 }
1284 return 0
1285 }
1286
1287 # Return true if the target supports -mpaired-single (as used on MIPS).
1288
1289 proc check_effective_target_mpaired_single { } {
1290 return [check_no_compiler_messages mpaired_single object {
1291 void foo (void) { }
1292 } "-mpaired-single"]
1293 }
1294
1295 # Return true if the target has access to FPU instructions.
1296
1297 proc check_effective_target_hard_float { } {
1298 if { [istarget mips*-*-*] } {
1299 return [check_no_compiler_messages hard_float assembly {
1300 #if (defined __mips_soft_float || defined __mips16)
1301 #error __mips_soft_float || __mips16
1302 #endif
1303 }]
1304 }
1305
1306 # This proc is actually checking the availabilty of FPU
1307 # support for doubles, so on the RX we must fail if the
1308 # 64-bit double multilib has been selected.
1309 if { [istarget rx-*-*] } {
1310 return 0
1311 # return [check_no_compiler_messages hard_float assembly {
1312 #if defined __RX_64_BIT_DOUBLES__
1313 #error __RX_64_BIT_DOUBLES__
1314 #endif
1315 # }]
1316 }
1317
1318 # The generic test doesn't work for C-SKY because some cores have
1319 # hard float for single precision only.
1320 if { [istarget csky*-*-*] } {
1321 return [check_no_compiler_messages hard_float assembly {
1322 #if defined __csky_soft_float__
1323 #error __csky_soft_float__
1324 #endif
1325 }]
1326 }
1327
1328 # The generic test equates hard_float with "no call for adding doubles".
1329 return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
1330 double a (double b, double c) { return b + c; }
1331 }]
1332 }
1333
1334 # Return true if the target is a 64-bit MIPS target.
1335
1336 proc check_effective_target_mips64 { } {
1337 return [check_no_compiler_messages mips64 assembly {
1338 #ifndef __mips64
1339 #error !__mips64
1340 #endif
1341 }]
1342 }
1343
1344 # Return true if the target is a MIPS target that does not produce
1345 # MIPS16 code.
1346
1347 proc check_effective_target_nomips16 { } {
1348 return [check_no_compiler_messages nomips16 object {
1349 #ifndef __mips
1350 #error !__mips
1351 #else
1352 /* A cheap way of testing for -mflip-mips16. */
1353 void foo (void) { asm ("addiu $20,$20,1"); }
1354 void bar (void) { asm ("addiu $20,$20,1"); }
1355 #endif
1356 }]
1357 }
1358
1359 # Add the options needed for MIPS16 function attributes. At the moment,
1360 # we don't support MIPS16 PIC.
1361
1362 proc add_options_for_mips16_attribute { flags } {
1363 return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
1364 }
1365
1366 # Return true if we can force a mode that allows MIPS16 code generation.
1367 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
1368 # for o32 and o64.
1369
1370 proc check_effective_target_mips16_attribute { } {
1371 return [check_no_compiler_messages mips16_attribute assembly {
1372 #ifdef PIC
1373 #error PIC
1374 #endif
1375 #if defined __mips_hard_float \
1376 && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
1377 && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
1378 #error __mips_hard_float && (!_ABIO32 || !_ABIO64)
1379 #endif
1380 } [add_options_for_mips16_attribute ""]]
1381 }
1382
1383 # Return 1 if the target supports long double larger than double when
1384 # using the new ABI, 0 otherwise.
1385
1386 proc check_effective_target_mips_newabi_large_long_double { } {
1387 return [check_no_compiler_messages mips_newabi_large_long_double object {
1388 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1389 } "-mabi=64"]
1390 }
1391
1392 # Return true if the target is a MIPS target that has access
1393 # to the LL and SC instructions.
1394
1395 proc check_effective_target_mips_llsc { } {
1396 if { ![istarget mips*-*-*] } {
1397 return 0
1398 }
1399 # Assume that these instructions are always implemented for
1400 # non-elf* targets, via emulation if necessary.
1401 if { ![istarget *-*-elf*] } {
1402 return 1
1403 }
1404 # Otherwise assume LL/SC support for everything but MIPS I.
1405 return [check_no_compiler_messages mips_llsc assembly {
1406 #if __mips == 1
1407 #error __mips == 1
1408 #endif
1409 }]
1410 }
1411
1412 # Return true if the target is a MIPS target that uses in-place relocations.
1413
1414 proc check_effective_target_mips_rel { } {
1415 if { ![istarget mips*-*-*] } {
1416 return 0
1417 }
1418 return [check_no_compiler_messages mips_rel object {
1419 #if (defined _ABIN32 && _MIPS_SIM == _ABIN32) \
1420 || (defined _ABI64 && _MIPS_SIM == _ABI64)
1421 #error _ABIN32 && (_ABIN32 || _ABI64)
1422 #endif
1423 }]
1424 }
1425
1426 # Return true if the target is a MIPS target that uses the EABI.
1427
1428 proc check_effective_target_mips_eabi { } {
1429 if { ![istarget mips*-*-*] } {
1430 return 0
1431 }
1432 return [check_no_compiler_messages mips_eabi object {
1433 #ifndef __mips_eabi
1434 #error !__mips_eabi
1435 #endif
1436 }]
1437 }
1438
1439 # Return 1 if the current multilib does not generate PIC by default.
1440
1441 proc check_effective_target_nonpic { } {
1442 return [check_no_compiler_messages nonpic assembly {
1443 #if __PIC__
1444 #error __PIC__
1445 #endif
1446 }]
1447 }
1448
1449 # Return 1 if the current multilib generates PIE by default.
1450
1451 proc check_effective_target_pie_enabled { } {
1452 return [check_no_compiler_messages pie_enabled assembly {
1453 #ifndef __PIE__
1454 #error unsupported
1455 #endif
1456 }]
1457 }
1458
1459 # Return 1 if the target generates -fstack-protector by default.
1460
1461 proc check_effective_target_fstack_protector_enabled {} {
1462 return [ check_no_compiler_messages fstack_protector_enabled assembly {
1463 #if !defined(__SSP__) && !defined(__SSP_ALL__) && \
1464 !defined(__SSP_STRONG__) && !defined(__SSP_EXPICIT__)
1465 #error unsupported
1466 #endif
1467 }]
1468 }
1469
1470 # Return 1 if the target does not use a status wrapper.
1471
1472 proc check_effective_target_unwrapped { } {
1473 if { [target_info needs_status_wrapper] != "" \
1474 && [target_info needs_status_wrapper] != "0" } {
1475 return 0
1476 }
1477 return 1
1478 }
1479
1480 # Return true if iconv is supported on the target. In particular IBM1047.
1481
1482 proc check_iconv_available { test_what } {
1483 global libiconv
1484
1485 # If the tool configuration file has not set libiconv, try "-liconv"
1486 if { ![info exists libiconv] } {
1487 set libiconv "-liconv"
1488 }
1489 set test_what [lindex $test_what 1]
1490 return [check_runtime_nocache $test_what [subst {
1491 #include <iconv.h>
1492 int main (void)
1493 {
1494 iconv_t cd;
1495
1496 cd = iconv_open ("$test_what", "UTF-8");
1497 if (cd == (iconv_t) -1)
1498 return 1;
1499 return 0;
1500 }
1501 }] $libiconv]
1502 }
1503
1504 # Return true if the atomic library is supported on the target.
1505 proc check_effective_target_libatomic_available { } {
1506 return [check_no_compiler_messages libatomic_available executable {
1507 int main (void) { return 0; }
1508 } "-latomic"]
1509 }
1510
1511 # Return 1 if an ASCII locale is supported on this host, 0 otherwise.
1512
1513 proc check_ascii_locale_available { } {
1514 return 1
1515 }
1516
1517 # Return true if named sections are supported on this target.
1518
1519 proc check_named_sections_available { } {
1520 return [check_no_compiler_messages named_sections assembly {
1521 int __attribute__ ((section("whatever"))) foo;
1522 }]
1523 }
1524
1525 # Return true if the "naked" function attribute is supported on this target.
1526
1527 proc check_effective_target_naked_functions { } {
1528 return [check_no_compiler_messages naked_functions assembly {
1529 void f() __attribute__((naked));
1530 }]
1531 }
1532
1533 # Return 1 if the target supports Fortran real kinds larger than real(8),
1534 # 0 otherwise.
1535 #
1536 # When the target name changes, replace the cached result.
1537
1538 proc check_effective_target_fortran_large_real { } {
1539 return [check_no_compiler_messages fortran_large_real executable {
1540 ! Fortran
1541 integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
1542 real(kind=k) :: x
1543 x = cos (x)
1544 end
1545 }]
1546 }
1547
1548 # Return 1 if the target supports Fortran real kind real(16),
1549 # 0 otherwise. Contrary to check_effective_target_fortran_large_real
1550 # this checks for Real(16) only; the other returned real(10) if
1551 # both real(10) and real(16) are available.
1552 #
1553 # When the target name changes, replace the cached result.
1554
1555 proc check_effective_target_fortran_real_16 { } {
1556 return [check_no_compiler_messages fortran_real_16 executable {
1557 ! Fortran
1558 real(kind=16) :: x
1559 x = cos (x)
1560 end
1561 }]
1562 }
1563
1564 # Return 1 if the target supports Fortran real kind 10,
1565 # 0 otherwise. Contrary to check_effective_target_fortran_large_real
1566 # this checks for real(10) only.
1567 #
1568 # When the target name changes, replace the cached result.
1569
1570 proc check_effective_target_fortran_real_10 { } {
1571 return [check_no_compiler_messages fortran_real_10 executable {
1572 ! Fortran
1573 real(kind=10) :: x
1574 x = cos (x)
1575 end
1576 }]
1577 }
1578
1579 # Return 1 if the target supports Fortran's IEEE modules,
1580 # 0 otherwise.
1581 #
1582 # When the target name changes, replace the cached result.
1583
1584 proc check_effective_target_fortran_ieee { flags } {
1585 return [check_no_compiler_messages fortran_ieee executable {
1586 ! Fortran
1587 use, intrinsic :: ieee_features
1588 end
1589 } $flags ]
1590 }
1591
1592
1593 # Return 1 if the target supports SQRT for the largest floating-point
1594 # type. (Some targets lack the libm support for this FP type.)
1595 # On most targets, this check effectively checks either whether sqrtl is
1596 # available or on __float128 systems whether libquadmath is installed,
1597 # which provides sqrtq.
1598 #
1599 # When the target name changes, replace the cached result.
1600
1601 proc check_effective_target_fortran_largest_fp_has_sqrt { } {
1602 return [check_no_compiler_messages fortran_largest_fp_has_sqrt executable {
1603 ! Fortran
1604 use iso_fortran_env, only: real_kinds
1605 integer,parameter:: maxFP = real_kinds(ubound(real_kinds,dim=1))
1606 real(kind=maxFP), volatile :: x
1607 x = 2.0_maxFP
1608 x = sqrt (x)
1609 end
1610 }]
1611 }
1612
1613
1614 # Return 1 if the target supports Fortran integer kinds larger than
1615 # integer(8), 0 otherwise.
1616 #
1617 # When the target name changes, replace the cached result.
1618
1619 proc check_effective_target_fortran_large_int { } {
1620 return [check_no_compiler_messages fortran_large_int executable {
1621 ! Fortran
1622 integer,parameter :: k = selected_int_kind (range (0_8) + 1)
1623 integer(kind=k) :: i
1624 end
1625 }]
1626 }
1627
1628 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
1629 #
1630 # When the target name changes, replace the cached result.
1631
1632 proc check_effective_target_fortran_integer_16 { } {
1633 return [check_no_compiler_messages fortran_integer_16 executable {
1634 ! Fortran
1635 integer(16) :: i
1636 end
1637 }]
1638 }
1639
1640 # Return 1 if we can statically link libgfortran, 0 otherwise.
1641 #
1642 # When the target name changes, replace the cached result.
1643
1644 proc check_effective_target_static_libgfortran { } {
1645 return [check_no_compiler_messages static_libgfortran executable {
1646 ! Fortran
1647 print *, 'test'
1648 end
1649 } "-static"]
1650 }
1651
1652 # Return 1 if we can use the -rdynamic option, 0 otherwise.
1653
1654 proc check_effective_target_rdynamic { } {
1655 return [check_no_compiler_messages rdynamic executable {
1656 int main() { return 0; }
1657 } "-rdynamic"]
1658 }
1659
1660 proc check_linker_plugin_available { } {
1661 return [check_no_compiler_messages_nocache linker_plugin executable {
1662 int main() { return 0; }
1663 } "-flto -fuse-linker-plugin"]
1664 }
1665
1666 # Return 1 if the target OS supports running SSE executables, 0
1667 # otherwise. Cache the result.
1668
1669 proc check_sse_os_support_available { } {
1670 return [check_cached_effective_target sse_os_support_available {
1671 # If this is not the right target then we can skip the test.
1672 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1673 expr 0
1674 } else {
1675 expr 1
1676 }
1677 }]
1678 }
1679
1680 # Return 1 if the target OS supports running AVX executables, 0
1681 # otherwise. Cache the result.
1682
1683 proc check_avx_os_support_available { } {
1684 return [check_cached_effective_target avx_os_support_available {
1685 # If this is not the right target then we can skip the test.
1686 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1687 expr 0
1688 } else {
1689 # Check that OS has AVX and SSE saving enabled.
1690 check_runtime_nocache avx_os_support_available {
1691 int main ()
1692 {
1693 unsigned int eax, edx;
1694
1695 asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
1696 return (eax & 0x06) != 0x06;
1697 }
1698 } ""
1699 }
1700 }]
1701 }
1702
1703 # Return 1 if the target OS supports running AVX executables, 0
1704 # otherwise. Cache the result.
1705
1706 proc check_avx512_os_support_available { } {
1707 return [check_cached_effective_target avx512_os_support_available {
1708 # If this is not the right target then we can skip the test.
1709 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1710 expr 0
1711 } else {
1712 # Check that OS has AVX512, AVX and SSE saving enabled.
1713 check_runtime_nocache avx512_os_support_available {
1714 int main ()
1715 {
1716 unsigned int eax, edx;
1717
1718 asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
1719 return (eax & 0xe6) != 0xe6;
1720 }
1721 } ""
1722 }
1723 }]
1724 }
1725
1726 # Return 1 if the target supports executing SSE instructions, 0
1727 # otherwise. Cache the result.
1728
1729 proc check_sse_hw_available { } {
1730 return [check_cached_effective_target sse_hw_available {
1731 # If this is not the right target then we can skip the test.
1732 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1733 expr 0
1734 } else {
1735 check_runtime_nocache sse_hw_available {
1736 #include "cpuid.h"
1737 int main ()
1738 {
1739 unsigned int eax, ebx, ecx, edx;
1740 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1741 return 1;
1742
1743 return !(edx & bit_SSE);
1744 }
1745 } ""
1746 }
1747 }]
1748 }
1749
1750 # Return 1 if the target supports executing SSE2 instructions, 0
1751 # otherwise. Cache the result.
1752
1753 proc check_sse2_hw_available { } {
1754 return [check_cached_effective_target sse2_hw_available {
1755 # If this is not the right target then we can skip the test.
1756 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1757 expr 0
1758 } else {
1759 check_runtime_nocache sse2_hw_available {
1760 #include "cpuid.h"
1761 int main ()
1762 {
1763 unsigned int eax, ebx, ecx, edx;
1764 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1765 return 1;
1766
1767 return !(edx & bit_SSE2);
1768 }
1769 } ""
1770 }
1771 }]
1772 }
1773
1774 # Return 1 if the target supports executing SSE4 instructions, 0
1775 # otherwise. Cache the result.
1776
1777 proc check_sse4_hw_available { } {
1778 return [check_cached_effective_target sse4_hw_available {
1779 # If this is not the right target then we can skip the test.
1780 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1781 expr 0
1782 } else {
1783 check_runtime_nocache sse4_hw_available {
1784 #include "cpuid.h"
1785 int main ()
1786 {
1787 unsigned int eax, ebx, ecx, edx;
1788 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1789 return 1;
1790
1791 return !(ecx & bit_SSE4_2);
1792 }
1793 } ""
1794 }
1795 }]
1796 }
1797
1798 # Return 1 if the target supports executing AVX instructions, 0
1799 # otherwise. Cache the result.
1800
1801 proc check_avx_hw_available { } {
1802 return [check_cached_effective_target avx_hw_available {
1803 # If this is not the right target then we can skip the test.
1804 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1805 expr 0
1806 } else {
1807 check_runtime_nocache avx_hw_available {
1808 #include "cpuid.h"
1809 int main ()
1810 {
1811 unsigned int eax, ebx, ecx, edx;
1812 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1813 return 1;
1814
1815 return ((ecx & (bit_AVX | bit_OSXSAVE))
1816 != (bit_AVX | bit_OSXSAVE));
1817 }
1818 } ""
1819 }
1820 }]
1821 }
1822
1823 # Return 1 if the target supports executing AVX2 instructions, 0
1824 # otherwise. Cache the result.
1825
1826 proc check_avx2_hw_available { } {
1827 return [check_cached_effective_target avx2_hw_available {
1828 # If this is not the right target then we can skip the test.
1829 if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1830 expr 0
1831 } else {
1832 check_runtime_nocache avx2_hw_available {
1833 #include <stddef.h>
1834 #include "cpuid.h"
1835 int main ()
1836 {
1837 unsigned int eax, ebx, ecx, edx;
1838
1839 if (__get_cpuid_max (0, NULL) < 7)
1840 return 1;
1841
1842 __cpuid (1, eax, ebx, ecx, edx);
1843
1844 if (!(ecx & bit_OSXSAVE))
1845 return 1;
1846
1847 __cpuid_count (7, 0, eax, ebx, ecx, edx);
1848
1849 return !(ebx & bit_AVX2);
1850 }
1851 } ""
1852 }
1853 }]
1854 }
1855
1856 # Return 1 if the target supports executing AVX512 foundation instructions, 0
1857 # otherwise. Cache the result.
1858
1859 proc check_avx512f_hw_available { } {
1860 return [check_cached_effective_target avx512f_hw_available {
1861 # If this is not the right target then we can skip the test.
1862 if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1863 expr 0
1864 } else {
1865 check_runtime_nocache avx512f_hw_available {
1866 #include <stddef.h>
1867 #include "cpuid.h"
1868 int main ()
1869 {
1870 unsigned int eax, ebx, ecx, edx;
1871
1872 if (__get_cpuid_max (0, NULL) < 7)
1873 return 1;
1874
1875 __cpuid (1, eax, ebx, ecx, edx);
1876
1877 if (!(ecx & bit_OSXSAVE))
1878 return 1;
1879
1880 __cpuid_count (7, 0, eax, ebx, ecx, edx);
1881
1882 return !(ebx & bit_AVX512F);
1883 }
1884 } ""
1885 }
1886 }]
1887 }
1888
1889 # Return 1 if the target supports running SSE executables, 0 otherwise.
1890
1891 proc check_effective_target_sse_runtime { } {
1892 if { [check_effective_target_sse]
1893 && [check_sse_hw_available]
1894 && [check_sse_os_support_available] } {
1895 return 1
1896 }
1897 return 0
1898 }
1899
1900 # Return 1 if the target supports running SSE2 executables, 0 otherwise.
1901
1902 proc check_effective_target_sse2_runtime { } {
1903 if { [check_effective_target_sse2]
1904 && [check_sse2_hw_available]
1905 && [check_sse_os_support_available] } {
1906 return 1
1907 }
1908 return 0
1909 }
1910
1911 # Return 1 if the target supports running SSE4 executables, 0 otherwise.
1912
1913 proc check_effective_target_sse4_runtime { } {
1914 if { [check_effective_target_sse4]
1915 && [check_sse4_hw_available]
1916 && [check_sse_os_support_available] } {
1917 return 1
1918 }
1919 return 0
1920 }
1921
1922 # Return 1 if the target supports running AVX executables, 0 otherwise.
1923
1924 proc check_effective_target_avx_runtime { } {
1925 if { [check_effective_target_avx]
1926 && [check_avx_hw_available]
1927 && [check_avx_os_support_available] } {
1928 return 1
1929 }
1930 return 0
1931 }
1932
1933 # Return 1 if the target supports running AVX2 executables, 0 otherwise.
1934
1935 proc check_effective_target_avx2_runtime { } {
1936 if { [check_effective_target_avx2]
1937 && [check_avx2_hw_available]
1938 && [check_avx_os_support_available] } {
1939 return 1
1940 }
1941 return 0
1942 }
1943
1944 # Return 1 if the target supports running AVX512f executables, 0 otherwise.
1945
1946 proc check_effective_target_avx512f_runtime { } {
1947 if { [check_effective_target_avx512f]
1948 && [check_avx512f_hw_available]
1949 && [check_avx512_os_support_available] } {
1950 return 1
1951 }
1952 return 0
1953 }
1954
1955 # Return 1 if bmi2 instructions can be compiled.
1956 proc check_effective_target_bmi2 { } {
1957 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
1958 return 0
1959 }
1960 return [check_no_compiler_messages bmi2 object {
1961 unsigned int
1962 _bzhi_u32 (unsigned int __X, unsigned int __Y)
1963 {
1964 return __builtin_ia32_bzhi_si (__X, __Y);
1965 }
1966 } "-mbmi2" ]
1967 }
1968
1969 # Return 1 if the target supports executing MIPS Paired-Single instructions,
1970 # 0 otherwise. Cache the result.
1971
1972 proc check_mpaired_single_hw_available { } {
1973 return [check_cached_effective_target mpaired_single_hw_available {
1974 # If this is not the right target then we can skip the test.
1975 if { !([istarget mips*-*-*]) } {
1976 expr 0
1977 } else {
1978 check_runtime_nocache mpaired_single_hw_available {
1979 int main()
1980 {
1981 asm volatile ("pll.ps $f2,$f4,$f6");
1982 return 0;
1983 }
1984 } ""
1985 }
1986 }]
1987 }
1988
1989 # Return 1 if the target supports executing Loongson vector instructions,
1990 # 0 otherwise. Cache the result.
1991
1992 proc check_mips_loongson_mmi_hw_available { } {
1993 return [check_cached_effective_target mips_loongson_mmi_hw_available {
1994 # If this is not the right target then we can skip the test.
1995 if { !([istarget mips*-*-*]) } {
1996 expr 0
1997 } else {
1998 check_runtime_nocache mips_loongson_mmi_hw_available {
1999 #include <loongson-mmiintrin.h>
2000 int main()
2001 {
2002 asm volatile ("paddw $f2,$f4,$f6");
2003 return 0;
2004 }
2005 } "-mloongson-mmi"
2006 }
2007 }]
2008 }
2009
2010 # Return 1 if the target supports executing MIPS MSA instructions, 0
2011 # otherwise. Cache the result.
2012
2013 proc check_mips_msa_hw_available { } {
2014 return [check_cached_effective_target mips_msa_hw_available {
2015 # If this is not the right target then we can skip the test.
2016 if { !([istarget mips*-*-*]) } {
2017 expr 0
2018 } else {
2019 check_runtime_nocache mips_msa_hw_available {
2020 #if !defined(__mips_msa)
2021 #error "MSA NOT AVAIL"
2022 #else
2023 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
2024 #error "MSA NOT AVAIL FOR ISA REV < 2"
2025 #endif
2026 #if !defined(__mips_hard_float)
2027 #error "MSA HARD_FLOAT REQUIRED"
2028 #endif
2029 #if __mips_fpr != 64
2030 #error "MSA 64-bit FPR REQUIRED"
2031 #endif
2032 #include <msa.h>
2033
2034 int main()
2035 {
2036 v8i16 v = __builtin_msa_ldi_h (0);
2037 v[0] = 0;
2038 return v[0];
2039 }
2040 #endif
2041 } "-mmsa"
2042 }
2043 }]
2044 }
2045
2046 # Return 1 if the target supports running MIPS Paired-Single
2047 # executables, 0 otherwise.
2048
2049 proc check_effective_target_mpaired_single_runtime { } {
2050 if { [check_effective_target_mpaired_single]
2051 && [check_mpaired_single_hw_available] } {
2052 return 1
2053 }
2054 return 0
2055 }
2056
2057 # Return 1 if the target supports running Loongson executables, 0 otherwise.
2058
2059 proc check_effective_target_mips_loongson_mmi_runtime { } {
2060 if { [check_effective_target_mips_loongson_mmi]
2061 && [check_mips_loongson_mmi_hw_available] } {
2062 return 1
2063 }
2064 return 0
2065 }
2066
2067 # Return 1 if the target supports running MIPS MSA executables, 0 otherwise.
2068
2069 proc check_effective_target_mips_msa_runtime { } {
2070 if { [check_effective_target_mips_msa]
2071 && [check_mips_msa_hw_available] } {
2072 return 1
2073 }
2074 return 0
2075 }
2076
2077 # Return 1 if we are compiling for 64-bit PowerPC but we do not use direct
2078 # move instructions for moves from GPR to FPR.
2079
2080 proc check_effective_target_powerpc64_no_dm { } {
2081 # The "mulld" checks if we are generating PowerPC64 code. The "lfd"
2082 # checks if we do not use direct moves, but use the old-fashioned
2083 # slower move-via-the-stack.
2084 return [check_no_messages_and_pattern powerpc64_no_dm \
2085 {\mmulld\M.*\mlfd} assembly {
2086 double f(long long x) { return x*x; }
2087 } {-O2}]
2088 }
2089
2090 # Return 1 if the target supports the __builtin_cpu_supports built-in,
2091 # including having a new enough library to support the test. Cache the result.
2092 # Require at least a power7 to run on.
2093
2094 proc check_ppc_cpu_supports_hw_available { } {
2095 return [check_cached_effective_target ppc_cpu_supports_hw_available {
2096 # Some simulators are known to not support VSX/power8 instructions.
2097 # For now, disable on Darwin
2098 if { [istarget powerpc-*-eabi]
2099 || [istarget powerpc*-*-eabispe]
2100 || [istarget *-*-darwin*]} {
2101 expr 0
2102 } else {
2103 set options "-mvsx"
2104 check_runtime_nocache ppc_cpu_supports_hw_available {
2105 int main()
2106 {
2107 #ifdef __MACH__
2108 asm volatile ("xxlor vs0,vs0,vs0");
2109 #else
2110 asm volatile ("xxlor 0,0,0");
2111 #endif
2112 if (!__builtin_cpu_supports ("vsx"))
2113 return 1;
2114 return 0;
2115 }
2116 } $options
2117 }
2118 }]
2119 }
2120
2121 # Return 1 if the target supports executing 750CL paired-single instructions, 0
2122 # otherwise. Cache the result.
2123
2124 proc check_750cl_hw_available { } {
2125 return [check_cached_effective_target 750cl_hw_available {
2126 # If this is not the right target then we can skip the test.
2127 if { ![istarget powerpc-*paired*] } {
2128 expr 0
2129 } else {
2130 check_runtime_nocache 750cl_hw_available {
2131 int main()
2132 {
2133 #ifdef __MACH__
2134 asm volatile ("ps_mul v0,v0,v0");
2135 #else
2136 asm volatile ("ps_mul 0,0,0");
2137 #endif
2138 return 0;
2139 }
2140 } "-mpaired"
2141 }
2142 }]
2143 }
2144
2145 # Return 1 if the target supports executing power8 vector instructions, 0
2146 # otherwise. Cache the result.
2147
2148 proc check_p8vector_hw_available { } {
2149 return [check_cached_effective_target p8vector_hw_available {
2150 # Some simulators are known to not support VSX/power8 instructions.
2151 # For now, disable on Darwin
2152 if { [istarget powerpc-*-eabi]
2153 || [istarget powerpc*-*-eabispe]
2154 || [istarget *-*-darwin*]} {
2155 expr 0
2156 } else {
2157 set options "-mpower8-vector"
2158 check_runtime_nocache p8vector_hw_available {
2159 int main()
2160 {
2161 #ifdef __MACH__
2162 asm volatile ("xxlorc vs0,vs0,vs0");
2163 #else
2164 asm volatile ("xxlorc 0,0,0");
2165 #endif
2166 return 0;
2167 }
2168 } $options
2169 }
2170 }]
2171 }
2172
2173 # Return 1 if the target supports executing power9 vector instructions, 0
2174 # otherwise. Cache the result.
2175
2176 proc check_p9vector_hw_available { } {
2177 return [check_cached_effective_target p9vector_hw_available {
2178 # Some simulators are known to not support VSX/power8/power9
2179 # instructions. For now, disable on Darwin.
2180 if { [istarget powerpc-*-eabi]
2181 || [istarget powerpc*-*-eabispe]
2182 || [istarget *-*-darwin*]} {
2183 expr 0
2184 } else {
2185 set options "-mpower9-vector"
2186 check_runtime_nocache p9vector_hw_available {
2187 int main()
2188 {
2189 long e = -1;
2190 vector double v = (vector double) { 0.0, 0.0 };
2191 asm ("xsxexpdp %0,%1" : "+r" (e) : "wa" (v));
2192 return e;
2193 }
2194 } $options
2195 }
2196 }]
2197 }
2198
2199 # Return 1 if the PowerPC target generates PC-relative instructions
2200 # automatically for targets that support PC-relative instructions.
2201 proc check_effective_target_powerpc_pcrel { } {
2202 return [check_no_messages_and_pattern powerpc_pcrel \
2203 {\mpla\M} assembly {
2204 static unsigned short s;
2205 unsigned short *p_foo (void) { return &s; }
2206 } {-O2 -mcpu=power10}]
2207 }
2208
2209 # Return 1 if the PowerPC target generates prefixed instructions automatically
2210 # for targets that support prefixed instructions.
2211 proc check_effective_target_powerpc_prefixed_addr { } {
2212 return [check_no_messages_and_pattern powerpc_prefixed_addr \
2213 {\mplwz\M} assembly {
2214 unsigned int foo (unsigned int *p) { return p[0x12345]; }
2215 } {-O2 -mcpu=power10}]
2216 }
2217
2218 # Return 1 if the target supports executing power9 modulo instructions, 0
2219 # otherwise. Cache the result.
2220
2221 proc check_p9modulo_hw_available { } {
2222 return [check_cached_effective_target p9modulo_hw_available {
2223 # Some simulators are known to not support VSX/power8/power9
2224 # instructions. For now, disable on Darwin.
2225 if { [istarget powerpc-*-eabi]
2226 || [istarget powerpc*-*-eabispe]
2227 || [istarget *-*-darwin*]} {
2228 expr 0
2229 } else {
2230 set options "-mmodulo"
2231 check_runtime_nocache p9modulo_hw_available {
2232 int main()
2233 {
2234 int i = 5, j = 3, r = -1;
2235 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
2236 return (r == 2);
2237 }
2238 } $options
2239 }
2240 }]
2241 }
2242
2243
2244 # Return 1 if the target supports executing power10 instructions, 0 otherwise.
2245 # Cache the result. It is assumed that if a simulator does not support the
2246 # power10 instructions, that it will generate an error and this test will fail.
2247
2248 proc check_power10_hw_available { } {
2249 return [check_cached_effective_target power10_hw_available {
2250 check_runtime_nocache power10_hw_available {
2251 int main()
2252 {
2253 /* Set e first and use +r to check if pli actually works. */
2254 long e = -1;
2255 asm ("pli %0,%1" : "+r" (e) : "n" (0x12345));
2256 if (e == 0x12345)
2257 return 0;
2258 return 1;
2259 }
2260 } "-mcpu=power10"
2261 }]
2262 }
2263
2264 # Return 1 if the target supports executing MMA instructions, 0 otherwise.
2265 # Cache the result. It is assumed that if a simulator does not support the
2266 # MMA instructions, that it will generate an error and this test will fail.
2267
2268 proc check_ppc_mma_hw_available { } {
2269 return [check_cached_effective_target ppc_mma_hw_available {
2270 check_runtime_nocache ppc_mma_hw_available {
2271 #include <altivec.h>
2272 typedef double v4sf_t __attribute__ ((vector_size (16)));
2273
2274 int main()
2275 {
2276 __vector_quad acc0;
2277 v4sf_t result[4];
2278 result[0][0] = 1.0;
2279 __builtin_mma_xxsetaccz (&acc0);
2280 __builtin_mma_disassemble_acc (result, &acc0);
2281 if (result[0][0] != 0.0)
2282 return 1;
2283 return 0;
2284 }
2285 } "-mcpu=power10"
2286 }]
2287 }
2288
2289 # Return 1 if the target supports executing __float128 on PowerPC via software
2290 # emulation, 0 otherwise. Cache the result.
2291
2292 proc check_ppc_float128_sw_available { } {
2293 return [check_cached_effective_target ppc_float128_sw_available {
2294 # Some simulators are known to not support VSX/power8/power9
2295 # instructions. For now, disable on Darwin.
2296 if { [istarget powerpc-*-eabi]
2297 || [istarget powerpc*-*-eabispe]
2298 || [istarget *-*-darwin*]} {
2299 expr 0
2300 } else {
2301 set options "-mfloat128 -mvsx"
2302 check_runtime_nocache ppc_float128_sw_available {
2303 volatile __float128 x = 1.0q;
2304 volatile __float128 y = 2.0q;
2305 int main()
2306 {
2307 __float128 z = x + y;
2308 return (z != 3.0q);
2309 }
2310 } $options
2311 }
2312 }]
2313 }
2314
2315 # Return 1 if the target supports executing __float128 on PowerPC via power9
2316 # hardware instructions, 0 otherwise. Cache the result.
2317
2318 proc check_ppc_float128_hw_available { } {
2319 return [check_cached_effective_target ppc_float128_hw_available {
2320 # Some simulators are known to not support VSX/power8/power9
2321 # instructions. For now, disable on Darwin.
2322 if { [istarget powerpc-*-eabi]
2323 || [istarget powerpc*-*-eabispe]
2324 || [istarget *-*-darwin*]} {
2325 expr 0
2326 } else {
2327 set options "-mfloat128 -mvsx -mfloat128-hardware -mpower9-vector"
2328 check_runtime_nocache ppc_float128_hw_available {
2329 volatile __float128 x = 1.0q;
2330 volatile __float128 y = 2.0q;
2331 int main()
2332 {
2333 __float128 z = x + y;
2334 __float128 w = -1.0q;
2335
2336 __asm__ ("xsaddqp %0,%1,%2" : "+v" (w) : "v" (x), "v" (y));
2337 return ((z != 3.0q) || (z != w));
2338 }
2339 } $options
2340 }
2341 }]
2342 }
2343
2344 # See if the __ieee128 keyword is understood.
2345 proc check_effective_target_ppc_ieee128_ok { } {
2346 return [check_cached_effective_target ppc_ieee128_ok {
2347 # disable on AIX.
2348 if { [istarget *-*-aix*] } {
2349 expr 0
2350 } else {
2351 set options "-mfloat128"
2352 check_runtime_nocache ppc_ieee128_ok {
2353 int main()
2354 {
2355 __ieee128 a;
2356 return 0;
2357 }
2358 } $options
2359 }
2360 }]
2361 }
2362
2363 # Return 1 if the target supports executing VSX instructions, 0
2364 # otherwise. Cache the result.
2365
2366 proc check_vsx_hw_available { } {
2367 return [check_cached_effective_target vsx_hw_available {
2368 # Some simulators are known to not support VSX instructions.
2369 # For now, disable on Darwin
2370 if { [istarget powerpc-*-eabi]
2371 || [istarget powerpc*-*-eabispe]
2372 || [istarget *-*-darwin*]} {
2373 expr 0
2374 } else {
2375 set options "-mvsx"
2376 check_runtime_nocache vsx_hw_available {
2377 int main()
2378 {
2379 #ifdef __MACH__
2380 asm volatile ("xxlor vs0,vs0,vs0");
2381 #else
2382 asm volatile ("xxlor 0,0,0");
2383 #endif
2384 return 0;
2385 }
2386 } $options
2387 }
2388 }]
2389 }
2390
2391 # Return 1 if the target supports executing AltiVec instructions, 0
2392 # otherwise. Cache the result.
2393
2394 proc check_vmx_hw_available { } {
2395 return [check_cached_effective_target vmx_hw_available {
2396 # Some simulators are known to not support VMX instructions.
2397 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2398 expr 0
2399 } else {
2400 # Most targets don't require special flags for this test case, but
2401 # Darwin does. Just to be sure, make sure VSX is not enabled for
2402 # the altivec tests.
2403 if { [istarget *-*-darwin*]
2404 || [istarget *-*-aix*] } {
2405 set options "-maltivec -mno-vsx"
2406 } else {
2407 set options "-mno-vsx"
2408 }
2409 check_runtime_nocache vmx_hw_available {
2410 int main()
2411 {
2412 #ifdef __MACH__
2413 asm volatile ("vor v0,v0,v0");
2414 #else
2415 asm volatile ("vor 0,0,0");
2416 #endif
2417 return 0;
2418 }
2419 } $options
2420 }
2421 }]
2422 }
2423
2424 proc check_ppc_recip_hw_available { } {
2425 return [check_cached_effective_target ppc_recip_hw_available {
2426 # Some simulators may not support FRE/FRES/FRSQRTE/FRSQRTES
2427 # For now, disable on Darwin
2428 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
2429 expr 0
2430 } else {
2431 set options "-mpowerpc-gfxopt -mpowerpc-gpopt -mpopcntb"
2432 check_runtime_nocache ppc_recip_hw_available {
2433 volatile double d_recip, d_rsqrt, d_four = 4.0;
2434 volatile float f_recip, f_rsqrt, f_four = 4.0f;
2435 int main()
2436 {
2437 asm volatile ("fres %0,%1" : "=f" (f_recip) : "f" (f_four));
2438 asm volatile ("fre %0,%1" : "=d" (d_recip) : "d" (d_four));
2439 asm volatile ("frsqrtes %0,%1" : "=f" (f_rsqrt) : "f" (f_four));
2440 asm volatile ("frsqrte %0,%1" : "=f" (d_rsqrt) : "d" (d_four));
2441 return 0;
2442 }
2443 } $options
2444 }
2445 }]
2446 }
2447
2448 # Return 1 if the target supports executing AltiVec and Cell PPU
2449 # instructions, 0 otherwise. Cache the result.
2450
2451 proc check_effective_target_cell_hw { } {
2452 return [check_cached_effective_target cell_hw_available {
2453 # Some simulators are known to not support VMX and PPU instructions.
2454 if { [istarget powerpc-*-eabi*] } {
2455 expr 0
2456 } else {
2457 # Most targets don't require special flags for this test
2458 # case, but Darwin and AIX do.
2459 if { [istarget *-*-darwin*]
2460 || [istarget *-*-aix*] } {
2461 set options "-maltivec -mcpu=cell"
2462 } else {
2463 set options "-mcpu=cell"
2464 }
2465 check_runtime_nocache cell_hw_available {
2466 int main()
2467 {
2468 #ifdef __MACH__
2469 asm volatile ("vor v0,v0,v0");
2470 asm volatile ("lvlx v0,r0,r0");
2471 #else
2472 asm volatile ("vor 0,0,0");
2473 asm volatile ("lvlx 0,0,0");
2474 #endif
2475 return 0;
2476 }
2477 } $options
2478 }
2479 }]
2480 }
2481
2482 # Return 1 if the target supports executing 64-bit instructions, 0
2483 # otherwise. Cache the result.
2484
2485 proc check_effective_target_powerpc64 { } {
2486 global powerpc64_available_saved
2487 global tool
2488
2489 if [info exists powerpc64_available_saved] {
2490 verbose "check_effective_target_powerpc64 returning saved $powerpc64_available_saved" 2
2491 } else {
2492 set powerpc64_available_saved 0
2493
2494 # Some simulators are known to not support powerpc64 instructions.
2495 if { [istarget powerpc-*-eabi*] || [istarget powerpc-ibm-aix*] } {
2496 verbose "check_effective_target_powerpc64 returning 0" 2
2497 return $powerpc64_available_saved
2498 }
2499
2500 # Set up, compile, and execute a test program containing a 64-bit
2501 # instruction. Include the current process ID in the file
2502 # names to prevent conflicts with invocations for multiple
2503 # testsuites.
2504 set src ppc[pid].c
2505 set exe ppc[pid].x
2506
2507 set f [open $src "w"]
2508 puts $f "int main() {"
2509 puts $f "#ifdef __MACH__"
2510 puts $f " asm volatile (\"extsw r0,r0\");"
2511 puts $f "#else"
2512 puts $f " asm volatile (\"extsw 0,0\");"
2513 puts $f "#endif"
2514 puts $f " return 0; }"
2515 close $f
2516
2517 set opts "additional_flags=-mcpu=G5"
2518
2519 verbose "check_effective_target_powerpc64 compiling testfile $src" 2
2520 set lines [${tool}_target_compile $src $exe executable "$opts"]
2521 file delete $src
2522
2523 if [string match "" $lines] then {
2524 # No error message, compilation succeeded.
2525 set result [${tool}_load "./$exe" "" ""]
2526 set status [lindex $result 0]
2527 remote_file build delete $exe
2528 verbose "check_effective_target_powerpc64 testfile status is <$status>" 2
2529
2530 if { $status == "pass" } then {
2531 set powerpc64_available_saved 1
2532 }
2533 } else {
2534 verbose "check_effective_target_powerpc64 testfile compilation failed" 2
2535 }
2536 }
2537
2538 return $powerpc64_available_saved
2539 }
2540
2541 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
2542 # complex float arguments. This affects gfortran tests that call cabsf
2543 # in libm built by an earlier compiler. Return 0 if libm uses the same
2544 # argument passing as the compiler under test, 1 otherwise.
2545
2546 proc check_effective_target_broken_cplxf_arg { } {
2547 # Skip the work for targets known not to be affected.
2548 if { ![istarget powerpc*-*-linux*] || ![is-effective-target lp64] } {
2549 return 0
2550 }
2551
2552 return [check_cached_effective_target broken_cplxf_arg {
2553 check_runtime_nocache broken_cplxf_arg {
2554 #include <complex.h>
2555 extern void abort (void);
2556 float fabsf (float);
2557 float cabsf (_Complex float);
2558 int main ()
2559 {
2560 _Complex float cf;
2561 float f;
2562 cf = 3 + 4.0fi;
2563 f = cabsf (cf);
2564 if (fabsf (f - 5.0) > 0.0001)
2565 /* Yes, it's broken. */
2566 return 0;
2567 /* All fine, not broken. */
2568 return 1;
2569 }
2570 } "-lm"
2571 }]
2572 }
2573
2574 # Return 1 is this is a TI C6X target supporting C67X instructions
2575 proc check_effective_target_ti_c67x { } {
2576 return [check_no_compiler_messages ti_c67x assembly {
2577 #if !defined(_TMS320C6700)
2578 #error !_TMS320C6700
2579 #endif
2580 }]
2581 }
2582
2583 # Return 1 is this is a TI C6X target supporting C64X+ instructions
2584 proc check_effective_target_ti_c64xp { } {
2585 return [check_no_compiler_messages ti_c64xp assembly {
2586 #if !defined(_TMS320C6400_PLUS)
2587 #error !_TMS320C6400_PLUS
2588 #endif
2589 }]
2590 }
2591
2592 # Check if a -march=... option is given, as part of (earlier) options.
2593 proc check_effective_target_march_option { } {
2594 return [check-flags [list "" { *-*-* } { "-march=*" } { "" } ]]
2595 }
2596
2597 proc check_alpha_max_hw_available { } {
2598 return [check_runtime alpha_max_hw_available {
2599 int main() { return __builtin_alpha_amask(1<<8) != 0; }
2600 }]
2601 }
2602
2603 # Returns true iff the FUNCTION is available on the target system.
2604 # (This is essentially a Tcl implementation of Autoconf's
2605 # AC_CHECK_FUNC.)
2606
2607 proc check_function_available { function } {
2608 return [check_no_compiler_messages ${function}_available \
2609 executable [subst {
2610 #ifdef __cplusplus
2611 extern "C"
2612 #endif
2613 char $function ();
2614 int main () { $function (); }
2615 }] "-fno-builtin" ]
2616 }
2617
2618 # Returns true iff "fork" is available on the target system.
2619
2620 proc check_fork_available {} {
2621 if { [istarget *-*-vxworks*] } {
2622 # VxWorks doesn't have fork but our way to test can't
2623 # tell as we're doing partial links for kernel modules.
2624 return 0
2625 }
2626 return [check_function_available "fork"]
2627 }
2628
2629 # Returns true iff "mkfifo" is available on the target system.
2630
2631 proc check_mkfifo_available {} {
2632 if { [istarget *-*-cygwin*] } {
2633 # Cygwin has mkfifo, but support is incomplete.
2634 return 0
2635 }
2636
2637 return [check_function_available "mkfifo"]
2638 }
2639
2640 # Returns true iff "__cxa_atexit" is used on the target system.
2641
2642 proc check_cxa_atexit_available { } {
2643 return [check_cached_effective_target cxa_atexit_available {
2644 if { [istarget hppa*-*-hpux10*] } {
2645 # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
2646 expr 0
2647 } elseif { [istarget *-*-vxworks] } {
2648 # vxworks doesn't have __cxa_atexit but subsequent test passes.
2649 expr 0
2650 } else {
2651 check_runtime_nocache cxa_atexit_available {
2652 // C++
2653 #include <stdlib.h>
2654 static unsigned int count;
2655 struct X
2656 {
2657 X() { count = 1; }
2658 ~X()
2659 {
2660 if (count != 3)
2661 exit(1);
2662 count = 4;
2663 }
2664 };
2665 void f()
2666 {
2667 static X x;
2668 }
2669 struct Y
2670 {
2671 Y() { f(); count = 2; }
2672 ~Y()
2673 {
2674 if (count != 2)
2675 exit(1);
2676 count = 3;
2677 }
2678 };
2679 Y y;
2680 int main() { return 0; }
2681 }
2682 }
2683 }]
2684 }
2685
2686 proc check_effective_target_objc2 { } {
2687 return [check_no_compiler_messages objc2 object {
2688 #ifdef __OBJC2__
2689 int dummy[1];
2690 #else
2691 #error !__OBJC2__
2692 #endif
2693 }]
2694 }
2695
2696 proc check_effective_target_next_runtime { } {
2697 return [check_no_compiler_messages objc2 object {
2698 #ifdef __NEXT_RUNTIME__
2699 int dummy[1];
2700 #else
2701 #error !__NEXT_RUNTIME__
2702 #endif
2703 }]
2704 }
2705
2706 # Return 1 if we're generating code for big-endian memory order.
2707
2708 proc check_effective_target_be { } {
2709 return [check_no_compiler_messages be object {
2710 int dummy[__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ? 1 : -1];
2711 }]
2712 }
2713
2714 # Return 1 if we're generating code for little-endian memory order.
2715
2716 proc check_effective_target_le { } {
2717 return [check_no_compiler_messages le object {
2718 int dummy[__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ? 1 : -1];
2719 }]
2720 }
2721
2722 # Return 1 if we're generating 32-bit code using default options, 0
2723 # otherwise.
2724
2725 proc check_effective_target_ilp32 { } {
2726 return [check_no_compiler_messages ilp32 object {
2727 int dummy[sizeof (int) == 4
2728 && sizeof (void *) == 4
2729 && sizeof (long) == 4 ? 1 : -1];
2730 }]
2731 }
2732
2733 # Return 1 if we're generating ia32 code using default options, 0
2734 # otherwise.
2735
2736 proc check_effective_target_ia32 { } {
2737 return [check_no_compiler_messages ia32 object {
2738 int dummy[sizeof (int) == 4
2739 && sizeof (void *) == 4
2740 && sizeof (long) == 4 ? 1 : -1] = { __i386__ };
2741 }]
2742 }
2743
2744 # Return 1 if we're generating x32 code using default options, 0
2745 # otherwise.
2746
2747 proc check_effective_target_x32 { } {
2748 return [check_no_compiler_messages x32 object {
2749 int dummy[sizeof (int) == 4
2750 && sizeof (void *) == 4
2751 && sizeof (long) == 4 ? 1 : -1] = { __x86_64__ };
2752 }]
2753 }
2754
2755 # Return 1 if we're generating 32-bit integers using default
2756 # options, 0 otherwise.
2757
2758 proc check_effective_target_int32 { } {
2759 return [check_no_compiler_messages int32 object {
2760 int dummy[sizeof (int) == 4 ? 1 : -1];
2761 }]
2762 }
2763
2764 # Return 1 if we're generating 32-bit or larger integers using default
2765 # options, 0 otherwise.
2766
2767 proc check_effective_target_int32plus { } {
2768 return [check_no_compiler_messages int32plus object {
2769 int dummy[sizeof (int) >= 4 ? 1 : -1];
2770 }]
2771 }
2772
2773 # Return 1 if we're generating 64-bit long long using default options,
2774 # 0 otherwise.
2775
2776 proc check_effective_target_longlong64 { } {
2777 return [check_no_compiler_messages longlong64 object {
2778 int dummy[sizeof (long long) == 8 ? 1 : -1];
2779 }]
2780 }
2781
2782 # Return 1 if we're generating 32-bit or larger pointers using default
2783 # options, 0 otherwise.
2784
2785 proc check_effective_target_ptr32plus { } {
2786 # The msp430 has 16-bit or 20-bit pointers. The 20-bit pointer is stored
2787 # in a 32-bit slot when in memory, so sizeof(void *) returns 4, but it
2788 # cannot really hold a 32-bit address, so we always return false here.
2789 if { [istarget msp430-*-*] } {
2790 return 0
2791 }
2792
2793 return [check_no_compiler_messages ptr32plus object {
2794 int dummy[sizeof (void *) >= 4 ? 1 : -1];
2795 }]
2796 }
2797
2798 # Return 1 if we support 16-bit or larger array and structure sizes
2799 # using default options, 0 otherwise.
2800 # This implies at least a 20-bit address space, as no targets have an address
2801 # space between 16 and 20 bits.
2802
2803 proc check_effective_target_size20plus { } {
2804 return [check_no_compiler_messages size20plus object {
2805 char dummy[65537L];
2806 }]
2807 }
2808
2809 # Return 1 if target supports function pointers, 0 otherwise.
2810
2811 proc check_effective_target_function_pointers { } {
2812 if { [istarget pru-*-*] } {
2813 return [check_no_compiler_messages func_ptr_avail assembly {
2814 #ifdef __PRU_EABI_GNU__
2815 #error unsupported
2816 #endif
2817 }]
2818 }
2819 return 1
2820 }
2821
2822 # Return 1 if target supports arbitrarily large return values, 0 otherwise.
2823
2824 proc check_effective_target_large_return_values { } {
2825 if { [istarget pru-*-*] } {
2826 return [check_no_compiler_messages large_return_values assembly {
2827 #ifdef __PRU_EABI_GNU__
2828 #error unsupported
2829 #endif
2830 }]
2831 }
2832 return 1
2833 }
2834 # Return 1 if we support 20-bit or larger array and structure sizes
2835 # using default options, 0 otherwise.
2836 # This implies at least a 24-bit address space, as no targets have an address
2837 # space between 20 and 24 bits.
2838
2839 proc check_effective_target_size24plus { } {
2840 return [check_no_compiler_messages size24plus object {
2841 char dummy[524289L];
2842 }]
2843 }
2844
2845 # Return 1 if we support 24-bit or larger array and structure sizes
2846 # using default options, 0 otherwise.
2847 # This implies at least a 32-bit address space, as no targets have an address
2848 # space between 24 and 32 bits.
2849
2850 proc check_effective_target_size32plus { } {
2851 return [check_no_compiler_messages size32plus object {
2852 char dummy[16777217L];
2853 }]
2854 }
2855
2856 # Returns 1 if we're generating 16-bit or smaller integers with the
2857 # default options, 0 otherwise.
2858
2859 proc check_effective_target_int16 { } {
2860 return [check_no_compiler_messages int16 object {
2861 int dummy[sizeof (int) < 4 ? 1 : -1];
2862 }]
2863 }
2864
2865 # Return 1 if we're generating 64-bit code using default options, 0
2866 # otherwise.
2867
2868 proc check_effective_target_lp64 { } {
2869 return [check_no_compiler_messages lp64 object {
2870 int dummy[sizeof (int) == 4
2871 && sizeof (void *) == 8
2872 && sizeof (long) == 8 ? 1 : -1];
2873 }]
2874 }
2875
2876 # Return 1 if we're generating 64-bit code using default llp64 options,
2877 # 0 otherwise.
2878
2879 proc check_effective_target_llp64 { } {
2880 return [check_no_compiler_messages llp64 object {
2881 int dummy[sizeof (int) == 4
2882 && sizeof (void *) == 8
2883 && sizeof (long long) == 8
2884 && sizeof (long) == 4 ? 1 : -1];
2885 }]
2886 }
2887
2888 # Return 1 if long and int have different sizes,
2889 # 0 otherwise.
2890
2891 proc check_effective_target_long_neq_int { } {
2892 return [check_no_compiler_messages long_ne_int object {
2893 int dummy[sizeof (int) != sizeof (long) ? 1 : -1];
2894 }]
2895 }
2896
2897 # Return 1 if int size is equal to float size,
2898 # 0 otherwise.
2899
2900 proc check_effective_target_int_eq_float { } {
2901 return [check_no_compiler_messages int_eq_float object {
2902 int dummy[sizeof (int) >= sizeof (float) ? 1 : -1];
2903 }]
2904 }
2905
2906 # Return 1 if short size is equal to int size,
2907 # 0 otherwise.
2908
2909 proc check_effective_target_short_eq_int { } {
2910 return [check_no_compiler_messages short_eq_int object {
2911 int dummy[sizeof (short) == sizeof (int) ? 1 : -1];
2912 }]
2913 }
2914
2915 # Return 1 if pointer size is equal to short size,
2916 # 0 otherwise.
2917
2918 proc check_effective_target_ptr_eq_short { } {
2919 return [check_no_compiler_messages ptr_eq_short object {
2920 int dummy[sizeof (void *) == sizeof (short) ? 1 : -1];
2921 }]
2922 }
2923
2924 # Return 1 if pointer size is equal to long size,
2925 # 0 otherwise.
2926
2927 proc check_effective_target_ptr_eq_long { } {
2928 # sizeof (void *) == 4 for msp430-elf -mlarge which is equal to
2929 # sizeof (long). Avoid false positive.
2930 if { [istarget msp430-*-*] } {
2931 return 0
2932 }
2933 return [check_no_compiler_messages ptr_eq_long object {
2934 int dummy[sizeof (void *) == sizeof (long) ? 1 : -1];
2935 }]
2936 }
2937
2938 # Return 1 if the target supports long double larger than double,
2939 # 0 otherwise.
2940
2941 proc check_effective_target_large_long_double { } {
2942 return [check_no_compiler_messages large_long_double object {
2943 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
2944 }]
2945 }
2946
2947 # Return 1 if the target supports double larger than float,
2948 # 0 otherwise.
2949
2950 proc check_effective_target_large_double { } {
2951 return [check_no_compiler_messages large_double object {
2952 int dummy[sizeof(double) > sizeof(float) ? 1 : -1];
2953 }]
2954 }
2955
2956 # Return 1 if the target supports long double of 128 bits,
2957 # 0 otherwise.
2958
2959 proc check_effective_target_longdouble128 { } {
2960 return [check_no_compiler_messages longdouble128 object {
2961 int dummy[sizeof(long double) == 16 ? 1 : -1];
2962 }]
2963 }
2964
2965 # Return 1 if the target supports long double of 64 bits,
2966 # 0 otherwise.
2967
2968 proc check_effective_target_longdouble64 { } {
2969 return [check_no_compiler_messages longdouble64 object {
2970 int dummy[sizeof(long double) == 8 ? 1 : -1];
2971 }]
2972 }
2973
2974 # Return 1 if the target supports double of 64 bits,
2975 # 0 otherwise.
2976
2977 proc check_effective_target_double64 { } {
2978 return [check_no_compiler_messages double64 object {
2979 int dummy[sizeof(double) == 8 ? 1 : -1];
2980 }]
2981 }
2982
2983 # Return 1 if the target supports double of at least 64 bits,
2984 # 0 otherwise.
2985
2986 proc check_effective_target_double64plus { } {
2987 return [check_no_compiler_messages double64plus object {
2988 int dummy[sizeof(double) >= 8 ? 1 : -1];
2989 }]
2990 }
2991
2992 # Return 1 if the target supports 'w' suffix on floating constant
2993 # 0 otherwise.
2994
2995 proc check_effective_target_has_w_floating_suffix { } {
2996 set opts ""
2997 if [check_effective_target_c++] {
2998 append opts "-std=gnu++03"
2999 }
3000 return [check_no_compiler_messages w_fp_suffix object {
3001 float dummy = 1.0w;
3002 } "$opts"]
3003 }
3004
3005 # Return 1 if the target supports 'q' suffix on floating constant
3006 # 0 otherwise.
3007
3008 proc check_effective_target_has_q_floating_suffix { } {
3009 set opts ""
3010 if [check_effective_target_c++] {
3011 append opts "-std=gnu++03"
3012 }
3013 return [check_no_compiler_messages q_fp_suffix object {
3014 float dummy = 1.0q;
3015 } "$opts"]
3016 }
3017
3018 # Return 1 if the target supports the _FloatN / _FloatNx type
3019 # indicated in the function name, 0 otherwise.
3020
3021 proc check_effective_target_float16 {} {
3022 return [check_no_compiler_messages_nocache float16 object {
3023 _Float16 x;
3024 } [add_options_for_float16 ""]]
3025 }
3026
3027 proc check_effective_target_float32 {} {
3028 return [check_no_compiler_messages_nocache float32 object {
3029 _Float32 x;
3030 } [add_options_for_float32 ""]]
3031 }
3032
3033 proc check_effective_target_float64 {} {
3034 return [check_no_compiler_messages_nocache float64 object {
3035 _Float64 x;
3036 } [add_options_for_float64 ""]]
3037 }
3038
3039 proc check_effective_target_float128 {} {
3040 return [check_no_compiler_messages_nocache float128 object {
3041 _Float128 x;
3042 } [add_options_for_float128 ""]]
3043 }
3044
3045 proc check_effective_target_float32x {} {
3046 return [check_no_compiler_messages_nocache float32x object {
3047 _Float32x x;
3048 } [add_options_for_float32x ""]]
3049 }
3050
3051 proc check_effective_target_float64x {} {
3052 return [check_no_compiler_messages_nocache float64x object {
3053 _Float64x x;
3054 } [add_options_for_float64x ""]]
3055 }
3056
3057 proc check_effective_target_float128x {} {
3058 return [check_no_compiler_messages_nocache float128x object {
3059 _Float128x x;
3060 } [add_options_for_float128x ""]]
3061 }
3062
3063 # Likewise, but runtime support for any special options used as well
3064 # as compile-time support is required.
3065
3066 proc check_effective_target_float16_runtime {} {
3067 return [check_effective_target_float16]
3068 }
3069
3070 proc check_effective_target_float32_runtime {} {
3071 return [check_effective_target_float32]
3072 }
3073
3074 proc check_effective_target_float64_runtime {} {
3075 return [check_effective_target_float64]
3076 }
3077
3078 proc check_effective_target_float128_runtime {} {
3079 if { ![check_effective_target_float128] } {
3080 return 0
3081 }
3082 if { [istarget powerpc*-*-*] } {
3083 return [check_effective_target_base_quadfloat_support]
3084 }
3085 return 1
3086 }
3087
3088 proc check_effective_target_float32x_runtime {} {
3089 return [check_effective_target_float32x]
3090 }
3091
3092 proc check_effective_target_float64x_runtime {} {
3093 if { ![check_effective_target_float64x] } {
3094 return 0
3095 }
3096 if { [istarget powerpc*-*-*] } {
3097 return [check_effective_target_base_quadfloat_support]
3098 }
3099 return 1
3100 }
3101
3102 proc check_effective_target_float128x_runtime {} {
3103 return [check_effective_target_float128x]
3104 }
3105
3106 # Return 1 if the target hardware supports any options added for
3107 # _FloatN and _FloatNx types, 0 otherwise.
3108
3109 proc check_effective_target_floatn_nx_runtime {} {
3110 if { [istarget powerpc*-*-aix*] } {
3111 return 0
3112 }
3113 if { [istarget powerpc*-*-*] } {
3114 return [check_effective_target_base_quadfloat_support]
3115 }
3116 return 1
3117 }
3118
3119 # Add options needed to use the _FloatN / _FloatNx type indicated in
3120 # the function name.
3121
3122 proc add_options_for_float16 { flags } {
3123 if { [istarget arm*-*-*] } {
3124 return "$flags -mfp16-format=ieee"
3125 }
3126 return "$flags"
3127 }
3128
3129 proc add_options_for_float32 { flags } {
3130 return "$flags"
3131 }
3132
3133 proc add_options_for_float64 { flags } {
3134 return "$flags"
3135 }
3136
3137 proc add_options_for_float128 { flags } {
3138 return [add_options_for___float128 "$flags"]
3139 }
3140
3141 proc add_options_for_float32x { flags } {
3142 return "$flags"
3143 }
3144
3145 proc add_options_for_float64x { flags } {
3146 return [add_options_for___float128 "$flags"]
3147 }
3148
3149 proc add_options_for_float128x { flags } {
3150 return "$flags"
3151 }
3152
3153 # Return 1 if the target supports __float128,
3154 # 0 otherwise.
3155
3156 proc check_effective_target___float128 { } {
3157 if { [istarget powerpc*-*-*] } {
3158 return [check_ppc_float128_sw_available]
3159 }
3160 if { [istarget ia64-*-*]
3161 || [istarget i?86-*-*] || [istarget x86_64-*-*] } {
3162 return 1
3163 }
3164 return 0
3165 }
3166
3167 proc add_options_for___float128 { flags } {
3168 if { [istarget powerpc*-*-*] } {
3169 return "$flags -mfloat128 -mvsx"
3170 }
3171 return "$flags"
3172 }
3173
3174 # Return 1 if the target supports any special run-time requirements
3175 # for __float128 or _Float128,
3176 # 0 otherwise.
3177
3178 proc check_effective_target_base_quadfloat_support { } {
3179 if { [istarget powerpc*-*-*] } {
3180 return [check_vsx_hw_available]
3181 }
3182 return 1
3183 }
3184
3185 # Return 1 if the target supports all four forms of fused multiply-add
3186 # (fma, fms, fnma, and fnms) for both float and double.
3187
3188 proc check_effective_target_scalar_all_fma { } {
3189 return [istarget aarch64*-*-*]
3190 }
3191
3192 # Return 1 if the target supports compiling fixed-point,
3193 # 0 otherwise.
3194
3195 proc check_effective_target_fixed_point { } {
3196 return [check_no_compiler_messages fixed_point object {
3197 _Sat _Fract x; _Sat _Accum y;
3198 }]
3199 }
3200
3201 # Return 1 if the target supports compiling decimal floating point,
3202 # 0 otherwise.
3203
3204 proc check_effective_target_dfp_nocache { } {
3205 verbose "check_effective_target_dfp_nocache: compiling source" 2
3206 set ret [check_no_compiler_messages_nocache dfp object {
3207 float x __attribute__((mode(DD)));
3208 }]
3209 verbose "check_effective_target_dfp_nocache: returning $ret" 2
3210 return $ret
3211 }
3212
3213 proc check_effective_target_dfprt_nocache { } {
3214 return [check_runtime_nocache dfprt {
3215 typedef float d64 __attribute__((mode(DD)));
3216 d64 x = 1.2df, y = 2.3dd, z;
3217 int main () { z = x + y; return 0; }
3218 }]
3219 }
3220
3221 # Return 1 if the target supports compiling Decimal Floating Point,
3222 # 0 otherwise.
3223 #
3224 # This won't change for different subtargets so cache the result.
3225
3226 proc check_effective_target_dfp { } {
3227 return [check_cached_effective_target dfp {
3228 check_effective_target_dfp_nocache
3229 }]
3230 }
3231
3232 # Return 1 if the target supports linking and executing Decimal Floating
3233 # Point, 0 otherwise.
3234 #
3235 # This won't change for different subtargets so cache the result.
3236
3237 proc check_effective_target_dfprt { } {
3238 return [check_cached_effective_target dfprt {
3239 check_effective_target_dfprt_nocache
3240 }]
3241 }
3242
3243 # Return 1 iff target has unsigned plain 'char' by default.
3244
3245 proc check_effective_target_unsigned_char {} {
3246 return [check_no_compiler_messages unsigned_char assembly {
3247 char ar[(char)-1];
3248 }]
3249 }
3250
3251 proc check_effective_target_powerpc_popcntb_ok { } {
3252 return [check_cached_effective_target powerpc_popcntb_ok {
3253
3254 # Disable on Darwin.
3255 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
3256 expr 0
3257 } else {
3258 check_runtime_nocache powerpc_popcntb_ok {
3259 volatile int r;
3260 volatile int a = 0x12345678;
3261 int main()
3262 {
3263 asm volatile ("popcntb %0,%1" : "=r" (r) : "r" (a));
3264 return 0;
3265 }
3266 } "-mcpu=power5"
3267 }
3268 }]
3269 }
3270
3271 # Return 1 if the target supports executing DFP hardware instructions,
3272 # 0 otherwise. Cache the result.
3273
3274 proc check_dfp_hw_available { } {
3275 return [check_cached_effective_target dfp_hw_available {
3276 # For now, disable on Darwin
3277 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
3278 expr 0
3279 } else {
3280 check_runtime_nocache dfp_hw_available {
3281 volatile _Decimal64 r;
3282 volatile _Decimal64 a = 4.0DD;
3283 volatile _Decimal64 b = 2.0DD;
3284 int main()
3285 {
3286 asm volatile ("dadd %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
3287 asm volatile ("dsub %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
3288 asm volatile ("dmul %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
3289 asm volatile ("ddiv %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
3290 return 0;
3291 }
3292 } "-mcpu=power6 -mhard-float"
3293 }
3294 }]
3295 }
3296
3297 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
3298
3299 proc check_effective_target_ucn_nocache { } {
3300 # -std=c99 is only valid for C
3301 if [check_effective_target_c] {
3302 set ucnopts "-std=c99"
3303 } else {
3304 set ucnopts ""
3305 }
3306 verbose "check_effective_target_ucn_nocache: compiling source" 2
3307 set ret [check_no_compiler_messages_nocache ucn object {
3308 int \u00C0;
3309 } $ucnopts]
3310 verbose "check_effective_target_ucn_nocache: returning $ret" 2
3311 return $ret
3312 }
3313
3314 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
3315 #
3316 # This won't change for different subtargets, so cache the result.
3317
3318 proc check_effective_target_ucn { } {
3319 return [check_cached_effective_target ucn {
3320 check_effective_target_ucn_nocache
3321 }]
3322 }
3323
3324 # Return 1 if the target needs a command line argument to enable a SIMD
3325 # instruction set.
3326
3327 proc check_effective_target_vect_cmdline_needed { } {
3328 global et_vect_cmdline_needed_target_name
3329
3330 if { ![info exists et_vect_cmdline_needed_target_name] } {
3331 set et_vect_cmdline_needed_target_name ""
3332 }
3333
3334 # If the target has changed since we set the cached value, clear it.
3335 set current_target [current_target_name]
3336 if { $current_target != $et_vect_cmdline_needed_target_name } {
3337 verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
3338 set et_vect_cmdline_needed_target_name $current_target
3339 if { [info exists et_vect_cmdline_needed_saved] } {
3340 verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
3341 unset et_vect_cmdline_needed_saved
3342 }
3343 }
3344
3345 return [check_cached_effective_target vect_cmdline_needed {
3346 if { [istarget alpha*-*-*]
3347 || [istarget ia64-*-*]
3348 || (([istarget i?86-*-*] || [istarget x86_64-*-*])
3349 && ![is-effective-target ia32])
3350 || ([istarget powerpc*-*-*]
3351 && ([check_effective_target_powerpc_spe]
3352 || [check_effective_target_powerpc_altivec]))
3353 || ([istarget sparc*-*-*] && [check_effective_target_sparc_vis])
3354 || ([istarget arm*-*-*] && [check_effective_target_arm_neon])
3355 || [istarget aarch64*-*-*]
3356 || [istarget amdgcn*-*-*]} {
3357 return 0
3358 } else {
3359 return 1
3360 }}]
3361 }
3362
3363 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
3364 #
3365 # This won't change for different subtargets so cache the result.
3366
3367 proc check_effective_target_vect_int { } {
3368 return [check_cached_effective_target_indexed vect_int {
3369 expr {
3370 [istarget i?86-*-*] || [istarget x86_64-*-*]
3371 || ([istarget powerpc*-*-*]
3372 && ![istarget powerpc-*-linux*paired*])
3373 || [istarget amdgcn-*-*]
3374 || [istarget sparc*-*-*]
3375 || [istarget alpha*-*-*]
3376 || [istarget ia64-*-*]
3377 || [istarget aarch64*-*-*]
3378 || [is-effective-target arm_neon]
3379 || ([istarget mips*-*-*]
3380 && ([et-is-effective-target mips_loongson_mmi]
3381 || [et-is-effective-target mips_msa]))
3382 || ([istarget s390*-*-*]
3383 && [check_effective_target_s390_vx])
3384 }}]
3385 }
3386
3387 # Return 1 if the target supports hardware vectorization of complex additions of
3388 # byte, 0 otherwise.
3389 #
3390 # This won't change for different subtargets so cache the result.
3391
3392 proc check_effective_target_vect_complex_add_byte { } {
3393 return [check_cached_effective_target_indexed vect_complex_add_byte {
3394 expr {
3395 ([check_effective_target_aarch64_sve2]
3396 && [check_effective_target_aarch64_little_endian])
3397 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
3398 && [check_effective_target_arm_little_endian])
3399 }}]
3400 }
3401
3402 # Return 1 if the target supports hardware vectorization of complex additions of
3403 # short, 0 otherwise.
3404 #
3405 # This won't change for different subtargets so cache the result.
3406
3407 proc check_effective_target_vect_complex_add_short { } {
3408 return [check_cached_effective_target_indexed vect_complex_add_short {
3409 expr {
3410 ([check_effective_target_aarch64_sve2]
3411 && [check_effective_target_aarch64_little_endian])
3412 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
3413 && [check_effective_target_arm_little_endian])
3414 }}]
3415 }
3416
3417 # Return 1 if the target supports hardware vectorization of complex additions of
3418 # int, 0 otherwise.
3419 #
3420 # This won't change for different subtargets so cache the result.
3421
3422 proc check_effective_target_vect_complex_add_int { } {
3423 return [check_cached_effective_target_indexed vect_complex_add_int {
3424 expr {
3425 ([check_effective_target_aarch64_sve2]
3426 && [check_effective_target_aarch64_little_endian])
3427 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
3428 && [check_effective_target_arm_little_endian])
3429 }}]
3430 }
3431
3432 # Return 1 if the target supports hardware vectorization of complex additions of
3433 # long, 0 otherwise.
3434 #
3435 # This won't change for different subtargets so cache the result.
3436
3437 proc check_effective_target_vect_complex_add_long { } {
3438 return [check_cached_effective_target_indexed vect_complex_add_long {
3439 expr {
3440 ([check_effective_target_aarch64_sve2]
3441 && [check_effective_target_aarch64_little_endian])
3442 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
3443 && [check_effective_target_arm_little_endian])
3444 }}]
3445 }
3446
3447 # Return 1 if the target supports hardware vectorization of complex additions of
3448 # half, 0 otherwise.
3449 #
3450 # This won't change for different subtargets so cache the result.
3451
3452 proc check_effective_target_vect_complex_add_half { } {
3453 return [check_cached_effective_target_indexed vect_complex_add_half {
3454 expr {
3455 ([check_effective_target_arm_v8_3a_fp16_complex_neon_ok]
3456 && ([check_effective_target_aarch64_little_endian]
3457 || [check_effective_target_arm_little_endian]))
3458 || ([check_effective_target_aarch64_sve2]
3459 && [check_effective_target_aarch64_little_endian])
3460 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
3461 && [check_effective_target_arm_little_endian])
3462 }}]
3463 }
3464
3465 # Return 1 if the target supports hardware vectorization of complex additions of
3466 # float, 0 otherwise.
3467 #
3468 # This won't change for different subtargets so cache the result.
3469
3470 proc check_effective_target_vect_complex_add_float { } {
3471 return [check_cached_effective_target_indexed vect_complex_add_float {
3472 expr {
3473 ([check_effective_target_arm_v8_3a_complex_neon_ok]
3474 && ([check_effective_target_aarch64_little_endian]
3475 || [check_effective_target_arm_little_endian]))
3476 || ([check_effective_target_aarch64_sve2]
3477 && [check_effective_target_aarch64_little_endian])
3478 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
3479 && [check_effective_target_arm_little_endian])
3480 }}]
3481 }
3482
3483 # Return 1 if the target supports hardware vectorization of complex additions of
3484 # double, 0 otherwise.
3485 #
3486 # This won't change for different subtargets so cache the result.
3487
3488 proc check_effective_target_vect_complex_add_double { } {
3489 return [check_cached_effective_target_indexed vect_complex_add_double {
3490 expr {
3491 ([check_effective_target_aarch64_sve2]
3492 && [check_effective_target_aarch64_little_endian])
3493 }}]
3494 }
3495
3496 # Return 1 if the target supports signed int->float conversion
3497 #
3498
3499 proc check_effective_target_vect_intfloat_cvt { } {
3500 return [check_cached_effective_target_indexed vect_intfloat_cvt {
3501 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
3502 || ([istarget powerpc*-*-*]
3503 && ![istarget powerpc-*-linux*paired*])
3504 || [is-effective-target arm_neon]
3505 || ([istarget mips*-*-*]
3506 && [et-is-effective-target mips_msa])
3507 || [istarget amdgcn-*-*]
3508 || ([istarget s390*-*-*]
3509 && [check_effective_target_s390_vxe2]) }}]
3510 }
3511
3512 # Return 1 if the target supports signed double->int conversion
3513 #
3514
3515 proc check_effective_target_vect_doubleint_cvt { } {
3516 return [check_cached_effective_target_indexed vect_doubleint_cvt {
3517 expr { (([istarget i?86-*-*] || [istarget x86_64-*-*])
3518 && [check_no_compiler_messages vect_doubleint_cvt assembly {
3519 #ifdef __tune_atom__
3520 # error No double vectorizer support.
3521 #endif
3522 }])
3523 || [istarget aarch64*-*-*]
3524 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
3525 || ([istarget mips*-*-*]
3526 && [et-is-effective-target mips_msa])
3527 || ([istarget s390*-*-*]
3528 && [check_effective_target_s390_vx]) }}]
3529 }
3530
3531 # Return 1 if the target supports signed int->double conversion
3532 #
3533
3534 proc check_effective_target_vect_intdouble_cvt { } {
3535 return [check_cached_effective_target_indexed vect_intdouble_cvt {
3536 expr { (([istarget i?86-*-*] || [istarget x86_64-*-*])
3537 && [check_no_compiler_messages vect_intdouble_cvt assembly {
3538 #ifdef __tune_atom__
3539 # error No double vectorizer support.
3540 #endif
3541 }])
3542 || [istarget aarch64*-*-*]
3543 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
3544 || ([istarget mips*-*-*]
3545 && [et-is-effective-target mips_msa])
3546 || ([istarget s390*-*-*]
3547 && [check_effective_target_s390_vx]) }}]
3548 }
3549
3550 #Return 1 if we're supporting __int128 for target, 0 otherwise.
3551
3552 proc check_effective_target_int128 { } {
3553 return [check_no_compiler_messages int128 object {
3554 int dummy[
3555 #ifndef __SIZEOF_INT128__
3556 -1
3557 #else
3558 1
3559 #endif
3560 ];
3561 }]
3562 }
3563
3564 # Return 1 if the target supports unsigned int->float conversion
3565 #
3566
3567 proc check_effective_target_vect_uintfloat_cvt { } {
3568 return [check_cached_effective_target_indexed vect_uintfloat_cvt {
3569 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
3570 || ([istarget powerpc*-*-*]
3571 && ![istarget powerpc-*-linux*paired*])
3572 || [istarget aarch64*-*-*]
3573 || [is-effective-target arm_neon]
3574 || ([istarget mips*-*-*]
3575 && [et-is-effective-target mips_msa])
3576 || [istarget amdgcn-*-*]
3577 || ([istarget s390*-*-*]
3578 && [check_effective_target_s390_vxe2]) }}]
3579 }
3580
3581
3582 # Return 1 if the target supports signed float->int conversion
3583 #
3584
3585 proc check_effective_target_vect_floatint_cvt { } {
3586 return [check_cached_effective_target_indexed vect_floatint_cvt {
3587 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
3588 || ([istarget powerpc*-*-*]
3589 && ![istarget powerpc-*-linux*paired*])
3590 || [is-effective-target arm_neon]
3591 || ([istarget mips*-*-*]
3592 && [et-is-effective-target mips_msa])
3593 || [istarget amdgcn-*-*]
3594 || ([istarget s390*-*-*]
3595 && [check_effective_target_s390_vxe2]) }}]
3596 }
3597
3598 # Return 1 if the target supports unsigned float->int conversion
3599 #
3600
3601 proc check_effective_target_vect_floatuint_cvt { } {
3602 return [check_cached_effective_target_indexed vect_floatuint_cvt {
3603 expr { ([istarget powerpc*-*-*]
3604 && ![istarget powerpc-*-linux*paired*])
3605 || [is-effective-target arm_neon]
3606 || ([istarget mips*-*-*]
3607 && [et-is-effective-target mips_msa])
3608 || [istarget amdgcn-*-*]
3609 || ([istarget s390*-*-*]
3610 && [check_effective_target_s390_vxe2]) }}]
3611 }
3612
3613 # Return 1 if peeling for alignment might be profitable on the target
3614 #
3615
3616 proc check_effective_target_vect_peeling_profitable { } {
3617 return [check_cached_effective_target_indexed vect_peeling_profitable {
3618 expr { ([istarget s390*-*-*]
3619 && [check_effective_target_s390_vx])
3620 || [check_effective_target_vect_element_align_preferred] }}]
3621 }
3622
3623 # Return 1 if the target supports #pragma omp declare simd, 0 otherwise.
3624 #
3625 # This won't change for different subtargets so cache the result.
3626
3627 proc check_effective_target_vect_simd_clones { } {
3628 # On i?86/x86_64 #pragma omp declare simd builds a sse2, avx,
3629 # avx2 and avx512f clone. Only the right clone for the
3630 # specified arch will be chosen, but still we need to at least
3631 # be able to assemble avx512f.
3632 return [check_cached_effective_target_indexed vect_simd_clones {
3633 expr { (([istarget i?86-*-*] || [istarget x86_64-*-*])
3634 && [check_effective_target_avx512f])
3635 || [istarget amdgcn-*-*] }}]
3636 }
3637
3638 # Return 1 if this is a AArch64 target supporting big endian
3639 proc check_effective_target_aarch64_big_endian { } {
3640 return [check_no_compiler_messages aarch64_big_endian assembly {
3641 #if !defined(__aarch64__) || !defined(__AARCH64EB__)
3642 #error !__aarch64__ || !__AARCH64EB__
3643 #endif
3644 }]
3645 }
3646
3647 # Return 1 if this is a AArch64 target supporting little endian
3648 proc check_effective_target_aarch64_little_endian { } {
3649 if { ![istarget aarch64*-*-*] } {
3650 return 0
3651 }
3652
3653 return [check_no_compiler_messages aarch64_little_endian assembly {
3654 #if !defined(__aarch64__) || defined(__AARCH64EB__)
3655 #error FOO
3656 #endif
3657 }]
3658 }
3659
3660 # Return 1 if this is an AArch64 target supporting SVE.
3661 proc check_effective_target_aarch64_sve { } {
3662 if { ![istarget aarch64*-*-*] } {
3663 return 0
3664 }
3665 return [check_no_compiler_messages aarch64_sve assembly {
3666 #if !defined (__ARM_FEATURE_SVE)
3667 #error FOO
3668 #endif
3669 }]
3670 }
3671
3672 # Return 1 if this is an AArch64 target supporting SVE2.
3673 proc check_effective_target_aarch64_sve2 { } {
3674 if { ![istarget aarch64*-*-*] } {
3675 return 0
3676 }
3677 return [check_no_compiler_messages aarch64_sve2 assembly {
3678 #if !defined (__ARM_FEATURE_SVE2)
3679 #error FOO
3680 #endif
3681 }]
3682 }
3683
3684 # Return 1 if this is an AArch64 target only supporting SVE (not SVE2).
3685 proc check_effective_target_aarch64_sve1_only { } {
3686 return [expr { [check_effective_target_aarch64_sve]
3687 && ![check_effective_target_aarch64_sve2] }]
3688 }
3689
3690 # Return the size in bits of an SVE vector, or 0 if the size is variable.
3691 proc aarch64_sve_bits { } {
3692 return [check_cached_effective_target aarch64_sve_bits {
3693 global tool
3694
3695 set src dummy[pid].c
3696 set f [open $src "w"]
3697 puts $f "int bits = __ARM_FEATURE_SVE_BITS;"
3698 close $f
3699 set output [${tool}_target_compile $src "" preprocess ""]
3700 file delete $src
3701
3702 regsub {.*bits = ([^;]*);.*} $output {\1} bits
3703 expr { $bits }
3704 }]
3705 }
3706
3707 # Return 1 if this is a compiler supporting ARC atomic operations
3708 proc check_effective_target_arc_atomic { } {
3709 return [check_no_compiler_messages arc_atomic assembly {
3710 #if !defined(__ARC_ATOMIC__)
3711 #error FOO
3712 #endif
3713 }]
3714 }
3715
3716 # Return 1 if this is an arm target using 32-bit instructions
3717 proc check_effective_target_arm32 { } {
3718 if { ![istarget arm*-*-*] } {
3719 return 0
3720 }
3721
3722 return [check_no_compiler_messages arm32 assembly {
3723 #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
3724 #error !__arm || __thumb__ && !__thumb2__
3725 #endif
3726 }]
3727 }
3728
3729 # Return 1 if this is an arm target not using Thumb
3730 proc check_effective_target_arm_nothumb { } {
3731 if { ![istarget arm*-*-*] } {
3732 return 0
3733 }
3734
3735 return [check_no_compiler_messages arm_nothumb assembly {
3736 #if !defined(__arm__) || (defined(__thumb__) || defined(__thumb2__))
3737 #error !__arm__ || __thumb || __thumb2__
3738 #endif
3739 }]
3740 }
3741
3742 # Return 1 if this is a little-endian ARM target
3743 proc check_effective_target_arm_little_endian { } {
3744 if { ![istarget arm*-*-*] } {
3745 return 0
3746 }
3747
3748 return [check_no_compiler_messages arm_little_endian assembly {
3749 #if !defined(__arm__) || !defined(__ARMEL__)
3750 #error !__arm__ || !__ARMEL__
3751 #endif
3752 }]
3753 }
3754
3755 # Return 1 if this is an ARM target that only supports aligned vector accesses
3756 proc check_effective_target_arm_vect_no_misalign { } {
3757 if { ![istarget arm*-*-*] } {
3758 return 0
3759 }
3760
3761 return [check_no_compiler_messages arm_vect_no_misalign assembly {
3762 #if !defined(__arm__) \
3763 || (defined(__ARM_FEATURE_UNALIGNED) \
3764 && defined(__ARMEL__))
3765 #error !__arm__ || (__ARMEL__ && __ARM_FEATURE_UNALIGNED)
3766 #endif
3767 }]
3768 }
3769
3770
3771 # Return 1 if this is an ARM target supporting -mfloat-abi=soft. Some
3772 # multilibs may be incompatible with this option.
3773
3774 proc check_effective_target_arm_soft_ok { } {
3775 return [check_no_compiler_messages arm_soft_ok object {
3776 #include <stdint.h>
3777 int dummy;
3778 int main (void) { return 0; }
3779 } "-mfloat-abi=soft"]
3780 }
3781
3782 # Return 1 if this is an ARM target supporting -mfpu=vfp with an
3783 # appropriate abi.
3784
3785 proc check_effective_target_arm_vfp_ok_nocache { } {
3786 global et_arm_vfp_flags
3787 set et_arm_vfp_flags ""
3788 if { [check_effective_target_arm32] } {
3789 foreach flags {"-mfpu=vfp" "-mfpu=vfp -mfloat-abi=softfp" "-mfpu=vfp -mfloat-abi=hard"} {
3790 if { [check_no_compiler_messages_nocache arm_vfp_ok object {
3791 #ifndef __ARM_FP
3792 #error __ARM_FP not defined
3793 #endif
3794 } "$flags"] } {
3795 set et_arm_vfp_flags $flags
3796 return 1
3797 }
3798 }
3799 }
3800
3801 return 0
3802 }
3803
3804 proc check_effective_target_arm_vfp_ok { } {
3805 return [check_cached_effective_target arm_vfp_ok \
3806 check_effective_target_arm_vfp_ok_nocache]
3807 }
3808
3809 # Add the options needed to compile code with -mfpu=vfp. We need either
3810 # -mfloat-abi=softfp or -mfloat-abi=hard, but if one is already
3811 # specified by the multilib, use it.
3812
3813 proc add_options_for_arm_vfp { flags } {
3814 if { ! [check_effective_target_arm_vfp_ok] } {
3815 return "$flags"
3816 }
3817 global et_arm_vfp_flags
3818 return "$flags $et_arm_vfp_flags"
3819 }
3820
3821 # Return 1 if this is an ARM target supporting -mfpu=vfp3
3822 # -mfloat-abi=softfp.
3823
3824 proc check_effective_target_arm_vfp3_ok { } {
3825 if { [check_effective_target_arm32] } {
3826 return [check_no_compiler_messages arm_vfp3_ok object {
3827 int dummy;
3828 } "-mfpu=vfp3 -mfloat-abi=softfp"]
3829 } else {
3830 return 0
3831 }
3832 }
3833
3834 # Return 1 if this is an ARM target supporting -mfpu=fp-armv8
3835 # -mfloat-abi=softfp.
3836 proc check_effective_target_arm_v8_vfp_ok {} {
3837 if { [check_effective_target_arm32] } {
3838 return [check_no_compiler_messages arm_v8_vfp_ok object {
3839 int foo (void)
3840 {
3841 __asm__ volatile ("vrinta.f32.f32 s0, s0");
3842 return 0;
3843 }
3844 } "-mfpu=fp-armv8 -mfloat-abi=softfp"]
3845 } else {
3846 return 0
3847 }
3848 }
3849
3850 # Return 1 if this is an ARM target supporting -mfpu=vfp
3851 # -mfloat-abi=hard. Some multilibs may be incompatible with these
3852 # options.
3853
3854 proc check_effective_target_arm_hard_vfp_ok { } {
3855 if { [check_effective_target_arm32]
3856 && ! [check-flags [list "" { *-*-* } { "-mfloat-abi=*" } { "-mfloat-abi=hard" }]] } {
3857 return [check_no_compiler_messages arm_hard_vfp_ok executable {
3858 int main() { return 0;}
3859 } "-mfpu=vfp -mfloat-abi=hard"]
3860 } else {
3861 return 0
3862 }
3863 }
3864
3865 # Return 1 if this is an ARM target defining __ARM_FP. We may need
3866 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3867 # incompatible with these options. Also set et_arm_fp_flags to the
3868 # best options to add.
3869
3870 proc check_effective_target_arm_fp_ok_nocache { } {
3871 global et_arm_fp_flags
3872 set et_arm_fp_flags ""
3873 if { [check_effective_target_arm32] } {
3874 foreach flags {"" "-mfloat-abi=softfp" "-mfloat-abi=hard"} {
3875 if { [check_no_compiler_messages_nocache arm_fp_ok object {
3876 #ifndef __ARM_FP
3877 #error __ARM_FP not defined
3878 #endif
3879 } "$flags"] } {
3880 set et_arm_fp_flags $flags
3881 return 1
3882 }
3883 }
3884 }
3885
3886 return 0
3887 }
3888
3889 proc check_effective_target_arm_fp_ok { } {
3890 return [check_cached_effective_target arm_fp_ok \
3891 check_effective_target_arm_fp_ok_nocache]
3892 }
3893
3894 # Add the options needed to define __ARM_FP. We need either
3895 # -mfloat-abi=softfp or -mfloat-abi=hard, but if one is already
3896 # specified by the multilib, use it.
3897
3898 proc add_options_for_arm_fp { flags } {
3899 if { ! [check_effective_target_arm_fp_ok] } {
3900 return "$flags"
3901 }
3902 global et_arm_fp_flags
3903 return "$flags $et_arm_fp_flags"
3904 }
3905
3906 # Return 1 if this is an ARM target defining __ARM_FP with
3907 # double-precision support. We may need -mfloat-abi=softfp or
3908 # equivalent options. Some multilibs may be incompatible with these
3909 # options. Also set et_arm_fp_dp_flags to the best options to add.
3910
3911 proc check_effective_target_arm_fp_dp_ok_nocache { } {
3912 global et_arm_fp_dp_flags
3913 set et_arm_fp_dp_flags ""
3914 if { [check_effective_target_arm32] } {
3915 foreach flags {"" "-mfloat-abi=softfp" "-mfloat-abi=hard"} {
3916 if { [check_no_compiler_messages_nocache arm_fp_dp_ok object {
3917 #ifndef __ARM_FP
3918 #error __ARM_FP not defined
3919 #endif
3920 #if ((__ARM_FP & 8) == 0)
3921 #error __ARM_FP indicates that double-precision is not supported
3922 #endif
3923 } "$flags"] } {
3924 set et_arm_fp_dp_flags $flags
3925 return 1
3926 }
3927 }
3928 }
3929
3930 return 0
3931 }
3932
3933 proc check_effective_target_arm_fp_dp_ok { } {
3934 return [check_cached_effective_target arm_fp_dp_ok \
3935 check_effective_target_arm_fp_dp_ok_nocache]
3936 }
3937
3938 # Add the options needed to define __ARM_FP with double-precision
3939 # support. We need either -mfloat-abi=softfp or -mfloat-abi=hard, but
3940 # if one is already specified by the multilib, use it.
3941
3942 proc add_options_for_arm_fp_dp { flags } {
3943 if { ! [check_effective_target_arm_fp_dp_ok] } {
3944 return "$flags"
3945 }
3946 global et_arm_fp_dp_flags
3947 return "$flags $et_arm_fp_dp_flags"
3948 }
3949
3950 # Return 1 if this is an ARM target that supports DSP multiply with
3951 # current multilib flags.
3952
3953 proc check_effective_target_arm_dsp { } {
3954 return [check_no_compiler_messages arm_dsp assembly {
3955 #ifndef __ARM_FEATURE_DSP
3956 #error not DSP
3957 #endif
3958 #include <arm_acle.h>
3959 int i;
3960 }]
3961 }
3962
3963 # Return 1 if this is an ARM target that supports unaligned word/halfword
3964 # load/store instructions.
3965
3966 proc check_effective_target_arm_unaligned { } {
3967 return [check_no_compiler_messages arm_unaligned assembly {
3968 #ifndef __ARM_FEATURE_UNALIGNED
3969 #error no unaligned support
3970 #endif
3971 int i;
3972 }]
3973 }
3974
3975 # Return 1 if this is an ARM target supporting -mfpu=crypto-neon-fp-armv8
3976 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
3977 # incompatible with these options. Also set et_arm_crypto_flags to the
3978 # best options to add.
3979
3980 proc check_effective_target_arm_crypto_ok_nocache { } {
3981 global et_arm_crypto_flags
3982 set et_arm_crypto_flags ""
3983 if { [check_effective_target_arm_v8_neon_ok] } {
3984 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=crypto-neon-fp-armv8" "-mfpu=crypto-neon-fp-armv8 -mfloat-abi=softfp"} {
3985 if { [check_no_compiler_messages_nocache arm_crypto_ok object {
3986 #include "arm_neon.h"
3987 uint8x16_t
3988 foo (uint8x16_t a, uint8x16_t b)
3989 {
3990 return vaeseq_u8 (a, b);
3991 }
3992 } "$flags"] } {
3993 set et_arm_crypto_flags $flags
3994 return 1
3995 }
3996 }
3997 }
3998
3999 return 0
4000 }
4001
4002 # Return 1 if this is an ARM target supporting -mfpu=crypto-neon-fp-armv8
4003
4004 proc check_effective_target_arm_crypto_ok { } {
4005 return [check_cached_effective_target arm_crypto_ok \
4006 check_effective_target_arm_crypto_ok_nocache]
4007 }
4008
4009 # Add options for crypto extensions.
4010 proc add_options_for_arm_crypto { flags } {
4011 if { ! [check_effective_target_arm_crypto_ok] } {
4012 return "$flags"
4013 }
4014 global et_arm_crypto_flags
4015 return "$flags $et_arm_crypto_flags"
4016 }
4017
4018 # Add the options needed for NEON. We need either -mfloat-abi=softfp
4019 # or -mfloat-abi=hard, but if one is already specified by the
4020 # multilib, use it. Similarly, if a -mfpu option already enables
4021 # NEON, do not add -mfpu=neon.
4022
4023 proc add_options_for_arm_neon { flags } {
4024 if { ! [check_effective_target_arm_neon_ok] } {
4025 return "$flags"
4026 }
4027 global et_arm_neon_flags
4028 return "$flags $et_arm_neon_flags"
4029 }
4030
4031 proc add_options_for_arm_v8_vfp { flags } {
4032 if { ! [check_effective_target_arm_v8_vfp_ok] } {
4033 return "$flags"
4034 }
4035 return "$flags -mfpu=fp-armv8 -mfloat-abi=softfp"
4036 }
4037
4038 proc add_options_for_arm_v8_neon { flags } {
4039 if { ! [check_effective_target_arm_v8_neon_ok] } {
4040 return "$flags"
4041 }
4042 global et_arm_v8_neon_flags
4043 return "$flags $et_arm_v8_neon_flags -march=armv8-a"
4044 }
4045
4046 # Add the options needed for ARMv8.1 Adv.SIMD. Also adds the ARMv8 NEON
4047 # options for AArch64 and for ARM.
4048
4049 proc add_options_for_arm_v8_1a_neon { flags } {
4050 if { ! [check_effective_target_arm_v8_1a_neon_ok] } {
4051 return "$flags"
4052 }
4053 global et_arm_v8_1a_neon_flags
4054 return "$flags $et_arm_v8_1a_neon_flags"
4055 }
4056
4057 # Add the options needed for ARMv8.2 with the scalar FP16 extension.
4058 # Also adds the ARMv8 FP options for ARM and for AArch64.
4059
4060 proc add_options_for_arm_v8_2a_fp16_scalar { flags } {
4061 if { ! [check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
4062 return "$flags"
4063 }
4064 global et_arm_v8_2a_fp16_scalar_flags
4065 return "$flags $et_arm_v8_2a_fp16_scalar_flags"
4066 }
4067
4068 # Add the options needed for ARMv8.2 with the FP16 extension. Also adds
4069 # the ARMv8 NEON options for ARM and for AArch64.
4070
4071 proc add_options_for_arm_v8_2a_fp16_neon { flags } {
4072 if { ! [check_effective_target_arm_v8_2a_fp16_neon_ok] } {
4073 return "$flags"
4074 }
4075 global et_arm_v8_2a_fp16_neon_flags
4076 return "$flags $et_arm_v8_2a_fp16_neon_flags"
4077 }
4078
4079 proc add_options_for_arm_crc { flags } {
4080 if { ! [check_effective_target_arm_crc_ok] } {
4081 return "$flags"
4082 }
4083 global et_arm_crc_flags
4084 return "$flags $et_arm_crc_flags"
4085 }
4086
4087 # Add the options needed for NEON. We need either -mfloat-abi=softfp
4088 # or -mfloat-abi=hard, but if one is already specified by the
4089 # multilib, use it. Similarly, if a -mfpu option already enables
4090 # NEON, do not add -mfpu=neon.
4091
4092 proc add_options_for_arm_neonv2 { flags } {
4093 if { ! [check_effective_target_arm_neonv2_ok] } {
4094 return "$flags"
4095 }
4096 global et_arm_neonv2_flags
4097 return "$flags $et_arm_neonv2_flags"
4098 }
4099
4100 # Add the options needed for vfp3.
4101 proc add_options_for_arm_vfp3 { flags } {
4102 if { ! [check_effective_target_arm_vfp3_ok] } {
4103 return "$flags"
4104 }
4105 return "$flags -mfpu=vfp3 -mfloat-abi=softfp"
4106 }
4107
4108 # Return 1 if this is an ARM target supporting -mfpu=neon
4109 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
4110 # incompatible with these options. Also set et_arm_neon_flags to the
4111 # best options to add.
4112
4113 proc check_effective_target_arm_neon_ok_nocache { } {
4114 global et_arm_neon_flags
4115 set et_arm_neon_flags ""
4116 if { [check_effective_target_arm32] } {
4117 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"} {
4118 if { [check_no_compiler_messages_nocache arm_neon_ok object {
4119 #include <arm_neon.h>
4120 int dummy;
4121 #ifndef __ARM_NEON__
4122 #error not NEON
4123 #endif
4124 /* Avoid the case where a test adds -mfpu=neon, but the toolchain is
4125 configured for -mcpu=arm926ej-s, for example. */
4126 #if __ARM_ARCH < 7 || __ARM_ARCH_PROFILE == 'M'
4127 #error Architecture does not support NEON.
4128 #endif
4129 } "$flags"] } {
4130 set et_arm_neon_flags $flags
4131 return 1
4132 }
4133 }
4134 }
4135
4136 return 0
4137 }
4138
4139 proc check_effective_target_arm_neon_ok { } {
4140 return [check_cached_effective_target arm_neon_ok \
4141 check_effective_target_arm_neon_ok_nocache]
4142 }
4143
4144
4145 # Return 1 if this is an ARM target supporting the SIMD32 intrinsics
4146 # from arm_acle.h. Some multilibs may be incompatible with these options.
4147 # Also set et_arm_simd32_flags to the best options to add.
4148 # arm_acle.h includes stdint.h which can cause trouble with incompatible
4149 # -mfloat-abi= options.
4150
4151 proc check_effective_target_arm_simd32_ok_nocache { } {
4152 global et_arm_simd32_flags
4153 set et_arm_simd32_flags ""
4154 foreach flags {"" "-march=armv6" "-march=armv6 -mfloat-abi=softfp" "-march=armv6 -mfloat-abi=hard"} {
4155 if { [check_no_compiler_messages_nocache arm_simd32_ok object {
4156 #include <arm_acle.h>
4157 int dummy;
4158 #ifndef __ARM_FEATURE_SIMD32
4159 #error not SIMD32
4160 #endif
4161 } "$flags"] } {
4162 set et_arm_simd32_flags $flags
4163 return 1
4164 }
4165 }
4166
4167 return 0
4168 }
4169
4170 proc check_effective_target_arm_simd32_ok { } {
4171 return [check_cached_effective_target arm_simd32_ok \
4172 check_effective_target_arm_simd32_ok_nocache]
4173 }
4174
4175 proc add_options_for_arm_simd32 { flags } {
4176 if { ! [check_effective_target_arm_simd32_ok] } {
4177 return "$flags"
4178 }
4179 global et_arm_simd32_flags
4180 return "$flags $et_arm_simd32_flags"
4181 }
4182
4183 # Return 1 if this is an ARM target supporting the __ssat and __usat
4184 # saturation intrinsics from arm_acle.h. Some multilibs may be
4185 # incompatible with these options. Also set et_arm_sat_flags to the
4186 # best options to add. arm_acle.h includes stdint.h which can cause
4187 # trouble with incompatible -mfloat-abi= options.
4188
4189 proc check_effective_target_arm_sat_ok_nocache { } {
4190 global et_arm_sat_flags
4191 set et_arm_sat_flags ""
4192 foreach flags {"" "-march=armv6" "-march=armv6 -mfloat-abi=softfp" "-march=armv6 -mfloat-abi=hard -mfpu=vfp"} {
4193 if { [check_no_compiler_messages_nocache et_arm_sat_flags object {
4194 #include <arm_acle.h>
4195 int dummy;
4196 #ifndef __ARM_FEATURE_SAT
4197 #error not SAT
4198 #endif
4199 } "$flags"] } {
4200 set et_arm_sat_flags $flags
4201 return 1
4202 }
4203 }
4204
4205 return 0
4206 }
4207
4208 proc check_effective_target_arm_sat_ok { } {
4209 return [check_cached_effective_target et_arm_sat_flags \
4210 check_effective_target_arm_sat_ok_nocache]
4211 }
4212
4213 proc add_options_for_arm_sat { flags } {
4214 if { ! [check_effective_target_arm_sat_ok] } {
4215 return "$flags"
4216 }
4217 global et_arm_sat_flags
4218 return "$flags $et_arm_sat_flags"
4219 }
4220
4221 # Return 1 if this is an ARM target supporting the DSP intrinsics from
4222 # arm_acle.h. Some multilibs may be incompatible with these options.
4223 # Also set et_arm_dsp_flags to the best options to add.
4224 # arm_acle.h includes stdint.h which can cause trouble with incompatible
4225 # -mfloat-abi= options.
4226 # check_effective_target_arm_dsp also exists, which checks the current
4227 # multilib, without trying other options.
4228
4229 proc check_effective_target_arm_dsp_ok_nocache { } {
4230 global et_arm_dsp_flags
4231 set et_arm_dsp_flags ""
4232 foreach flags {"" "-march=armv5te" "-march=armv5te -mfloat-abi=softfp" "-march=armv5te -mfloat-abi=hard"} {
4233 if { [check_no_compiler_messages_nocache et_arm_dsp_ok object {
4234 #include <arm_acle.h>
4235 int dummy;
4236 #ifndef __ARM_FEATURE_DSP
4237 #error not DSP
4238 #endif
4239 } "$flags"] } {
4240 set et_arm_dsp_flags $flags
4241 return 1
4242 }
4243 }
4244
4245 return 0
4246 }
4247
4248 proc check_effective_target_arm_dsp_ok { } {
4249 return [check_cached_effective_target et_arm_dsp_flags \
4250 check_effective_target_arm_dsp_ok_nocache]
4251 }
4252
4253 proc add_options_for_arm_dsp { flags } {
4254 if { ! [check_effective_target_arm_dsp_ok] } {
4255 return "$flags"
4256 }
4257 global et_arm_dsp_flags
4258 return "$flags $et_arm_dsp_flags"
4259 }
4260
4261 # Return 1 if this is an ARM target supporting -mfpu=neon without any
4262 # -mfloat-abi= option. Useful in tests where add_options is not
4263 # supported (such as lto tests).
4264
4265 proc check_effective_target_arm_neon_ok_no_float_abi_nocache { } {
4266 if { [check_effective_target_arm32] } {
4267 foreach flags {"-mfpu=neon"} {
4268 if { [check_no_compiler_messages_nocache arm_neon_ok_no_float_abi object {
4269 #include <arm_neon.h>
4270 int dummy;
4271 #ifndef __ARM_NEON__
4272 #error not NEON
4273 #endif
4274 /* Avoid the case where a test adds -mfpu=neon, but the toolchain is
4275 configured for -mcpu=arm926ej-s, for example. */
4276 #if __ARM_ARCH < 7 || __ARM_ARCH_PROFILE == 'M'
4277 #error Architecture does not support NEON.
4278 #endif
4279 } "$flags"] } {
4280 return 1
4281 }
4282 }
4283 }
4284
4285 return 0
4286 }
4287
4288 proc check_effective_target_arm_neon_ok_no_float_abi { } {
4289 return [check_cached_effective_target arm_neon_ok_no_float_abi \
4290 check_effective_target_arm_neon_ok_no_float_abi_nocache]
4291 }
4292
4293 proc check_effective_target_arm_crc_ok_nocache { } {
4294 global et_arm_crc_flags
4295 set et_arm_crc_flags "-march=armv8-a+crc"
4296 return [check_no_compiler_messages_nocache arm_crc_ok object {
4297 #if !defined (__ARM_FEATURE_CRC32)
4298 #error FOO
4299 #endif
4300 #include <arm_acle.h>
4301 } "$et_arm_crc_flags"]
4302 }
4303
4304 proc check_effective_target_arm_crc_ok { } {
4305 return [check_cached_effective_target arm_crc_ok \
4306 check_effective_target_arm_crc_ok_nocache]
4307 }
4308
4309 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
4310 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
4311 # incompatible with these options. Also set et_arm_neon_fp16_flags to
4312 # the best options to add.
4313
4314 proc check_effective_target_arm_neon_fp16_ok_nocache { } {
4315 global et_arm_neon_fp16_flags
4316 global et_arm_neon_flags
4317 set et_arm_neon_fp16_flags ""
4318 if { [check_effective_target_arm32]
4319 && [check_effective_target_arm_neon_ok] } {
4320 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
4321 "-mfpu=neon-fp16 -mfloat-abi=softfp"
4322 "-mfp16-format=ieee"
4323 "-mfloat-abi=softfp -mfp16-format=ieee"
4324 "-mfpu=neon-fp16 -mfp16-format=ieee"
4325 "-mfpu=neon-fp16 -mfloat-abi=softfp -mfp16-format=ieee"} {
4326 if { [check_no_compiler_messages_nocache arm_neon_fp16_ok object {
4327 #include "arm_neon.h"
4328 float16x4_t
4329 foo (float32x4_t arg)
4330 {
4331 return vcvt_f16_f32 (arg);
4332 }
4333 } "$et_arm_neon_flags $flags"] } {
4334 set et_arm_neon_fp16_flags [concat $et_arm_neon_flags $flags]
4335 return 1
4336 }
4337 }
4338 }
4339
4340 return 0
4341 }
4342
4343 proc check_effective_target_arm_neon_fp16_ok { } {
4344 return [check_cached_effective_target arm_neon_fp16_ok \
4345 check_effective_target_arm_neon_fp16_ok_nocache]
4346 }
4347
4348 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
4349 # and -mfloat-abi=softfp together. Some multilibs may be
4350 # incompatible with these options. Also set et_arm_neon_softfp_fp16_flags to
4351 # the best options to add.
4352
4353 proc check_effective_target_arm_neon_softfp_fp16_ok_nocache { } {
4354 global et_arm_neon_softfp_fp16_flags
4355 global et_arm_neon_flags
4356 set et_arm_neon_softfp_fp16_flags ""
4357 if { [check_effective_target_arm32]
4358 && [check_effective_target_arm_neon_ok] } {
4359 foreach flags {"-mfpu=neon-fp16 -mfloat-abi=softfp"
4360 "-mfpu=neon-fp16 -mfloat-abi=softfp -mfp16-format=ieee"} {
4361 if { [check_no_compiler_messages_nocache arm_neon_softfp_fp16_ok object {
4362 #include "arm_neon.h"
4363 float16x4_t
4364 foo (float32x4_t arg)
4365 {
4366 return vcvt_f16_f32 (arg);
4367 }
4368 } "$et_arm_neon_flags $flags"] } {
4369 set et_arm_neon_softfp_fp16_flags [concat $et_arm_neon_flags $flags]
4370 return 1
4371 }
4372 }
4373 }
4374
4375 return 0
4376 }
4377
4378 proc check_effective_target_arm_neon_softfp_fp16_ok { } {
4379 return [check_cached_effective_target arm_neon_softfp_fp16_ok \
4380 check_effective_target_arm_neon_softfp_fp16_ok_nocache]
4381 }
4382
4383
4384
4385 proc check_effective_target_arm_neon_fp16_hw { } {
4386 if {! [check_effective_target_arm_neon_fp16_ok] } {
4387 return 0
4388 }
4389 global et_arm_neon_fp16_flags
4390 check_runtime arm_neon_fp16_hw {
4391 int
4392 main (int argc, char **argv)
4393 {
4394 asm ("vcvt.f32.f16 q1, d0");
4395 return 0;
4396 }
4397 } $et_arm_neon_fp16_flags
4398 }
4399
4400 proc add_options_for_arm_neon_fp16 { flags } {
4401 if { ! [check_effective_target_arm_neon_fp16_ok] } {
4402 return "$flags"
4403 }
4404 global et_arm_neon_fp16_flags
4405 return "$flags $et_arm_neon_fp16_flags"
4406 }
4407
4408 proc add_options_for_arm_neon_softfp_fp16 { flags } {
4409 if { ! [check_effective_target_arm_neon_softfp_fp16_ok] } {
4410 return "$flags"
4411 }
4412 global et_arm_neon_softfp_fp16_flags
4413 return "$flags $et_arm_neon_softfp_fp16_flags"
4414 }
4415
4416 proc add_options_for_aarch64_sve { flags } {
4417 if { ![istarget aarch64*-*-*] || [check_effective_target_aarch64_sve] } {
4418 return "$flags"
4419 }
4420 return "$flags -march=armv8.2-a+sve"
4421 }
4422
4423 # Return 1 if this is an ARM target supporting the FP16 alternative
4424 # format. Some multilibs may be incompatible with the options needed. Also
4425 # set et_arm_neon_fp16_flags to the best options to add.
4426
4427 proc check_effective_target_arm_fp16_alternative_ok_nocache { } {
4428 if { [istarget *-*-vxworks7*] } {
4429 # Not supported by the target system.
4430 return 0
4431 }
4432 global et_arm_neon_fp16_flags
4433 set et_arm_neon_fp16_flags ""
4434 if { [check_effective_target_arm32] } {
4435 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
4436 "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
4437 if { [check_no_compiler_messages_nocache \
4438 arm_fp16_alternative_ok object {
4439 #if !defined (__ARM_FP16_FORMAT_ALTERNATIVE)
4440 #error __ARM_FP16_FORMAT_ALTERNATIVE not defined
4441 #endif
4442 } "$flags -mfp16-format=alternative"] } {
4443 set et_arm_neon_fp16_flags "$flags -mfp16-format=alternative"
4444 return 1
4445 }
4446 }
4447 }
4448
4449 return 0
4450 }
4451
4452 proc check_effective_target_arm_fp16_alternative_ok { } {
4453 return [check_cached_effective_target arm_fp16_alternative_ok \
4454 check_effective_target_arm_fp16_alternative_ok_nocache]
4455 }
4456
4457 # Return 1 if this is an ARM target supports specifying the FP16 none
4458 # format. Some multilibs may be incompatible with the options needed.
4459
4460 proc check_effective_target_arm_fp16_none_ok_nocache { } {
4461 if { [check_effective_target_arm32] } {
4462 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
4463 "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
4464 if { [check_no_compiler_messages_nocache \
4465 arm_fp16_none_ok object {
4466 #if defined (__ARM_FP16_FORMAT_ALTERNATIVE)
4467 #error __ARM_FP16_FORMAT_ALTERNATIVE defined
4468 #endif
4469 #if defined (__ARM_FP16_FORMAT_IEEE)
4470 #error __ARM_FP16_FORMAT_IEEE defined
4471 #endif
4472 } "$flags -mfp16-format=none"] } {
4473 return 1
4474 }
4475 }
4476 }
4477
4478 return 0
4479 }
4480
4481 proc check_effective_target_arm_fp16_none_ok { } {
4482 return [check_cached_effective_target arm_fp16_none_ok \
4483 check_effective_target_arm_fp16_none_ok_nocache]
4484 }
4485
4486 # Return 1 if this is an ARM target supporting -mfpu=neon-fp-armv8
4487 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
4488 # incompatible with these options. Also set et_arm_v8_neon_flags to the
4489 # best options to add.
4490
4491 proc check_effective_target_arm_v8_neon_ok_nocache { } {
4492 global et_arm_v8_neon_flags
4493 set et_arm_v8_neon_flags ""
4494 if { [check_effective_target_arm32] } {
4495 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp-armv8" "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
4496 if { [check_no_compiler_messages_nocache arm_v8_neon_ok object {
4497 #if __ARM_ARCH < 8
4498 #error not armv8 or later
4499 #endif
4500 #include "arm_neon.h"
4501 void
4502 foo ()
4503 {
4504 __asm__ volatile ("vrintn.f32 q0, q0");
4505 }
4506 } "$flags -march=armv8-a"] } {
4507 set et_arm_v8_neon_flags $flags
4508 return 1
4509 }
4510 }
4511 }
4512
4513 return 0
4514 }
4515
4516 proc check_effective_target_arm_v8_neon_ok { } {
4517 return [check_cached_effective_target arm_v8_neon_ok \
4518 check_effective_target_arm_v8_neon_ok_nocache]
4519 }
4520
4521 # Return 1 if this is an ARM target supporting -mfpu=neon-vfpv4
4522 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
4523 # incompatible with these options. Also set et_arm_neonv2_flags to the
4524 # best options to add.
4525
4526 proc check_effective_target_arm_neonv2_ok_nocache { } {
4527 global et_arm_neonv2_flags
4528 global et_arm_neon_flags
4529 set et_arm_neonv2_flags ""
4530 if { [check_effective_target_arm32]
4531 && [check_effective_target_arm_neon_ok] } {
4532 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-vfpv4" "-mfpu=neon-vfpv4 -mfloat-abi=softfp"} {
4533 if { [check_no_compiler_messages_nocache arm_neonv2_ok object {
4534 #include "arm_neon.h"
4535 float32x2_t
4536 foo (float32x2_t a, float32x2_t b, float32x2_t c)
4537 {
4538 return vfma_f32 (a, b, c);
4539 }
4540 } "$et_arm_neon_flags $flags"] } {
4541 set et_arm_neonv2_flags [concat $et_arm_neon_flags $flags]
4542 return 1
4543 }
4544 }
4545 }
4546
4547 return 0
4548 }
4549
4550 proc check_effective_target_arm_neonv2_ok { } {
4551 return [check_cached_effective_target arm_neonv2_ok \
4552 check_effective_target_arm_neonv2_ok_nocache]
4553 }
4554
4555 # Add the options needed for VFP FP16 support. We need either
4556 # -mfloat-abi=softfp or -mfloat-abi=hard. If one is already specified by
4557 # the multilib, use it.
4558
4559 proc add_options_for_arm_fp16 { flags } {
4560 if { ! [check_effective_target_arm_fp16_ok] } {
4561 return "$flags"
4562 }
4563 global et_arm_fp16_flags
4564 return "$flags $et_arm_fp16_flags"
4565 }
4566
4567 # Add the options needed to enable support for IEEE format
4568 # half-precision support. This is valid for ARM targets.
4569
4570 proc add_options_for_arm_fp16_ieee { flags } {
4571 if { ! [check_effective_target_arm_fp16_ok] } {
4572 return "$flags"
4573 }
4574 global et_arm_fp16_flags
4575 return "$flags $et_arm_fp16_flags -mfp16-format=ieee"
4576 }
4577
4578 # Add the options needed to enable support for ARM Alternative format
4579 # half-precision support. This is valid for ARM targets.
4580
4581 proc add_options_for_arm_fp16_alternative { flags } {
4582 if { ! [check_effective_target_arm_fp16_ok] } {
4583 return "$flags"
4584 }
4585 global et_arm_fp16_flags
4586 return "$flags $et_arm_fp16_flags -mfp16-format=alternative"
4587 }
4588
4589 # Return 1 if this is an ARM target that can support a VFP fp16 variant.
4590 # Skip multilibs that are incompatible with these options and set
4591 # et_arm_fp16_flags to the best options to add. This test is valid for
4592 # ARM only.
4593
4594 proc check_effective_target_arm_fp16_ok_nocache { } {
4595 global et_arm_fp16_flags
4596 set et_arm_fp16_flags ""
4597 if { ! [check_effective_target_arm32] } {
4598 return 0;
4599 }
4600 if [check-flags \
4601 [list "" { *-*-* } { "-mfpu=*" } \
4602 { "-mfpu=*fp16*" "-mfpu=*fpv[4-9]*" \
4603 "-mfpu=*fpv[1-9][0-9]*" "-mfpu=*fp-armv8*" } ]] {
4604 # Multilib flags would override -mfpu.
4605 return 0
4606 }
4607 if [check-flags [list "" { *-*-* } { "-mfloat-abi=soft" } { "" } ]] {
4608 # Must generate floating-point instructions.
4609 return 0
4610 }
4611 if [check_effective_target_arm_hf_eabi] {
4612 # Use existing float-abi and force an fpu which supports fp16
4613 set et_arm_fp16_flags "-mfpu=vfpv4"
4614 return 1;
4615 }
4616 if [check-flags [list "" { *-*-* } { "-mfpu=*" } { "" } ]] {
4617 # The existing -mfpu value is OK; use it, but add softfp.
4618 set et_arm_fp16_flags "-mfloat-abi=softfp"
4619 return 1;
4620 }
4621 # Add -mfpu for a VFP fp16 variant since there is no preprocessor
4622 # macro to check for this support.
4623 set flags "-mfpu=vfpv4 -mfloat-abi=softfp"
4624 if { [check_no_compiler_messages_nocache arm_fp16_ok assembly {
4625 int dummy;
4626 } "$flags"] } {
4627 set et_arm_fp16_flags "$flags"
4628 return 1
4629 }
4630
4631 return 0
4632 }
4633
4634 proc check_effective_target_arm_fp16_ok { } {
4635 return [check_cached_effective_target arm_fp16_ok \
4636 check_effective_target_arm_fp16_ok_nocache]
4637 }
4638
4639 # Return 1 if the target supports executing VFP FP16 instructions, 0
4640 # otherwise. This test is valid for ARM only.
4641
4642 proc check_effective_target_arm_fp16_hw { } {
4643 if {! [check_effective_target_arm_fp16_ok] } {
4644 return 0
4645 }
4646 global et_arm_fp16_flags
4647 check_runtime arm_fp16_hw {
4648 int
4649 main (int argc, char **argv)
4650 {
4651 __fp16 a = 1.0;
4652 float r;
4653 asm ("vcvtb.f32.f16 %0, %1"
4654 : "=w" (r) : "w" (a)
4655 : /* No clobbers. */);
4656 return (r == 1.0) ? 0 : 1;
4657 }
4658 } "$et_arm_fp16_flags -mfp16-format=ieee"
4659 }
4660
4661 # Creates a series of routines that return 1 if the given architecture
4662 # can be selected and a routine to give the flags to select that architecture
4663 # Note: Extra flags may be added to disable options from newer compilers
4664 # (Thumb in particular - but others may be added in the future).
4665 # Warning: Do not use check_effective_target_arm_arch_*_ok for architecture
4666 # extension (eg. ARMv8.1-A) since there is no macro defined for them. See
4667 # how only __ARM_ARCH_8A__ is checked for ARMv8.1-A.
4668 # Usage: /* { dg-require-effective-target arm_arch_v5_ok } */
4669 # /* { dg-add-options arm_arch_v5t } */
4670 # /* { dg-require-effective-target arm_arch_v5t_multilib } */
4671 foreach { armfunc armflag armdefs } {
4672 v4 "-march=armv4 -marm" __ARM_ARCH_4__
4673 v4t "-march=armv4t -mfloat-abi=softfp" __ARM_ARCH_4T__
4674 v4t_arm "-march=armv4t -marm" __ARM_ARCH_4T__
4675 v4t_thumb "-march=armv4t -mthumb -mfloat-abi=softfp" __ARM_ARCH_4T__
4676 v5t "-march=armv5t -mfloat-abi=softfp" __ARM_ARCH_5T__
4677 v5t_arm "-march=armv5t -marm" __ARM_ARCH_5T__
4678 v5t_thumb "-march=armv5t -mthumb -mfloat-abi=softfp" __ARM_ARCH_5T__
4679 v5te "-march=armv5te -mfloat-abi=softfp" __ARM_ARCH_5TE__
4680 v5te_arm "-march=armv5te -marm" __ARM_ARCH_5TE__
4681 v5te_thumb "-march=armv5te -mthumb -mfloat-abi=softfp" __ARM_ARCH_5TE__
4682 v6 "-march=armv6 -mfloat-abi=softfp" __ARM_ARCH_6__
4683 v6_arm "-march=armv6 -marm" __ARM_ARCH_6__
4684 v6_thumb "-march=armv6 -mthumb -mfloat-abi=softfp" __ARM_ARCH_6__
4685 v6k "-march=armv6k -mfloat-abi=softfp" __ARM_ARCH_6K__
4686 v6k_arm "-march=armv6k -marm" __ARM_ARCH_6K__
4687 v6k_thumb "-march=armv6k -mthumb -mfloat-abi=softfp" __ARM_ARCH_6K__
4688 v6t2 "-march=armv6t2" __ARM_ARCH_6T2__
4689 v6z "-march=armv6z -mfloat-abi=softfp" __ARM_ARCH_6Z__
4690 v6z_arm "-march=armv6z -marm" __ARM_ARCH_6Z__
4691 v6z_thumb "-march=armv6z -mthumb -mfloat-abi=softfp" __ARM_ARCH_6Z__
4692 v6m "-march=armv6-m -mthumb -mfloat-abi=soft" __ARM_ARCH_6M__
4693 v7a "-march=armv7-a" __ARM_ARCH_7A__
4694 v7r "-march=armv7-r" __ARM_ARCH_7R__
4695 v7m "-march=armv7-m -mthumb" __ARM_ARCH_7M__
4696 v7em "-march=armv7e-m -mthumb" __ARM_ARCH_7EM__
4697 v7ve "-march=armv7ve -marm"
4698 "__ARM_ARCH_7A__ && __ARM_FEATURE_IDIV"
4699 v8a "-march=armv8-a" __ARM_ARCH_8A__
4700 v8a_hard "-march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard" __ARM_ARCH_8A__
4701 v8_1a "-march=armv8.1-a" __ARM_ARCH_8A__
4702 v8_2a "-march=armv8.2-a" __ARM_ARCH_8A__
4703 v8r "-march=armv8-r" __ARM_ARCH_8R__
4704 v8m_base "-march=armv8-m.base -mthumb -mfloat-abi=soft"
4705 __ARM_ARCH_8M_BASE__
4706 v8m_main "-march=armv8-m.main -mthumb" __ARM_ARCH_8M_MAIN__
4707 v8_1m_main "-march=armv8.1-m.main -mthumb" __ARM_ARCH_8M_MAIN__ } {
4708 eval [string map [list FUNC $armfunc FLAG $armflag DEFS $armdefs ] {
4709 proc check_effective_target_arm_arch_FUNC_ok { } {
4710 return [check_no_compiler_messages arm_arch_FUNC_ok assembly {
4711 #if !(DEFS)
4712 #error !(DEFS)
4713 #endif
4714 int
4715 main (void)
4716 {
4717 return 0;
4718 }
4719 } "FLAG" ]
4720 }
4721
4722 proc add_options_for_arm_arch_FUNC { flags } {
4723 return "$flags FLAG"
4724 }
4725
4726 proc check_effective_target_arm_arch_FUNC_multilib { } {
4727 return [check_runtime arm_arch_FUNC_multilib {
4728 int
4729 main (void)
4730 {
4731 return 0;
4732 }
4733 } [add_options_for_arm_arch_FUNC ""]]
4734 }
4735 }]
4736 }
4737
4738 # Return 1 if GCC was configured with --with-mode=
4739 proc check_effective_target_default_mode { } {
4740
4741 return [check_configured_with "with-mode="]
4742 }
4743
4744 # Return 1 if this is an ARM target where -marm causes ARM to be
4745 # used (not Thumb)
4746
4747 proc check_effective_target_arm_arm_ok { } {
4748 return [check_no_compiler_messages arm_arm_ok assembly {
4749 #if !defined (__arm__) || defined (__thumb__) || defined (__thumb2__)
4750 #error !__arm__ || __thumb__ || __thumb2__
4751 #endif
4752 } "-marm"]
4753 }
4754
4755
4756 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
4757 # used.
4758
4759 proc check_effective_target_arm_thumb1_ok { } {
4760 return [check_no_compiler_messages arm_thumb1_ok assembly {
4761 #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
4762 #error !__arm__ || !__thumb__ || __thumb2__
4763 #endif
4764 int foo (int i) { return i; }
4765 } "-mthumb"]
4766 }
4767
4768 # Return 1 is this is an ARM target where -mthumb causes Thumb-2 to be
4769 # used.
4770
4771 proc check_effective_target_arm_thumb2_ok { } {
4772 return [check_no_compiler_messages arm_thumb2_ok assembly {
4773 #if !defined(__thumb2__)
4774 #error !__thumb2__
4775 #endif
4776 int foo (int i) { return i; }
4777 } "-mthumb"]
4778 }
4779
4780 # Return 1 if this is an ARM target where Thumb-1 is used without options
4781 # added by the test.
4782
4783 proc check_effective_target_arm_thumb1 { } {
4784 return [check_no_compiler_messages arm_thumb1 assembly {
4785 #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
4786 #error !__arm__ || !__thumb__ || __thumb2__
4787 #endif
4788 int i;
4789 } ""]
4790 }
4791
4792 # Return 1 if this is an ARM target where Thumb-2 is used without options
4793 # added by the test.
4794
4795 proc check_effective_target_arm_thumb2 { } {
4796 return [check_no_compiler_messages arm_thumb2 assembly {
4797 #if !defined(__thumb2__)
4798 #error !__thumb2__
4799 #endif
4800 int i;
4801 } ""]
4802 }
4803
4804 # Return 1 if this is an ARM target where conditional execution is available.
4805
4806 proc check_effective_target_arm_cond_exec { } {
4807 return [check_no_compiler_messages arm_cond_exec assembly {
4808 #if defined(__arm__) && defined(__thumb__) && !defined(__thumb2__)
4809 #error FOO
4810 #endif
4811 int i;
4812 } ""]
4813 }
4814
4815 # Return 1 if this is an ARM cortex-M profile cpu
4816
4817 proc check_effective_target_arm_cortex_m { } {
4818 if { ![istarget arm*-*-*] } {
4819 return 0
4820 }
4821 return [check_no_compiler_messages arm_cortex_m assembly {
4822 #if defined(__ARM_ARCH_ISA_ARM)
4823 #error __ARM_ARCH_ISA_ARM is defined
4824 #endif
4825 int i;
4826 } "-mthumb"]
4827 }
4828
4829 # Return 1 if this is an ARM target where -mthumb causes Thumb-1 to be
4830 # used and MOVT/MOVW instructions to be available.
4831
4832 proc check_effective_target_arm_thumb1_movt_ok {} {
4833 if [check_effective_target_arm_thumb1_ok] {
4834 return [check_no_compiler_messages arm_movt object {
4835 int
4836 foo (void)
4837 {
4838 asm ("movt r0, #42");
4839 }
4840 } "-mthumb"]
4841 } else {
4842 return 0
4843 }
4844 }
4845
4846 # Return 1 if this is an ARM target where -mthumb causes Thumb-1 to be
4847 # used and CBZ and CBNZ instructions are available.
4848
4849 proc check_effective_target_arm_thumb1_cbz_ok {} {
4850 if [check_effective_target_arm_thumb1_ok] {
4851 return [check_no_compiler_messages arm_movt object {
4852 int
4853 foo (void)
4854 {
4855 asm ("cbz r0, 2f\n2:");
4856 }
4857 } "-mthumb"]
4858 } else {
4859 return 0
4860 }
4861 }
4862
4863 # Return 1 if this is an ARM target where ARMv8-M Security Extensions is
4864 # available.
4865
4866 proc check_effective_target_arm_cmse_ok {} {
4867 return [check_no_compiler_messages arm_cmse object {
4868 int
4869 foo (void)
4870 {
4871 asm ("bxns r0");
4872 }
4873 } "-mcmse"];
4874 }
4875
4876 # Return 1 if the target supports executing CMSE instructions, 0
4877 # otherwise. Cache the result.
4878
4879 proc check_effective_target_arm_cmse_hw { } {
4880 return [check_runtime arm_cmse_hw_available {
4881 int main (void)
4882 {
4883 unsigned id_pfr1;
4884 asm ("ldr\t%0, =0xe000ed44\n" \
4885 "ldr\t%0, [%0]\n" \
4886 "sg" : "=l" (id_pfr1));
4887 /* Exit with code 0 iff security extension is available. */
4888 return !(id_pfr1 & 0xf0);
4889 }
4890 } "-mcmse"]
4891 }
4892 # Return 1 if the target supports executing MVE instructions, 0
4893 # otherwise.
4894
4895 proc check_effective_target_arm_mve_hw {} {
4896 return [check_runtime arm_mve_hw_available {
4897 int
4898 main (void)
4899 {
4900 long long a = 16;
4901 int b = 3;
4902 asm ("sqrshrl %Q1, %R1, #64, %2"
4903 : "=l" (a)
4904 : "0" (a), "r" (b));
4905 return (a != 2);
4906 }
4907 } ""]
4908 }
4909
4910 # Return 1 if this is an ARM target where ARMv8-M Security Extensions with
4911 # clearing instructions (clrm, vscclrm, vstr/vldr with FPCXT) is available.
4912
4913 proc check_effective_target_arm_cmse_clear_ok {} {
4914 return [check_no_compiler_messages arm_cmse_clear object {
4915 int
4916 foo (void)
4917 {
4918 asm ("clrm {r1, r2}");
4919 }
4920 } "-mcmse"];
4921 }
4922
4923 # Return 1 if this compilation turns on string_ops_prefer_neon on.
4924
4925 proc check_effective_target_arm_tune_string_ops_prefer_neon { } {
4926 return [check_no_messages_and_pattern arm_tune_string_ops_prefer_neon "@string_ops_prefer_neon:\t1" assembly {
4927 int foo (void) { return 0; }
4928 } "-O2 -mprint-tune-info" ]
4929 }
4930
4931 # Return 1 if the target supports executing NEON instructions, 0
4932 # otherwise. Cache the result.
4933
4934 proc check_effective_target_arm_neon_hw { } {
4935 return [check_runtime arm_neon_hw_available {
4936 int
4937 main (void)
4938 {
4939 long long a = 0, b = 1;
4940 asm ("vorr %P0, %P1, %P2"
4941 : "=w" (a)
4942 : "0" (a), "w" (b));
4943 return (a != 1);
4944 }
4945 } [add_options_for_arm_neon ""]]
4946 }
4947
4948 # Return true if this is an AArch64 target that can run SVE code.
4949
4950 proc check_effective_target_aarch64_sve_hw { } {
4951 if { ![istarget aarch64*-*-*] } {
4952 return 0
4953 }
4954 return [check_runtime aarch64_sve_hw_available {
4955 int
4956 main (void)
4957 {
4958 asm volatile ("ptrue p0.b");
4959 return 0;
4960 }
4961 } [add_options_for_aarch64_sve ""]]
4962 }
4963
4964 # Return true if this is an AArch64 target that can run SVE2 code.
4965
4966 proc check_effective_target_aarch64_sve2_hw { } {
4967 if { ![istarget aarch64*-*-*] } {
4968 return 0
4969 }
4970 return [check_runtime aarch64_sve2_hw_available {
4971 int
4972 main (void)
4973 {
4974 asm volatile ("addp z0.b, p0/m, z0.b, z1.b");
4975 return 0;
4976 }
4977 }]
4978 }
4979
4980 # Return true if this is an AArch64 target that can run SVE code and
4981 # if its SVE vectors have exactly BITS bits.
4982
4983 proc aarch64_sve_hw_bits { bits } {
4984 if { ![check_effective_target_aarch64_sve_hw] } {
4985 return 0
4986 }
4987 return [check_runtime aarch64_sve${bits}_hw [subst {
4988 int
4989 main (void)
4990 {
4991 int res;
4992 asm volatile ("cntd %0" : "=r" (res));
4993 if (res * 64 != $bits)
4994 __builtin_abort ();
4995 return 0;
4996 }
4997 }] [add_options_for_aarch64_sve ""]]
4998 }
4999
5000 # Return true if this is an AArch64 target that can run SVE code and
5001 # if its SVE vectors have exactly 256 bits.
5002
5003 foreach N { 128 256 512 1024 2048 } {
5004 eval [string map [list N $N] {
5005 proc check_effective_target_aarch64_sveN_hw { } {
5006 return [aarch64_sve_hw_bits N]
5007 }
5008 }]
5009 }
5010
5011 proc check_effective_target_arm_neonv2_hw { } {
5012 return [check_runtime arm_neon_hwv2_available {
5013 #include "arm_neon.h"
5014 int
5015 main (void)
5016 {
5017 float32x2_t a, b, c;
5018 asm ("vfma.f32 %P0, %P1, %P2"
5019 : "=w" (a)
5020 : "w" (b), "w" (c));
5021 return 0;
5022 }
5023 } [add_options_for_arm_neonv2 ""]]
5024 }
5025
5026 # ID_AA64PFR1_EL1.BT using bits[3:0] == 1 implies BTI implimented.
5027 proc check_effective_target_aarch64_bti_hw { } {
5028 if { ![istarget aarch64*-*-*] } {
5029 return 0
5030 }
5031 return [check_runtime aarch64_bti_hw_available {
5032 int
5033 main (void)
5034 {
5035 int a;
5036 asm volatile ("mrs %0, id_aa64pfr1_el1" : "=r" (a));
5037 return !((a & 0xf) == 1);
5038 }
5039 } "-O2" ]
5040 }
5041
5042 # Return 1 if the target supports executing the armv8.3-a FJCVTZS
5043 # instruction.
5044 proc check_effective_target_aarch64_fjcvtzs_hw { } {
5045 if { ![istarget aarch64*-*-*] } {
5046 return 0
5047 }
5048 return [check_runtime aarch64_fjcvtzs_hw_available {
5049 int
5050 main (void)
5051 {
5052 double in = 25.1;
5053 int out;
5054 asm volatile ("fjcvtzs %w0, %d1"
5055 : "=r" (out)
5056 : "w" (in)
5057 : /* No clobbers. */);
5058 return out != 25;
5059 }
5060 } "-march=armv8.3-a" ]
5061 }
5062
5063 # Return 1 if GCC was configured with --enable-standard-branch-protection
5064 proc check_effective_target_default_branch_protection { } {
5065 return [check_configured_with "enable-standard-branch-protection"]
5066 }
5067
5068 # Return 1 if this is an ARM target supporting -mfloat-abi=softfp.
5069
5070 proc check_effective_target_arm_softfp_ok { } {
5071 return [check_no_compiler_messages arm_softfp_ok object {
5072 #include <stdint.h>
5073 int dummy;
5074 int main (void) { return 0; }
5075 } "-mfloat-abi=softfp"]
5076 }
5077
5078 # Return 1 if this is an ARM target supporting -mfloat-abi=hard.
5079
5080 proc check_effective_target_arm_hard_ok { } {
5081 return [check_no_compiler_messages arm_hard_ok object {
5082 #include <stdint.h>
5083 int dummy;
5084 int main (void) { return 0; }
5085 } "-mfloat-abi=hard"]
5086 }
5087
5088 # Return 1 if the target supports ARMv8.1-M MVE with floating point
5089 # instructions, 0 otherwise. The test is valid for ARM.
5090 # Record the command line options needed.
5091
5092 proc check_effective_target_arm_v8_1m_mve_fp_ok_nocache { } {
5093 global et_arm_v8_1m_mve_fp_flags
5094 set et_arm_v8_1m_mve_fp_flags ""
5095
5096 if { ![istarget arm*-*-*] } {
5097 return 0;
5098 }
5099
5100 # Iterate through sets of options to find the compiler flags that
5101 # need to be added to the -march option.
5102 foreach flags {"" "-mfloat-abi=softfp -mfpu=auto -march=armv8.1-m.main+mve.fp" "-mfloat-abi=hard -mfpu=auto -march=armv8.1-m.main+mve.fp"} {
5103 if { [check_no_compiler_messages_nocache \
5104 arm_v8_1m_mve_fp_ok object {
5105 #include <arm_mve.h>
5106 #if !(__ARM_FEATURE_MVE & 2)
5107 #error "__ARM_FEATURE_MVE for floating point not defined"
5108 #endif
5109 #if __ARM_BIG_ENDIAN
5110 #error "MVE intrinsics are not supported in Big-Endian mode."
5111 #endif
5112 } "$flags -mthumb"] } {
5113 set et_arm_v8_1m_mve_fp_flags "$flags -mthumb --save-temps"
5114 return 1
5115 }
5116 }
5117
5118 return 0;
5119 }
5120
5121 proc check_effective_target_arm_v8_1m_mve_fp_ok { } {
5122 return [check_cached_effective_target arm_v8_1m_mve_fp_ok \
5123 check_effective_target_arm_v8_1m_mve_fp_ok_nocache]
5124 }
5125
5126 proc add_options_for_arm_v8_1m_mve_fp { flags } {
5127 if { ! [check_effective_target_arm_v8_1m_mve_fp_ok] } {
5128 return "$flags"
5129 }
5130 global et_arm_v8_1m_mve_fp_flags
5131 return "$flags $et_arm_v8_1m_mve_fp_flags"
5132 }
5133
5134 # Return 1 if the target supports the ARMv8.1 Adv.SIMD extension, 0
5135 # otherwise. The test is valid for AArch64 and ARM. Record the command
5136 # line options needed.
5137
5138 proc check_effective_target_arm_v8_1a_neon_ok_nocache { } {
5139 global et_arm_v8_1a_neon_flags
5140 set et_arm_v8_1a_neon_flags ""
5141
5142 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
5143 return 0;
5144 }
5145
5146 # Iterate through sets of options to find the compiler flags that
5147 # need to be added to the -march option. Start with the empty set
5148 # since AArch64 only needs the -march setting.
5149 foreach flags {"" "-mfpu=neon-fp-armv8" "-mfloat-abi=softfp" \
5150 "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
5151 foreach arches { "-march=armv8-a+rdma" "-march=armv8.1-a" } {
5152 if { [check_no_compiler_messages_nocache arm_v8_1a_neon_ok object {
5153 #if !defined (__ARM_FEATURE_QRDMX)
5154 #error "__ARM_FEATURE_QRDMX not defined"
5155 #endif
5156 } "$flags $arches"] } {
5157 set et_arm_v8_1a_neon_flags "$flags $arches"
5158 return 1
5159 }
5160 }
5161 }
5162
5163 return 0;
5164 }
5165
5166 proc check_effective_target_arm_v8_1a_neon_ok { } {
5167 return [check_cached_effective_target arm_v8_1a_neon_ok \
5168 check_effective_target_arm_v8_1a_neon_ok_nocache]
5169 }
5170
5171 # Return 1 if the target supports ARMv8.2 scalar FP16 arithmetic
5172 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
5173 # Record the command line options needed.
5174
5175 proc check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache { } {
5176 global et_arm_v8_2a_fp16_scalar_flags
5177 set et_arm_v8_2a_fp16_scalar_flags ""
5178
5179 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
5180 return 0;
5181 }
5182
5183 # Iterate through sets of options to find the compiler flags that
5184 # need to be added to the -march option.
5185 foreach flags {"" "-mfpu=fp-armv8" "-mfloat-abi=softfp" \
5186 "-mfpu=fp-armv8 -mfloat-abi=softfp"} {
5187 if { [check_no_compiler_messages_nocache \
5188 arm_v8_2a_fp16_scalar_ok object {
5189 #if !defined (__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
5190 #error "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC not defined"
5191 #endif
5192 } "$flags -march=armv8.2-a+fp16"] } {
5193 set et_arm_v8_2a_fp16_scalar_flags "$flags -march=armv8.2-a+fp16"
5194 return 1
5195 }
5196 }
5197
5198 return 0;
5199 }
5200
5201 proc check_effective_target_arm_v8_2a_fp16_scalar_ok { } {
5202 return [check_cached_effective_target arm_v8_2a_fp16_scalar_ok \
5203 check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache]
5204 }
5205
5206 # Return 1 if the target supports ARMv8.2 Adv.SIMD FP16 arithmetic
5207 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
5208 # Record the command line options needed.
5209
5210 proc check_effective_target_arm_v8_2a_fp16_neon_ok_nocache { } {
5211 global et_arm_v8_2a_fp16_neon_flags
5212 set et_arm_v8_2a_fp16_neon_flags ""
5213
5214 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
5215 return 0;
5216 }
5217
5218 # Iterate through sets of options to find the compiler flags that
5219 # need to be added to the -march option.
5220 foreach flags {"" "-mfpu=neon-fp-armv8" "-mfloat-abi=softfp" \
5221 "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
5222 if { [check_no_compiler_messages_nocache \
5223 arm_v8_2a_fp16_neon_ok object {
5224 #if !defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
5225 #error "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC not defined"
5226 #endif
5227 } "$flags -march=armv8.2-a+fp16"] } {
5228 set et_arm_v8_2a_fp16_neon_flags "$flags -march=armv8.2-a+fp16"
5229 return 1
5230 }
5231 }
5232
5233 return 0;
5234 }
5235
5236 proc check_effective_target_arm_v8_2a_fp16_neon_ok { } {
5237 return [check_cached_effective_target arm_v8_2a_fp16_neon_ok \
5238 check_effective_target_arm_v8_2a_fp16_neon_ok_nocache]
5239 }
5240
5241 # Return 1 if the target supports ARMv8.2 Adv.SIMD Dot Product
5242 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
5243 # Record the command line options needed.
5244
5245 proc check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache { } {
5246 global et_arm_v8_2a_dotprod_neon_flags
5247 set et_arm_v8_2a_dotprod_neon_flags ""
5248
5249 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
5250 return 0;
5251 }
5252
5253 # Iterate through sets of options to find the compiler flags that
5254 # need to be added to the -march option.
5255 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8"} {
5256 if { [check_no_compiler_messages_nocache \
5257 arm_v8_2a_dotprod_neon_ok object {
5258 #include <stdint.h>
5259 #if !defined (__ARM_FEATURE_DOTPROD)
5260 #error "__ARM_FEATURE_DOTPROD not defined"
5261 #endif
5262 } "$flags -march=armv8.2-a+dotprod"] } {
5263 set et_arm_v8_2a_dotprod_neon_flags "$flags -march=armv8.2-a+dotprod"
5264 return 1
5265 }
5266 }
5267
5268 return 0;
5269 }
5270
5271 # Return 1 if the target supports ARMv8.1-M MVE
5272 # instructions, 0 otherwise. The test is valid for ARM.
5273 # Record the command line options needed.
5274
5275 proc check_effective_target_arm_v8_1m_mve_ok_nocache { } {
5276 global et_arm_v8_1m_mve_flags
5277 set et_arm_v8_1m_mve_flags ""
5278
5279 if { ![istarget arm*-*-*] } {
5280 return 0;
5281 }
5282
5283 # Iterate through sets of options to find the compiler flags that
5284 # need to be added to the -march option.
5285 foreach flags {"" "-mfloat-abi=softfp -mfpu=auto -march=armv8.1-m.main+mve" "-mfloat-abi=hard -mfpu=auto -march=armv8.1-m.main+mve"} {
5286 if { [check_no_compiler_messages_nocache \
5287 arm_v8_1m_mve_ok object {
5288 #if !defined (__ARM_FEATURE_MVE)
5289 #error "__ARM_FEATURE_MVE not defined"
5290 #endif
5291 #if __ARM_BIG_ENDIAN
5292 #error "MVE intrinsics are not supported in Big-Endian mode."
5293 #endif
5294 #include <arm_mve.h>
5295 } "$flags -mthumb"] } {
5296 set et_arm_v8_1m_mve_flags "$flags -mthumb --save-temps"
5297 return 1
5298 }
5299 }
5300
5301 return 0;
5302 }
5303
5304 proc check_effective_target_arm_v8_1m_mve_ok { } {
5305 return [check_cached_effective_target arm_v8_1m_mve_ok \
5306 check_effective_target_arm_v8_1m_mve_ok_nocache]
5307 }
5308
5309 proc add_options_for_arm_v8_1m_mve { flags } {
5310 if { ! [check_effective_target_arm_v8_1m_mve_ok] } {
5311 return "$flags"
5312 }
5313 global et_arm_v8_1m_mve_flags
5314 return "$flags $et_arm_v8_1m_mve_flags"
5315 }
5316
5317 proc check_effective_target_arm_v8_2a_dotprod_neon_ok { } {
5318 return [check_cached_effective_target arm_v8_2a_dotprod_neon_ok \
5319 check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache]
5320 }
5321
5322 proc add_options_for_arm_v8_2a_dotprod_neon { flags } {
5323 if { ! [check_effective_target_arm_v8_2a_dotprod_neon_ok] } {
5324 return "$flags"
5325 }
5326 global et_arm_v8_2a_dotprod_neon_flags
5327 return "$flags $et_arm_v8_2a_dotprod_neon_flags"
5328 }
5329
5330 # Return 1 if the target supports ARMv8.2+i8mm Adv.SIMD Dot Product
5331 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
5332 # Record the command line options needed.
5333
5334 proc check_effective_target_arm_v8_2a_i8mm_ok_nocache { } {
5335 global et_arm_v8_2a_i8mm_flags
5336 set et_arm_v8_2a_i8mm_flags ""
5337
5338 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
5339 return 0;
5340 }
5341
5342 # Iterate through sets of options to find the compiler flags that
5343 # need to be added to the -march option.
5344 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8" } {
5345 if { [check_no_compiler_messages_nocache \
5346 arm_v8_2a_i8mm_ok object {
5347 #include <arm_neon.h>
5348 #if !defined (__ARM_FEATURE_MATMUL_INT8)
5349 #error "__ARM_FEATURE_MATMUL_INT8 not defined"
5350 #endif
5351 } "$flags -march=armv8.2-a+i8mm"] } {
5352 set et_arm_v8_2a_i8mm_flags "$flags -march=armv8.2-a+i8mm"
5353 return 1
5354 }
5355 }
5356
5357 return 0;
5358 }
5359
5360 proc check_effective_target_arm_v8_2a_i8mm_ok { } {
5361 return [check_cached_effective_target arm_v8_2a_i8mm_ok \
5362 check_effective_target_arm_v8_2a_i8mm_ok_nocache]
5363 }
5364
5365 proc add_options_for_arm_v8_2a_i8mm { flags } {
5366 if { ! [check_effective_target_arm_v8_2a_i8mm_ok] } {
5367 return "$flags"
5368 }
5369 global et_arm_v8_2a_i8mm_flags
5370 return "$flags $et_arm_v8_2a_i8mm_flags"
5371 }
5372
5373 # Return 1 if the target supports FP16 VFMAL and VFMSL
5374 # instructions, 0 otherwise.
5375 # Record the command line options needed.
5376
5377 proc check_effective_target_arm_fp16fml_neon_ok_nocache { } {
5378 global et_arm_fp16fml_neon_flags
5379 set et_arm_fp16fml_neon_flags ""
5380
5381 if { ![istarget arm*-*-*] } {
5382 return 0;
5383 }
5384
5385 # Iterate through sets of options to find the compiler flags that
5386 # need to be added to the -march option.
5387 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8"} {
5388 if { [check_no_compiler_messages_nocache \
5389 arm_fp16fml_neon_ok assembly {
5390 #include <arm_neon.h>
5391 float32x2_t
5392 foo (float32x2_t r, float16x4_t a, float16x4_t b)
5393 {
5394 return vfmlal_high_f16 (r, a, b);
5395 }
5396 } "$flags -march=armv8.2-a+fp16fml"] } {
5397 set et_arm_fp16fml_neon_flags "$flags -march=armv8.2-a+fp16fml"
5398 return 1
5399 }
5400 }
5401
5402 return 0;
5403 }
5404
5405 proc check_effective_target_arm_fp16fml_neon_ok { } {
5406 return [check_cached_effective_target arm_fp16fml_neon_ok \
5407 check_effective_target_arm_fp16fml_neon_ok_nocache]
5408 }
5409
5410 proc add_options_for_arm_fp16fml_neon { flags } {
5411 if { ! [check_effective_target_arm_fp16fml_neon_ok] } {
5412 return "$flags"
5413 }
5414 global et_arm_fp16fml_neon_flags
5415 return "$flags $et_arm_fp16fml_neon_flags"
5416 }
5417
5418 # Return 1 if the target supports BFloat16 SIMD instructions, 0 otherwise.
5419 # The test is valid for ARM and for AArch64.
5420
5421 proc check_effective_target_arm_v8_2a_bf16_neon_ok_nocache { } {
5422 global et_arm_v8_2a_bf16_neon_flags
5423 set et_arm_v8_2a_bf16_neon_flags ""
5424
5425 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
5426 return 0;
5427 }
5428
5429 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8" } {
5430 if { [check_no_compiler_messages_nocache arm_v8_2a_bf16_neon_ok object {
5431 #include <arm_neon.h>
5432 #if !defined (__ARM_FEATURE_BF16_VECTOR_ARITHMETIC)
5433 #error "__ARM_FEATURE_BF16_VECTOR_ARITHMETIC not defined"
5434 #endif
5435 } "$flags -march=armv8.2-a+bf16"] } {
5436 set et_arm_v8_2a_bf16_neon_flags "$flags -march=armv8.2-a+bf16"
5437 return 1
5438 }
5439 }
5440
5441 return 0;
5442 }
5443
5444 proc check_effective_target_arm_v8_2a_bf16_neon_ok { } {
5445 return [check_cached_effective_target arm_v8_2a_bf16_neon_ok \
5446 check_effective_target_arm_v8_2a_bf16_neon_ok_nocache]
5447 }
5448
5449 proc add_options_for_arm_v8_2a_bf16_neon { flags } {
5450 if { ! [check_effective_target_arm_v8_2a_bf16_neon_ok] } {
5451 return "$flags"
5452 }
5453 global et_arm_v8_2a_bf16_neon_flags
5454 return "$flags $et_arm_v8_2a_bf16_neon_flags"
5455 }
5456
5457 # A series of routines are created to 1) check if a given architecture is
5458 # effective (check_effective_target_*_ok) and then 2) give the corresponding
5459 # flags that enable the architecture (add_options_for_*).
5460 # The series includes:
5461 # arm_v8m_main_cde: Armv8-m CDE (Custom Datapath Extension).
5462 # arm_v8m_main_cde_fp: Armv8-m CDE with FP registers.
5463 # arm_v8_1m_main_cde_mve: Armv8.1-m CDE with MVE.
5464 # Usage:
5465 # /* { dg-require-effective-target arm_v8m_main_cde_ok } */
5466 # /* { dg-add-options arm_v8m_main_cde } */
5467 # The tests are valid for Arm.
5468
5469 foreach { armfunc armflag armdef arminc } {
5470 arm_v8m_main_cde
5471 "-march=armv8-m.main+cdecp0+cdecp6 -mthumb"
5472 "defined (__ARM_FEATURE_CDE)"
5473 ""
5474 arm_v8m_main_cde_fp
5475 "-march=armv8-m.main+fp+cdecp0+cdecp6 -mthumb -mfpu=auto"
5476 "defined (__ARM_FEATURE_CDE) && defined (__ARM_FP)"
5477 ""
5478 arm_v8_1m_main_cde_mve
5479 "-march=armv8.1-m.main+mve+cdecp0+cdecp6 -mthumb -mfpu=auto"
5480 "defined (__ARM_FEATURE_CDE) && defined (__ARM_FEATURE_MVE)"
5481 "#include <arm_mve.h>"
5482 arm_v8_1m_main_cde_mve_fp
5483 "-march=armv8.1-m.main+mve.fp+cdecp0+cdecp6 -mthumb -mfpu=auto"
5484 "defined (__ARM_FEATURE_CDE) || __ARM_FEATURE_MVE == 3"
5485 "#include <arm_mve.h>"
5486 } {
5487 eval [string map [list FUNC $armfunc FLAG $armflag DEF $armdef INC $arminc ] {
5488 proc check_effective_target_FUNC_ok_nocache { } {
5489 global et_FUNC_flags
5490 set et_FUNC_flags ""
5491
5492 if { ![istarget arm*-*-*] } {
5493 return 0;
5494 }
5495
5496 if { [check_no_compiler_messages_nocache FUNC_ok assembly {
5497 #if !(DEF)
5498 #error "DEF failed"
5499 #endif
5500 #include <arm_cde.h>
5501 INC
5502 } "FLAG"] } {
5503 set et_FUNC_flags "FLAG"
5504 return 1
5505 }
5506
5507 return 0;
5508 }
5509
5510 proc check_effective_target_FUNC_ok { } {
5511 return [check_cached_effective_target FUNC_ok \
5512 check_effective_target_FUNC_ok_nocache]
5513 }
5514
5515 proc add_options_for_FUNC { flags } {
5516 if { ! [check_effective_target_FUNC_ok] } {
5517 return "$flags"
5518 }
5519 global et_FUNC_flags
5520 return "$flags $et_FUNC_flags"
5521 }
5522
5523 proc check_effective_target_FUNC_multilib { } {
5524 if { ! [check_effective_target_FUNC_ok] } {
5525 return 0;
5526 }
5527 return [check_runtime FUNC_multilib {
5528 #if !(DEF)
5529 #error "DEF failed"
5530 #endif
5531 #include <arm_cde.h>
5532 INC
5533 int
5534 main (void)
5535 {
5536 return 0;
5537 }
5538 } [add_options_for_FUNC ""]]
5539 }
5540 }]
5541 }
5542
5543 # Return 1 if the target supports executing ARMv8 NEON instructions, 0
5544 # otherwise.
5545
5546 proc check_effective_target_arm_v8_neon_hw { } {
5547 return [check_runtime arm_v8_neon_hw_available {
5548 #include "arm_neon.h"
5549 int
5550 main (void)
5551 {
5552 float32x2_t a = { 1.0f, 2.0f };
5553 #ifdef __ARM_ARCH_ISA_A64
5554 asm ("frinta %0.2s, %1.2s"
5555 : "=w" (a)
5556 : "w" (a));
5557 #else
5558 asm ("vrinta.f32 %P0, %P1"
5559 : "=w" (a)
5560 : "0" (a));
5561 #endif
5562 return a[0] == 2.0f;
5563 }
5564 } [add_options_for_arm_v8_neon ""]]
5565 }
5566
5567 # Return 1 if the target supports executing the ARMv8.1 Adv.SIMD extension, 0
5568 # otherwise. The test is valid for AArch64 and ARM.
5569
5570 proc check_effective_target_arm_v8_1a_neon_hw { } {
5571 if { ![check_effective_target_arm_v8_1a_neon_ok] } {
5572 return 0;
5573 }
5574 return [check_runtime arm_v8_1a_neon_hw_available {
5575 int
5576 main (void)
5577 {
5578 #ifdef __ARM_ARCH_ISA_A64
5579 __Int32x2_t a = {0, 1};
5580 __Int32x2_t b = {0, 2};
5581 __Int32x2_t result;
5582
5583 asm ("sqrdmlah %0.2s, %1.2s, %2.2s"
5584 : "=w"(result)
5585 : "w"(a), "w"(b)
5586 : /* No clobbers. */);
5587
5588 #else
5589
5590 __simd64_int32_t a = {0, 1};
5591 __simd64_int32_t b = {0, 2};
5592 __simd64_int32_t result;
5593
5594 asm ("vqrdmlah.s32 %P0, %P1, %P2"
5595 : "=w"(result)
5596 : "w"(a), "w"(b)
5597 : /* No clobbers. */);
5598 #endif
5599
5600 return result[0];
5601 }
5602 } [add_options_for_arm_v8_1a_neon ""]]
5603 }
5604
5605 # Return 1 if the target supports executing floating point instructions from
5606 # ARMv8.2 with the FP16 extension, 0 otherwise. The test is valid for ARM and
5607 # for AArch64.
5608
5609 proc check_effective_target_arm_v8_2a_fp16_scalar_hw { } {
5610 if { ![check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
5611 return 0;
5612 }
5613 return [check_runtime arm_v8_2a_fp16_scalar_hw_available {
5614 int
5615 main (void)
5616 {
5617 __fp16 a = 1.0;
5618 __fp16 result;
5619
5620 #ifdef __ARM_ARCH_ISA_A64
5621
5622 asm ("fabs %h0, %h1"
5623 : "=w"(result)
5624 : "w"(a)
5625 : /* No clobbers. */);
5626
5627 #else
5628
5629 asm ("vabs.f16 %0, %1"
5630 : "=w"(result)
5631 : "w"(a)
5632 : /* No clobbers. */);
5633
5634 #endif
5635
5636 return (result == 1.0) ? 0 : 1;
5637 }
5638 } [add_options_for_arm_v8_2a_fp16_scalar ""]]
5639 }
5640
5641 # Return 1 if the target supports executing Adv.SIMD instructions from ARMv8.2
5642 # with the FP16 extension, 0 otherwise. The test is valid for ARM and for
5643 # AArch64.
5644
5645 proc check_effective_target_arm_v8_2a_fp16_neon_hw { } {
5646 if { ![check_effective_target_arm_v8_2a_fp16_neon_ok] } {
5647 return 0;
5648 }
5649 return [check_runtime arm_v8_2a_fp16_neon_hw_available {
5650 int
5651 main (void)
5652 {
5653 #ifdef __ARM_ARCH_ISA_A64
5654
5655 __Float16x4_t a = {1.0, -1.0, 1.0, -1.0};
5656 __Float16x4_t result;
5657
5658 asm ("fabs %0.4h, %1.4h"
5659 : "=w"(result)
5660 : "w"(a)
5661 : /* No clobbers. */);
5662
5663 #else
5664
5665 __simd64_float16_t a = {1.0, -1.0, 1.0, -1.0};
5666 __simd64_float16_t result;
5667
5668 asm ("vabs.f16 %P0, %P1"
5669 : "=w"(result)
5670 : "w"(a)
5671 : /* No clobbers. */);
5672
5673 #endif
5674
5675 return (result[0] == 1.0) ? 0 : 1;
5676 }
5677 } [add_options_for_arm_v8_2a_fp16_neon ""]]
5678 }
5679
5680 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.2
5681 # with the Dot Product extension, 0 otherwise. The test is valid for ARM and for
5682 # AArch64.
5683
5684 proc check_effective_target_arm_v8_2a_dotprod_neon_hw { } {
5685 if { ![check_effective_target_arm_v8_2a_dotprod_neon_ok] } {
5686 return 0;
5687 }
5688 return [check_runtime arm_v8_2a_dotprod_neon_hw_available {
5689 #include "arm_neon.h"
5690 int
5691 main (void)
5692 {
5693
5694 uint32x2_t results = {0,0};
5695 uint8x8_t a = {1,1,1,1,2,2,2,2};
5696 uint8x8_t b = {2,2,2,2,3,3,3,3};
5697
5698 #ifdef __ARM_ARCH_ISA_A64
5699 asm ("udot %0.2s, %1.8b, %2.8b"
5700 : "=w"(results)
5701 : "w"(a), "w"(b)
5702 : /* No clobbers. */);
5703
5704 #else
5705 asm ("vudot.u8 %P0, %P1, %P2"
5706 : "=w"(results)
5707 : "w"(a), "w"(b)
5708 : /* No clobbers. */);
5709 #endif
5710
5711 return (results[0] == 8 && results[1] == 24) ? 1 : 0;
5712 }
5713 } [add_options_for_arm_v8_2a_dotprod_neon ""]]
5714 }
5715
5716 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.2
5717 # with the i8mm extension, 0 otherwise. The test is valid for ARM and for
5718 # AArch64.
5719
5720 proc check_effective_target_arm_v8_2a_i8mm_neon_hw { } {
5721 if { ![check_effective_target_arm_v8_2a_i8mm_ok] } {
5722 return 0;
5723 }
5724 return [check_runtime arm_v8_2a_i8mm_neon_hw_available {
5725 #include "arm_neon.h"
5726 int
5727 main (void)
5728 {
5729
5730 uint32x2_t results = {0,0};
5731 uint8x8_t a = {1,1,1,1,2,2,2,2};
5732 int8x8_t b = {2,2,2,2,3,3,3,3};
5733
5734 #ifdef __ARM_ARCH_ISA_A64
5735 asm ("usdot %0.2s, %1.8b, %2.8b"
5736 : "=w"(results)
5737 : "w"(a), "w"(b)
5738 : /* No clobbers. */);
5739
5740 #else
5741 asm ("vusdot.u8 %P0, %P1, %P2"
5742 : "=w"(results)
5743 : "w"(a), "w"(b)
5744 : /* No clobbers. */);
5745 #endif
5746
5747 return (vget_lane_u32 (results, 0) == 8
5748 && vget_lane_u32 (results, 1) == 24) ? 1 : 0;
5749 }
5750 } [add_options_for_arm_v8_2a_i8mm ""]]
5751 }
5752
5753 # Return 1 if this is a ARM target with NEON enabled.
5754
5755 proc check_effective_target_arm_neon { } {
5756 if { [check_effective_target_arm32] } {
5757 return [check_no_compiler_messages arm_neon object {
5758 #ifndef __ARM_NEON__
5759 #error not NEON
5760 #else
5761 int dummy;
5762 #endif
5763 }]
5764 } else {
5765 return 0
5766 }
5767 }
5768
5769 proc check_effective_target_arm_neonv2 { } {
5770 if { [check_effective_target_arm32] } {
5771 return [check_no_compiler_messages arm_neon object {
5772 #ifndef __ARM_NEON__
5773 #error not NEON
5774 #else
5775 #ifndef __ARM_FEATURE_FMA
5776 #error not NEONv2
5777 #else
5778 int dummy;
5779 #endif
5780 #endif
5781 }]
5782 } else {
5783 return 0
5784 }
5785 }
5786
5787 # Return 1 if this is an ARM target with load acquire and store release
5788 # instructions for 8-, 16- and 32-bit types.
5789
5790 proc check_effective_target_arm_acq_rel { } {
5791 return [check_no_compiler_messages arm_acq_rel object {
5792 void
5793 load_acquire_store_release (void)
5794 {
5795 asm ("lda r0, [r1]\n\t"
5796 "stl r0, [r1]\n\t"
5797 "ldah r0, [r1]\n\t"
5798 "stlh r0, [r1]\n\t"
5799 "ldab r0, [r1]\n\t"
5800 "stlb r0, [r1]"
5801 : : : "r0", "memory");
5802 }
5803 }]
5804 }
5805
5806 # Add the options needed for MIPS Paired-Single.
5807
5808 proc add_options_for_mpaired_single { flags } {
5809 if { ! [check_effective_target_mpaired_single] } {
5810 return "$flags"
5811 }
5812 return "$flags -mpaired-single"
5813 }
5814
5815 # Add the options needed for MIPS SIMD Architecture.
5816
5817 proc add_options_for_mips_msa { flags } {
5818 if { ! [check_effective_target_mips_msa] } {
5819 return "$flags"
5820 }
5821 return "$flags -mmsa"
5822 }
5823
5824 # Add the options needed for MIPS Loongson MMI Architecture.
5825
5826 proc add_options_for_mips_loongson_mmi { flags } {
5827 if { ! [check_effective_target_mips_loongson_mmi] } {
5828 return "$flags"
5829 }
5830 return "$flags -mloongson-mmi"
5831 }
5832
5833
5834 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
5835 # the Loongson vector modes.
5836
5837 proc check_effective_target_mips_loongson_mmi { } {
5838 return [check_no_compiler_messages loongson assembly {
5839 #if !defined(__mips_loongson_mmi)
5840 #error !__mips_loongson_mmi
5841 #endif
5842 #if !defined(__mips_loongson_vector_rev)
5843 #error !__mips_loongson_vector_rev
5844 #endif
5845 }]
5846 }
5847
5848 # Return 1 if this is a MIPS target that supports the legacy NAN.
5849
5850 proc check_effective_target_mips_nanlegacy { } {
5851 return [check_no_compiler_messages nanlegacy assembly {
5852 #include <stdlib.h>
5853 int main () { return 0; }
5854 } "-mnan=legacy"]
5855 }
5856
5857 # Return 1 if an MSA program can be compiled to object
5858
5859 proc check_effective_target_mips_msa { } {
5860 if ![check_effective_target_nomips16] {
5861 return 0
5862 }
5863 return [check_no_compiler_messages msa object {
5864 #if !defined(__mips_msa)
5865 #error "MSA NOT AVAIL"
5866 #else
5867 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
5868 #error "MSA NOT AVAIL FOR ISA REV < 2"
5869 #endif
5870 #if !defined(__mips_hard_float)
5871 #error "MSA HARD_FLOAT REQUIRED"
5872 #endif
5873 #if __mips_fpr != 64
5874 #error "MSA 64-bit FPR REQUIRED"
5875 #endif
5876 #include <msa.h>
5877
5878 int main()
5879 {
5880 v8i16 v = __builtin_msa_ldi_h (1);
5881
5882 return v[0];
5883 }
5884 #endif
5885 } "-mmsa" ]
5886 }
5887
5888 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
5889 # Architecture.
5890
5891 proc check_effective_target_arm_eabi { } {
5892 return [check_no_compiler_messages arm_eabi object {
5893 #ifndef __ARM_EABI__
5894 #error not EABI
5895 #else
5896 int dummy;
5897 #endif
5898 }]
5899 }
5900
5901 # Return 1 if this is an ARM target that adheres to the hard-float variant of
5902 # the ABI for the ARM Architecture (e.g. -mfloat-abi=hard).
5903
5904 proc check_effective_target_arm_hf_eabi { } {
5905 return [check_no_compiler_messages arm_hf_eabi object {
5906 #if !defined(__ARM_EABI__) || !defined(__ARM_PCS_VFP)
5907 #error not hard-float EABI
5908 #else
5909 int dummy;
5910 #endif
5911 }]
5912 }
5913
5914 # Return 1 if this is an ARM target uses emulated floating point
5915 # operations.
5916
5917 proc check_effective_target_arm_softfloat { } {
5918 return [check_no_compiler_messages arm_softfloat object {
5919 #if !defined(__SOFTFP__)
5920 #error not soft-float EABI
5921 #else
5922 int dummy;
5923 #endif
5924 }]
5925 }
5926
5927 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
5928 # Some multilibs may be incompatible with this option.
5929
5930 proc check_effective_target_arm_iwmmxt_ok { } {
5931 if { [check_effective_target_arm32] } {
5932 return [check_no_compiler_messages arm_iwmmxt_ok object {
5933 int dummy;
5934 } "-mcpu=iwmmxt"]
5935 } else {
5936 return 0
5937 }
5938 }
5939
5940 # Return true if LDRD/STRD instructions are prefered over LDM/STM instructions
5941 # for an ARM target.
5942 proc check_effective_target_arm_prefer_ldrd_strd { } {
5943 if { ![check_effective_target_arm32] } {
5944 return 0;
5945 }
5946
5947 return [check_no_messages_and_pattern arm_prefer_ldrd_strd "strd\tr" assembly {
5948 void foo (void) { __asm__ ("" ::: "r4", "r5"); }
5949 } "-O2 -mthumb" ]
5950 }
5951
5952 # Return true if LDRD/STRD instructions are available on this target.
5953 proc check_effective_target_arm_ldrd_strd_ok { } {
5954 if { ![check_effective_target_arm32] } {
5955 return 0;
5956 }
5957
5958 return [check_no_compiler_messages arm_ldrd_strd_ok object {
5959 int main(void)
5960 {
5961 __UINT64_TYPE__ a = 1, b = 10;
5962 __UINT64_TYPE__ *c = &b;
5963 // `a` will be in a valid register since it's a DImode quantity.
5964 asm ("ldrd %0, %1"
5965 : "=r" (a)
5966 : "m" (c));
5967 return a == 10;
5968 }
5969 }]
5970 }
5971
5972 # Return 1 if this is a PowerPC target supporting -meabi.
5973
5974 proc check_effective_target_powerpc_eabi_ok { } {
5975 if { [istarget powerpc*-*-*] } {
5976 return [check_no_compiler_messages powerpc_eabi_ok object {
5977 int dummy;
5978 } "-meabi"]
5979 } else {
5980 return 0
5981 }
5982 }
5983
5984 # Return 1 if this is a PowerPC target with floating-point registers.
5985
5986 proc check_effective_target_powerpc_fprs { } {
5987 if { [istarget powerpc*-*-*]
5988 || [istarget rs6000-*-*] } {
5989 return [check_no_compiler_messages powerpc_fprs object {
5990 #ifdef __NO_FPRS__
5991 #error no FPRs
5992 #else
5993 int dummy;
5994 #endif
5995 }]
5996 } else {
5997 return 0
5998 }
5999 }
6000
6001 # Return 1 if this is a PowerPC target with hardware double-precision
6002 # floating point.
6003
6004 proc check_effective_target_powerpc_hard_double { } {
6005 if { [istarget powerpc*-*-*]
6006 || [istarget rs6000-*-*] } {
6007 return [check_no_compiler_messages powerpc_hard_double object {
6008 #ifdef _SOFT_DOUBLE
6009 #error soft double
6010 #else
6011 int dummy;
6012 #endif
6013 }]
6014 } else {
6015 return 0
6016 }
6017 }
6018
6019 # Return 1 if this is a PowerPC target with hardware floating point sqrt.
6020
6021 proc check_effective_target_powerpc_sqrt { } {
6022 # We need to be PowerPC, and we need to have hardware fp enabled.
6023 if {![check_effective_target_powerpc_fprs]} {
6024 return 0;
6025 }
6026
6027 return [check_no_compiler_messages powerpc_sqrt object {
6028 #ifndef _ARCH_PPCSQ
6029 #error _ARCH_PPCSQ is not defined
6030 #endif
6031 } {}]
6032 }
6033
6034 # Return 1 if this is a PowerPC target supporting -maltivec.
6035
6036 proc check_effective_target_powerpc_altivec_ok { } {
6037 if { ([istarget powerpc*-*-*]
6038 && ![istarget powerpc-*-linux*paired*])
6039 || [istarget rs6000-*-*] } {
6040 # AltiVec is not supported on AIX before 5.3.
6041 if { [istarget powerpc*-*-aix4*]
6042 || [istarget powerpc*-*-aix5.1*]
6043 || [istarget powerpc*-*-aix5.2*] } {
6044 return 0
6045 }
6046 return [check_no_compiler_messages powerpc_altivec_ok object {
6047 int dummy;
6048 } "-maltivec"]
6049 } else {
6050 return 0
6051 }
6052 }
6053
6054 # Return 1 if this is a PowerPC target supporting -mpower8-vector
6055
6056 proc check_effective_target_powerpc_p8vector_ok { } {
6057 if { ([istarget powerpc*-*-*]
6058 && ![istarget powerpc-*-linux*paired*])
6059 || [istarget rs6000-*-*] } {
6060 # AltiVec is not supported on AIX before 5.3.
6061 if { [istarget powerpc*-*-aix4*]
6062 || [istarget powerpc*-*-aix5.1*]
6063 || [istarget powerpc*-*-aix5.2*] } {
6064 return 0
6065 }
6066 # Darwin doesn't run on power8, so far.
6067 if { [istarget *-*-darwin*] } {
6068 return 0
6069 }
6070 return [check_no_compiler_messages powerpc_p8vector_ok object {
6071 int main (void) {
6072 asm volatile ("xxlorc 0,0,0");
6073 return 0;
6074 }
6075 } "-mpower8-vector"]
6076 } else {
6077 return 0
6078 }
6079 }
6080
6081 # Return 1 if this is a PowerPC target supporting -mpower9-vector
6082
6083 proc check_effective_target_powerpc_p9vector_ok { } {
6084 if { ([istarget powerpc*-*-*]
6085 && ![istarget powerpc-*-linux*paired*])
6086 || [istarget rs6000-*-*] } {
6087 # AltiVec is not supported on AIX before 5.3.
6088 if { [istarget powerpc*-*-aix4*]
6089 || [istarget powerpc*-*-aix5.1*]
6090 || [istarget powerpc*-*-aix5.2*] } {
6091 return 0
6092 }
6093 # Darwin doesn't run on power9, so far.
6094 if { [istarget *-*-darwin*] } {
6095 return 0
6096 }
6097 return [check_no_compiler_messages powerpc_p9vector_ok object {
6098 int main (void) {
6099 long e = -1;
6100 vector double v = (vector double) { 0.0, 0.0 };
6101 asm ("xsxexpdp %0,%1" : "+r" (e) : "wa" (v));
6102 return e;
6103 }
6104 } "-mpower9-vector"]
6105 } else {
6106 return 0
6107 }
6108 }
6109
6110 # Return 1 if this is a PowerPC target supporting -mmodulo
6111
6112 proc check_effective_target_powerpc_p9modulo_ok { } {
6113 if { ([istarget powerpc*-*-*]
6114 && ![istarget powerpc-*-linux*paired*])
6115 || [istarget rs6000-*-*] } {
6116 # AltiVec is not supported on AIX before 5.3.
6117 if { [istarget powerpc*-*-aix4*]
6118 || [istarget powerpc*-*-aix5.1*]
6119 || [istarget powerpc*-*-aix5.2*] } {
6120 return 0
6121 }
6122 return [check_no_compiler_messages powerpc_p9modulo_ok object {
6123 int main (void) {
6124 int i = 5, j = 3, r = -1;
6125 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
6126 return (r == 2);
6127 }
6128 } "-mmodulo"]
6129 } else {
6130 return 0
6131 }
6132 }
6133
6134 # return 1 if our compiler returns the ARCH_PWR defines with the options
6135 # as provided by the test.
6136 proc check_effective_target_has_arch_pwr5 { } {
6137 return [check_no_compiler_messages arch_pwr5 assembly {
6138 #ifndef _ARCH_PWR5
6139 #error does not have power5 support.
6140 #else
6141 /* "has power5 support" */
6142 #endif
6143 }]
6144 }
6145
6146 proc check_effective_target_has_arch_pwr6 { } {
6147 return [check_no_compiler_messages arch_pwr6 assembly {
6148 #ifndef _ARCH_PWR6
6149 #error does not have power6 support.
6150 #else
6151 /* "has power6 support" */
6152 #endif
6153 }]
6154 }
6155
6156 proc check_effective_target_has_arch_pwr7 { } {
6157 return [check_no_compiler_messages arch_pwr7 assembly {
6158 #ifndef _ARCH_PWR7
6159 #error does not have power7 support.
6160 #else
6161 /* "has power7 support" */
6162 #endif
6163 }]
6164 }
6165
6166 proc check_effective_target_has_arch_pwr8 { } {
6167 return [check_no_compiler_messages arch_pwr8 assembly {
6168 #ifndef _ARCH_PWR8
6169 #error does not have power8 support.
6170 #else
6171 /* "has power8 support" */
6172 #endif
6173 }]
6174 }
6175
6176 proc check_effective_target_has_arch_pwr9 { } {
6177 return [check_no_compiler_messages arch_pwr9 assembly {
6178 #ifndef _ARCH_PWR9
6179 #error does not have power9 support.
6180 #else
6181 /* "has power9 support" */
6182 #endif
6183 }]
6184 }
6185
6186 proc check_effective_target_has_arch_pwr10 { } {
6187 return [check_no_compiler_messages arch_pwr10 assembly {
6188 #ifndef _ARCH_PWR10
6189 #error does not have power10 support.
6190 #else
6191 /* "has power10 support" */
6192 #endif
6193 }]
6194 }
6195
6196 # Return 1 if this is a PowerPC target supporting -mcpu=power10.
6197 # Limit this to 64-bit linux systems for now until other targets support
6198 # power10.
6199
6200 proc check_effective_target_power10_ok { } {
6201 if { ([istarget powerpc64*-*-linux*]) } {
6202 return [check_no_compiler_messages power10_ok object {
6203 int main (void) {
6204 long e;
6205 asm ("pli %0,%1" : "=r" (e) : "n" (0x12345));
6206 return e;
6207 }
6208 } "-mcpu=power10"]
6209 } else {
6210 return 0
6211 }
6212 }
6213
6214 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
6215 # software emulation on power7/power8 systems or hardware support on power9.
6216
6217 proc check_effective_target_powerpc_float128_sw_ok { } {
6218 if { ([istarget powerpc*-*-*]
6219 && ![istarget powerpc-*-linux*paired*])
6220 || [istarget rs6000-*-*] } {
6221 # AltiVec is not supported on AIX before 5.3.
6222 if { [istarget powerpc*-*-aix4*]
6223 || [istarget powerpc*-*-aix5.1*]
6224 || [istarget powerpc*-*-aix5.2*] } {
6225 return 0
6226 }
6227 # Darwin doesn't have VSX, so no soft support for float128.
6228 if { [istarget *-*-darwin*] } {
6229 return 0
6230 }
6231 return [check_no_compiler_messages powerpc_float128_sw_ok object {
6232 volatile __float128 x = 1.0q;
6233 volatile __float128 y = 2.0q;
6234 int main() {
6235 __float128 z = x + y;
6236 return (z == 3.0q);
6237 }
6238 } "-mfloat128 -mvsx"]
6239 } else {
6240 return 0
6241 }
6242 }
6243
6244 # Return 1 if this is a PowerPC target supporting -mfloat128 via hardware
6245 # support on power9.
6246
6247 proc check_effective_target_powerpc_float128_hw_ok { } {
6248 if { ([istarget powerpc*-*-*]
6249 && ![istarget powerpc-*-linux*paired*])
6250 || [istarget rs6000-*-*] } {
6251 # AltiVec is not supported on AIX before 5.3.
6252 if { [istarget powerpc*-*-aix4*]
6253 || [istarget powerpc*-*-aix5.1*]
6254 || [istarget powerpc*-*-aix5.2*] } {
6255 return 0
6256 }
6257 # Darwin doesn't run on any machine with float128 h/w so far.
6258 if { [istarget *-*-darwin*] } {
6259 return 0
6260 }
6261 return [check_no_compiler_messages powerpc_float128_hw_ok object {
6262 volatile __float128 x = 1.0q;
6263 volatile __float128 y = 2.0q;
6264 int main() {
6265 __float128 z;
6266 __asm__ ("xsaddqp %0,%1,%2" : "=v" (z) : "v" (x), "v" (y));
6267 return (z == 3.0q);
6268 }
6269 } "-mfloat128-hardware"]
6270 } else {
6271 return 0
6272 }
6273 }
6274
6275 # Return 1 if current options define float128, 0 otherwise.
6276
6277 proc check_effective_target_ppc_float128 { } {
6278 return [check_no_compiler_messages_nocache ppc_float128 object {
6279 #ifndef __FLOAT128__
6280 nope no good
6281 #endif
6282 }]
6283 }
6284
6285 # Return 1 if current options generate float128 insns, 0 otherwise.
6286
6287 proc check_effective_target_ppc_float128_insns { } {
6288 return [check_no_compiler_messages_nocache ppc_float128 object {
6289 #ifndef __FLOAT128_HARDWARE__
6290 nope no good
6291 #endif
6292 }]
6293 }
6294
6295 # Return 1 if current options generate VSX instructions, 0 otherwise.
6296
6297 proc check_effective_target_powerpc_vsx { } {
6298 return [check_no_compiler_messages_nocache powerpc_vsx object {
6299 #ifndef __VSX__
6300 nope no vsx
6301 #endif
6302 }]
6303 }
6304
6305 # Return 1 if this is a PowerPC target supporting -mvsx
6306
6307 proc check_effective_target_powerpc_vsx_ok { } {
6308 if { ([istarget powerpc*-*-*]
6309 && ![istarget powerpc-*-linux*paired*])
6310 || [istarget rs6000-*-*] } {
6311 # VSX is not supported on AIX before 7.1.
6312 if { [istarget powerpc*-*-aix4*]
6313 || [istarget powerpc*-*-aix5*]
6314 || [istarget powerpc*-*-aix6*] } {
6315 return 0
6316 }
6317 # Darwin doesn't have VSX, even if it's used with an assembler
6318 # which recognises the insns.
6319 if { [istarget *-*-darwin*] } {
6320 return 0
6321 }
6322 return [check_no_compiler_messages powerpc_vsx_ok object {
6323 int main (void) {
6324 asm volatile ("xxlor 0,0,0");
6325 return 0;
6326 }
6327 } "-mvsx"]
6328 } else {
6329 return 0
6330 }
6331 }
6332
6333 # Return 1 if this is a PowerPC target supporting -mhtm
6334
6335 proc check_effective_target_powerpc_htm_ok { } {
6336 if { ([istarget powerpc*-*-*]
6337 && ![istarget powerpc-*-linux*paired*])
6338 || [istarget rs6000-*-*] } {
6339 # HTM is not supported on AIX yet.
6340 if { [istarget powerpc*-*-aix*] } {
6341 return 0
6342 }
6343 return [check_no_compiler_messages powerpc_htm_ok object {
6344 int main (void) {
6345 asm volatile ("tbegin. 0");
6346 return 0;
6347 }
6348 } "-mhtm"]
6349 } else {
6350 return 0
6351 }
6352 }
6353
6354 # Return 1 if the target supports executing HTM hardware instructions,
6355 # 0 otherwise. Cache the result.
6356
6357 proc check_htm_hw_available { } {
6358 return [check_cached_effective_target htm_hw_available {
6359 # For now, disable on Darwin
6360 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
6361 expr 0
6362 } else {
6363 check_runtime_nocache htm_hw_available {
6364 int main()
6365 {
6366 __builtin_ttest ();
6367 return 0;
6368 }
6369 } "-mhtm"
6370 }
6371 }]
6372 }
6373 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
6374
6375 proc check_effective_target_powerpc_ppu_ok { } {
6376 if [check_effective_target_powerpc_altivec_ok] {
6377 return [check_no_compiler_messages cell_asm_available object {
6378 int main (void) {
6379 #ifdef __MACH__
6380 asm volatile ("lvlx v0,v0,v0");
6381 #else
6382 asm volatile ("lvlx 0,0,0");
6383 #endif
6384 return 0;
6385 }
6386 }]
6387 } else {
6388 return 0
6389 }
6390 }
6391
6392 # Return 1 if this is a PowerPC target that supports SPU.
6393
6394 proc check_effective_target_powerpc_spu { } {
6395 if { [istarget powerpc*-*-linux*] } {
6396 return [check_effective_target_powerpc_altivec_ok]
6397 } else {
6398 return 0
6399 }
6400 }
6401
6402 # Return 1 if this is a PowerPC SPE target. The check includes options
6403 # specified by dg-options for this test, so don't cache the result.
6404
6405 proc check_effective_target_powerpc_spe_nocache { } {
6406 if { [istarget powerpc*-*-*] } {
6407 return [check_no_compiler_messages_nocache powerpc_spe object {
6408 #ifndef __SPE__
6409 #error not SPE
6410 #else
6411 int dummy;
6412 #endif
6413 } [current_compiler_flags]]
6414 } else {
6415 return 0
6416 }
6417 }
6418
6419 # Return 1 if this is a PowerPC target with SPE enabled.
6420
6421 proc check_effective_target_powerpc_spe { } {
6422 if { [istarget powerpc*-*-*] } {
6423 return [check_no_compiler_messages powerpc_spe object {
6424 #ifndef __SPE__
6425 #error not SPE
6426 #else
6427 int dummy;
6428 #endif
6429 }]
6430 } else {
6431 return 0
6432 }
6433 }
6434
6435 # Return 1 if this is a PowerPC target with Altivec enabled.
6436
6437 proc check_effective_target_powerpc_altivec { } {
6438 if { [istarget powerpc*-*-*] } {
6439 return [check_no_compiler_messages powerpc_altivec object {
6440 #ifndef __ALTIVEC__
6441 #error not Altivec
6442 #else
6443 int dummy;
6444 #endif
6445 }]
6446 } else {
6447 return 0
6448 }
6449 }
6450
6451 # Return 1 if this is a PowerPC 405 target. The check includes options
6452 # specified by dg-options for this test, so don't cache the result.
6453
6454 proc check_effective_target_powerpc_405_nocache { } {
6455 if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
6456 return [check_no_compiler_messages_nocache powerpc_405 object {
6457 #ifdef __PPC405__
6458 int dummy;
6459 #else
6460 #error not a PPC405
6461 #endif
6462 } [current_compiler_flags]]
6463 } else {
6464 return 0
6465 }
6466 }
6467
6468 # Return 1 if this is a PowerPC target using the ELFv2 ABI.
6469
6470 proc check_effective_target_powerpc_elfv2 { } {
6471 if { [istarget powerpc*-*-*] } {
6472 return [check_no_compiler_messages powerpc_elfv2 object {
6473 #if _CALL_ELF != 2
6474 #error not ELF v2 ABI
6475 #else
6476 int dummy;
6477 #endif
6478 }]
6479 } else {
6480 return 0
6481 }
6482 }
6483
6484 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
6485 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables. Return 1 if the
6486 # test environment appears to run executables on such a simulator.
6487
6488 proc check_effective_target_ultrasparc_hw { } {
6489 return [check_runtime ultrasparc_hw {
6490 int main() { return 0; }
6491 } "-mcpu=ultrasparc"]
6492 }
6493
6494 # Return 1 if the test environment supports executing UltraSPARC VIS2
6495 # instructions. We check this by attempting: "bmask %g0, %g0, %g0"
6496
6497 proc check_effective_target_ultrasparc_vis2_hw { } {
6498 return [check_runtime ultrasparc_vis2_hw {
6499 int main() { __asm__(".word 0x81b00320"); return 0; }
6500 } "-mcpu=ultrasparc3"]
6501 }
6502
6503 # Return 1 if the test environment supports executing UltraSPARC VIS3
6504 # instructions. We check this by attempting: "addxc %g0, %g0, %g0"
6505
6506 proc check_effective_target_ultrasparc_vis3_hw { } {
6507 return [check_runtime ultrasparc_vis3_hw {
6508 int main() { __asm__(".word 0x81b00220"); return 0; }
6509 } "-mcpu=niagara3"]
6510 }
6511
6512 # Return 1 if this is a SPARC-V9 target.
6513
6514 proc check_effective_target_sparc_v9 { } {
6515 if { [istarget sparc*-*-*] } {
6516 return [check_no_compiler_messages sparc_v9 object {
6517 int main (void) {
6518 asm volatile ("return %i7+8");
6519 return 0;
6520 }
6521 }]
6522 } else {
6523 return 0
6524 }
6525 }
6526
6527 # Return 1 if this is a SPARC target with VIS enabled.
6528
6529 proc check_effective_target_sparc_vis { } {
6530 if { [istarget sparc*-*-*] } {
6531 return [check_no_compiler_messages sparc_vis object {
6532 #ifndef __VIS__
6533 #error not VIS
6534 #else
6535 int dummy;
6536 #endif
6537 }]
6538 } else {
6539 return 0
6540 }
6541 }
6542
6543 # Return 1 if the target supports hardware vector shift operation.
6544
6545 proc check_effective_target_vect_shift { } {
6546 return [check_cached_effective_target_indexed vect_shift {
6547 expr {([istarget powerpc*-*-*]
6548 && ![istarget powerpc-*-linux*paired*])
6549 || [istarget ia64-*-*]
6550 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6551 || [istarget aarch64*-*-*]
6552 || [is-effective-target arm_neon]
6553 || ([istarget mips*-*-*]
6554 && ([et-is-effective-target mips_msa]
6555 || [et-is-effective-target mips_loongson_mmi]))
6556 || ([istarget s390*-*-*]
6557 && [check_effective_target_s390_vx])
6558 || [istarget amdgcn-*-*] }}]
6559 }
6560
6561 # Return 1 if the target supports hardware vector shift by register operation.
6562
6563 proc check_effective_target_vect_var_shift { } {
6564 return [check_cached_effective_target_indexed vect_var_shift {
6565 expr {(([istarget i?86-*-*] || [istarget x86_64-*-*])
6566 && [check_avx2_available])
6567 }}]
6568 }
6569
6570 proc check_effective_target_whole_vector_shift { } {
6571 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6572 || [istarget ia64-*-*]
6573 || [istarget aarch64*-*-*]
6574 || [istarget powerpc64*-*-*]
6575 || ([is-effective-target arm_neon]
6576 && [check_effective_target_arm_little_endian])
6577 || ([istarget mips*-*-*]
6578 && [et-is-effective-target mips_loongson_mmi])
6579 || ([istarget s390*-*-*]
6580 && [check_effective_target_s390_vx])
6581 || [istarget amdgcn-*-*] } {
6582 set answer 1
6583 } else {
6584 set answer 0
6585 }
6586
6587 verbose "check_effective_target_vect_long: returning $answer" 2
6588 return $answer
6589 }
6590
6591 # Return 1 if the target supports vector bswap operations.
6592
6593 proc check_effective_target_vect_bswap { } {
6594 return [check_cached_effective_target_indexed vect_bswap {
6595 expr { [istarget aarch64*-*-*]
6596 || [is-effective-target arm_neon]
6597 || [istarget amdgcn-*-*] }}]
6598 }
6599
6600 # Return 1 if the target supports comparison of bool vectors for at
6601 # least one vector length.
6602
6603 proc check_effective_target_vect_bool_cmp { } {
6604 return [check_cached_effective_target_indexed vect_bool_cmp {
6605 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6606 || [istarget aarch64*-*-*]
6607 || [is-effective-target arm_neon] }}]
6608 }
6609
6610 # Return 1 if the target supports addition of char vectors for at least
6611 # one vector length.
6612
6613 proc check_effective_target_vect_char_add { } {
6614 return [check_cached_effective_target_indexed vect_char_add {
6615 expr {
6616 [istarget i?86-*-*] || [istarget x86_64-*-*]
6617 || ([istarget powerpc*-*-*]
6618 && ![istarget powerpc-*-linux*paired*])
6619 || [istarget amdgcn-*-*]
6620 || [istarget ia64-*-*]
6621 || [istarget aarch64*-*-*]
6622 || [is-effective-target arm_neon]
6623 || ([istarget mips*-*-*]
6624 && ([et-is-effective-target mips_loongson_mmi]
6625 || [et-is-effective-target mips_msa]))
6626 || ([istarget s390*-*-*]
6627 && [check_effective_target_s390_vx])
6628 }}]
6629 }
6630
6631 # Return 1 if the target supports hardware vector shift operation for char.
6632
6633 proc check_effective_target_vect_shift_char { } {
6634 return [check_cached_effective_target_indexed vect_shift_char {
6635 expr { ([istarget powerpc*-*-*]
6636 && ![istarget powerpc-*-linux*paired*])
6637 || [is-effective-target arm_neon]
6638 || ([istarget mips*-*-*]
6639 && [et-is-effective-target mips_msa])
6640 || ([istarget s390*-*-*]
6641 && [check_effective_target_s390_vx])
6642 || [istarget amdgcn-*-*] }}]
6643 }
6644
6645 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
6646 #
6647 # This can change for different subtargets so do not cache the result.
6648
6649 proc check_effective_target_vect_long { } {
6650 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6651 || (([istarget powerpc*-*-*]
6652 && ![istarget powerpc-*-linux*paired*])
6653 && [check_effective_target_ilp32])
6654 || [is-effective-target arm_neon]
6655 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
6656 || [istarget aarch64*-*-*]
6657 || ([istarget mips*-*-*]
6658 && [et-is-effective-target mips_msa])
6659 || ([istarget s390*-*-*]
6660 && [check_effective_target_s390_vx])
6661 || [istarget amdgcn-*-*] } {
6662 set answer 1
6663 } else {
6664 set answer 0
6665 }
6666
6667 verbose "check_effective_target_vect_long: returning $answer" 2
6668 return $answer
6669 }
6670
6671 # Return 1 if the target supports hardware vectors of float when
6672 # -funsafe-math-optimizations is enabled, 0 otherwise.
6673 #
6674 # This won't change for different subtargets so cache the result.
6675
6676 proc check_effective_target_vect_float { } {
6677 return [check_cached_effective_target_indexed vect_float {
6678 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6679 || [istarget powerpc*-*-*]
6680 || [istarget mips-sde-elf]
6681 || [istarget mipsisa64*-*-*]
6682 || [istarget ia64-*-*]
6683 || [istarget aarch64*-*-*]
6684 || ([istarget mips*-*-*]
6685 && [et-is-effective-target mips_msa])
6686 || [is-effective-target arm_neon]
6687 || ([istarget s390*-*-*]
6688 && [check_effective_target_s390_vxe])
6689 || [istarget amdgcn-*-*] }}]
6690 }
6691
6692 # Return 1 if the target supports hardware vectors of float without
6693 # -funsafe-math-optimizations being enabled, 0 otherwise.
6694
6695 proc check_effective_target_vect_float_strict { } {
6696 return [expr { [check_effective_target_vect_float]
6697 && ![istarget arm*-*-*] }]
6698 }
6699
6700 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
6701 #
6702 # This won't change for different subtargets so cache the result.
6703
6704 proc check_effective_target_vect_double { } {
6705 return [check_cached_effective_target_indexed vect_double {
6706 expr { (([istarget i?86-*-*] || [istarget x86_64-*-*])
6707 && [check_no_compiler_messages vect_double assembly {
6708 #ifdef __tune_atom__
6709 # error No double vectorizer support.
6710 #endif
6711 }])
6712 || [istarget aarch64*-*-*]
6713 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
6714 || ([istarget mips*-*-*]
6715 && [et-is-effective-target mips_msa])
6716 || ([istarget s390*-*-*]
6717 && [check_effective_target_s390_vx])
6718 || [istarget amdgcn-*-*]} }]
6719 }
6720
6721 # Return 1 if the target supports conditional addition, subtraction,
6722 # multiplication, division, minimum and maximum on vectors of double,
6723 # via the cond_ optabs. Return 0 otherwise.
6724
6725 proc check_effective_target_vect_double_cond_arith { } {
6726 return [check_effective_target_aarch64_sve]
6727 }
6728
6729 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
6730 #
6731 # This won't change for different subtargets so cache the result.
6732
6733 proc check_effective_target_vect_long_long { } {
6734 return [check_cached_effective_target_indexed vect_long_long {
6735 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6736 || ([istarget mips*-*-*]
6737 && [et-is-effective-target mips_msa])
6738 || ([istarget s390*-*-*]
6739 && [check_effective_target_s390_vx]) }}]
6740 }
6741
6742
6743 # Return 1 if the target plus current options does not support a vector
6744 # max instruction on "int", 0 otherwise.
6745 #
6746 # This won't change for different subtargets so cache the result.
6747
6748 proc check_effective_target_vect_no_int_min_max { } {
6749 return [check_cached_effective_target_indexed vect_no_int_min_max {
6750 expr { [istarget sparc*-*-*]
6751 || [istarget alpha*-*-*]
6752 || ([istarget mips*-*-*]
6753 && [et-is-effective-target mips_loongson_mmi]) }}]
6754 }
6755
6756 # Return 1 if the target plus current options does not support a vector
6757 # add instruction on "int", 0 otherwise.
6758 #
6759 # This won't change for different subtargets so cache the result.
6760
6761 proc check_effective_target_vect_no_int_add { } {
6762 # Alpha only supports vector add on V8QI and V4HI.
6763 return [check_cached_effective_target_indexed vect_no_int_add {
6764 expr { [istarget alpha*-*-*] }}]
6765 }
6766
6767 # Return 1 if the target plus current options does not support vector
6768 # bitwise instructions, 0 otherwise.
6769 #
6770 # This won't change for different subtargets so cache the result.
6771
6772 proc check_effective_target_vect_no_bitwise { } {
6773 return [check_cached_effective_target_indexed vect_no_bitwise { return 0 }]
6774 }
6775
6776 # Return 1 if the target plus current options supports vector permutation,
6777 # 0 otherwise.
6778 #
6779 # This won't change for different subtargets so cache the result.
6780
6781 proc check_effective_target_vect_perm { } {
6782 return [check_cached_effective_target_indexed vect_perm {
6783 expr { [is-effective-target arm_neon]
6784 || [istarget aarch64*-*-*]
6785 || [istarget powerpc*-*-*]
6786 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6787 || ([istarget mips*-*-*]
6788 && ([et-is-effective-target mpaired_single]
6789 || [et-is-effective-target mips_msa]))
6790 || ([istarget s390*-*-*]
6791 && [check_effective_target_s390_vx])
6792 || [istarget amdgcn-*-*] }}]
6793 }
6794
6795 # Return 1 if, for some VF:
6796 #
6797 # - the target's default vector size is VF * ELEMENT_BITS bits
6798 #
6799 # - it is possible to implement the equivalent of:
6800 #
6801 # int<ELEMENT_BITS>_t s1[COUNT][COUNT * VF], s2[COUNT * VF];
6802 # for (int i = 0; i < COUNT; ++i)
6803 # for (int j = 0; j < COUNT * VF; ++j)
6804 # s1[i][j] = s2[j - j % COUNT + i]
6805 #
6806 # using only a single 2-vector permute for each vector in s1.
6807 #
6808 # E.g. for COUNT == 3 and vector length 4, the two arrays would be:
6809 #
6810 # s2 | a0 a1 a2 a3 | b0 b1 b2 b3 | c0 c1 c2 c3
6811 # ------+-------------+-------------+------------
6812 # s1[0] | a0 a0 a0 a3 | a3 a3 b2 b2 | b2 c1 c1 c1
6813 # s1[1] | a1 a1 a1 b0 | b0 b0 b3 b3 | b3 c2 c2 c2
6814 # s1[2] | a2 a2 a2 b1 | b1 b1 c0 c0 | c0 c3 c3 c3
6815 #
6816 # Each s1 permute requires only two of a, b and c.
6817 #
6818 # The distance between the start of vector n in s1[0] and the start
6819 # of vector n in s2 is:
6820 #
6821 # A = (n * VF) % COUNT
6822 #
6823 # The corresponding value for the end of vector n is:
6824 #
6825 # B = (n * VF + VF - 1) % COUNT
6826 #
6827 # Subtracting i from each value gives the corresponding difference
6828 # for s1[i]. The condition being tested by this function is false
6829 # iff A - i > 0 and B - i < 0 for some i and n, such that the first
6830 # element for s1[i] comes from vector n - 1 of s2 and the last element
6831 # comes from vector n + 1 of s2. The condition is therefore true iff
6832 # A <= B for all n. This is turn means the condition is true iff:
6833 #
6834 # (n * VF) % COUNT + (VF - 1) % COUNT < COUNT
6835 #
6836 # for all n. COUNT - (n * VF) % COUNT is bounded by gcd (VF, COUNT),
6837 # and will be that value for at least one n in [0, COUNT), so we want:
6838 #
6839 # (VF - 1) % COUNT < gcd (VF, COUNT)
6840
6841 proc vect_perm_supported { count element_bits } {
6842 set vector_bits [lindex [available_vector_sizes] 0]
6843 # The number of vectors has to be a power of 2 when permuting
6844 # variable-length vectors.
6845 if { $vector_bits <= 0 && ($count & -$count) != $count } {
6846 return 0
6847 }
6848 set vf [expr { $vector_bits / $element_bits }]
6849
6850 # Compute gcd (VF, COUNT).
6851 set gcd $vf
6852 set temp1 $count
6853 while { $temp1 > 0 } {
6854 set temp2 [expr { $gcd % $temp1 }]
6855 set gcd $temp1
6856 set temp1 $temp2
6857 }
6858 return [expr { ($vf - 1) % $count < $gcd }]
6859 }
6860
6861 # Return 1 if the target supports SLP permutation of 3 vectors when each
6862 # element has 32 bits.
6863
6864 proc check_effective_target_vect_perm3_int { } {
6865 return [expr { [check_effective_target_vect_perm]
6866 && [vect_perm_supported 3 32] }]
6867 }
6868
6869 # Return 1 if the target plus current options supports vector permutation
6870 # on byte-sized elements, 0 otherwise.
6871 #
6872 # This won't change for different subtargets so cache the result.
6873
6874 proc check_effective_target_vect_perm_byte { } {
6875 return [check_cached_effective_target_indexed vect_perm_byte {
6876 expr { ([is-effective-target arm_neon]
6877 && [is-effective-target arm_little_endian])
6878 || ([istarget aarch64*-*-*]
6879 && [is-effective-target aarch64_little_endian])
6880 || [istarget powerpc*-*-*]
6881 || ([istarget mips-*.*]
6882 && [et-is-effective-target mips_msa])
6883 || ([istarget s390*-*-*]
6884 && [check_effective_target_s390_vx])
6885 || [istarget amdgcn-*-*] }}]
6886 }
6887
6888 # Return 1 if the target supports SLP permutation of 3 vectors when each
6889 # element has 8 bits.
6890
6891 proc check_effective_target_vect_perm3_byte { } {
6892 return [expr { [check_effective_target_vect_perm_byte]
6893 && [vect_perm_supported 3 8] }]
6894 }
6895
6896 # Return 1 if the target plus current options supports vector permutation
6897 # on short-sized elements, 0 otherwise.
6898 #
6899 # This won't change for different subtargets so cache the result.
6900
6901 proc check_effective_target_vect_perm_short { } {
6902 return [check_cached_effective_target_indexed vect_perm_short {
6903 expr { ([is-effective-target arm_neon]
6904 && [is-effective-target arm_little_endian])
6905 || ([istarget aarch64*-*-*]
6906 && [is-effective-target aarch64_little_endian])
6907 || [istarget powerpc*-*-*]
6908 || (([istarget i?86-*-*] || [istarget x86_64-*-*])
6909 && [check_ssse3_available])
6910 || ([istarget mips*-*-*]
6911 && [et-is-effective-target mips_msa])
6912 || ([istarget s390*-*-*]
6913 && [check_effective_target_s390_vx])
6914 || [istarget amdgcn-*-*] }}]
6915 }
6916
6917 # Return 1 if the target supports SLP permutation of 3 vectors when each
6918 # element has 16 bits.
6919
6920 proc check_effective_target_vect_perm3_short { } {
6921 return [expr { [check_effective_target_vect_perm_short]
6922 && [vect_perm_supported 3 16] }]
6923 }
6924
6925 # Return 1 if the target plus current options supports folding of
6926 # copysign into XORSIGN.
6927 #
6928 # This won't change for different subtargets so cache the result.
6929
6930 proc check_effective_target_xorsign { } {
6931 return [check_cached_effective_target_indexed xorsign {
6932 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6933 || [istarget aarch64*-*-*] || [istarget arm*-*-*] }}]
6934 }
6935
6936 # Return 1 if the target plus current options supports a vector
6937 # widening summation of *short* args into *int* result, 0 otherwise.
6938 #
6939 # This won't change for different subtargets so cache the result.
6940
6941 proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
6942 return [check_cached_effective_target_indexed vect_widen_sum_hi_to_si_pattern {
6943 expr { [istarget powerpc*-*-*]
6944 || ([istarget aarch64*-*-*]
6945 && ![check_effective_target_aarch64_sve])
6946 || [is-effective-target arm_neon]
6947 || [istarget ia64-*-*] }}]
6948 }
6949
6950 # Return 1 if the target plus current options supports a vector
6951 # widening summation of *short* args into *int* result, 0 otherwise.
6952 # A target can also support this widening summation if it can support
6953 # promotion (unpacking) from shorts to ints.
6954 #
6955 # This won't change for different subtargets so cache the result.
6956
6957 proc check_effective_target_vect_widen_sum_hi_to_si { } {
6958 return [check_cached_effective_target_indexed vect_widen_sum_hi_to_si {
6959 expr { [check_effective_target_vect_unpack]
6960 || [istarget powerpc*-*-*]
6961 || [istarget ia64-*-*] }}]
6962 }
6963
6964 # Return 1 if the target plus current options supports a vector
6965 # widening summation of *char* args into *short* result, 0 otherwise.
6966 # A target can also support this widening summation if it can support
6967 # promotion (unpacking) from chars to shorts.
6968 #
6969 # This won't change for different subtargets so cache the result.
6970
6971 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
6972 return [check_cached_effective_target_indexed vect_widen_sum_qi_to_hi {
6973 expr { [check_effective_target_vect_unpack]
6974 || [is-effective-target arm_neon]
6975 || [istarget ia64-*-*] }}]
6976 }
6977
6978 # Return 1 if the target plus current options supports a vector
6979 # widening summation of *char* args into *int* result, 0 otherwise.
6980 #
6981 # This won't change for different subtargets so cache the result.
6982
6983 proc check_effective_target_vect_widen_sum_qi_to_si { } {
6984 return [check_cached_effective_target_indexed vect_widen_sum_qi_to_si {
6985 expr { [istarget powerpc*-*-*] }}]
6986 }
6987
6988 # Return 1 if the target plus current options supports a vector
6989 # widening multiplication of *char* args into *short* result, 0 otherwise.
6990 # A target can also support this widening multplication if it can support
6991 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
6992 # multiplication of shorts).
6993 #
6994 # This won't change for different subtargets so cache the result.
6995
6996
6997 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
6998 return [check_cached_effective_target_indexed vect_widen_mult_qi_to_hi {
6999 expr { ([check_effective_target_vect_unpack]
7000 && [check_effective_target_vect_short_mult])
7001 || ([istarget powerpc*-*-*]
7002 || ([istarget aarch64*-*-*]
7003 && ![check_effective_target_aarch64_sve])
7004 || [is-effective-target arm_neon]
7005 || ([istarget s390*-*-*]
7006 && [check_effective_target_s390_vx]))
7007 || [istarget amdgcn-*-*] }}]
7008 }
7009
7010 # Return 1 if the target plus current options supports a vector
7011 # widening multiplication of *short* args into *int* result, 0 otherwise.
7012 # A target can also support this widening multplication if it can support
7013 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
7014 # multiplication of ints).
7015 #
7016 # This won't change for different subtargets so cache the result.
7017
7018
7019 proc check_effective_target_vect_widen_mult_hi_to_si { } {
7020 return [check_cached_effective_target_indexed vect_widen_mult_hi_to_si {
7021 expr { ([check_effective_target_vect_unpack]
7022 && [check_effective_target_vect_int_mult])
7023 || ([istarget powerpc*-*-*]
7024 || [istarget ia64-*-*]
7025 || ([istarget aarch64*-*-*]
7026 && ![check_effective_target_aarch64_sve])
7027 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7028 || [is-effective-target arm_neon]
7029 || ([istarget s390*-*-*]
7030 && [check_effective_target_s390_vx]))
7031 || [istarget amdgcn-*-*] }}]
7032 }
7033
7034 # Return 1 if the target plus current options supports a vector
7035 # widening multiplication of *char* args into *short* result, 0 otherwise.
7036 #
7037 # This won't change for different subtargets so cache the result.
7038
7039 proc check_effective_target_vect_widen_mult_qi_to_hi_pattern { } {
7040 return [check_cached_effective_target_indexed vect_widen_mult_qi_to_hi_pattern {
7041 expr { [istarget powerpc*-*-*]
7042 || ([is-effective-target arm_neon]
7043 && [check_effective_target_arm_little_endian])
7044 || ([istarget s390*-*-*]
7045 && [check_effective_target_s390_vx])
7046 || [istarget amdgcn-*-*] }}]
7047 }
7048
7049 # Return 1 if the target plus current options supports a vector
7050 # widening multiplication of *short* args into *int* result, 0 otherwise.
7051 #
7052 # This won't change for different subtargets so cache the result.
7053
7054 proc check_effective_target_vect_widen_mult_hi_to_si_pattern { } {
7055 return [check_cached_effective_target_indexed vect_widen_mult_hi_to_si_pattern {
7056 expr { [istarget powerpc*-*-*]
7057 || [istarget ia64-*-*]
7058 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7059 || ([is-effective-target arm_neon]
7060 && [check_effective_target_arm_little_endian])
7061 || ([istarget s390*-*-*]
7062 && [check_effective_target_s390_vx])
7063 || [istarget amdgcn-*-*] }}]
7064 }
7065
7066 # Return 1 if the target plus current options supports a vector
7067 # widening multiplication of *int* args into *long* result, 0 otherwise.
7068 #
7069 # This won't change for different subtargets so cache the result.
7070
7071 proc check_effective_target_vect_widen_mult_si_to_di_pattern { } {
7072 return [check_cached_effective_target_indexed vect_widen_mult_si_to_di_pattern {
7073 expr { [istarget ia64-*-*]
7074 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7075 || ([istarget s390*-*-*]
7076 && [check_effective_target_s390_vx]) }}]
7077 }
7078
7079 # Return 1 if the target plus current options supports a vector
7080 # widening shift, 0 otherwise.
7081 #
7082 # This won't change for different subtargets so cache the result.
7083
7084 proc check_effective_target_vect_widen_shift { } {
7085 return [check_cached_effective_target_indexed vect_widen_shift {
7086 expr { [is-effective-target arm_neon] }}]
7087 }
7088
7089 # Return 1 if the target plus current options supports a vector
7090 # dot-product of signed chars, 0 otherwise.
7091 #
7092 # This won't change for different subtargets so cache the result.
7093
7094 proc check_effective_target_vect_sdot_qi { } {
7095 return [check_cached_effective_target_indexed vect_sdot_qi {
7096 expr { [istarget ia64-*-*]
7097 || [istarget aarch64*-*-*]
7098 || [istarget arm*-*-*]
7099 || ([istarget mips*-*-*]
7100 && [et-is-effective-target mips_msa]) }}]
7101 }
7102
7103 # Return 1 if the target plus current options supports a vector
7104 # dot-product of unsigned chars, 0 otherwise.
7105 #
7106 # This won't change for different subtargets so cache the result.
7107
7108 proc check_effective_target_vect_udot_qi { } {
7109 return [check_cached_effective_target_indexed vect_udot_qi {
7110 expr { [istarget powerpc*-*-*]
7111 || [istarget aarch64*-*-*]
7112 || [istarget arm*-*-*]
7113 || [istarget ia64-*-*]
7114 || ([istarget mips*-*-*]
7115 && [et-is-effective-target mips_msa]) }}]
7116 }
7117
7118 # Return 1 if the target plus current options supports a vector
7119 # dot-product where one operand of the multiply is signed char
7120 # and the other unsigned chars, 0 otherwise.
7121 #
7122 # This won't change for different subtargets so cache the result.
7123
7124 proc check_effective_target_vect_usdot_qi { } {
7125 return [check_cached_effective_target_indexed vect_usdot_qi {
7126 expr { [istarget aarch64*-*-*]
7127 || [istarget arm*-*-*] }}]
7128 }
7129
7130
7131 # Return 1 if the target plus current options supports a vector
7132 # dot-product of signed shorts, 0 otherwise.
7133 #
7134 # This won't change for different subtargets so cache the result.
7135
7136 proc check_effective_target_vect_sdot_hi { } {
7137 return [check_cached_effective_target_indexed vect_sdot_hi {
7138 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
7139 || [istarget ia64-*-*]
7140 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7141 || ([istarget mips*-*-*]
7142 && [et-is-effective-target mips_msa]) }}]
7143 }
7144
7145 # Return 1 if the target plus current options supports a vector
7146 # dot-product of unsigned shorts, 0 otherwise.
7147 #
7148 # This won't change for different subtargets so cache the result.
7149
7150 proc check_effective_target_vect_udot_hi { } {
7151 return [check_cached_effective_target_indexed vect_udot_hi {
7152 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
7153 || ([istarget mips*-*-*]
7154 && [et-is-effective-target mips_msa]) }}]
7155 }
7156
7157 # Return 1 if the target plus current options supports a vector
7158 # sad operation of unsigned chars, 0 otherwise.
7159 #
7160 # This won't change for different subtargets so cache the result.
7161
7162 proc check_effective_target_vect_usad_char { } {
7163 return [check_cached_effective_target_indexed vect_usad_char {
7164 expr { [istarget i?86-*-*]
7165 || [istarget x86_64-*-*]
7166 || ([istarget aarch64*-*-*]
7167 && ![check_effective_target_aarch64_sve])
7168 || ([istarget powerpc*-*-*]
7169 && [check_p9vector_hw_available])}}]
7170 }
7171
7172 # Return 1 if the target plus current options supports both signed
7173 # and unsigned average operations on vectors of bytes.
7174
7175 proc check_effective_target_vect_avg_qi {} {
7176 return [expr { [istarget aarch64*-*-*]
7177 && ![check_effective_target_aarch64_sve1_only] }]
7178 }
7179
7180 # Return 1 if the target plus current options supports both signed
7181 # and unsigned multiply-high-with-round-and-scale operations
7182 # on vectors of half-words.
7183
7184 proc check_effective_target_vect_mulhrs_hi {} {
7185 return [expr { [istarget aarch64*-*-*]
7186 && [check_effective_target_aarch64_sve2] }]
7187 }
7188
7189 # Return 1 if the target plus current options supports signed division
7190 # by power-of-2 operations on vectors of 4-byte integers.
7191
7192 proc check_effective_target_vect_sdiv_pow2_si {} {
7193 return [expr { [istarget aarch64*-*-*]
7194 && [check_effective_target_aarch64_sve] }]
7195 }
7196
7197 # Return 1 if the target plus current options supports a vector
7198 # demotion (packing) of shorts (to chars) and ints (to shorts)
7199 # using modulo arithmetic, 0 otherwise.
7200 #
7201 # This won't change for different subtargets so cache the result.
7202
7203 proc check_effective_target_vect_pack_trunc { } {
7204 return [check_cached_effective_target_indexed vect_pack_trunc {
7205 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
7206 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7207 || [istarget aarch64*-*-*]
7208 || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok]
7209 && [check_effective_target_arm_little_endian])
7210 || ([istarget mips*-*-*]
7211 && [et-is-effective-target mips_msa])
7212 || ([istarget s390*-*-*]
7213 && [check_effective_target_s390_vx])
7214 || [istarget amdgcn*-*-*] }}]
7215 }
7216
7217 # Return 1 if the target plus current options supports a vector
7218 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
7219 #
7220 # This won't change for different subtargets so cache the result.
7221
7222 proc check_effective_target_vect_unpack { } {
7223 return [check_cached_effective_target_indexed vect_unpack {
7224 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
7225 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7226 || [istarget ia64-*-*]
7227 || [istarget aarch64*-*-*]
7228 || ([istarget mips*-*-*]
7229 && [et-is-effective-target mips_msa])
7230 || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok]
7231 && [check_effective_target_arm_little_endian])
7232 || ([istarget s390*-*-*]
7233 && [check_effective_target_s390_vx])
7234 || [istarget amdgcn*-*-*] }}]
7235 }
7236
7237 # Return 1 if the target plus current options does not guarantee
7238 # that its STACK_BOUNDARY is >= the reguired vector alignment.
7239 #
7240 # This won't change for different subtargets so cache the result.
7241
7242 proc check_effective_target_unaligned_stack { } {
7243 return [check_cached_effective_target_indexed unaligned_stack { expr 0 }]
7244 }
7245
7246 # Return 1 if the target plus current options does not support a vector
7247 # alignment mechanism, 0 otherwise.
7248 #
7249 # This won't change for different subtargets so cache the result.
7250
7251 proc check_effective_target_vect_no_align { } {
7252 return [check_cached_effective_target_indexed vect_no_align {
7253 expr { [istarget mipsisa64*-*-*]
7254 || [istarget mips-sde-elf]
7255 || [istarget sparc*-*-*]
7256 || [istarget ia64-*-*]
7257 || [check_effective_target_arm_vect_no_misalign]
7258 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
7259 || ([istarget mips*-*-*]
7260 && [et-is-effective-target mips_loongson_mmi]) }}]
7261 }
7262
7263 # Return 1 if the target supports a vector misalign access, 0 otherwise.
7264 #
7265 # This won't change for different subtargets so cache the result.
7266
7267 proc check_effective_target_vect_hw_misalign { } {
7268 return [check_cached_effective_target_indexed vect_hw_misalign {
7269 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
7270 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
7271 || [istarget aarch64*-*-*]
7272 || ([istarget mips*-*-*] && [et-is-effective-target mips_msa])
7273 || ([istarget s390*-*-*]
7274 && [check_effective_target_s390_vx]) } {
7275 return 1
7276 }
7277 if { [istarget arm*-*-*]
7278 && ![check_effective_target_arm_vect_no_misalign] } {
7279 return 1
7280 }
7281 return 0
7282 }]
7283 }
7284
7285
7286 # Return 1 if arrays are aligned to the vector alignment
7287 # boundary, 0 otherwise.
7288
7289 proc check_effective_target_vect_aligned_arrays { } {
7290 set et_vect_aligned_arrays 0
7291 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
7292 && !([is-effective-target ia32]
7293 || ([check_avx_available] && ![check_prefer_avx128]))) } {
7294 set et_vect_aligned_arrays 1
7295 }
7296
7297 verbose "check_effective_target_vect_aligned_arrays:\
7298 returning $et_vect_aligned_arrays" 2
7299 return $et_vect_aligned_arrays
7300 }
7301
7302 # Return 1 if types of size 32 bit or less are naturally aligned
7303 # (aligned to their type-size), 0 otherwise.
7304 #
7305 # This won't change for different subtargets so cache the result.
7306
7307 proc check_effective_target_natural_alignment_32 { } {
7308 # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
7309 # FIXME: m68k has -malign-int
7310 return [check_cached_effective_target_indexed natural_alignment_32 {
7311 if { ([istarget *-*-darwin*] && [is-effective-target lp64])
7312 || [istarget avr-*-*]
7313 || [istarget m68k-*-linux*]
7314 || [istarget pru-*-*]
7315 || [istarget stormy16-*-*]
7316 || [istarget rl78-*-*]
7317 || [istarget pdp11-*-*]
7318 || [istarget msp430-*-*]
7319 || [istarget m32c-*-*]
7320 || [istarget cris-*-*] } {
7321 return 0
7322 } else {
7323 return 1
7324 }
7325 }]
7326 }
7327
7328 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
7329 # type-size), 0 otherwise.
7330 #
7331 # This won't change for different subtargets so cache the result.
7332
7333 proc check_effective_target_natural_alignment_64 { } {
7334 return [check_cached_effective_target_indexed natural_alignment_64 {
7335 expr { [is-effective-target natural_alignment_32]
7336 && [is-effective-target lp64] && ![istarget *-*-darwin*] }
7337 }]
7338 }
7339
7340 # Return 1 if all vector types are naturally aligned (aligned to their
7341 # type-size), 0 otherwise.
7342
7343 proc check_effective_target_vect_natural_alignment { } {
7344 set et_vect_natural_alignment 1
7345 if { [check_effective_target_arm_eabi]
7346 || [istarget nvptx-*-*]
7347 || [istarget s390*-*-*]
7348 || [istarget amdgcn-*-*] } {
7349 set et_vect_natural_alignment 0
7350 }
7351 verbose "check_effective_target_vect_natural_alignment:\
7352 returning $et_vect_natural_alignment" 2
7353 return $et_vect_natural_alignment
7354 }
7355
7356 # Return true if the target supports the check_raw_ptrs and check_war_ptrs
7357 # optabs on vectors.
7358
7359 proc check_effective_target_vect_check_ptrs { } {
7360 return [check_effective_target_aarch64_sve2]
7361 }
7362
7363 # Return true if fully-masked loops are supported.
7364
7365 proc check_effective_target_vect_fully_masked { } {
7366 return [expr { [check_effective_target_aarch64_sve]
7367 || [istarget amdgcn*-*-*] }]
7368 }
7369
7370 # Return true if the target supports the @code{len_load} and
7371 # @code{len_store} optabs.
7372
7373 proc check_effective_target_vect_len_load_store { } {
7374 return [check_effective_target_has_arch_pwr9]
7375 }
7376
7377 # Return the value of parameter vect-partial-vector-usage specified for
7378 # target by checking the output of "-Q --help=params". Return zero if
7379 # the desirable pattern isn't found.
7380
7381 proc check_vect_partial_vector_usage { } {
7382 global tool
7383
7384 return [check_cached_effective_target vect_partial_vector_usage {
7385 set result [check_compile vect_partial_vector_usage assembly {
7386 int i;
7387 } "-Q --help=params" ]
7388
7389 # Get compiler emitted messages and delete generated file.
7390 set lines [lindex $result 0]
7391 set output [lindex $result 1]
7392 remote_file build delete $output
7393
7394 set pattern {=vect-partial-vector-usage=<0,2>\s+([0-2])}
7395 # Capture the usage value to val, set it to zero if not found.
7396 if { ![regexp $pattern $lines whole val] } then {
7397 set val 0
7398 }
7399
7400 return $val
7401 }]
7402 }
7403
7404 # Return true if the target supports loop vectorization with partial vectors
7405 # and @code{vect-partial-vector-usage} is set to 1.
7406
7407 proc check_effective_target_vect_partial_vectors_usage_1 { } {
7408 return [expr { ([check_effective_target_vect_fully_masked]
7409 || [check_effective_target_vect_len_load_store])
7410 && [check_vect_partial_vector_usage] == 1 }]
7411 }
7412
7413 # Return true if the target supports loop vectorization with partial vectors
7414 # and @code{vect-partial-vector-usage} is set to 2.
7415
7416 proc check_effective_target_vect_partial_vectors_usage_2 { } {
7417 return [expr { ([check_effective_target_vect_fully_masked]
7418 || [check_effective_target_vect_len_load_store])
7419 && [check_vect_partial_vector_usage] == 2 }]
7420 }
7421
7422 # Return true if the target supports loop vectorization with partial vectors
7423 # and @code{vect-partial-vector-usage} is nonzero.
7424
7425 proc check_effective_target_vect_partial_vectors { } {
7426 return [expr { ([check_effective_target_vect_fully_masked]
7427 || [check_effective_target_vect_len_load_store])
7428 && [check_vect_partial_vector_usage] != 0 }]
7429 }
7430
7431 # Return 1 if the target doesn't prefer any alignment beyond element
7432 # alignment during vectorization.
7433
7434 proc check_effective_target_vect_element_align_preferred { } {
7435 return [expr { [check_effective_target_aarch64_sve]
7436 && [check_effective_target_vect_variable_length] }]
7437 }
7438
7439 # Return 1 if we can align stack data to the preferred vector alignment.
7440
7441 proc check_effective_target_vect_align_stack_vars { } {
7442 if { [check_effective_target_aarch64_sve] } {
7443 return [check_effective_target_vect_variable_length]
7444 }
7445 return 1
7446 }
7447
7448 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
7449
7450 proc check_effective_target_vector_alignment_reachable { } {
7451 set et_vector_alignment_reachable 0
7452 if { [check_effective_target_vect_aligned_arrays]
7453 || [check_effective_target_natural_alignment_32] } {
7454 set et_vector_alignment_reachable 1
7455 }
7456 verbose "check_effective_target_vector_alignment_reachable:\
7457 returning $et_vector_alignment_reachable" 2
7458 return $et_vector_alignment_reachable
7459 }
7460
7461 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
7462
7463 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
7464 set et_vector_alignment_reachable_for_64bit 0
7465 if { [check_effective_target_vect_aligned_arrays]
7466 || [check_effective_target_natural_alignment_64] } {
7467 set et_vector_alignment_reachable_for_64bit 1
7468 }
7469 verbose "check_effective_target_vector_alignment_reachable_for_64bit:\
7470 returning $et_vector_alignment_reachable_for_64bit" 2
7471 return $et_vector_alignment_reachable_for_64bit
7472 }
7473
7474 # Return 1 if the target only requires element alignment for vector accesses
7475
7476 proc check_effective_target_vect_element_align { } {
7477 return [check_cached_effective_target_indexed vect_element_align {
7478 expr { ([istarget arm*-*-*]
7479 && ![check_effective_target_arm_vect_no_misalign])
7480 || [check_effective_target_vect_hw_misalign]
7481 || [istarget amdgcn-*-*] }}]
7482 }
7483
7484 # Return 1 if we expect to see unaligned accesses in at least some
7485 # vector dumps.
7486
7487 proc check_effective_target_vect_unaligned_possible { } {
7488 return [expr { ![check_effective_target_vect_element_align_preferred]
7489 && (![check_effective_target_vect_no_align]
7490 || [check_effective_target_vect_hw_misalign]) }]
7491 }
7492
7493 # Return 1 if the target supports vector LOAD_LANES operations, 0 otherwise.
7494
7495 proc check_effective_target_vect_load_lanes { } {
7496 # We don't support load_lanes correctly on big-endian arm.
7497 return [check_cached_effective_target vect_load_lanes {
7498 expr { ([check_effective_target_arm_little_endian]
7499 && [check_effective_target_arm_neon_ok])
7500 || [istarget aarch64*-*-*] }}]
7501 }
7502
7503 # Return 1 if the target supports vector masked loads.
7504
7505 proc check_effective_target_vect_masked_load { } {
7506 return [expr { [check_avx_available]
7507 || [check_effective_target_aarch64_sve]
7508 || [istarget amdgcn*-*-*] } ]
7509 }
7510
7511 # Return 1 if the target supports vector masked stores.
7512
7513 proc check_effective_target_vect_masked_store { } {
7514 return [expr { [check_effective_target_aarch64_sve]
7515 || [istarget amdgcn*-*-*] }]
7516 }
7517
7518 # Return 1 if the target supports vector scatter stores.
7519
7520 proc check_effective_target_vect_scatter_store { } {
7521 return [expr { [check_effective_target_aarch64_sve]
7522 || [istarget amdgcn*-*-*] }]
7523 }
7524
7525 # Return 1 if the target supports vector conditional operations, 0 otherwise.
7526
7527 proc check_effective_target_vect_condition { } {
7528 return [check_cached_effective_target_indexed vect_condition {
7529 expr { [istarget aarch64*-*-*]
7530 || [istarget powerpc*-*-*]
7531 || [istarget ia64-*-*]
7532 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7533 || ([istarget mips*-*-*]
7534 && [et-is-effective-target mips_msa])
7535 || ([istarget arm*-*-*]
7536 && [check_effective_target_arm_neon_ok])
7537 || ([istarget s390*-*-*]
7538 && [check_effective_target_s390_vx])
7539 || [istarget amdgcn-*-*] }}]
7540 }
7541
7542 # Return 1 if the target supports vector conditional operations where
7543 # the comparison has different type from the lhs, 0 otherwise.
7544
7545 proc check_effective_target_vect_cond_mixed { } {
7546 return [check_cached_effective_target_indexed vect_cond_mixed {
7547 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
7548 || [istarget aarch64*-*-*]
7549 || [istarget powerpc*-*-*]
7550 || ([istarget arm*-*-*]
7551 && [check_effective_target_arm_neon_ok])
7552 || ([istarget mips*-*-*]
7553 && [et-is-effective-target mips_msa])
7554 || ([istarget s390*-*-*]
7555 && [check_effective_target_s390_vx])
7556 || [istarget amdgcn-*-*] }}]
7557 }
7558
7559 # Return 1 if the target supports vector char multiplication, 0 otherwise.
7560
7561 proc check_effective_target_vect_char_mult { } {
7562 return [check_cached_effective_target_indexed vect_char_mult {
7563 expr { [istarget aarch64*-*-*]
7564 || [istarget ia64-*-*]
7565 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7566 || [check_effective_target_arm32]
7567 || [check_effective_target_powerpc_altivec]
7568 || ([istarget mips*-*-*]
7569 && [et-is-effective-target mips_msa])
7570 || ([istarget s390*-*-*]
7571 && [check_effective_target_s390_vx])
7572 || [istarget amdgcn-*-*] }}]
7573 }
7574
7575 # Return 1 if the target supports vector short multiplication, 0 otherwise.
7576
7577 proc check_effective_target_vect_short_mult { } {
7578 return [check_cached_effective_target_indexed vect_short_mult {
7579 expr { [istarget ia64-*-*]
7580 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7581 || [istarget powerpc*-*-*]
7582 || [istarget aarch64*-*-*]
7583 || [check_effective_target_arm32]
7584 || ([istarget mips*-*-*]
7585 && ([et-is-effective-target mips_msa]
7586 || [et-is-effective-target mips_loongson_mmi]))
7587 || ([istarget s390*-*-*]
7588 && [check_effective_target_s390_vx])
7589 || [istarget amdgcn-*-*] }}]
7590 }
7591
7592 # Return 1 if the target supports vector int multiplication, 0 otherwise.
7593
7594 proc check_effective_target_vect_int_mult { } {
7595 return [check_cached_effective_target_indexed vect_int_mult {
7596 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
7597 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7598 || [istarget ia64-*-*]
7599 || [istarget aarch64*-*-*]
7600 || ([istarget mips*-*-*]
7601 && [et-is-effective-target mips_msa])
7602 || [check_effective_target_arm32]
7603 || ([istarget s390*-*-*]
7604 && [check_effective_target_s390_vx])
7605 || [istarget amdgcn-*-*] }}]
7606 }
7607
7608 # Return 1 if the target supports 64 bit hardware vector
7609 # multiplication of long operands with a long result, 0 otherwise.
7610 #
7611 # This can change for different subtargets so do not cache the result.
7612
7613 proc check_effective_target_vect_long_mult { } {
7614 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
7615 || (([istarget powerpc*-*-*]
7616 && ![istarget powerpc-*-linux*paired*])
7617 && [check_effective_target_ilp32])
7618 || [is-effective-target arm_neon]
7619 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
7620 || [istarget aarch64*-*-*]
7621 || ([istarget mips*-*-*]
7622 && [et-is-effective-target mips_msa]) } {
7623 set answer 1
7624 } else {
7625 set answer 0
7626 }
7627
7628 verbose "check_effective_target_vect_long_mult: returning $answer" 2
7629 return $answer
7630 }
7631
7632 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
7633
7634 proc check_effective_target_vect_extract_even_odd { } {
7635 return [check_cached_effective_target_indexed extract_even_odd {
7636 expr { [istarget aarch64*-*-*]
7637 || [istarget powerpc*-*-*]
7638 || [is-effective-target arm_neon]
7639 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7640 || [istarget ia64-*-*]
7641 || ([istarget mips*-*-*]
7642 && ([et-is-effective-target mips_msa]
7643 || [et-is-effective-target mpaired_single]))
7644 || ([istarget s390*-*-*]
7645 && [check_effective_target_s390_vx]) }}]
7646 }
7647
7648 # Return 1 if the target supports vector interleaving, 0 otherwise.
7649
7650 proc check_effective_target_vect_interleave { } {
7651 return [check_cached_effective_target_indexed vect_interleave {
7652 expr { [istarget aarch64*-*-*]
7653 || [istarget powerpc*-*-*]
7654 || [is-effective-target arm_neon]
7655 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7656 || [istarget ia64-*-*]
7657 || ([istarget mips*-*-*]
7658 && ([et-is-effective-target mpaired_single]
7659 || [et-is-effective-target mips_msa]))
7660 || ([istarget s390*-*-*]
7661 && [check_effective_target_s390_vx]) }}]
7662 }
7663
7664 foreach N {2 3 4 8} {
7665 eval [string map [list N $N] {
7666 # Return 1 if the target supports 2-vector interleaving
7667 proc check_effective_target_vect_stridedN { } {
7668 return [check_cached_effective_target_indexed vect_stridedN {
7669 if { (N & -N) == N
7670 && [check_effective_target_vect_interleave]
7671 && [check_effective_target_vect_extract_even_odd] } {
7672 return 1
7673 }
7674 if { ([istarget arm*-*-*]
7675 || [istarget aarch64*-*-*]) && N >= 2 && N <= 4 } {
7676 return 1
7677 }
7678 if [check_effective_target_vect_fully_masked] {
7679 return 1
7680 }
7681 return 0
7682 }]
7683 }
7684 }]
7685 }
7686
7687 # Return the list of vector sizes (in bits) that each target supports.
7688 # A vector length of "0" indicates variable-length vectors.
7689
7690 proc available_vector_sizes { } {
7691 set result {}
7692 if { [istarget aarch64*-*-*] } {
7693 if { [check_effective_target_aarch64_sve] } {
7694 lappend result [aarch64_sve_bits]
7695 }
7696 lappend result 128 64
7697 } elseif { [istarget arm*-*-*]
7698 && [check_effective_target_arm_neon_ok] } {
7699 lappend result 128 64
7700 } elseif { [istarget i?86-*-*] || [istarget x86_64-*-*] } {
7701 if { [check_avx_available] && ![check_prefer_avx128] } {
7702 lappend result 256
7703 }
7704 lappend result 128
7705 if { ![is-effective-target ia32] } {
7706 lappend result 64
7707 }
7708 lappend result 32
7709 } elseif { [istarget sparc*-*-*] } {
7710 lappend result 64
7711 } elseif { [istarget amdgcn*-*-*] } {
7712 lappend result 4096
7713 } else {
7714 # The traditional default asumption.
7715 lappend result 128
7716 }
7717 return $result
7718 }
7719
7720 # Return 1 if the target supports multiple vector sizes
7721
7722 proc check_effective_target_vect_multiple_sizes { } {
7723 return [expr { [llength [available_vector_sizes]] > 1 }]
7724 }
7725
7726 # Return true if variable-length vectors are supported.
7727
7728 proc check_effective_target_vect_variable_length { } {
7729 return [expr { [lindex [available_vector_sizes] 0] == 0 }]
7730 }
7731
7732 # Return 1 if the target supports vectors of 64 bits.
7733
7734 proc check_effective_target_vect64 { } {
7735 return [expr { [lsearch -exact [available_vector_sizes] 64] >= 0 }]
7736 }
7737
7738 # Return 1 if the target supports vectors of 32 bits.
7739
7740 proc check_effective_target_vect32 { } {
7741 return [expr { [lsearch -exact [available_vector_sizes] 32] >= 0 }]
7742 }
7743
7744 # Return 1 if the target supports vector copysignf calls.
7745
7746 proc check_effective_target_vect_call_copysignf { } {
7747 return [check_cached_effective_target_indexed vect_call_copysignf {
7748 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
7749 || [istarget powerpc*-*-*]
7750 || [istarget aarch64*-*-*] }}]
7751 }
7752
7753 # Return 1 if the target supports hardware square root instructions.
7754
7755 proc check_effective_target_sqrt_insn { } {
7756 return [check_cached_effective_target sqrt_insn {
7757 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
7758 || [check_effective_target_powerpc_sqrt]
7759 || [istarget aarch64*-*-*]
7760 || ([istarget arm*-*-*] && [check_effective_target_arm_vfp_ok])
7761 || ([istarget s390*-*-*]
7762 && [check_effective_target_s390_vx])
7763 || [istarget amdgcn-*-*] }}]
7764 }
7765
7766 # Return any additional options to enable square root intructions.
7767
7768 proc add_options_for_sqrt_insn { flags } {
7769 if { [istarget amdgcn*-*-*] } {
7770 return "$flags -ffast-math"
7771 }
7772 if { [istarget arm*-*-*] } {
7773 return [add_options_for_arm_vfp "$flags"]
7774 }
7775 return $flags
7776 }
7777
7778 # Return 1 if the target supports vector sqrtf calls.
7779
7780 proc check_effective_target_vect_call_sqrtf { } {
7781 return [check_cached_effective_target_indexed vect_call_sqrtf {
7782 expr { [istarget aarch64*-*-*]
7783 || [istarget i?86-*-*] || [istarget x86_64-*-*]
7784 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
7785 || ([istarget s390*-*-*]
7786 && [check_effective_target_s390_vx]) }}]
7787 }
7788
7789 # Return 1 if the target supports vector lrint calls.
7790
7791 proc check_effective_target_vect_call_lrint { } {
7792 set et_vect_call_lrint 0
7793 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
7794 && [check_effective_target_ilp32])
7795 || [istarget amdgcn-*-*] } {
7796 set et_vect_call_lrint 1
7797 }
7798
7799 verbose "check_effective_target_vect_call_lrint: returning $et_vect_call_lrint" 2
7800 return $et_vect_call_lrint
7801 }
7802
7803 # Return 1 if the target supports vector btrunc calls.
7804
7805 proc check_effective_target_vect_call_btrunc { } {
7806 return [check_cached_effective_target_indexed vect_call_btrunc {
7807 expr { [istarget aarch64*-*-*]
7808 || [istarget amdgcn-*-*] }}]
7809 }
7810
7811 # Return 1 if the target supports vector btruncf calls.
7812
7813 proc check_effective_target_vect_call_btruncf { } {
7814 return [check_cached_effective_target_indexed vect_call_btruncf {
7815 expr { [istarget aarch64*-*-*]
7816 || [istarget amdgcn-*-*] }}]
7817 }
7818
7819 # Return 1 if the target supports vector ceil calls.
7820
7821 proc check_effective_target_vect_call_ceil { } {
7822 return [check_cached_effective_target_indexed vect_call_ceil {
7823 expr { [istarget aarch64*-*-*]
7824 || [istarget amdgcn-*-*] }}]
7825 }
7826
7827 # Return 1 if the target supports vector ceilf calls.
7828
7829 proc check_effective_target_vect_call_ceilf { } {
7830 return [check_cached_effective_target_indexed vect_call_ceilf {
7831 expr { [istarget aarch64*-*-*] }}]
7832 }
7833
7834 # Return 1 if the target supports vector floor calls.
7835
7836 proc check_effective_target_vect_call_floor { } {
7837 return [check_cached_effective_target_indexed vect_call_floor {
7838 expr { [istarget aarch64*-*-*] }}]
7839 }
7840
7841 # Return 1 if the target supports vector floorf calls.
7842
7843 proc check_effective_target_vect_call_floorf { } {
7844 return [check_cached_effective_target_indexed vect_call_floorf {
7845 expr { [istarget aarch64*-*-*]
7846 || [istarget amdgcn-*-*] }}]
7847 }
7848
7849 # Return 1 if the target supports vector lceil calls.
7850
7851 proc check_effective_target_vect_call_lceil { } {
7852 return [check_cached_effective_target_indexed vect_call_lceil {
7853 expr { [istarget aarch64*-*-*] }}]
7854 }
7855
7856 # Return 1 if the target supports vector lfloor calls.
7857
7858 proc check_effective_target_vect_call_lfloor { } {
7859 return [check_cached_effective_target_indexed vect_call_lfloor {
7860 expr { [istarget aarch64*-*-*] }}]
7861 }
7862
7863 # Return 1 if the target supports vector nearbyint calls.
7864
7865 proc check_effective_target_vect_call_nearbyint { } {
7866 return [check_cached_effective_target_indexed vect_call_nearbyint {
7867 expr { [istarget aarch64*-*-*] }}]
7868 }
7869
7870 # Return 1 if the target supports vector nearbyintf calls.
7871
7872 proc check_effective_target_vect_call_nearbyintf { } {
7873 return [check_cached_effective_target_indexed vect_call_nearbyintf {
7874 expr { [istarget aarch64*-*-*] }}]
7875 }
7876
7877 # Return 1 if the target supports vector round calls.
7878
7879 proc check_effective_target_vect_call_round { } {
7880 return [check_cached_effective_target_indexed vect_call_round {
7881 expr { [istarget aarch64*-*-*] }}]
7882 }
7883
7884 # Return 1 if the target supports vector roundf calls.
7885
7886 proc check_effective_target_vect_call_roundf { } {
7887 return [check_cached_effective_target_indexed vect_call_roundf {
7888 expr { [istarget aarch64*-*-*] }}]
7889 }
7890
7891 # Return 1 if the target supports AND, OR and XOR reduction.
7892
7893 proc check_effective_target_vect_logical_reduc { } {
7894 return [check_effective_target_aarch64_sve]
7895 }
7896
7897 # Return 1 if the target supports the fold_extract_last optab.
7898
7899 proc check_effective_target_vect_fold_extract_last { } {
7900 return [expr { [check_effective_target_aarch64_sve]
7901 || [istarget amdgcn*-*-*] }]
7902 }
7903
7904 # Return 1 if the target supports section-anchors
7905
7906 proc check_effective_target_section_anchors { } {
7907 return [check_cached_effective_target section_anchors {
7908 expr { [istarget powerpc*-*-*]
7909 || [istarget arm*-*-*]
7910 || [istarget aarch64*-*-*] }}]
7911 }
7912
7913 # Return 1 if the target supports atomic operations on "int_128" values.
7914
7915 proc check_effective_target_sync_int_128 { } {
7916 return 0
7917 }
7918
7919 # Return 1 if the target supports atomic operations on "int_128" values
7920 # and can execute them.
7921 # This requires support for both compare-and-swap and true atomic loads.
7922
7923 proc check_effective_target_sync_int_128_runtime { } {
7924 return 0
7925 }
7926
7927 # Return 1 if the target supports atomic operations on "long long".
7928 #
7929 # Note: 32bit x86 targets require -march=pentium in dg-options.
7930 # Note: 32bit s390 targets require -mzarch in dg-options.
7931
7932 proc check_effective_target_sync_long_long { } {
7933 if { [istarget i?86-*-*] || [istarget x86_64-*-*])
7934 || [istarget aarch64*-*-*]
7935 || [istarget arm*-*-*]
7936 || [istarget alpha*-*-*]
7937 || ([istarget sparc*-*-*] && [check_effective_target_lp64])
7938 || [istarget s390*-*-*] } {
7939 return 1
7940 } else {
7941 return 0
7942 }
7943 }
7944
7945 # Return 1 if the target supports popcount on long.
7946
7947 proc check_effective_target_popcountl { } {
7948 return [check_no_messages_and_pattern popcountl "!\\(call" rtl-expand {
7949 int foo (long b)
7950 {
7951 return __builtin_popcountl (b);
7952 }
7953 } "" ]
7954 }
7955
7956 # Return 1 if the target supports popcount on long long.
7957
7958 proc check_effective_target_popcountll { } {
7959 return [check_no_messages_and_pattern popcountll "!\\(call" rtl-expand {
7960 int foo (long long b)
7961 {
7962 return __builtin_popcountll (b);
7963 }
7964 } "" ]
7965 }
7966
7967
7968 # Return 1 if the target supports popcount on int.
7969
7970 proc check_effective_target_popcount { } {
7971 return [check_no_messages_and_pattern popcount "!\\(call" rtl-expand {
7972 int foo (int b)
7973 {
7974 return __builtin_popcount (b);
7975 }
7976 } "" ]
7977 }
7978
7979 # Return 1 if the target supports atomic operations on "long long"
7980 # and can execute them.
7981 #
7982 # Note: 32bit x86 targets require -march=pentium in dg-options.
7983
7984 proc check_effective_target_sync_long_long_runtime { } {
7985 if { (([istarget x86_64-*-*] || [istarget i?86-*-*])
7986 && [check_cached_effective_target sync_long_long_available {
7987 check_runtime_nocache sync_long_long_available {
7988 #include "cpuid.h"
7989 int main ()
7990 {
7991 unsigned int eax, ebx, ecx, edx;
7992 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
7993 return !(edx & bit_CMPXCHG8B);
7994 return 1;
7995 }
7996 } ""
7997 }])
7998 || [istarget aarch64*-*-*]
7999 || [istarget arm*-*-uclinuxfdpiceabi]
8000 || ([istarget arm*-*-linux-*]
8001 && [check_runtime sync_longlong_runtime {
8002 #include <stdlib.h>
8003 int main ()
8004 {
8005 long long l1;
8006
8007 if (sizeof (long long) != 8)
8008 exit (1);
8009
8010 /* Just check for native;
8011 checking for kernel fallback is tricky. */
8012 asm volatile ("ldrexd r0,r1, [%0]"
8013 : : "r" (&l1) : "r0", "r1");
8014 exit (0);
8015 }
8016 } "" ])
8017 || [istarget alpha*-*-*]
8018 || ([istarget sparc*-*-*]
8019 && [check_effective_target_lp64]
8020 && [check_effective_target_ultrasparc_hw])
8021 || ([istarget powerpc*-*-*] && [check_effective_target_lp64]) } {
8022 return 1
8023 } else {
8024 return 0
8025 }
8026 }
8027
8028 # Return 1 if the target supports byte swap instructions.
8029
8030 proc check_effective_target_bswap { } {
8031 return [check_cached_effective_target bswap {
8032 expr { [istarget aarch64*-*-*]
8033 || [istarget alpha*-*-*]
8034 || [istarget i?86-*-*] || [istarget x86_64-*-*]
8035 || [istarget m68k-*-*]
8036 || [istarget powerpc*-*-*]
8037 || [istarget rs6000-*-*]
8038 || [istarget s390*-*-*]
8039 || ([istarget arm*-*-*]
8040 && [check_no_compiler_messages_nocache arm_v6_or_later object {
8041 #if __ARM_ARCH < 6
8042 #error not armv6 or later
8043 #endif
8044 int i;
8045 } ""]) }}]
8046 }
8047
8048 # Return 1 if the target supports atomic operations on "int" and "long".
8049
8050 proc check_effective_target_sync_int_long { } {
8051 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
8052 # load-reserved/store-conditional instructions.
8053 return [check_cached_effective_target sync_int_long {
8054 expr { [istarget ia64-*-*]
8055 || [istarget i?86-*-*] || [istarget x86_64-*-*]
8056 || [istarget aarch64*-*-*]
8057 || [istarget alpha*-*-*]
8058 || [istarget arm*-*-linux-*]
8059 || [istarget arm*-*-uclinuxfdpiceabi]
8060 || ([istarget arm*-*-*]
8061 && [check_effective_target_arm_acq_rel])
8062 || [istarget bfin*-*linux*]
8063 || [istarget hppa*-*linux*]
8064 || [istarget s390*-*-*]
8065 || [istarget powerpc*-*-*]
8066 || [istarget cris-*-*]
8067 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
8068 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
8069 || [check_effective_target_mips_llsc]
8070 || [istarget nvptx*-*-*]
8071 }}]
8072 }
8073
8074 # Return 1 if the target supports atomic operations on "int" and "long" on
8075 # stack addresses.
8076
8077 proc check_effective_target_sync_int_long_stack { } {
8078 return [check_cached_effective_target sync_int_long_stack {
8079 expr { ![istarget nvptx*-*-*]
8080 && [check_effective_target_sync_int_long]
8081 }}]
8082 }
8083
8084 # Return 1 if the target supports atomic operations on "char" and "short".
8085
8086 proc check_effective_target_sync_char_short { } {
8087 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
8088 # load-reserved/store-conditional instructions.
8089 return [check_cached_effective_target sync_char_short {
8090 expr { [istarget aarch64*-*-*]
8091 || [istarget ia64-*-*]
8092 || [istarget i?86-*-*] || [istarget x86_64-*-*]
8093 || [istarget alpha*-*-*]
8094 || [istarget arm*-*-linux-*]
8095 || [istarget arm*-*-uclinuxfdpiceabi]
8096 || ([istarget arm*-*-*]
8097 && [check_effective_target_arm_acq_rel])
8098 || [istarget hppa*-*linux*]
8099 || [istarget s390*-*-*]
8100 || [istarget powerpc*-*-*]
8101 || [istarget cris-*-*]
8102 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
8103 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
8104 || [check_effective_target_mips_llsc] }}]
8105 }
8106
8107 # Return 1 if the target uses a ColdFire FPU.
8108
8109 proc check_effective_target_coldfire_fpu { } {
8110 return [check_no_compiler_messages coldfire_fpu assembly {
8111 #ifndef __mcffpu__
8112 #error !__mcffpu__
8113 #endif
8114 }]
8115 }
8116
8117 # Return true if this is a uClibc target.
8118
8119 proc check_effective_target_uclibc {} {
8120 return [check_no_compiler_messages uclibc object {
8121 #include <features.h>
8122 #if !defined (__UCLIBC__)
8123 #error !__UCLIBC__
8124 #endif
8125 }]
8126 }
8127
8128 # Return true if this is a uclibc target and if the uclibc feature
8129 # described by __$feature__ is not present.
8130
8131 proc check_missing_uclibc_feature {feature} {
8132 return [check_no_compiler_messages $feature object "
8133 #include <features.h>
8134 #if !defined (__UCLIBC) || defined (__${feature}__)
8135 #error FOO
8136 #endif
8137 "]
8138 }
8139
8140 # Return true if this is a Newlib target.
8141
8142 proc check_effective_target_newlib {} {
8143 return [check_no_compiler_messages newlib object {
8144 #include <newlib.h>
8145 }]
8146 }
8147
8148 # Return true if GCC was configured with --enable-newlib-nano-formatted-io
8149 proc check_effective_target_newlib_nano_io { } {
8150 return [check_configured_with "--enable-newlib-nano-formatted-io"]
8151 }
8152
8153 # Some newlib versions don't provide a frexpl and instead depend
8154 # on frexp to implement long double conversions in their printf-like
8155 # functions. This leads to broken results. Detect such versions here.
8156
8157 proc check_effective_target_newlib_broken_long_double_io {} {
8158 if { [is-effective-target newlib] && ![is-effective-target frexpl] } {
8159 return 1
8160 }
8161 return 0
8162 }
8163
8164 # Return true if this is NOT a Bionic target.
8165
8166 proc check_effective_target_non_bionic {} {
8167 return [check_no_compiler_messages non_bionic object {
8168 #include <ctype.h>
8169 #if defined (__BIONIC__)
8170 #error FOO
8171 #endif
8172 }]
8173 }
8174
8175 # Return true if this target has error.h header.
8176
8177 proc check_effective_target_error_h {} {
8178 return [check_no_compiler_messages error_h object {
8179 #include <error.h>
8180 }]
8181 }
8182
8183 # Return true if this target has tgmath.h header.
8184
8185 proc check_effective_target_tgmath_h {} {
8186 return [check_no_compiler_messages tgmath_h object {
8187 #include <tgmath.h>
8188 }]
8189 }
8190
8191 # Return true if target's libc supports complex functions.
8192
8193 proc check_effective_target_libc_has_complex_functions {} {
8194 return [check_no_compiler_messages libc_has_complex_functions object {
8195 #include <complex.h>
8196 }]
8197 }
8198
8199 # Return 1 if
8200 # (a) an error of a few ULP is expected in string to floating-point
8201 # conversion functions; and
8202 # (b) overflow is not always detected correctly by those functions.
8203
8204 proc check_effective_target_lax_strtofp {} {
8205 # By default, assume that all uClibc targets suffer from this.
8206 return [check_effective_target_uclibc]
8207 }
8208
8209 # Return 1 if this is a target for which wcsftime is a dummy
8210 # function that always returns 0.
8211
8212 proc check_effective_target_dummy_wcsftime {} {
8213 # By default, assume that all uClibc targets suffer from this.
8214 return [check_effective_target_uclibc]
8215 }
8216
8217 # Return 1 if constructors with initialization priority arguments are
8218 # supposed on this target.
8219
8220 proc check_effective_target_init_priority {} {
8221 return [check_no_compiler_messages init_priority assembly "
8222 void f() __attribute__((constructor (1000)));
8223 void f() \{\}
8224 "]
8225 }
8226
8227 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
8228 # This can be used with any check_* proc that takes no argument and
8229 # returns only 1 or 0. It could be used with check_* procs that take
8230 # arguments with keywords that pass particular arguments.
8231
8232 proc is-effective-target { arg } {
8233 global et_index
8234 set selected 0
8235 if { ![info exists et_index] } {
8236 # Initialize the effective target index that is used in some
8237 # check_effective_target_* procs.
8238 set et_index 0
8239 }
8240 if { [info procs check_effective_target_${arg}] != [list] } {
8241 set selected [check_effective_target_${arg}]
8242 } else {
8243 switch $arg {
8244 "vmx_hw" { set selected [check_vmx_hw_available] }
8245 "vsx_hw" { set selected [check_vsx_hw_available] }
8246 "p8vector_hw" { set selected [check_p8vector_hw_available] }
8247 "p9vector_hw" { set selected [check_p9vector_hw_available] }
8248 "p9modulo_hw" { set selected [check_p9modulo_hw_available] }
8249 "power10_hw" { set selected [check_power10_hw_available] }
8250 "ppc_float128_sw" { set selected [check_ppc_float128_sw_available] }
8251 "ppc_float128_hw" { set selected [check_ppc_float128_hw_available] }
8252 "ppc_recip_hw" { set selected [check_ppc_recip_hw_available] }
8253 "ppc_cpu_supports_hw" { set selected [check_ppc_cpu_supports_hw_available] }
8254 "ppc_mma_hw" { set selected [check_ppc_mma_hw_available] }
8255 "dfp_hw" { set selected [check_dfp_hw_available] }
8256 "htm_hw" { set selected [check_htm_hw_available] }
8257 "named_sections" { set selected [check_named_sections_available] }
8258 "gc_sections" { set selected [check_gc_sections_available] }
8259 "cxa_atexit" { set selected [check_cxa_atexit_available] }
8260 default { error "unknown effective target keyword `$arg'" }
8261 }
8262 }
8263
8264 verbose "is-effective-target: $arg $selected" 2
8265 return $selected
8266 }
8267
8268 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
8269
8270 proc is-effective-target-keyword { arg } {
8271 if { [info procs check_effective_target_${arg}] != [list] } {
8272 return 1
8273 } else {
8274 # These have different names for their check_* procs.
8275 switch $arg {
8276 "vmx_hw" { return 1 }
8277 "vsx_hw" { return 1 }
8278 "p8vector_hw" { return 1 }
8279 "p9vector_hw" { return 1 }
8280 "p9modulo_hw" { return 1 }
8281 "power10_hw" { return 1 }
8282 "ppc_float128_sw" { return 1 }
8283 "ppc_float128_hw" { return 1 }
8284 "ppc_recip_hw" { return 1 }
8285 "ppc_mma_hw" { return 1 }
8286 "dfp_hw" { return 1 }
8287 "htm_hw" { return 1 }
8288 "named_sections" { return 1 }
8289 "gc_sections" { return 1 }
8290 "cxa_atexit" { return 1 }
8291 default { return 0 }
8292 }
8293 }
8294 }
8295
8296 # Execute tests for all targets in EFFECTIVE_TARGETS list. Set et_index to
8297 # indicate what target is currently being processed. This is for
8298 # the vectorizer tests, e.g. vect_int, to keep track what target supports
8299 # a given feature.
8300
8301 proc et-dg-runtest { runtest testcases flags default-extra-flags } {
8302 global dg-do-what-default
8303 global EFFECTIVE_TARGETS
8304 global et_index
8305
8306 if { [llength $EFFECTIVE_TARGETS] > 0 } {
8307 foreach target $EFFECTIVE_TARGETS {
8308 set target_flags $flags
8309 set dg-do-what-default compile
8310 set et_index [lsearch -exact $EFFECTIVE_TARGETS $target]
8311 if { [info procs add_options_for_${target}] != [list] } {
8312 set target_flags [add_options_for_${target} "$flags"]
8313 }
8314 if { [info procs check_effective_target_${target}_runtime]
8315 != [list] && [check_effective_target_${target}_runtime] } {
8316 set dg-do-what-default run
8317 }
8318 $runtest $testcases $target_flags ${default-extra-flags}
8319 }
8320 } else {
8321 set et_index 0
8322 $runtest $testcases $flags ${default-extra-flags}
8323 }
8324 }
8325
8326 # Return 1 if a target matches the target in EFFECTIVE_TARGETS at index
8327 # et_index, 0 otherwise.
8328
8329 proc et-is-effective-target { target } {
8330 global EFFECTIVE_TARGETS
8331 global et_index
8332
8333 if { [llength $EFFECTIVE_TARGETS] > $et_index
8334 && [lindex $EFFECTIVE_TARGETS $et_index] == $target } {
8335 return 1
8336 }
8337 return 0
8338 }
8339
8340 # Return 1 if target default to short enums
8341
8342 proc check_effective_target_short_enums { } {
8343 return [check_no_compiler_messages short_enums assembly {
8344 enum foo { bar };
8345 int s[sizeof (enum foo) == 1 ? 1 : -1];
8346 }]
8347 }
8348
8349 # Return 1 if target supports merging string constants at link time.
8350
8351 proc check_effective_target_string_merging { } {
8352 return [check_no_messages_and_pattern string_merging \
8353 "rodata\\.str" assembly {
8354 const char *var = "String";
8355 } {-O2}]
8356 }
8357
8358 # Return 1 if target has the basic signed and unsigned types in
8359 # <stdint.h>, 0 otherwise. This will be obsolete when GCC ensures a
8360 # working <stdint.h> for all targets.
8361
8362 proc check_effective_target_stdint_types { } {
8363 return [check_no_compiler_messages stdint_types assembly {
8364 #include <stdint.h>
8365 int8_t a; int16_t b; int32_t c; int64_t d;
8366 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
8367 }]
8368 }
8369
8370 # Like check_effective_target_stdint_types, but test what happens when
8371 # -mbig-endian is passed. This test only makes sense on targets that
8372 # support -mbig-endian; it will fail elsewhere.
8373
8374 proc check_effective_target_stdint_types_mbig_endian { } {
8375 return [check_no_compiler_messages stdint_types_mbig_endian assembly {
8376 #include <stdint.h>
8377 int8_t a; int16_t b; int32_t c; int64_t d;
8378 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
8379 } "-mbig-endian"]
8380 }
8381
8382 # Return 1 if target has the basic signed and unsigned types in
8383 # <inttypes.h>, 0 otherwise. This is for tests that GCC's notions of
8384 # these types agree with those in the header, as some systems have
8385 # only <inttypes.h>.
8386
8387 proc check_effective_target_inttypes_types { } {
8388 return [check_no_compiler_messages inttypes_types assembly {
8389 #include <inttypes.h>
8390 int8_t a; int16_t b; int32_t c; int64_t d;
8391 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
8392 }]
8393 }
8394
8395 # Return 1 if programs are intended to be run on a simulator
8396 # (i.e. slowly) rather than hardware (i.e. fast).
8397
8398 proc check_effective_target_simulator { } {
8399
8400 # All "src/sim" simulators set this one.
8401 if [board_info target exists is_simulator] {
8402 return [board_info target is_simulator]
8403 }
8404
8405 # The "sid" simulators don't set that one, but at least they set
8406 # this one.
8407 if [board_info target exists slow_simulator] {
8408 return [board_info target slow_simulator]
8409 }
8410
8411 return 0
8412 }
8413
8414 # Return 1 if programs are intended to be run on hardware rather than
8415 # on a simulator
8416
8417 proc check_effective_target_hw { } {
8418
8419 # All "src/sim" simulators set this one.
8420 if [board_info target exists is_simulator] {
8421 if [board_info target is_simulator] {
8422 return 0
8423 } else {
8424 return 1
8425 }
8426 }
8427
8428 # The "sid" simulators don't set that one, but at least they set
8429 # this one.
8430 if [board_info target exists slow_simulator] {
8431 if [board_info target slow_simulator] {
8432 return 0
8433 } else {
8434 return 1
8435 }
8436 }
8437
8438 return 1
8439 }
8440
8441 # Return 1 if the target is a VxWorks kernel.
8442
8443 proc check_effective_target_vxworks_kernel { } {
8444 return [check_no_compiler_messages vxworks_kernel assembly {
8445 #if !defined __vxworks || defined __RTP__
8446 #error NO
8447 #endif
8448 }]
8449 }
8450
8451 # Return 1 if the target is a VxWorks RTP.
8452
8453 proc check_effective_target_vxworks_rtp { } {
8454 return [check_no_compiler_messages vxworks_rtp assembly {
8455 #if !defined __vxworks || !defined __RTP__
8456 #error NO
8457 #endif
8458 }]
8459 }
8460
8461 # Return 1 if the target is expected to provide wide character support.
8462
8463 proc check_effective_target_wchar { } {
8464 if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
8465 return 0
8466 }
8467 return [check_no_compiler_messages wchar assembly {
8468 #include <wchar.h>
8469 }]
8470 }
8471
8472 # Return 1 if the target has <pthread.h>.
8473
8474 proc check_effective_target_pthread_h { } {
8475 return [check_no_compiler_messages pthread_h assembly {
8476 #include <pthread.h>
8477 }]
8478 }
8479
8480 # Return 1 if the target can truncate a file from a file-descriptor,
8481 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
8482 # chsize. We test for a trivially functional truncation; no stubs.
8483 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
8484 # different function to be used.
8485
8486 proc check_effective_target_fd_truncate { } {
8487 set prog {
8488 #define _FILE_OFFSET_BITS 64
8489 #include <unistd.h>
8490 #include <stdio.h>
8491 #include <stdlib.h>
8492 #include <string.h>
8493 int main ()
8494 {
8495 FILE *f = fopen ("tst.tmp", "wb");
8496 int fd;
8497 const char t[] = "test writing more than ten characters";
8498 char s[11];
8499 int status = 0;
8500 fd = fileno (f);
8501 write (fd, t, sizeof (t) - 1);
8502 lseek (fd, 0, 0);
8503 if (ftruncate (fd, 10) != 0)
8504 status = 1;
8505 close (fd);
8506 fclose (f);
8507 if (status)
8508 {
8509 unlink ("tst.tmp");
8510 exit (status);
8511 }
8512 f = fopen ("tst.tmp", "rb");
8513 if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
8514 status = 1;
8515 fclose (f);
8516 unlink ("tst.tmp");
8517 exit (status);
8518 }
8519 }
8520
8521 if { [check_runtime ftruncate $prog] } {
8522 return 1;
8523 }
8524
8525 regsub "ftruncate" $prog "chsize" prog
8526 return [check_runtime chsize $prog]
8527 }
8528
8529 # Add to FLAGS all the target-specific flags needed to enable
8530 # full IEEE compliance mode.
8531
8532 proc add_options_for_ieee { flags } {
8533 if { [istarget alpha*-*-*]
8534 || [istarget sh*-*-*] } {
8535 return "$flags -mieee"
8536 }
8537 if { [istarget rx-*-*] } {
8538 return "$flags -mnofpu"
8539 }
8540 return $flags
8541 }
8542
8543 if {![info exists flags_to_postpone]} {
8544 set flags_to_postpone ""
8545 }
8546
8547 # Add to FLAGS the flags needed to enable functions to bind locally
8548 # when using pic/PIC passes in the testsuite.
8549 proc add_options_for_bind_pic_locally { flags } {
8550 global flags_to_postpone
8551
8552 # Instead of returning 'flags' with the -fPIE or -fpie appended, we save it
8553 # in 'flags_to_postpone' and append it later in gcc_target_compile procedure in
8554 # order to make sure that the multilib_flags doesn't override this.
8555
8556 if {[check_no_compiler_messages using_pic2 assembly {
8557 #if __PIC__ != 2
8558 #error __PIC__ != 2
8559 #endif
8560 }]} {
8561 set flags_to_postpone "-fPIE"
8562 return $flags
8563 }
8564 if {[check_no_compiler_messages using_pic1 assembly {
8565 #if __PIC__ != 1
8566 #error __PIC__ != 1
8567 #endif
8568 }]} {
8569 set flags_to_postpone "-fpie"
8570 return $flags
8571 }
8572 return $flags
8573 }
8574
8575 # Add to FLAGS the flags needed to enable 64-bit vectors.
8576
8577 proc add_options_for_double_vectors { flags } {
8578 if [is-effective-target arm_neon_ok] {
8579 return "$flags -mvectorize-with-neon-double"
8580 }
8581
8582 return $flags
8583 }
8584
8585 # Add to FLAGS the flags needed to define the STACK_SIZE macro.
8586
8587 proc add_options_for_stack_size { flags } {
8588 if [is-effective-target stack_size] {
8589 set stack_size [dg-effective-target-value stack_size]
8590 return "$flags -DSTACK_SIZE=$stack_size"
8591 }
8592
8593 return $flags
8594 }
8595
8596 # Return 1 if the target provides a full C99 runtime.
8597
8598 proc check_effective_target_c99_runtime { } {
8599 return [check_cached_effective_target c99_runtime {
8600 global srcdir
8601
8602 set file [open "$srcdir/gcc.dg/builtins-config.h"]
8603 set contents [read $file]
8604 close $file
8605 append contents {
8606 #ifndef HAVE_C99_RUNTIME
8607 #error !HAVE_C99_RUNTIME
8608 #endif
8609 }
8610 check_no_compiler_messages_nocache c99_runtime assembly $contents
8611 }]
8612 }
8613
8614 # Return 1 if the target provides the D runtime.
8615
8616 proc check_effective_target_d_runtime { } {
8617 return [check_no_compiler_messages d_runtime executable {
8618 // D
8619 module mod;
8620
8621 extern(C) int main() {
8622 return 0;
8623 }
8624 }]
8625 }
8626
8627 # Return 1 if the target provides the D standard library.
8628
8629 proc check_effective_target_d_runtime_has_std_library { } {
8630 return [check_no_compiler_messages d_runtime_has_std_library executable {
8631 // D
8632 module mod;
8633
8634 extern(C) int main() {
8635 import std.math;
8636 real function(real) pcos = &cos;
8637 return 0;
8638 }
8639 }]
8640 }
8641
8642 # Return 1 if target wchar_t is at least 4 bytes.
8643
8644 proc check_effective_target_4byte_wchar_t { } {
8645 return [check_no_compiler_messages 4byte_wchar_t object {
8646 int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
8647 }]
8648 }
8649
8650 # Return 1 if the target supports automatic stack alignment.
8651
8652 proc check_effective_target_automatic_stack_alignment { } {
8653 # Ordinarily x86 supports automatic stack alignment ...
8654 if { [istarget i?86*-*-*] || [istarget x86_64-*-*] } then {
8655 if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
8656 # ... except Win64 SEH doesn't. Succeed for Win32 though.
8657 return [check_effective_target_ilp32];
8658 }
8659 return 1;
8660 }
8661 return 0;
8662 }
8663
8664 # Return true if we are compiling for AVX target.
8665
8666 proc check_avx_available { } {
8667 if { [check_no_compiler_messages avx_available assembly {
8668 #ifndef __AVX__
8669 #error unsupported
8670 #endif
8671 } ""] } {
8672 return 1;
8673 }
8674 return 0;
8675 }
8676
8677 # Return true if we are compiling for AVX2 target.
8678
8679 proc check_avx2_available { } {
8680 if { [check_no_compiler_messages avx2_available assembly {
8681 #ifndef __AVX2__
8682 #error unsupported
8683 #endif
8684 } ""] } {
8685 return 1;
8686 }
8687 return 0;
8688 }
8689
8690 # Return true if we are compiling for SSSE3 target.
8691
8692 proc check_ssse3_available { } {
8693 if { [check_no_compiler_messages sse3a_available assembly {
8694 #ifndef __SSSE3__
8695 #error unsupported
8696 #endif
8697 } ""] } {
8698 return 1;
8699 }
8700 return 0;
8701 }
8702
8703 # Return true if 32- and 16-bytes vectors are available.
8704
8705 proc check_effective_target_vect_sizes_32B_16B { } {
8706 return [expr { [available_vector_sizes] == [list 256 128] }]
8707 }
8708
8709 # Return true if 16- and 8-bytes vectors are available.
8710
8711 proc check_effective_target_vect_sizes_16B_8B { } {
8712 if { [check_avx_available]
8713 || [is-effective-target arm_neon]
8714 || [istarget aarch64*-*-*] } {
8715 return 1;
8716 } else {
8717 return 0;
8718 }
8719 }
8720
8721
8722 # Return true if 128-bits vectors are preferred even if 256-bits vectors
8723 # are available.
8724
8725 proc check_prefer_avx128 { } {
8726 if ![check_avx_available] {
8727 return 0;
8728 }
8729 return [check_no_messages_and_pattern avx_explicit "xmm" assembly {
8730 float a[1024],b[1024],c[1024];
8731 void foo (void) { int i; for (i = 0; i < 1024; i++) a[i]=b[i]+c[i];}
8732 } "-O2 -ftree-vectorize"]
8733 }
8734
8735
8736 # Return 1 if avx512f instructions can be compiled.
8737
8738 proc check_effective_target_avx512f { } {
8739 return [check_no_compiler_messages avx512f object {
8740 typedef double __m512d __attribute__ ((__vector_size__ (64)));
8741 typedef double __m128d __attribute__ ((__vector_size__ (16)));
8742
8743 __m512d _mm512_add (__m512d a)
8744 {
8745 return __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
8746 }
8747
8748 __m128d _mm128_add (__m128d a)
8749 {
8750 return __builtin_ia32_addsd_round (a, a, 8);
8751 }
8752
8753 __m128d _mm128_getmant (__m128d a)
8754 {
8755 return __builtin_ia32_getmantsd_round (a, a, 0, 8);
8756 }
8757 } "-O2 -mavx512f" ]
8758 }
8759
8760 # Return 1 if avx instructions can be compiled.
8761
8762 proc check_effective_target_avx { } {
8763 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8764 return 0
8765 }
8766 return [check_no_compiler_messages avx object {
8767 void _mm256_zeroall (void)
8768 {
8769 __builtin_ia32_vzeroall ();
8770 }
8771 } "-O2 -mavx" ]
8772 }
8773
8774 # Return 1 if avx2 instructions can be compiled.
8775 proc check_effective_target_avx2 { } {
8776 return [check_no_compiler_messages avx2 object {
8777 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
8778 __v4di
8779 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
8780 {
8781 return __builtin_ia32_andnotsi256 (__X, __Y);
8782 }
8783 } "-O0 -mavx2" ]
8784 }
8785
8786 # Return 1 if avxvnni instructions can be compiled.
8787 proc check_effective_target_avxvnni { } {
8788 return [check_no_compiler_messages avxvnni object {
8789 typedef int __v8si __attribute__ ((__vector_size__ (32)));
8790 __v8si
8791 _mm256_dpbusd_epi32 (__v8si __A, __v8si __B, __v8si __C)
8792 {
8793 return __builtin_ia32_vpdpbusd_v8si (__A, __B, __C);
8794 }
8795 } "-mavxvnni" ]
8796 }
8797
8798 # Return 1 if sse instructions can be compiled.
8799 proc check_effective_target_sse { } {
8800 return [check_no_compiler_messages sse object {
8801 int main ()
8802 {
8803 __builtin_ia32_stmxcsr ();
8804 return 0;
8805 }
8806 } "-O2 -msse" ]
8807 }
8808
8809 # Return 1 if sse2 instructions can be compiled.
8810 proc check_effective_target_sse2 { } {
8811 return [check_no_compiler_messages sse2 object {
8812 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8813
8814 __m128i _mm_srli_si128 (__m128i __A, int __N)
8815 {
8816 return (__m128i)__builtin_ia32_psrldqi128 (__A, 8);
8817 }
8818 } "-O2 -msse2" ]
8819 }
8820
8821 # Return 1 if sse4.1 instructions can be compiled.
8822 proc check_effective_target_sse4 { } {
8823 return [check_no_compiler_messages sse4.1 object {
8824 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8825 typedef int __v4si __attribute__ ((__vector_size__ (16)));
8826
8827 __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
8828 {
8829 return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
8830 (__v4si)__Y);
8831 }
8832 } "-O2 -msse4.1" ]
8833 }
8834
8835 # Return 1 if F16C instructions can be compiled.
8836
8837 proc check_effective_target_f16c { } {
8838 return [check_no_compiler_messages f16c object {
8839 #include "immintrin.h"
8840 float
8841 foo (unsigned short val)
8842 {
8843 return _cvtsh_ss (val);
8844 }
8845 } "-O2 -mf16c" ]
8846 }
8847
8848 proc check_effective_target_ms_hook_prologue { } {
8849 if { [check_no_compiler_messages ms_hook_prologue object {
8850 void __attribute__ ((__ms_hook_prologue__)) foo ();
8851 } ""] } {
8852 return 1
8853 } else {
8854 return 0
8855 }
8856 }
8857
8858 # Return 1 if 3dnow instructions can be compiled.
8859 proc check_effective_target_3dnow { } {
8860 return [check_no_compiler_messages 3dnow object {
8861 typedef int __m64 __attribute__ ((__vector_size__ (8)));
8862 typedef float __v2sf __attribute__ ((__vector_size__ (8)));
8863
8864 __m64 _m_pfadd (__m64 __A, __m64 __B)
8865 {
8866 return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
8867 }
8868 } "-O2 -m3dnow" ]
8869 }
8870
8871 # Return 1 if sse3 instructions can be compiled.
8872 proc check_effective_target_sse3 { } {
8873 return [check_no_compiler_messages sse3 object {
8874 typedef double __m128d __attribute__ ((__vector_size__ (16)));
8875 typedef double __v2df __attribute__ ((__vector_size__ (16)));
8876
8877 __m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
8878 {
8879 return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
8880 }
8881 } "-O2 -msse3" ]
8882 }
8883
8884 # Return 1 if ssse3 instructions can be compiled.
8885 proc check_effective_target_ssse3 { } {
8886 return [check_no_compiler_messages ssse3 object {
8887 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8888 typedef int __v4si __attribute__ ((__vector_size__ (16)));
8889
8890 __m128i _mm_abs_epi32 (__m128i __X)
8891 {
8892 return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
8893 }
8894 } "-O2 -mssse3" ]
8895 }
8896
8897 # Return 1 if aes instructions can be compiled.
8898 proc check_effective_target_aes { } {
8899 return [check_no_compiler_messages aes object {
8900 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8901 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
8902
8903 __m128i _mm_aesimc_si128 (__m128i __X)
8904 {
8905 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
8906 }
8907 } "-O2 -maes" ]
8908 }
8909
8910 # Return 1 if vaes instructions can be compiled.
8911 proc check_effective_target_vaes { } {
8912 return [check_no_compiler_messages vaes object {
8913 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8914 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
8915
8916 __m128i _mm_aesimc_si128 (__m128i __X)
8917 {
8918 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
8919 }
8920 } "-O2 -maes -mavx" ]
8921 }
8922
8923 # Return 1 if pclmul instructions can be compiled.
8924 proc check_effective_target_pclmul { } {
8925 return [check_no_compiler_messages pclmul object {
8926 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8927 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
8928
8929 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
8930 {
8931 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
8932 (__v2di)__Y,
8933 1);
8934 }
8935 } "-O2 -mpclmul" ]
8936 }
8937
8938 # Return 1 if vpclmul instructions can be compiled.
8939 proc check_effective_target_vpclmul { } {
8940 return [check_no_compiler_messages vpclmul object {
8941 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8942 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
8943
8944 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
8945 {
8946 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
8947 (__v2di)__Y,
8948 1);
8949 }
8950 } "-O2 -mpclmul -mavx" ]
8951 }
8952
8953 # Return 1 if sse4a instructions can be compiled.
8954 proc check_effective_target_sse4a { } {
8955 return [check_no_compiler_messages sse4a object {
8956 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8957 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
8958
8959 __m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
8960 {
8961 return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
8962 }
8963 } "-O2 -msse4a" ]
8964 }
8965
8966 # Return 1 if fma4 instructions can be compiled.
8967 proc check_effective_target_fma4 { } {
8968 return [check_no_compiler_messages fma4 object {
8969 typedef float __m128 __attribute__ ((__vector_size__ (16)));
8970 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
8971 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
8972 {
8973 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
8974 (__v4sf)__B,
8975 (__v4sf)__C);
8976 }
8977 } "-O2 -mfma4" ]
8978 }
8979
8980 # Return 1 if fma instructions can be compiled.
8981 proc check_effective_target_fma { } {
8982 return [check_no_compiler_messages fma object {
8983 typedef float __m128 __attribute__ ((__vector_size__ (16)));
8984 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
8985 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
8986 {
8987 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
8988 (__v4sf)__B,
8989 (__v4sf)__C);
8990 }
8991 } "-O2 -mfma" ]
8992 }
8993
8994 # Return 1 if xop instructions can be compiled.
8995 proc check_effective_target_xop { } {
8996 return [check_no_compiler_messages xop object {
8997 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
8998 typedef short __v8hi __attribute__ ((__vector_size__ (16)));
8999 __m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
9000 {
9001 return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
9002 (__v8hi)__B,
9003 (__v8hi)__C);
9004 }
9005 } "-O2 -mxop" ]
9006 }
9007
9008 # Return 1 if lzcnt instruction can be compiled.
9009 proc check_effective_target_lzcnt { } {
9010 return [check_no_compiler_messages lzcnt object {
9011 unsigned short _lzcnt (unsigned short __X)
9012 {
9013 return __builtin_clzs (__X);
9014 }
9015 } "-mlzcnt" ]
9016 }
9017
9018 # Return 1 if bmi instructions can be compiled.
9019 proc check_effective_target_bmi { } {
9020 return [check_no_compiler_messages bmi object {
9021 unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
9022 {
9023 return __builtin_ia32_bextr_u32 (__X, __Y);
9024 }
9025 } "-mbmi" ]
9026 }
9027
9028 # Return 1 if ADX instructions can be compiled.
9029 proc check_effective_target_adx { } {
9030 return [check_no_compiler_messages adx object {
9031 unsigned char
9032 _adxcarry_u32 (unsigned char __CF, unsigned int __X,
9033 unsigned int __Y, unsigned int *__P)
9034 {
9035 return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
9036 }
9037 } "-madx" ]
9038 }
9039
9040 # Return 1 if rtm instructions can be compiled.
9041 proc check_effective_target_rtm { } {
9042 return [check_no_compiler_messages rtm object {
9043 void
9044 _rtm_xend (void)
9045 {
9046 return __builtin_ia32_xend ();
9047 }
9048 } "-mrtm" ]
9049 }
9050
9051 # Return 1 if avx512vl instructions can be compiled.
9052 proc check_effective_target_avx512vl { } {
9053 return [check_no_compiler_messages avx512vl object {
9054 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
9055 __v4di
9056 mm256_and_epi64 (__v4di __X, __v4di __Y)
9057 {
9058 __v4di __W;
9059 return __builtin_ia32_pandq256_mask (__X, __Y, __W, -1);
9060 }
9061 } "-mavx512vl" ]
9062 }
9063
9064 # Return 1 if avx512cd instructions can be compiled.
9065 proc check_effective_target_avx512cd { } {
9066 return [check_no_compiler_messages avx512cd_trans object {
9067 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
9068 __v8di
9069 _mm512_conflict_epi64 (__v8di __W, __v8di __A)
9070 {
9071 return (__v8di) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A,
9072 (__v8di) __W,
9073 -1);
9074 }
9075 } "-Wno-psabi -mavx512cd" ]
9076 }
9077
9078 # Return 1 if avx512er instructions can be compiled.
9079 proc check_effective_target_avx512er { } {
9080 return [check_no_compiler_messages avx512er_trans object {
9081 typedef float __v16sf __attribute__ ((__vector_size__ (64)));
9082 __v16sf
9083 mm512_exp2a23_ps (__v16sf __X)
9084 {
9085 return __builtin_ia32_exp2ps_mask (__X, __X, -1, 4);
9086 }
9087 } "-Wno-psabi -mavx512er" ]
9088 }
9089
9090 # Return 1 if sha instructions can be compiled.
9091 proc check_effective_target_sha { } {
9092 return [check_no_compiler_messages sha object {
9093 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
9094 typedef int __v4si __attribute__ ((__vector_size__ (16)));
9095
9096 __m128i _mm_sha1msg1_epu32 (__m128i __X, __m128i __Y)
9097 {
9098 return (__m128i) __builtin_ia32_sha1msg1 ((__v4si)__X,
9099 (__v4si)__Y);
9100 }
9101 } "-O2 -msha" ]
9102 }
9103
9104 # Return 1 if avx512dq instructions can be compiled.
9105 proc check_effective_target_avx512dq { } {
9106 return [check_no_compiler_messages avx512dq object {
9107 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
9108 __v8di
9109 _mm512_mask_mullo_epi64 (__v8di __W, __v8di __A, __v8di __B)
9110 {
9111 return (__v8di) __builtin_ia32_pmullq512_mask ((__v8di) __A,
9112 (__v8di) __B,
9113 (__v8di) __W,
9114 -1);
9115 }
9116 } "-mavx512dq" ]
9117 }
9118
9119 # Return 1 if avx512bw instructions can be compiled.
9120 proc check_effective_target_avx512bw { } {
9121 return [check_no_compiler_messages avx512bw object {
9122 typedef short __v32hi __attribute__ ((__vector_size__ (64)));
9123 __v32hi
9124 _mm512_mask_mulhrs_epi16 (__v32hi __W, __v32hi __A, __v32hi __B)
9125 {
9126 return (__v32hi) __builtin_ia32_pmulhrsw512_mask ((__v32hi) __A,
9127 (__v32hi) __B,
9128 (__v32hi) __W,
9129 -1);
9130 }
9131 } "-mavx512bw" ]
9132 }
9133
9134 # Return 1 if -Wa,-march=+noavx512bw is supported.
9135 proc check_effective_target_assembler_march_noavx512bw {} {
9136 if { [istarget i?86*-*-*] || [istarget x86_64*-*-*] } {
9137 return [check_no_compiler_messages assembler_march_noavx512bw object {
9138 void foo (void) {}
9139 } "-mno-avx512bw -Wa,-march=+noavx512bw"]
9140 }
9141 return 0
9142 }
9143
9144 # Return 1 if avx512vp2intersect instructions can be compiled.
9145 proc check_effective_target_avx512vp2intersect { } {
9146 return [check_no_compiler_messages avx512vp2intersect object {
9147 typedef int __v16si __attribute__ ((__vector_size__ (64)));
9148 typedef short __mmask16;
9149 void
9150 _mm512_2intersect_epi32 (__v16si __A, __v16si __B, __mmask16 *__U,
9151 __mmask16 *__M)
9152 {
9153 __builtin_ia32_2intersectd512 (__U, __M, (__v16si) __A, (__v16si) __B);
9154 }
9155 } "-mavx512vp2intersect" ]
9156 }
9157
9158 # Return 1 if avx512ifma instructions can be compiled.
9159 proc check_effective_target_avx512ifma { } {
9160 return [check_no_compiler_messages avx512ifma object {
9161 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
9162 __v8di
9163 _mm512_madd52lo_epu64 (__v8di __X, __v8di __Y, __v8di __Z)
9164 {
9165 return (__v8di) __builtin_ia32_vpmadd52luq512_mask ((__v8di) __X,
9166 (__v8di) __Y,
9167 (__v8di) __Z,
9168 -1);
9169 }
9170 } "-mavx512ifma" ]
9171 }
9172
9173 # Return 1 if avx512vbmi instructions can be compiled.
9174 proc check_effective_target_avx512vbmi { } {
9175 return [check_no_compiler_messages avx512vbmi object {
9176 typedef char __v64qi __attribute__ ((__vector_size__ (64)));
9177 __v64qi
9178 _mm512_multishift_epi64_epi8 (__v64qi __X, __v64qi __Y)
9179 {
9180 return (__v64qi) __builtin_ia32_vpmultishiftqb512_mask ((__v64qi) __X,
9181 (__v64qi) __Y,
9182 (__v64qi) __Y,
9183 -1);
9184 }
9185 } "-mavx512vbmi" ]
9186 }
9187
9188 # Return 1 if avx512_4fmaps instructions can be compiled.
9189 proc check_effective_target_avx5124fmaps { } {
9190 return [check_no_compiler_messages avx5124fmaps object {
9191 typedef float __v16sf __attribute__ ((__vector_size__ (64)));
9192 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
9193
9194 __v16sf
9195 _mm512_mask_4fmadd_ps (__v16sf __DEST, __v16sf __A, __v16sf __B, __v16sf __C,
9196 __v16sf __D, __v16sf __E, __v4sf *__F)
9197 {
9198 return (__v16sf) __builtin_ia32_4fmaddps_mask ((__v16sf) __A,
9199 (__v16sf) __B,
9200 (__v16sf) __C,
9201 (__v16sf) __D,
9202 (__v16sf) __E,
9203 (const __v4sf *) __F,
9204 (__v16sf) __DEST,
9205 0xffff);
9206 }
9207 } "-mavx5124fmaps" ]
9208 }
9209
9210 # Return 1 if avx512_4vnniw instructions can be compiled.
9211 proc check_effective_target_avx5124vnniw { } {
9212 return [check_no_compiler_messages avx5124vnniw object {
9213 typedef int __v16si __attribute__ ((__vector_size__ (64)));
9214 typedef int __v4si __attribute__ ((__vector_size__ (16)));
9215
9216 __v16si
9217 _mm512_4dpwssd_epi32 (__v16si __A, __v16si __B, __v16si __C,
9218 __v16si __D, __v16si __E, __v4si *__F)
9219 {
9220 return (__v16si) __builtin_ia32_vp4dpwssd ((__v16si) __B,
9221 (__v16si) __C,
9222 (__v16si) __D,
9223 (__v16si) __E,
9224 (__v16si) __A,
9225 (const __v4si *) __F);
9226 }
9227 } "-mavx5124vnniw" ]
9228 }
9229
9230 # Return 1 if avx512_vpopcntdq instructions can be compiled.
9231 proc check_effective_target_avx512vpopcntdq { } {
9232 return [check_no_compiler_messages avx512vpopcntdq object {
9233 typedef int __v16si __attribute__ ((__vector_size__ (64)));
9234
9235 __v16si
9236 _mm512_popcnt_epi32 (__v16si __A)
9237 {
9238 return (__v16si) __builtin_ia32_vpopcountd_v16si ((__v16si) __A);
9239 }
9240 } "-mavx512vpopcntdq" ]
9241 }
9242
9243 # Return 1 if 128 or 256-bit avx512_vpopcntdq instructions can be compiled.
9244 proc check_effective_target_avx512vpopcntdqvl { } {
9245 return [check_no_compiler_messages avx512vpopcntdqvl object {
9246 typedef int __v8si __attribute__ ((__vector_size__ (32)));
9247
9248 __v8si
9249 _mm256_popcnt_epi32 (__v8si __A)
9250 {
9251 return (__v8si) __builtin_ia32_vpopcountd_v8si ((__v8si) __A);
9252 }
9253 } "-mavx512vpopcntdq -mavx512vl" ]
9254 }
9255
9256 # Return 1 if gfni instructions can be compiled.
9257 proc check_effective_target_gfni { } {
9258 return [check_no_compiler_messages gfni object {
9259 typedef char __v16qi __attribute__ ((__vector_size__ (16)));
9260
9261 __v16qi
9262 _mm_gf2p8affineinv_epi64_epi8 (__v16qi __A, __v16qi __B, const int __C)
9263 {
9264 return (__v16qi) __builtin_ia32_vgf2p8affineinvqb_v16qi ((__v16qi) __A,
9265 (__v16qi) __B,
9266 0);
9267 }
9268 } "-mgfni" ]
9269 }
9270
9271 # Return 1 if avx512vbmi2 instructions can be compiled.
9272 proc check_effective_target_avx512vbmi2 { } {
9273 return [check_no_compiler_messages avx512vbmi2 object {
9274 typedef char __v16qi __attribute__ ((__vector_size__ (16)));
9275 typedef unsigned long long __mmask16;
9276
9277 __v16qi
9278 _mm_mask_compress_epi8 (__v16qi __A, __mmask16 __B, __v16qi __C)
9279 {
9280 return (__v16qi) __builtin_ia32_compressqi128_mask((__v16qi)__C,
9281 (__v16qi)__A,
9282 (__mmask16)__B);
9283 }
9284 } "-mavx512vbmi2 -mavx512vl" ]
9285 }
9286
9287 # Return 1 if avx512vbmi2 instructions can be compiled.
9288 proc check_effective_target_avx512vnni { } {
9289 return [check_no_compiler_messages avx512vnni object {
9290 typedef int __v16si __attribute__ ((__vector_size__ (64)));
9291
9292 __v16si
9293 _mm_mask_compress_epi8 (__v16si __A, __v16si __B, __v16si __C)
9294 {
9295 return (__v16si) __builtin_ia32_vpdpbusd_v16si ((__v16si)__A,
9296 (__v16si)__B,
9297 (__v16si)__C);
9298 }
9299 } "-mavx512vnni -mavx512f" ]
9300 }
9301
9302 # Return 1 if vaes instructions can be compiled.
9303 proc check_effective_target_avx512vaes { } {
9304 return [check_no_compiler_messages avx512vaes object {
9305
9306 typedef int __v16si __attribute__ ((__vector_size__ (64)));
9307
9308 __v32qi
9309 _mm256_aesdec_epi128 (__v32qi __A, __v32qi __B)
9310 {
9311 return (__v32qi)__builtin_ia32_vaesdec_v32qi ((__v32qi) __A, (__v32qi) __B);
9312 }
9313 } "-mvaes" ]
9314 }
9315
9316 # Return 1 if amx-tile instructions can be compiled.
9317 proc check_effective_target_amx_tile { } {
9318 return [check_no_compiler_messages amx_tile object {
9319 void
9320 foo ()
9321 {
9322 __asm__ volatile ("tilerelease" ::);
9323 }
9324 } "-mamx-tile" ]
9325 }
9326
9327 # Return 1 if amx-int8 instructions can be compiled.
9328 proc check_effective_target_amx_int8 { } {
9329 return [check_no_compiler_messages amx_int8 object {
9330 void
9331 foo ()
9332 {
9333 __asm__ volatile ("tdpbssd\t%%tmm1, %%tmm2, %%tmm3" ::);
9334 }
9335 } "-mamx-int8" ]
9336 }
9337
9338 # Return 1 if amx-bf16 instructions can be compiled.
9339 proc check_effective_target_amx_bf16 { } {
9340 return [check_no_compiler_messages amx_bf16 object {
9341 void
9342 foo ()
9343 {
9344 __asm__ volatile ("tdpbf16ps\t%%tmm1, %%tmm2, %%tmm3" ::);
9345 }
9346 } "-mamx-bf16" ]
9347 }
9348
9349 # Return 1 if vpclmulqdq instructions can be compiled.
9350 proc check_effective_target_vpclmulqdq { } {
9351 return [check_no_compiler_messages vpclmulqdq object {
9352 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
9353
9354 __v4di
9355 _mm256_clmulepi64_epi128 (__v4di __A, __v4di __B)
9356 {
9357 return (__v4di) __builtin_ia32_vpclmulqdq_v4di (__A, __B, 0);
9358 }
9359 } "-mvpclmulqdq -mavx512vl" ]
9360 }
9361
9362 # Return 1 if avx512_bitalg instructions can be compiled.
9363 proc check_effective_target_avx512bitalg { } {
9364 return [check_no_compiler_messages avx512bitalg object {
9365 typedef short int __v32hi __attribute__ ((__vector_size__ (64)));
9366
9367 __v32hi
9368 _mm512_popcnt_epi16 (__v32hi __A)
9369 {
9370 return (__v32hi) __builtin_ia32_vpopcountw_v32hi ((__v32hi) __A);
9371 }
9372 } "-mavx512bitalg" ]
9373 }
9374
9375 # Return 1 if C wchar_t type is compatible with char16_t.
9376
9377 proc check_effective_target_wchar_t_char16_t_compatible { } {
9378 return [check_no_compiler_messages wchar_t_char16_t object {
9379 __WCHAR_TYPE__ wc;
9380 __CHAR16_TYPE__ *p16 = &wc;
9381 char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
9382 }]
9383 }
9384
9385 # Return 1 if C wchar_t type is compatible with char32_t.
9386
9387 proc check_effective_target_wchar_t_char32_t_compatible { } {
9388 return [check_no_compiler_messages wchar_t_char32_t object {
9389 __WCHAR_TYPE__ wc;
9390 __CHAR32_TYPE__ *p32 = &wc;
9391 char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
9392 }]
9393 }
9394
9395 # Return 1 if pow10 function exists.
9396
9397 proc check_effective_target_pow10 { } {
9398 return [check_runtime pow10 {
9399 #include <math.h>
9400 int main () {
9401 double x;
9402 x = pow10 (1);
9403 return 0;
9404 }
9405 } "-lm" ]
9406 }
9407
9408 # Return 1 if frexpl function exists.
9409
9410 proc check_effective_target_frexpl { } {
9411 return [check_runtime frexpl {
9412 #include <math.h>
9413 int main () {
9414 long double x;
9415 int y;
9416 x = frexpl (5.0, &y);
9417 return 0;
9418 }
9419 } "-lm" ]
9420 }
9421
9422
9423 # Return 1 if issignaling function exists.
9424 proc check_effective_target_issignaling {} {
9425 return [check_runtime issignaling {
9426 #define _GNU_SOURCE
9427 #include <math.h>
9428 int main ()
9429 {
9430 return issignaling (0.0);
9431 }
9432 } "-lm" ]
9433 }
9434
9435 # Return 1 if current options generate DFP instructions, 0 otherwise.
9436 proc check_effective_target_hard_dfp {} {
9437 return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
9438 typedef float d64 __attribute__((mode(DD)));
9439 d64 x, y, z;
9440 void foo (void) { z = x + y; }
9441 }]
9442 }
9443
9444 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
9445 # for strchr etc. functions.
9446
9447 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
9448 return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
9449 #include <string.h>
9450 #include <wchar.h>
9451 #if !defined(__cplusplus) \
9452 || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
9453 || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
9454 ISO C++ correct string.h and wchar.h protos not supported.
9455 #else
9456 int i;
9457 #endif
9458 }]
9459 }
9460
9461 # Return 1 if GNU as is used.
9462
9463 proc check_effective_target_gas { } {
9464 global use_gas_saved
9465 global tool
9466
9467 if {![info exists use_gas_saved]} {
9468 # Check if the as used by gcc is GNU as.
9469 set options [list "additional_flags=-print-prog-name=as"]
9470 set gcc_as [lindex [${tool}_target_compile "" "" "none" $options] 0]
9471 # Provide /dev/null as input, otherwise gas times out reading from
9472 # stdin.
9473 set status [remote_exec host "$gcc_as" "-v /dev/null"]
9474 set as_output [lindex $status 1]
9475 if { [ string first "GNU" $as_output ] >= 0 } {
9476 set use_gas_saved 1
9477 } else {
9478 set use_gas_saved 0
9479 }
9480 }
9481 return $use_gas_saved
9482 }
9483
9484 # Return 1 if GNU ld is used.
9485
9486 proc check_effective_target_gld { } {
9487 global use_gld_saved
9488 global tool
9489
9490 if {![info exists use_gld_saved]} {
9491 # Check if the ld used by gcc is GNU ld.
9492 set options [list "additional_flags=-print-prog-name=ld"]
9493 set gcc_ld [lindex [${tool}_target_compile "" "" "none" $options] 0]
9494 set status [remote_exec host "$gcc_ld" "--version"]
9495 set ld_output [lindex $status 1]
9496 if { [ string first "GNU" $ld_output ] >= 0 } {
9497 set use_gld_saved 1
9498 } else {
9499 set use_gld_saved 0
9500 }
9501 }
9502 return $use_gld_saved
9503 }
9504
9505 # Return 1 if the compiler has been configure with link-time optimization
9506 # (LTO) support.
9507
9508 proc check_effective_target_lto { } {
9509 if { [istarget *-*-vxworks*] } {
9510 # No LTO on VxWorks, with kernel modules
9511 # built with partial links
9512 return 0
9513 }
9514 if { [istarget nvptx-*-*]
9515 || [istarget amdgcn-*-*] } {
9516 return 0;
9517 }
9518 return [check_no_compiler_messages lto object {
9519 void foo (void) { }
9520 } "-flto"]
9521 }
9522
9523 # Return 1 if the compiler and linker support incremental link-time
9524 # optimization.
9525
9526 proc check_effective_target_lto_incremental { } {
9527 if ![check_effective_target_lto] {
9528 return 0
9529 }
9530 return [check_no_compiler_messages lto_incremental executable {
9531 int main () { return 0; }
9532 } "-flto -r -nostdlib"]
9533 }
9534
9535 # Return 1 if the compiler has been configured with analyzer support.
9536
9537 proc check_effective_target_analyzer { } {
9538 return [check_no_compiler_messages analyzer object {
9539 void foo (void) { }
9540 } "-fanalyzer"]
9541 }
9542
9543 # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
9544
9545 proc check_effective_target_maybe_x32 { } {
9546 return [check_no_compiler_messages maybe_x32 object {
9547 void foo (void) {}
9548 } "-mx32 -maddress-mode=short"]
9549 }
9550
9551 # Return 1 if this target supports the -fsplit-stack option, 0
9552 # otherwise.
9553
9554 proc check_effective_target_split_stack {} {
9555 return [check_no_compiler_messages split_stack object {
9556 void foo (void) { }
9557 } "-fsplit-stack"]
9558 }
9559
9560 # Return 1 if this target supports the -masm=intel option, 0
9561 # otherwise
9562
9563 proc check_effective_target_masm_intel {} {
9564 return [check_no_compiler_messages masm_intel object {
9565 extern void abort (void);
9566 } "-masm=intel"]
9567 }
9568
9569 # Return 1 if the language for the compiler under test is C.
9570
9571 proc check_effective_target_c { } {
9572 global tool
9573 if [string match $tool "gcc"] {
9574 return 1
9575 }
9576 return 0
9577 }
9578
9579 # Return 1 if the language for the compiler under test is C++.
9580
9581 proc check_effective_target_c++ { } {
9582 global tool
9583 if { [string match $tool "g++"] || [string match $tool "libstdc++"] } {
9584 return 1
9585 }
9586 return 0
9587 }
9588
9589 set cxx_default "c++17"
9590 # Check whether the current active language standard supports the features
9591 # of C++11/C++14 by checking for the presence of one of the -std flags.
9592 # This assumes that the default for the compiler is $cxx_default, and that
9593 # there will never be multiple -std= arguments on the command line.
9594 proc check_effective_target_c++11_only { } {
9595 global cxx_default
9596 if ![check_effective_target_c++] {
9597 return 0
9598 }
9599 if [check-flags { { } { } { -std=c++0x -std=gnu++0x -std=c++11 -std=gnu++11 } }] {
9600 return 1
9601 }
9602 if { $cxx_default == "c++11" && [check-flags { { } { } { } { -std=* } }] } {
9603 return 1
9604 }
9605 return 0
9606 }
9607 proc check_effective_target_c++11 { } {
9608 if [check_effective_target_c++11_only] {
9609 return 1
9610 }
9611 return [check_effective_target_c++14]
9612 }
9613 proc check_effective_target_c++11_down { } {
9614 if ![check_effective_target_c++] {
9615 return 0
9616 }
9617 return [expr ![check_effective_target_c++14] ]
9618 }
9619
9620 proc check_effective_target_c++14_only { } {
9621 global cxx_default
9622 if ![check_effective_target_c++] {
9623 return 0
9624 }
9625 if [check-flags { { } { } { -std=c++14 -std=gnu++14 -std=c++14 -std=gnu++14 } }] {
9626 return 1
9627 }
9628 if { $cxx_default == "c++14" && [check-flags { { } { } { } { -std=* } }] } {
9629 return 1
9630 }
9631 return 0
9632 }
9633
9634 proc check_effective_target_c++14 { } {
9635 if [check_effective_target_c++14_only] {
9636 return 1
9637 }
9638 return [check_effective_target_c++17]
9639 }
9640 proc check_effective_target_c++14_down { } {
9641 if ![check_effective_target_c++] {
9642 return 0
9643 }
9644 return [expr ![check_effective_target_c++17] ]
9645 }
9646
9647 proc check_effective_target_c++98_only { } {
9648 global cxx_default
9649 if ![check_effective_target_c++] {
9650 return 0
9651 }
9652 if [check-flags { { } { } { -std=c++98 -std=gnu++98 -std=c++03 -std=gnu++03 } }] {
9653 return 1
9654 }
9655 if { $cxx_default == "c++98" && [check-flags { { } { } { } { -std=* } }] } {
9656 return 1
9657 }
9658 return 0
9659 }
9660
9661 proc check_effective_target_c++17_only { } {
9662 global cxx_default
9663 if ![check_effective_target_c++] {
9664 return 0
9665 }
9666 if [check-flags { { } { } { -std=c++17 -std=gnu++17 -std=c++1z -std=gnu++1z } }] {
9667 return 1
9668 }
9669 if { $cxx_default == "c++17" && [check-flags { { } { } { } { -std=* } }] } {
9670 return 1
9671 }
9672 return 0
9673 }
9674
9675 proc check_effective_target_c++17 { } {
9676 if [check_effective_target_c++17_only] {
9677 return 1
9678 }
9679 return [check_effective_target_c++2a]
9680 }
9681 proc check_effective_target_c++17_down { } {
9682 if ![check_effective_target_c++] {
9683 return 0
9684 }
9685 return [expr ![check_effective_target_c++2a] ]
9686 }
9687
9688 proc check_effective_target_c++2a_only { } {
9689 global cxx_default
9690 if ![check_effective_target_c++] {
9691 return 0
9692 }
9693 if [check-flags { { } { } { -std=c++2a -std=gnu++2a -std=c++20 -std=gnu++20 } }] {
9694 return 1
9695 }
9696 if { $cxx_default == "c++20" && [check-flags { { } { } { } { -std=* } }] } {
9697 return 1
9698 }
9699 return 0
9700 }
9701 proc check_effective_target_c++2a { } {
9702 if [check_effective_target_c++2a_only] {
9703 return 1
9704 }
9705 return [check_effective_target_c++23]
9706 }
9707
9708 proc check_effective_target_c++20_only { } {
9709 return [check_effective_target_c++2a_only]
9710 }
9711
9712 proc check_effective_target_c++20 { } {
9713 return [check_effective_target_c++2a]
9714 }
9715 proc check_effective_target_c++20_down { } {
9716 if ![check_effective_target_c++] {
9717 return 0
9718 }
9719 return [expr ![check_effective_target_c++23] ]
9720 }
9721
9722 proc check_effective_target_c++23_only { } {
9723 global cxx_default
9724 if ![check_effective_target_c++] {
9725 return 0
9726 }
9727 if [check-flags { { } { } { -std=c++23 -std=gnu++23 -std=c++2b -std=gnu++2b } }] {
9728 return 1
9729 }
9730 if { $cxx_default == "c++23" && [check-flags { { } { } { } { -std=* } }] } {
9731 return 1
9732 }
9733 return 0
9734 }
9735 proc check_effective_target_c++23 { } {
9736 return [check_effective_target_c++23_only]
9737 }
9738
9739 # Check for C++ Concepts support, i.e. -fconcepts flag.
9740 proc check_effective_target_concepts { } {
9741 if [check_effective_target_c++2a] {
9742 return 1
9743 }
9744 return [check-flags { "" { } { -fconcepts } }]
9745 }
9746
9747 # Return 1 if expensive testcases should be run.
9748
9749 proc check_effective_target_run_expensive_tests { } {
9750 if { [getenv GCC_TEST_RUN_EXPENSIVE] != "" } {
9751 return 1
9752 }
9753 return 0
9754 }
9755
9756 # Returns 1 if "mempcpy" is available on the target system.
9757
9758 proc check_effective_target_mempcpy {} {
9759 if { [istarget *-*-vxworks*] } {
9760 # VxWorks doesn't have mempcpy but our way to test fails
9761 # to detect as we're doing partial links for kernel modules.
9762 return 0
9763 }
9764 return [check_function_available "mempcpy"]
9765 }
9766
9767 # Returns 1 if "stpcpy" is available on the target system.
9768
9769 proc check_effective_target_stpcpy {} {
9770 return [check_function_available "stpcpy"]
9771 }
9772
9773 # Returns 1 if "sigsetjmp" is available on the target system.
9774 # Also check if "__sigsetjmp" is defined since that's what glibc
9775 # uses.
9776
9777 proc check_effective_target_sigsetjmp {} {
9778 if { [check_function_available "sigsetjmp"]
9779 || [check_function_available "__sigsetjmp"] } {
9780 return 1
9781 }
9782 return 0
9783 }
9784
9785 # Check whether the vectorizer tests are supported by the target and
9786 # append additional target-dependent compile flags to DEFAULT_VECTCFLAGS.
9787 # If a port wants to execute the tests more than once it should append
9788 # the supported target to EFFECTIVE_TARGETS instead, and the compile flags
9789 # will be added by a call to add_options_for_<target>.
9790 # Set dg-do-what-default to either compile or run, depending on target
9791 # capabilities. Do not set this if the supported target is appended to
9792 # EFFECTIVE_TARGETS. Flags and this variable will be set by et-dg-runtest
9793 # automatically. Return the number of effective targets if vectorizer tests
9794 # are supported, 0 otherwise.
9795
9796 proc check_vect_support_and_set_flags { } {
9797 global DEFAULT_VECTCFLAGS
9798 global dg-do-what-default
9799 global EFFECTIVE_TARGETS
9800
9801 if [istarget powerpc-*paired*] {
9802 lappend DEFAULT_VECTCFLAGS "-mpaired"
9803 if [check_750cl_hw_available] {
9804 set dg-do-what-default run
9805 } else {
9806 set dg-do-what-default compile
9807 }
9808 } elseif [istarget powerpc*-*-*] {
9809 # Skip targets not supporting -maltivec.
9810 if ![is-effective-target powerpc_altivec_ok] {
9811 return 0
9812 }
9813
9814 lappend DEFAULT_VECTCFLAGS "-maltivec"
9815 if [check_p9vector_hw_available] {
9816 lappend DEFAULT_VECTCFLAGS "-mpower9-vector"
9817 } elseif [check_p8vector_hw_available] {
9818 lappend DEFAULT_VECTCFLAGS "-mpower8-vector"
9819 } elseif [check_vsx_hw_available] {
9820 lappend DEFAULT_VECTCFLAGS "-mvsx" "-mno-allow-movmisalign"
9821 }
9822
9823 if [check_vmx_hw_available] {
9824 set dg-do-what-default run
9825 } else {
9826 if [is-effective-target ilp32] {
9827 # Specify a cpu that supports VMX for compile-only tests.
9828 lappend DEFAULT_VECTCFLAGS "-mcpu=970"
9829 }
9830 set dg-do-what-default compile
9831 }
9832 } elseif { [istarget i?86-*-*] || [istarget x86_64-*-*] } {
9833 lappend DEFAULT_VECTCFLAGS "-msse2"
9834 if { [check_effective_target_sse2_runtime] } {
9835 set dg-do-what-default run
9836 } else {
9837 set dg-do-what-default compile
9838 }
9839 } elseif { [istarget mips*-*-*]
9840 && [check_effective_target_nomips16] } {
9841 if { [check_effective_target_mpaired_single] } {
9842 lappend EFFECTIVE_TARGETS mpaired_single
9843 }
9844 if { [check_effective_target_mips_loongson_mmi] } {
9845 lappend EFFECTIVE_TARGETS mips_loongson_mmi
9846 }
9847 if { [check_effective_target_mips_msa] } {
9848 lappend EFFECTIVE_TARGETS mips_msa
9849 }
9850 return [llength $EFFECTIVE_TARGETS]
9851 } elseif [istarget sparc*-*-*] {
9852 lappend DEFAULT_VECTCFLAGS "-mcpu=ultrasparc" "-mvis"
9853 if [check_effective_target_ultrasparc_hw] {
9854 set dg-do-what-default run
9855 } else {
9856 set dg-do-what-default compile
9857 }
9858 } elseif [istarget alpha*-*-*] {
9859 # Alpha's vectorization capabilities are extremely limited.
9860 # It's more effort than its worth disabling all of the tests
9861 # that it cannot pass. But if you actually want to see what
9862 # does work, command out the return.
9863 return 0
9864
9865 lappend DEFAULT_VECTCFLAGS "-mmax"
9866 if [check_alpha_max_hw_available] {
9867 set dg-do-what-default run
9868 } else {
9869 set dg-do-what-default compile
9870 }
9871 } elseif [istarget ia64-*-*] {
9872 set dg-do-what-default run
9873 } elseif [is-effective-target arm_neon_ok] {
9874 eval lappend DEFAULT_VECTCFLAGS [add_options_for_arm_neon ""]
9875 # NEON does not support denormals, so is not used for vectorization by
9876 # default to avoid loss of precision. We must pass -ffast-math to test
9877 # vectorization of float operations.
9878 lappend DEFAULT_VECTCFLAGS "-ffast-math"
9879 if [is-effective-target arm_neon_hw] {
9880 set dg-do-what-default run
9881 } else {
9882 set dg-do-what-default compile
9883 }
9884 } elseif [istarget "aarch64*-*-*"] {
9885 set dg-do-what-default run
9886 } elseif [istarget s390*-*-*] {
9887 # The S/390 backend set a default of 2 for that value.
9888 # Override it to have the same situation as with other
9889 # targets.
9890 lappend DEFAULT_VECTCFLAGS "--param" "min-vect-loop-bound=1"
9891 lappend DEFAULT_VECTCFLAGS "--param" "max-unrolled-insns=200"
9892 lappend DEFAULT_VECTCFLAGS "--param" "max-unroll-times=8"
9893 lappend DEFAULT_VECTCFLAGS "--param" "max-completely-peeled-insns=200"
9894 lappend DEFAULT_VECTCFLAGS "--param" "max-completely-peel-times=16"
9895 if [check_effective_target_s390_vxe2] {
9896 lappend DEFAULT_VECTCFLAGS "-march=z15" "-mzarch"
9897 set dg-do-what-default run
9898 } elseif [check_effective_target_s390_vxe] {
9899 lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch"
9900 set dg-do-what-default run
9901 } elseif [check_effective_target_s390_vx] {
9902 lappend DEFAULT_VECTCFLAGS "-march=z13" "-mzarch"
9903 set dg-do-what-default run
9904 } else {
9905 lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch"
9906 set dg-do-what-default compile
9907 }
9908 } elseif [istarget amdgcn-*-*] {
9909 set dg-do-what-default run
9910 } else {
9911 return 0
9912 }
9913
9914 return 1
9915 }
9916
9917 # Return 1 if the target does *not* require strict alignment.
9918
9919 proc check_effective_target_non_strict_align {} {
9920
9921 # On ARM, the default is to use STRICT_ALIGNMENT, but there
9922 # are interfaces defined for misaligned access and thus
9923 # depending on the architecture levels unaligned access is
9924 # available.
9925 if [istarget "arm*-*-*"] {
9926 return [check_effective_target_arm_unaligned]
9927 }
9928
9929 return [check_no_compiler_messages non_strict_align assembly {
9930 char *y;
9931 typedef char __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) c;
9932 c *z;
9933 void foo(void) { z = (c *) y; }
9934 } "-Wcast-align"]
9935 }
9936
9937 # Return 1 if the target has <ucontext.h>.
9938
9939 proc check_effective_target_ucontext_h { } {
9940 return [check_no_compiler_messages ucontext_h assembly {
9941 #include <ucontext.h>
9942 }]
9943 }
9944
9945 proc check_effective_target_aarch64_tiny { } {
9946 if { [istarget aarch64*-*-*] } {
9947 return [check_no_compiler_messages aarch64_tiny object {
9948 #ifdef __AARCH64_CMODEL_TINY__
9949 int dummy;
9950 #else
9951 #error target not AArch64 tiny code model
9952 #endif
9953 }]
9954 } else {
9955 return 0
9956 }
9957 }
9958
9959 # Create functions to check that the AArch64 assembler supports the
9960 # various architecture extensions via the .arch_extension pseudo-op.
9961
9962 foreach { aarch64_ext } { "fp" "simd" "crypto" "crc" "lse" "dotprod" "sve"
9963 "i8mm" "f32mm" "f64mm" "bf16" "sb" "sve2" } {
9964 eval [string map [list FUNC $aarch64_ext] {
9965 proc check_effective_target_aarch64_asm_FUNC_ok { } {
9966 if { [istarget aarch64*-*-*] } {
9967 return [check_no_compiler_messages aarch64_FUNC_assembler object {
9968 __asm__ (".arch_extension FUNC");
9969 } "-march=armv8-a+FUNC"]
9970 } else {
9971 return 0
9972 }
9973 }
9974 }]
9975 }
9976
9977 proc check_effective_target_aarch64_small { } {
9978 if { [istarget aarch64*-*-*] } {
9979 return [check_no_compiler_messages aarch64_small object {
9980 #ifdef __AARCH64_CMODEL_SMALL__
9981 int dummy;
9982 #else
9983 #error target not AArch64 small code model
9984 #endif
9985 }]
9986 } else {
9987 return 0
9988 }
9989 }
9990
9991 proc check_effective_target_aarch64_large { } {
9992 if { [istarget aarch64*-*-*] } {
9993 return [check_no_compiler_messages aarch64_large object {
9994 #ifdef __AARCH64_CMODEL_LARGE__
9995 int dummy;
9996 #else
9997 #error target not AArch64 large code model
9998 #endif
9999 }]
10000 } else {
10001 return 0
10002 }
10003 }
10004
10005 # Return 1 if the assembler accepts the aarch64 .variant_pcs directive.
10006
10007 proc check_effective_target_aarch64_variant_pcs { } {
10008 if { [istarget aarch64*-*-*] } {
10009 return [check_no_compiler_messages aarch64_variant_pcs object {
10010 __asm__ (".variant_pcs foo");
10011 }]
10012 } else {
10013 return 0
10014 }
10015 }
10016
10017 # Return 1 if this is a reduced AVR Tiny core. Such cores have different
10018 # register set, instruction set, addressing capabilities and ABI.
10019
10020 proc check_effective_target_avr_tiny { } {
10021 if { [istarget avr*-*-*] } {
10022 return [check_no_compiler_messages avr_tiny object {
10023 #ifdef __AVR_TINY__
10024 int dummy;
10025 #else
10026 #error target not a reduced AVR Tiny core
10027 #endif
10028 }]
10029 } else {
10030 return 0
10031 }
10032 }
10033
10034 # Return 1 if <fenv.h> is available.
10035
10036 proc check_effective_target_fenv {} {
10037 return [check_no_compiler_messages fenv object {
10038 #include <fenv.h>
10039 } [add_options_for_ieee "-std=gnu99"]]
10040 }
10041
10042 # Return 1 if <fenv.h> is available with all the standard IEEE
10043 # exceptions and floating-point exceptions are raised by arithmetic
10044 # operations. (If the target requires special options for "inexact"
10045 # exceptions, those need to be specified in the testcases.)
10046
10047 proc check_effective_target_fenv_exceptions {} {
10048 return [check_runtime fenv_exceptions {
10049 #include <fenv.h>
10050 #include <stdlib.h>
10051 #ifndef FE_DIVBYZERO
10052 # error Missing FE_DIVBYZERO
10053 #endif
10054 #ifndef FE_INEXACT
10055 # error Missing FE_INEXACT
10056 #endif
10057 #ifndef FE_INVALID
10058 # error Missing FE_INVALID
10059 #endif
10060 #ifndef FE_OVERFLOW
10061 # error Missing FE_OVERFLOW
10062 #endif
10063 #ifndef FE_UNDERFLOW
10064 # error Missing FE_UNDERFLOW
10065 #endif
10066 volatile float a = 0.0f, r;
10067 int
10068 main (void)
10069 {
10070 r = a / a;
10071 if (fetestexcept (FE_INVALID))
10072 exit (0);
10073 else
10074 abort ();
10075 }
10076 } [add_options_for_ieee "-std=gnu99"]]
10077 }
10078
10079 # Return 1 if <fenv.h> is available with all the standard IEEE
10080 # exceptions and floating-point exceptions are raised by arithmetic
10081 # operations for decimal floating point. (If the target requires
10082 # special options for "inexact" exceptions, those need to be specified
10083 # in the testcases.)
10084
10085 proc check_effective_target_fenv_exceptions_dfp {} {
10086 return [check_runtime fenv_exceptions_dfp {
10087 #include <fenv.h>
10088 #include <stdlib.h>
10089 #ifndef FE_DIVBYZERO
10090 # error Missing FE_DIVBYZERO
10091 #endif
10092 #ifndef FE_INEXACT
10093 # error Missing FE_INEXACT
10094 #endif
10095 #ifndef FE_INVALID
10096 # error Missing FE_INVALID
10097 #endif
10098 #ifndef FE_OVERFLOW
10099 # error Missing FE_OVERFLOW
10100 #endif
10101 #ifndef FE_UNDERFLOW
10102 # error Missing FE_UNDERFLOW
10103 #endif
10104 volatile _Decimal64 a = 0.0DD, r;
10105 int
10106 main (void)
10107 {
10108 r = a / a;
10109 if (fetestexcept (FE_INVALID))
10110 exit (0);
10111 else
10112 abort ();
10113 }
10114 } [add_options_for_ieee "-std=gnu99"]]
10115 }
10116
10117 # Return 1 if -fexceptions is supported.
10118
10119 proc check_effective_target_exceptions {} {
10120 if { [istarget amdgcn*-*-*] } {
10121 return 0
10122 }
10123 return 1
10124 }
10125
10126 # Used to check if the testing configuration supports exceptions.
10127 # Returns 0 if exceptions are unsupported or disabled (e.g. by passing
10128 # -fno-exceptions). Returns 1 if exceptions are enabled.
10129 proc check_effective_target_exceptions_enabled {} {
10130 return [check_cached_effective_target exceptions_enabled {
10131 if { [check_effective_target_exceptions] } {
10132 return [check_no_compiler_messages exceptions_enabled assembly {
10133 // C++
10134 void foo (void)
10135 {
10136 throw 1;
10137 }
10138 }]
10139 } else {
10140 # If exceptions aren't supported, then they're not enabled.
10141 return 0
10142 }
10143 }]
10144 }
10145
10146 proc check_effective_target_tiny {} {
10147 return [check_cached_effective_target tiny {
10148 if { [istarget aarch64*-*-*]
10149 && [check_effective_target_aarch64_tiny] } {
10150 return 1
10151 }
10152 if { [istarget avr-*-*]
10153 && [check_effective_target_avr_tiny] } {
10154 return 1
10155 }
10156 # PRU Program Counter is 16-bits, and trampolines are not supported.
10157 # Hence directly declare as a tiny target.
10158 if [istarget pru-*-*] {
10159 return 1
10160 }
10161 return 0
10162 }]
10163 }
10164
10165 # Return 1 if the target supports -mbranch-cost=N option.
10166
10167 proc check_effective_target_branch_cost {} {
10168 if { [ istarget arm*-*-*]
10169 || [istarget avr*-*-*]
10170 || [istarget csky*-*-*]
10171 || [istarget epiphany*-*-*]
10172 || [istarget frv*-*-*]
10173 || [istarget i?86-*-*] || [istarget x86_64-*-*]
10174 || [istarget mips*-*-*]
10175 || [istarget s390*-*-*]
10176 || [istarget riscv*-*-*]
10177 || [istarget sh*-*-*] } {
10178 return 1
10179 }
10180 return 0
10181 }
10182
10183 # Record that dg-final test TEST requires convential compilation.
10184
10185 proc force_conventional_output_for { test } {
10186 if { [info proc $test] == "" } {
10187 perror "$test does not exist"
10188 exit 1
10189 }
10190 proc ${test}_required_options {} {
10191 global gcc_force_conventional_output
10192 upvar 1 extra_tool_flags extra_tool_flags
10193 if {[regexp -- "^scan-assembler" [info level 0]]
10194 && ![string match "*-fident*" $extra_tool_flags]} {
10195 # Do not let .ident confuse assembler scan tests
10196 return [list $gcc_force_conventional_output "-fno-ident"]
10197 }
10198 return $gcc_force_conventional_output
10199 }
10200 }
10201
10202 # Record that dg-final test scan-ltrans-tree-dump* requires -flto-partition=one
10203 # in order to force a single partition, allowing scan-ltrans-tree-dump* to scan
10204 # a dump file *.exe.ltrans0.*.
10205
10206 proc scan-ltrans-tree-dump_required_options {} {
10207 return "-flto-partition=one"
10208 }
10209 proc scan-ltrans-tree-dump-times_required_options {} {
10210 return "-flto-partition=one"
10211 }
10212 proc scan-ltrans-tree-dump-not_required_options {} {
10213 return "-flto-partition=one"
10214 }
10215 proc scan-ltrans-tree-dump-dem_required_options {} {
10216 return "-flto-partition=one"
10217 }
10218 proc scan-ltrans-tree-dump-dem-not_required_options {} {
10219 return "-flto-partition=one"
10220 }
10221
10222 # Return 1 if the x86-64 target supports PIE with copy reloc, 0
10223 # otherwise. Cache the result.
10224
10225 proc check_effective_target_pie_copyreloc { } {
10226 global tool
10227 global GCC_UNDER_TEST
10228
10229 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
10230 return 0
10231 }
10232
10233 # Need auto-host.h to check linker support.
10234 if { ![file exists ../../auto-host.h ] } {
10235 return 0
10236 }
10237
10238 return [check_cached_effective_target pie_copyreloc {
10239 # Set up and compile to see if linker supports PIE with copy
10240 # reloc. Include the current process ID in the file names to
10241 # prevent conflicts with invocations for multiple testsuites.
10242
10243 set src pie[pid].c
10244 set obj pie[pid].o
10245
10246 set f [open $src "w"]
10247 puts $f "#include \"../../auto-host.h\""
10248 puts $f "#if HAVE_LD_PIE_COPYRELOC == 0"
10249 puts $f "# error Linker does not support PIE with copy reloc."
10250 puts $f "#endif"
10251 close $f
10252
10253 verbose "check_effective_target_pie_copyreloc compiling testfile $src" 2
10254 set lines [${tool}_target_compile $src $obj object ""]
10255
10256 file delete $src
10257 file delete $obj
10258
10259 if [string match "" $lines] then {
10260 verbose "check_effective_target_pie_copyreloc testfile compilation passed" 2
10261 return 1
10262 } else {
10263 verbose "check_effective_target_pie_copyreloc testfile compilation failed" 2
10264 return 0
10265 }
10266 }]
10267 }
10268
10269 # Return 1 if the x86 target supports R_386_GOT32X relocation, 0
10270 # otherwise. Cache the result.
10271
10272 proc check_effective_target_got32x_reloc { } {
10273 global tool
10274 global GCC_UNDER_TEST
10275
10276 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
10277 return 0
10278 }
10279
10280 # Need auto-host.h to check linker support.
10281 if { ![file exists ../../auto-host.h ] } {
10282 return 0
10283 }
10284
10285 return [check_cached_effective_target got32x_reloc {
10286 # Include the current process ID in the file names to prevent
10287 # conflicts with invocations for multiple testsuites.
10288
10289 set src got32x[pid].c
10290 set obj got32x[pid].o
10291
10292 set f [open $src "w"]
10293 puts $f "#include \"../../auto-host.h\""
10294 puts $f "#if HAVE_AS_IX86_GOT32X == 0"
10295 puts $f "# error Assembler does not support R_386_GOT32X."
10296 puts $f "#endif"
10297 close $f
10298
10299 verbose "check_effective_target_got32x_reloc compiling testfile $src" 2
10300 set lines [${tool}_target_compile $src $obj object ""]
10301
10302 file delete $src
10303 file delete $obj
10304
10305 if [string match "" $lines] then {
10306 verbose "check_effective_target_got32x_reloc testfile compilation passed" 2
10307 return 1
10308 } else {
10309 verbose "check_effective_target_got32x_reloc testfile compilation failed" 2
10310 return 0
10311 }
10312 }]
10313
10314 return $got32x_reloc_available_saved
10315 }
10316
10317 # Return 1 if the x86 target supports calling ___tls_get_addr via GOT,
10318 # 0 otherwise. Cache the result.
10319
10320 proc check_effective_target_tls_get_addr_via_got { } {
10321 global tool
10322 global GCC_UNDER_TEST
10323
10324 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
10325 return 0
10326 }
10327
10328 # Need auto-host.h to check linker support.
10329 if { ![file exists ../../auto-host.h ] } {
10330 return 0
10331 }
10332
10333 return [check_cached_effective_target tls_get_addr_via_got {
10334 # Include the current process ID in the file names to prevent
10335 # conflicts with invocations for multiple testsuites.
10336
10337 set src tls_get_addr_via_got[pid].c
10338 set obj tls_get_addr_via_got[pid].o
10339
10340 set f [open $src "w"]
10341 puts $f "#include \"../../auto-host.h\""
10342 puts $f "#if HAVE_AS_IX86_TLS_GET_ADDR_GOT == 0"
10343 puts $f "# error Assembler/linker do not support calling ___tls_get_addr via GOT."
10344 puts $f "#endif"
10345 close $f
10346
10347 verbose "check_effective_target_tls_get_addr_via_got compiling testfile $src" 2
10348 set lines [${tool}_target_compile $src $obj object ""]
10349
10350 file delete $src
10351 file delete $obj
10352
10353 if [string match "" $lines] then {
10354 verbose "check_effective_target_tls_get_addr_via_got testfile compilation passed" 2
10355 return 1
10356 } else {
10357 verbose "check_effective_target_tls_get_addr_via_got testfile compilation failed" 2
10358 return 0
10359 }
10360 }]
10361 }
10362
10363 # Return 1 if the target uses comdat groups.
10364
10365 proc check_effective_target_comdat_group {} {
10366 return [check_no_messages_and_pattern comdat_group "\.section\[^\n\r]*,comdat|\.group\[^\n\r]*,#comdat" assembly {
10367 // C++
10368 inline int foo () { return 1; }
10369 int (*fn) () = foo;
10370 }]
10371 }
10372
10373 # Return 1 if target supports __builtin_eh_return
10374 proc check_effective_target_builtin_eh_return { } {
10375 return [check_no_compiler_messages builtin_eh_return object {
10376 void test (long l, void *p)
10377 {
10378 __builtin_eh_return (l, p);
10379 }
10380 } "" ]
10381 }
10382
10383 # Return 1 if the target supports max reduction for vectors.
10384
10385 proc check_effective_target_vect_max_reduc { } {
10386 if { [istarget aarch64*-*-*] || [is-effective-target arm_neon] } {
10387 return 1
10388 }
10389 return 0
10390 }
10391
10392 # Return 1 if the compiler has been configured with nvptx offloading.
10393
10394 proc check_effective_target_offload_nvptx { } {
10395 return [check_no_compiler_messages offload_nvptx assembly {
10396 int main () {return 0;}
10397 } "-foffload=nvptx-none" ]
10398 }
10399
10400 # Return 1 if the compiler has been configured with gcn offloading.
10401
10402 proc check_effective_target_offload_gcn { } {
10403 return [check_no_compiler_messages offload_gcn assembly {
10404 int main () {return 0;}
10405 } "-foffload=amdgcn-amdhsa" ]
10406 }
10407
10408 # Return 1 if the target support -fprofile-update=atomic
10409 proc check_effective_target_profile_update_atomic {} {
10410 return [check_no_compiler_messages profile_update_atomic assembly {
10411 int main (void) { return 0; }
10412 } "-fprofile-update=atomic -fprofile-generate"]
10413 }
10414
10415 # Return 1 if vector (va - vector add) instructions are understood by
10416 # the assembler and can be executed. This also covers checking for
10417 # the VX kernel feature. A kernel without that feature does not
10418 # enable the vector facility and the following check will die with a
10419 # signal.
10420 proc check_effective_target_s390_vx { } {
10421 if ![istarget s390*-*-*] then {
10422 return 0;
10423 }
10424
10425 return [check_runtime s390_check_vx {
10426 int main (void)
10427 {
10428 asm ("va %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
10429 return 0;
10430 }
10431 } "-march=z13 -mzarch" ]
10432 }
10433
10434 # Same as above but for the z14 vector enhancement facility. Test
10435 # is performed with the vector nand instruction.
10436 proc check_effective_target_s390_vxe { } {
10437 if ![istarget s390*-*-*] then {
10438 return 0;
10439 }
10440
10441 return [check_runtime s390_check_vxe {
10442 int main (void)
10443 {
10444 asm ("vnn %%v24, %%v26, %%v28" : : : "v24", "v26", "v28");
10445 return 0;
10446 }
10447 } "-march=z14 -mzarch" ]
10448 }
10449
10450 # Same as above but for the arch13 vector enhancement facility. Test
10451 # is performed with the vector shift left double by bit instruction.
10452 proc check_effective_target_s390_vxe2 { } {
10453 if ![istarget s390*-*-*] then {
10454 return 0;
10455 }
10456
10457 return [check_runtime s390_check_vxe2 {
10458 int main (void)
10459 {
10460 asm ("vsld %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
10461 return 0;
10462 }
10463 } "-march=arch13 -mzarch" ]
10464 }
10465
10466 # Same as above but for the arch14 NNPA facility.
10467 proc check_effective_target_s390_nnpa { } {
10468 if ![istarget s390*-*-*] then {
10469 return 0;
10470 }
10471
10472 return [check_runtime s390_check_nnpa {
10473 int main (void)
10474 {
10475 asm ("vzero %%v24\n\t"
10476 "vcrnf %%v24,%%v24,%%v24,0,2" : : : "v24");
10477 return 0;
10478 }
10479 } "-march=arch14 -mzarch" ]
10480 }
10481
10482 #For versions of ARM architectures that have hardware div insn,
10483 #disable the divmod transform
10484
10485 proc check_effective_target_arm_divmod_simode { } {
10486 return [check_no_compiler_messages arm_divmod assembly {
10487 #ifdef __ARM_ARCH_EXT_IDIV__
10488 #error has div insn
10489 #endif
10490 int i;
10491 }]
10492 }
10493
10494 # Return 1 if target supports divmod hardware insn or divmod libcall.
10495
10496 proc check_effective_target_divmod { } {
10497 #TODO: Add checks for all targets that have either hardware divmod insn
10498 # or define libfunc for divmod.
10499 if { [istarget arm*-*-*]
10500 || [istarget i?86-*-*] || [istarget x86_64-*-*] } {
10501 return 1
10502 }
10503 return 0
10504 }
10505
10506 # Return 1 if target supports divmod for SImode. The reason for
10507 # separating this from check_effective_target_divmod is that
10508 # some versions of ARM architecture define div instruction
10509 # only for simode, and for these archs, we do not want to enable
10510 # divmod transform for simode.
10511
10512 proc check_effective_target_divmod_simode { } {
10513 if { [istarget arm*-*-*] } {
10514 return [check_effective_target_arm_divmod_simode]
10515 }
10516
10517 return [check_effective_target_divmod]
10518 }
10519
10520 # Return 1 if store merging optimization is applicable for target.
10521 # Store merging is not profitable for targets like the avr which
10522 # can load/store only one byte at a time. Use int size as a proxy
10523 # for the number of bytes the target can write, and skip for targets
10524 # with a smallish (< 32) size.
10525
10526 proc check_effective_target_store_merge { } {
10527 if { [is-effective-target non_strict_align ] && [is-effective-target int32plus] } {
10528 return 1
10529 }
10530
10531 return 0
10532 }
10533
10534 # Return 1 if we're able to assemble rdrand
10535
10536 proc check_effective_target_rdrand { } {
10537 return [check_no_compiler_messages_nocache rdrand object {
10538 unsigned int
10539 __foo(void)
10540 {
10541 unsigned int val;
10542 __builtin_ia32_rdrand32_step(&val);
10543 return val;
10544 }
10545 } "-mrdrnd" ]
10546 }
10547
10548 # Return 1 if the target supports coprocessor instructions: cdp, ldc, ldcl,
10549 # stc, stcl, mcr and mrc.
10550 proc check_effective_target_arm_coproc1_ok_nocache { } {
10551 if { ![istarget arm*-*-*] } {
10552 return 0
10553 }
10554 return [check_no_compiler_messages_nocache arm_coproc1_ok assembly {
10555 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 4
10556 #error FOO
10557 #endif
10558 #include <arm_acle.h>
10559 }]
10560 }
10561
10562 proc check_effective_target_arm_coproc1_ok { } {
10563 return [check_cached_effective_target arm_coproc1_ok \
10564 check_effective_target_arm_coproc1_ok_nocache]
10565 }
10566
10567 # Return 1 if the target supports all coprocessor instructions checked by
10568 # check_effective_target_arm_coproc1_ok in addition to the following: cdp2,
10569 # ldc2, ldc2l, stc2, stc2l, mcr2 and mrc2.
10570 proc check_effective_target_arm_coproc2_ok_nocache { } {
10571 if { ![check_effective_target_arm_coproc1_ok] } {
10572 return 0
10573 }
10574 return [check_no_compiler_messages_nocache arm_coproc2_ok assembly {
10575 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 5
10576 #error FOO
10577 #endif
10578 #include <arm_acle.h>
10579 }]
10580 }
10581
10582 proc check_effective_target_arm_coproc2_ok { } {
10583 return [check_cached_effective_target arm_coproc2_ok \
10584 check_effective_target_arm_coproc2_ok_nocache]
10585 }
10586
10587 # Return 1 if the target supports all coprocessor instructions checked by
10588 # check_effective_target_arm_coproc2_ok in addition the following: mcrr and
10589 # mrrc.
10590 proc check_effective_target_arm_coproc3_ok_nocache { } {
10591 if { ![check_effective_target_arm_coproc2_ok] } {
10592 return 0
10593 }
10594 return [check_no_compiler_messages_nocache arm_coproc3_ok assembly {
10595 #if (__thumb__ && !__thumb2__) \
10596 || (__ARM_ARCH < 6 && !defined (__ARM_ARCH_5TE__))
10597 #error FOO
10598 #endif
10599 #include <arm_acle.h>
10600 }]
10601 }
10602
10603 proc check_effective_target_arm_coproc3_ok { } {
10604 return [check_cached_effective_target arm_coproc3_ok \
10605 check_effective_target_arm_coproc3_ok_nocache]
10606 }
10607
10608 # Return 1 if the target supports all coprocessor instructions checked by
10609 # check_effective_target_arm_coproc3_ok in addition the following: mcrr2 and
10610 # mrcc2.
10611 proc check_effective_target_arm_coproc4_ok_nocache { } {
10612 if { ![check_effective_target_arm_coproc3_ok] } {
10613 return 0
10614 }
10615 return [check_no_compiler_messages_nocache arm_coproc4_ok assembly {
10616 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 6
10617 #error FOO
10618 #endif
10619 #include <arm_acle.h>
10620 }]
10621 }
10622
10623 proc check_effective_target_arm_coproc4_ok { } {
10624 return [check_cached_effective_target arm_coproc4_ok \
10625 check_effective_target_arm_coproc4_ok_nocache]
10626 }
10627
10628 # Return 1 if the target supports the auto_inc_dec optimization pass.
10629 proc check_effective_target_autoincdec { } {
10630 if { ![check_no_compiler_messages auto_incdec assembly { void f () { }
10631 } "-O2 -fdump-rtl-auto_inc_dec" ] } {
10632 return 0
10633 }
10634
10635 set dumpfile [glob -nocomplain "auto_incdec[pid].c.\[0-9\]\[0-9\]\[0-9\]r.auto_inc_dec"]
10636 if { [file exists $dumpfile ] } {
10637 file delete $dumpfile
10638 return 1
10639 }
10640 return 0
10641 }
10642
10643 # Return 1 if the target has support for stack probing designed
10644 # to avoid stack-clash style attacks.
10645 #
10646 # This is used to restrict the stack-clash mitigation tests to
10647 # just those targets that have been explicitly supported.
10648 #
10649 # In addition to the prologue work on those targets, each target's
10650 # properties should be described in the functions below so that
10651 # tests do not become a mess of unreadable target conditions.
10652 #
10653 proc check_effective_target_supports_stack_clash_protection { } {
10654
10655 if { [istarget x86_64-*-*] || [istarget i?86-*-*]
10656 || [istarget powerpc*-*-*] || [istarget rs6000*-*-*]
10657 || [istarget aarch64*-**] || [istarget s390*-*-*] } {
10658 return 1
10659 }
10660 return 0
10661 }
10662
10663 # Return 1 if the target creates a frame pointer for non-leaf functions
10664 # Note we ignore cases where we apply tail call optimization here.
10665 proc check_effective_target_frame_pointer_for_non_leaf { } {
10666 # Solaris/x86 defaults to -fno-omit-frame-pointer.
10667 if { [istarget i?86-*-solaris*] || [istarget x86_64-*-solaris*] } {
10668 return 1
10669 }
10670
10671 return 0
10672 }
10673
10674 # Return 1 if the target's calling sequence or its ABI
10675 # create implicit stack probes at or prior to function entry.
10676 proc check_effective_target_caller_implicit_probes { } {
10677
10678 # On x86/x86_64 the call instruction itself pushes the return
10679 # address onto the stack. That is an implicit probe of *sp.
10680 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
10681 return 1
10682 }
10683
10684 # On PPC, the ABI mandates that the address of the outer
10685 # frame be stored at *sp. Thus each allocation of stack
10686 # space is itself an implicit probe of *sp.
10687 if { [istarget powerpc*-*-*] || [istarget rs6000*-*-*] } {
10688 return 1
10689 }
10690
10691 # s390's ABI has a register save area allocated by the
10692 # caller for use by the callee. The mere existence does
10693 # not constitute a probe by the caller, but when the slots
10694 # used by the callee those stores are implicit probes.
10695 if { [istarget s390*-*-*] } {
10696 return 1
10697 }
10698
10699 # Not strictly true on aarch64, but we have agreed that we will
10700 # consider any function that pushes SP more than 3kbytes into
10701 # the guard page as broken. This essentially means that we can
10702 # consider the aarch64 as having a caller implicit probe at
10703 # *(sp + 1k).
10704 if { [istarget aarch64*-*-*] } {
10705 return 1;
10706 }
10707
10708 return 0
10709 }
10710
10711 # Targets that potentially realign the stack pointer often cause residual
10712 # stack allocations and make it difficult to elimination loops or residual
10713 # allocations for dynamic stack allocations
10714 proc check_effective_target_callee_realigns_stack { } {
10715 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
10716 return 1
10717 }
10718 return 0
10719 }
10720
10721 # Return 1 if CET instructions can be compiled.
10722 proc check_effective_target_cet { } {
10723 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
10724 return 0
10725 }
10726 return [check_no_compiler_messages cet object {
10727 void foo (void)
10728 {
10729 asm ("setssbsy");
10730 }
10731 } "-O2 -fcf-protection" ]
10732 }
10733
10734 # Return 1 if target supports floating point "infinite"
10735 proc check_effective_target_inf { } {
10736 return [check_no_compiler_messages supports_inf assembly {
10737 const double pinf = __builtin_inf ();
10738 }]
10739 }
10740
10741 # Return 1 if target supports floating point "infinite" for float.
10742 proc check_effective_target_inff { } {
10743 return [check_no_compiler_messages supports_inff assembly {
10744 const float pinf = __builtin_inff ();
10745 }]
10746 }
10747
10748 # Return 1 if the target supports ARMv8.3 Adv.SIMD Complex instructions
10749 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
10750 # Record the command line options needed.
10751
10752 proc check_effective_target_arm_v8_3a_complex_neon_ok_nocache { } {
10753 global et_arm_v8_3a_complex_neon_flags
10754 set et_arm_v8_3a_complex_neon_flags ""
10755
10756 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
10757 return 0;
10758 }
10759
10760 # Iterate through sets of options to find the compiler flags that
10761 # need to be added to the -march option.
10762 foreach flags {"" "-mfloat-abi=softfp -mfpu=auto" "-mfloat-abi=hard -mfpu=auto"} {
10763 if { [check_no_compiler_messages_nocache \
10764 arm_v8_3a_complex_neon_ok assembly {
10765 #if !defined (__ARM_FEATURE_COMPLEX)
10766 #error "__ARM_FEATURE_COMPLEX not defined"
10767 #endif
10768 } "$flags -march=armv8.3-a"] } {
10769 set et_arm_v8_3a_complex_neon_flags "$flags -march=armv8.3-a"
10770 return 1;
10771 }
10772 }
10773
10774 return 0;
10775 }
10776
10777 proc check_effective_target_arm_v8_3a_complex_neon_ok { } {
10778 return [check_cached_effective_target arm_v8_3a_complex_neon_ok \
10779 check_effective_target_arm_v8_3a_complex_neon_ok_nocache]
10780 }
10781
10782 proc add_options_for_arm_v8_3a_complex_neon { flags } {
10783 if { ! [check_effective_target_arm_v8_3a_complex_neon_ok] } {
10784 return "$flags"
10785 }
10786 global et_arm_v8_3a_complex_neon_flags
10787 return "$flags $et_arm_v8_3a_complex_neon_flags"
10788 }
10789
10790 # Return 1 if the target supports ARMv8.3 Adv.SIMD + FP16 Complex instructions
10791 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
10792 # Record the command line options needed.
10793
10794 proc check_effective_target_arm_v8_3a_fp16_complex_neon_ok_nocache { } {
10795 global et_arm_v8_3a_fp16_complex_neon_flags
10796 set et_arm_v8_3a_fp16_complex_neon_flags ""
10797
10798 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
10799 return 0;
10800 }
10801
10802 # Iterate through sets of options to find the compiler flags that
10803 # need to be added to the -march option.
10804 foreach flags {"" "-mfloat-abi=softfp -mfpu=auto" "-mfloat-abi=hard -mfpu=auto"} {
10805 if { [check_no_compiler_messages_nocache \
10806 arm_v8_3a_fp16_complex_neon_ok assembly {
10807 #if !defined (__ARM_FEATURE_COMPLEX)
10808 #error "__ARM_FEATURE_COMPLEX not defined"
10809 #endif
10810 } "$flags -march=armv8.3-a+fp16"] } {
10811 set et_arm_v8_3a_fp16_complex_neon_flags \
10812 "$flags -march=armv8.3-a+fp16"
10813 return 1;
10814 }
10815 }
10816
10817 return 0;
10818 }
10819
10820 proc check_effective_target_arm_v8_3a_fp16_complex_neon_ok { } {
10821 return [check_cached_effective_target arm_v8_3a_fp16_complex_neon_ok \
10822 check_effective_target_arm_v8_3a_fp16_complex_neon_ok_nocache]
10823 }
10824
10825 proc add_options_for_arm_v8_3a_fp16_complex_neon { flags } {
10826 if { ! [check_effective_target_arm_v8_3a_fp16_complex_neon_ok] } {
10827 return "$flags"
10828 }
10829 global et_arm_v8_3a_fp16_complex_neon_flags
10830 return "$flags $et_arm_v8_3a_fp16_complex_neon_flags"
10831 }
10832
10833
10834 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.3
10835 # with the complex instruction extension, 0 otherwise. The test is valid for
10836 # ARM and for AArch64.
10837
10838 proc check_effective_target_arm_v8_3a_complex_neon_hw { } {
10839 if { ![check_effective_target_arm_v8_3a_complex_neon_ok] } {
10840 return 1;
10841 }
10842 return [check_runtime arm_v8_3a_complex_neon_hw_available {
10843 #include "arm_neon.h"
10844 int
10845 main (void)
10846 {
10847
10848 float32x2_t results = {-4.0,5.0};
10849 float32x2_t a = {1.0,3.0};
10850 float32x2_t b = {2.0,5.0};
10851
10852 #ifdef __ARM_ARCH_ISA_A64
10853 asm ("fcadd %0.2s, %1.2s, %2.2s, #90"
10854 : "=w"(results)
10855 : "w"(a), "w"(b)
10856 : /* No clobbers. */);
10857
10858 #else
10859 asm ("vcadd.f32 %P0, %P1, %P2, #90"
10860 : "=w"(results)
10861 : "w"(a), "w"(b)
10862 : /* No clobbers. */);
10863 #endif
10864
10865 return (results[0] == 8 && results[1] == 24) ? 0 : 1;
10866 }
10867 } [add_options_for_arm_v8_3a_complex_neon ""]]
10868 }
10869
10870 # Return 1 if the assembler supports assembling the Armv8.3 pointer authentication B key directive
10871 proc check_effective_target_arm_v8_3a_bkey_directive { } {
10872 return [check_no_compiler_messages cet object {
10873 int main(void) {
10874 asm (".cfi_b_key_frame");
10875 return 0;
10876 }
10877 }]
10878 }
10879
10880 # Return 1 if the target supports executing the Armv8.1-M Mainline Low
10881 # Overhead Loop, 0 otherwise. The test is valid for ARM.
10882
10883 proc check_effective_target_arm_v8_1_lob_ok { } {
10884 if { ![check_effective_target_arm_cortex_m] } {
10885 return 0;
10886 } else {
10887 return [check_runtime arm_v8_1_lob_hw_available {
10888 int
10889 main (void)
10890 { int i = 0;
10891 asm ("movw r3, #10\n\t" /* movs? */
10892 "dls lr, r3" : : : "r3", "lr");
10893 loop:
10894 i++;
10895 asm goto ("le lr, %l0" : : : "lr" : loop);
10896 return i != 10;
10897 }
10898 } "-march=armv8.1-m.main -mthumb" ]
10899 }
10900 }
10901
10902 # Return 1 if this is an ARM target where Thumb-2 is used without
10903 # options added by the test and the target does not support executing
10904 # the Armv8.1-M Mainline Low Overhead Loop, 0 otherwise. The test is
10905 # valid for ARM.
10906
10907 proc check_effective_target_arm_thumb2_no_arm_v8_1_lob { } {
10908 if { [check_effective_target_arm_thumb2]
10909 && ![check_effective_target_arm_v8_1_lob_ok] } {
10910 return 1
10911 }
10912 return 0
10913 }
10914
10915 # Return 1 if this is an ARM target where -mthumb causes Thumb-2 to be
10916 # used and the target does not support executing the Armv8.1-M
10917 # Mainline Low Overhead Loop, 0 otherwise. The test is valid for ARM.
10918
10919 proc check_effective_target_arm_thumb2_ok_no_arm_v8_1_lob { } {
10920 if { [check_effective_target_arm_thumb2_ok]
10921 && ![check_effective_target_arm_v8_1_lob_ok] } {
10922 return 1
10923 }
10924 return 0
10925 }
10926
10927 # Returns 1 if the target is using glibc, 0 otherwise.
10928
10929 proc check_effective_target_glibc { } {
10930 return [check_no_compiler_messages glibc_object assembly {
10931 #include <stdlib.h>
10932 #if !defined(__GLIBC__)
10933 #error undefined
10934 #endif
10935 }]
10936 }
10937
10938 # Return 1 if the target plus current options supports a vector
10939 # complex addition with rotate of half and single float modes, 0 otherwise.
10940 #
10941 # This won't change for different subtargets so cache the result.
10942
10943 foreach N {hf sf} {
10944 eval [string map [list N $N] {
10945 proc check_effective_target_vect_complex_rot_N { } {
10946 return [check_cached_effective_target_indexed vect_complex_rot_N {
10947 expr { [istarget aarch64*-*-*]
10948 || [istarget arm*-*-*] }}]
10949 }
10950 }]
10951 }
10952
10953 # Return 1 if the target plus current options supports a vector
10954 # complex addition with rotate of double float modes, 0 otherwise.
10955 #
10956 # This won't change for different subtargets so cache the result.
10957
10958 foreach N {df} {
10959 eval [string map [list N $N] {
10960 proc check_effective_target_vect_complex_rot_N { } {
10961 return [check_cached_effective_target_indexed vect_complex_rot_N {
10962 expr { [istarget aarch64*-*-*] }}]
10963 }
10964 }]
10965 }
10966
10967 # Return 1 if this target uses an LLVM assembler and/or linker
10968 proc check_effective_target_llvm_binutils { } {
10969 return [check_cached_effective_target llvm_binutils {
10970 expr { [istarget amdgcn*-*-*]
10971 || [check_effective_target_offload_gcn] }}]
10972 }
10973
10974 # Return 1 if the compiler supports '-mfentry'.
10975
10976 proc check_effective_target_mfentry { } {
10977 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
10978 return 0
10979 }
10980 return [check_no_compiler_messages mfentry object {
10981 void foo (void) { }
10982 } "-mfentry"]
10983 }
10984
10985 # Return 1 if this target supports indirect calls
10986 proc check_effective_target_indirect_calls { } {
10987 if { [istarget bpf-*-*] } {
10988 return 0
10989 }
10990 return 1
10991 }
10992
10993 # Return 1 if we can use the -lgccjit option, 0 otherwise.
10994
10995 proc check_effective_target_lgccjit { } {
10996 if { [info procs jit_target_compile] == "" } then {
10997 global GCC_UNDER_TEST
10998 if ![info exists GCC_UNDER_TEST] {
10999 set GCC_UNDER_TEST "[find_gcc]"
11000 }
11001 proc jit_target_compile { source dest type options } [info body gcc_target_compile]
11002 }
11003 return [check_no_compiler_messages lgccjit executable {
11004 int main() { return 0; }
11005 } "-lgccjit"]
11006 }
11007
11008 # Return 1 if the MSP430 small memory model is in use.
11009 proc check_effective_target_msp430_small {} {
11010 return [check_no_compiler_messages msp430_small assembly {
11011 #if (!defined __MSP430__ || defined __MSP430X_LARGE__)
11012 #error !msp430 || __MSP430X_LARGE__
11013 #endif
11014 } ""]
11015 }
11016
11017 # Return 1 if the MSP430 large memory model is in use.
11018 proc check_effective_target_msp430_large {} {
11019 return [check_no_compiler_messages msp430_large assembly {
11020 #ifndef __MSP430X_LARGE__
11021 #error __MSP430X_LARGE__
11022 #endif
11023 } ""]
11024 }
11025
11026 # Return 1 if GCC was configured with --with-tune=cortex-a76
11027 proc check_effective_target_tune_cortex_a76 { } {
11028 return [check_configured_with "with-tune=cortex-a76"]
11029 }
11030
11031 # Return 1 if the target has an efficient means to encode large initializers
11032 # in the assembly.
11033
11034 proc check_effective_target_large_initializer { } {
11035 if { [istarget nvptx*-*-*] } {
11036 return 0
11037 }
11038
11039 return 1
11040 }
11041
11042 # Return 1 if the target allows function prototype mismatches
11043 # in the assembly.
11044
11045 proc check_effective_target_non_strict_prototype { } {
11046 if { [istarget nvptx*-*-*] } {
11047 return 0
11048 }
11049
11050 return 1
11051 }
11052
11053 # Returns 1 if the target toolchain supports extended
11054 # syntax of .symver directive, 0 otherwise.
11055
11056 proc check_symver_available { } {
11057 return [check_no_compiler_messages symver_available object {
11058 int foo(void) { return 0; }
11059 int main (void) {
11060 asm volatile (".symver foo,foo@VER_1, local");
11061 return 0;
11062 }
11063 }]
11064 }
11065
11066 # Return 1 if emitted assembly contains .ident directive.
11067
11068 proc check_effective_target_ident_directive {} {
11069 return [check_no_messages_and_pattern ident_directive \
11070 "(?n)^\[\t\]+\\.ident" assembly {
11071 int i;
11072 }]
11073 }
11074
11075 # Return 1 if we're able to assemble movdiri and movdir64b
11076
11077 proc check_effective_target_movdir { } {
11078 return [check_no_compiler_messages movdir object {
11079 void
11080 foo (unsigned int *d, unsigned int s)
11081 {
11082 __builtin_ia32_directstoreu_u32 (d, s);
11083 }
11084 void
11085 bar (void *d, const void *s)
11086 {
11087 __builtin_ia32_movdir64b (d, s);
11088 }
11089 } "-mmovdiri -mmovdir64b" ]
11090 }
11091
11092 # Return 1 if target is not support address sanitize, 1 otherwise.
11093
11094 proc check_effective_target_no_fsanitize_address {} {
11095 if ![check_no_compiler_messages fsanitize_address executable {
11096 int main (void) { return 0; }
11097 }] {
11098 return 1;
11099 }
11100 return 0;
11101 }
11102
11103 # Return 1 if this target supports 'R' flag in .section directive, 0
11104 # otherwise. Cache the result.
11105
11106 proc check_effective_target_R_flag_in_section { } {
11107 global tool
11108 global GCC_UNDER_TEST
11109
11110 # Need auto-host.h to check linker support.
11111 if { ![file exists ../../auto-host.h ] } {
11112 return 0
11113 }
11114
11115 return [check_cached_effective_target R_flag_in_section {
11116
11117 set src pie[pid].c
11118 set obj pie[pid].o
11119
11120 set f [open $src "w"]
11121 puts $f "#include \"../../auto-host.h\""
11122 puts $f "#if HAVE_GAS_SHF_GNU_RETAIN == 0 || HAVE_INITFINI_ARRAY_SUPPORT == 0"
11123 puts $f "# error Assembler does not support 'R' flag in .section directive."
11124 puts $f "#endif"
11125 close $f
11126
11127 verbose "check_effective_target_R_flag_in_section compiling testfile $src" 2
11128 set lines [${tool}_target_compile $src $obj assembly ""]
11129
11130 file delete $src
11131 file delete $obj
11132
11133 if [string match "" $lines] then {
11134 verbose "check_effective_target_R_flag_in_section testfile compilation passed" 2
11135 return 1
11136 } else {
11137 verbose "check_effective_target_R_flag_in_section testfile compilation failed" 2
11138 return 0
11139 }
11140 }]
11141 }
11142
11143 # Return 1 if this target supports 'o' flag in .section directive, 0
11144 # otherwise. Cache the result.
11145
11146 proc check_effective_target_o_flag_in_section { } {
11147 global tool
11148 global GCC_UNDER_TEST
11149
11150 # Need auto-host.h to check linker support.
11151 if { ![file exists ../../auto-host.h ] } {
11152 return 0
11153 }
11154
11155 return [check_cached_effective_target o_flag_in_section {
11156
11157 set src pie[pid].c
11158 set obj pie[pid].o
11159
11160 set f [open $src "w"]
11161 puts $f "#include \"../../auto-host.h\""
11162 puts $f "#if HAVE_GAS_SECTION_LINK_ORDER == 0"
11163 puts $f "# error Assembler does not support 'o' flag in .section directive."
11164 puts $f "#endif"
11165 close $f
11166
11167 verbose "check_effective_target_o_flag_in_section compiling testfile $src" 2
11168 set lines [${tool}_target_compile $src $obj object ""]
11169
11170 file delete $src
11171 file delete $obj
11172
11173 if [string match "" $lines] then {
11174 verbose "check_effective_target_o_flag_in_section testfile compilation passed" 2
11175 return 1
11176 } else {
11177 verbose "check_effective_target_o_flag_in_section testfile compilation failed" 2
11178 return 0
11179 }
11180 }]
11181 }
11182
11183 # return 1 if LRA is supported.
11184
11185 proc check_effective_target_lra { } {
11186 if { [istarget hppa*-*-*] } {
11187 return 0
11188 }
11189 return 1
11190 }
11191
11192 # Test whether optimizations are enabled ('__OPTIMIZE__') per the
11193 # 'current_compiler_flags' (thus don't cache).
11194
11195 proc check_effective_target___OPTIMIZE__ {} {
11196 return [check_no_compiler_messages_nocache __OPTIMIZE__ assembly {
11197 #ifndef __OPTIMIZE__
11198 # error nein
11199 #endif
11200 } [current_compiler_flags]]
11201 }
This page took 0.528901 seconds and 5 git commands to generate.