Debian Codegraph @

gcc/testsuite/lib/target-supports.exp

raw
1 # Copyright (C) 1999-2025 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 # [email protected]
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 # "/* Assembly" for assembly code,
34 # "// C++" for c++,
35 # "// D" for D,
36 # "! Fortran" for Fortran code,
37 # "/* ObjC", for ObjC
38 # "// ObjC++" for ObjC++
39 # "// Go" for Go
40 # "// Rust" for Rust
41 # "*> COBOL" for COBOL
42 # and "(* Modula-2" for Modula-2
43 # If the tool is ObjC/ObjC++ then we overide the extension to .m/.mm to
44 # allow for ObjC/ObjC++ specific flags.
45
46 proc check_compile {basename type contents args} {
47 global tool
48 verbose "check_compile tool: $tool for $basename"
49
50 # Save additional_sources to avoid compiling testsuite's sources
51 # against check_compile's source.
52 global additional_sources
53 if [info exists additional_sources] {
54 set tmp_additional_sources "$additional_sources"
55 set additional_sources ""
56 }
57
58 if { [llength $args] > 0 } {
59 set options [list "additional_flags=[lindex $args 0]"]
60 } else {
61 set options ""
62 }
63 # Silence "command-line option [...] is valid for [...] but not for [...]"
64 # that we may easily run into here, if more than one language is involved.
65 lappend options additional_flags=-Wno-complain-wrong-lang
66
67 switch -glob -- $contents {
68 "*/\\* Assembly*" { set src ${basename}[pid].S }
69 "*! Fortran*" { set src ${basename}[pid].f90 }
70 "*// C++*" { set src ${basename}[pid].cc }
71 "*// D*" { set src ${basename}[pid].d }
72 "*// ObjC++*" { set src ${basename}[pid].mm }
73 "*/\\* ObjC*" { set src ${basename}[pid].m }
74 "*// Go*" { set src ${basename}[pid].go }
75 "*// Rust*" { set src ${basename}[pid].rs }
76 "*\\*> COBOL*" { set src ${basename}[pid].cob }
77 "*(\\* Modula-2*" { set src ${basename}[pid].mod }
78 default {
79 switch -- $tool {
80 "objc" { set src ${basename}[pid].m }
81 "obj-c++" { set src ${basename}[pid].mm }
82 default { set src ${basename}[pid].c }
83 }
84 }
85 }
86
87 set compile_type $type
88 switch -glob $type {
89 assembly { set output ${basename}[pid].s }
90 object { set output ${basename}[pid].o }
91 executable { set output ${basename}[pid].exe }
92 "tree-*" -
93 "rtl-*" {
94 set output ${basename}[pid].s
95 lappend options "additional_flags=-fdump-$type"
96 set compile_type assembly
97 }
98 }
99 set f [open $src "w"]
100 puts $f $contents
101 close $f
102 global compiler_flags
103 set save_compiler_flags $compiler_flags
104 set lines [${tool}_target_compile $src $output $compile_type "$options"]
105 set compiler_flags $save_compiler_flags
106 file delete $src
107
108 set scan_output $output
109 # Don't try folding this into the switch above; calling "glob" before the
110 # file is created won't work.
111 if [regexp "rtl-(.*)" $type dummy rtl_type] {
112 set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
113 file delete $output
114 } elseif [regexp "tree-(.*)" $type dummy tree_type] {
115 set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]t.$tree_type]"
116 file delete $output
117 }
118
119 # Restore additional_sources.
120 if [info exists additional_sources] {
121 set additional_sources "$tmp_additional_sources"
122 }
123
124 return [list $lines $scan_output]
125 }
126
127 proc current_target_name { } {
128 global target_info
129 if [info exists target_info(target,name)] {
130 set answer $target_info(target,name)
131 } else {
132 set answer ""
133 }
134 return $answer
135 }
136
137 # Implement an effective-target check for property PROP by invoking
138 # the Tcl command ARGS and seeing if it returns true.
139
140 proc check_cached_effective_target { prop args } {
141 global et_cache
142
143 set target [current_target_name]
144 if {![info exists et_cache($prop,$target)]} {
145 verbose "check_cached_effective_target $prop: checking $target" 2
146 if {[string is true -strict $args] || [string is false -strict $args]} {
147 error {check_cached_effective_target condition already evaluated; did you pass [...] instead of the expected {...}?}
148 } else {
149 set code [catch {uplevel eval $args} result]
150 if {$code != 0 && $code != 2} {
151 return -code $code $result
152 }
153 set et_cache($prop,$target) $result
154 }
155 }
156 set value $et_cache($prop,$target)
157 verbose "check_cached_effective_target $prop: returning $value for $target" 2
158 return $value
159 }
160
161 # Implements a version of check_cached_effective_target that also takes et_index
162 # into account when creating the key for the cache.
163 proc check_cached_effective_target_indexed { prop args } {
164 global et_index
165 set key "$et_index $prop"
166 verbose "check_cached_effective_target_index $prop: returning $key" 2
167
168 return [check_cached_effective_target $key [list uplevel eval $args]]
169 }
170
171 # Clear effective-target cache. This is useful after testing
172 # effective-target features and overriding TEST_ALWAYS_FLAGS and/or
173 # ALWAYS_CXXFLAGS.
174 # If one changes ALWAYS_CXXFLAGS or TEST_ALWAYS_FLAGS then they should
175 # do a clear_effective_target_cache at the end as the target cache can
176 # make decisions based upon the flags, and those decisions need to be
177 # redone when the flags change. An example of this is the
178 # asan_init/asan_finish pair.
179
180 proc clear_effective_target_cache { } {
181 global et_cache
182 array unset et_cache
183 }
184
185 # Like check_compile, but delete the output file and return true if the
186 # compiler printed no messages.
187 proc check_no_compiler_messages_nocache {args} {
188 set result [eval check_compile $args]
189 set lines [lindex $result 0]
190 set output [lindex $result 1]
191 remote_file build delete $output
192 return [string match "" $lines]
193 }
194
195 # Like check_no_compiler_messages_nocache, but cache the result.
196 # PROP is the property we're checking, and doubles as a prefix for
197 # temporary filenames.
198 proc check_no_compiler_messages {prop args} {
199 return [check_cached_effective_target $prop {
200 eval [list check_no_compiler_messages_nocache $prop] $args
201 }]
202 }
203
204 # Like check_compile, but return true if the compiler printed no
205 # messages and if the contents of the output file satisfy PATTERN.
206 # If PATTERN has the form "!REGEXP", the contents satisfy it if they
207 # don't match regular expression REGEXP, otherwise they satisfy it
208 # if they do match regular expression PATTERN. (PATTERN can start
209 # with something like "[!]" if the regular expression needs to match
210 # "!" as the first character.)
211 #
212 # Delete the output file before returning. The other arguments are
213 # as for check_compile.
214 proc check_no_messages_and_pattern_nocache {basename pattern args} {
215 global tool
216
217 set result [eval [list check_compile $basename] $args]
218 set lines [lindex $result 0]
219 set output [lindex $result 1]
220
221 set ok 0
222 if { [string match "" $lines] } {
223 set chan [open "$output"]
224 set invert [regexp {^!(.*)} $pattern dummy pattern]
225 set ok [expr { [regexp $pattern [read $chan]] != $invert }]
226 close $chan
227 }
228
229 remote_file build delete $output
230 return $ok
231 }
232
233 # Like check_no_messages_and_pattern_nocache, but cache the result.
234 # PROP is the property we're checking, and doubles as a prefix for
235 # temporary filenames.
236 proc check_no_messages_and_pattern {prop pattern args} {
237 return [check_cached_effective_target $prop {
238 eval [list check_no_messages_and_pattern_nocache $prop $pattern] $args
239 }]
240 }
241
242 # Try to compile and run an executable from code CONTENTS. Return true
243 # if the compiler reports no messages and if execution "passes" in the
244 # usual DejaGNU sense. The arguments are as for check_compile, with
245 # TYPE implicitly being "executable".
246 proc check_runtime_nocache {basename contents args} {
247 global tool
248
249 set result [eval [list check_compile $basename executable $contents] $args]
250 set lines [lindex $result 0]
251 set output [lindex $result 1]
252
253 set ok 0
254 if { [string match "" $lines] } {
255 # No error messages, everything is OK.
256 set result [remote_load target "./$output" "" ""]
257 set status [lindex $result 0]
258 verbose "check_runtime_nocache $basename: status is <$status>" 2
259 if { $status == "pass" } {
260 set ok 1
261 }
262 }
263 remote_file build delete $output
264 return $ok
265 }
266
267 # Like check_runtime_nocache, but cache the result. PROP is the
268 # property we're checking, and doubles as a prefix for temporary
269 # filenames.
270 proc check_runtime {prop args} {
271 global tool
272
273 return [check_cached_effective_target $prop {
274 eval [list check_runtime_nocache $prop] $args
275 }]
276 }
277
278 # Return 1 if GCC was configured with $pattern.
279 proc check_configured_with { pattern } {
280 global tool
281
282 set options [list "additional_flags=-v"]
283 set gcc_output [${tool}_target_compile "" "" "none" $options]
284 if { [ regexp "Configured with: \[^\n\]*$pattern" $gcc_output ] } {
285 verbose "Matched: $pattern" 2
286 return 1
287 }
288
289 verbose "Failed to match: $pattern" 2
290 return 0
291 }
292
293 ###############################
294 # proc check_weak_available { }
295 ###############################
296
297 # weak symbols are only supported in some configs/object formats
298 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
299
300 proc check_weak_available { } {
301 global target_cpu
302
303 # All mips targets should support it
304
305 if { [ string first "mips" $target_cpu ] >= 0 } {
306 return 1
307 }
308
309 # All AIX targets should support it
310
311 if { [istarget *-*-aix*] } {
312 return 1
313 }
314
315 # All solaris2 targets should support it
316
317 if { [istarget *-*-solaris2*] } {
318 return 1
319 }
320
321 # Windows targets Cygwin and MingW32 support it
322
323 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
324 return 1
325 }
326
327 # nvptx (nearly) supports it
328
329 if { [istarget nvptx-*-*] } {
330 return 1
331 }
332
333 # pdp11 doesn't support it
334
335 if { [istarget pdp11*-*-*] } {
336 return 0
337 }
338
339 # VxWorks hardly supports it (vx7 RTPs only)
340
341 if { [istarget *-*-vxworks*] } {
342 return 0
343 }
344
345 # ELF and ECOFF support it. a.out does with gas/gld but may also with
346 # other linkers, so we should try it
347
348 set objformat [gcc_target_object_format]
349
350 switch $objformat {
351 elf { return 1 }
352 ecoff { return 1 }
353 a.out { return 1 }
354 mach-o { return 1 }
355 som { return 1 }
356 unknown { return -1 }
357 default { return 0 }
358 }
359 }
360
361 # return options to add to enable weak undefined symbols.
362
363 proc add_options_for_weak_undefined { flags } {
364 if { [istarget *-*-darwin*] } {
365 lappend flags "-Wl,-undefined,dynamic_lookup"
366 if { [istarget *-*-darwin\[89\]*] } {
367 lappend flags "-Wl,-flat_namespace"
368 }
369 }
370 return $flags
371 }
372
373 # return 1 if weak undefined symbols are supported.
374
375 proc check_effective_target_weak_undefined { } {
376 if { [istarget hppa*-*-hpux*] } {
377 return 0
378 }
379 return [check_runtime weak_undefined {
380 extern void foo () __attribute__((weak));
381 int main (void) { if (foo) return 1; return 0; }
382 } [add_options_for_weak_undefined ""]]
383 }
384
385 ###############################
386 # proc check_weak_override_available { }
387 ###############################
388
389 # Like check_weak_available, but return 0 if weak symbol definitions
390 # cannot be overridden.
391
392 proc check_weak_override_available { } {
393 if { [istarget *-*-mingw*] } {
394 return 0
395 }
396 return [check_weak_available]
397 }
398
399 # Return 1 if VMA is equal to LMA for the .data section, 0
400 # otherwise. Cache the result.
401
402 proc check_effective_target_vma_equals_lma { } {
403 global tool
404
405 return [check_cached_effective_target vma_equals_lma {
406 set src vma_equals_lma[pid].c
407 set exe vma_equals_lma[pid].exe
408 verbose "check_effective_target_vma_equals_lma compiling testfile $src" 2
409 set f [open $src "w"]
410 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
411 puts $f "int foo = 42; void main() {}"
412 close $f
413 set lines [${tool}_target_compile $src $exe executable ""]
414 file delete $src
415
416 if [string match "" $lines] then {
417 # No error messages
418
419 set objdump_name [find_binutils_prog objdump]
420 set output [remote_exec host "$objdump_name" "--section-headers --section=.data $exe"]
421 set output [lindex $output 1]
422
423 remote_file build delete $exe
424
425 # Example output of objdump:
426 #vma_equals_lma9059.exe: file format elf32-littlearm
427 #
428 #Sections:
429 #Idx Name Size VMA LMA File off Algn
430 # 6 .data 00000558 20000000 08002658 00020000 2**3
431 # CONTENTS, ALLOC, LOAD, DATA
432
433 # Capture LMA and VMA columns for .data section
434 if ![ regexp {\d*\d+\s+\.data\s+\d+\s+(\d+)\s+(\d+)} $output dummy vma lma ] {
435 verbose "Could not parse objdump output" 2
436 return 0
437 } else {
438 return [string equal $vma $lma]
439 }
440 } else {
441 remote_file build delete $exe
442 verbose "Could not determine if VMA is equal to LMA. Assuming not equal." 2
443 return 0
444 }
445 }]
446 }
447
448 # The "noinit" attribute is only supported by some targets.
449 # This proc returns 1 if it's supported, 0 if it's not.
450
451 proc check_effective_target_noinit { } {
452 if { [istarget arm*-*-eabi]
453 || [istarget msp430-*-*] } {
454 return 1
455 }
456
457 return 0
458 }
459
460 # The "persistent" attribute is only supported by some targets.
461 # This proc returns 1 if it's supported, 0 if it's not.
462
463 proc check_effective_target_persistent { } {
464 if { [istarget arm*-*-eabi]
465 || [istarget msp430-*-*] } {
466 return 1
467 }
468
469 return 0
470 }
471
472 ###############################
473 # proc check_visibility_available { what_kind }
474 ###############################
475
476 # The visibility attribute is only support in some object formats
477 # This proc returns 1 if it is supported, 0 if not.
478 # The argument is the kind of visibility, default/protected/hidden/internal.
479
480 proc check_visibility_available { what_kind } {
481 if [string match "" $what_kind] { set what_kind "hidden" }
482
483 return [check_no_compiler_messages visibility_available_$what_kind object "
484 void f() __attribute__((visibility(\"$what_kind\")));
485 void f() {}
486 "]
487 }
488
489 ###############################
490 # proc check_alias_available { }
491 ###############################
492
493 # Determine if the target toolchain supports the alias attribute.
494
495 # Returns 2 if the target supports aliases. Returns 1 if the target
496 # only supports weak aliased. Returns 0 if the target does not
497 # support aliases at all. Returns -1 if support for aliases could not
498 # be determined.
499
500 proc check_alias_available { } {
501 global tool
502
503 return [check_cached_effective_target alias_available {
504 set src alias[pid].c
505 set obj alias[pid].o
506 verbose "check_alias_available compiling testfile $src" 2
507 set f [open $src "w"]
508 # Compile a small test program. The definition of "g" is
509 # necessary to keep the Solaris assembler from complaining
510 # about the program.
511 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
512 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
513 close $f
514 set lines [${tool}_target_compile $src $obj object ""]
515 file delete $src
516 remote_file build delete $obj
517
518 if [string match "" $lines] then {
519 # No error messages, everything is OK.
520 return 2
521 } else {
522 if [regexp "alias definitions not supported" $lines] {
523 verbose "check_alias_available target does not support aliases" 2
524
525 set objformat [gcc_target_object_format]
526
527 if { $objformat == "elf" } {
528 verbose "check_alias_available but target uses ELF format, so it ought to" 2
529 return -1
530 } else {
531 return 0
532 }
533 } else {
534 if [regexp "only weak aliases are supported" $lines] {
535 verbose "check_alias_available target supports only weak aliases" 2
536 return 1
537 } else {
538 return -1
539 }
540 }
541 }
542 }]
543 }
544
545 # Returns 1 if the target toolchain supports strong aliases, 0 otherwise.
546
547 proc check_effective_target_alias { } {
548 if { [check_alias_available] < 2 } {
549 return 0
550 } else {
551 return 1
552 }
553 }
554
555 # Returns 1 if the target uses the ELF object format, 0 otherwise.
556
557 proc check_effective_target_elf { } {
558 if { [gcc_target_object_format] == "elf" } {
559 return 1;
560 } else {
561 return 0;
562 }
563 }
564
565 # Returns 1 if the target toolchain supports ifunc, 0 otherwise.
566
567 proc check_ifunc_available { } {
568 return [check_no_compiler_messages ifunc_available object {
569 #ifdef __cplusplus
570 extern "C" {
571 #endif
572 extern void f_ ();
573 typedef void F (void);
574 F* g (void) { return &f_; }
575 void f () __attribute__ ((ifunc ("g")));
576 #ifdef __cplusplus
577 }
578 #endif
579 }]
580 }
581
582 # Returns true if --gc-sections is supported on the target.
583
584 proc check_gc_sections_available { } {
585 global tool
586
587 return [check_cached_effective_target gc_sections_available {
588 # Some targets don't support gc-sections despite whatever's
589 # advertised by ld's options.
590 if { [istarget alpha*-*-*]
591 || [istarget ia64-*-*] } {
592 return 0
593 }
594
595 # elf2flt uses -q (--emit-relocs), which is incompatible with
596 # --gc-sections.
597 if { [board_info target exists ldflags]
598 && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
599 return 0
600 }
601
602 # VxWorks kernel modules are relocatable objects linked with -r,
603 # while RTP executables are linked with -q (--emit-relocs).
604 # Both of these options are incompatible with --gc-sections.
605 if { [istarget *-*-vxworks*] } {
606 return 0
607 }
608
609 # Check if the ld used by gcc supports --gc-sections.
610 set options [list "additional_flags=-print-prog-name=ld"]
611 set gcc_ld [lindex [${tool}_target_compile "" "" "none" $options] 0]
612 set ld_output [remote_exec host "$gcc_ld" "--help"]
613 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
614 return 1
615 } else {
616 return 0
617 }
618 }]
619 }
620
621 # Returns 1 if "dot" is supported on the host.
622
623 proc check_dot_available { } {
624 verbose "check_dot_available" 2
625
626 set status [remote_exec host "dot" "-V"]
627 verbose " status: $status" 2
628 if { [lindex $status 0] != 0 } {
629 return 0
630 }
631 return 1
632 }
633
634 # Return 1 if according to target_info struct and explicit target list
635 # target is supposed to support trampolines.
636
637 proc check_effective_target_trampolines { } {
638 if [target_info exists gcc,no_trampolines] {
639 return 0
640 }
641 if { [istarget avr-*-*]
642 || [istarget msp430-*-*]
643 || [istarget nvptx-*-*]
644 || [istarget ft32-*-*]
645 || [istarget pru-*-*]
646 || [istarget bpf-*-*] } {
647 return 0;
648 }
649 return 1
650 }
651
652 # Return 1 if target has limited stack size.
653
654 proc check_effective_target_stack_size { } {
655 # For nvptx target, stack size limits are relevant for execution only.
656 if { [istarget nvptx-*-*] } {
657 set dg-do-what [find-dg-do-what]
658 if { ![llength ${dg-do-what}] } {
659 error "unexpected call stack"
660 }
661 if { ![string equal [lindex ${dg-do-what} 0] run] } {
662 return 0
663 }
664 }
665
666 if [target_info exists gcc,stack_size] {
667 return 1
668 }
669 return 0
670 }
671
672 # Return the value attribute of an effective target, otherwise return 0.
673
674 proc dg-effective-target-value { effective_target } {
675 if { "$effective_target" == "stack_size" } {
676 if [check_effective_target_stack_size] {
677 return [target_info gcc,stack_size]
678 }
679 }
680
681 return 0
682 }
683
684 # Return 1 if signal.h is supported.
685
686 proc check_effective_target_signal { } {
687 if [target_info exists gcc,signal_suppress] {
688 return 0
689 }
690 return 1
691 }
692
693 # Return 1 if according to target_info struct and explicit target list
694 # target disables -fdelete-null-pointer-checks. Targets should return 0
695 # if they simply default to -fno-delete-null-pointer-checks but obey
696 # -fdelete-null-pointer-checks when passed explicitly (and tests that
697 # depend on this option should do that).
698
699 proc check_effective_target_keeps_null_pointer_checks { } {
700 if [target_info exists keeps_null_pointer_checks] {
701 return 1
702 }
703 if { [istarget msp430-*-*]
704 || [istarget avr-*-*] } {
705 return 1;
706 }
707 return 0
708 }
709
710 # Return the autofdo profile wrapper
711
712 # Linux by default allows 516KB of perf event buffers
713 # in /proc/sys/kernel/perf_event_mlock_kb
714 # Each individual perf tries to grab it
715 # This causes problems with parallel test suite runs. Instead
716 # limit us to 8 pages (32K), which should be good enough
717 # for the small test programs. With the default settings
718 # this allows parallelism of 16 and higher of parallel gcc-auto-profile
719 proc profopt-perf-wrapper { } {
720 global srcdir
721 return "$srcdir/../config/i386/gcc-auto-profile --all -m8 "
722 }
723
724 # Return true if profiling is supported on the target.
725
726 proc check_profiling_available { test_what } {
727 verbose "Profiling argument is <$test_what>" 1
728
729 # These conditions depend on the argument so examine them before
730 # looking at the cache variable.
731
732 # Tree profiling requires TLS runtime support.
733 if { $test_what == "-fprofile-generate" } {
734 if { ![check_effective_target_tls_runtime] } {
735 return 0
736 }
737 }
738
739 if { $test_what == "-fauto-profile" } {
740 if { !([check_effective_target_x86] && [istarget *-*-linux*]) } {
741 verbose "autofdo only supported on linux"
742 return 0
743 }
744 # not cross compiling?
745 if { ![isnative] } {
746 verbose "autofdo not supported for non native builds"
747 return 0
748 }
749 set event [profopt-perf-wrapper]
750 if {$event == "" } {
751 verbose "autofdo not supported"
752 return 0
753 }
754 global srcdir
755 set status [remote_exec host "$srcdir/../config/i386/gcc-auto-profile" "-m8 true -v >/dev/null"]
756 if { [lindex $status 0] != 0 } {
757 verbose "autofdo not supported because perf does not work"
758 return 0
759 }
760
761 # no good way to check this in advance -- check later instead.
762 #set status [remote_exec host "create_gcov" "2>/dev/null"]
763 #if { [lindex $status 0] != 255 } {
764 # verbose "autofdo not supported due to missing create_gcov"
765 # return 0
766 #}
767 }
768
769 # Support for -p on solaris2 relies on mcrt1.o which comes with the
770 # vendor compiler. We cannot reliably predict the directory where the
771 # vendor compiler (and thus mcrt1.o) is installed so we can't
772 # necessarily find mcrt1.o even if we have it.
773 if { [istarget *-*-solaris2*] && $test_what == "-p" } {
774 return 0
775 }
776
777 # We don't yet support profiling for MIPS16.
778 if { [istarget mips*-*-*]
779 && ![check_effective_target_nomips16]
780 && ($test_what == "-p" || $test_what == "-pg") } {
781 return 0
782 }
783
784 # MinGW does not support -p.
785 if { [istarget *-*-mingw*] && $test_what == "-p" } {
786 return 0
787 }
788
789 # cygwin does not support -p.
790 if { [istarget *-*-cygwin*] && $test_what == "-p" } {
791 return 0
792 }
793
794 # uClibc does not have gcrt1.o.
795 if { [check_effective_target_uclibc]
796 && ($test_what == "-p" || $test_what == "-pg") } {
797 return 0
798 }
799
800 # Now examine the cache variable.
801 set profiling_working \
802 [check_cached_effective_target profiling_available {
803 # Some targets don't have any implementation of __bb_init_func or are
804 # missing other needed machinery.
805 if {[istarget aarch64*-*-elf]
806 || [istarget am3*-*-linux*]
807 || [istarget amdgcn-*-*]
808 || [istarget arm*-*-eabi*]
809 || [istarget arm*-*-elf]
810 || [istarget arm*-*-symbianelf*]
811 || [istarget avr-*-*]
812 || [istarget bfin-*-*]
813 || [istarget cris-*-*]
814 || [istarget csky-*-elf*]
815 || [istarget fido-*-elf]
816 || [istarget h8300-*-*]
817 || [istarget lm32-*-*]
818 || [istarget m32c-*-elf]
819 || [istarget m68k-*-elf]
820 || [istarget m68k-*-uclinux*]
821 || [istarget mips*-*-elf*]
822 || [istarget mmix-*-*]
823 || [istarget mn10300-*-elf*]
824 || [istarget moxie-*-elf*]
825 || [istarget msp430-*-*]
826 || [istarget nds32*-*-elf]
827 || [istarget nvptx-*-*]
828 || [istarget powerpc-*-eabi*]
829 || [istarget powerpc-*-elf]
830 || [istarget pru-*-*]
831 || [istarget rx-*-*]
832 || [istarget tic6x-*-elf]
833 || [istarget visium-*-*]
834 || [istarget xstormy16-*]
835 || [istarget xtensa*-*-elf]
836 || [istarget *-*-rtems*]
837 || [istarget *-*-vxworks*] } {
838 return 0
839 } else {
840 return 1
841 }
842 }]
843
844 # -pg link test result can't be cached since it may change between
845 # runs.
846 if { $profiling_working == 1
847 && ![check_no_compiler_messages_nocache profiling executable {
848 int main() { return 0; } } "-pg"] } {
849 set profiling_working 0
850 }
851
852 return $profiling_working
853 }
854
855 # Check to see if a target is "freestanding". This is as per the definition
856 # in Section 4 of C99 standard. Effectively, it is a target which supports no
857 # extra headers or libraries other than what is considered essential.
858 proc check_effective_target_freestanding { } {
859 return 0
860 }
861
862 # Return 1 if a hosted implementation of libstdc++ is available
863 # (i.e. not freestanding). Language must be c++.
864 proc check_effective_target_hostedlib { } {
865 if [check_effective_target_freestanding] {
866 return 0
867 }
868 if [check_effective_target_c++] {
869 return [check_no_compiler_messages hostedlib assembly {
870 #include <bits/c++config.h>
871 #if ! _GLIBCXX_HOSTED
872 #error not hosted
873 #endif
874 int hosted;
875 }]
876 }
877 return 1
878 }
879
880 # Check to see that file I/O functions are available.
881 proc check_effective_target_fileio { } {
882 return [check_no_compiler_messages fileio_available executable {
883 #include <stdio.h>
884 int main() {
885 char *n = tmpnam (NULL);
886 FILE *f = fopen (n, "w");
887 fclose (f);
888 remove (n);
889 return 0;
890 } } ""]
891 }
892
893 # Return 1 if target has packed layout of structure members by
894 # default, 0 otherwise. Note that this is slightly different than
895 # whether the target has "natural alignment": both attributes may be
896 # false.
897
898 proc check_effective_target_default_packed { } {
899 return [check_no_compiler_messages default_packed assembly {
900 struct x { char a; long b; } c;
901 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
902 }]
903 }
904
905 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
906 # documentation, where the test also comes from.
907
908 proc check_effective_target_pcc_bitfield_type_matters { } {
909 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
910 # bitfields, but let's stick to the example code from the docs.
911 return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
912 struct foo1 { char x; char :0; char y; };
913 struct foo2 { char x; int :0; char y; };
914 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
915 }]
916 }
917
918 # Add to FLAGS all the target-specific flags needed to use thread-local storage.
919
920 proc add_options_for_tls { flags } {
921 # On AIX, __tls_get_addr/___tls_get_addr only lives in
922 # libthread, so always pass -pthread for native TLS.
923 # Need to duplicate native TLS check from
924 # check_effective_target_tls_native to avoid recursion.
925 if { ([istarget powerpc-ibm-aix*]) &&
926 [check_no_messages_and_pattern tls_native "!emutls" assembly {
927 __thread int i;
928 int f (void) { return i; }
929 void g (int j) { i = j; }
930 }] } {
931 return "-pthread [g++_link_flags [get_multilibs "-pthread"] ] $flags "
932 }
933 return $flags
934 }
935
936 # Return 1 if indirect jumps are supported, 0 otherwise.
937
938 proc check_effective_target_indirect_jumps {} {
939 if { [istarget nvptx-*-*] || [istarget bpf-*-*] } {
940 return 0
941 }
942 return 1
943 }
944
945 # Return 1 if nonlocal goto is supported, 0 otherwise.
946
947 proc check_effective_target_nonlocal_goto {} {
948 if { [istarget nvptx-*-*] || [istarget bpf-*-*] } {
949 return 0
950 }
951 return 1
952 }
953
954 # Return 1 if global constructors are supported, 0 otherwise.
955
956 proc check_effective_target_global_constructor {} {
957 if { [istarget bpf-*-*] } {
958 return 0
959 }
960 return 1
961 }
962
963 # Return 1 if taking label values is supported, 0 otherwise.
964
965 proc check_effective_target_label_values {} {
966 if { [istarget nvptx-*-*] || [target_info exists gcc,no_label_values] } {
967 return 0
968 }
969
970 return 1
971 }
972
973 # Return 1 if builtin_return_address and builtin_frame_address are
974 # supported, 0 otherwise.
975
976 proc check_effective_target_return_address {} {
977 if { [istarget nvptx-*-*] } {
978 return 0
979 }
980 # No notion of return address in eBPF.
981 if { [istarget bpf-*-*] } {
982 return 0
983 }
984 # It could be supported on amdgcn, but isn't yet.
985 if { [istarget amdgcn*-*-*] } {
986 return 0
987 }
988 return 1
989 }
990
991 # Return 1 if the assembler does not verify function types against
992 # calls, 0 otherwise. Such verification will typically show up problems
993 # with K&R C function declarations.
994
995 proc check_effective_target_untyped_assembly {} {
996 if { [istarget nvptx-*-*] } {
997 return 0
998 }
999 return 1
1000 }
1001
1002 # Return 1 if dynamic stack allocation is supported, 0 otherwise.
1003
1004 proc check_effective_target_alloca {} {
1005 if { [istarget bpf-*-*] } {
1006 return 0
1007 }
1008 if { [istarget nvptx-*-*] } {
1009 # For nvptx, 'alloca' support depends on the configuration. In case
1010 # of PTX "native" stacks, for 'dg-do run', it additionally depends on
1011 # runtime support.
1012 if { ![check_effective_target_nvptx_softstack] } {
1013 # '-mno-soft-stack': PTX "native" stacks
1014
1015 # Not supported unless '-mptx=7.3'+ and '-march=sm_52'+.
1016 if { !([check_nvptx_default_ptx_isa_version_at_least 7 3]
1017 && [check_nvptx_default_ptx_isa_target_architecture_at_least sm_52]) } {
1018 return 0
1019 }
1020
1021 set dg-do-what [find-dg-do-what]
1022 if { ![llength ${dg-do-what}] } {
1023 # This happens if 'gcc-dg-prune' etc. get called outside of
1024 # 'dg-test'. For these purposes, assume that dynamic stack
1025 # allocation is supported.
1026 return 1
1027 }
1028 if { [string equal [lindex ${dg-do-what} 0] run] } {
1029 # For 'dg-do run', it additionally depends on runtime support.
1030 # (If not supported, we don't try to demote 'run' to 'link',
1031 # but instead simply fail the effective-target 'alloca' check.)
1032 return [check_effective_target_nvptx_runtime_alloca_ptx]
1033 } else {
1034 return 1
1035 }
1036 } else {
1037 # '-msoft-stack'
1038 return 1
1039 }
1040 }
1041 return 1
1042 }
1043
1044 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
1045
1046 proc check_effective_target_tls {} {
1047 return [check_no_compiler_messages tls assembly {
1048 __thread int i;
1049 int f (void) { return i; }
1050 void g (int j) { i = j; }
1051 }]
1052 }
1053
1054 # Return 1 if we can link using TLS, 0 otherwise.
1055
1056 proc check_effective_target_tls_link {} {
1057 return [check_no_compiler_messages tls_link executable {
1058 __thread int i;
1059 int main (void) { return i; }
1060 void g (int j) { i = j; }
1061 }]
1062 }
1063
1064 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
1065
1066 proc check_effective_target_tls_native {} {
1067 # VxWorks uses emulated TLS machinery, but with non-standard helper
1068 # functions, so we fail to automatically detect it.
1069 if { [istarget *-*-vxworks*] } {
1070 return 0
1071 }
1072
1073 return [check_no_messages_and_pattern tls_native "!emutls" assembly {
1074 __thread int i;
1075 int f (void) { return i; }
1076 void g (int j) { i = j; }
1077 }]
1078 }
1079
1080 # Return 1 if *emulated* thread local storage (TLS) is supported, 0 otherwise.
1081
1082 proc check_effective_target_tls_emulated {} {
1083 # VxWorks uses emulated TLS machinery, but with non-standard helper
1084 # functions, so we fail to automatically detect it.
1085 if { [istarget *-*-vxworks*] } {
1086 return 1
1087 }
1088
1089 return [check_no_messages_and_pattern tls_emulated "emutls" assembly {
1090 __thread int i;
1091 int f (void) { return i; }
1092 void g (int j) { i = j; }
1093 }]
1094 }
1095
1096 # Return 1 if TLS executables can run correctly, 0 otherwise.
1097
1098 proc check_effective_target_tls_runtime {} {
1099 return [check_runtime tls_runtime {
1100 __thread int thr __attribute__((tls_model("global-dynamic"))) = 0;
1101 int main (void) { return thr; }
1102 } [add_options_for_tls ""]]
1103 }
1104
1105 # Return 1 if atomic compare-and-swap is supported on 'int'
1106
1107 proc check_effective_target_cas_char {} {
1108 return [check_no_compiler_messages cas_char assembly {
1109 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
1110 #error unsupported
1111 #endif
1112 } ""]
1113 }
1114
1115 proc check_effective_target_cas_int {} {
1116 return [check_no_compiler_messages cas_int assembly {
1117 #if __INT_MAX__ == 0x7fff && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
1118 /* ok */
1119 #elif __INT_MAX__ == 0x7fffffff && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1120 /* ok */
1121 #else
1122 #error unsupported
1123 #endif
1124 } ""]
1125 }
1126
1127 # Return 1 if -ffunction-sections is supported, 0 otherwise.
1128
1129 proc check_effective_target_function_sections {} {
1130 # Darwin has its own scheme and silently accepts -ffunction-sections.
1131 if { [istarget *-*-darwin*] } {
1132 return 0
1133 }
1134
1135 return [check_no_compiler_messages functionsections assembly {
1136 void foo (void) { }
1137 } "-ffunction-sections"]
1138 }
1139
1140 # Return 1 if instruction scheduling is available, 0 otherwise.
1141
1142 proc check_effective_target_scheduling {} {
1143 return [check_no_compiler_messages scheduling object {
1144 void foo (void) { }
1145 } "-fschedule-insns"]
1146 }
1147
1148 # Return 1 if trapping arithmetic is available, 0 otherwise.
1149
1150 proc check_effective_target_trapping {} {
1151 return [check_no_compiler_messages trapping object {
1152 int add (int a, int b) { return a + b; }
1153 } "-ftrapv"]
1154 }
1155
1156 # Return 1 if compilation with -fgraphite is error-free for trivial
1157 # code, 0 otherwise.
1158
1159 proc check_effective_target_fgraphite {} {
1160 return [check_no_compiler_messages fgraphite object {
1161 void foo (void) { }
1162 } "-O1 -fgraphite"]
1163 }
1164
1165 # Return 1 if compiled with --enable-offload-targets=
1166 # This affects host compilation as ENABLE_OFFLOAD then evaluates to true.
1167 proc check_effective_target_offloading_enabled {} {
1168 return [check_configured_with "--enable-offload-targets"]
1169 }
1170
1171 # Return 1 if compilation with -fopenacc is error-free for trivial
1172 # code, 0 otherwise.
1173
1174 proc check_effective_target_fopenacc {} {
1175 # nvptx/amdgcn can be built with the device-side bits of openacc, but it
1176 # does not make sense to test it as an openacc host.
1177 if [istarget nvptx-*-*] { return 0 }
1178 if [istarget amdgcn-*-*] { return 0 }
1179
1180 return [check_no_compiler_messages fopenacc object {
1181 void foo (void) { }
1182 } "-fopenacc"]
1183 }
1184
1185 # Return 1 if compilation with -fopenmp is error-free for trivial
1186 # code, 0 otherwise.
1187
1188 proc check_effective_target_fopenmp {} {
1189 # nvptx/amdgcn can be built with the device-side bits of libgomp, but it
1190 # does not make sense to test it as an openmp host.
1191 if [istarget nvptx-*-*] { return 0 }
1192 if [istarget amdgcn-*-*] { return 0 }
1193
1194 return [check_no_compiler_messages fopenmp object {
1195 void foo (void) { }
1196 } "-fopenmp"]
1197 }
1198
1199 # Return 1 if compilation with -fgnu-tm is error-free for trivial
1200 # code, 0 otherwise.
1201
1202 proc check_effective_target_fgnu_tm {} {
1203 return [check_no_compiler_messages fgnu_tm object {
1204 void foo (void) { }
1205 } "-fgnu-tm"]
1206 }
1207
1208 # Return 1 if the target supports mmap, 0 otherwise.
1209
1210 proc check_effective_target_mmap {} {
1211 return [check_function_available "mmap"]
1212 }
1213
1214 # Return 1 if the target supports sysconf, 0 otherwise.
1215
1216 proc check_effective_target_sysconf {} {
1217 # VxWorks has sysconf in rtp mode only, but our way to test can't
1218 # tell kernel mode doesn't, as we're doing partial links for
1219 # kernel modules. We can tell by checking for a declaration, or
1220 # for some sysconf parm, because configurations that don't offer
1221 # sysconf don't have either.
1222 if { [istarget *-*-vxworks*] } {
1223 return [check_no_compiler_messages sysconfdecl assembly {
1224 #include <unistd.h>
1225 int f() { return sysconf(_SC_PAGESIZE); }
1226 }];
1227 }
1228 return [check_function_available "sysconf"]
1229 }
1230
1231 # Return 1 if the target supports dlopen, 0 otherwise.
1232 proc check_effective_target_dlopen {} {
1233 return [check_no_compiler_messages dlopen executable {
1234 #include <dlfcn.h>
1235 int main(void) { dlopen ("dummy.so", RTLD_NOW); }
1236 } [add_options_for_dlopen ""]]
1237 }
1238
1239 proc add_options_for_dlopen { flags } {
1240 return "$flags -ldl"
1241 }
1242
1243 # Return 1 if the target supports clone, 0 otherwise.
1244 proc check_effective_target_clone {} {
1245 return [check_function_available "clone"]
1246 }
1247
1248 # Return 1 if the target supports posix_memalign, 0 otherwise.
1249 proc check_effective_target_posix_memalign {} {
1250 if { [istarget *-*-vxworks*] } {
1251 # VxWorks doesn't have posix_memalign but our way to test
1252 # can't tell as we're doing partial links for kernel modules.
1253 return 0
1254 }
1255 return [check_function_available "posix_memalign"]
1256 }
1257
1258 # Return 1 if the target supports setrlimit, 0 otherwise.
1259 proc check_effective_target_setrlimit {} {
1260 # Darwin has non-posix compliant RLIMIT_AS
1261 if { [istarget *-*-darwin*] } {
1262 return 0
1263 }
1264 return [check_function_available "setrlimit"]
1265 }
1266
1267 # Return 1 if the target supports gettimeofday, 0 otherwise.
1268 proc check_effective_target_gettimeofday {} {
1269 return [check_function_available "gettimeofday"]
1270 }
1271
1272 # Return 1 if the target supports swapcontext, 0 otherwise.
1273 proc check_effective_target_swapcontext {} {
1274 return [check_no_compiler_messages swapcontext executable {
1275 #include <ucontext.h>
1276 int main (void)
1277 {
1278 ucontext_t orig_context,child_context;
1279 if (swapcontext(&child_context, &orig_context) < 0) { }
1280 }
1281 }]
1282 }
1283
1284 # Return 1 if the target supports POSIX threads, 0 otherwise.
1285 proc check_effective_target_pthread {} {
1286 return [check_no_compiler_messages pthread object {
1287 #include <pthread.h>
1288 void foo (void) { }
1289 } "-pthread"]
1290 }
1291
1292 # Return 1 if the target supports both Unix and internet sockets, 0 otherwise.
1293 proc check_effective_target_sockets {} {
1294 return [check_no_compiler_messages socket executable {
1295 #include <sys/socket.h>
1296 #include <sys/un.h>
1297 #include <netinet/in.h>
1298 int main (void) {
1299 socket(AF_UNIX, SOCK_STREAM, 0);
1300 socket(AF_INET, SOCK_DGRAM, 0);
1301 return 0;
1302 }
1303 } ""]
1304 }
1305
1306 # Return 1 if compilation with -mpe-aligned-commons is error-free
1307 # for trivial code, 0 otherwise.
1308
1309 proc check_effective_target_pe_aligned_commons {} {
1310 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
1311 return [check_no_compiler_messages pe_aligned_commons object {
1312 int foo;
1313 } "-mpe-aligned-commons"]
1314 }
1315 return 0
1316 }
1317
1318 # Return 1 if the target supports -static
1319 proc check_effective_target_static {} {
1320 if { [istarget arm*-*-uclinuxfdpiceabi] } {
1321 return 0;
1322 }
1323 return [check_no_compiler_messages static executable {
1324 int main (void) { return 0; }
1325 } "-static"]
1326 }
1327
1328 # Return 1 if the target supports -fstack-protector
1329 proc check_effective_target_fstack_protector {} {
1330 if { [istarget hppa*-*-*] } {
1331 return 0;
1332 }
1333 return [check_runtime fstack_protector {
1334 #include <string.h>
1335 int main (int argc, char *argv[]) {
1336 char buf[64];
1337 return !strcpy (buf, strrchr (argv[0], '/'));
1338 }
1339 } "-fstack-protector"]
1340 }
1341
1342 # Return 1 if the target supports -fstack-check or -fstack-check=$stack_kind
1343 proc check_stack_check_available { stack_kind } {
1344 if [string match "" $stack_kind] then {
1345 set stack_opt "-fstack-check"
1346 } else { set stack_opt "-fstack-check=$stack_kind" }
1347
1348 return [check_no_compiler_messages stack_check_$stack_kind executable {
1349 int main (void) { return 0; }
1350 } "$stack_opt"]
1351 }
1352
1353 # Return 1 if the target supports stack scrubbing.
1354 proc check_effective_target_strub {} {
1355 return [check_no_compiler_messages strub assembly {
1356 void __attribute__ ((__strub__)) fn (void) {}
1357 } ""]
1358 }
1359
1360 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
1361 # for trivial code, 0 otherwise. As some targets (ARM for example) only
1362 # warn when -fprofile-use is also supplied we test that combination too.
1363
1364 proc check_effective_target_freorder {} {
1365 if { [check_no_compiler_messages freorder object {
1366 void foo (void) { }
1367 } "-freorder-blocks-and-partition"]
1368 && [check_no_compiler_messages fprofile_use_freorder object {
1369 void foo (void) { }
1370 } "-fprofile-use -freorder-blocks-and-partition -Wno-missing-profile"] } {
1371 return 1
1372 }
1373 return 0
1374 }
1375
1376 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
1377 # emitted, 0 otherwise. Whether a shared library can actually be built is
1378 # out of scope for this test.
1379
1380 proc check_effective_target_fpic { } {
1381 # Note that M68K has a multilib that supports -fpic but not
1382 # -fPIC, so we need to check both. We test with a program that
1383 # requires GOT references.
1384 foreach arg {fpic fPIC} {
1385 if [check_no_compiler_messages $arg object {
1386 extern int foo (void); extern int bar;
1387 int baz (void) { return foo () + bar; }
1388 } "-$arg"] {
1389 return 1
1390 }
1391 }
1392 return 0
1393 }
1394
1395 # On AArch64, if -fpic is not supported, then we will fall back to -fPIC
1396 # silently. So, we can't rely on above "check_effective_target_fpic" as it
1397 # assumes compiler will give warning if -fpic not supported. Here we check
1398 # whether binutils supports those new -fpic relocation modifiers, and assume
1399 # -fpic is supported if there is binutils support. GCC configuration will
1400 # enable -fpic for AArch64 in this case.
1401 #
1402 # "check_effective_target_aarch64_small_fpic" is dedicated for checking small
1403 # memory model -fpic relocation types.
1404
1405 proc check_effective_target_aarch64_small_fpic { } {
1406 if { [istarget aarch64*-*-*] } {
1407 return [check_no_compiler_messages aarch64_small_fpic object {
1408 void foo (void) { asm ("ldr x0, [x2, #:gotpage_lo15:globalsym]"); }
1409 }]
1410 } else {
1411 return 0
1412 }
1413 }
1414
1415 # On AArch64, instruction sequence for TLS LE under -mtls-size=32 will utilize
1416 # the relocation modifier "tprel_g0_nc" together with MOVK, it's only supported
1417 # in binutils since 2015-03-04 as PR gas/17843.
1418 #
1419 # This test directive make sure binutils support all features needed by TLS LE
1420 # under -mtls-size=32 on AArch64.
1421
1422 proc check_effective_target_aarch64_tlsle32 { } {
1423 if { [istarget aarch64*-*-*] } {
1424 return [check_no_compiler_messages aarch64_tlsle32 object {
1425 void foo (void) { asm ("movk x1,#:tprel_g0_nc:t1"); }
1426 }]
1427 } else {
1428 return 0
1429 }
1430 }
1431
1432 # Return 1 if -shared is supported, as in no warnings or errors
1433 # emitted, 0 otherwise.
1434
1435 proc check_effective_target_shared { } {
1436 # Darwin's linker defaults to error on undefined (which makes it look as
1437 # if we do not support shared) but we can tell it to allow the symbols used
1438 # here to be undefined.
1439 set extra_flags ""
1440 if { [istarget *-*-darwin\[912\]*] } {
1441 set extra_flags "-Wl,-U,_foo,-U,_bar,-U,__Z3foov"
1442 }
1443 # Note that M68K has a multilib that supports -fpic but not
1444 # -fPIC, so we need to check both. We test with a program that
1445 # requires GOT references, and with a libc symbol that would
1446 # bring in significant parts of a static-only libc. Absent a
1447 # shared libc, this would make -shared tests fail, so we don't
1448 # want to enable the shared effective target then.
1449 return [check_no_compiler_messages shared executable {
1450 #include <stdlib.h>
1451 extern int foo (void); extern int bar;
1452 char *baz (void) {
1453 return foo () + (char*) malloc (bar);
1454 }
1455 } "-shared -fpic $extra_flags"]
1456 }
1457
1458 # Return 1 if -pie, -fpie and -fPIE are supported, 0 otherwise.
1459
1460 proc check_effective_target_pie { } {
1461 if { [istarget *-*-darwin\[912\]*]
1462 || [istarget *-*-dragonfly*]
1463 || [istarget *-*-freebsd*]
1464 || [istarget *-*-linux*]
1465 || [istarget arm*-*-uclinuxfdpiceabi]
1466 || [istarget *-*-solaris2*]
1467 || [istarget *-*-gnu*]
1468 || [istarget *-*-amdhsa]} {
1469 return 1;
1470 }
1471 return 0
1472 }
1473
1474 # Return true if the target supports -mpaired-single (as used on MIPS).
1475
1476 proc check_effective_target_mpaired_single { args } {
1477 return [check_no_compiler_messages mpaired_single object {
1478 void foo (void) { }
1479 } "$args"]
1480 }
1481
1482 # Return true if the target has access to FPU instructions.
1483
1484 proc check_effective_target_hard_float { } {
1485 # This should work on cores that only have single-precision,
1486 # and should also correctly handle legacy cores that had thumb1 and
1487 # lacked FP support for that, but had it in Arm state.
1488 if { [istarget arm*-*-*] } {
1489 return [check_no_compiler_messages hard_float assembly {
1490 #if __ARM_FP == 0
1491 #error __arm_soft_float
1492 #endif
1493 }]
1494 }
1495
1496 if { [istarget loongarch*-*-*] } {
1497 return [check_no_compiler_messages hard_float assembly {
1498 #if (defined __loongarch_soft_float)
1499 #error __loongarch_soft_float
1500 #endif
1501 }]
1502 }
1503
1504 if { [istarget mips*-*-*] } {
1505 return [check_no_compiler_messages hard_float assembly {
1506 #if (defined __mips_soft_float || defined __mips16)
1507 #error __mips_soft_float || __mips16
1508 #endif
1509 }]
1510 }
1511
1512 # This proc is actually checking the availabilty of FPU
1513 # support for doubles, so on the RX we must fail if the
1514 # 64-bit double multilib has been selected.
1515 if { [istarget rx-*-*] } {
1516 return 0
1517 # return [check_no_compiler_messages hard_float assembly {
1518 #if defined __RX_64_BIT_DOUBLES__
1519 #error __RX_64_BIT_DOUBLES__
1520 #endif
1521 # }]
1522 }
1523
1524 # The generic test doesn't work for C-SKY because some cores have
1525 # hard float for single precision only.
1526 if { [istarget csky*-*-*] } {
1527 return [check_no_compiler_messages hard_float assembly {
1528 #if defined __csky_soft_float__
1529 #error __csky_soft_float__
1530 #endif
1531 }]
1532 }
1533
1534 # The generic test equates hard_float with "no call for adding doubles".
1535 return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
1536 double a (double b, double c) { return b + c; }
1537 }]
1538 }
1539
1540 # Return true if the target is a 64-bit MIPS target.
1541
1542 proc check_effective_target_mips64 { } {
1543 return [check_no_compiler_messages mips64 assembly {
1544 #ifndef __mips64
1545 #error !__mips64
1546 #endif
1547 }]
1548 }
1549
1550 # Return true if the target is a MIPS target that does not produce
1551 # MIPS16 code.
1552
1553 proc check_effective_target_nomips16 { } {
1554 return [check_no_compiler_messages nomips16 object {
1555 #ifndef __mips
1556 #error !__mips
1557 #else
1558 /* A cheap way of testing for -mflip-mips16. */
1559 void foo (void) { asm ("addiu $20,$20,1"); }
1560 void bar (void) { asm ("addiu $20,$20,1"); }
1561 #endif
1562 }]
1563 }
1564
1565 # Add the options needed for MIPS16 function attributes. At the moment,
1566 # we don't support MIPS16 PIC.
1567
1568 proc add_options_for_mips16_attribute { flags } {
1569 return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
1570 }
1571
1572 # Return true if we can force a mode that allows MIPS16 code generation.
1573 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
1574 # for o32 and o64.
1575
1576 proc check_effective_target_mips16_attribute { } {
1577 return [check_no_compiler_messages mips16_attribute assembly {
1578 #ifdef PIC
1579 #error PIC
1580 #endif
1581 #if defined __mips_hard_float \
1582 && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
1583 && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
1584 #error __mips_hard_float && (!_ABIO32 || !_ABIO64)
1585 #endif
1586 } [add_options_for_mips16_attribute ""]]
1587 }
1588
1589 # Return 1 if the target supports long double larger than double when
1590 # using the new ABI, 0 otherwise.
1591
1592 proc check_effective_target_mips_newabi_large_long_double { } {
1593 return [check_no_compiler_messages mips_newabi_large_long_double object {
1594 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1595 } "-mabi=64"]
1596 }
1597
1598 # Return true if the target is a MIPS target that has access
1599 # to the LL and SC instructions.
1600
1601 proc check_effective_target_mips_llsc { } {
1602 if { ![istarget mips*-*-*] } {
1603 return 0
1604 }
1605 # Assume that these instructions are always implemented for
1606 # non-elf* targets, via emulation if necessary.
1607 if { ![istarget *-*-elf*] } {
1608 return 1
1609 }
1610 # Otherwise assume LL/SC support for everything but MIPS I.
1611 return [check_no_compiler_messages mips_llsc assembly {
1612 #if __mips == 1
1613 #error __mips == 1
1614 #endif
1615 }]
1616 }
1617
1618 # Return true if the target is a MIPS target that uses in-place relocations.
1619
1620 proc check_effective_target_mips_rel { } {
1621 if { ![istarget mips*-*-*] } {
1622 return 0
1623 }
1624 return [check_no_compiler_messages mips_rel object {
1625 #if (defined _ABIN32 && _MIPS_SIM == _ABIN32) \
1626 || (defined _ABI64 && _MIPS_SIM == _ABI64)
1627 #error _ABIN32 && (_ABIN32 || _ABI64)
1628 #endif
1629 }]
1630 }
1631
1632 # Return true if the target is a MIPS target that uses the EABI.
1633
1634 proc check_effective_target_mips_eabi { } {
1635 if { ![istarget mips*-*-*] } {
1636 return 0
1637 }
1638 return [check_no_compiler_messages mips_eabi object {
1639 #ifndef __mips_eabi
1640 #error !__mips_eabi
1641 #endif
1642 }]
1643 }
1644
1645 # Return 1 if the current multilib does not generate PIC by default.
1646
1647 proc check_effective_target_nonpic { } {
1648 return [check_no_compiler_messages nonpic assembly {
1649 #if __PIC__
1650 #error __PIC__
1651 #endif
1652 }]
1653 }
1654
1655 # Return 1 if the current multilib generates PIE by default.
1656
1657 proc check_effective_target_pie_enabled { } {
1658 return [check_no_compiler_messages pie_enabled assembly {
1659 #ifndef __PIE__
1660 #error unsupported
1661 #endif
1662 }]
1663 }
1664
1665 # Return 1 if the target generates -fstack-protector by default.
1666
1667 proc check_effective_target_fstack_protector_enabled {} {
1668 return [ check_no_compiler_messages fstack_protector_enabled assembly {
1669 #if !defined(__SSP__) && !defined(__SSP_ALL__) && \
1670 !defined(__SSP_STRONG__) && !defined(__SSP_EXPICIT__)
1671 #error unsupported
1672 #endif
1673 }]
1674 }
1675
1676 # Return 1 if the target does not use a status wrapper.
1677
1678 proc check_effective_target_unwrapped { } {
1679 if { [target_info needs_status_wrapper] != "" \
1680 && [target_info needs_status_wrapper] != "0" } {
1681 return 0
1682 }
1683 return 1
1684 }
1685
1686 # Return true if iconv is supported on the target. In particular IBM1047.
1687
1688 proc check_iconv_available { test_what } {
1689 global libiconv
1690
1691 # If the tool configuration file has not set libiconv, try "-liconv"
1692 if { ![info exists libiconv] } {
1693 set libiconv "-liconv"
1694 }
1695 set test_what [lindex $test_what 1]
1696 return [check_runtime_nocache $test_what [subst {
1697 #include <iconv.h>
1698 int main (void)
1699 {
1700 iconv_t cd;
1701
1702 cd = iconv_open ("$test_what", "UTF-8");
1703 if (cd == (iconv_t) -1)
1704 return 1;
1705 return 0;
1706 }
1707 }] $libiconv]
1708 }
1709
1710 # Return true if the atomic library is supported on the target.
1711 proc check_effective_target_libatomic_available { } {
1712 return [check_no_compiler_messages libatomic_available executable {
1713 int main (void) { return 0; }
1714 } "-latomic"]
1715 }
1716
1717 # Return 1 if an ASCII locale is supported on this host, 0 otherwise.
1718
1719 proc check_ascii_locale_available { } {
1720 return 1
1721 }
1722
1723 # Return true if named sections are supported on this target.
1724
1725 proc check_named_sections_available { } {
1726 return [check_no_compiler_messages named_sections assembly {
1727 int __attribute__ ((section("whatever"))) foo;
1728 }]
1729 }
1730
1731 # Return true if the "naked" function attribute is supported on this target.
1732
1733 proc check_effective_target_naked_functions { } {
1734 return [check_no_compiler_messages naked_functions assembly {
1735 void f() __attribute__((naked));
1736 }]
1737 }
1738
1739 # Return 1 if the target supports Fortran real kinds larger than real(8),
1740 # 0 otherwise.
1741 #
1742 # When the target name changes, replace the cached result.
1743
1744 proc check_effective_target_fortran_large_real { } {
1745 return [check_no_compiler_messages fortran_large_real executable {
1746 ! Fortran
1747 integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
1748 real(kind=k) :: x
1749 x = cos (x)
1750 end
1751 }]
1752 }
1753
1754 # Return 1 if the target supports Fortran real kind real(16),
1755 # 0 otherwise. Contrary to check_effective_target_fortran_large_real
1756 # this checks for Real(16) only; the other returned real(10) if
1757 # both real(10) and real(16) are available.
1758 #
1759 # When the target name changes, replace the cached result.
1760
1761 proc check_effective_target_fortran_real_16 { } {
1762 return [check_no_compiler_messages fortran_real_16 executable {
1763 ! Fortran
1764 real(kind=16) :: x
1765 x = cos (x)
1766 end
1767 }]
1768 }
1769
1770 # Return 1 if the target supports Fortran real kind 10,
1771 # 0 otherwise. Contrary to check_effective_target_fortran_large_real
1772 # this checks for real(10) only.
1773 #
1774 # When the target name changes, replace the cached result.
1775
1776 proc check_effective_target_fortran_real_10 { } {
1777 return [check_no_compiler_messages fortran_real_10 executable {
1778 ! Fortran
1779 real(kind=10) :: x
1780 x = cos (x)
1781 end
1782 }]
1783 }
1784
1785 # Return 1 if the target supports Fortran real kind C_FLOAT128,
1786 # 0 otherwise. This differs from check_effective_target_fortran_real_16
1787 # because _Float128 has the additional requirement that it be the
1788 # 128-bit IEEE encoding; even if _Float128 is available in C, it may not
1789 # have a corresponding Fortran kind on targets (PowerPC) that use some
1790 # other encoding for long double/TFmode/real(16).
1791 proc check_effective_target_fortran_real_c_float128 { } {
1792 return [check_no_compiler_messages fortran_real_c_float128 executable {
1793 ! Fortran
1794 use iso_c_binding
1795 real(kind=c_float128) :: x
1796 x = cos (x)
1797 end
1798 }]
1799 }
1800
1801 # Return 1 if the target supports Fortran's IEEE modules,
1802 # 0 otherwise.
1803 #
1804 # When the target name changes, replace the cached result.
1805
1806 proc check_effective_target_fortran_ieee { flags } {
1807 return [check_no_compiler_messages fortran_ieee executable {
1808 ! Fortran
1809 use, intrinsic :: ieee_features
1810 end
1811 } $flags ]
1812 }
1813
1814
1815 # Return 1 if the target supports SQRT for the largest floating-point
1816 # type. (Some targets lack the libm support for this FP type.)
1817 # On most targets, this check effectively checks either whether sqrtl is
1818 # available or on __float128 systems whether libquadmath is installed,
1819 # which provides sqrtq.
1820 #
1821 # When the target name changes, replace the cached result.
1822
1823 proc check_effective_target_fortran_largest_fp_has_sqrt { } {
1824 return [check_no_compiler_messages fortran_largest_fp_has_sqrt executable {
1825 ! Fortran
1826 use iso_fortran_env, only: real_kinds
1827 integer,parameter:: maxFP = real_kinds(ubound(real_kinds,dim=1))
1828 real(kind=maxFP), volatile :: x
1829 x = 2.0_maxFP
1830 x = sqrt (x)
1831 end
1832 }]
1833 }
1834
1835
1836 # Return 1 if the target supports Fortran integer kinds larger than
1837 # integer(8), 0 otherwise.
1838 #
1839 # When the target name changes, replace the cached result.
1840
1841 proc check_effective_target_fortran_large_int { } {
1842 return [check_no_compiler_messages fortran_large_int executable {
1843 ! Fortran
1844 integer,parameter :: k = selected_int_kind (range (0_8) + 1)
1845 integer(kind=k) :: i
1846 end
1847 }]
1848 }
1849
1850 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
1851 #
1852 # When the target name changes, replace the cached result.
1853
1854 proc check_effective_target_fortran_integer_16 { } {
1855 return [check_no_compiler_messages fortran_integer_16 executable {
1856 ! Fortran
1857 integer(16) :: i
1858 end
1859 }]
1860 }
1861
1862 # Check if long double on the target defaults to the IBM extended format.
1863
1864 proc check_effective_target_long_double_is_ibm128 { } {
1865 if { ![istarget powerpc*-*-*] } {
1866 return 0
1867 }
1868
1869 return [check_no_compiler_messages long_double_is_ibm128 assembly {
1870 #ifndef __LONG_DOUBLE_IBM128__
1871 #error "__LONG_DOUBLE_IBM128__ not defined"
1872 #endif
1873 }]
1874 }
1875
1876 # Return 1 if we can statically link libgfortran, 0 otherwise.
1877 #
1878 # When the target name changes, replace the cached result.
1879
1880 proc check_effective_target_static_libgfortran { } {
1881 return [check_no_compiler_messages static_libgfortran executable {
1882 ! Fortran
1883 print *, 'test'
1884 end
1885 } "-static"]
1886 }
1887
1888 # Return 1 if we can use the -rdynamic option, 0 otherwise.
1889
1890 proc check_effective_target_rdynamic { } {
1891 return [check_no_compiler_messages rdynamic executable {
1892 int main() { return 0; }
1893 } "-rdynamic"]
1894 }
1895
1896 proc check_linker_plugin_available { } {
1897 return [check_no_compiler_messages_nocache linker_plugin executable {
1898 int main() { return 0; }
1899 } "-flto -fuse-linker-plugin"]
1900 }
1901
1902 # Return 1 if the target is RV32, 0 otherwise. Cache the result.
1903
1904 proc check_effective_target_rv32 { } {
1905 # Check that we are compiling for RV32 by checking the xlen size.
1906 return [check_no_compiler_messages riscv_rv32 assembly {
1907 #if !defined(__riscv_xlen)
1908 #error "__riscv_xlen not defined!"
1909 #else
1910 #if __riscv_xlen != 32
1911 #error "Not RV32"
1912 #endif
1913 #endif
1914 }]
1915 }
1916
1917 # Return 1 if the target is RV64, 0 otherwise. Cache the result.
1918
1919 proc check_effective_target_rv64 { } {
1920 # Check that we are compiling for RV64 by checking the xlen size.
1921 return [check_no_compiler_messages riscv_rv64 assembly {
1922 #if !defined(__riscv_xlen)
1923 #error "__riscv_xlen not defined!"
1924 #else
1925 #if __riscv_xlen != 64
1926 #error "Not RV64"
1927 #endif
1928 #endif
1929 }]
1930 }
1931
1932 # Return 1 if the target abi is __riscv_float_abi_soft, 0 otherwise.
1933 # Cache the result.
1934
1935 proc check_effective_target_rv_float_abi_soft { } {
1936 # Check that we are compiling for RV64 by checking the xlen size.
1937 return [check_no_compiler_messages riscv_riscv_float_abi_soft assembly {
1938 #ifndef __riscv_float_abi_soft
1939 #error "Not __riscv_float_abi_soft"
1940 #endif
1941 }]
1942 }
1943
1944 # Return 1 if the target arch supports the atomic extension, 0 otherwise.
1945 # Cache the result.
1946
1947 proc check_effective_target_riscv_a { } {
1948 return [check_no_compiler_messages riscv_ext_a assembly {
1949 #ifndef __riscv_a
1950 #error "Not __riscv_a"
1951 #endif
1952 }]
1953 }
1954
1955 # Return 1 if the ABI is either ILP32E or ILP64E, 0 otherwise.
1956 # Cache the result.
1957
1958 proc check_effective_target_riscv_abi_e { } {
1959 # If current ISA is E, then only E ABI is supported.
1960 if { [check_no_compiler_messages riscv_abi_e assembly {
1961 #ifndef __riscv_e
1962 #error "Not __riscv_e"
1963 #endif
1964 }] } {
1965 return 1
1966 }
1967
1968 # E ABI can be chosen by both E and I base ISA variants.
1969 #
1970 # TODO - check for I ISA and E ABI combination.
1971
1972 return 0
1973 }
1974
1975 # Return 1 if the target arch supports the atomic LRSC extension, 0 otherwise.
1976 # Cache the result.
1977
1978 proc check_effective_target_riscv_zalrsc { } {
1979 return [check_no_compiler_messages riscv_ext_zalrsc assembly {
1980 #ifndef __riscv_zalrsc
1981 #error "Not __riscv_zalrsc"
1982 #endif
1983 }]
1984 }
1985
1986 # Return 1 if the target arch supports the atomic AMO extension, 0 otherwise.
1987 # Cache the result.
1988
1989 proc check_effective_target_riscv_zaamo { } {
1990 return [check_no_compiler_messages riscv_ext_zaamo assembly {
1991 #ifndef __riscv_zaamo
1992 #error "Not __riscv_zaamo"
1993 #endif
1994 }]
1995 }
1996
1997 # Return 1 if the target arch supports the atomic BHA extension, 0 otherwise.
1998 # Cache the result.
1999
2000 proc check_effective_target_riscv_zabha { } {
2001 return [check_no_compiler_messages riscv_ext_zabha assembly {
2002 #ifndef __riscv_zabha
2003 #error "Not __riscv_zabha"
2004 #endif
2005 }]
2006 }
2007
2008 # Return 1 if the target arch supports the atomic CAS extension, 0 otherwise.
2009 # Cache the result.
2010
2011 proc check_effective_target_riscv_zacas { } {
2012 return [check_no_compiler_messages riscv_ext_zacas assembly {
2013 #ifndef __riscv_zacas
2014 #error "Not __riscv_zacas"
2015 #endif
2016 }]
2017 }
2018
2019 # Return 1 if the target arch supports the double precision floating point
2020 # extension, 0 otherwise. Cache the result.
2021
2022 proc check_effective_target_riscv_d { } {
2023 return [check_no_compiler_messages riscv_ext_d assembly {
2024 #ifndef __riscv_d
2025 #error "Not __riscv_d"
2026 #endif
2027 }]
2028 }
2029
2030 # Return 1 if the target arch supports the vector extension, 0 otherwise.
2031 # Cache the result.
2032
2033 proc check_effective_target_riscv_v { } {
2034 return [check_no_compiler_messages riscv_ext_v assembly {
2035 #ifndef __riscv_v
2036 #error "Not __riscv_v"
2037 #endif
2038 }]
2039 }
2040
2041 # Return 1 if the target runtime supports 256-bit vectors, 0 otherwise.
2042 # Cache the result.
2043
2044 proc check_effective_target_rvv_zvl256b_ok { } {
2045 # Check if the target has a VLENB of 32.
2046 set gcc_march [riscv_get_arch]
2047 return [check_runtime ${gcc_march}_exec {
2048 int main()
2049 {
2050 int vlenb = 0;
2051 asm ("csrr %0,vlenb" : "=r" (vlenb) : : );
2052 if (vlenb == 32)
2053 return 0;
2054 return 1;
2055 }
2056 } "-march=${gcc_march}"]
2057 }
2058
2059 # Return 1 if the target runtime supports 512-bit vectors, 0 otherwise.
2060 # Cache the result.
2061
2062 proc check_effective_target_rvv_zvl512b_ok { } {
2063 # Check if the target has a VLENB of 64.
2064 set gcc_march [riscv_get_arch]
2065 return [check_runtime ${gcc_march}_exec {
2066 int main()
2067 {
2068 int vlenb = 0;
2069 asm ("csrr %0,vlenb" : "=r" (vlenb) : : );
2070 if (vlenb == 64)
2071 return 0;
2072 return 1;
2073 }
2074 } "-march=${gcc_march}"]
2075 }
2076
2077
2078 # Return 1 if the target arch supports the Zvfh extension, 0 otherwise.
2079 # Cache the result.
2080
2081 proc check_effective_target_riscv_zvfh { } {
2082 return [check_no_compiler_messages riscv_ext_zvfh assembly {
2083 #ifndef __riscv_zvfh
2084 #error "Not __riscv_zvfh"
2085 #endif
2086 }]
2087 }
2088
2089 # Return 1 if the target arch supports half float, 0 otherwise.
2090 # Note, this differs from the test performed by
2091 # /* { dg-skip-if "" { *-*-* } { "*" } { "-march=rv*zfh*" } } */
2092 # in that it takes default behaviour into account.
2093 # Cache the result.
2094
2095 proc check_effective_target_riscv_zfh { } {
2096 return [check_no_compiler_messages riscv_ext_zfh assembly {
2097 #ifndef __riscv_zfh
2098 #error "Not __riscv_zfh"
2099 #endif
2100 }]
2101 }
2102
2103 # Return 1 if the target arch supports the TSO memory ordering extension,
2104 # 0 otherwise. Cache the result.
2105
2106 proc check_effective_target_riscv_ztso { } {
2107 return [check_no_compiler_messages riscv_ext_ztso assembly {
2108 #ifndef __riscv_ztso
2109 #error "Not __riscv_ztso"
2110 #endif
2111 }]
2112 }
2113
2114 # Return 1 if the target arch supports the Zbb extension, 0 otherwise.
2115 # Cache the result.
2116
2117 proc check_effective_target_riscv_zbb { } {
2118 return [check_no_compiler_messages riscv_ext_zbb assembly {
2119 #ifndef __riscv_zbb
2120 #error "Not __riscv_zbb"
2121 #endif
2122 }]
2123 }
2124
2125 # Return 1 if the target arch supports the Zbb extension, 0 otherwise.
2126 # Cache the result.
2127
2128 proc check_effective_target_riscv_zvbb { } {
2129 return [check_no_compiler_messages riscv_ext_zvbb assembly {
2130 #ifndef __riscv_zvbb
2131 #error "Not __riscv_zvbb"
2132 #endif
2133 }]
2134 }
2135
2136 # Return 1 if the target arch supports the Zbc extension, 0 otherwise.
2137 # Cache the result.
2138
2139 proc check_effective_target_riscv_zbc { } {
2140 return [check_no_compiler_messages riscv_ext_zbc assembly {
2141 #ifndef __riscv_zbc
2142 #error "Not __riscv_zbc"
2143 #endif
2144 }]
2145 }
2146
2147 # Return 1 if the target arch supports the Zbkb extension, 0 otherwise.
2148 # Cache the result.
2149
2150 proc check_effective_target_riscv_zbkb { } {
2151 return [check_no_compiler_messages riscv_ext_zbkb assembly {
2152 #ifndef __riscv_zbkb
2153 #error "Not __riscv_zbkb"
2154 #endif
2155 }]
2156 }
2157
2158 # Return 1 if the target arch supports the Zbkc extension, 0 otherwise.
2159 # Cache the result.
2160
2161 proc check_effective_target_riscv_zbkc { } {
2162 return [check_no_compiler_messages riscv_ext_zbkc assembly {
2163 #ifndef __riscv_zbkc
2164 #error "Not __riscv_zbkc"
2165 #endif
2166 }]
2167 }
2168
2169 # Return 1 if the target arch supports the XTheadVector extension, 0 otherwise.
2170 # Cache the result.
2171
2172 proc check_effective_target_riscv_xtheadvector { } {
2173 return [check_no_compiler_messages riscv_ext_xtheadvector assembly {
2174 #ifndef __riscv_xtheadvector
2175 #error "Not __riscv_xtheadvector"
2176 #endif
2177 }]
2178 }
2179
2180
2181 # Return 1 if we can execute code when using dg-add-options riscv_v
2182
2183 proc check_effective_target_riscv_v_ok { } {
2184 # If the target already supports v without any added options,
2185 # we may assume we can execute just fine.
2186 if { [check_effective_target_riscv_v] } {
2187 return 1
2188 }
2189
2190 # check if we can execute vector insns with the given hardware or
2191 # simulator
2192 set gcc_march [regsub {[[:alnum:]]*} [riscv_get_arch] &v]
2193 if { [check_runtime ${gcc_march}_exec {
2194 int main() { asm("vsetivli t0, 9, e8, m1, tu, ma"); return 0; } } "-march=${gcc_march}"] } {
2195 return 1
2196 }
2197
2198 # Possible future extensions: If the target is a simulator, dg-add-options
2199 # might change its config to make it allow vector insns, or we might use
2200 # options to set special elf flags / sections to effect that.
2201
2202 return 0
2203 }
2204
2205 # Return 1 if we can execute code when using dg-add-options riscv_zfh
2206
2207 proc check_effective_target_riscv_zfh_ok { } {
2208 # If the target already supports zfh without any added options,
2209 # we may assume we can execute just fine.
2210 # ??? Other cases we should consider:
2211 # - target / simulator already supports zfh extension - test for that.
2212 # - target is a simulator, and dg-add-options knows how to enable zfh support in that simulator
2213 if { [check_effective_target_riscv_zfh] } {
2214 return 1
2215 }
2216
2217 # check if we can execute zfh insns with the given hardware or
2218 # simulator
2219 set gcc_march [riscv_get_arch]
2220 if { [check_runtime ${gcc_march}_zfh_exec {
2221 int main() { asm("feq.h a3,fa5,fa4"); return 0; } } "-march=${gcc_march}_zfh"] } {
2222 return 1
2223 }
2224
2225 # Possible future extensions: If the target is a simulator, dg-add-options
2226 # might change its config to make it allow half float insns, or we might
2227 # use options to set special elf flags / sections to effect that.
2228
2229 return 0
2230 }
2231
2232 # Return 1 if we can execute code when using dg-add-options riscv_zvfh
2233
2234 proc check_effective_target_riscv_zvfh_ok { } {
2235 # If the target already supports v without any added options,
2236 # we may assume we can execute just fine.
2237 if { [check_effective_target_riscv_zvfh] } {
2238 return 1
2239 }
2240
2241 # check if we can execute vector insns with the given hardware or
2242 # simulator
2243 set gcc_march [regsub {[[:alnum:]]*} [riscv_get_arch] &v]
2244 if { [check_runtime ${gcc_march}_zvfh_exec {
2245 int main()
2246 {
2247 asm ("vsetivli zero,8,e16,m1,ta,ma");
2248 asm ("vfadd.vv v8,v8,v16" : : : "v8");
2249 return 0;
2250 } } "-march=${gcc_march}"] } {
2251 return 1
2252 }
2253
2254 return 0
2255 }
2256
2257 # Return 1 if we can execute code when using dg-add-options riscv_zbc
2258
2259 proc check_effective_target_riscv_zbc_ok { } {
2260 # If the target already supports zbc without any added options,
2261 # we may assume we can execute just fine.
2262 if { [check_effective_target_riscv_zbc] } {
2263 return 1
2264 }
2265
2266 # check if we can execute zbc insns with the given hardware or
2267 # simulator
2268 set gcc_march [regsub {[[:alnum:]]*} [riscv_get_arch] &zbc]
2269 if { [check_runtime ${gcc_march}_zbc_exec {
2270 int main()
2271 {
2272 asm ("clmul a0,a0,a1");
2273 asm ("clmulh a0,a0,a1");
2274 return 0;
2275 } } "-march=${gcc_march}"] } {
2276 return 1
2277 }
2278 return 0
2279 }
2280
2281 # Return 1 if we can execute code when using dg-add-options riscv_zbkb
2282
2283 proc check_effective_target_riscv_zbkb_ok { } {
2284 # If the target already supports zbkb without any added options,
2285 # we may assume we can execute just fine.
2286 if { [check_effective_target_riscv_zbkb] } {
2287 return 1
2288 }
2289
2290 # check if we can execute zbkb insns with the given hardware or
2291 # simulator
2292 set gcc_march [regsub {[[:alnum:]]*} [riscv_get_arch] &zbkb]
2293 if { [check_runtime ${gcc_march}_zbkb_exec {
2294 int main()
2295 {
2296 asm ("brev8 a0,a0");
2297 return 0;
2298 } } "-march=${gcc_march}"] } {
2299 return 1
2300 }
2301 return 0
2302 }
2303
2304 # Return 1 if we can execute code when using dg-add-options riscv_zbkc
2305
2306 proc check_effective_target_riscv_zbkc_ok { } {
2307 # If the target already supports zbkc without any added options,
2308 # we may assume we can execute just fine.
2309 if { [check_effective_target_riscv_zbkc] } {
2310 return 1
2311 }
2312
2313 # check if we can execute zbkc insns with the given hardware or
2314 # simulator
2315 set gcc_march [regsub {[[:alnum:]]*} [riscv_get_arch] &zbkc]
2316 if { [check_runtime ${gcc_march}_zbkc_exec {
2317 int main()
2318 {
2319 asm ("clmul a0,a0,a1");
2320 asm ("clmulh a0,a0,a1");
2321 return 0;
2322 } } "-march=${gcc_march}"] } {
2323 return 1
2324 }
2325 return 0
2326 }
2327
2328 # Return 1 if we can execute code when using dg-add-options riscv_zvbb
2329
2330 proc check_effective_target_riscv_zvbb_ok { } {
2331 # If the target already supports v without any added options,
2332 # we may assume we can execute just fine.
2333 if { [check_effective_target_riscv_zvbb] } {
2334 return 1
2335 }
2336
2337 # check if we can execute vector insns with the given hardware or
2338 # simulator
2339 set gcc_march [regsub {[[:alnum:]]*} [riscv_get_arch] &zvbb]
2340 if { [check_runtime ${gcc_march}_zvbb_exec {
2341 int main()
2342 {
2343 asm ("vsetivli zero,8,e16,m1,ta,ma");
2344 asm ("vwsll.vi v8,v16,2" : : : "v8");
2345 return 0;
2346 } } "-march=${gcc_march}"] } {
2347 return 1
2348 }
2349 return 0
2350 }
2351
2352 # Return 1 if we can load a vector from a 1-byte aligned address.
2353
2354 proc check_effective_target_riscv_v_misalign_ok { } {
2355
2356 if { ![check_effective_target_riscv_v_ok] } {
2357 return 0
2358 }
2359
2360 set gcc_march [riscv_get_arch]
2361 if { [check_runtime ${gcc_march}_misalign_exec {
2362 int main() {
2363 unsigned char a[16]
2364 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
2365 asm ("vsetivli zero,7,e8,m1,ta,ma");
2366 asm ("addi a7,%0,1" : : "r" (a) : "a7" );
2367 asm ("vle8.v v8,0(a7)" : : : "v8");
2368 return 0; } } "-march=${gcc_march}"] } {
2369 return 1
2370 }
2371
2372 return 0
2373 }
2374
2375 # Deduce the string for the RISC-V architecture targeted by the compiler
2376 # under test. Also take into account the global compiler flags passed
2377 # by testsuite.
2378 proc riscv_get_arch { } {
2379 set gcc_march ""
2380 # ??? do we neeed to add more extensions to the list below?
2381 foreach ext { i e m a f d q c b v zicsr zifencei zfh zba zbb zbc zbkb zbkc zbs zvbb zvfh ztso zaamo zalrsc zabha zacas } {
2382 if { [check_no_compiler_messages riscv_ext_$ext assembly [string map [list DEF __riscv_$ext] {
2383 #ifndef DEF
2384 #error "Not DEF"
2385 #endif
2386 }]] } {
2387 if { [string length $ext] > 1 } {
2388 set ext _${ext}
2389 }
2390 set gcc_march $gcc_march$ext
2391 }
2392 if { [string equal $gcc_march "imafd"] } {
2393 set gcc_march "g"
2394 }
2395 }
2396 if { [check_effective_target_rv32] } {
2397 set gcc_march rv32$gcc_march
2398 } elseif { [check_effective_target_rv64] } {
2399 set gcc_march rv64$gcc_march
2400 } else {
2401 set gcc_march ""
2402 }
2403 return "$gcc_march"
2404 }
2405
2406 proc add_options_for_riscv_a { flags } {
2407 if { [lsearch $flags -march=*] >= 0 } {
2408 # If there are any -march flags, we have to adjust all of them.
2409 set expanded_flags [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*)g+} $flags \\1imafd ]
2410 return [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*[b-eg-rt-wy]*)a*} $expanded_flags \\1a ]
2411 }
2412 if { [check_effective_target_riscv_a] } {
2413 return "$flags"
2414 }
2415 return "$flags -march=[regsub {(rv[[:digit:]]*[b-eg-rt-wy]*)a*} [riscv_get_arch] &a]"
2416 }
2417
2418 proc remove_options_for_riscv_a_only { flags } {
2419 # Only remove the 'a' extension. Useful when removing zalrsc/zaamo.
2420 if { [lsearch $flags -march=*] >= 0 } {
2421 # If there are any -march flags, we have to adjust all of them.
2422 set expanded_flags [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*)g+} $flags \\1imafd ]
2423 set modified_flags [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*[b-eg-rt-wy]*)a*} $expanded_flags \\1 ]
2424 return $modified_flags
2425 }
2426 if { [check_effective_target_riscv_a] } {
2427 # Manually specify the -march and remove it with another call
2428 return [remove_options_for_riscv_a_only "$flags -march=[riscv_get_arch]"]
2429 }
2430 return $flags
2431 }
2432
2433 proc remove_options_for_riscv_a { flags } {
2434 # Remove the 'a' extension and implied zalrsc/zaamo extensions.
2435 if { [lsearch $flags -march=*] >= 0 } {
2436 # If there are any -march flags, we have to adjust all of them.
2437 set modified_flags [remove_options_for_riscv_a_only $flags]
2438 # Also removed implied extensions
2439 set modified_flags [remove_options_for_riscv_z_ext zaamo $flags]
2440 set modified_flags [remove_options_for_riscv_z_ext zalrsc $flags]
2441 return $modified_flags
2442 }
2443 if { [check_effective_target_riscv_a] } {
2444 # Manually specify the -march and remove it with another call
2445 return [remove_options_for_riscv_a "$flags -march=[riscv_get_arch]"]
2446 }
2447 return $flags
2448 }
2449
2450 proc add_options_for_riscv_d { flags } {
2451 if { [lsearch $flags -march=*] >= 0 } {
2452 # If there are any -march flags, we have to adjust all of them.
2453 return [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*[a-ce-rt-wy]*)d*} $flags \\1d ]
2454 }
2455 if { [check_effective_target_riscv_d] } {
2456 return "$flags"
2457 }
2458 return "$flags -march=[regsub {[[:alnum:]]*} [riscv_get_arch] &d]"
2459 }
2460
2461 proc remove_options_for_riscv_d { flags } {
2462 if { [lsearch $flags -march=*] >= 0 } {
2463 # If there are any -march flags, we have to adjust all of them.
2464 return [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*[a-ce-rt-wy]*)d*} $flags \\1d ]
2465 }
2466 if { [check_effective_target_riscv_d] } {
2467 # Manually specify the -march and remove it with another call
2468 return [remove_options_for_riscv_d "$flags -march=[riscv_get_arch]"]
2469 }
2470 return $flags
2471 }
2472
2473 proc add_options_for_riscv_v { flags } {
2474 if { [lsearch $flags -march=*] >= 0 } {
2475 # If there are any -march flags, we have to adjust all of them.
2476 return [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*[a-rt-uwy]*)v*} $flags \\1v ]
2477 }
2478 if { [check_effective_target_riscv_v] } {
2479 return "$flags"
2480 }
2481 return "$flags -march=[regsub {[[:alnum:]]*} [riscv_get_arch] &v]"
2482 }
2483
2484 proc remove_options_for_riscv_v { flags } {
2485 if { [lsearch $flags -march=*] >= 0 } {
2486 # If there are any -march flags, we have to adjust all of them.
2487 return [regsub -all -- {((?:^|[[:space:]])-march=rv[[:digit:]]*[a-rt-uwy]*)v*} $flags \\1 ]
2488 }
2489 if { [check_effective_target_riscv_v] } {
2490 # Manually specify the -march and remove it with another call
2491 return [remove_options_for_riscv_v "$flags -march=[riscv_get_arch]"]
2492 }
2493 return $flags
2494 }
2495
2496 proc add_options_for_riscv_z_ext { ext flags } {
2497 if {[lsearch $flags "-march=*"] >= 0} {
2498 # If there are any -march flags, we have to adjust all of them.
2499 set modified_flags {}
2500 foreach flag $flags {
2501 if {[regexp {^-march=(\S+)} $flag match march_name]} {
2502 if {![string match "*_${ext}*" $march_name]} {
2503 set march_name "${march_name}_${ext}"
2504 }
2505 lappend modified_flags "-march=$march_name"
2506 } else {
2507 lappend modified_flags $flag
2508 }
2509 }
2510 return [join $modified_flags " "]
2511 }
2512 if { [check_effective_target_riscv_$ext] } {
2513 return "$flags"
2514 }
2515 return "$flags -march=[riscv_get_arch]_${ext}"
2516 }
2517
2518 proc remove_options_for_riscv_z_ext { ext flags } {
2519 if { [lsearch $flags -march=*] >= 0 } {
2520 # If there are multiple -march flags, we have to adjust all of them.
2521 set modified_flags ""
2522 foreach flag $flags {
2523 if {[regexp {^-march=(\S+)} $flag -> march_name]} {
2524 # Remove "_ext" from the march_name if present
2525 set march_name [string map [list _${ext} {}] $march_name]
2526 lappend modified_flags "-march=$march_name"
2527 } else {
2528 lappend modified_flags $flag
2529 }
2530 }
2531 return [join $modified_flags " "]
2532 }
2533 if { [check_effective_target_riscv_$ext] } {
2534 # Manually specify the -march and remove it with another call
2535 return [remove_options_for_riscv_z_ext $ext "$flags -march=[riscv_get_arch]"]
2536 }
2537 return $flags
2538 }
2539
2540 proc add_options_for_riscv_zaamo { flags } {
2541 return [add_options_for_riscv_z_ext zaamo $flags]
2542 }
2543
2544 proc remove_options_for_riscv_zaamo { flags } {
2545 set modified_flags [remove_options_for_riscv_z_ext zaamo $flags]
2546 # If zabha is set then zaamo will be implied. We need to remove zabha
2547 # as well.
2548 set modified_flags [remove_options_for_riscv_z_ext zabha $modified_flags]
2549 # If zacas is set then zaamo will be implied. We need to remove zacas
2550 # as well.
2551 set modified_flags [remove_options_for_riscv_z_ext zacas $modified_flags]
2552 # If 'a' is set then zaamo will be implied. We need to downgrade instances
2553 # of 'a' to 'zalrsc'
2554 set no_a_flags [remove_options_for_riscv_a_only $modified_flags]
2555 if {![string equal $modified_flags $no_a_flags]} {
2556 # 'a' was removed, add 'zalrsc' since it was previously implied
2557 set modified_flags [add_options_for_riscv_zalrsc $no_a_flags]
2558 }
2559 return $modified_flags
2560 }
2561
2562 proc add_options_for_riscv_zalrsc { flags } {
2563 return [add_options_for_riscv_z_ext zalrsc $flags]
2564 }
2565
2566 proc remove_options_for_riscv_zalrsc { flags } {
2567 set modified_flags [remove_options_for_riscv_z_ext zalrsc $flags]
2568 # If 'a' is set then zalrsc will be implied. We need to downgrade instances
2569 # of 'a' to 'zaamo'
2570 set no_a_flags [remove_options_for_riscv_a_only $modified_flags]
2571 if {![string equal $modified_flags $no_a_flags]} {
2572 # 'a' was removed, add 'zalrsc' since it was previously implied
2573 set modified_flags [add_options_for_riscv_zalrsc $no_a_flags]
2574 }
2575 return $modified_flags
2576 }
2577
2578 proc add_options_for_riscv_zabha { flags } {
2579 return [add_options_for_riscv_z_ext zabha $flags]
2580 }
2581
2582 proc remove_options_for_riscv_zabha { flags } {
2583 set modified_flags [remove_options_for_riscv_zaamo $flags]
2584 return [remove_options_for_riscv_z_ext zabha $modified_flags]
2585 }
2586
2587 proc add_options_for_riscv_zacas { flags } {
2588 return [add_options_for_riscv_z_ext zacas $flags]
2589 }
2590
2591 proc remove_options_for_riscv_zacas { flags } {
2592 set modified_flags [remove_options_for_riscv_zaamo $flags]
2593 return [remove_options_for_riscv_z_ext zacas $modified_flags]
2594 }
2595
2596 proc add_options_for_riscv_zfh { flags } {
2597 return [add_options_for_riscv_z_ext zfh $flags]
2598 }
2599
2600 proc remove_options_for_riscv_zfh { flags } {
2601 return [remove_options_for_riscv_z_ext zfh $flags]
2602 }
2603
2604 proc add_options_for_riscv_ztso { flags } {
2605 return [add_options_for_riscv_z_ext ztso $flags]
2606 }
2607
2608 proc remove_options_for_riscv_ztso { flags } {
2609 return [remove_options_for_riscv_z_ext ztso $flags]
2610 }
2611
2612 proc remove_options_for_riscv_zvfh { flags } {
2613 return [add_options_for_riscv_z_ext zvfh $flags]
2614 }
2615
2616 proc add_options_for_riscv_zvbb { flags } {
2617 return [add_options_for_riscv_z_ext zvbb $flags]
2618 }
2619
2620 proc remove_options_for_riscv_zvbb { flags } {
2621 return [add_options_for_riscv_z_ext zvbb $flags]
2622 }
2623
2624 # Return 1 if the target is ia32 or x86_64.
2625
2626 proc check_effective_target_x86 { } {
2627 if { ([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
2628 return 1
2629 } else {
2630 return 0
2631 }
2632 }
2633
2634 # Return 1 if the target OS supports running SSE executables, 0
2635 # otherwise. Cache the result.
2636
2637 proc check_sse_os_support_available { } {
2638 return [check_cached_effective_target sse_os_support_available {
2639 # If this is not the right target then we can skip the test.
2640 expr [check_effective_target_x86]
2641 }]
2642 }
2643
2644 # Return 1 if the target OS supports running AVX executables, 0
2645 # otherwise. Cache the result.
2646
2647 proc check_avx_os_support_available { } {
2648 return [check_cached_effective_target avx_os_support_available {
2649 # If this is not the right target then we can skip the test.
2650 if { ![check_effective_target_x86] } {
2651 expr 0
2652 } else {
2653 # Check that OS has AVX and SSE saving enabled.
2654 check_runtime_nocache avx_os_support_available {
2655 int main ()
2656 {
2657 unsigned int eax, edx;
2658
2659 asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
2660 return (eax & 0x06) != 0x06;
2661 }
2662 } ""
2663 }
2664 }]
2665 }
2666
2667 # Return 1 if the target OS supports running AVX executables, 0
2668 # otherwise. Cache the result.
2669
2670 proc check_avx512_os_support_available { } {
2671 return [check_cached_effective_target avx512_os_support_available {
2672 # If this is not the right target then we can skip the test.
2673 if { ![check_effective_target_x86] } {
2674 expr 0
2675 } else {
2676 # Check that OS has AVX512, AVX and SSE saving enabled.
2677 check_runtime_nocache avx512_os_support_available {
2678 int main ()
2679 {
2680 unsigned int eax, edx;
2681
2682 asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
2683 return (eax & 0xe6) != 0xe6;
2684 }
2685 } ""
2686 }
2687 }]
2688 }
2689
2690 # Return 1 if the target supports executing SSE instructions, 0
2691 # otherwise. Cache the result.
2692
2693 proc check_sse_hw_available { } {
2694 return [check_cached_effective_target sse_hw_available {
2695 # If this is not the right target then we can skip the test.
2696 if { ![check_effective_target_x86] } {
2697 expr 0
2698 } else {
2699 check_runtime_nocache sse_hw_available {
2700 #include "cpuid.h"
2701 int main ()
2702 {
2703 unsigned int eax, ebx, ecx, edx;
2704 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
2705 return 1;
2706
2707 return !(edx & bit_SSE);
2708 }
2709 } ""
2710 }
2711 }]
2712 }
2713
2714 # Return 1 if the target supports executing SSE2 instructions, 0
2715 # otherwise. Cache the result.
2716
2717 proc check_sse2_hw_available { } {
2718 return [check_cached_effective_target sse2_hw_available {
2719 # If this is not the right target then we can skip the test.
2720 if { ![check_effective_target_x86] } {
2721 expr 0
2722 } else {
2723 check_runtime_nocache sse2_hw_available {
2724 #include "cpuid.h"
2725 int main ()
2726 {
2727 unsigned int eax, ebx, ecx, edx;
2728 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
2729 return 1;
2730
2731 return !(edx & bit_SSE2);
2732 }
2733 } ""
2734 }
2735 }]
2736 }
2737
2738 # Return 1 if the target supports executing SSE4 instructions, 0
2739 # otherwise. Cache the result.
2740
2741 proc check_sse4_hw_available { } {
2742 return [check_cached_effective_target sse4_hw_available {
2743 # If this is not the right target then we can skip the test.
2744 if { ![check_effective_target_x86] } {
2745 expr 0
2746 } else {
2747 check_runtime_nocache sse4_hw_available {
2748 #include "cpuid.h"
2749 int main ()
2750 {
2751 unsigned int eax, ebx, ecx, edx;
2752 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
2753 return 1;
2754
2755 return !(ecx & bit_SSE4_2);
2756 }
2757 } ""
2758 }
2759 }]
2760 }
2761
2762 # Return 1 if the target supports executing AVX instructions, 0
2763 # otherwise. Cache the result.
2764
2765 proc check_avx_hw_available { } {
2766 return [check_cached_effective_target avx_hw_available {
2767 # If this is not the right target then we can skip the test.
2768 if { ![check_effective_target_x86] } {
2769 expr 0
2770 } else {
2771 check_runtime_nocache avx_hw_available {
2772 #include "cpuid.h"
2773 int main ()
2774 {
2775 unsigned int eax, ebx, ecx, edx;
2776 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
2777 return 1;
2778
2779 return ((ecx & (bit_AVX | bit_OSXSAVE))
2780 != (bit_AVX | bit_OSXSAVE));
2781 }
2782 } ""
2783 }
2784 }]
2785 }
2786
2787 # Return 1 if the target supports executing AVX2 instructions, 0
2788 # otherwise. Cache the result.
2789
2790 proc check_avx2_hw_available { } {
2791 return [check_cached_effective_target avx2_hw_available {
2792 # If this is not the right target then we can skip the test.
2793 if { ![check_effective_target_x86] } {
2794 expr 0
2795 } else {
2796 check_runtime_nocache avx2_hw_available {
2797 #include <stddef.h>
2798 #include "cpuid.h"
2799 int main ()
2800 {
2801 unsigned int eax, ebx, ecx, edx;
2802
2803 if (__get_cpuid_max (0, NULL) < 7)
2804 return 1;
2805
2806 __cpuid (1, eax, ebx, ecx, edx);
2807
2808 if (!(ecx & bit_OSXSAVE))
2809 return 1;
2810
2811 __cpuid_count (7, 0, eax, ebx, ecx, edx);
2812
2813 return !(ebx & bit_AVX2);
2814 }
2815 } ""
2816 }
2817 }]
2818 }
2819
2820 # Return 1 if the target supports executing AVX512 foundation instructions, 0
2821 # otherwise. Cache the result.
2822
2823 proc check_avx512f_hw_available { } {
2824 return [check_cached_effective_target avx512f_hw_available {
2825 # If this is not the right target then we can skip the test.
2826 if { ![check_effective_target_x86] } {
2827 expr 0
2828 } else {
2829 check_runtime_nocache avx512f_hw_available {
2830 #include <stddef.h>
2831 #include "cpuid.h"
2832 int main ()
2833 {
2834 unsigned int eax, ebx, ecx, edx;
2835
2836 if (__get_cpuid_max (0, NULL) < 7)
2837 return 1;
2838
2839 __cpuid (1, eax, ebx, ecx, edx);
2840
2841 if (!(ecx & bit_OSXSAVE))
2842 return 1;
2843
2844 __cpuid_count (7, 0, eax, ebx, ecx, edx);
2845
2846 return !(ebx & bit_AVX512F);
2847 }
2848 } ""
2849 }
2850 }]
2851 }
2852
2853 # Return 1 if the target supports running SSE executables, 0 otherwise.
2854
2855 proc check_effective_target_sse_runtime { } {
2856 if { [check_effective_target_sse]
2857 && [check_sse_hw_available]
2858 && [check_sse_os_support_available] } {
2859 return 1
2860 }
2861 return 0
2862 }
2863
2864 # Return 1 if the target supports running SSE2 executables, 0 otherwise.
2865
2866 proc check_effective_target_sse2_runtime { } {
2867 if { [check_effective_target_sse2]
2868 && [check_sse2_hw_available]
2869 && [check_sse_os_support_available] } {
2870 return 1
2871 }
2872 return 0
2873 }
2874
2875 # Return 1 if the target supports running SSE4 executables, 0 otherwise.
2876
2877 proc check_effective_target_sse4_runtime { } {
2878 if { [check_effective_target_sse4]
2879 && [check_sse4_hw_available]
2880 && [check_sse_os_support_available] } {
2881 return 1
2882 }
2883 return 0
2884 }
2885
2886 # Return 1 if the target supports running AVX executables, 0 otherwise.
2887
2888 proc check_effective_target_avx_runtime { } {
2889 if { [check_effective_target_avx]
2890 && [check_avx_hw_available]
2891 && [check_avx_os_support_available] } {
2892 return 1
2893 }
2894 return 0
2895 }
2896
2897 # Return 1 if the target supports running AVX2 executables, 0 otherwise.
2898
2899 proc check_effective_target_avx2_runtime { } {
2900 if { [check_effective_target_avx2]
2901 && [check_avx2_hw_available]
2902 && [check_avx_os_support_available] } {
2903 return 1
2904 }
2905 return 0
2906 }
2907
2908 # Return 1 if the target supports running AVX512f executables, 0 otherwise.
2909
2910 proc check_effective_target_avx512f_runtime { } {
2911 if { [check_effective_target_avx512f]
2912 && [check_avx512f_hw_available]
2913 && [check_avx512_os_support_available] } {
2914 return 1
2915 }
2916 return 0
2917 }
2918
2919 # Return 1 if bmi2 instructions can be compiled.
2920 proc check_effective_target_bmi2 { } {
2921 if { ![check_effective_target_x86] } {
2922 return 0
2923 }
2924 return [check_no_compiler_messages bmi2 object {
2925 unsigned int
2926 _bzhi_u32 (unsigned int __X, unsigned int __Y)
2927 {
2928 return __builtin_ia32_bzhi_si (__X, __Y);
2929 }
2930 } "-mbmi2" ]
2931 }
2932
2933 # Return 1 if the target supports executing MIPS Paired-Single instructions,
2934 # 0 otherwise. Cache the result.
2935
2936 proc check_mpaired_single_hw_available { } {
2937 return [check_cached_effective_target mpaired_single_hw_available {
2938 # If this is not the right target then we can skip the test.
2939 if { !([istarget mips*-*-*]) } {
2940 expr 0
2941 } else {
2942 check_runtime_nocache mpaired_single_hw_available {
2943 int main()
2944 {
2945 asm volatile ("pll.ps $f2,$f4,$f6");
2946 return 0;
2947 }
2948 } ""
2949 }
2950 }]
2951 }
2952
2953 # Return 1 if the target supports executing Loongson vector instructions,
2954 # 0 otherwise. Cache the result.
2955
2956 proc check_mips_loongson_mmi_hw_available { } {
2957 return [check_cached_effective_target mips_loongson_mmi_hw_available {
2958 # If this is not the right target then we can skip the test.
2959 if { !([istarget mips*-*-*]) } {
2960 expr 0
2961 } else {
2962 check_runtime_nocache mips_loongson_mmi_hw_available {
2963 #include <loongson-mmiintrin.h>
2964 int main()
2965 {
2966 asm volatile ("paddw $f2,$f4,$f6");
2967 return 0;
2968 }
2969 } "-mloongson-mmi"
2970 }
2971 }]
2972 }
2973
2974 # Return 1 if the target supports executing MIPS MSA instructions, 0
2975 # otherwise. Cache the result.
2976
2977 proc check_mips_msa_hw_available { } {
2978 return [check_cached_effective_target mips_msa_hw_available {
2979 # If this is not the right target then we can skip the test.
2980 if { !([istarget mips*-*-*]) } {
2981 expr 0
2982 } else {
2983 check_runtime_nocache mips_msa_hw_available {
2984 #if !defined(__mips_msa)
2985 #error "MSA NOT AVAIL"
2986 #else
2987 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
2988 #error "MSA NOT AVAIL FOR ISA REV < 2"
2989 #endif
2990 #if !defined(__mips_hard_float)
2991 #error "MSA HARD_FLOAT REQUIRED"
2992 #endif
2993 #if __mips_fpr != 64
2994 #error "MSA 64-bit FPR REQUIRED"
2995 #endif
2996 #include <msa.h>
2997
2998 int main()
2999 {
3000 v8i16 v = __builtin_msa_ldi_h (0);
3001 v[0] = 0;
3002 return v[0];
3003 }
3004 #endif
3005 } "-mmsa"
3006 }
3007 }]
3008 }
3009
3010 # Return 1 if the target supports running MIPS Paired-Single
3011 # executables, 0 otherwise.
3012
3013 proc check_effective_target_mpaired_single_runtime { } {
3014 if { [check_effective_target_mpaired_single "-mpaired-single"]
3015 && [check_mpaired_single_hw_available] } {
3016 return 1
3017 }
3018 return 0
3019 }
3020
3021 # Return 1 if the target supports running Loongson executables, 0 otherwise.
3022
3023 proc check_effective_target_mips_loongson_mmi_runtime { } {
3024 if { [check_effective_target_mips_loongson_mmi "-mloongson-mmi"]
3025 && [check_mips_loongson_mmi_hw_available] } {
3026 return 1
3027 }
3028 return 0
3029 }
3030
3031 # Return 1 if the target supports running MIPS MSA executables, 0 otherwise.
3032
3033 proc check_effective_target_mips_msa_runtime { } {
3034 if { [check_effective_target_mips_msa "-mmsa"]
3035 && [check_mips_msa_hw_available] } {
3036 return 1
3037 }
3038 return 0
3039 }
3040
3041 # Return 1 if we are compiling for 64-bit PowerPC but we do not use direct
3042 # move instructions for moves from GPR to FPR.
3043
3044 proc check_effective_target_powerpc64_no_dm { } {
3045 # The "mulld" checks if we are generating PowerPC64 code. The "lfd"
3046 # checks if we do not use direct moves, but use the old-fashioned
3047 # slower move-via-the-stack.
3048 return [check_no_messages_and_pattern powerpc64_no_dm \
3049 {\mmulld\M.*\mlfd} assembly {
3050 double f(long long x) { return x*x; }
3051 } {-O2}]
3052 }
3053
3054 # Return 1 if the target supports the __builtin_cpu_supports built-in,
3055 # including having a new enough library to support the test. Cache the result.
3056 # Require at least a power7 to run on.
3057
3058 proc check_ppc_cpu_supports_hw_available { } {
3059 return [check_cached_effective_target ppc_cpu_supports_hw_available {
3060 # Some simulators are known to not support VSX/power8 instructions.
3061 # For now, disable on Darwin
3062 if { [istarget powerpc-*-eabi]
3063 || [istarget *-*-darwin*]} {
3064 expr 0
3065 } else {
3066 set options "-mvsx"
3067 check_runtime_nocache ppc_cpu_supports_hw_available {
3068 int main()
3069 {
3070 #ifdef __MACH__
3071 asm volatile ("xxlor vs0,vs0,vs0");
3072 #else
3073 asm volatile ("xxlor 0,0,0");
3074 #endif
3075 if (!__builtin_cpu_supports ("vsx"))
3076 return 1;
3077 return 0;
3078 }
3079 } $options
3080 }
3081 }]
3082 }
3083
3084 # Return 1 if the target supports executing power8 vector instructions, 0
3085 # otherwise. Cache the result.
3086
3087 proc check_p8vector_hw_available { } {
3088 return [check_cached_effective_target p8vector_hw_available {
3089 # Some simulators are known to not support VSX/power8 instructions.
3090 # For now, disable on Darwin
3091 if { [istarget powerpc-*-eabi]
3092 || [istarget *-*-darwin*]} {
3093 expr 0
3094 } else {
3095 set options "-mcpu=power8"
3096 check_runtime_nocache p8vector_hw_available {
3097 int main()
3098 {
3099 vector long long v1 = {0x1, 0x2};
3100 vector long long v2;
3101 asm ("xxlorc %0,%1,%1" : "=wa" (v2) : "wa" (v1));
3102 return 0;
3103 }
3104 } $options
3105 }
3106 }]
3107 }
3108
3109 # Return 1 if the target supports executing power9 vector instructions, 0
3110 # otherwise. Cache the result.
3111
3112 proc check_p9vector_hw_available { } {
3113 return [check_cached_effective_target p9vector_hw_available {
3114 # Some simulators are known to not support VSX/power8/power9
3115 # instructions. For now, disable on Darwin.
3116 if { [istarget powerpc-*-eabi]
3117 || [istarget *-*-darwin*]} {
3118 expr 0
3119 } else {
3120 set options "-mcpu=power9"
3121 check_runtime_nocache p9vector_hw_available {
3122 int main()
3123 {
3124 long e = -1;
3125 vector double v = (vector double) { 0.0, 0.0 };
3126 asm ("xsxexpdp %0,%1" : "+r" (e) : "wa" (v));
3127 return e;
3128 }
3129 } $options
3130 }
3131 }]
3132 }
3133
3134 # Return 1 if the PowerPC target generates PC-relative instructions
3135 # automatically for targets that support PC-relative instructions.
3136 proc check_effective_target_powerpc_pcrel { } {
3137 return [check_no_messages_and_pattern powerpc_pcrel \
3138 {\mpla\M} assembly {
3139 static unsigned short s;
3140 unsigned short *p_foo (void) { return &s; }
3141 } {-O2 -mcpu=power10}]
3142 }
3143
3144 # Return 1 if the PowerPC target generates prefixed instructions automatically
3145 # for targets that support prefixed instructions.
3146 proc check_effective_target_powerpc_prefixed_addr { } {
3147 return [check_no_messages_and_pattern powerpc_prefixed_addr \
3148 {\mplwz\M} assembly {
3149 unsigned int foo (unsigned int *p) { return p[0x12345]; }
3150 } {-O2 -mcpu=power10}]
3151 }
3152
3153 # Return 1 if the target supports executing power9 modulo instructions, 0
3154 # otherwise. Cache the result.
3155
3156 proc check_p9modulo_hw_available { } {
3157 return [check_cached_effective_target p9modulo_hw_available {
3158 # Some simulators are known to not support VSX/power8/power9
3159 # instructions. For now, disable on Darwin.
3160 if { [istarget powerpc-*-eabi]
3161 || [istarget *-*-darwin*]} {
3162 expr 0
3163 } else {
3164 set options "-mmodulo"
3165 check_runtime_nocache p9modulo_hw_available {
3166 int main()
3167 {
3168 int i = 5, j = 3, r = -1;
3169 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
3170 return (r != 2);
3171 }
3172 } $options
3173 }
3174 }]
3175 }
3176
3177
3178 # Return 1 if the target supports executing power10 instructions, 0 otherwise.
3179 # Cache the result. It is assumed that if a simulator does not support the
3180 # power10 instructions, that it will generate an error and this test will fail.
3181
3182 proc check_power10_hw_available { } {
3183 return [check_cached_effective_target power10_hw_available {
3184 check_runtime_nocache power10_hw_available {
3185 int main()
3186 {
3187 /* Set e first and use +r to check if pli actually works. */
3188 long e = -1;
3189 asm ("pli %0,%1" : "+r" (e) : "n" (0x12345));
3190 if (e == 0x12345)
3191 return 0;
3192 return 1;
3193 }
3194 } "-mcpu=power10"
3195 }]
3196 }
3197
3198 # Return 1 if the target supports executing MMA instructions, 0 otherwise.
3199 # Cache the result. It is assumed that if a simulator does not support the
3200 # MMA instructions, that it will generate an error and this test will fail.
3201
3202 proc check_ppc_mma_hw_available { } {
3203 return [check_cached_effective_target ppc_mma_hw_available {
3204 check_runtime_nocache ppc_mma_hw_available {
3205 #include <altivec.h>
3206 typedef double v4sf_t __attribute__ ((vector_size (16)));
3207
3208 int main()
3209 {
3210 __vector_quad acc0;
3211 v4sf_t result[4];
3212 result[0][0] = 1.0;
3213 __builtin_mma_xxsetaccz (&acc0);
3214 __builtin_mma_disassemble_acc (result, &acc0);
3215 if (result[0][0] != 0.0)
3216 return 1;
3217 return 0;
3218 }
3219 } "-mcpu=power10"
3220 }]
3221 }
3222
3223 # Return 1 if the target supports executing __float128 on PowerPC via software
3224 # emulation, 0 otherwise. Cache the result.
3225
3226 proc check_ppc_float128_sw_available { } {
3227 return [check_cached_effective_target ppc_float128_sw_available {
3228 # Some simulators are known to not support VSX/power8/power9
3229 # instructions. For now, disable on Darwin and VxWorks.
3230 if { [istarget *-*-vxworks*]
3231 || [istarget powerpc-*-eabi]
3232 || [istarget *-*-darwin*]} {
3233 expr 0
3234 } else {
3235 set options "-mfloat128 -mvsx"
3236 check_runtime_nocache ppc_float128_sw_available {
3237 volatile __float128 x = 1.0q;
3238 volatile __float128 y = 2.0q;
3239 int main()
3240 {
3241 __float128 z = x + y;
3242 return (z != 3.0q);
3243 }
3244 } $options
3245 }
3246 }]
3247 }
3248
3249 # Return 1 if the target supports executing __float128 on PowerPC via power9
3250 # hardware instructions, 0 otherwise. Cache the result.
3251
3252 proc check_ppc_float128_hw_available { } {
3253 return [check_cached_effective_target ppc_float128_hw_available {
3254 # Some simulators are known to not support VSX/power8/power9
3255 # instructions. For now, disable on Darwin.
3256 if { [istarget *-*-vxworks*]
3257 || [istarget powerpc-*-eabi]
3258 || [istarget *-*-darwin*]} {
3259 expr 0
3260 } else {
3261 set options "-mfloat128 -mvsx -mfloat128-hardware -mcpu=power9"
3262 check_runtime_nocache ppc_float128_hw_available {
3263 volatile __float128 x = 1.0q;
3264 volatile __float128 y = 2.0q;
3265 int main()
3266 {
3267 __float128 z = x + y;
3268 __float128 w = -1.0q;
3269
3270 __asm__ ("xsaddqp %0,%1,%2" : "+v" (w) : "v" (x), "v" (y));
3271 return ((z != 3.0q) || (z != w));
3272 }
3273 } $options
3274 }
3275 }]
3276 }
3277
3278 # See if the __ieee128 keyword is understood.
3279 proc check_effective_target_ppc_ieee128_ok { } {
3280 return [check_cached_effective_target ppc_ieee128_ok {
3281 # disable on AIX and VxWorks.
3282 if { [istarget *-*-aix*]
3283 || [istarget *-*-vxworks*]} {
3284 expr 0
3285 } else {
3286 set options "-mfloat128"
3287 check_runtime_nocache ppc_ieee128_ok {
3288 int main()
3289 {
3290 __ieee128 a;
3291 return 0;
3292 }
3293 } $options
3294 }
3295 }]
3296 }
3297
3298 # Check if GCC and GLIBC supports explicitly specifying that the long double
3299 # format uses the IBM 128-bit extended double format. Under little endian
3300 # PowerPC Linux, you need GLIBC 2.32 or later to be able to use a different
3301 # long double format for running a program than the system default.
3302
3303 proc check_effective_target_long_double_ibm128 { } {
3304 return [check_runtime_nocache long_double_ibm128 {
3305 #include <string.h>
3306 #include <stdio.h>
3307 /* use volatile to prevent optimization. */
3308 volatile __ibm128 a = (__ibm128) 3.0;
3309 volatile long double one = 1.0L;
3310 volatile long double two = 2.0L;
3311 volatile long double b;
3312 char buffer[20];
3313 int main()
3314 {
3315 __ibm128 a2;
3316 long double b2;
3317 if (sizeof (long double) != 16)
3318 return 1;
3319 b = one + two;
3320 /* eliminate removing volatile cast warning. */
3321 a2 = a;
3322 b2 = b;
3323 if (memcmp (&a2, &b2, 16) != 0)
3324 return 1;
3325 sprintf (buffer, "%lg", b);
3326 return strcmp (buffer, "3") != 0;
3327 }
3328 } [add_options_for_long_double_ibm128 ""]]
3329 }
3330
3331 # Return the appropriate options to specify that long double uses the IBM
3332 # 128-bit format on PowerPC.
3333
3334 proc add_options_for_long_double_ibm128 { flags } {
3335 if { [istarget powerpc*-*-*] } {
3336 return "$flags -mlong-double-128 -Wno-psabi -mabi=ibmlongdouble"
3337 }
3338 return "$flags"
3339 }
3340
3341 # Check if GCC and GLIBC supports explicitly specifying that the long double
3342 # format uses the IEEE 128-bit format. Under little endian PowerPC Linux, you
3343 # need GLIBC 2.32 or later to be able to use a different long double format for
3344 # running a program than the system default.
3345
3346 proc check_effective_target_long_double_ieee128 { } {
3347 return [check_runtime_nocache long_double_ieee128 {
3348 #include <string.h>
3349 #include <stdio.h>
3350 /* use volatile to prevent optimization. */
3351 volatile _Float128 a = 3.0f128;
3352 volatile long double one = 1.0L;
3353 volatile long double two = 2.0L;
3354 volatile long double b;
3355 char buffer[20];
3356 int main()
3357 {
3358 _Float128 a2;
3359 long double b2;
3360 if (sizeof (long double) != 16)
3361 return 1;
3362 b = one + two;
3363 /* eliminate removing volatile cast warning. */
3364 a2 = a;
3365 b2 = b;
3366 if (memcmp (&a2, &b2, 16) != 0)
3367 return 1;
3368 sprintf (buffer, "%lg", b);
3369 return strcmp (buffer, "3") != 0;
3370 }
3371 } [add_options_for_long_double_ieee128 ""]]
3372 }
3373
3374 # Return the appropriate options to specify that long double uses the IBM
3375 # 128-bit format on PowerPC.
3376 proc add_options_for_long_double_ieee128 { flags } {
3377 if { [istarget powerpc*-*-*] } {
3378 return "$flags -mlong-double-128 -Wno-psabi -mabi=ieeelongdouble"
3379 }
3380 return "$flags"
3381 }
3382
3383 # Return 1 if the target supports executing VSX instructions, 0
3384 # otherwise. Cache the result.
3385
3386 proc check_vsx_hw_available { } {
3387 return [check_cached_effective_target vsx_hw_available {
3388 # Some simulators are known to not support VSX instructions.
3389 # For now, disable on Darwin
3390 if { [istarget powerpc-*-eabi]
3391 || [istarget *-*-darwin*]} {
3392 expr 0
3393 } else {
3394 set options "-mvsx"
3395 check_runtime_nocache vsx_hw_available {
3396 int main()
3397 {
3398 vector int v1 = {0, 0, 0, 0};
3399 vector int v2;
3400 asm ("xxlor %0,%1,%1" : "=wa" (v2) : "wa" (v1));
3401 return 0;
3402 }
3403 } $options
3404 }
3405 }]
3406 }
3407
3408 # Return 1 if the target supports executing AltiVec instructions, 0
3409 # otherwise. Cache the result.
3410
3411 proc check_vmx_hw_available { } {
3412 return [check_cached_effective_target vmx_hw_available {
3413 # Some simulators are known to not support VMX instructions.
3414 if { [istarget powerpc-*-eabi] } {
3415 expr 0
3416 } else {
3417 # Most targets don't require special flags for this test case, but
3418 # Darwin does. Just to be sure, make sure VSX is not enabled for
3419 # the altivec tests.
3420 if { [istarget *-*-darwin*]
3421 || [istarget *-*-aix*] } {
3422 set options "-maltivec -mno-vsx"
3423 } else {
3424 set options "-mno-vsx"
3425 }
3426 check_runtime_nocache vmx_hw_available {
3427 int main()
3428 {
3429 vector int v1 = {0, 0, 0, 0};
3430 vector int v2;
3431 asm ("vor %0,%1,%1" : "=v" (v2) : "v" (v1));
3432 return 0;
3433 }
3434 } $options
3435 }
3436 }]
3437 }
3438
3439 proc check_ppc_recip_hw_available { } {
3440 return [check_cached_effective_target ppc_recip_hw_available {
3441 # Some simulators may not support FRE/FRES/FRSQRTE/FRSQRTES
3442 # For now, disable on Darwin
3443 if { [istarget powerpc-*-eabi] || [istarget *-*-darwin*]} {
3444 expr 0
3445 } else {
3446 set options "-mpowerpc-gfxopt -mpowerpc-gpopt -mpopcntb"
3447 check_runtime_nocache ppc_recip_hw_available {
3448 volatile double d_recip, d_rsqrt, d_four = 4.0;
3449 volatile float f_recip, f_rsqrt, f_four = 4.0f;
3450 int main()
3451 {
3452 asm volatile ("fres %0,%1" : "=f" (f_recip) : "f" (f_four));
3453 asm volatile ("fre %0,%1" : "=d" (d_recip) : "d" (d_four));
3454 asm volatile ("frsqrtes %0,%1" : "=f" (f_rsqrt) : "f" (f_four));
3455 asm volatile ("frsqrte %0,%1" : "=f" (d_rsqrt) : "d" (d_four));
3456 return 0;
3457 }
3458 } $options
3459 }
3460 }]
3461 }
3462
3463 # Return 1 if the target supports executing AltiVec and Cell PPU
3464 # instructions, 0 otherwise. Cache the result.
3465
3466 proc check_effective_target_cell_hw { } {
3467 return [check_cached_effective_target cell_hw_available {
3468 # Some simulators are known to not support VMX and PPU instructions.
3469 if { [istarget powerpc-*-eabi*] } {
3470 expr 0
3471 } else {
3472 # Most targets don't require special flags for this test
3473 # case, but Darwin and AIX do.
3474 if { [istarget *-*-darwin*]
3475 || [istarget *-*-aix*] } {
3476 set options "-maltivec -mcpu=cell"
3477 } else {
3478 set options "-mcpu=cell"
3479 }
3480 check_runtime_nocache cell_hw_available {
3481 int main()
3482 {
3483 #ifdef __MACH__
3484 asm volatile ("vor v0,v0,v0");
3485 asm volatile ("lvlx v0,r0,r0");
3486 #else
3487 asm volatile ("vor 0,0,0");
3488 asm volatile ("lvlx 0,0,0");
3489 #endif
3490 return 0;
3491 }
3492 } $options
3493 }
3494 }]
3495 }
3496
3497 # Return 1 if the target supports executing 64-bit instructions, 0
3498 # otherwise. Cache the result.
3499
3500 proc check_effective_target_powerpc64 { } {
3501 global powerpc64_available_saved
3502 global tool
3503
3504 if [info exists powerpc64_available_saved] {
3505 verbose "check_effective_target_powerpc64 returning saved $powerpc64_available_saved" 2
3506 } else {
3507 set powerpc64_available_saved 0
3508
3509 # Some simulators are known to not support powerpc64 instructions.
3510 if { [istarget powerpc-*-eabi*] || [istarget powerpc-ibm-aix*] } {
3511 verbose "check_effective_target_powerpc64 returning 0" 2
3512 return $powerpc64_available_saved
3513 }
3514
3515 # Set up, compile, and execute a test program containing a 64-bit
3516 # instruction. Include the current process ID in the file
3517 # names to prevent conflicts with invocations for multiple
3518 # testsuites.
3519 set src ppc[pid].c
3520 set exe ppc[pid].x
3521
3522 set f [open $src "w"]
3523 puts $f "int main() {"
3524 puts $f "#ifdef __MACH__"
3525 puts $f " asm volatile (\"extsw r0,r0\");"
3526 puts $f "#else"
3527 puts $f " asm volatile (\"extsw 0,0\");"
3528 puts $f "#endif"
3529 puts $f " return 0; }"
3530 close $f
3531
3532 set opts "additional_flags=-mcpu=G5"
3533
3534 verbose "check_effective_target_powerpc64 compiling testfile $src" 2
3535 set lines [${tool}_target_compile $src $exe executable "$opts"]
3536 file delete $src
3537
3538 if [string match "" $lines] then {
3539 # No error message, compilation succeeded.
3540 set result [${tool}_load "./$exe" "" ""]
3541 set status [lindex $result 0]
3542 remote_file build delete $exe
3543 verbose "check_effective_target_powerpc64 testfile status is <$status>" 2
3544
3545 if { $status == "pass" } then {
3546 set powerpc64_available_saved 1
3547 }
3548 } else {
3549 verbose "check_effective_target_powerpc64 testfile compilation failed" 2
3550 }
3551 }
3552
3553 return $powerpc64_available_saved
3554 }
3555
3556 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
3557 # complex float arguments. This affects gfortran tests that call cabsf
3558 # in libm built by an earlier compiler. Return 0 if libm uses the same
3559 # argument passing as the compiler under test, 1 otherwise.
3560
3561 proc check_effective_target_broken_cplxf_arg { } {
3562 # Skip the work for targets known not to be affected.
3563 if { ![istarget powerpc*-*-linux*] || ![is-effective-target lp64] } {
3564 return 0
3565 }
3566
3567 return [check_cached_effective_target broken_cplxf_arg {
3568 check_runtime_nocache broken_cplxf_arg {
3569 #include <complex.h>
3570 extern void abort (void);
3571 float fabsf (float);
3572 float cabsf (_Complex float);
3573 int main ()
3574 {
3575 _Complex float cf;
3576 float f;
3577 cf = 3 + 4.0fi;
3578 f = cabsf (cf);
3579 if (fabsf (f - 5.0) > 0.0001)
3580 /* Yes, it's broken. */
3581 return 0;
3582 /* All fine, not broken. */
3583 return 1;
3584 }
3585 } "-lm"
3586 }]
3587 }
3588
3589 # Return 1 is this is a TI C6X target supporting C67X instructions
3590 proc check_effective_target_ti_c67x { } {
3591 return [check_no_compiler_messages ti_c67x assembly {
3592 #if !defined(_TMS320C6700)
3593 #error !_TMS320C6700
3594 #endif
3595 }]
3596 }
3597
3598 # Return 1 is this is a TI C6X target supporting C64X+ instructions
3599 proc check_effective_target_ti_c64xp { } {
3600 return [check_no_compiler_messages ti_c64xp assembly {
3601 #if !defined(_TMS320C6400_PLUS)
3602 #error !_TMS320C6400_PLUS
3603 #endif
3604 }]
3605 }
3606
3607 # Check if a -march=... option is given, as part of (earlier) options.
3608 proc check_effective_target_march_option { } {
3609 return [check-flags [list "" { *-*-* } { "-march=*" } { "" } ]]
3610 }
3611
3612 proc check_alpha_max_hw_available { } {
3613 return [check_runtime alpha_max_hw_available {
3614 int main() { return __builtin_alpha_amask(1<<8) != 0; }
3615 }]
3616 }
3617
3618 # Returns true iff the FUNCTION is available on the target system.
3619 # (This is essentially a Tcl implementation of Autoconf's
3620 # AC_CHECK_FUNC.)
3621
3622 proc check_function_available { function } {
3623 return [check_no_compiler_messages ${function}_available \
3624 executable [subst {
3625 #ifdef __cplusplus
3626 extern "C"
3627 #endif
3628 char $function ();
3629 int main () { $function (); }
3630 }] "-fno-builtin" ]
3631 }
3632
3633 # Returns true iff "fork" is available on the target system.
3634
3635 proc check_fork_available {} {
3636 if { [istarget *-*-vxworks*] } {
3637 # VxWorks doesn't have fork but our way to test can't
3638 # tell as we're doing partial links for kernel modules.
3639 return 0
3640 }
3641 if { [istarget cris-*-*] } {
3642 # Compiling and linking works, and an executable running e.g.
3643 # gcc.dg/torture/ftrapv-1.c works on now-historical hardware,
3644 # but the GNU simulator emits an error for the fork syscall.
3645 return [check_effective_target_hw]
3646 }
3647 return [check_function_available "fork"]
3648 }
3649
3650 # Returns true iff "mkfifo" is available on the target system.
3651
3652 proc check_mkfifo_available {} {
3653 if { [istarget *-*-cygwin*] } {
3654 # Cygwin has mkfifo, but support is incomplete.
3655 return 0
3656 }
3657
3658 return [check_function_available "mkfifo"]
3659 }
3660
3661 # Returns true iff "__cxa_atexit" is used on the target system.
3662
3663 proc check_cxa_atexit_available { } {
3664 return [check_cached_effective_target cxa_atexit_available {
3665 if { [istarget *-*-vxworks] } {
3666 # vxworks doesn't have __cxa_atexit but subsequent test passes.
3667 expr 0
3668 } else {
3669 check_runtime_nocache cxa_atexit_available {
3670 // C++
3671 #include <stdlib.h>
3672 static unsigned int count;
3673 struct X
3674 {
3675 X() { count = 1; }
3676 ~X()
3677 {
3678 if (count != 3)
3679 exit(1);
3680 count = 4;
3681 }
3682 };
3683 void f()
3684 {
3685 static X x;
3686 }
3687 struct Y
3688 {
3689 Y() { f(); count = 2; }
3690 ~Y()
3691 {
3692 if (count != 2)
3693 exit(1);
3694 count = 3;
3695 }
3696 };
3697 Y y;
3698 int main() { return 0; }
3699 }
3700 }
3701 }]
3702 }
3703
3704 proc check_effective_target_objc2 { } {
3705 return [check_no_compiler_messages objc2 object {
3706 #ifdef __OBJC2__
3707 int dummy[1];
3708 #else
3709 #error !__OBJC2__
3710 #endif
3711 }]
3712 }
3713
3714 proc check_effective_target_next_runtime { } {
3715 return [check_no_compiler_messages objc2 object {
3716 #ifdef __NEXT_RUNTIME__
3717 int dummy[1];
3718 #else
3719 #error !__NEXT_RUNTIME__
3720 #endif
3721 }]
3722 }
3723
3724 # Return 1 if we're generating code for big-endian memory order.
3725
3726 proc check_effective_target_be { } {
3727 return [check_no_compiler_messages be object {
3728 int dummy[__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ? 1 : -1];
3729 }]
3730 }
3731
3732 # Return 1 if we're generating code for little-endian memory order.
3733
3734 proc check_effective_target_le { } {
3735 return [check_no_compiler_messages le object {
3736 int dummy[__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ? 1 : -1];
3737 }]
3738 }
3739
3740 # Return 1 if we can link a program with 2+GB of data.
3741
3742 proc check_effective_target_two_plus_gigs { } {
3743 return [check_no_compiler_messages two_plus_gigs executable {
3744 char dummy[0x80000000];
3745 int main () { return 0; }
3746 }]
3747 }
3748
3749 # Return 1 if we're generating 32-bit code using default options, 0
3750 # otherwise.
3751
3752 proc check_effective_target_ilp32 { } {
3753 return [check_no_compiler_messages ilp32 object {
3754 int dummy[sizeof (int) == 4
3755 && sizeof (void *) == 4
3756 && sizeof (long) == 4 ? 1 : -1];
3757 }]
3758 }
3759
3760 # Return 1 if we're generating ia32 code using default options, 0
3761 # otherwise.
3762
3763 proc check_effective_target_ia32 { } {
3764 return [check_no_compiler_messages ia32 object {
3765 int dummy[sizeof (int) == 4
3766 && sizeof (void *) == 4
3767 && sizeof (long) == 4 ? 1 : -1] = { __i386__ };
3768 }]
3769 }
3770
3771 # Return 1 if we're generating x32 code using default options, 0
3772 # otherwise.
3773
3774 proc check_effective_target_x32 { } {
3775 return [check_no_compiler_messages x32 object {
3776 int dummy[sizeof (int) == 4
3777 && sizeof (void *) == 4
3778 && sizeof (long) == 4 ? 1 : -1] = { __x86_64__ };
3779 }]
3780 }
3781
3782 # Return 1 if we're generating 32-bit integers using default
3783 # options, 0 otherwise.
3784
3785 proc check_effective_target_int32 { } {
3786 return [check_no_compiler_messages int32 object {
3787 int dummy[sizeof (int) == 4 ? 1 : -1];
3788 }]
3789 }
3790
3791 # Return 1 if we're generating 32-bit or larger integers using default
3792 # options, 0 otherwise.
3793
3794 proc check_effective_target_int32plus { } {
3795 return [check_no_compiler_messages int32plus object {
3796 int dummy[sizeof (int) >= 4 ? 1 : -1];
3797 }]
3798 }
3799
3800 # Return 1 if we're generating 64-bit long long using default options,
3801 # 0 otherwise.
3802
3803 proc check_effective_target_longlong64 { } {
3804 return [check_no_compiler_messages longlong64 object {
3805 int dummy[sizeof (long long) == 8 ? 1 : -1];
3806 }]
3807 }
3808
3809 # Return 1 if we're generating 32-bit or larger pointers using default
3810 # options, 0 otherwise.
3811
3812 proc check_effective_target_ptr32plus { } {
3813 # The msp430 has 16-bit or 20-bit pointers. The 20-bit pointer is stored
3814 # in a 32-bit slot when in memory, so sizeof(void *) returns 4, but it
3815 # cannot really hold a 32-bit address, so we always return false here.
3816 if { [istarget msp430-*-*] } {
3817 return 0
3818 }
3819
3820 return [check_no_compiler_messages ptr32plus object {
3821 int dummy[sizeof (void *) >= 4 ? 1 : -1];
3822 }]
3823 }
3824
3825 # Return 1 if we support 16-bit or larger array and structure sizes
3826 # using default options, 0 otherwise.
3827 # This implies at least a 20-bit address space, as no targets have an address
3828 # space between 16 and 20 bits.
3829
3830 proc check_effective_target_size20plus { } {
3831 return [check_no_compiler_messages size20plus object {
3832 char dummy[65537L];
3833 }]
3834 }
3835
3836 # Return 1 if target supports function pointers, 0 otherwise.
3837
3838 proc check_effective_target_function_pointers { } {
3839 if { [istarget pru-*-*] } {
3840 return [check_no_compiler_messages func_ptr_avail assembly {
3841 #ifdef __PRU_EABI_GNU__
3842 #error unsupported
3843 #endif
3844 }]
3845 }
3846 return 1
3847 }
3848
3849 # Return 1 if target supports arbitrarily large return values, 0 otherwise.
3850
3851 proc check_effective_target_large_return_values { } {
3852 if { [istarget pru-*-*] } {
3853 return [check_no_compiler_messages large_return_values assembly {
3854 #ifdef __PRU_EABI_GNU__
3855 #error unsupported
3856 #endif
3857 }]
3858 }
3859 return 1
3860 }
3861 # Return 1 if we support 20-bit or larger array and structure sizes
3862 # using default options, 0 otherwise.
3863 # This implies at least a 24-bit address space, as no targets have an address
3864 # space between 20 and 24 bits.
3865
3866 proc check_effective_target_size24plus { } {
3867 return [check_no_compiler_messages size24plus object {
3868 char dummy[524289L];
3869 }]
3870 }
3871
3872 # Return 1 if we support 24-bit or larger array and structure sizes
3873 # using default options, 0 otherwise.
3874 # This implies at least a 32-bit address space, as no targets have an address
3875 # space between 24 and 32 bits.
3876
3877 proc check_effective_target_size32plus { } {
3878 return [check_no_compiler_messages size32plus object {
3879 char dummy[16777217L];
3880 }]
3881 }
3882
3883 # Returns 1 if we're generating 16-bit or smaller integers with the
3884 # default options, 0 otherwise.
3885
3886 proc check_effective_target_int16 { } {
3887 return [check_no_compiler_messages int16 object {
3888 int dummy[sizeof (int) < 4 ? 1 : -1];
3889 }]
3890 }
3891
3892 # Return 1 if we're generating 64-bit code using default options, 0
3893 # otherwise.
3894
3895 proc check_effective_target_lp64 { } {
3896 return [check_no_compiler_messages lp64 object {
3897 int dummy[sizeof (int) == 4
3898 && sizeof (void *) == 8
3899 && sizeof (long) == 8 ? 1 : -1];
3900 }]
3901 }
3902
3903 # Return 1 if we're generating 64-bit code using default llp64 options,
3904 # 0 otherwise.
3905
3906 proc check_effective_target_llp64 { } {
3907 return [check_no_compiler_messages llp64 object {
3908 int dummy[sizeof (int) == 4
3909 && sizeof (void *) == 8
3910 && sizeof (long long) == 8
3911 && sizeof (long) == 4 ? 1 : -1];
3912 }]
3913 }
3914
3915 # Return 1 if long and int have different sizes,
3916 # 0 otherwise.
3917
3918 proc check_effective_target_long_neq_int { } {
3919 return [check_no_compiler_messages long_ne_int object {
3920 int dummy[sizeof (int) != sizeof (long) ? 1 : -1];
3921 }]
3922 }
3923
3924 # Return 1 if int size is equal to float size,
3925 # 0 otherwise.
3926
3927 proc check_effective_target_int_eq_float { } {
3928 return [check_no_compiler_messages int_eq_float object {
3929 int dummy[sizeof (int) >= sizeof (float) ? 1 : -1];
3930 }]
3931 }
3932
3933 # Return 1 if short size is equal to int size,
3934 # 0 otherwise.
3935
3936 proc check_effective_target_short_eq_int { } {
3937 return [check_no_compiler_messages short_eq_int object {
3938 int dummy[sizeof (short) == sizeof (int) ? 1 : -1];
3939 }]
3940 }
3941
3942 # Return 1 if pointer size is equal to short size,
3943 # 0 otherwise.
3944
3945 proc check_effective_target_ptr_eq_short { } {
3946 return [check_no_compiler_messages ptr_eq_short object {
3947 int dummy[sizeof (void *) == sizeof (short) ? 1 : -1];
3948 }]
3949 }
3950
3951 # Return 1 if pointer size is equal to long size,
3952 # 0 otherwise.
3953
3954 proc check_effective_target_ptr_eq_long { } {
3955 # sizeof (void *) == 4 for msp430-elf -mlarge which is equal to
3956 # sizeof (long). Avoid false positive.
3957 if { [istarget msp430-*-*] } {
3958 return 0
3959 }
3960 return [check_no_compiler_messages ptr_eq_long object {
3961 int dummy[sizeof (void *) == sizeof (long) ? 1 : -1];
3962 }]
3963 }
3964
3965 # Return 1 if the target supports long double larger than double,
3966 # 0 otherwise.
3967
3968 proc check_effective_target_large_long_double { } {
3969 return [check_no_compiler_messages large_long_double object {
3970 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
3971 }]
3972 }
3973
3974 # Return 1 if the target supports double larger than float,
3975 # 0 otherwise.
3976
3977 proc check_effective_target_large_double { } {
3978 return [check_no_compiler_messages large_double object {
3979 int dummy[sizeof(double) > sizeof(float) ? 1 : -1];
3980 }]
3981 }
3982
3983 # Return 1 if the target supports long double of 128 bits,
3984 # 0 otherwise.
3985
3986 proc check_effective_target_longdouble128 { } {
3987 return [check_no_compiler_messages longdouble128 object {
3988 int dummy[sizeof(long double) == 16 ? 1 : -1];
3989 }]
3990 }
3991
3992 # Return 1 if the target supports long double of 64 bits,
3993 # 0 otherwise.
3994
3995 proc check_effective_target_longdouble64 { } {
3996 return [check_no_compiler_messages longdouble64 object {
3997 int dummy[sizeof(long double) == 8 ? 1 : -1];
3998 }]
3999 }
4000
4001 # Return 1 if the target supports double of 64 bits,
4002 # 0 otherwise.
4003
4004 proc check_effective_target_double64 { } {
4005 return [check_no_compiler_messages double64 object {
4006 int dummy[sizeof(double) == 8 ? 1 : -1];
4007 }]
4008 }
4009
4010 # Return 1 if the target supports double of at least 64 bits,
4011 # 0 otherwise.
4012
4013 proc check_effective_target_double64plus { } {
4014 return [check_no_compiler_messages double64plus object {
4015 int dummy[sizeof(double) >= 8 ? 1 : -1];
4016 }]
4017 }
4018
4019 # Return 1 if the target supports 'w' suffix on floating constant
4020 # 0 otherwise.
4021
4022 proc check_effective_target_has_w_floating_suffix { } {
4023 set opts ""
4024 if [check_effective_target_c++] {
4025 append opts "-std=gnu++03"
4026 }
4027 return [check_no_compiler_messages w_fp_suffix object {
4028 float dummy = 1.0w;
4029 } "$opts"]
4030 }
4031
4032 # Return 1 if the target supports 'q' suffix on floating constant
4033 # 0 otherwise.
4034
4035 proc check_effective_target_has_q_floating_suffix { } {
4036 set opts ""
4037 if [check_effective_target_c++] {
4038 append opts "-std=gnu++03"
4039 }
4040 return [check_no_compiler_messages q_fp_suffix object {
4041 float dummy = 1.0q;
4042 } "$opts"]
4043 }
4044
4045 # Return 1 if the target supports the _FloatN / _FloatNx type
4046 # indicated in the function name, 0 otherwise.
4047
4048 proc check_effective_target_float16 {} {
4049 return [check_no_compiler_messages_nocache float16 object {
4050 _Float16 foo (_Float16 x) { return x; }
4051 } [add_options_for_float16 ""]]
4052 }
4053
4054 proc check_effective_target_float32 {} {
4055 return [check_no_compiler_messages_nocache float32 object {
4056 _Float32 x;
4057 } [add_options_for_float32 ""]]
4058 }
4059
4060 proc check_effective_target_float64 {} {
4061 return [check_no_compiler_messages_nocache float64 object {
4062 _Float64 x;
4063 } [add_options_for_float64 ""]]
4064 }
4065
4066 proc check_effective_target_float128 {} {
4067 return [check_no_compiler_messages_nocache float128 object {
4068 _Float128 x;
4069 } [add_options_for_float128 ""]]
4070 }
4071
4072 proc check_effective_target_float32x {} {
4073 return [check_no_compiler_messages_nocache float32x object {
4074 _Float32x x;
4075 } [add_options_for_float32x ""]]
4076 }
4077
4078 proc check_effective_target_float64x {} {
4079 return [check_no_compiler_messages_nocache float64x object {
4080 _Float64x x;
4081 } [add_options_for_float64x ""]]
4082 }
4083
4084 proc check_effective_target_float128x {} {
4085 return [check_no_compiler_messages_nocache float128x object {
4086 _Float128x x;
4087 } [add_options_for_float128x ""]]
4088 }
4089
4090 # Likewise, but runtime support for any special options used as well
4091 # as compile-time support is required.
4092
4093 proc check_effective_target_float16_runtime {} {
4094 return [check_effective_target_float16]
4095 }
4096
4097 proc check_effective_target_float32_runtime {} {
4098 return [check_effective_target_float32]
4099 }
4100
4101 proc check_effective_target_float64_runtime {} {
4102 return [check_effective_target_float64]
4103 }
4104
4105 proc check_effective_target_float128_runtime {} {
4106 if { ![check_effective_target_float128] } {
4107 return 0
4108 }
4109 if { [istarget powerpc*-*-*] } {
4110 return [check_effective_target_base_quadfloat_support]
4111 }
4112 return 1
4113 }
4114
4115 proc check_effective_target_float32x_runtime {} {
4116 return [check_effective_target_float32x]
4117 }
4118
4119 proc check_effective_target_float64x_runtime {} {
4120 if { ![check_effective_target_float64x] } {
4121 return 0
4122 }
4123 if { [istarget powerpc*-*-*] } {
4124 return [check_effective_target_base_quadfloat_support]
4125 }
4126 return 1
4127 }
4128
4129 proc check_effective_target_float128x_runtime {} {
4130 return [check_effective_target_float128x]
4131 }
4132
4133 # Return 1 if the target hardware supports any options added for
4134 # _FloatN and _FloatNx types, 0 otherwise.
4135
4136 proc check_effective_target_floatn_nx_runtime {} {
4137 if { [istarget powerpc*-*-aix*] } {
4138 return 0
4139 }
4140 if { [istarget powerpc*-*-*] } {
4141 return [check_effective_target_base_quadfloat_support]
4142 }
4143 return 1
4144 }
4145
4146 # Return 1 when double is at least as good as _Float32x, i.e. double can
4147 # be used to emulate _Float32x.
4148
4149 proc check_effective_target_double_float32xplus {} {
4150 return [check_no_compiler_messages_nocache double_float32xplus object {
4151 _Float32x x;
4152 int dummy1[__DBL_MANT_DIG__ >= __FLT32X_MANT_DIG__ ? 1 : -1];
4153 int dummy2[__DBL_MAX_EXP__ >= __FLT32X_MAX_EXP__ ? 1 : -1];
4154 } [add_options_for_float32x ""]]
4155 }
4156
4157 # Add options needed to use the _FloatN / _FloatNx type indicated in
4158 # the function name.
4159
4160 proc add_options_for_float16 { flags } {
4161 if { [istarget arm*-*-*] } {
4162 return "$flags -mfp16-format=ieee"
4163 }
4164 if { [check_effective_target_x86] } {
4165 return "$flags -msse2 -mfpmath=sse"
4166 }
4167 return "$flags"
4168 }
4169
4170 proc add_options_for_float32 { flags } {
4171 return "$flags"
4172 }
4173
4174 proc add_options_for_float64 { flags } {
4175 return "$flags"
4176 }
4177
4178 proc add_options_for_float128 { flags } {
4179 return [add_options_for___float128 "$flags"]
4180 }
4181
4182 proc add_options_for_float32x { flags } {
4183 return "$flags"
4184 }
4185
4186 proc add_options_for_float64x { flags } {
4187 return [add_options_for___float128 "$flags"]
4188 }
4189
4190 proc add_options_for_float128x { flags } {
4191 return "$flags"
4192 }
4193
4194 # Return 1 if the target supports __float128,
4195 # 0 otherwise.
4196
4197 proc check_effective_target___float128 { } {
4198 if { [istarget powerpc*-*-*] } {
4199 return [check_ppc_float128_sw_available]
4200 }
4201 if { [istarget ia64-*-*]
4202 || [check_effective_target_x86] } {
4203 return 1
4204 }
4205 return 0
4206 }
4207
4208 proc add_options_for___float128 { flags } {
4209 if { [istarget powerpc*-*-linux*] } {
4210 return "$flags -mfloat128 -mvsx"
4211 }
4212 return "$flags"
4213 }
4214
4215 # Return 1 if the target supports any special run-time requirements
4216 # for __float128 or _Float128,
4217 # 0 otherwise.
4218
4219 proc check_effective_target_base_quadfloat_support { } {
4220 if { [istarget powerpc*-*-*] } {
4221 return [check_vsx_hw_available]
4222 }
4223 return 1
4224 }
4225
4226 # Return 1 if the target supports the __bf16 type, 0 otherwise.
4227
4228 proc check_effective_target_bfloat16 {} {
4229 return [check_no_compiler_messages_nocache bfloat16 object {
4230 __bf16 foo (__bf16 x) { return x + x; }
4231 } [add_options_for_bfloat16 ""]]
4232 }
4233
4234 proc check_effective_target_bfloat16_runtime {} {
4235 return [check_effective_target_bfloat16]
4236 }
4237
4238 proc add_options_for_bfloat16 { flags } {
4239 if { [check_effective_target_x86] } {
4240 return "$flags -msse2"
4241 }
4242 return "$flags"
4243 }
4244
4245 # Return 1 if the target supports all four forms of fused multiply-add
4246 # (fma, fms, fnma, and fnms) for both float and double.
4247
4248 proc check_effective_target_scalar_all_fma { } {
4249 if { [istarget aarch64*-*-*]
4250 || [istarget loongarch*-*-*]} {
4251 return 1
4252 }
4253 return 0
4254 }
4255
4256 # Return 1 if the target supports compiling fixed-point,
4257 # 0 otherwise.
4258
4259 proc check_effective_target_fixed_point { } {
4260 return [check_no_compiler_messages fixed_point object {
4261 _Sat _Fract x; _Sat _Accum y;
4262 }]
4263 }
4264
4265 # Return 1 if the target supports _BitInt(N), 0 otherwise.
4266
4267 proc check_effective_target_bitint { } {
4268 return [check_no_compiler_messages bitint object {
4269 _BitInt (2) a = 1wb;
4270 unsigned _BitInt (__BITINT_MAXWIDTH__) b = 0uwb;
4271 } "-std=c23"]
4272 }
4273
4274 # Return 1 if the target supports _BitInt(128), 0 otherwise.
4275
4276 proc check_effective_target_bitint128 { } {
4277 return [check_no_compiler_messages bitint128 object {
4278 _BitInt (2) a = 1wb;
4279 unsigned _BitInt (128) b = 0uwb;
4280 } "-std=c23"]
4281 }
4282
4283 # Return 1 if the target supports _BitInt(575), 0 otherwise.
4284
4285 proc check_effective_target_bitint575 { } {
4286 return [check_no_compiler_messages bitint575 object {
4287 _BitInt (2) a = 1wb;
4288 unsigned _BitInt (575) b = 0uwb;
4289 } "-std=c23"]
4290 }
4291
4292 # Return 1 if the target supports _BitInt(65535), 0 otherwise.
4293
4294 proc check_effective_target_bitint65535 { } {
4295 return [check_no_compiler_messages bitint65535 object {
4296 _BitInt (2) a = 1wb;
4297 unsigned _BitInt (65535) b = 0uwb;
4298 } "-std=c23"]
4299 }
4300
4301 # Return 1 if the target supports compiling decimal floating point,
4302 # 0 otherwise.
4303
4304 proc check_effective_target_dfp_nocache { } {
4305 verbose "check_effective_target_dfp_nocache: compiling source" 2
4306 set ret [check_no_compiler_messages_nocache dfp object {
4307 float x __attribute__((mode(DD)));
4308 }]
4309 verbose "check_effective_target_dfp_nocache: returning $ret" 2
4310 return $ret
4311 }
4312
4313 proc check_effective_target_dfprt_nocache { } {
4314 return [check_runtime_nocache dfprt {
4315 typedef float d64 __attribute__((mode(DD)));
4316 d64 x = 1.2df, y = 2.3dd, z;
4317 int main () { z = x + y; return 0; }
4318 }]
4319 }
4320
4321 # Return 1 if the target supports compiling Decimal Floating Point,
4322 # 0 otherwise.
4323 #
4324 # This won't change for different subtargets so cache the result.
4325
4326 proc check_effective_target_dfp { } {
4327 return [check_cached_effective_target dfp {
4328 check_effective_target_dfp_nocache
4329 }]
4330 }
4331
4332 # Return 1 if the target supports linking and executing Decimal Floating
4333 # Point, 0 otherwise.
4334 #
4335 # This won't change for different subtargets so cache the result.
4336
4337 proc check_effective_target_dfprt { } {
4338 return [check_cached_effective_target dfprt {
4339 check_effective_target_dfprt_nocache
4340 }]
4341 }
4342
4343 # Return 1 if the target uses the BID format for Decimal Floating
4344 # Point, 0 otherwise.
4345
4346 proc check_effective_target_dfp_bid { } {
4347 if { [istarget aarch64*-*-*]
4348 || [check_effective_target_x86]} {
4349 return 1
4350 }
4351 return 0
4352 }
4353
4354 # Return 1 iff target has unsigned plain 'char' by default.
4355
4356 proc check_effective_target_unsigned_char {} {
4357 return [check_no_compiler_messages unsigned_char assembly {
4358 char ar[(char)-1];
4359 }]
4360 }
4361
4362 # Return 1 if the target supports executing DFP hardware instructions,
4363 # 0 otherwise. Cache the result.
4364
4365 proc check_dfp_hw_available { } {
4366 return [check_cached_effective_target dfp_hw_available {
4367 # For now, disable on Darwin
4368 if { [istarget powerpc-*-eabi] || [istarget *-*-darwin*]} {
4369 expr 0
4370 } else {
4371 check_runtime_nocache dfp_hw_available {
4372 volatile _Decimal64 r;
4373 volatile _Decimal64 a = 4.0DD;
4374 volatile _Decimal64 b = 2.0DD;
4375 int main()
4376 {
4377 asm volatile ("dadd %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
4378 asm volatile ("dsub %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
4379 asm volatile ("dmul %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
4380 asm volatile ("ddiv %0,%1,%2" : "=d" (r) : "d" (a), "d" (b));
4381 return 0;
4382 }
4383 } "-mcpu=power6 -mhard-float"
4384 }
4385 }]
4386 }
4387
4388 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
4389
4390 proc check_effective_target_ucn_nocache { } {
4391 # -std=c99 is only valid for C
4392 if [check_effective_target_c] {
4393 set ucnopts "-std=c99"
4394 } else {
4395 set ucnopts ""
4396 }
4397 verbose "check_effective_target_ucn_nocache: compiling source" 2
4398 set ret [check_no_compiler_messages_nocache ucn object {
4399 int \u00C0;
4400 } $ucnopts]
4401 verbose "check_effective_target_ucn_nocache: returning $ret" 2
4402 return $ret
4403 }
4404
4405 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
4406 #
4407 # This won't change for different subtargets, so cache the result.
4408
4409 proc check_effective_target_ucn { } {
4410 return [check_cached_effective_target ucn {
4411 check_effective_target_ucn_nocache
4412 }]
4413 }
4414
4415 # Return 1 if the target needs a command line argument to enable a SIMD
4416 # instruction set.
4417
4418 proc check_effective_target_vect_cmdline_needed { } {
4419 global et_vect_cmdline_needed_target_name
4420
4421 if { ![info exists et_vect_cmdline_needed_target_name] } {
4422 set et_vect_cmdline_needed_target_name ""
4423 }
4424
4425 # If the target has changed since we set the cached value, clear it.
4426 set current_target [current_target_name]
4427 if { $current_target != $et_vect_cmdline_needed_target_name } {
4428 verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
4429 set et_vect_cmdline_needed_target_name $current_target
4430 if { [info exists et_vect_cmdline_needed_saved] } {
4431 verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
4432 unset et_vect_cmdline_needed_saved
4433 }
4434 }
4435
4436 return [check_cached_effective_target vect_cmdline_needed {
4437 if { [istarget alpha*-*-*]
4438 || [istarget ia64-*-*]
4439 || ([check_effective_target_x86]
4440 && ![is-effective-target ia32])
4441 || ([istarget powerpc*-*-*]
4442 && [check_effective_target_powerpc_altivec])
4443 || ([istarget sparc*-*-*] && [check_effective_target_sparc_vis])
4444 || ([istarget arm*-*-*] && ([check_effective_target_arm_neon]
4445 || [check_effective_target_arm_mve])
4446 )
4447 || [istarget aarch64*-*-*]
4448 || [istarget amdgcn*-*-*]
4449 || [istarget riscv*-*-*]} {
4450 return 0
4451 } else {
4452 return 1
4453 }}]
4454 }
4455
4456 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
4457 #
4458 # This won't change for different subtargets so cache the result.
4459
4460 proc check_effective_target_vect_int { } {
4461 return [check_cached_effective_target_indexed vect_int {
4462 expr {
4463 [check_effective_target_x86]
4464 || [istarget powerpc*-*-*]
4465 || [istarget amdgcn-*-*]
4466 || [istarget sparc*-*-*]
4467 || [istarget alpha*-*-*]
4468 || [istarget ia64-*-*]
4469 || [istarget aarch64*-*-*]
4470 || [is-effective-target arm_neon]
4471 || ([istarget mips*-*-*]
4472 && ([et-is-effective-target mips_loongson_mmi]
4473 || [et-is-effective-target mips_msa]))
4474 || ([istarget s390*-*-*]
4475 && [check_effective_target_s390_vx])
4476 || ([istarget riscv*-*-*]
4477 && [check_effective_target_riscv_v])
4478 || ([istarget loongarch*-*-*]
4479 && [check_effective_target_loongarch_sx])
4480 }}]
4481 }
4482
4483 # Return 1 if the target supports vector integer division, 0 otherwise.
4484 proc check_effective_target_vect_int_div { } {
4485 return [check_effective_target_aarch64_sve]
4486 }
4487
4488 # Return 1 if the target supports two-way dot products on inpus of hi mode
4489 # producing si outputs, 0 otherwise.
4490
4491 proc check_effective_target_vect_dotprod_hisi { } {
4492 return [check_cached_effective_target_indexed aarch64_sme2 {
4493 expr { [check_effective_target_aarch64_sme2]
4494 }}]
4495 }
4496
4497 # Return 1 if the target supports vectorization of early breaks,
4498 # 0 otherwise.
4499 #
4500 # This won't change for different subtargets so cache the result.
4501
4502 proc check_effective_target_vect_early_break { } {
4503 return [check_cached_effective_target_indexed vect_early_break {
4504 expr {
4505 [istarget aarch64*-*-*]
4506 || [check_effective_target_arm_v8_neon_ok]
4507 || [check_effective_target_sse4]
4508 || [istarget amdgcn-*-*]
4509 || [check_effective_target_riscv_v]
4510 || [check_effective_target_loongarch_sx]
4511 }}]
4512 }
4513
4514 # Return 1 if the target supports hardware execution of early breaks,
4515 # 0 otherwise.
4516 #
4517 # This won't change for different subtargets so cache the result.
4518
4519 proc check_effective_target_vect_early_break_hw { } {
4520 return [check_cached_effective_target_indexed vect_early_break_hw {
4521 expr {
4522 [istarget aarch64*-*-*]
4523 || [check_effective_target_arm_v8_neon_hw]
4524 || [check_sse4_hw_available]
4525 || [istarget amdgcn-*-*]
4526 || [check_effective_target_riscv_v_ok]
4527 || [check_effective_target_loongarch_sx_hw]
4528 }}]
4529 }
4530
4531 proc add_options_for_vect_early_break { flags } {
4532 if { ! [check_effective_target_vect_early_break] } {
4533 return "$flags"
4534 }
4535
4536 if { [check_effective_target_arm_v8_neon_ok] } {
4537 global et_arm_v8_neon_flags
4538 return "$flags $et_arm_v8_neon_flags -mcpu=unset -march=armv8-a"
4539 }
4540
4541 if { [check_effective_target_sse4] } {
4542 return "$flags -msse4.1"
4543 }
4544
4545 return "$flags"
4546 }
4547
4548 # Return 1 if the target supports hardware vectorization of complex additions of
4549 # byte, 0 otherwise.
4550 #
4551 # This won't change for different subtargets so cache the result.
4552
4553 proc check_effective_target_vect_complex_add_byte { } {
4554 return [check_cached_effective_target_indexed vect_complex_add_byte {
4555 expr {
4556 ([check_effective_target_aarch64_sve2]
4557 && [check_effective_target_aarch64_little_endian])
4558 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
4559 && [check_effective_target_arm_little_endian])
4560 }}]
4561 }
4562
4563 # Return 1 if the target supports hardware vectorization of complex additions of
4564 # short, 0 otherwise.
4565 #
4566 # This won't change for different subtargets so cache the result.
4567
4568 proc check_effective_target_vect_complex_add_short { } {
4569 return [check_cached_effective_target_indexed vect_complex_add_short {
4570 expr {
4571 ([check_effective_target_aarch64_sve2]
4572 && [check_effective_target_aarch64_little_endian])
4573 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
4574 && [check_effective_target_arm_little_endian])
4575 }}]
4576 }
4577
4578 # Return 1 if the target supports hardware vectorization of complex additions of
4579 # int, 0 otherwise.
4580 #
4581 # This won't change for different subtargets so cache the result.
4582
4583 proc check_effective_target_vect_complex_add_int { } {
4584 return [check_cached_effective_target_indexed vect_complex_add_int {
4585 expr {
4586 ([check_effective_target_aarch64_sve2]
4587 && [check_effective_target_aarch64_little_endian])
4588 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
4589 && [check_effective_target_arm_little_endian])
4590 }}]
4591 }
4592
4593 # Return 1 if the target supports hardware vectorization of complex additions of
4594 # long, 0 otherwise.
4595 #
4596 # This won't change for different subtargets so cache the result.
4597
4598 proc check_effective_target_vect_complex_add_long { } {
4599 return [check_cached_effective_target_indexed vect_complex_add_long {
4600 expr {
4601 ([check_effective_target_aarch64_sve2]
4602 && [check_effective_target_aarch64_little_endian])
4603 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
4604 && [check_effective_target_arm_little_endian])
4605 }}]
4606 }
4607
4608 # Return 1 if the target supports hardware vectorization of complex additions of
4609 # half, 0 otherwise.
4610 #
4611 # This won't change for different subtargets so cache the result.
4612
4613 proc check_effective_target_vect_complex_add_half { } {
4614 return [check_cached_effective_target_indexed vect_complex_add_half {
4615 expr {
4616 ([check_effective_target_arm_v8_3a_fp16_complex_neon_ok]
4617 && ([check_effective_target_aarch64_little_endian]
4618 || [check_effective_target_arm_little_endian]))
4619 || ([check_effective_target_aarch64_sve2]
4620 && [check_effective_target_aarch64_little_endian])
4621 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
4622 && [check_effective_target_arm_little_endian])
4623 }}]
4624 }
4625
4626 # Return 1 if the target supports hardware vectorization of complex additions of
4627 # float, 0 otherwise.
4628 #
4629 # This won't change for different subtargets so cache the result.
4630
4631 proc check_effective_target_vect_complex_add_float { } {
4632 return [check_cached_effective_target_indexed vect_complex_add_float {
4633 expr {
4634 ([check_effective_target_arm_v8_3a_complex_neon_ok]
4635 && ([check_effective_target_aarch64_little_endian]
4636 || [check_effective_target_arm_little_endian]))
4637 || ([check_effective_target_aarch64_sve2]
4638 && [check_effective_target_aarch64_little_endian])
4639 || ([check_effective_target_arm_v8_1m_mve_fp_ok]
4640 && [check_effective_target_arm_little_endian])
4641 }}]
4642 }
4643
4644 # Return 1 if the target supports hardware vectorization of complex additions of
4645 # double, 0 otherwise.
4646 #
4647 # This won't change for different subtargets so cache the result.
4648
4649 proc check_effective_target_vect_complex_add_double { } {
4650 return [check_cached_effective_target_indexed vect_complex_add_double {
4651 expr {
4652 (([check_effective_target_arm_v8_3a_complex_neon_ok]
4653 && [check_effective_target_aarch64_little_endian])
4654 || ([check_effective_target_aarch64_sve2]
4655 && [check_effective_target_aarch64_little_endian]))
4656 }}]
4657 }
4658
4659 # Return 1 if the target supports signed int->float conversion
4660 #
4661
4662 proc check_effective_target_vect_intfloat_cvt { } {
4663 return [check_cached_effective_target_indexed vect_intfloat_cvt {
4664 expr { [check_effective_target_x86]
4665 || [istarget powerpc*-*-*]
4666 || [is-effective-target arm_neon]
4667 || ([istarget mips*-*-*]
4668 && [et-is-effective-target mips_msa])
4669 || [istarget amdgcn-*-*]
4670 || ([istarget s390*-*-*]
4671 && [check_effective_target_s390_vxe2])
4672 || ([istarget riscv*-*-*]
4673 && [check_effective_target_riscv_v])
4674 || ([istarget loongarch*-*-*]
4675 && [check_effective_target_loongarch_sx]) }}]
4676 }
4677
4678 # Return 1 if the target supports signed double->int conversion
4679 #
4680
4681 proc check_effective_target_vect_doubleint_cvt { } {
4682 return [check_cached_effective_target_indexed vect_doubleint_cvt {
4683 expr { ([check_effective_target_x86]
4684 && [check_no_compiler_messages vect_doubleint_cvt assembly {
4685 #ifdef __tune_atom__
4686 # error No double vectorizer support.
4687 #endif
4688 }])
4689 || [istarget aarch64*-*-*]
4690 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
4691 || ([istarget mips*-*-*]
4692 && [et-is-effective-target mips_msa])
4693 || ([istarget s390*-*-*]
4694 && [check_effective_target_s390_vx])
4695 || ([istarget riscv*-*-*]
4696 && [check_effective_target_riscv_v])
4697 || ([istarget loongarch*-*-*]
4698 && [check_effective_target_loongarch_sx]) }}]
4699 }
4700
4701 # Return 1 if the target supports signed int->double conversion
4702 #
4703
4704 proc check_effective_target_vect_intdouble_cvt { } {
4705 return [check_cached_effective_target_indexed vect_intdouble_cvt {
4706 expr { ([check_effective_target_x86]
4707 && [check_no_compiler_messages vect_intdouble_cvt assembly {
4708 #ifdef __tune_atom__
4709 # error No double vectorizer support.
4710 #endif
4711 }])
4712 || [istarget aarch64*-*-*]
4713 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
4714 || ([istarget mips*-*-*]
4715 && [et-is-effective-target mips_msa])
4716 || ([istarget s390*-*-*]
4717 && [check_effective_target_s390_vx])
4718 || ([istarget riscv*-*-*]
4719 && [check_effective_target_riscv_v])
4720 || ([istarget loongarch*-*-*]
4721 && [check_effective_target_loongarch_sx]) }}]
4722 }
4723
4724 #Return 1 if we're supporting __int128 for target, 0 otherwise.
4725
4726 proc check_effective_target_int128 { } {
4727 return [check_no_compiler_messages int128 object {
4728 int dummy[
4729 #ifndef __SIZEOF_INT128__
4730 -1
4731 #else
4732 1
4733 #endif
4734 ];
4735 }]
4736 }
4737
4738 # Return 1 if the target supports unsigned int->float conversion
4739 #
4740
4741 proc check_effective_target_vect_uintfloat_cvt { } {
4742 return [check_cached_effective_target_indexed vect_uintfloat_cvt {
4743 expr { [check_effective_target_x86]
4744 || [istarget powerpc*-*-*]
4745 || [istarget aarch64*-*-*]
4746 || [is-effective-target arm_neon]
4747 || ([istarget mips*-*-*]
4748 && [et-is-effective-target mips_msa])
4749 || [istarget amdgcn-*-*]
4750 || ([istarget s390*-*-*]
4751 && [check_effective_target_s390_vxe2])
4752 || ([istarget riscv*-*-*]
4753 && [check_effective_target_riscv_v])
4754 || ([istarget loongarch*-*-*]
4755 && [check_effective_target_loongarch_sx]) }}]
4756 }
4757
4758
4759 # Return 1 if the target supports signed float->int conversion
4760 #
4761
4762 proc check_effective_target_vect_floatint_cvt { } {
4763 return [check_cached_effective_target_indexed vect_floatint_cvt {
4764 expr { [check_effective_target_x86]
4765 || [istarget powerpc*-*-*]
4766 || [is-effective-target arm_neon]
4767 || ([istarget mips*-*-*]
4768 && [et-is-effective-target mips_msa])
4769 || [istarget amdgcn-*-*]
4770 || ([istarget s390*-*-*]
4771 && [check_effective_target_s390_vxe2])
4772 || ([istarget riscv*-*-*]
4773 && [check_effective_target_riscv_v])
4774 || ([istarget loongarch*-*-*]
4775 && [check_effective_target_loongarch_sx]) }}]
4776 }
4777
4778 # Return 1 if the target supports unsigned float->int conversion
4779 #
4780
4781 proc check_effective_target_vect_floatuint_cvt { } {
4782 return [check_cached_effective_target_indexed vect_floatuint_cvt {
4783 expr { [istarget powerpc*-*-*]
4784 || [is-effective-target arm_neon]
4785 || ([istarget mips*-*-*]
4786 && [et-is-effective-target mips_msa])
4787 || [istarget amdgcn-*-*]
4788 || ([istarget s390*-*-*]
4789 && [check_effective_target_s390_vxe2])
4790 || ([istarget riscv*-*-*]
4791 && [check_effective_target_riscv_v])
4792 || ([istarget loongarch*-*-*]
4793 && [check_effective_target_loongarch_sx]) }}]
4794 }
4795
4796 # Return 1 if the target supports vector integer char -> long long extend optab
4797 #
4798
4799 proc check_effective_target_vect_ext_char_longlong { } {
4800 return [check_cached_effective_target_indexed vect_ext_char_longlong {
4801 expr { ([istarget riscv*-*-*]
4802 && [check_effective_target_riscv_v])
4803 || ([istarget loongarch*-*-*]
4804 && [check_effective_target_loongarch_sx]) }}]
4805 }
4806
4807 # Return 1 if peeling for alignment might be profitable on the target
4808 #
4809
4810 proc check_effective_target_vect_peeling_profitable { } {
4811 return [check_cached_effective_target_indexed vect_peeling_profitable {
4812 expr { ([istarget s390*-*-*]
4813 && [check_effective_target_s390_vx])
4814 || [check_effective_target_vect_element_align_preferred] }}]
4815 }
4816
4817 # Return 1 if the target supports #pragma omp declare simd, 0 otherwise.
4818 #
4819 # This won't change for different subtargets so cache the result.
4820
4821 proc check_effective_target_vect_simd_clones { } {
4822 # On i?86/x86_64 #pragma omp declare simd builds a sse2, avx,
4823 # avx2 and avx512f clone. Only the right clone for the
4824 # specified arch will be chosen, but still we need to at least
4825 # be able to assemble avx512f.
4826 return [check_cached_effective_target_indexed vect_simd_clones {
4827 expr { ([check_effective_target_x86]
4828 && [check_effective_target_avx512f])
4829 || [istarget amdgcn-*-*]
4830 || [istarget aarch64*-*-*] }}]
4831 }
4832
4833 # Return 1 if this is a AArch64 target supporting big endian
4834 proc check_effective_target_aarch64_big_endian { } {
4835 return [check_no_compiler_messages aarch64_big_endian assembly {
4836 #if !defined(__aarch64__) || !defined(__AARCH64EB__)
4837 #error !__aarch64__ || !__AARCH64EB__
4838 #endif
4839 }]
4840 }
4841
4842 # Return 1 if this is a AArch64 target supporting little endian
4843 proc check_effective_target_aarch64_little_endian { } {
4844 if { ![istarget aarch64*-*-*] } {
4845 return 0
4846 }
4847
4848 return [check_no_compiler_messages aarch64_little_endian assembly {
4849 #if !defined(__aarch64__) || defined(__AARCH64EB__)
4850 #error FOO
4851 #endif
4852 }]
4853 }
4854
4855 # Return 1 if this is an AArch64 target supporting SVE.
4856 proc check_effective_target_aarch64_sve { } {
4857 if { ![istarget aarch64*-*-*] } {
4858 return 0
4859 }
4860 return [check_no_compiler_messages aarch64_sve assembly {
4861 #if !defined (__ARM_FEATURE_SVE)
4862 #error FOO
4863 #endif
4864 }]
4865 }
4866
4867 # Return 1 if this is an AArch64 target supporting SVE2.
4868 proc check_effective_target_aarch64_sve2 { } {
4869 if { ![istarget aarch64*-*-*] } {
4870 return 0
4871 }
4872 return [check_no_compiler_messages aarch64_sve2 assembly {
4873 #if !defined (__ARM_FEATURE_SVE2)
4874 #error FOO
4875 #endif
4876 }]
4877 }
4878
4879 # Return 1 if this is an AArch64 target only supporting SVE (not SVE2).
4880 proc check_effective_target_aarch64_sve1_only { } {
4881 return [expr { [check_effective_target_aarch64_sve]
4882 && ![check_effective_target_aarch64_sve2] }]
4883 }
4884
4885 # Return the size in bits of an SVE vector, or 0 if the size is variable.
4886 proc aarch64_sve_bits { } {
4887 return [check_cached_effective_target aarch64_sve_bits {
4888 global tool
4889
4890 set src dummy[pid].c
4891 set f [open $src "w"]
4892 puts $f "int bits = __ARM_FEATURE_SVE_BITS;"
4893 close $f
4894 set output [${tool}_target_compile $src "" preprocess ""]
4895 file delete $src
4896
4897 regsub {.*bits = ([^;]*);.*} $output {\1} bits
4898 expr { $bits }
4899 }]
4900 }
4901
4902 # Return 1 if this is an AArch64 target that generates instructions for SME.
4903 proc check_effective_target_aarch64_sme { } {
4904 if { ![istarget aarch64*-*-*] } {
4905 return 0
4906 }
4907 return [check_no_compiler_messages aarch64_sme assembly {
4908 #if !defined (__ARM_FEATURE_SME)
4909 #error FOO
4910 #endif
4911 }]
4912 }
4913
4914 # Return 1 if this is an AArch64 target that generates instructions for SME.
4915 proc check_effective_target_aarch64_sme2 { } {
4916 if { ![istarget aarch64*-*-*] } {
4917 return 0
4918 }
4919 return [check_no_compiler_messages aarch64_sme2 assembly {
4920 #if !defined (__ARM_FEATURE_SME2)
4921 #error FOO
4922 #endif
4923 }]
4924 }
4925
4926 # Return 1 if this is a compiler supporting ARC atomic operations
4927 proc check_effective_target_arc_atomic { } {
4928 return [check_no_compiler_messages arc_atomic assembly {
4929 #if !defined(__ARC_ATOMIC__)
4930 #error FOO
4931 #endif
4932 }]
4933 }
4934
4935 # Return 1 if this is an arm target using 32-bit instructions
4936 proc check_effective_target_arm32 { } {
4937 if { ![istarget arm*-*-*] } {
4938 return 0
4939 }
4940
4941 return [check_no_compiler_messages arm32 assembly {
4942 #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
4943 #error !__arm || __thumb__ && !__thumb2__
4944 #endif
4945 }]
4946 }
4947
4948 # Return 1 if this is an arm target not using Thumb
4949 proc check_effective_target_arm_nothumb { } {
4950 if { ![istarget arm*-*-*] } {
4951 return 0
4952 }
4953
4954 return [check_no_compiler_messages arm_nothumb assembly {
4955 #if !defined(__arm__) || (defined(__thumb__) || defined(__thumb2__))
4956 #error !__arm__ || __thumb || __thumb2__
4957 #endif
4958 }]
4959 }
4960
4961 # Return 1 if this is a little-endian ARM target
4962 proc check_effective_target_arm_little_endian { } {
4963 if { ![istarget arm*-*-*] } {
4964 return 0
4965 }
4966
4967 return [check_no_compiler_messages arm_little_endian assembly {
4968 #if !defined(__arm__) || !defined(__ARMEL__)
4969 #error !__arm__ || !__ARMEL__
4970 #endif
4971 }]
4972 }
4973
4974 # Return 1 if this is an ARM target that only supports aligned vector accesses
4975 proc check_effective_target_arm_vect_no_misalign { } {
4976 if { ![istarget arm*-*-*] } {
4977 return 0
4978 }
4979
4980 return [check_no_compiler_messages arm_vect_no_misalign assembly {
4981 #if !defined(__arm__) \
4982 || (defined(__ARM_FEATURE_UNALIGNED) \
4983 && defined(__ARMEL__))
4984 #error !__arm__ || (__ARMEL__ && __ARM_FEATURE_UNALIGNED)
4985 #endif
4986 }]
4987 }
4988
4989
4990 # Return 1 if this is an ARM target supporting -mfloat-abi=soft. Some
4991 # multilibs may be incompatible with this option.
4992
4993 proc check_effective_target_arm_soft_ok { } {
4994 return [check_no_compiler_messages arm_soft_ok object {
4995 #include <stdint.h>
4996 int dummy;
4997 int main (void) { return 0; }
4998 } "-mfloat-abi=soft"]
4999 }
5000
5001 # Return 1 if this is an ARM target supporting -mfloat-abi=soft even
5002 # for linking. Some multilibs may be incompatible with this option,
5003 # and some linkers may reject incompatible options.
5004
5005 proc check_effective_target_arm_soft_ok_link { } {
5006 return [check_no_compiler_messages arm_soft_ok_link executable {
5007 #include <stdint.h>
5008 int dummy;
5009 int main (void) { return 0; }
5010 } "-mfloat-abi=soft"]
5011 }
5012
5013 # Return 1 if this is an ARM target supporting -mfpu=vfp with an
5014 # appropriate abi.
5015
5016 proc check_effective_target_arm_vfp_ok_nocache { } {
5017 global et_arm_vfp_flags
5018 set et_arm_vfp_flags ""
5019 if { [check_effective_target_arm32] } {
5020 foreach flags {"-mfpu=vfp" "-mfpu=vfp -mfloat-abi=softfp" "-mfpu=vfp -mfloat-abi=hard"} {
5021 if { [check_no_compiler_messages_nocache arm_vfp_ok object {
5022 #ifndef __ARM_FP
5023 #error __ARM_FP not defined
5024 #endif
5025 } "$flags"] } {
5026 set et_arm_vfp_flags $flags
5027 return 1
5028 }
5029 }
5030 }
5031
5032 return 0
5033 }
5034
5035 proc check_effective_target_arm_vfp_ok { } {
5036 return [check_cached_effective_target arm_vfp_ok \
5037 check_effective_target_arm_vfp_ok_nocache]
5038 }
5039
5040 # Add the options needed to compile code with -mfpu=vfp. We need either
5041 # -mfloat-abi=softfp or -mfloat-abi=hard, but if one is already
5042 # specified by the multilib, use it.
5043
5044 proc add_options_for_arm_vfp { flags } {
5045 if { ! [check_effective_target_arm_vfp_ok] } {
5046 return "$flags"
5047 }
5048 global et_arm_vfp_flags
5049 return "$flags $et_arm_vfp_flags"
5050 }
5051
5052 # Return 1 if this is an ARM target supporting -mfpu=vfp3
5053 # -mfloat-abi=softfp.
5054
5055 proc check_effective_target_arm_vfp3_ok { } {
5056 if { [check_effective_target_arm32] } {
5057 return [check_no_compiler_messages arm_vfp3_ok object {
5058 int dummy;
5059 } "-mfpu=vfp3 -mfloat-abi=softfp"]
5060 } else {
5061 return 0
5062 }
5063 }
5064
5065 # Return 1 if this is an ARM target supporting -mfpu=fp-armv8
5066 # -mfloat-abi=softfp.
5067 proc check_effective_target_arm_v8_vfp_ok_nocache {} {
5068 global et_arm_v8_vfp_flags
5069 set et_arm_v8_vfp_flags ""
5070 foreach flags {
5071 ""
5072 "-mfloat-abi=softfp"
5073 "-mcpu=unset -march=armv8-a+simd -mfpu=auto"
5074 "-mcpu=unset -march=armv8-a+simd -mfpu=auto -mfloat-abi=softfp"
5075 } {
5076 if { [check_no_compiler_messages_nocache arm_v8_vfp_ok object {
5077 #if __ARM_ARCH < 8
5078 #error not armv8 or later
5079 #endif
5080 #if __ARM_ARCH_PROFILE == 'M'
5081 #error incompatible profile
5082 #endif
5083 int foo (void)
5084 {
5085 __asm__ volatile ("vrinta.f32.f32 s0, s0");
5086 return 0;
5087 }
5088 } "$flags"] } {
5089 set et_arm_v8_vfp_flags "$flags"
5090 return 1
5091 }
5092 }
5093
5094 return 0
5095 }
5096
5097 proc check_effective_target_arm_v8_vfp_ok { } {
5098 return [check_cached_effective_target arm_v8_vfp_ok \
5099 check_effective_target_arm_v8_vfp_ok_nocache]
5100 }
5101
5102 # Return 1 if this is an ARM target supporting -mfpu=vfp
5103 # -mfloat-abi=hard. Some multilibs may be incompatible with these
5104 # options.
5105
5106 proc check_effective_target_arm_hard_vfp_ok { } {
5107 if { [check_effective_target_arm32]
5108 && ! [check-flags [list "" { *-*-* } { "-mfloat-abi=*" } { "-mfloat-abi=hard" }]] } {
5109 return [check_no_compiler_messages arm_hard_vfp_ok executable {
5110 int main() { return 0;}
5111 } "-mfpu=vfp -mfloat-abi=hard"]
5112 } else {
5113 return 0
5114 }
5115 }
5116
5117 # Return 1 if this is an ARM target defining __ARM_FP. We may need
5118 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
5119 # incompatible with these options. Also set et_arm_fp_flags to the
5120 # best options to add.
5121
5122 proc check_effective_target_arm_fp_ok_nocache { } {
5123 global et_arm_fp_flags
5124 set et_arm_fp_flags ""
5125 if { [check_effective_target_arm32] } {
5126 foreach flags {"" "-mfloat-abi=softfp" "-mfloat-abi=hard"} {
5127 if { [check_no_compiler_messages_nocache arm_fp_ok object {
5128 #ifndef __ARM_FP
5129 #error __ARM_FP not defined
5130 #endif
5131 } "$flags"] } {
5132 set et_arm_fp_flags $flags
5133 return 1
5134 }
5135 }
5136 }
5137
5138 return 0
5139 }
5140
5141 proc check_effective_target_arm_fp_ok { } {
5142 return [check_cached_effective_target arm_fp_ok \
5143 check_effective_target_arm_fp_ok_nocache]
5144 }
5145
5146 # Add the options needed to define __ARM_FP. We need either
5147 # -mfloat-abi=softfp or -mfloat-abi=hard, but if one is already
5148 # specified by the multilib, use it.
5149
5150 proc add_options_for_arm_fp { flags } {
5151 if { ! [check_effective_target_arm_fp_ok] } {
5152 return "$flags"
5153 }
5154 global et_arm_fp_flags
5155 return "$flags $et_arm_fp_flags"
5156 }
5157
5158 # Some libc headers will only compile correctly if the correct ABI flags
5159 # are picked for the target environment. Try to find an ABI setting
5160 # that works. Glibc falls into this category. This test is intended
5161 # to enable FP as far as possible, so does not try -mfloat-abi=soft.
5162 proc check_effective_target_arm_libc_fp_abi_ok_nocache { } {
5163 global et_arm_libc_fp_abi_flags
5164 set et_arm_libc_fp_abi_flags ""
5165 if { [istarget arm*-*-*] } {
5166 foreach flags {"-mfloat-abi=hard" "-mfloat-abi=softfp"} {
5167 if { [check_no_compiler_messages_nocache arm_libc_fp_abi_ok object {
5168 #include <stdint.h>
5169 } "$flags"] } {
5170 set et_arm_libc_fp_abi_flags $flags
5171 return 1
5172 }
5173 }
5174 }
5175 return 0
5176 }
5177
5178 proc check_effective_target_arm_libc_fp_abi_ok { } {
5179 return [check_cached_effective_target arm_libc_fp_abi_ok \
5180 check_effective_target_arm_libc_fp_abi_ok_nocache]
5181 }
5182
5183 # Add flags that pick the right ABI for the supported libc headers on
5184 # this platform.
5185 proc add_options_for_arm_libc_fp_abi { flags } {
5186 if { ! [check_effective_target_arm_libc_fp_abi_ok] } {
5187 return "$flags"
5188 }
5189 global et_arm_libc_fp_abi_flags
5190 return "$flags $et_arm_libc_fp_abi_flags"
5191 }
5192
5193 # Try to find the minimal set of flags needed to make the header file
5194 # arm_neon.h compatible with this compilation. This is complicated due
5195 # to the fact that this header doesn't work properly on m-profile cores
5196 # and also won't work correctly if the wrong floating-point ABI is used
5197 # on the platform (since arm_neon.h can include stdint.h, which on Linux
5198 # will pull in stub headers that aren't installed).
5199 # Note: This will not necessarily enable Neon instructions, just provide
5200 # something where the header will not cause errors.
5201
5202 proc check_effective_target_arm_neon_h_ok_nocache { } {
5203 # none-arm or thumb1 cannot support neon, so there's no point in
5204 # looking further.
5205 if { [istarget arm*-*-*]
5206 && [check_effective_target_arm_libc_fp_abi_ok]} {
5207 global et_arm_neon_h_flags
5208 set base_flags [add_options_for_arm_libc_fp_abi ""]
5209 foreach flags {"" "-mfpu=auto" "-marm" "-marm -mfpu=auto" \
5210 "-mcpu=unset -march=armv7-a+fp -mfpu=auto" } {
5211 if { [check_no_compiler_messages_nocache arm_neon_h_ok assembly {
5212 #if __ARM_ARCH < 5
5213 #error architecture too low for FP
5214 #endif
5215 #if __ARM_ARCH < 7
5216 #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
5217 #error incompatible arch or mode
5218 #endif
5219 #endif
5220 #if __ARM_ARCH_PROFILE == 'M'
5221 #error incompatible profile
5222 #endif
5223 } "$base_flags $flags" ] } {
5224 set et_arm_neon_h_flags "$base_flags $flags"
5225 return 1
5226 }
5227 }
5228 }
5229 return 0
5230 }
5231
5232 proc check_effective_target_arm_neon_h_ok { } {
5233 return [check_cached_effective_target arm_neon_h_ok \
5234 check_effective_target_arm_neon_h_ok_nocache]
5235 }
5236
5237 proc add_options_for_arm_neon_h { flags } {
5238 if { ! [check_effective_target_arm_neon_h_ok] } {
5239 return "$flags"
5240 }
5241 global et_arm_neon_h_flags
5242 return "$flags $et_arm_neon_h_flags"
5243 }
5244
5245 # Return 1 if this is an ARM target defining __ARM_FP with
5246 # double-precision support. We may need -mfloat-abi=softfp or
5247 # equivalent options. Some multilibs may be incompatible with these
5248 # options. Also set et_arm_fp_dp_flags to the best options to add.
5249
5250 proc check_effective_target_arm_fp_dp_ok_nocache { } {
5251 global et_arm_fp_dp_flags
5252 set et_arm_fp_dp_flags ""
5253 if { [check_effective_target_arm32] } {
5254 foreach flags {"" "-mfloat-abi=softfp" "-mfloat-abi=hard"} {
5255 if { [check_no_compiler_messages_nocache arm_fp_dp_ok object {
5256 #ifndef __ARM_FP
5257 #error __ARM_FP not defined
5258 #endif
5259 #if ((__ARM_FP & 8) == 0)
5260 #error __ARM_FP indicates that double-precision is not supported
5261 #endif
5262 } "$flags"] } {
5263 set et_arm_fp_dp_flags $flags
5264 return 1
5265 }
5266 }
5267 }
5268
5269 return 0
5270 }
5271
5272 proc check_effective_target_arm_fp_dp_ok { } {
5273 return [check_cached_effective_target arm_fp_dp_ok \
5274 check_effective_target_arm_fp_dp_ok_nocache]
5275 }
5276
5277 # Add the options needed to define __ARM_FP with double-precision
5278 # support. We need either -mfloat-abi=softfp or -mfloat-abi=hard, but
5279 # if one is already specified by the multilib, use it.
5280
5281 proc add_options_for_arm_fp_dp { flags } {
5282 if { ! [check_effective_target_arm_fp_dp_ok] } {
5283 return "$flags"
5284 }
5285 global et_arm_fp_dp_flags
5286 return "$flags $et_arm_fp_dp_flags"
5287 }
5288
5289 # Return 1 if this is an ARM target that supports DSP multiply with
5290 # current multilib flags.
5291
5292 proc check_effective_target_arm_dsp { } {
5293 return [check_no_compiler_messages arm_dsp assembly {
5294 #ifndef __ARM_FEATURE_DSP
5295 #error not DSP
5296 #endif
5297 #include <arm_acle.h>
5298 int i;
5299 }]
5300 }
5301
5302 # Return 1 if this is an ARM target that supports unaligned word/halfword
5303 # load/store instructions.
5304
5305 proc check_effective_target_arm_unaligned { } {
5306 return [check_no_compiler_messages arm_unaligned assembly {
5307 #ifndef __ARM_FEATURE_UNALIGNED
5308 #error no unaligned support
5309 #endif
5310 int i;
5311 }]
5312 }
5313
5314 # Return 1 if this is an ARM target supporting -mfpu=crypto-neon-fp-armv8
5315 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
5316 # incompatible with these options. Also set et_arm_crypto_flags to the
5317 # best options to add.
5318
5319 proc check_effective_target_arm_crypto_ok_nocache { } {
5320 global et_arm_crypto_flags
5321 set et_arm_crypto_flags ""
5322 if { [check_effective_target_arm_v8_neon_ok] } {
5323 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=crypto-neon-fp-armv8" "-mfpu=crypto-neon-fp-armv8 -mfloat-abi=softfp"} {
5324 if { [check_no_compiler_messages_nocache arm_crypto_ok object {
5325 #include "arm_neon.h"
5326 uint8x16_t
5327 foo (uint8x16_t a, uint8x16_t b)
5328 {
5329 return vaeseq_u8 (a, b);
5330 }
5331 } "$flags"] } {
5332 set et_arm_crypto_flags $flags
5333 return 1
5334 }
5335 }
5336 }
5337
5338 return 0
5339 }
5340
5341 # Return 1 if this is an ARM target supporting -mfpu=crypto-neon-fp-armv8
5342
5343 proc check_effective_target_arm_crypto_ok { } {
5344 return [check_cached_effective_target arm_crypto_ok \
5345 check_effective_target_arm_crypto_ok_nocache]
5346 }
5347
5348 # Add options for crypto extensions.
5349 proc add_options_for_arm_crypto { flags } {
5350 if { ! [check_effective_target_arm_crypto_ok] } {
5351 return "$flags"
5352 }
5353 global et_arm_crypto_flags
5354 return "$flags $et_arm_crypto_flags"
5355 }
5356
5357 # Add the options needed for NEON. We need either -mfloat-abi=softfp
5358 # or -mfloat-abi=hard, but if one is already specified by the
5359 # multilib, use it. Similarly, if a -mfpu option already enables
5360 # NEON, do not add -mfpu=neon.
5361
5362 proc add_options_for_arm_neon { flags } {
5363 if { ! [check_effective_target_arm_neon_ok] } {
5364 return "$flags"
5365 }
5366 global et_arm_neon_flags
5367 return "$flags $et_arm_neon_flags"
5368 }
5369
5370 proc add_options_for_arm_v8_vfp { flags } {
5371 if { ! [check_effective_target_arm_v8_vfp_ok] } {
5372 return "$flags"
5373 }
5374 global et_arm_v8_vfp_flags
5375 return "$flags $et_arm_v8_vfp_flags"
5376 }
5377
5378 proc add_options_for_arm_v8_neon { flags } {
5379 if { ! [check_effective_target_arm_v8_neon_ok] } {
5380 return "$flags"
5381 }
5382 global et_arm_v8_neon_flags
5383 return "$flags $et_arm_v8_neon_flags -mcpu=unset -march=armv8-a"
5384 }
5385
5386 # Add the options needed for ARMv8.1 Adv.SIMD. Also adds the ARMv8 NEON
5387 # options for AArch64 and for ARM.
5388
5389 proc add_options_for_arm_v8_1a_neon { flags } {
5390 if { ! [check_effective_target_arm_v8_1a_neon_ok] } {
5391 return "$flags"
5392 }
5393 global et_arm_v8_1a_neon_flags
5394 return "$flags $et_arm_v8_1a_neon_flags"
5395 }
5396
5397 # Add the options needed for ARMv8.2 with the scalar FP16 extension.
5398 # Also adds the ARMv8 FP options for ARM and for AArch64.
5399
5400 proc add_options_for_arm_v8_2a_fp16_scalar { flags } {
5401 if { ! [check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
5402 return "$flags"
5403 }
5404 global et_arm_v8_2a_fp16_scalar_flags
5405 return "$flags $et_arm_v8_2a_fp16_scalar_flags"
5406 }
5407
5408 # Add the options needed for ARMv8.2 with the FP16 extension. Also adds
5409 # the ARMv8 NEON options for ARM and for AArch64.
5410
5411 proc add_options_for_arm_v8_2a_fp16_neon { flags } {
5412 if { ! [check_effective_target_arm_v8_2a_fp16_neon_ok] } {
5413 return "$flags"
5414 }
5415 global et_arm_v8_2a_fp16_neon_flags
5416 return "$flags $et_arm_v8_2a_fp16_neon_flags"
5417 }
5418
5419 proc add_options_for_arm_crc { flags } {
5420 if { ! [check_effective_target_arm_crc_ok] } {
5421 return "$flags"
5422 }
5423 global et_arm_crc_flags
5424 return "$flags $et_arm_crc_flags"
5425 }
5426
5427 # Add the options needed for NEON. We need either -mfloat-abi=softfp
5428 # or -mfloat-abi=hard, but if one is already specified by the
5429 # multilib, use it. Similarly, if a -mfpu option already enables
5430 # NEON, do not add -mfpu=neon.
5431
5432 proc add_options_for_arm_neonv2 { flags } {
5433 if { ! [check_effective_target_arm_neonv2_ok] } {
5434 return "$flags"
5435 }
5436 global et_arm_neonv2_flags
5437 return "$flags $et_arm_neonv2_flags"
5438 }
5439
5440 # Add the options needed for vfp3.
5441 proc add_options_for_arm_vfp3 { flags } {
5442 if { ! [check_effective_target_arm_vfp3_ok] } {
5443 return "$flags"
5444 }
5445 return "$flags -mfpu=vfp3 -mfloat-abi=softfp"
5446 }
5447
5448 # Return 1 if this is an ARM target supporting -mfpu=neon
5449 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
5450 # incompatible with these options. Also set et_arm_neon_flags to the
5451 # best options to add.
5452
5453 proc check_effective_target_arm_neon_ok_nocache { } {
5454 if { ![istarget arm*-*-*] } {
5455 return 0
5456 }
5457 global et_arm_neon_flags
5458 set et_arm_neon_flags ""
5459 foreach flags {
5460 ""
5461 "-mcpu=unset -march=armv7-a+simd -mfpu=auto"
5462
5463 "-mfloat-abi=softfp"
5464 "-mfloat-abi=softfp -mcpu=unset -march=armv7-a+simd -mfpu=auto"
5465
5466 "-mfloat-abi=hard"
5467 "-mfloat-abi=hard -mcpu=unset -march=armv7-a+simd -mfpu=auto"
5468 } {
5469 if { [check_no_compiler_messages_nocache arm_neon_ok object {
5470 #include <arm_neon.h>
5471 int dummy;
5472 #ifndef __ARM_NEON__
5473 #error not NEON
5474 #endif
5475 /* Avoid the case where a test adds -mfpu=neon, but the toolchain is
5476 configured for -mcpu=arm926ej-s, for example. */
5477 #if __ARM_ARCH < 7 || __ARM_ARCH_PROFILE == 'M'
5478 #error Architecture does not support NEON.
5479 #endif
5480 } "$flags"] } {
5481 set et_arm_neon_flags $flags
5482 return 1
5483 }
5484 }
5485
5486 return 0
5487 }
5488
5489 proc check_effective_target_arm_neon_ok { } {
5490 return [check_cached_effective_target arm_neon_ok \
5491 check_effective_target_arm_neon_ok_nocache]
5492 }
5493
5494
5495 # Return 1 if this is an ARM target supporting the SIMD32 intrinsics
5496 # from arm_acle.h. Some multilibs may be incompatible with these options.
5497 # Also set et_arm_simd32_flags to the best options to add.
5498 # arm_acle.h includes stdint.h which can cause trouble with incompatible
5499 # -mfloat-abi= options.
5500
5501 proc check_effective_target_arm_simd32_ok_nocache { } {
5502 global et_arm_simd32_flags
5503 set et_arm_simd32_flags ""
5504 foreach flags {"" "-mcpu=unset -march=armv6" "-mcpu=unset -march=armv6 -mfloat-abi=softfp" "-mcpu=unset -march=armv6 -mfloat-abi=hard"} {
5505 if { [check_no_compiler_messages_nocache arm_simd32_ok object {
5506 #include <arm_acle.h>
5507 int dummy;
5508 #ifndef __ARM_FEATURE_SIMD32
5509 #error not SIMD32
5510 #endif
5511 } "$flags"] } {
5512 set et_arm_simd32_flags $flags
5513 return 1
5514 }
5515 }
5516
5517 return 0
5518 }
5519
5520 proc check_effective_target_arm_simd32_ok { } {
5521 return [check_cached_effective_target arm_simd32_ok \
5522 check_effective_target_arm_simd32_ok_nocache]
5523 }
5524
5525 proc add_options_for_arm_simd32 { flags } {
5526 if { ! [check_effective_target_arm_simd32_ok] } {
5527 return "$flags"
5528 }
5529 global et_arm_simd32_flags
5530 return "$flags $et_arm_simd32_flags"
5531 }
5532
5533 # Return 1 if this is an ARM target supporting the __ssat and __usat
5534 # saturation intrinsics from arm_acle.h. Some multilibs may be
5535 # incompatible with these options. Also set et_arm_sat_flags to the
5536 # best options to add. arm_acle.h includes stdint.h which can cause
5537 # trouble with incompatible -mfloat-abi= options.
5538
5539 proc check_effective_target_arm_sat_ok_nocache { } {
5540 global et_arm_sat_flags
5541 set et_arm_sat_flags ""
5542 foreach flags {"" "-mcpu=unset -march=armv6" "-mcpu=unset -march=armv6 -mfloat-abi=softfp" "-mcpu=unset -march=armv6 -mfloat-abi=hard -mfpu=vfp"} {
5543 if { [check_no_compiler_messages_nocache et_arm_sat_flags object {
5544 #include <arm_acle.h>
5545 int dummy;
5546 #ifndef __ARM_FEATURE_SAT
5547 #error not SAT
5548 #endif
5549 } "$flags"] } {
5550 set et_arm_sat_flags $flags
5551 return 1
5552 }
5553 }
5554
5555 return 0
5556 }
5557
5558 proc check_effective_target_arm_sat_ok { } {
5559 return [check_cached_effective_target et_arm_sat_flags \
5560 check_effective_target_arm_sat_ok_nocache]
5561 }
5562
5563 proc add_options_for_arm_sat { flags } {
5564 if { ! [check_effective_target_arm_sat_ok] } {
5565 return "$flags"
5566 }
5567 global et_arm_sat_flags
5568 return "$flags $et_arm_sat_flags"
5569 }
5570
5571 # Return 1 if this is an ARM target supporting the DSP intrinsics from
5572 # arm_acle.h. Some multilibs may be incompatible with these options.
5573 # Also set et_arm_dsp_flags to the best options to add.
5574 # arm_acle.h includes stdint.h which can cause trouble with incompatible
5575 # -mfloat-abi= options.
5576 # check_effective_target_arm_dsp also exists, which checks the current
5577 # multilib, without trying other options.
5578
5579 proc check_effective_target_arm_dsp_ok_nocache { } {
5580 global et_arm_dsp_flags
5581 set et_arm_dsp_flags ""
5582 foreach flags {"" "-mcpu=unset -march=armv5te" "-mcpu=unset -march=armv5te -mfloat-abi=softfp" "-mcpu=unset -march=armv5te -mfloat-abi=hard"} {
5583 if { [check_no_compiler_messages_nocache et_arm_dsp_ok object {
5584 #include <arm_acle.h>
5585 int dummy;
5586 #ifndef __ARM_FEATURE_DSP
5587 #error not DSP
5588 #endif
5589 } "$flags"] } {
5590 set et_arm_dsp_flags $flags
5591 return 1
5592 }
5593 }
5594
5595 return 0
5596 }
5597
5598 proc check_effective_target_arm_dsp_ok { } {
5599 return [check_cached_effective_target et_arm_dsp_flags \
5600 check_effective_target_arm_dsp_ok_nocache]
5601 }
5602
5603 proc add_options_for_arm_dsp { flags } {
5604 if { ! [check_effective_target_arm_dsp_ok] } {
5605 return "$flags"
5606 }
5607 global et_arm_dsp_flags
5608 return "$flags $et_arm_dsp_flags"
5609 }
5610
5611 # Return 1 if this is an ARM target supporting -mfpu=neon without any
5612 # -mfloat-abi= option. Useful in tests where add_options is not
5613 # supported (such as lto tests).
5614
5615 proc check_effective_target_arm_neon_ok_no_float_abi_nocache { } {
5616 if { [check_effective_target_arm32] } {
5617 foreach flags {"-mfpu=neon"} {
5618 if { [check_no_compiler_messages_nocache arm_neon_ok_no_float_abi object {
5619 #include <arm_neon.h>
5620 int dummy;
5621 #ifndef __ARM_NEON__
5622 #error not NEON
5623 #endif
5624 /* Avoid the case where a test adds -mfpu=neon, but the toolchain is
5625 configured for -mcpu=arm926ej-s, for example. */
5626 #if __ARM_ARCH < 7 || __ARM_ARCH_PROFILE == 'M'
5627 #error Architecture does not support NEON.
5628 #endif
5629 } "$flags"] } {
5630 return 1
5631 }
5632 }
5633 }
5634
5635 return 0
5636 }
5637
5638 proc check_effective_target_arm_neon_ok_no_float_abi { } {
5639 return [check_cached_effective_target arm_neon_ok_no_float_abi \
5640 check_effective_target_arm_neon_ok_no_float_abi_nocache]
5641 }
5642
5643 proc check_effective_target_arm_crc_ok_nocache { } {
5644 global et_arm_crc_flags
5645 set et_arm_crc_flags "-mcpu=unset -march=armv8-a+crc"
5646 return [check_no_compiler_messages_nocache arm_crc_ok object {
5647 #if !defined (__ARM_FEATURE_CRC32)
5648 #error FOO
5649 #endif
5650 #include <arm_acle.h>
5651 } "$et_arm_crc_flags"]
5652 }
5653
5654 proc check_effective_target_arm_crc_ok { } {
5655 return [check_cached_effective_target arm_crc_ok \
5656 check_effective_target_arm_crc_ok_nocache]
5657 }
5658
5659 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
5660 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
5661 # incompatible with these options. Also set et_arm_neon_fp16_flags to
5662 # the best options to add.
5663
5664 proc check_effective_target_arm_neon_fp16_ok_nocache { } {
5665 global et_arm_neon_fp16_flags
5666 global et_arm_neon_flags
5667 set et_arm_neon_fp16_flags ""
5668 foreach flags {
5669 ""
5670 "-mfp16-format=ieee"
5671 "-mcpu=unset -march=armv7-a+simd+vfpv3-fp16 -mfpu=auto"
5672 "-mcpu=unset -march=armv7-a+simd+vfpv3-fp16 -mfpu=auto -mfp16-format=ieee"
5673
5674 "-mfloat-abi=softfp"
5675 "-mfloat-abi=softfp -mfp16-format=ieee"
5676 "-mcpu=unset -march=armv7-a+simd+vfpv3-fp16 -mfpu=auto -mfloat-abi=softfp"
5677 "-mcpu=unset -march=armv7-a+simd+vfpv3-fp16 -mfpu=auto -mfloat-abi=softfp -mfp16-format=ieee"
5678
5679 "-mfloat-abi=hard"
5680 "-mfloat-abi=hard -mfp16-format=ieee"
5681 "-mcpu=unset -march=armv7-a+simd+vfpv3-fp16 -mfpu=auto -mfloat-abi=hard"
5682 "-mcpu=unset -march=armv7-a+simd+vfpv3-fp16 -mfpu=auto -mfloat-abi=hard -mfp16-format=ieee"
5683 } {
5684 if { [check_no_compiler_messages_nocache arm_neon_fp16_ok object {
5685 #include "arm_neon.h"
5686 float16x4_t
5687 foo (float32x4_t arg)
5688 {
5689 return vcvt_f16_f32 (arg);
5690 }
5691 } "$flags"] } {
5692 set et_arm_neon_fp16_flags $flags
5693 return 1
5694 }
5695 }
5696
5697 return 0
5698 }
5699
5700 proc check_effective_target_arm_neon_fp16_ok { } {
5701 return [check_cached_effective_target arm_neon_fp16_ok \
5702 check_effective_target_arm_neon_fp16_ok_nocache]
5703 }
5704
5705 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
5706 # and -mfloat-abi=softfp together. Some multilibs may be
5707 # incompatible with these options. Also set et_arm_neon_softfp_fp16_flags to
5708 # the best options to add.
5709
5710 proc check_effective_target_arm_neon_softfp_fp16_ok_nocache { } {
5711 global et_arm_neon_softfp_fp16_flags
5712 global et_arm_neon_flags
5713 set et_arm_neon_softfp_fp16_flags ""
5714 if { [check_effective_target_arm_neon_ok] } {
5715 foreach flags {"-mfpu=neon-fp16 -mfloat-abi=softfp"
5716 "-mfpu=neon-fp16 -mfloat-abi=softfp -mfp16-format=ieee"} {
5717 if { [check_no_compiler_messages_nocache arm_neon_softfp_fp16_ok object {
5718 #include "arm_neon.h"
5719 float16x4_t
5720 foo (float32x4_t arg)
5721 {
5722 return vcvt_f16_f32 (arg);
5723 }
5724 } "$et_arm_neon_flags $flags"] } {
5725 set et_arm_neon_softfp_fp16_flags [concat $et_arm_neon_flags $flags]
5726 return 1
5727 }
5728 }
5729 }
5730
5731 return 0
5732 }
5733
5734 proc check_effective_target_arm_neon_softfp_fp16_ok { } {
5735 return [check_cached_effective_target arm_neon_softfp_fp16_ok \
5736 check_effective_target_arm_neon_softfp_fp16_ok_nocache]
5737 }
5738
5739
5740
5741 proc check_effective_target_arm_neon_fp16_hw { } {
5742 if {! [check_effective_target_arm_neon_fp16_ok] } {
5743 return 0
5744 }
5745 global et_arm_neon_fp16_flags
5746 check_runtime arm_neon_fp16_hw {
5747 int
5748 main (int argc, char **argv)
5749 {
5750 asm ("vcvt.f32.f16 q1, d0");
5751 return 0;
5752 }
5753 } $et_arm_neon_fp16_flags
5754 }
5755
5756 proc add_options_for_arm_neon_fp16 { flags } {
5757 if { ! [check_effective_target_arm_neon_fp16_ok] } {
5758 return "$flags"
5759 }
5760 global et_arm_neon_fp16_flags
5761 return "$flags $et_arm_neon_fp16_flags"
5762 }
5763
5764 proc add_options_for_arm_neon_softfp_fp16 { flags } {
5765 if { ! [check_effective_target_arm_neon_softfp_fp16_ok] } {
5766 return "$flags"
5767 }
5768 global et_arm_neon_softfp_fp16_flags
5769 return "$flags $et_arm_neon_softfp_fp16_flags"
5770 }
5771
5772 proc add_options_for_aarch64_sve { flags } {
5773 if { ![istarget aarch64*-*-*] || [check_effective_target_aarch64_sve] } {
5774 return "$flags"
5775 }
5776 return "$flags -march=armv8.2-a+sve"
5777 }
5778
5779 proc add_options_for_aarch64_sme { flags } {
5780 if { ![istarget aarch64*-*-*] || [check_effective_target_aarch64_sme] } {
5781 return "$flags"
5782 }
5783 return "$flags -march=armv9-a+sme"
5784 }
5785
5786 # Return 1 if this is an ARM target supporting the FP16 alternative
5787 # format. Some multilibs may be incompatible with the options needed. Also
5788 # set et_arm_fp16_alternative_flags to the best options to add.
5789
5790 proc check_effective_target_arm_fp16_alternative_ok_nocache { } {
5791 if { [istarget *-*-vxworks7*] } {
5792 # Not supported by the target system.
5793 return 0
5794 }
5795 global et_arm_fp16_alternative_flags
5796 set et_arm_fp16_alternative_flags ""
5797 if { [check_effective_target_arm32] } {
5798 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
5799 "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
5800 if { [check_no_compiler_messages_nocache \
5801 arm_fp16_alternative_ok object {
5802 #if !defined (__ARM_FP16_FORMAT_ALTERNATIVE) || ! (__ARM_FP & 2)
5803 #error __ARM_FP16_FORMAT_ALTERNATIVE not defined
5804 #endif
5805 } "$flags -mfp16-format=alternative"] } {
5806 set et_arm_fp16_alternative_flags "$flags -mfp16-format=alternative"
5807 return 1
5808 }
5809 }
5810 }
5811
5812 return 0
5813 }
5814
5815 proc check_effective_target_arm_fp16_alternative_ok { } {
5816 return [check_cached_effective_target arm_fp16_alternative_ok \
5817 check_effective_target_arm_fp16_alternative_ok_nocache]
5818 }
5819
5820 # Return 1 if this is an ARM target supports specifying the FP16 none
5821 # format. Some multilibs may be incompatible with the options needed.
5822
5823 proc check_effective_target_arm_fp16_none_ok_nocache { } {
5824 if { [check_effective_target_arm32] } {
5825 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp16"
5826 "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
5827 if { [check_no_compiler_messages_nocache \
5828 arm_fp16_none_ok object {
5829 #if defined (__ARM_FP16_FORMAT_ALTERNATIVE)
5830 #error __ARM_FP16_FORMAT_ALTERNATIVE defined
5831 #endif
5832 #if defined (__ARM_FP16_FORMAT_IEEE)
5833 #error __ARM_FP16_FORMAT_IEEE defined
5834 #endif
5835 } "$flags -mfp16-format=none"] } {
5836 return 1
5837 }
5838 }
5839 }
5840
5841 return 0
5842 }
5843
5844 proc check_effective_target_arm_fp16_none_ok { } {
5845 return [check_cached_effective_target arm_fp16_none_ok \
5846 check_effective_target_arm_fp16_none_ok_nocache]
5847 }
5848
5849 # Return 1 if this is an ARM target supporting -mfpu=neon-fp-armv8
5850 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
5851 # incompatible with these options. Also set et_arm_v8_neon_flags to the
5852 # best options to add.
5853
5854 proc check_effective_target_arm_v8_neon_ok_nocache { } {
5855 global et_arm_v8_neon_flags
5856 set et_arm_v8_neon_flags ""
5857 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-fp-armv8" "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
5858 if { [check_no_compiler_messages_nocache arm_v8_neon_ok object {
5859 #if __ARM_ARCH < 8
5860 #error not armv8 or later
5861 #endif
5862 #include "arm_neon.h"
5863 void
5864 foo ()
5865 {
5866 __asm__ volatile ("vrintn.f32 q0, q0");
5867 }
5868 } "$flags -mcpu=unset -march=armv8-a"] } {
5869 set et_arm_v8_neon_flags $flags
5870 return 1
5871 }
5872 }
5873
5874 return 0
5875 }
5876
5877 proc check_effective_target_arm_v8_neon_ok { } {
5878 return [check_cached_effective_target arm_v8_neon_ok \
5879 check_effective_target_arm_v8_neon_ok_nocache]
5880 }
5881
5882 # Return 1 if this is an ARM target supporting -mfpu=neon-vfpv4
5883 # -mfloat-abi=softfp or equivalent options. Some multilibs may be
5884 # incompatible with these options. Also set et_arm_neonv2_flags to the
5885 # best options to add.
5886
5887 proc check_effective_target_arm_neonv2_ok_nocache { } {
5888 global et_arm_neonv2_flags
5889 global et_arm_neon_flags
5890 set et_arm_neonv2_flags ""
5891 if { [check_effective_target_arm_neon_ok] } {
5892 foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon-vfpv4" "-mfpu=neon-vfpv4 -mfloat-abi=softfp"} {
5893 if { [check_no_compiler_messages_nocache arm_neonv2_ok object {
5894 #include "arm_neon.h"
5895 float32x2_t
5896 foo (float32x2_t a, float32x2_t b, float32x2_t c)
5897 {
5898 return vfma_f32 (a, b, c);
5899 }
5900 } "$et_arm_neon_flags $flags"] } {
5901 set et_arm_neonv2_flags [concat $et_arm_neon_flags $flags]
5902 return 1
5903 }
5904 }
5905 }
5906
5907 return 0
5908 }
5909
5910 proc check_effective_target_arm_neonv2_ok { } {
5911 return [check_cached_effective_target arm_neonv2_ok \
5912 check_effective_target_arm_neonv2_ok_nocache]
5913 }
5914
5915 # Add the options needed for VFP FP16 support. We need either
5916 # -mfloat-abi=softfp or -mfloat-abi=hard. If one is already specified by
5917 # the multilib, use it.
5918
5919 proc add_options_for_arm_fp16 { flags } {
5920 if { ! [check_effective_target_arm_fp16_ok] } {
5921 return "$flags"
5922 }
5923 global et_arm_fp16_flags
5924 return "$flags $et_arm_fp16_flags"
5925 }
5926
5927 # Add the options needed to enable support for IEEE format
5928 # half-precision support. This is valid for ARM targets.
5929
5930 proc add_options_for_arm_fp16_ieee { flags } {
5931 if { ! [check_effective_target_arm_fp16_ok] } {
5932 return "$flags"
5933 }
5934 global et_arm_fp16_flags
5935 return "$flags $et_arm_fp16_flags -mfp16-format=ieee"
5936 }
5937
5938 # Add the options needed to enable support for ARM Alternative format
5939 # half-precision support. This is valid for ARM targets.
5940
5941 proc add_options_for_arm_fp16_alternative { flags } {
5942 if { ! [check_effective_target_arm_fp16_alternative_ok] } {
5943 return "$flags"
5944 }
5945 global et_arm_fp16_alternative_flags
5946 return "$flags $et_arm_fp16_alternative_flags"
5947 }
5948
5949 # Return 1 if this is an ARM target that can support a VFP fp16 variant.
5950 # Skip multilibs that are incompatible with these options and set
5951 # et_arm_fp16_flags to the best options to add. This test is valid for
5952 # ARM only.
5953
5954 proc check_effective_target_arm_fp16_ok_nocache { } {
5955 global et_arm_fp16_flags
5956 set et_arm_fp16_flags ""
5957 if { ! [check_effective_target_arm32] } {
5958 return 0;
5959 }
5960 if [check-flags \
5961 [list "" { *-*-* } { "-mfpu=*" } \
5962 { "-mfpu=*fp16*" "-mfpu=*fpv[4-9]*" \
5963 "-mfpu=*fpv[1-9][0-9]*" "-mfpu=*fp-armv8*" } ]] {
5964 # Multilib flags would override -mfpu.
5965 return 0
5966 }
5967 if [check-flags [list "" { *-*-* } { "-mfloat-abi=soft" } { "" } ]] {
5968 # Must generate floating-point instructions.
5969 return 0
5970 }
5971 if [check_effective_target_arm_hf_eabi] {
5972 # Use existing float-abi and force an fpu which supports fp16
5973 set et_arm_fp16_flags "-mfpu=vfpv4"
5974 return 1;
5975 }
5976 if [check-flags [list "" { *-*-* } { "-mfpu=*" } { "" } ]] {
5977 # The existing -mfpu value is OK; use it, but add softfp.
5978 set et_arm_fp16_flags "-mfloat-abi=softfp"
5979 return 1;
5980 }
5981 # Add -mfpu for a VFP fp16 variant since there is no preprocessor
5982 # macro to check for this support.
5983 set flags "-mfpu=vfpv4 -mfloat-abi=softfp"
5984 if { [check_no_compiler_messages_nocache arm_fp16_ok assembly {
5985 int dummy;
5986 } "$flags"] } {
5987 set et_arm_fp16_flags "$flags"
5988 return 1
5989 }
5990
5991 return 0
5992 }
5993
5994 proc check_effective_target_arm_fp16_ok { } {
5995 return [check_cached_effective_target arm_fp16_ok \
5996 check_effective_target_arm_fp16_ok_nocache]
5997 }
5998
5999 # Return 1 if the target supports executing VFP FP16 instructions, 0
6000 # otherwise. This test is valid for ARM only.
6001
6002 proc check_effective_target_arm_fp16_hw { } {
6003 if {! [check_effective_target_arm_fp16_ok] } {
6004 return 0
6005 }
6006 global et_arm_fp16_flags
6007 check_runtime arm_fp16_hw {
6008 int
6009 main (int argc, char **argv)
6010 {
6011 __fp16 a = 1.0;
6012 float r;
6013 asm ("vcvtb.f32.f16 %0, %1"
6014 : "=w" (r) : "w" (a)
6015 : /* No clobbers. */);
6016 return (r == 1.0) ? 0 : 1;
6017 }
6018 } "$et_arm_fp16_flags -mfp16-format=ieee"
6019 }
6020
6021 # Creates a series of routines that return 1 if the given architecture
6022 # can be selected and a routine to give the flags to select that architecture
6023 # Note: Extra flags may be added to disable options from newer compilers
6024 # (Thumb in particular - but others may be added in the future).
6025 # Warning: Do not use check_effective_target_arm_arch_*_ok for architecture
6026 # extension (eg. ARMv8.1-A) since there is no macro defined for them. See
6027 # how only __ARM_ARCH_8A__ is checked for ARMv8.1-A.
6028 # Usage: /* { dg-require-effective-target arm_arch_v5_ok } */
6029 # /* { dg-add-options arm_arch_v5t } */
6030 # /* { dg-require-effective-target arm_arch_v5t_multilib } */
6031
6032 # This table should only be used to set -march= (and associated
6033 # flags). See below for setting -mcpu
6034 foreach { armfunc armflag armdefs } {
6035 v4 "-march=armv4 -marm" __ARM_ARCH_4__
6036 v4t "-march=armv4t -mfloat-abi=softfp" __ARM_ARCH_4T__
6037 v4t_arm "-march=armv4t -marm" "__ARM_ARCH_4T__ && !__thumb__"
6038 v4t_thumb "-march=armv4t -mthumb -mfloat-abi=softfp" "__ARM_ARCH_4T__ && __thumb__"
6039 v5t "-march=armv5t -mfloat-abi=softfp" __ARM_ARCH_5T__
6040 v5t_arm "-march=armv5t -marm" "__ARM_ARCH_5T__ && !__thumb__"
6041 v5t_thumb "-march=armv5t -mthumb -mfloat-abi=softfp" "__ARM_ARCH_5T__ && __thumb__"
6042 v5te "-march=armv5te+fp -mfloat-abi=softfp" __ARM_ARCH_5TE__
6043 v5te_arm "-march=armv5te+fp -marm" "__ARM_ARCH_5TE__ && !__thumb__"
6044 v5te_thumb "-march=armv5te+fp -mthumb -mfloat-abi=softfp" "__ARM_ARCH_5TE__ && __thumb__"
6045 v6 "-march=armv6+fp -mfloat-abi=softfp" __ARM_ARCH_6__
6046 v6_arm "-march=armv6+fp -marm" "__ARM_ARCH_6__ && !__thumb__"
6047 v6_thumb "-march=armv6+fp -mthumb -mfloat-abi=softfp" "__ARM_ARCH_6__ && __thumb__"
6048 v6k "-march=armv6k+fp -mfloat-abi=softfp" __ARM_ARCH_6K__
6049 v6k_arm "-march=armv6k+fp -marm" "__ARM_ARCH_6K__ && !__thumb__"
6050 v6k_thumb "-march=armv6k+fp -mthumb -mfloat-abi=softfp" "__ARM_ARCH_6K__ && __thumb__"
6051 v6t2 "-march=armv6t2+fp" __ARM_ARCH_6T2__
6052 v6z "-march=armv6z+fp -mfloat-abi=softfp" __ARM_ARCH_6Z__
6053 v6z_arm "-march=armv6z+fp -marm" "__ARM_ARCH_6Z__ && !__thumb__"
6054 v6z_thumb "-march=armv6z+fp -mthumb -mfloat-abi=softfp" "__ARM_ARCH_6Z__ && __thumb__"
6055 v6m "-march=armv6-m -mthumb -mfloat-abi=soft" __ARM_ARCH_6M__
6056 v7a "-march=armv7-a+fp" __ARM_ARCH_7A__
6057 v7a_arm "-march=armv7-a+fp -marm" "__ARM_ARCH_7A__ && !__thumb__"
6058 v7a_fp_hard "-march=armv7-a+fp -mfpu=auto -mfloat-abi=hard" __ARM_ARCH_7A__
6059 v7a_neon "-march=armv7-a+simd -mfpu=auto -mfloat-abi=softfp" "__ARM_ARCH_7A__ && __ARM_NEON__"
6060 v7a_neon_thumb "-march=armv7-a+simd -mfpu=auto -mfloat-abi=softfp -mthumb" "__ARM_ARCH_7A__ && __ARM_NEON__ && __thumb__"
6061 v7r "-march=armv7-r+fp" __ARM_ARCH_7R__
6062 v7m "-march=armv7-m -mthumb -mfloat-abi=soft" __ARM_ARCH_7M__
6063 v7em "-march=armv7e-m+fp -mthumb" __ARM_ARCH_7EM__
6064 v7em_hard "-march=armv7e-m+fp -mfpu=auto -mfloat-abi=hard -mthumb" __ARM_ARCH_7EM__
6065 v7ve "-march=armv7ve+fp -marm"
6066 "__ARM_ARCH_7A__ && __ARM_FEATURE_IDIV"
6067 v7ve_neon "-march=armv7ve+simd -mfpu=auto -mfloat-abi=softfp"
6068 "__ARM_ARCH_7A__ && __ARM_FEATURE_IDIV && __ARM_NEON__"
6069 v8a "-march=armv8-a+simd" __ARM_ARCH_8A__
6070 v8a_hard "-march=armv8-a+simd -mfpu=auto -mfloat-abi=hard" __ARM_ARCH_8A__
6071 v8a_crc_hard "-march=armv8-a+crc+simd -mfpu=auto -mfloat-abi=hard" "__ARM_ARCH_8A__ && __ARM_FEATURE_CRC32"
6072 v8_1a "-march=armv8.1-a+simd" __ARM_ARCH_8A__
6073 v8_2a "-march=armv8.2-a+simd" __ARM_ARCH_8A__
6074 v8_2a_bf16 "-march=armv8.2-a+bf16 -mfpu=auto -mfloat-abi=softfp" __ARM_ARCH_8A__
6075 v8_2a_bf16_hard "-march=armv8.2-a+bf16 -mfpu=auto -mfloat-abi=hard" __ARM_ARCH_8A__
6076 v8r "-march=armv8-r+fp.sp" __ARM_ARCH_8R__
6077 v8m_base "-march=armv8-m.base -mthumb -mfloat-abi=soft"
6078 __ARM_ARCH_8M_BASE__
6079 v8m_main "-march=armv8-m.main+fp -mthumb" __ARM_ARCH_8M_MAIN__
6080 v8_1m_main "-march=armv8.1-m.main+fp -mthumb" __ARM_ARCH_8M_MAIN__
6081 v8_1m_main_pacbti "-march=armv8.1-m.main+pacbti+fp -mthumb"
6082 "__ARM_ARCH_8M_MAIN__ && __ARM_FEATURE_BTI && __ARM_FEATURE_PAUTH"
6083 v8_1m_main_fp_hard "-march=armv8.1-m.main+pacbti+fp -mthumb -mfpu=auto -mfloat-abi=hard" "__ARM_ARCH_8M_MAIN__ && (__ARM_FP & 2)"
6084 v9a "-march=armv9-a+simd" __ARM_ARCH_9A__ } {
6085 eval [string map [list FUNC $armfunc FLAG $armflag DEFS $armdefs ] {
6086 proc check_effective_target_arm_arch_FUNC_ok { } {
6087 return [check_no_compiler_messages arm_arch_FUNC_ok assembly {
6088 #if !(DEFS)
6089 #error !(DEFS)
6090 #endif
6091 int
6092 main (void)
6093 {
6094 return 0;
6095 }
6096 } "-mcpu=unset FLAG" ]
6097 }
6098
6099 proc add_options_for_arm_arch_FUNC { flags } {
6100 return "$flags -mcpu=unset FLAG"
6101 }
6102
6103 proc check_effective_target_arm_arch_FUNC_link { } {
6104 return [check_no_compiler_messages arm_arch_FUNC_link executable {
6105 #include <stdint.h>
6106 int dummy;
6107 int main (void) { return 0; }
6108 } [add_options_for_arm_arch_FUNC ""]]
6109 }
6110
6111 proc check_effective_target_arm_arch_FUNC_multilib { } {
6112 return [check_runtime arm_arch_FUNC_multilib {
6113 int
6114 main (void)
6115 {
6116 return 0;
6117 }
6118 } [add_options_for_arm_arch_FUNC ""]]
6119 }
6120 }]
6121 }
6122
6123 # Creates a series of routines that return 1 if the given CPU
6124 # can be selected and a routine to give the flags to select that CPU
6125 # Note: Extra flags may be added to disable options from newer compilers
6126 # (Thumb in particular - but others may be added in the future).
6127 # Usage: /* { dg-require-effective-target arm_cpu_xscale_ok } */
6128 # /* { dg-add-options arm_cpu_xscale } */
6129 # /* { dg-require-effective-target arm_xscale_multilib } */
6130
6131 # NOTE: -mcpu does not override -mtune, so to ensure the tuning is consistent
6132 # for tests using these flags all entries should set -mcpu and -mtune explicitly
6133
6134 # This table should only be used to set -mcpu= (and associated
6135 # flags). See above for setting -march=.
6136 foreach { armfunc armflag armdefs } {
6137 xscale_arm "-mcpu=xscale -mtune=xscale -mfloat-abi=soft -marm" "__XSCALE__ && !__thumb__"
6138 cortex_a53 "-mcpu=cortex-a53 -mtune=cortex-a53" __ARM_ARCH_8A__
6139 cortex_a57 "-mcpu=cortex-a57 -mtune=cortex-a57" __ARM_ARCH_8A__
6140 cortex_m0 "-mcpu=cortex-m0 -mtune=cortex-m0 -mfloat-abi=soft -mthumb" "__ARM_ARCH_6M__ && __thumb__"
6141 cortex_m0_small "-mcpu=cortex-m0.small-multiply -mtune=cortex-m0.small-multiply -mfloat-abi=soft -mthumb" "__ARM_ARCH_6M__ && __thumb__"
6142 cortex_m0plus_small "-mcpu=cortex-m0plus.small-multiply -mtune=cortex-m0plus.small-multiply -mfloat-abi=soft -mthumb" "__ARM_ARCH_6M__ && __thumb__"
6143 cortex_m1_small "-mcpu=cortex-m1.small-multiply -mtune=cortex-m1.small-multiply -mfloat-abi=soft -mthumb" "__ARM_ARCH_6M__ && __thumb__"
6144 cortex_m3 "-mcpu=cortex-m3 -mtune=cortex-m3 -mfloat-abi=soft -mthumb" "__ARM_ARCH_7M__"
6145 cortex_m4 "-mcpu=cortex-m4 -mtune=cortex-m4 -mfpu=auto -mthumb" "__ARM_ARCH_7EM__"
6146 cortex_m4_hard "-mcpu=cortex-m4 -mtune=cortex-m4 -mfpu=auto -mfloat-abi=hard -mthumb" "__ARM_ARCH_7EM__"
6147 cortex_m7 "-mcpu=cortex-m7 -mtune=cortex-m7 -mfpu=auto -mthumb" "__ARM_ARCH_7EM__"
6148 cortex_m23 "-mcpu=cortex-m23 -mtune=cortex-m23 -mfloat-abi=soft -mthumb" "__ARM_ARCH_8M_BASE__ && __thumb__"
6149 cortex_m55 "-mcpu=cortex-m55 -mtune=cortex-m55 -mfpu=auto -mthumb" "__ARM_ARCH_8M_MAIN__ && __thumb__"
6150 } {
6151 eval [string map [list FUNC $armfunc FLAG $armflag DEFS $armdefs ] {
6152 proc check_effective_target_arm_cpu_FUNC_ok { } {
6153 return [check_no_compiler_messages arm_cpu_FUNC_ok assembly {
6154 #if !(DEFS)
6155 #error !(DEFS)
6156 #endif
6157 int
6158 main (void)
6159 {
6160 return 0;
6161 }
6162 } "-march=unset FLAG" ]
6163 }
6164
6165 proc add_options_for_arm_cpu_FUNC { flags } {
6166 return "$flags -march=unset FLAG"
6167 }
6168
6169 proc check_effective_target_arm_cpu_FUNC_link { } {
6170 return [check_no_compiler_messages arm_cpu_FUNC_link executable {
6171 #include <stdint.h>
6172 int dummy;
6173 int main (void) { return 0; }
6174 } [add_options_for_arm_cpu_FUNC ""]]
6175 }
6176
6177 proc check_effective_target_arm_cpu_FUNC_multilib { } {
6178 return [check_runtime arm_cpu_FUNC_multilib {
6179 int
6180 main (void)
6181 {
6182 return 0;
6183 }
6184 } [add_options_for_arm_cpu_FUNC ""]]
6185 }
6186 }]
6187 }
6188
6189 # Return 1 if current target supports both single- and double-precision FP
6190 proc check_effective_target_arm_mixed_fp { } {
6191 if { ![istarget arm*-*-*] } {
6192 return 0
6193 }
6194
6195 return [check_no_compiler_messages arm_mixed_fp assembly {
6196 // Mixed FP means we have hw FP, but only for SFmode (ignores HFmode)
6197 #if !defined(__ARM_FP) || ((__ARM_FP & 0xc) != 0x4)
6198 #error Not mixed FP
6199 #endif
6200 int main (void) { return 0; }
6201 } "" ]
6202 }
6203
6204 # Return 1 if GCC was configured with --with-mode=
6205 proc check_effective_target_default_mode { } {
6206
6207 return [check_configured_with "with-mode="]
6208 }
6209
6210 # Return 1 if this is an ARM target where -marm causes ARM to be
6211 # used (not Thumb)
6212
6213 proc check_effective_target_arm_arm_ok { } {
6214 return [check_no_compiler_messages arm_arm_ok assembly {
6215 #if !defined (__arm__) || defined (__thumb__) || defined (__thumb2__)
6216 #error !__arm__ || __thumb__ || __thumb2__
6217 #endif
6218 } "-marm"]
6219 }
6220
6221
6222 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
6223 # used.
6224
6225 proc check_effective_target_arm_thumb1_ok { } {
6226 return [check_no_compiler_messages arm_thumb1_ok assembly {
6227 #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
6228 #error !__arm__ || !__thumb__ || __thumb2__
6229 #endif
6230 int foo (int i) { return i; }
6231 } "-mthumb"]
6232 }
6233
6234 # Return 1 is this is an ARM target where -mthumb causes Thumb-2 to be
6235 # used.
6236
6237 proc check_effective_target_arm_thumb2_ok { } {
6238 return [check_no_compiler_messages arm_thumb2_ok assembly {
6239 #if !defined(__thumb2__)
6240 #error !__thumb2__
6241 #endif
6242 int foo (int i) { return i; }
6243 } "-mthumb"]
6244 }
6245
6246 # Return 1 if this is an ARM target where Thumb-1 is used without options
6247 # added by the test.
6248
6249 proc check_effective_target_arm_thumb1 { } {
6250 return [check_no_compiler_messages arm_thumb1 assembly {
6251 #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
6252 #error !__arm__ || !__thumb__ || __thumb2__
6253 #endif
6254 int i;
6255 } ""]
6256 }
6257
6258 # Return 1 if this is an ARM target where Thumb-2 is used without options
6259 # added by the test.
6260
6261 proc check_effective_target_arm_thumb2 { } {
6262 return [check_no_compiler_messages arm_thumb2 assembly {
6263 #if !defined(__thumb2__)
6264 #error !__thumb2__
6265 #endif
6266 int i;
6267 } ""]
6268 }
6269
6270 # Return 1 if this is an ARM target where conditional execution is available.
6271
6272 proc check_effective_target_arm_cond_exec { } {
6273 return [check_no_compiler_messages arm_cond_exec assembly {
6274 #if defined(__arm__) && defined(__thumb__) && !defined(__thumb2__)
6275 #error FOO
6276 #endif
6277 int i;
6278 } ""]
6279 }
6280
6281 # Return 1 if this is an ARM cortex-M profile cpu
6282
6283 proc check_effective_target_arm_cortex_m { } {
6284 if { ![istarget arm*-*-*] } {
6285 return 0
6286 }
6287 return [check_no_compiler_messages arm_cortex_m assembly {
6288 #if defined(__ARM_ARCH_ISA_ARM)
6289 #error __ARM_ARCH_ISA_ARM is defined
6290 #endif
6291 int i;
6292 } "-mthumb"]
6293 }
6294
6295 # Return 1 if this is an ARM target where -mthumb causes Thumb-1 to be
6296 # used and MOVT/MOVW instructions to be available.
6297
6298 proc check_effective_target_arm_thumb1_movt_ok {} {
6299 if [check_effective_target_arm_thumb1_ok] {
6300 return [check_no_compiler_messages arm_movt object {
6301 int
6302 foo (void)
6303 {
6304 asm ("movt r0, #42");
6305 }
6306 } "-mthumb"]
6307 } else {
6308 return 0
6309 }
6310 }
6311
6312 # Return 1 if this is an ARM target where -mthumb causes Thumb-1 to be
6313 # used and CBZ and CBNZ instructions are available.
6314
6315 proc check_effective_target_arm_thumb1_cbz_ok {} {
6316 if [check_effective_target_arm_thumb1_ok] {
6317 return [check_no_compiler_messages arm_cbz object {
6318 int
6319 foo (void)
6320 {
6321 asm ("cbz r0, 2f\n2:");
6322 }
6323 } "-mthumb"]
6324 } else {
6325 return 0
6326 }
6327 }
6328
6329 # Return 1 if this is an Arm target which supports the Armv6t2 extensions.
6330 # This can be either in Arm state or in Thumb state.
6331
6332 proc check_effective_target_arm_arch_v6t2_hw {} {
6333 if [check_effective_target_arm_arch_v6t2_ok] {
6334 return [check_runtime arm_arch_v6t2 {
6335 int
6336 main (void)
6337 {
6338 asm ("bfc r0, #1, #2");
6339 return 0;
6340 }
6341 } [add_options_for_arm_arch_v6t2 ""]]
6342 } else {
6343 return 0
6344 }
6345 }
6346
6347 # Return 1 if this is an ARM target where ARMv8-M Security Extensions is
6348 # available.
6349
6350 proc check_effective_target_arm_cmse_ok {} {
6351 return [check_no_compiler_messages arm_cmse object {
6352 int
6353 foo (void)
6354 {
6355 asm ("bxns r0");
6356 }
6357 } "-mcmse"];
6358 }
6359
6360 # Return 1 if the target supports executing CMSE instructions, 0
6361 # otherwise. Cache the result.
6362
6363 proc check_effective_target_arm_cmse_hw { } {
6364 return [check_runtime arm_cmse_hw_available {
6365 int main (void)
6366 {
6367 unsigned id_pfr1;
6368 asm ("ldr\t%0, =0xe000ed44\n" \
6369 "ldr\t%0, [%0]\n" \
6370 "sg" : "=l" (id_pfr1));
6371 /* Exit with code 0 iff security extension is available. */
6372 return !(id_pfr1 & 0xf0);
6373 }
6374 } "-mcmse"]
6375 }
6376
6377 # Return 1 if the target supports executing MVE instructions, 0
6378 # otherwise.
6379
6380 proc check_effective_target_arm_mve_hw {} {
6381 return [check_runtime arm_mve_hw_available {
6382 int
6383 main (void)
6384 {
6385 long long a = 16;
6386 int b = 3;
6387 asm ("sqrshrl %Q1, %R1, #64, %2"
6388 : "=l" (a)
6389 : "0" (a), "r" (b));
6390 return (a != 2);
6391 }
6392 } [add_options_for_arm_v8_1m_mve_fp ""]]
6393 }
6394
6395 # Return 1 if this is an ARM target where ARMv8-M Security Extensions with
6396 # clearing instructions (clrm, vscclrm, vstr/vldr with FPCXT) is available.
6397
6398 proc check_effective_target_arm_cmse_clear_ok {} {
6399 return [check_no_compiler_messages arm_cmse_clear object {
6400 int
6401 foo (void)
6402 {
6403 asm ("clrm {r1, r2}");
6404 }
6405 } "-mcmse"];
6406 }
6407
6408 # Return 1 if this is an ARM target supporting
6409 # -mbranch-protection=standard, 0 otherwise.
6410
6411 proc check_effective_target_mbranch_protection_ok {} {
6412
6413 return [check_no_compiler_messages mbranch_protection_ok object {
6414 int main (void) { return 0; }
6415 } "-mbranch-protection=standard"]
6416 }
6417
6418 # Return 1 if the target supports executing PACBTI instructions, 0
6419 # otherwise.
6420
6421 proc check_effective_target_arm_pacbti_hw {} {
6422 return [check_runtime arm_pacbti_hw_available {
6423 __attribute__ ((naked)) int
6424 main (void)
6425 {
6426 asm ("pac r12, lr, sp");
6427 asm ("mov r0, #0");
6428 asm ("autg r12, lr, sp");
6429 asm ("bx lr");
6430 }
6431 } "-mcpu=unset -march=armv8.1-m.main+pacbti+fp -mbranch-protection=standard -mthumb -mfloat-abi=hard"]
6432 }
6433
6434 # Return 1 if this compilation turns on string_ops_prefer_neon on.
6435
6436 proc check_effective_target_arm_tune_string_ops_prefer_neon { } {
6437 return [check_no_messages_and_pattern arm_tune_string_ops_prefer_neon "@string_ops_prefer_neon:\t1" assembly {
6438 int foo (void) { return 0; }
6439 } "-O2 -mprint-tune-info" ]
6440 }
6441
6442 # Return 1 if the target supports executing NEON instructions, 0
6443 # otherwise. Cache the result.
6444
6445 proc check_effective_target_arm_neon_hw { } {
6446 return [check_runtime arm_neon_hw_available {
6447 int
6448 main (void)
6449 {
6450 long long a = 0, b = 1;
6451 asm ("vorr %P0, %P1, %P2"
6452 : "=w" (a)
6453 : "0" (a), "w" (b));
6454 return (a != 1);
6455 }
6456 } [add_options_for_arm_neon ""]]
6457 }
6458
6459 # Return true if this is an AArch64 target that can run SVE code.
6460
6461 proc check_effective_target_aarch64_sve_hw { } {
6462 if { ![istarget aarch64*-*-*] } {
6463 return 0
6464 }
6465 return [check_runtime aarch64_sve_hw_available {
6466 int
6467 main (void)
6468 {
6469 asm volatile ("ptrue p0.b");
6470 return 0;
6471 }
6472 } [add_options_for_aarch64_sve ""]]
6473 }
6474
6475 # Return true if this is an AArch64 target that can run SVE2 code.
6476
6477 proc check_effective_target_aarch64_sve2_hw { } {
6478 if { ![istarget aarch64*-*-*] } {
6479 return 0
6480 }
6481 return [check_runtime aarch64_sve2_hw_available {
6482 int
6483 main (void)
6484 {
6485 asm volatile ("addp z0.b, p0/m, z0.b, z1.b");
6486 return 0;
6487 }
6488 }]
6489 }
6490
6491 # Return true if this is an AArch64 target that can run SVE2.1 code.
6492
6493 proc check_effective_target_aarch64_sve2p1_hw { } {
6494 if { ![istarget aarch64*-*-*] } {
6495 return 0
6496 }
6497 return [check_runtime aarch64_sve2p1_hw_available {
6498 #pragma GCC target "+sve2p1"
6499 int
6500 main (void)
6501 {
6502 asm volatile ("dupq z0.b, z0.b[0]");
6503 return 0;
6504 }
6505 }]
6506 }
6507
6508 # Return true if this is an AArch64 target that can run SVE code and
6509 # if its SVE vectors have exactly BITS bits.
6510
6511 proc aarch64_sve_hw_bits { bits } {
6512 if { ![check_effective_target_aarch64_sve_hw] } {
6513 return 0
6514 }
6515 return [check_runtime aarch64_sve${bits}_hw [subst {
6516 int
6517 main (void)
6518 {
6519 int res;
6520 asm volatile ("cntd %0" : "=r" (res));
6521 if (res * 64 != $bits)
6522 __builtin_abort ();
6523 return 0;
6524 }
6525 }] [add_options_for_aarch64_sve ""]]
6526 }
6527
6528 # Return true if this is an AArch64 target that can run SVE code and
6529 # if its SVE vectors have exactly 256 bits.
6530
6531 foreach N { 128 256 512 1024 2048 } {
6532 eval [string map [list N $N] {
6533 proc check_effective_target_aarch64_sveN_hw { } {
6534 return [aarch64_sve_hw_bits N]
6535 }
6536 }]
6537 }
6538
6539 # Return true if this is an AArch64 target that can run SME code.
6540
6541 proc check_effective_target_aarch64_sme_hw { } {
6542 if { ![istarget aarch64*-*-*] } {
6543 return 0
6544 }
6545 return [check_runtime aarch64_sme_hw_available {
6546 int
6547 main (void)
6548 {
6549 asm volatile ("rdsvl x0, #1");
6550 return 0;
6551 }
6552 } [add_options_for_aarch64_sme ""]]
6553 }
6554
6555 proc check_effective_target_arm_neonv2_hw { } {
6556 return [check_runtime arm_neon_hwv2_available {
6557 #include "arm_neon.h"
6558 int
6559 main (void)
6560 {
6561 float32x2_t a, b, c;
6562 asm ("vfma.f32 %P0, %P1, %P2"
6563 : "=w" (a)
6564 : "w" (b), "w" (c));
6565 return 0;
6566 }
6567 } [add_options_for_arm_neonv2 ""]]
6568 }
6569
6570 # ID_AA64PFR1_EL1.BT using bits[3:0] == 1 implies BTI implimented.
6571 proc check_effective_target_aarch64_bti_hw { } {
6572 if { ![istarget aarch64*-*-*] } {
6573 return 0
6574 }
6575 return [check_runtime aarch64_bti_hw_available {
6576 int
6577 main (void)
6578 {
6579 int a;
6580 asm volatile ("mrs %0, id_aa64pfr1_el1" : "=r" (a));
6581 return !((a & 0xf) == 1);
6582 }
6583 } "-O2" ]
6584 }
6585
6586 # Return 1 if the target supports executing the armv8.3-a FJCVTZS
6587 # instruction.
6588 proc check_effective_target_aarch64_fjcvtzs_hw { } {
6589 if { ![istarget aarch64*-*-*] } {
6590 return 0
6591 }
6592 return [check_runtime aarch64_fjcvtzs_hw_available {
6593 int
6594 main (void)
6595 {
6596 double in = 25.1;
6597 int out;
6598 asm volatile ("fjcvtzs %w0, %d1"
6599 : "=r" (out)
6600 : "w" (in)
6601 : /* No clobbers. */);
6602 return out != 25;
6603 }
6604 } "-march=armv8.3-a" ]
6605 }
6606
6607 # Return 1 if GCC was configured with --enable-standard-branch-protection
6608 proc check_effective_target_default_branch_protection { } {
6609 return [check_configured_with "enable-standard-branch-protection"]
6610 }
6611
6612 # Return 1 if this is an ARM target supporting -mfloat-abi=softfp.
6613
6614 proc check_effective_target_arm_softfp_ok { } {
6615 return [check_no_compiler_messages arm_softfp_ok object {
6616 #include <stdint.h>
6617 int dummy;
6618 int main (void) { return 0; }
6619 } "-mfloat-abi=softfp"]
6620 }
6621
6622 # Return 1 if this is an ARM target supporting -mfloat-abi=hard.
6623
6624 proc check_effective_target_arm_hard_ok { } {
6625 return [check_no_compiler_messages arm_hard_ok object {
6626 #include <stdint.h>
6627 int dummy;
6628 int main (void) { return 0; }
6629 } "-mfloat-abi=hard"]
6630 }
6631
6632 # Return 1 if this is an ARM target supporting MVE.
6633 proc check_effective_target_arm_mve { } {
6634 if { ![istarget arm*-*-*] } {
6635 return 0
6636 }
6637 return [check_no_compiler_messages arm_mve assembly {
6638 #if !defined (__ARM_FEATURE_MVE)
6639 #error FOO
6640 #endif
6641 }]
6642 }
6643
6644 # Return 1 if the target supports ARMv8.1-M MVE with floating point
6645 # instructions, 0 otherwise. The test is valid for ARM.
6646 # Record the command line options needed.
6647
6648 proc check_effective_target_arm_v8_1m_mve_fp_ok_nocache { } {
6649 global et_arm_v8_1m_mve_fp_flags
6650 set et_arm_v8_1m_mve_fp_flags ""
6651
6652 if { ![istarget arm*-*-*] } {
6653 return 0;
6654 }
6655
6656 # Iterate through sets of options to find the compiler flags that
6657 # need to be added to the -march option.
6658 foreach flags {"" "-mfloat-abi=softfp -mfpu=auto -mcpu=unset -march=armv8.1-m.main+mve.fp" "-mfloat-abi=hard -mfpu=auto -mcpu=unset -march=armv8.1-m.main+mve.fp"} {
6659 if { [check_no_compiler_messages_nocache \
6660 arm_v8_1m_mve_fp_ok object {
6661 #include <arm_mve.h>
6662 #if !(__ARM_FEATURE_MVE & 2)
6663 #error "__ARM_FEATURE_MVE for floating point not defined"
6664 #endif
6665 #if __ARM_BIG_ENDIAN
6666 #error "MVE intrinsics are not supported in Big-Endian mode."
6667 #endif
6668 } "$flags -mthumb"] } {
6669 set et_arm_v8_1m_mve_fp_flags "$flags -mthumb --save-temps"
6670 return 1
6671 }
6672 }
6673
6674 return 0;
6675 }
6676
6677 proc check_effective_target_arm_v8_1m_mve_fp_ok { } {
6678 return [check_cached_effective_target arm_v8_1m_mve_fp_ok \
6679 check_effective_target_arm_v8_1m_mve_fp_ok_nocache]
6680 }
6681
6682 proc add_options_for_arm_v8_1m_mve_fp { flags } {
6683 if { ! [check_effective_target_arm_v8_1m_mve_fp_ok] } {
6684 return "$flags"
6685 }
6686 global et_arm_v8_1m_mve_fp_flags
6687 return "$flags $et_arm_v8_1m_mve_fp_flags"
6688 }
6689
6690 # Return 1 if the target supports the ARMv8.1 Adv.SIMD extension, 0
6691 # otherwise. The test is valid for AArch64 and ARM. Record the command
6692 # line options needed.
6693
6694 proc check_effective_target_arm_v8_1a_neon_ok_nocache { } {
6695 global et_arm_v8_1a_neon_flags
6696 set et_arm_v8_1a_neon_flags ""
6697
6698 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
6699 return 0;
6700 }
6701
6702 # Iterate through sets of options to find the compiler flags that
6703 # need to be added to the -march option. Start with the empty set
6704 # since AArch64 only needs the -march setting.
6705 foreach flags {"" "-mfpu=neon-fp-armv8" "-mfloat-abi=softfp" \
6706 "-mfpu=neon-fp-armv8 -mfloat-abi=softfp"} {
6707 foreach arches { "-mcpu=unset -march=armv8-a+rdma" "-mcpu=unset -march=armv8.1-a" } {
6708 if { [check_no_compiler_messages_nocache arm_v8_1a_neon_ok object {
6709 #if !defined (__ARM_FEATURE_QRDMX)
6710 #error "__ARM_FEATURE_QRDMX not defined"
6711 #endif
6712 } "$flags $arches"] } {
6713 set et_arm_v8_1a_neon_flags "$flags $arches"
6714 return 1
6715 }
6716 }
6717 }
6718
6719 return 0;
6720 }
6721
6722 proc check_effective_target_arm_v8_1a_neon_ok { } {
6723 return [check_cached_effective_target arm_v8_1a_neon_ok \
6724 check_effective_target_arm_v8_1a_neon_ok_nocache]
6725 }
6726
6727 # Return 1 if the target supports ARMv8.2 scalar FP16 arithmetic
6728 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
6729 # Record the command line options needed.
6730
6731 proc check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache { } {
6732 global et_arm_v8_2a_fp16_scalar_flags
6733 set et_arm_v8_2a_fp16_scalar_flags ""
6734
6735 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
6736 return 0;
6737 }
6738
6739 # Iterate through sets of options to find the compiler flags that
6740 # need to be added to the -march option.
6741 foreach flags {"" "-mfpu=fp-armv8" "-mfloat-abi=softfp" \
6742 "-mfpu=fp-armv8 -mfloat-abi=softfp"} {
6743 if { [check_no_compiler_messages_nocache \
6744 arm_v8_2a_fp16_scalar_ok object {
6745 #if !defined (__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
6746 #error "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC not defined"
6747 #endif
6748 } "$flags -mcpu=unset -march=armv8.2-a+fp16"] } {
6749 set et_arm_v8_2a_fp16_scalar_flags "$flags -mcpu=unset -march=armv8.2-a+fp16"
6750 return 1
6751 }
6752 }
6753
6754 return 0;
6755 }
6756
6757 proc check_effective_target_arm_v8_2a_fp16_scalar_ok { } {
6758 return [check_cached_effective_target arm_v8_2a_fp16_scalar_ok \
6759 check_effective_target_arm_v8_2a_fp16_scalar_ok_nocache]
6760 }
6761
6762 # Return 1 if the target supports ARMv8.2 Adv.SIMD FP16 arithmetic
6763 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
6764 # Record the command line options needed.
6765
6766 proc check_effective_target_arm_v8_2a_fp16_neon_ok_nocache { } {
6767 global et_arm_v8_2a_fp16_neon_flags
6768 set et_arm_v8_2a_fp16_neon_flags ""
6769
6770 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
6771 return 0;
6772 }
6773
6774 if { [istarget arm*-*-*] } {
6775 set flag_opts {
6776 ""
6777 "-mfp16-format=ieee"
6778 "-mcpu=unset -march=armv8.2-a+fp16 -mfpu=auto"
6779 "-mcpu=unset -march=armv8.2-a+fp16 -mfpu=auto -mfp16-format=ieee"
6780
6781 "-mfloat-abi=softfp"
6782 "-mfloat-abi=softfp -mfp16-format=ieee"
6783 "-mcpu=unset -march=armv8.2-a+fp16 -mfpu=auto -mfloat-abi=softfp"
6784 "-mcpu=unset -march=armv8.2-a+fp16 -mfpu=auto -mfloat-abi=softfp -mfp16-format=ieee"
6785
6786 "-mfloat-abi=hard"
6787 "-mfloat-abi=hard -mfp16-format=ieee"
6788 "-mcpu=unset -march=armv8.2-a+fp16 -mfpu=auto -mfloat-abi=hard"
6789 "-mcpu=unset -march=armv8.2-a+fp16 -mfpu=auto -mfloat-abi=hard -mfp16-format=ieee"
6790 }
6791 } else {
6792 set flag_opts {
6793 ""
6794 "-march=armv8.2-a+fp16"
6795 }
6796 }
6797
6798 # Iterate through sets of options to find the compiler flags that
6799 # need to be added to the -march option.
6800 foreach flags $flag_opts {
6801 if { [check_no_compiler_messages_nocache \
6802 arm_v8_2a_fp16_neon_ok object {
6803 #if !defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
6804 #error "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC not defined"
6805 #endif
6806 } "$flags"] } {
6807 set et_arm_v8_2a_fp16_neon_flags "$flags"
6808 return 1
6809 }
6810 }
6811
6812 return 0;
6813 }
6814
6815 proc check_effective_target_arm_v8_2a_fp16_neon_ok { } {
6816 return [check_cached_effective_target arm_v8_2a_fp16_neon_ok \
6817 check_effective_target_arm_v8_2a_fp16_neon_ok_nocache]
6818 }
6819
6820 # Return 1 if the target supports ARMv8.2 Adv.SIMD Dot Product
6821 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
6822 # Record the command line options needed.
6823
6824 proc check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache { } {
6825 global et_arm_v8_2a_dotprod_neon_flags
6826 set et_arm_v8_2a_dotprod_neon_flags ""
6827
6828 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
6829 return 0;
6830 }
6831
6832 # Iterate through sets of options to find the compiler flags that
6833 # need to be added to the -march option.
6834 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8"} {
6835 if { [check_no_compiler_messages_nocache \
6836 arm_v8_2a_dotprod_neon_ok object {
6837 #include <stdint.h>
6838 #if !defined (__ARM_FEATURE_DOTPROD)
6839 #error "__ARM_FEATURE_DOTPROD not defined"
6840 #endif
6841 } "$flags -mcpu=unset -march=armv8.2-a+dotprod"] } {
6842 set et_arm_v8_2a_dotprod_neon_flags "$flags -mcpu=unset -march=armv8.2-a+dotprod"
6843 return 1
6844 }
6845 }
6846
6847 return 0;
6848 }
6849
6850 # Return 1 if the target supports ARMv8.1-M MVE
6851 # instructions, 0 otherwise. The test is valid for ARM.
6852 # Record the command line options needed.
6853
6854 proc check_effective_target_arm_v8_1m_mve_ok_nocache { } {
6855 global et_arm_v8_1m_mve_flags
6856 set et_arm_v8_1m_mve_flags ""
6857
6858 if { ![istarget arm*-*-*] } {
6859 return 0;
6860 }
6861
6862 # Iterate through sets of options to find the compiler flags that
6863 # need to be added to the -march option.
6864 foreach flags {"" "-mfloat-abi=softfp -mfpu=auto -mcpu=unset -march=armv8.1-m.main+mve" "-mfloat-abi=hard -mfpu=auto -mcpu=unset -march=armv8.1-m.main+mve"} {
6865 if { [check_no_compiler_messages_nocache \
6866 arm_v8_1m_mve_ok object {
6867 #if !defined (__ARM_FEATURE_MVE)
6868 #error "__ARM_FEATURE_MVE not defined"
6869 #endif
6870 #if __ARM_BIG_ENDIAN
6871 #error "MVE intrinsics are not supported in Big-Endian mode."
6872 #endif
6873 #include <arm_mve.h>
6874 } "$flags -mthumb"] } {
6875 set et_arm_v8_1m_mve_flags "$flags -mthumb --save-temps"
6876 return 1
6877 }
6878 }
6879
6880 return 0;
6881 }
6882
6883 proc check_effective_target_arm_v8_1m_mve_ok { } {
6884 return [check_cached_effective_target arm_v8_1m_mve_ok \
6885 check_effective_target_arm_v8_1m_mve_ok_nocache]
6886 }
6887
6888 proc add_options_for_arm_v8_1m_mve { flags } {
6889 if { ! [check_effective_target_arm_v8_1m_mve_ok] } {
6890 return "$flags"
6891 }
6892 global et_arm_v8_1m_mve_flags
6893 return "$flags $et_arm_v8_1m_mve_flags"
6894 }
6895
6896 proc check_effective_target_arm_v8_2a_dotprod_neon_ok { } {
6897 return [check_cached_effective_target arm_v8_2a_dotprod_neon_ok \
6898 check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache]
6899 }
6900
6901 proc add_options_for_arm_v8_2a_dotprod_neon { flags } {
6902 if { ! [check_effective_target_arm_v8_2a_dotprod_neon_ok] } {
6903 return "$flags"
6904 }
6905 global et_arm_v8_2a_dotprod_neon_flags
6906 return "$flags $et_arm_v8_2a_dotprod_neon_flags"
6907 }
6908
6909 # Return 1 if the target supports ARMv8.2+i8mm Adv.SIMD Dot Product
6910 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
6911 # Record the command line options needed.
6912
6913 proc check_effective_target_arm_v8_2a_i8mm_ok_nocache { } {
6914 global et_arm_v8_2a_i8mm_flags
6915 set et_arm_v8_2a_i8mm_flags ""
6916
6917 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
6918 return 0;
6919 }
6920
6921 # Iterate through sets of options to find the compiler flags that
6922 # need to be added to the -march option.
6923 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8" } {
6924 if { [check_no_compiler_messages_nocache \
6925 arm_v8_2a_i8mm_ok object {
6926 #include <arm_neon.h>
6927 #if !defined (__ARM_FEATURE_MATMUL_INT8)
6928 #error "__ARM_FEATURE_MATMUL_INT8 not defined"
6929 #endif
6930 } "$flags -mcpu=unset -march=armv8.2-a+i8mm"] } {
6931 set et_arm_v8_2a_i8mm_flags "$flags -mcpu=unset -march=armv8.2-a+i8mm"
6932 return 1
6933 }
6934 }
6935
6936 return 0;
6937 }
6938
6939 proc check_effective_target_arm_v8_2a_i8mm_ok { } {
6940 return [check_cached_effective_target arm_v8_2a_i8mm_ok \
6941 check_effective_target_arm_v8_2a_i8mm_ok_nocache]
6942 }
6943
6944 proc add_options_for_arm_v8_2a_i8mm { flags } {
6945 if { ! [check_effective_target_arm_v8_2a_i8mm_ok] } {
6946 return "$flags"
6947 }
6948 global et_arm_v8_2a_i8mm_flags
6949 return "$flags $et_arm_v8_2a_i8mm_flags"
6950 }
6951
6952 # Return 1 if the target supports FP16 VFMAL and VFMSL
6953 # instructions, 0 otherwise.
6954 # Record the command line options needed.
6955
6956 proc check_effective_target_arm_fp16fml_neon_ok_nocache { } {
6957 global et_arm_fp16fml_neon_flags
6958 set et_arm_fp16fml_neon_flags ""
6959
6960 if { ![istarget arm*-*-*] } {
6961 return 0;
6962 }
6963
6964 # Iterate through sets of options to find the compiler flags that
6965 # need to be added to the -march option.
6966 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8"} {
6967 if { [check_no_compiler_messages_nocache \
6968 arm_fp16fml_neon_ok assembly {
6969 #include <arm_neon.h>
6970 float32x2_t
6971 foo (float32x2_t r, float16x4_t a, float16x4_t b)
6972 {
6973 return vfmlal_high_f16 (r, a, b);
6974 }
6975 } "$flags -mcpu=unset -march=armv8.2-a+fp16fml"] } {
6976 set et_arm_fp16fml_neon_flags "$flags -mcpu=unset -march=armv8.2-a+fp16fml"
6977 return 1
6978 }
6979 }
6980
6981 return 0;
6982 }
6983
6984 proc check_effective_target_arm_fp16fml_neon_ok { } {
6985 return [check_cached_effective_target arm_fp16fml_neon_ok \
6986 check_effective_target_arm_fp16fml_neon_ok_nocache]
6987 }
6988
6989 proc add_options_for_arm_fp16fml_neon { flags } {
6990 if { ! [check_effective_target_arm_fp16fml_neon_ok] } {
6991 return "$flags"
6992 }
6993 global et_arm_fp16fml_neon_flags
6994 return "$flags $et_arm_fp16fml_neon_flags"
6995 }
6996
6997 # Return 1 if the target supports BFloat16 SIMD instructions, 0 otherwise.
6998 # The test is valid for ARM and for AArch64.
6999
7000 proc check_effective_target_arm_v8_2a_bf16_neon_ok_nocache { } {
7001 global et_arm_v8_2a_bf16_neon_flags
7002 set et_arm_v8_2a_bf16_neon_flags ""
7003
7004 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
7005 return 0;
7006 }
7007
7008 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8" } {
7009 if { [check_no_compiler_messages_nocache arm_v8_2a_bf16_neon_ok object {
7010 #include <arm_neon.h>
7011 #if !defined (__ARM_FEATURE_BF16_VECTOR_ARITHMETIC)
7012 #error "__ARM_FEATURE_BF16_VECTOR_ARITHMETIC not defined"
7013 #endif
7014 } "$flags -mcpu=unset -march=armv8.2-a+bf16"] } {
7015 set et_arm_v8_2a_bf16_neon_flags "$flags -mcpu=unset -march=armv8.2-a+bf16"
7016 return 1
7017 }
7018 }
7019
7020 return 0;
7021 }
7022
7023 proc check_effective_target_arm_v8_2a_bf16_neon_ok { } {
7024 return [check_cached_effective_target arm_v8_2a_bf16_neon_ok \
7025 check_effective_target_arm_v8_2a_bf16_neon_ok_nocache]
7026 }
7027
7028 proc add_options_for_arm_v8_2a_bf16_neon { flags } {
7029 if { ! [check_effective_target_arm_v8_2a_bf16_neon_ok] } {
7030 return "$flags"
7031 }
7032 global et_arm_v8_2a_bf16_neon_flags
7033 return "$flags $et_arm_v8_2a_bf16_neon_flags"
7034 }
7035
7036 # A series of routines are created to 1) check if a given architecture is
7037 # effective (check_effective_target_*_ok) and then 2) give the corresponding
7038 # flags that enable the architecture (add_options_for_*).
7039 # The series includes:
7040 # arm_v8m_main_cde: Armv8-m CDE (Custom Datapath Extension).
7041 # arm_v8m_main_cde_fp: Armv8-m CDE with FP registers.
7042 # arm_v8_1m_main_cde_mve: Armv8.1-m CDE with MVE.
7043 # arm_v8_1m_main_cde_mve_fp: Armv8.1-m CDE with MVE with FP support.
7044 # Usage:
7045 # /* { dg-require-effective-target arm_v8m_main_cde_ok } */
7046 # /* { dg-add-options arm_v8m_main_cde } */
7047 # The tests are valid for Arm.
7048
7049 foreach { armfunc armflag armdef arminc } {
7050 arm_v8m_main_cde
7051 "-march=armv8-m.main+cdecp0+cdecp6 -mthumb"
7052 "defined (__ARM_FEATURE_CDE)"
7053 ""
7054 arm_v8m_main_cde_fp
7055 "-march=armv8-m.main+fp+cdecp0+cdecp6 -mthumb -mfpu=auto"
7056 "defined (__ARM_FEATURE_CDE) && defined (__ARM_FP)"
7057 ""
7058 arm_v8_1m_main_cde_mve
7059 "-march=armv8.1-m.main+mve+cdecp0+cdecp6 -mthumb -mfpu=auto"
7060 "defined (__ARM_FEATURE_CDE) && defined (__ARM_FEATURE_MVE)"
7061 "#include <arm_mve.h>"
7062 arm_v8_1m_main_cde_mve_fp
7063 "-march=armv8.1-m.main+mve.fp+cdecp0+cdecp6 -mthumb -mfpu=auto"
7064 "defined (__ARM_FEATURE_CDE) || __ARM_FEATURE_MVE == 3"
7065 "#include <arm_mve.h>"
7066 } {
7067 eval [string map [list FUNC $armfunc FLAG $armflag DEF $armdef INC $arminc ] {
7068 proc check_effective_target_FUNC_ok_nocache { } {
7069 global et_FUNC_flags
7070 set et_FUNC_flags ""
7071
7072 if { ![istarget arm*-*-*] } {
7073 return 0;
7074 }
7075
7076 if { [check_no_compiler_messages_nocache FUNC_ok assembly {
7077 #if !(DEF)
7078 #error "DEF failed"
7079 #endif
7080 #include <arm_cde.h>
7081 INC
7082 } "-mcpu=unset FLAG"] } {
7083 set et_FUNC_flags "-mcpu=unset FLAG"
7084 return 1
7085 }
7086
7087 return 0;
7088 }
7089
7090 proc check_effective_target_FUNC_ok { } {
7091 return [check_cached_effective_target FUNC_ok \
7092 check_effective_target_FUNC_ok_nocache]
7093 }
7094
7095 proc add_options_for_FUNC { flags } {
7096 if { ! [check_effective_target_FUNC_ok] } {
7097 return "$flags"
7098 }
7099 global et_FUNC_flags
7100 return "$flags $et_FUNC_flags"
7101 }
7102
7103 proc check_effective_target_FUNC_link { } {
7104 if { ! [check_effective_target_FUNC_ok] } {
7105 return 0;
7106 }
7107 return [check_no_compiler_messages FUNC_link executable {
7108 #if !(DEF)
7109 #error "DEF failed"
7110 #endif
7111 #include <arm_cde.h>
7112 INC
7113 int
7114 main (void)
7115 {
7116 return 0;
7117 }
7118 } [add_options_for_FUNC ""]]
7119 }
7120
7121 proc check_effective_target_FUNC_multilib { } {
7122 if { ! [check_effective_target_FUNC_ok] } {
7123 return 0;
7124 }
7125 return [check_runtime FUNC_multilib {
7126 #if !(DEF)
7127 #error "DEF failed"
7128 #endif
7129 #include <arm_cde.h>
7130 INC
7131 int
7132 main (void)
7133 {
7134 return 0;
7135 }
7136 } [add_options_for_FUNC ""]]
7137 }
7138 }]
7139 }
7140
7141 # Return 1 if the target supports executing ARMv8 NEON instructions, 0
7142 # otherwise.
7143
7144 proc check_effective_target_arm_v8_neon_hw { } {
7145 return [check_runtime arm_v8_neon_hw_available {
7146 #include "arm_neon.h"
7147 int
7148 main (void)
7149 {
7150 float32x2_t a = { 1.0f, 2.0f };
7151 #ifdef __ARM_ARCH_ISA_A64
7152 asm ("frinta %0.2s, %1.2s"
7153 : "=w" (a)
7154 : "w" (a));
7155 #else
7156 asm ("vrinta.f32 %P0, %P1"
7157 : "=w" (a)
7158 : "0" (a));
7159 #endif
7160 return a[0] == 2.0f;
7161 }
7162 } [add_options_for_arm_v8_neon ""]]
7163 }
7164
7165 # Return 1 if the target supports executing the ARMv8.1 Adv.SIMD extension, 0
7166 # otherwise. The test is valid for AArch64 and ARM.
7167
7168 proc check_effective_target_arm_v8_1a_neon_hw { } {
7169 if { ![check_effective_target_arm_v8_1a_neon_ok] } {
7170 return 0;
7171 }
7172 return [check_runtime arm_v8_1a_neon_hw_available {
7173 int
7174 main (void)
7175 {
7176 #ifdef __ARM_ARCH_ISA_A64
7177 __Int32x2_t a = {0, 1};
7178 __Int32x2_t b = {0, 2};
7179 __Int32x2_t result;
7180
7181 asm ("sqrdmlah %0.2s, %1.2s, %2.2s"
7182 : "=w"(result)
7183 : "w"(a), "w"(b)
7184 : /* No clobbers. */);
7185
7186 #else
7187
7188 __simd64_int32_t a = {0, 1};
7189 __simd64_int32_t b = {0, 2};
7190 __simd64_int32_t result;
7191
7192 asm ("vqrdmlah.s32 %P0, %P1, %P2"
7193 : "=w"(result)
7194 : "w"(a), "w"(b)
7195 : /* No clobbers. */);
7196 #endif
7197
7198 return result[0];
7199 }
7200 } [add_options_for_arm_v8_1a_neon ""]]
7201 }
7202
7203 # Return 1 if the target supports executing floating point instructions from
7204 # ARMv8.2 with the FP16 extension, 0 otherwise. The test is valid for ARM and
7205 # for AArch64.
7206
7207 proc check_effective_target_arm_v8_2a_fp16_scalar_hw { } {
7208 if { ![check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
7209 return 0;
7210 }
7211 return [check_runtime arm_v8_2a_fp16_scalar_hw_available {
7212 int
7213 main (void)
7214 {
7215 __fp16 a = 1.0;
7216 __fp16 result;
7217
7218 #ifdef __ARM_ARCH_ISA_A64
7219
7220 asm ("fabs %h0, %h1"
7221 : "=w"(result)
7222 : "w"(a)
7223 : /* No clobbers. */);
7224
7225 #else
7226
7227 asm ("vabs.f16 %0, %1"
7228 : "=w"(result)
7229 : "w"(a)
7230 : /* No clobbers. */);
7231
7232 #endif
7233
7234 return (result == 1.0) ? 0 : 1;
7235 }
7236 } [add_options_for_arm_v8_2a_fp16_scalar ""]]
7237 }
7238
7239 # Return 1 if the target supports executing Adv.SIMD instructions from ARMv8.2
7240 # with the FP16 extension, 0 otherwise. The test is valid for ARM and for
7241 # AArch64.
7242
7243 proc check_effective_target_arm_v8_2a_fp16_neon_hw { } {
7244 if { ![check_effective_target_arm_v8_2a_fp16_neon_ok] } {
7245 return 0;
7246 }
7247 return [check_runtime arm_v8_2a_fp16_neon_hw_available {
7248 int
7249 main (void)
7250 {
7251 #ifdef __ARM_ARCH_ISA_A64
7252
7253 __Float16x4_t a = {1.0, -1.0, 1.0, -1.0};
7254 __Float16x4_t result;
7255
7256 asm ("fabs %0.4h, %1.4h"
7257 : "=w"(result)
7258 : "w"(a)
7259 : /* No clobbers. */);
7260
7261 #else
7262
7263 __simd64_float16_t a = {1.0, -1.0, 1.0, -1.0};
7264 __simd64_float16_t result;
7265
7266 asm ("vabs.f16 %P0, %P1"
7267 : "=w"(result)
7268 : "w"(a)
7269 : /* No clobbers. */);
7270
7271 #endif
7272
7273 return (result[0] == 1.0) ? 0 : 1;
7274 }
7275 } [add_options_for_arm_v8_2a_fp16_neon ""]]
7276 }
7277
7278 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.2
7279 # with the Dot Product extension, 0 otherwise. The test is valid for ARM and for
7280 # AArch64.
7281
7282 proc check_effective_target_arm_v8_2a_dotprod_neon_hw { } {
7283 if { ![check_effective_target_arm_v8_2a_dotprod_neon_ok] } {
7284 return 0;
7285 }
7286 return [check_runtime arm_v8_2a_dotprod_neon_hw_available {
7287 #include "arm_neon.h"
7288 int
7289 main (void)
7290 {
7291
7292 uint32x2_t results = {0,0};
7293 uint8x8_t a = {1,1,1,1,2,2,2,2};
7294 uint8x8_t b = {2,2,2,2,3,3,3,3};
7295
7296 #ifdef __ARM_ARCH_ISA_A64
7297 asm ("udot %0.2s, %1.8b, %2.8b"
7298 : "=w"(results)
7299 : "w"(a), "w"(b)
7300 : /* No clobbers. */);
7301
7302 #else
7303 asm ("vudot.u8 %P0, %P1, %P2"
7304 : "=w"(results)
7305 : "w"(a), "w"(b)
7306 : /* No clobbers. */);
7307 #endif
7308
7309 return (results[0] == 8 && results[1] == 24) ? 1 : 0;
7310 }
7311 } [add_options_for_arm_v8_2a_dotprod_neon ""]]
7312 }
7313
7314 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.2
7315 # with the i8mm extension, 0 otherwise. The test is valid for ARM and for
7316 # AArch64.
7317
7318 proc check_effective_target_arm_v8_2a_i8mm_neon_hw { } {
7319 if { ![check_effective_target_arm_v8_2a_i8mm_ok] } {
7320 return 0;
7321 }
7322 return [check_runtime arm_v8_2a_i8mm_neon_hw_available {
7323 #include "arm_neon.h"
7324 int
7325 main (void)
7326 {
7327
7328 uint32x2_t results = {0,0};
7329 uint8x8_t a = {1,1,1,1,2,2,2,2};
7330 int8x8_t b = {2,2,2,2,3,3,3,3};
7331
7332 #ifdef __ARM_ARCH_ISA_A64
7333 asm ("usdot %0.2s, %1.8b, %2.8b"
7334 : "=w"(results)
7335 : "w"(a), "w"(b)
7336 : /* No clobbers. */);
7337
7338 #else
7339 asm ("vusdot.u8 %P0, %P1, %P2"
7340 : "=w"(results)
7341 : "w"(a), "w"(b)
7342 : /* No clobbers. */);
7343 #endif
7344
7345 return (vget_lane_u32 (results, 0) == 8
7346 && vget_lane_u32 (results, 1) == 24) ? 1 : 0;
7347 }
7348 } [add_options_for_arm_v8_2a_i8mm ""]]
7349 }
7350
7351 # Return 1 if this is a ARM target with NEON enabled.
7352
7353 proc check_effective_target_arm_neon { } {
7354 if { [check_effective_target_arm32] } {
7355 return [check_no_compiler_messages arm_neon object {
7356 #ifndef __ARM_NEON__
7357 #error not NEON
7358 #else
7359 int dummy;
7360 #endif
7361 }]
7362 } else {
7363 return 0
7364 }
7365 }
7366
7367 proc check_effective_target_arm_neonv2 { } {
7368 if { [check_effective_target_arm32] } {
7369 return [check_no_compiler_messages arm_neon object {
7370 #ifndef __ARM_NEON__
7371 #error not NEON
7372 #else
7373 #ifndef __ARM_FEATURE_FMA
7374 #error not NEONv2
7375 #else
7376 int dummy;
7377 #endif
7378 #endif
7379 }]
7380 } else {
7381 return 0
7382 }
7383 }
7384
7385 # Return 1 if this is an ARM target with load acquire and store release
7386 # instructions for 8-, 16- and 32-bit types.
7387
7388 proc check_effective_target_arm_acq_rel { } {
7389 return [check_no_compiler_messages arm_acq_rel object {
7390 void
7391 load_acquire_store_release (void)
7392 {
7393 asm ("lda r0, [r1]\n\t"
7394 "stl r0, [r1]\n\t"
7395 "ldah r0, [r1]\n\t"
7396 "stlh r0, [r1]\n\t"
7397 "ldab r0, [r1]\n\t"
7398 "stlb r0, [r1]"
7399 : : : "r0", "memory");
7400 }
7401 }]
7402 }
7403
7404 # Add the options needed for MIPS Paired-Single.
7405
7406 proc add_options_for_mpaired_single { flags } {
7407 if { ! [check_effective_target_mpaired_single "-mpaired-single"] } {
7408 return "$flags"
7409 }
7410 return "$flags -mpaired-single"
7411 }
7412
7413 # Add the options needed for MIPS SIMD Architecture.
7414
7415 proc add_options_for_mips_msa { flags } {
7416 if { ! [check_effective_target_mips_msa "-mmsa"] } {
7417 return "$flags"
7418 }
7419 return "$flags -mmsa"
7420 }
7421
7422 # Add the options needed for MIPS Loongson MMI Architecture.
7423
7424 proc add_options_for_mips_loongson_mmi { flags } {
7425 if { ! [check_effective_target_mips_loongson_mmi "-mloongson-mmi"] } {
7426 return "$flags"
7427 }
7428 return "$flags -mloongson-mmi"
7429 }
7430
7431
7432 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
7433 # the Loongson vector modes.
7434
7435 proc check_effective_target_mips_loongson_mmi { args } {
7436 return [check_no_compiler_messages loongson assembly {
7437 #if !defined(__mips_loongson_mmi)
7438 #error !__mips_loongson_mmi
7439 #endif
7440 #if !defined(__mips_loongson_vector_rev)
7441 #error !__mips_loongson_vector_rev
7442 #endif
7443 } "$args"]
7444 }
7445
7446 # Return 1 if this is a MIPS target that supports the legacy NAN.
7447
7448 proc check_effective_target_mips_nanlegacy { } {
7449 return [check_no_compiler_messages nanlegacy assembly {
7450 #include <stdlib.h>
7451 int main () { return 0; }
7452 } "-mnan=legacy"]
7453 }
7454
7455 # Return 1 if an MSA program can be compiled to object
7456
7457 proc check_effective_target_mips_msa { args } {
7458 if ![check_effective_target_nomips16] {
7459 return 0
7460 }
7461 return [check_no_compiler_messages msa object {
7462 #if !defined(__mips_msa)
7463 #error "MSA NOT AVAIL"
7464 #else
7465 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
7466 #error "MSA NOT AVAIL FOR ISA REV < 2"
7467 #endif
7468 #if !defined(__mips_hard_float)
7469 #error "MSA HARD_FLOAT REQUIRED"
7470 #endif
7471 #if __mips_fpr != 64
7472 #error "MSA 64-bit FPR REQUIRED"
7473 #endif
7474 #include <msa.h>
7475
7476 int main()
7477 {
7478 v8i16 v = __builtin_msa_ldi_h (1);
7479
7480 return v[0];
7481 }
7482 #endif
7483 } "$args"]
7484 }
7485
7486 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
7487 # Architecture.
7488
7489 proc check_effective_target_arm_eabi { } {
7490 return [check_no_compiler_messages arm_eabi object {
7491 #ifndef __ARM_EABI__
7492 #error not EABI
7493 #else
7494 int dummy;
7495 #endif
7496 }]
7497 }
7498
7499 # Return 1 if this is an ARM target that adheres to the hard-float variant of
7500 # the ABI for the ARM Architecture (e.g. -mfloat-abi=hard).
7501
7502 proc check_effective_target_arm_hf_eabi { } {
7503 return [check_no_compiler_messages arm_hf_eabi object {
7504 #if !defined(__ARM_EABI__) || !defined(__ARM_PCS_VFP)
7505 #error not hard-float EABI
7506 #else
7507 int dummy;
7508 #endif
7509 }]
7510 }
7511
7512 # Return 1 if this is an ARM target uses emulated floating point
7513 # operations.
7514
7515 proc check_effective_target_arm_softfloat { } {
7516 return [check_no_compiler_messages arm_softfloat object {
7517 #if !defined(__SOFTFP__)
7518 #error not soft-float EABI
7519 #else
7520 int dummy;
7521 #endif
7522 }]
7523 }
7524
7525 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
7526 # Some multilibs may be incompatible with this option.
7527
7528 proc check_effective_target_arm_iwmmxt_ok { } {
7529 if { [check_effective_target_arm32] } {
7530 return [check_no_compiler_messages arm_iwmmxt_ok object {
7531 int dummy;
7532 } "-mcpu=iwmmxt"]
7533 } else {
7534 return 0
7535 }
7536 }
7537
7538 # Return true if LDRD/STRD instructions are prefered over LDM/STM instructions
7539 # for an ARM target.
7540 proc check_effective_target_arm_prefer_ldrd_strd { } {
7541 if { ![check_effective_target_arm32] } {
7542 return 0;
7543 }
7544
7545 return [check_no_messages_and_pattern arm_prefer_ldrd_strd "strd\tr" assembly {
7546 void foo (void) { __asm__ ("" ::: "r4", "r5"); }
7547 } "-O2 -mthumb" ]
7548 }
7549
7550 # Return true if LDRD/STRD instructions are available on this target.
7551 proc check_effective_target_arm_ldrd_strd_ok { } {
7552 if { ![check_effective_target_arm32] } {
7553 return 0;
7554 }
7555
7556 return [check_no_compiler_messages arm_ldrd_strd_ok object {
7557 int main(void)
7558 {
7559 __UINT64_TYPE__ a = 1, b = 10;
7560 __UINT64_TYPE__ *c = &b;
7561 // `a` will be in a valid register since it's a DImode quantity.
7562 asm ("ldrd %0, %1"
7563 : "=r" (a)
7564 : "m" (c));
7565 return a == 10;
7566 }
7567 }]
7568 }
7569
7570 # Return 1 if this is a PowerPC target supporting -meabi.
7571
7572 proc check_effective_target_powerpc_eabi_ok { } {
7573 if { [istarget powerpc*-*-*] } {
7574 return [check_no_compiler_messages powerpc_eabi_ok object {
7575 int dummy;
7576 } "-meabi"]
7577 } else {
7578 return 0
7579 }
7580 }
7581
7582 # Return 1 if this is a PowerPC target with floating-point registers.
7583
7584 proc check_effective_target_powerpc_fprs { } {
7585 if { [istarget powerpc*-*-*]
7586 || [istarget rs6000-*-*] } {
7587 return [check_no_compiler_messages powerpc_fprs object {
7588 #ifdef __NO_FPRS__
7589 #error no FPRs
7590 #else
7591 int dummy;
7592 #endif
7593 }]
7594 } else {
7595 return 0
7596 }
7597 }
7598
7599 # Return 1 if this is a PowerPC target with hardware double-precision
7600 # floating point.
7601
7602 proc check_effective_target_powerpc_hard_double { } {
7603 if { [istarget powerpc*-*-*]
7604 || [istarget rs6000-*-*] } {
7605 return [check_no_compiler_messages powerpc_hard_double object {
7606 #ifdef _SOFT_DOUBLE
7607 #error soft double
7608 #else
7609 int dummy;
7610 #endif
7611 }]
7612 } else {
7613 return 0
7614 }
7615 }
7616
7617 # Return 1 if this is a PowerPC target with hardware floating point sqrt.
7618
7619 proc check_effective_target_powerpc_sqrt { } {
7620 # We need to be PowerPC, and we need to have hardware fp enabled.
7621 if {![check_effective_target_powerpc_fprs]} {
7622 return 0;
7623 }
7624
7625 return [check_no_compiler_messages powerpc_sqrt object {
7626 void test (void)
7627 {
7628 #ifndef _ARCH_PPCSQ
7629 #error _ARCH_PPCSQ is not defined
7630 #endif
7631 }
7632 } {}]
7633 }
7634
7635 # Return 1 if this is a PowerPC target supporting -maltivec.
7636
7637 proc check_effective_target_powerpc_altivec_ok { } {
7638 # Not PowerPC, then not ok
7639 if { !([istarget powerpc*-*-*] || [istarget rs6000-*-*]) } { return 0 }
7640
7641 # Return true iff compiling with -maltivec does not error.
7642 return [check_no_compiler_messages powerpc_altivec_ok object {
7643 int dummy;
7644 } "-maltivec"]
7645 }
7646
7647 # Return 1 if this is a PowerPC target supporting -mmodulo
7648
7649 proc check_effective_target_powerpc_p9modulo_ok { } {
7650 if { [istarget powerpc*-*-*]
7651 || [istarget rs6000-*-*] } {
7652 return [check_no_compiler_messages powerpc_p9modulo_ok object {
7653 int main (void) {
7654 int i = 5, j = 3, r = -1;
7655 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
7656 return (r == 2);
7657 }
7658 } "-mmodulo"]
7659 } else {
7660 return 0
7661 }
7662 }
7663
7664 # return 1 if our compiler returns the ARCH_PWR defines with the options
7665 # as provided by the test.
7666 proc check_effective_target_has_arch_pwr5 { } {
7667 return [check_no_compiler_messages_nocache arch_pwr5 assembly {
7668 void test (void)
7669 {
7670 #ifndef _ARCH_PWR5
7671 #error does not have power5 support.
7672 #else
7673 /* "has power5 support" */
7674 #endif
7675 }
7676 } [current_compiler_flags]]
7677 }
7678
7679 proc check_effective_target_has_arch_pwr6 { } {
7680 return [check_no_compiler_messages_nocache arch_pwr6 assembly {
7681 void test (void)
7682 {
7683 #ifndef _ARCH_PWR6
7684 #error does not have power6 support.
7685 #else
7686 /* "has power6 support" */
7687 #endif
7688 }
7689 } [current_compiler_flags]]
7690 }
7691
7692 proc check_effective_target_has_arch_pwr7 { } {
7693 return [check_no_compiler_messages_nocache arch_pwr7 assembly {
7694 void test (void)
7695 {
7696 #ifndef _ARCH_PWR7
7697 #error does not have power7 support.
7698 #else
7699 /* "has power7 support" */
7700 #endif
7701 }
7702 } [current_compiler_flags]]
7703 }
7704
7705 proc check_effective_target_has_arch_pwr8 { } {
7706 return [check_no_compiler_messages_nocache arch_pwr8 assembly {
7707 void test (void)
7708 {
7709 #ifndef _ARCH_PWR8
7710 #error does not have power8 support.
7711 #else
7712 /* "has power8 support" */
7713 #endif
7714 }
7715 } [current_compiler_flags]]
7716 }
7717
7718 proc check_effective_target_has_arch_pwr9 { } {
7719 return [check_no_compiler_messages_nocache arch_pwr9 assembly {
7720 void test (void)
7721 {
7722 #ifndef _ARCH_PWR9
7723 #error does not have power9 support.
7724 #else
7725 /* "has power9 support" */
7726 #endif
7727 }
7728 } [current_compiler_flags]]
7729 }
7730
7731 proc check_effective_target_has_arch_pwr10 { } {
7732 return [check_no_compiler_messages_nocache arch_pwr10 assembly {
7733 void test (void)
7734 {
7735 #ifndef _ARCH_PWR10
7736 #error does not have power10 support.
7737 #else
7738 /* "has power10 support" */
7739 #endif
7740 }
7741 } [current_compiler_flags]]
7742 }
7743
7744 proc check_effective_target_has_arch_ppc64 { } {
7745 return [check_no_compiler_messages_nocache arch_ppc64 assembly {
7746 void test (void)
7747 {
7748 #ifndef _ARCH_PPC64
7749 #error does not have ppc64 support.
7750 #else
7751 /* "has ppc64 support" */
7752 #endif
7753 }
7754 } [current_compiler_flags]]
7755 }
7756
7757 # Return 1 if this is a PowerPC target supporting -mcpu=power10.
7758 # Limit this to 64-bit linux systems for now until other targets support
7759 # power10.
7760
7761 proc check_effective_target_power10_ok { } {
7762 if { ([istarget powerpc64*-*-linux*]) } {
7763 return [check_no_compiler_messages power10_ok object {
7764 int main (void) {
7765 long e;
7766 asm ("pli %0,%1" : "=r" (e) : "n" (0x12345));
7767 return e;
7768 }
7769 } "-mcpu=power10"]
7770 } else {
7771 return 0
7772 }
7773 }
7774
7775 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
7776 # software emulation on power7/power8 systems or hardware support on power9.
7777
7778 proc check_effective_target_powerpc_float128_sw_ok { } {
7779 if { [istarget powerpc*-*-*]
7780 || [istarget rs6000-*-*] } {
7781 # Darwin doesn't have VSX, so no soft support for float128.
7782 if { [istarget *-*-darwin*] } {
7783 return 0
7784 }
7785 return [check_no_compiler_messages powerpc_float128_sw_ok object {
7786 volatile __float128 x = 1.0q;
7787 volatile __float128 y = 2.0q;
7788 int main() {
7789 __float128 z = x + y;
7790 return (z == 3.0q);
7791 }
7792 } "-mfloat128 -mvsx"]
7793 } else {
7794 return 0
7795 }
7796 }
7797
7798 # Return 1 if this is a PowerPC target supporting -mfloat128 via hardware
7799 # support on power9.
7800
7801 proc check_effective_target_powerpc_float128_hw_ok { } {
7802 if { [istarget powerpc*-*-*]
7803 || [istarget rs6000-*-*] } {
7804 # Darwin doesn't run on any machine with float128 h/w so far.
7805 if { [istarget *-*-darwin*] } {
7806 return 0
7807 }
7808 return [check_no_compiler_messages powerpc_float128_hw_ok object {
7809 volatile __float128 x = 1.0q;
7810 volatile __float128 y = 2.0q;
7811 int main() {
7812 __float128 z;
7813 __asm__ ("xsaddqp %0,%1,%2" : "=v" (z) : "v" (x), "v" (y));
7814 return (z == 3.0q);
7815 }
7816 } "-mfloat128-hardware"]
7817 } else {
7818 return 0
7819 }
7820 }
7821
7822 # Return 1 if current options define float128, 0 otherwise.
7823
7824 proc check_effective_target_ppc_float128 { } {
7825 return [check_no_compiler_messages_nocache ppc_float128 object {
7826 void test (void)
7827 {
7828 #ifndef __FLOAT128__
7829 nope no good
7830 #endif
7831 }
7832 }]
7833 }
7834
7835 # Return 1 if current options generate float128 insns, 0 otherwise.
7836
7837 proc check_effective_target_ppc_float128_insns { } {
7838 return [check_no_compiler_messages_nocache ppc_float128 object {
7839 void test (void)
7840 {
7841 #ifndef __FLOAT128_HARDWARE__
7842 nope no good
7843 #endif
7844 }
7845 }]
7846 }
7847
7848 # Return 1 if current options generate VSX instructions, 0 otherwise.
7849
7850 proc check_effective_target_powerpc_vsx { } {
7851 return [check_no_compiler_messages_nocache powerpc_vsx object {
7852 void test (void)
7853 {
7854 #ifndef __VSX__
7855 nope no vsx
7856 #endif
7857 }
7858 } [current_compiler_flags]]
7859 }
7860
7861 # Return 1 if this is a PowerPC target supporting -mvsx
7862
7863 proc check_effective_target_powerpc_vsx_ok { } {
7864 if { [istarget powerpc*-*-*]
7865 || [istarget rs6000-*-*] } {
7866 # Darwin doesn't have VSX, even if it's used with an assembler
7867 # which recognises the insns.
7868 if { [istarget *-*-darwin*] } {
7869 return 0
7870 }
7871 return [check_no_compiler_messages powerpc_vsx_ok object {
7872 int main (void) {
7873 asm volatile ("xxlor 0,0,0");
7874 return 0;
7875 }
7876 } "-mvsx"]
7877 } else {
7878 return 0
7879 }
7880 }
7881
7882 # Return 1 if this is a PowerPC target supporting -mhtm
7883
7884 proc check_effective_target_powerpc_htm_ok { } {
7885 if { [istarget powerpc*-*-*]
7886 || [istarget rs6000-*-*] } {
7887 # HTM is not supported on AIX yet.
7888 if { [istarget powerpc*-*-aix*] } {
7889 return 0
7890 }
7891 return [check_no_compiler_messages powerpc_htm_ok object {
7892 int main (void) {
7893 asm volatile ("tbegin. 0");
7894 return 0;
7895 }
7896 } "-mhtm"]
7897 } else {
7898 return 0
7899 }
7900 }
7901
7902 # Return 1 if the target supports executing HTM hardware instructions,
7903 # 0 otherwise. Cache the result.
7904
7905 proc check_htm_hw_available { } {
7906 return [check_cached_effective_target htm_hw_available {
7907 # For now, disable on Darwin
7908 if { [istarget powerpc-*-eabi] || [istarget *-*-darwin*]} {
7909 expr 0
7910 } else {
7911 check_runtime_nocache htm_hw_available {
7912 int main()
7913 {
7914 __builtin_ttest ();
7915 return 0;
7916 }
7917 } "-mhtm"
7918 }
7919 }]
7920 }
7921 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
7922
7923 proc check_effective_target_powerpc_ppu_ok { } {
7924 if [check_effective_target_powerpc_altivec_ok] {
7925 return [check_no_compiler_messages cell_asm_available object {
7926 int main (void) {
7927 #ifdef __MACH__
7928 asm volatile ("lvlx v0,v0,v0");
7929 #else
7930 asm volatile ("lvlx 0,0,0");
7931 #endif
7932 return 0;
7933 }
7934 }]
7935 } else {
7936 return 0
7937 }
7938 }
7939
7940 # Return 1 if this is a PowerPC target that supports SPU.
7941
7942 proc check_effective_target_powerpc_spu { } {
7943 if { [istarget powerpc*-*-linux*] } {
7944 return [check_effective_target_powerpc_altivec_ok]
7945 } else {
7946 return 0
7947 }
7948 }
7949
7950 # Return 1 if this is a PowerPC target with Altivec enabled.
7951
7952 proc check_effective_target_powerpc_altivec { } {
7953 if { [istarget powerpc*-*-*] } {
7954 return [check_no_compiler_messages powerpc_altivec object {
7955 #ifndef __ALTIVEC__
7956 #error not Altivec
7957 #else
7958 int dummy;
7959 #endif
7960 }]
7961 } else {
7962 return 0
7963 }
7964 }
7965
7966 # Return 1 if this is a PowerPC target using the ELFv2 ABI.
7967
7968 proc check_effective_target_powerpc_elfv2 { } {
7969 if { [istarget powerpc*-*-*] } {
7970 return [check_no_compiler_messages powerpc_elfv2 object {
7971 #if _CALL_ELF != 2
7972 #error not ELF v2 ABI
7973 #else
7974 int dummy;
7975 #endif
7976 }]
7977 } else {
7978 return 0
7979 }
7980 }
7981
7982 # Return 1 if this is a PowerPC target supporting -mrop-protect
7983
7984 proc check_effective_target_rop_ok { } {
7985 return [check_effective_target_has_arch_pwr8] && [check_effective_target_powerpc_elfv2]
7986 }
7987
7988 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
7989 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables. Return 1 if the
7990 # test environment appears to run executables on such a simulator.
7991
7992 proc check_effective_target_ultrasparc_hw { } {
7993 return [check_runtime ultrasparc_hw {
7994 int main() { return 0; }
7995 } "-mcpu=ultrasparc"]
7996 }
7997
7998 # Return 1 if the test environment supports executing UltraSPARC VIS2
7999 # instructions. We check this by attempting: "bmask %g0, %g0, %g0"
8000
8001 proc check_effective_target_ultrasparc_vis2_hw { } {
8002 return [check_runtime ultrasparc_vis2_hw {
8003 int main() { __asm__(".word 0x81b00320"); return 0; }
8004 } "-mcpu=ultrasparc3"]
8005 }
8006
8007 # Return 1 if the test environment supports executing UltraSPARC VIS3
8008 # instructions. We check this by attempting: "addxc %g0, %g0, %g0"
8009
8010 proc check_effective_target_ultrasparc_vis3_hw { } {
8011 return [check_runtime ultrasparc_vis3_hw {
8012 int main() { __asm__(".word 0x81b00220"); return 0; }
8013 } "-mcpu=niagara3"]
8014 }
8015
8016 # Return 1 if this is a SPARC-V9 target.
8017
8018 proc check_effective_target_sparc_v9 { } {
8019 if { [istarget sparc*-*-*] } {
8020 return [check_no_compiler_messages sparc_v9 object {
8021 int main (void) {
8022 asm volatile ("return %i7+8");
8023 return 0;
8024 }
8025 }]
8026 } else {
8027 return 0
8028 }
8029 }
8030
8031 # Return 1 if this is a SPARC target with VIS enabled.
8032
8033 proc check_effective_target_sparc_vis { } {
8034 if { [istarget sparc*-*-*] } {
8035 return [check_no_compiler_messages sparc_vis object {
8036 #ifndef __VIS__
8037 #error not VIS
8038 #else
8039 int dummy;
8040 #endif
8041 } [current_compiler_flags]]
8042 } else {
8043 return 0
8044 }
8045 }
8046
8047 # Return 1 if the target supports hardware vector shift operation.
8048
8049 proc check_effective_target_vect_shift { } {
8050 return [check_cached_effective_target_indexed vect_shift {
8051 expr {[istarget powerpc*-*-*]
8052 || [istarget ia64-*-*]
8053 || [check_effective_target_x86]
8054 || [istarget aarch64*-*-*]
8055 || [is-effective-target arm_neon]
8056 || ([istarget mips*-*-*]
8057 && ([et-is-effective-target mips_msa]
8058 || [et-is-effective-target mips_loongson_mmi]))
8059 || ([istarget s390*-*-*]
8060 && [check_effective_target_s390_vx])
8061 || [istarget amdgcn-*-*]
8062 || ([istarget riscv*-*-*]
8063 && [check_effective_target_riscv_v])
8064 || ([istarget loongarch*-*-*]
8065 && [check_effective_target_loongarch_sx]) }}]
8066 }
8067
8068 # Return 1 if the target supports hardware vector shift by register operation.
8069
8070 proc check_effective_target_vect_var_shift { } {
8071 return [check_cached_effective_target_indexed vect_var_shift {
8072 expr {([check_effective_target_x86]
8073 && [check_avx2_available])
8074 || [istarget aarch64*-*-*]
8075 || ([istarget riscv*-*-*]
8076 && [check_effective_target_riscv_v])
8077 || ([istarget loongarch*-*-*]
8078 && [check_effective_target_loongarch_sx])
8079 }}]
8080 }
8081
8082 proc check_effective_target_whole_vector_shift { } {
8083 if { [check_effective_target_x86]
8084 || [istarget ia64-*-*]
8085 || [istarget aarch64*-*-*]
8086 || [istarget powerpc64*-*-*]
8087 || ([is-effective-target arm_neon]
8088 && [check_effective_target_arm_little_endian])
8089 || ([istarget mips*-*-*]
8090 && [et-is-effective-target mips_loongson_mmi])
8091 || ([istarget s390*-*-*]
8092 && [check_effective_target_s390_vx])
8093 || [istarget amdgcn-*-*]
8094 || ([istarget riscv*-*-*]
8095 && [check_effective_target_riscv_v])
8096 || ([istarget loongarch*-*-*]
8097 && [check_effective_target_loongarch_sx]) } {
8098 set answer 1
8099 } else {
8100 set answer 0
8101 }
8102
8103 verbose "check_effective_target_vect_long: returning $answer" 2
8104 return $answer
8105 }
8106
8107 # Return 1 if the target supports vector bswap operations.
8108
8109 proc check_effective_target_vect_bswap { } {
8110 return [check_cached_effective_target_indexed vect_bswap {
8111 expr { ([istarget aarch64*-*-*]
8112 || [is-effective-target arm_neon]
8113 || [istarget amdgcn-*-*])
8114 || [istarget loongarch*-*-*]
8115 || ([istarget s390*-*-*]
8116 && [check_effective_target_s390_vx]) }}]
8117 }
8118
8119 # Return 1 if the target supports comparison of bool vectors for at
8120 # least one vector length.
8121
8122 proc check_effective_target_vect_bool_cmp { } {
8123 return [check_cached_effective_target_indexed vect_bool_cmp {
8124 expr { [check_effective_target_x86]
8125 || [istarget aarch64*-*-*]
8126 || [is-effective-target arm_neon]
8127 || ([istarget riscv*-*-*]
8128 && [check_effective_target_riscv_v])
8129 || ([istarget loongarch*-*-*]
8130 && [check_effective_target_loongarch_sx]) }}]
8131 }
8132
8133 # Return 1 if the target supports addition of char vectors for at least
8134 # one vector length.
8135
8136 proc check_effective_target_vect_char_add { } {
8137 return [check_cached_effective_target_indexed vect_char_add {
8138 expr {
8139 [check_effective_target_x86]
8140 || [istarget powerpc*-*-*]
8141 || [istarget amdgcn-*-*]
8142 || [istarget ia64-*-*]
8143 || [istarget aarch64*-*-*]
8144 || [is-effective-target arm_neon]
8145 || ([istarget mips*-*-*]
8146 && ([et-is-effective-target mips_loongson_mmi]
8147 || [et-is-effective-target mips_msa]))
8148 || ([istarget s390*-*-*]
8149 && [check_effective_target_s390_vx])
8150 || ([istarget riscv*-*-*]
8151 && [check_effective_target_riscv_v])
8152 || ([istarget loongarch*-*-*]
8153 && [check_effective_target_loongarch_sx])
8154 }}]
8155 }
8156
8157 # Return 1 if the target supports hardware vector shift operation for char.
8158
8159 proc check_effective_target_vect_shift_char { } {
8160 return [check_cached_effective_target_indexed vect_shift_char {
8161 expr { [istarget powerpc*-*-*]
8162 || [is-effective-target arm_neon]
8163 || ([istarget mips*-*-*]
8164 && [et-is-effective-target mips_msa])
8165 || ([istarget s390*-*-*]
8166 && [check_effective_target_s390_vx])
8167 || [istarget amdgcn-*-*]
8168 || ([istarget riscv*-*-*]
8169 && [check_effective_target_riscv_v])
8170 || ([istarget loongarch*-*-*]
8171 && [check_effective_target_loongarch_sx]) }}]
8172 }
8173
8174 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
8175 #
8176 # This can change for different subtargets so do not cache the result.
8177
8178 proc check_effective_target_vect_long { } {
8179 if { [check_effective_target_x86]
8180 || ([istarget powerpc*-*-*]
8181 && [check_effective_target_ilp32])
8182 || [is-effective-target arm_neon]
8183 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
8184 || [istarget aarch64*-*-*]
8185 || ([istarget mips*-*-*]
8186 && [et-is-effective-target mips_msa])
8187 || ([istarget s390*-*-*]
8188 && [check_effective_target_s390_vx])
8189 || [istarget amdgcn-*-*]
8190 || ([istarget riscv*-*-*]
8191 && [check_effective_target_riscv_v])
8192 || ([istarget loongarch*-*-*]
8193 && [check_effective_target_loongarch_sx]) } {
8194 set answer 1
8195 } else {
8196 set answer 0
8197 }
8198
8199 verbose "check_effective_target_vect_long: returning $answer" 2
8200 return $answer
8201 }
8202
8203 # Return 1 if the target supports hardware vectors of float when
8204 # -funsafe-math-optimizations is enabled, 0 otherwise.
8205 #
8206 # This won't change for different subtargets so cache the result.
8207
8208 proc check_effective_target_vect_float { } {
8209 return [check_cached_effective_target_indexed vect_float {
8210 expr { [check_effective_target_x86]
8211 || [istarget powerpc*-*-*]
8212 || [istarget mips-sde-elf]
8213 || [istarget mipsisa64*-*-*]
8214 || [istarget ia64-*-*]
8215 || [istarget aarch64*-*-*]
8216 || ([istarget mips*-*-*]
8217 && [et-is-effective-target mips_msa])
8218 || [is-effective-target arm_neon]
8219 || ([istarget s390*-*-*]
8220 && [check_effective_target_s390_vxe])
8221 || [istarget amdgcn-*-*]
8222 || ([istarget riscv*-*-*]
8223 && [check_effective_target_riscv_v])
8224 || ([istarget loongarch*-*-*]
8225 && [check_effective_target_loongarch_sx]) }}]
8226 }
8227
8228 # Return 1 if the target supports hardware vectors of float without
8229 # -funsafe-math-optimizations being enabled, 0 otherwise.
8230
8231 proc check_effective_target_vect_float_strict { } {
8232 return [expr { [check_effective_target_vect_float]
8233 && ![istarget arm*-*-*] }]
8234 }
8235
8236 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
8237 #
8238 # This won't change for different subtargets so cache the result.
8239
8240 proc check_effective_target_vect_double { } {
8241 return [check_cached_effective_target_indexed vect_double {
8242 expr { ([check_effective_target_x86]
8243 && [check_no_compiler_messages vect_double assembly {
8244 #ifdef __tune_atom__
8245 # error No double vectorizer support.
8246 #endif
8247 }])
8248 || [istarget aarch64*-*-*]
8249 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
8250 || ([istarget mips*-*-*]
8251 && [et-is-effective-target mips_msa])
8252 || ([istarget s390*-*-*]
8253 && [check_effective_target_s390_vx])
8254 || [istarget amdgcn-*-*]
8255 || ([istarget riscv*-*-*]
8256 && [check_effective_target_riscv_v])
8257 || ([istarget loongarch*-*-*]
8258 && [check_effective_target_loongarch_sx]) }}]
8259 }
8260
8261 # Return 1 if the target supports conditional addition, subtraction,
8262 # multiplication, division, minimum and maximum on vectors of double,
8263 # via the cond_ optabs. Return 0 otherwise.
8264
8265 proc check_effective_target_vect_double_cond_arith { } {
8266 return [expr { [check_effective_target_aarch64_sve]
8267 || [check_effective_target_riscv_v] }]
8268 }
8269
8270 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
8271 #
8272 # This won't change for different subtargets so cache the result.
8273
8274 proc check_effective_target_vect_long_long { } {
8275 return [check_cached_effective_target_indexed vect_long_long {
8276 expr { [check_effective_target_x86]
8277 || ([istarget mips*-*-*]
8278 && [et-is-effective-target mips_msa])
8279 || ([istarget s390*-*-*]
8280 && [check_effective_target_s390_vx])
8281 || ([istarget powerpc*-*-*]
8282 && [check_effective_target_has_arch_pwr8])
8283 || [istarget aarch64*-*-*]
8284 || ([istarget riscv*-*-*]
8285 && [check_effective_target_riscv_v])
8286 || ([istarget loongarch*-*-*]
8287 && [check_effective_target_loongarch_sx])
8288 || [istarget amdgcn-*-*] }}]
8289 }
8290
8291
8292 # Return 1 if the target plus current options does not support a vector
8293 # max instruction on "int", 0 otherwise.
8294 #
8295 # This won't change for different subtargets so cache the result.
8296
8297 proc check_effective_target_vect_no_int_min_max { } {
8298 return [check_cached_effective_target_indexed vect_no_int_min_max {
8299 expr { [istarget sparc*-*-*]
8300 || [istarget alpha*-*-*]
8301 || ([istarget mips*-*-*]
8302 && [et-is-effective-target mips_loongson_mmi]) }}]
8303 }
8304
8305 # Return 1 if the target plus current options does not support a vector
8306 # add instruction on "int", 0 otherwise.
8307 #
8308 # This won't change for different subtargets so cache the result.
8309
8310 proc check_effective_target_vect_no_int_add { } {
8311 # Alpha only supports vector add on V8QI and V4HI.
8312 return [check_cached_effective_target_indexed vect_no_int_add {
8313 expr { [istarget alpha*-*-*] }}]
8314 }
8315
8316 # Return 1 if the target plus current options does not support vector
8317 # bitwise instructions, 0 otherwise.
8318 #
8319 # This won't change for different subtargets so cache the result.
8320
8321 proc check_effective_target_vect_no_bitwise { } {
8322 return [check_cached_effective_target_indexed vect_no_bitwise { return 0 }]
8323 }
8324
8325 # Return 1 if the target plus current options supports vector permutation,
8326 # 0 otherwise.
8327 #
8328 # This won't change for different subtargets so cache the result.
8329
8330 proc check_effective_target_vect_perm { } {
8331 return [check_cached_effective_target_indexed vect_perm {
8332 expr { [is-effective-target arm_neon]
8333 || [istarget aarch64*-*-*]
8334 || [istarget powerpc*-*-*]
8335 || [check_effective_target_x86]
8336 || ([istarget mips*-*-*]
8337 && ([et-is-effective-target mpaired_single]
8338 || [et-is-effective-target mips_msa]))
8339 || ([istarget s390*-*-*]
8340 && [check_effective_target_s390_vx])
8341 || [istarget amdgcn-*-*]
8342 || ([istarget riscv*-*-*]
8343 && [check_effective_target_riscv_v])
8344 || ([istarget loongarch*-*-*]
8345 && [check_effective_target_loongarch_sx]) }}]
8346 }
8347
8348 # Return 1 if, for some VF:
8349 #
8350 # - the target's default vector size is VF * ELEMENT_BITS bits
8351 #
8352 # - it is possible to implement the equivalent of:
8353 #
8354 # int<ELEMENT_BITS>_t s1[COUNT][COUNT * VF], s2[COUNT * VF];
8355 # for (int i = 0; i < COUNT; ++i)
8356 # for (int j = 0; j < COUNT * VF; ++j)
8357 # s1[i][j] = s2[j - j % COUNT + i]
8358 #
8359 # using only a single 2-vector permute for each vector in s1.
8360 #
8361 # E.g. for COUNT == 3 and vector length 4, the two arrays would be:
8362 #
8363 # s2 | a0 a1 a2 a3 | b0 b1 b2 b3 | c0 c1 c2 c3
8364 # ------+-------------+-------------+------------
8365 # s1[0] | a0 a0 a0 a3 | a3 a3 b2 b2 | b2 c1 c1 c1
8366 # s1[1] | a1 a1 a1 b0 | b0 b0 b3 b3 | b3 c2 c2 c2
8367 # s1[2] | a2 a2 a2 b1 | b1 b1 c0 c0 | c0 c3 c3 c3
8368 #
8369 # Each s1 permute requires only two of a, b and c.
8370 #
8371 # The distance between the start of vector n in s1[0] and the start
8372 # of vector n in s2 is:
8373 #
8374 # A = (n * VF) % COUNT
8375 #
8376 # The corresponding value for the end of vector n is:
8377 #
8378 # B = (n * VF + VF - 1) % COUNT
8379 #
8380 # Subtracting i from each value gives the corresponding difference
8381 # for s1[i]. The condition being tested by this function is false
8382 # iff A - i > 0 and B - i < 0 for some i and n, such that the first
8383 # element for s1[i] comes from vector n - 1 of s2 and the last element
8384 # comes from vector n + 1 of s2. The condition is therefore true iff
8385 # A <= B for all n. This is turn means the condition is true iff:
8386 #
8387 # (n * VF) % COUNT + (VF - 1) % COUNT < COUNT
8388 #
8389 # for all n. COUNT - (n * VF) % COUNT is bounded by gcd (VF, COUNT),
8390 # and will be that value for at least one n in [0, COUNT), so we want:
8391 #
8392 # (VF - 1) % COUNT < gcd (VF, COUNT)
8393
8394 proc vect_perm_supported { count element_bits } {
8395 set vector_bits [lindex [available_vector_sizes] 0]
8396 # The number of vectors has to be a power of 2 when permuting
8397 # variable-length vectors.
8398 if { $vector_bits <= 0 && ($count & -$count) != $count } {
8399 return 0
8400 }
8401 set vf [expr { $vector_bits / $element_bits }]
8402
8403 # Compute gcd (VF, COUNT).
8404 set gcd $vf
8405 set temp1 $count
8406 while { $temp1 > 0 } {
8407 set temp2 [expr { $gcd % $temp1 }]
8408 set gcd $temp1
8409 set temp1 $temp2
8410 }
8411 return [expr { ($vf - 1) % $count < $gcd }]
8412 }
8413
8414 # Return 1 if the target supports SLP permutation of 3 vectors when each
8415 # element has 32 bits.
8416
8417 proc check_effective_target_vect_perm3_int { } {
8418 return [expr { [check_effective_target_vect_perm]
8419 && [vect_perm_supported 3 32] }]
8420 }
8421
8422 # Return 1 if the target plus current options supports vector permutation
8423 # on byte-sized elements, 0 otherwise.
8424 #
8425 # This won't change for different subtargets so cache the result.
8426
8427 proc check_effective_target_vect_perm_byte { } {
8428 return [check_cached_effective_target_indexed vect_perm_byte {
8429 expr { ([is-effective-target arm_neon]
8430 && [is-effective-target arm_little_endian])
8431 || ([istarget aarch64*-*-*]
8432 && [is-effective-target aarch64_little_endian])
8433 || [istarget powerpc*-*-*]
8434 || ([istarget mips-*.*]
8435 && [et-is-effective-target mips_msa])
8436 || ([istarget s390*-*-*]
8437 && [check_effective_target_s390_vx])
8438 || [istarget amdgcn-*-*]
8439 || ([istarget riscv*-*-*]
8440 && [check_effective_target_riscv_v])
8441 || ([istarget loongarch*-*-*]
8442 && [check_effective_target_loongarch_sx]) }}]
8443 }
8444
8445 # Return 1 if the target supports SLP permutation of 3 vectors when each
8446 # element has 8 bits.
8447
8448 proc check_effective_target_vect_perm3_byte { } {
8449 return [expr { [check_effective_target_vect_perm_byte]
8450 && [vect_perm_supported 3 8] }]
8451 }
8452
8453 # Return 1 if the target plus current options supports vector permutation
8454 # on short-sized elements, 0 otherwise.
8455 #
8456 # This won't change for different subtargets so cache the result.
8457
8458 proc check_effective_target_vect_perm_short { } {
8459 return [check_cached_effective_target_indexed vect_perm_short {
8460 expr { ([is-effective-target arm_neon]
8461 && [is-effective-target arm_little_endian])
8462 || ([istarget aarch64*-*-*]
8463 && [is-effective-target aarch64_little_endian])
8464 || [istarget powerpc*-*-*]
8465 || ([check_effective_target_x86]
8466 && [check_ssse3_available])
8467 || ([istarget mips*-*-*]
8468 && [et-is-effective-target mips_msa])
8469 || ([istarget s390*-*-*]
8470 && [check_effective_target_s390_vx])
8471 || [istarget amdgcn-*-*]
8472 || ([istarget riscv*-*-*]
8473 && [check_effective_target_riscv_v])
8474 || ([istarget loongarch*-*-*]
8475 && [check_effective_target_loongarch_sx]) }}]
8476 }
8477
8478 # Return 1 if the target supports SLP permutation of 3 vectors when each
8479 # element has 16 bits.
8480
8481 proc check_effective_target_vect_perm3_short { } {
8482 return [expr { [check_effective_target_vect_perm_short]
8483 && [vect_perm_supported 3 16] }]
8484 }
8485
8486 # Return 1 if the target plus current options supports folding of
8487 # copysign into XORSIGN.
8488 #
8489 # This won't change for different subtargets so cache the result.
8490
8491 proc check_effective_target_xorsign { } {
8492 return [check_cached_effective_target_indexed xorsign {
8493 expr { [check_effective_target_x86]
8494 || [istarget aarch64*-*-*] || [istarget arm*-*-*] }}]
8495 }
8496
8497 # Return 1 if the target plus current options supports folding of
8498 # copysign into IFN_COPYSIGN.
8499 #
8500 # This won't change for different subtargets so cache the result.
8501
8502 proc check_effective_target_ifn_copysign { } {
8503 return [check_cached_effective_target_indexed ifn_copysign {
8504 expr {
8505 ([check_effective_target_x86]
8506 && [is-effective-target sse])
8507 || ([istarget loongarch*-*-*]
8508 && [check_effective_target_hard_float])
8509 || [istarget powerpc*-*-*]
8510 || [istarget alpha*-*-*]
8511 || [istarget aarch64*-*-*]
8512 || [is-effective-target arm_neon]
8513 || ([istarget s390*-*-*]
8514 && [check_effective_target_s390_vx])
8515 || ([istarget riscv*-*-*]
8516 && [check_effective_target_hard_float])
8517 }}]
8518 }
8519
8520 # Return 1 if the target plus current options supports a vector
8521 # widening summation of *short* args into *int* result, 0 otherwise.
8522 #
8523 # This won't change for different subtargets so cache the result.
8524
8525 proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
8526 return [check_cached_effective_target_indexed vect_widen_sum_hi_to_si_pattern {
8527 expr { [istarget powerpc*-*-*]
8528 || ([istarget aarch64*-*-*]
8529 && ![check_effective_target_aarch64_sve])
8530 || [is-effective-target arm_neon]
8531 || [istarget ia64-*-*] }}]
8532 }
8533
8534 # Return 1 if the target plus current options supports a vector
8535 # widening summation of *short* args into *int* result, 0 otherwise.
8536 # A target can also support this widening summation if it can support
8537 # promotion (unpacking) from shorts to ints.
8538 #
8539 # This won't change for different subtargets so cache the result.
8540
8541 proc check_effective_target_vect_widen_sum_hi_to_si { } {
8542 return [check_cached_effective_target_indexed vect_widen_sum_hi_to_si {
8543 expr { [check_effective_target_vect_unpack]
8544 || [istarget powerpc*-*-*]
8545 || [istarget ia64-*-*]
8546 || [istarget loongarch*-*-*]
8547 || [istarget riscv*-*-*] }}]
8548 }
8549
8550 # Return 1 if the target plus current options supports a vector
8551 # widening summation of *char* args into *short* result, 0 otherwise.
8552 # A target can also support this widening summation if it can support
8553 # promotion (unpacking) from chars to shorts.
8554 #
8555 # This won't change for different subtargets so cache the result.
8556
8557 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
8558 return [check_cached_effective_target_indexed vect_widen_sum_qi_to_hi {
8559 expr { [check_effective_target_vect_unpack]
8560 || [is-effective-target arm_neon]
8561 || [istarget ia64-*-*]
8562 || [istarget riscv*-*-*]
8563 || [istarget loongarch*-*-*] }}]
8564 }
8565
8566 # Return 1 if the target plus current options supports a vector
8567 # widening summation of *char* args into *int* result, 0 otherwise.
8568 #
8569 # This won't change for different subtargets so cache the result.
8570
8571 proc check_effective_target_vect_widen_sum_qi_to_si { } {
8572 return [check_cached_effective_target_indexed vect_widen_sum_qi_to_si {
8573 expr { [istarget powerpc*-*-*]
8574 || [istarget loongarch*-*-*]
8575 || [istarget riscv*-*-*] }}]
8576 }
8577
8578 # Return 1 if the target plus current options supports a vector
8579 # widening multiplication of *char* args into *short* result, 0 otherwise.
8580 # A target can also support this widening multplication if it can support
8581 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
8582 # multiplication of shorts).
8583 #
8584 # This won't change for different subtargets so cache the result.
8585
8586
8587 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
8588 return [check_cached_effective_target_indexed vect_widen_mult_qi_to_hi {
8589 expr { ([check_effective_target_vect_unpack]
8590 && [check_effective_target_vect_short_mult])
8591 || ([istarget powerpc*-*-*]
8592 || ([istarget aarch64*-*-*]
8593 && ![check_effective_target_aarch64_sve])
8594 || [is-effective-target arm_neon]
8595 || ([istarget s390*-*-*]
8596 && [check_effective_target_s390_vx]))
8597 || [istarget amdgcn-*-*] }}]
8598 }
8599
8600 # Return 1 if the target plus current options supports a vector
8601 # widening multiplication of *short* args into *int* result, 0 otherwise.
8602 # A target can also support this widening multplication if it can support
8603 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
8604 # multiplication of ints).
8605 #
8606 # This won't change for different subtargets so cache the result.
8607
8608
8609 proc check_effective_target_vect_widen_mult_hi_to_si { } {
8610 return [check_cached_effective_target_indexed vect_widen_mult_hi_to_si {
8611 expr { ([check_effective_target_vect_unpack]
8612 && [check_effective_target_vect_int_mult])
8613 || ([istarget powerpc*-*-*]
8614 || [istarget ia64-*-*]
8615 || ([istarget aarch64*-*-*]
8616 && ![check_effective_target_aarch64_sve])
8617 || [check_effective_target_x86]
8618 || [is-effective-target arm_neon]
8619 || ([istarget s390*-*-*]
8620 && [check_effective_target_s390_vx]))
8621 || [istarget amdgcn-*-*] }}]
8622 }
8623
8624 # Return 1 if the target plus current options supports a vector
8625 # widening multiplication of *char* args into *short* result, 0 otherwise.
8626 #
8627 # This won't change for different subtargets so cache the result.
8628
8629 proc check_effective_target_vect_widen_mult_qi_to_hi_pattern { } {
8630 return [check_cached_effective_target_indexed vect_widen_mult_qi_to_hi_pattern {
8631 expr { [istarget powerpc*-*-*]
8632 || ([is-effective-target arm_neon]
8633 && [check_effective_target_arm_little_endian])
8634 || ([istarget s390*-*-*]
8635 && [check_effective_target_s390_vx])
8636 || [istarget loongarch*-*-*]
8637 || [istarget amdgcn-*-*] }}]
8638 }
8639
8640 # Return 1 if the target plus current options supports a vector
8641 # widening multiplication of *short* args into *int* result, 0 otherwise.
8642 #
8643 # This won't change for different subtargets so cache the result.
8644
8645 proc check_effective_target_vect_widen_mult_hi_to_si_pattern { } {
8646 return [check_cached_effective_target_indexed vect_widen_mult_hi_to_si_pattern {
8647 expr { [istarget powerpc*-*-*]
8648 || [istarget ia64-*-*]
8649 || [istarget loongarch*-*-*]
8650 || [check_effective_target_x86]
8651 || ([is-effective-target arm_neon]
8652 && [check_effective_target_arm_little_endian])
8653 || ([istarget s390*-*-*]
8654 && [check_effective_target_s390_vx])
8655 || [istarget amdgcn-*-*] }}]
8656 }
8657
8658 # Return 1 if the target plus current options supports a vector
8659 # widening multiplication of *int* args into *long* result, 0 otherwise.
8660 #
8661 # This won't change for different subtargets so cache the result.
8662
8663 proc check_effective_target_vect_widen_mult_si_to_di_pattern { } {
8664 return [check_cached_effective_target_indexed vect_widen_mult_si_to_di_pattern {
8665 expr { [istarget ia64-*-*]
8666 || [check_effective_target_x86]
8667 || [istarget loongarch*-*-*]
8668 || ([istarget s390*-*-*]
8669 && [check_effective_target_s390_vx]) }}]
8670 }
8671
8672 # Return 1 if the target plus current options supports a vector
8673 # widening shift, 0 otherwise.
8674 #
8675 # This won't change for different subtargets so cache the result.
8676
8677 proc check_effective_target_vect_widen_shift { } {
8678 return [check_cached_effective_target_indexed vect_widen_shift {
8679 expr { [is-effective-target arm_neon] }}]
8680 }
8681
8682 # Return 1 if the target plus current options supports a vector
8683 # dot-product of signed chars, 0 otherwise.
8684 #
8685 # This won't change for different subtargets so cache the result.
8686
8687 proc check_effective_target_vect_sdot_qi { } {
8688 return [check_cached_effective_target_indexed vect_sdot_qi {
8689 expr { [istarget ia64-*-*]
8690 || [istarget aarch64*-*-*]
8691 || [istarget arm*-*-*]
8692 || ([istarget mips*-*-*]
8693 && [et-is-effective-target mips_msa])
8694 || ([istarget riscv*-*-*]
8695 && [check_effective_target_riscv_v])
8696 || ([istarget loongarch*-*-*]
8697 && [check_effective_target_loongarch_sx]) }}]
8698 }
8699
8700 # Return 1 if the target plus current options supports a vector
8701 # dot-product of unsigned chars, 0 otherwise.
8702 #
8703 # This won't change for different subtargets so cache the result.
8704
8705 proc check_effective_target_vect_udot_qi { } {
8706 return [check_cached_effective_target_indexed vect_udot_qi {
8707 expr { [istarget powerpc*-*-*]
8708 || [istarget aarch64*-*-*]
8709 || [istarget arm*-*-*]
8710 || [istarget ia64-*-*]
8711 || ([istarget mips*-*-*]
8712 && [et-is-effective-target mips_msa])
8713 || ([istarget riscv*-*-*]
8714 && [check_effective_target_riscv_v])
8715 || ([istarget loongarch*-*-*]
8716 && [check_effective_target_loongarch_sx]) }}]
8717 }
8718
8719 # Return 1 if the target plus current options supports a vector
8720 # dot-product where one operand of the multiply is signed char
8721 # and the other unsigned chars, 0 otherwise.
8722 #
8723 # This won't change for different subtargets so cache the result.
8724
8725 proc check_effective_target_vect_usdot_qi { } {
8726 return [check_cached_effective_target_indexed vect_usdot_qi {
8727 expr { [istarget aarch64*-*-*]
8728 || [istarget arm*-*-*] }}]
8729 }
8730
8731
8732 # Return 1 if the target plus current options supports a vector
8733 # dot-product of signed shorts, 0 otherwise.
8734 #
8735 # This won't change for different subtargets so cache the result.
8736
8737 proc check_effective_target_vect_sdot_hi { } {
8738 return [check_cached_effective_target_indexed vect_sdot_hi {
8739 expr { [istarget powerpc*-*-*]
8740 || [istarget ia64-*-*]
8741 || [check_effective_target_x86]
8742 || ([istarget mips*-*-*]
8743 && [et-is-effective-target mips_msa])
8744 || ([istarget riscv*-*-*]
8745 && [check_effective_target_riscv_v])
8746 || ([istarget loongarch*-*-*]
8747 && [check_effective_target_loongarch_sx]) }}]
8748 }
8749
8750 # Return 1 if the target plus current options supports a vector
8751 # dot-product of unsigned shorts, 0 otherwise.
8752 #
8753 # This won't change for different subtargets so cache the result.
8754
8755 proc check_effective_target_vect_udot_hi { } {
8756 return [check_cached_effective_target_indexed vect_udot_hi {
8757 expr { [istarget powerpc*-*-*]
8758 || ([istarget mips*-*-*]
8759 && [et-is-effective-target mips_msa])
8760 || ([istarget riscv*-*-*]
8761 && [check_effective_target_riscv_v])
8762 || ([istarget loongarch*-*-*]
8763 && [check_effective_target_loongarch_sx]) }}]
8764 }
8765
8766 # Return 1 if the target plus current options supports a vector
8767 # sad operation of unsigned chars, 0 otherwise.
8768 #
8769 # This won't change for different subtargets so cache the result.
8770
8771 proc check_effective_target_vect_usad_char { } {
8772 return [check_cached_effective_target_indexed vect_usad_char {
8773 expr { [check_effective_target_x86]
8774 || ([istarget aarch64*-*-*]
8775 && ![check_effective_target_aarch64_sve])
8776 || ([istarget powerpc*-*-*]
8777 && [check_p9vector_hw_available])
8778 || ([istarget riscv*-*-*]
8779 && [check_effective_target_riscv_v])
8780 || ([istarget loongarch*-*-*]
8781 && [check_effective_target_loongarch_sx]) }}]
8782 }
8783
8784 # Return 1 if the target plus current options supports both signed
8785 # and unsigned average operations on vectors of bytes.
8786
8787 proc check_effective_target_vect_avg_qi {} {
8788 return [expr { ([istarget aarch64*-*-*]
8789 && ![check_effective_target_aarch64_sve1_only])
8790 || ([istarget riscv*-*-*]
8791 && [check_effective_target_riscv_v])
8792 || ([istarget loongarch*-*-*]
8793 && [check_effective_target_loongarch_sx]) }]
8794 }
8795
8796 # Return 1 if the target plus current options supports both signed
8797 # and unsigned multiply-high-with-round-and-scale operations
8798 # on vectors of half-words.
8799
8800 proc check_effective_target_vect_mulhrs_hi {} {
8801 return [expr { [istarget aarch64*-*-*]
8802 && [check_effective_target_aarch64_sve2] }]
8803 }
8804
8805 # Return 1 if the target plus current options supports signed division
8806 # by power-of-2 operations on vectors of 4-byte integers.
8807
8808 proc check_effective_target_vect_sdiv_pow2_si {} {
8809 return [expr { ([istarget aarch64*-*-*]
8810 && [check_effective_target_aarch64_sve]) }]
8811 }
8812
8813 # Return 1 if the target plus current options supports a vector
8814 # demotion (packing) of shorts (to chars) and ints (to shorts)
8815 # using modulo arithmetic, 0 otherwise.
8816 #
8817 # This won't change for different subtargets so cache the result.
8818
8819 proc check_effective_target_vect_pack_trunc { } {
8820 return [check_cached_effective_target_indexed vect_pack_trunc {
8821 expr { [istarget powerpc*-*-*]
8822 || [check_effective_target_x86]
8823 || [istarget aarch64*-*-*]
8824 || ([check_effective_target_arm_neon_ok]
8825 && [check_effective_target_arm_little_endian])
8826 || ([istarget mips*-*-*]
8827 && [et-is-effective-target mips_msa])
8828 || ([istarget s390*-*-*]
8829 && [check_effective_target_s390_vx])
8830 || [istarget amdgcn*-*-*]
8831 || ([istarget riscv*-*-*]
8832 && [check_effective_target_riscv_v])
8833 || ([istarget loongarch*-*-*]
8834 && [check_effective_target_loongarch_sx]) }}]
8835 }
8836
8837 # Return 1 if the target plus current options supports a vector
8838 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
8839 #
8840 # This won't change for different subtargets so cache the result.
8841
8842 proc check_effective_target_vect_unpack { } {
8843 return [check_cached_effective_target_indexed vect_unpack {
8844 expr { [istarget powerpc*-*-*]
8845 || [check_effective_target_x86]
8846 || [istarget ia64-*-*]
8847 || [istarget aarch64*-*-*]
8848 || ([istarget mips*-*-*]
8849 && [et-is-effective-target mips_msa])
8850 || ([check_effective_target_arm_neon_ok]
8851 && [check_effective_target_arm_little_endian])
8852 || ([istarget s390*-*-*]
8853 && [check_effective_target_s390_vx])
8854 || [istarget amdgcn*-*-*]
8855 || ([istarget riscv*-*-*]
8856 && [check_effective_target_riscv_v])
8857 || ([istarget loongarch*-*-*]
8858 && [check_effective_target_loongarch_sx]) }}]
8859 }
8860
8861 # Return 1 if the target plus current options does not guarantee
8862 # that its STACK_BOUNDARY is >= the reguired vector alignment.
8863 #
8864 # This won't change for different subtargets so cache the result.
8865
8866 proc check_effective_target_unaligned_stack { } {
8867 return [check_cached_effective_target_indexed unaligned_stack { expr 0 }]
8868 }
8869
8870 # Return 1 if the target plus current options does not support a vector
8871 # alignment mechanism, 0 otherwise.
8872 #
8873 # This won't change for different subtargets so cache the result.
8874
8875 proc check_effective_target_vect_no_align { } {
8876 return [check_cached_effective_target_indexed vect_no_align {
8877 expr { [istarget mipsisa64*-*-*]
8878 || [istarget mips-sde-elf]
8879 || [istarget sparc*-*-*]
8880 || [istarget ia64-*-*]
8881 || [check_effective_target_arm_vect_no_misalign]
8882 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
8883 || ([istarget mips*-*-*]
8884 && [et-is-effective-target mips_loongson_mmi]) }}]
8885 }
8886
8887 # Return 1 if the target supports a vector misalign access, 0 otherwise.
8888 #
8889 # This won't change for different subtargets so cache the result.
8890
8891 proc check_effective_target_vect_hw_misalign { } {
8892 return [check_cached_effective_target_indexed vect_hw_misalign {
8893 if { [check_effective_target_x86]
8894 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
8895 || [istarget aarch64*-*-*]
8896 || ([istarget mips*-*-*] && [et-is-effective-target mips_msa])
8897 || ([istarget s390*-*-*]
8898 && [check_effective_target_s390_vx])
8899 || ([istarget loongarch*-*-*])
8900 || [istarget amdgcn*-*-*] } {
8901 return 1
8902 }
8903 if { [istarget arm*-*-*]
8904 && ![check_effective_target_arm_vect_no_misalign] } {
8905 return 1
8906 }
8907 if { [istarget riscv*-*-*]
8908 && [check_effective_target_riscv_v_misalign_ok] } {
8909 return 1
8910 }
8911
8912 return 0
8913 }]
8914 }
8915
8916
8917 # Return 1 if arrays are aligned to the vector alignment
8918 # boundary, 0 otherwise.
8919
8920 proc check_effective_target_vect_aligned_arrays { } {
8921 set et_vect_aligned_arrays 0
8922 if { ([check_effective_target_x86]
8923 && !([is-effective-target ia32]
8924 || ([check_avx_available] && ![check_prefer_avx128]))) } {
8925 set et_vect_aligned_arrays 1
8926 }
8927
8928 verbose "check_effective_target_vect_aligned_arrays:\
8929 returning $et_vect_aligned_arrays" 2
8930 return $et_vect_aligned_arrays
8931 }
8932
8933 # Return 1 if the biggest alignment required by target is 1 * BITS_PER_UNIT.
8934 # In such case the target does not impose any alignment constraints.
8935
8936 proc check_effective_target_no_alignment_constraints { } {
8937 return [check_runtime_nocache no_alignment_constraints {
8938 int
8939 main (void)
8940 {
8941 return __BIGGEST_ALIGNMENT__ == 1 ? 0 : 1;
8942 }
8943 }]
8944 }
8945
8946 # Return 1 if types of size 32 bit or less are naturally aligned
8947 # (aligned to their type-size), 0 otherwise.
8948 #
8949 # This won't change for different subtargets so cache the result.
8950
8951 proc check_effective_target_natural_alignment_32 { } {
8952 # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
8953 # FIXME: m68k has -malign-int
8954 return [check_cached_effective_target_indexed natural_alignment_32 {
8955 if { ([istarget *-*-darwin*] && [is-effective-target lp64])
8956 || [istarget avr-*-*]
8957 || [istarget m68k-*-linux*]
8958 || [istarget pru-*-*]
8959 || [istarget stormy16-*-*]
8960 || [istarget rl78-*-*]
8961 || [istarget pdp11-*-*]
8962 || [istarget msp430-*-*]
8963 || [istarget m32c-*-*]
8964 || [istarget cris-*-*] } {
8965 return 0
8966 } else {
8967 return 1
8968 }
8969 }]
8970 }
8971
8972 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
8973 # type-size), 0 otherwise.
8974 #
8975 # This won't change for different subtargets so cache the result.
8976
8977 proc check_effective_target_natural_alignment_64 { } {
8978 return [check_cached_effective_target_indexed natural_alignment_64 {
8979 expr { [is-effective-target natural_alignment_32]
8980 && [is-effective-target lp64] && ![istarget *-*-darwin*] }
8981 }]
8982 }
8983
8984 # Return 1 if all vector types are naturally aligned (aligned to their
8985 # type-size), 0 otherwise.
8986
8987 proc check_effective_target_vect_natural_alignment { } {
8988 set et_vect_natural_alignment 1
8989 if { [check_effective_target_arm_eabi]
8990 || [istarget nvptx-*-*]
8991 || [istarget s390*-*-*]
8992 || [istarget amdgcn-*-*] } {
8993 set et_vect_natural_alignment 0
8994 }
8995 verbose "check_effective_target_vect_natural_alignment:\
8996 returning $et_vect_natural_alignment" 2
8997 return $et_vect_natural_alignment
8998 }
8999
9000 # Return true if the target supports the check_raw_ptrs and check_war_ptrs
9001 # optabs on vectors.
9002
9003 proc check_effective_target_vect_check_ptrs { } {
9004 return [check_effective_target_aarch64_sve2]
9005 }
9006
9007 # Return true if fully-masked loops are supported.
9008
9009 proc check_effective_target_vect_fully_masked { } {
9010 return [expr { [check_effective_target_aarch64_sve]
9011 || [istarget amdgcn*-*-*]
9012 || [check_effective_target_riscv_v] }]
9013 }
9014
9015 # Return true if the target supports the @code{len_load} and
9016 # @code{len_store} optabs.
9017
9018 proc check_effective_target_vect_len_load_store { } {
9019 return [expr { [check_effective_target_has_arch_pwr9]
9020 || [check_effective_target_s390_vx]
9021 || [check_effective_target_riscv_v] }]
9022 }
9023
9024 # Return the value of parameter vect-partial-vector-usage specified for
9025 # target by checking the output of "-Q --help=params". Return zero if
9026 # the desirable pattern isn't found.
9027
9028 proc check_vect_partial_vector_usage { } {
9029 global tool
9030
9031 return [check_cached_effective_target vect_partial_vector_usage {
9032 set result [check_compile vect_partial_vector_usage assembly {
9033 int i;
9034 } "-Q --help=params" ]
9035
9036 # Get compiler emitted messages and delete generated file.
9037 set lines [lindex $result 0]
9038 set output [lindex $result 1]
9039 remote_file build delete $output
9040
9041 set pattern {=vect-partial-vector-usage=<0,2>\s+([0-2])}
9042 # Capture the usage value to val, set it to zero if not found.
9043 if { ![regexp $pattern $lines whole val] } then {
9044 set val 0
9045 }
9046
9047 return $val
9048 }]
9049 }
9050
9051 # Return true if the target supports loop vectorization with partial vectors
9052 # and @code{vect-partial-vector-usage} is set to 1.
9053
9054 proc check_effective_target_vect_partial_vectors_usage_1 { } {
9055 return [expr { ([check_effective_target_vect_fully_masked]
9056 || [check_effective_target_vect_len_load_store])
9057 && [check_vect_partial_vector_usage] == 1 }]
9058 }
9059
9060 # Return true if the target supports loop vectorization with partial vectors
9061 # and @code{vect-partial-vector-usage} is set to 2.
9062
9063 proc check_effective_target_vect_partial_vectors_usage_2 { } {
9064 return [expr { ([check_effective_target_vect_fully_masked]
9065 || [check_effective_target_vect_len_load_store])
9066 && [check_vect_partial_vector_usage] == 2 }]
9067 }
9068
9069 # Return true if the target supports loop vectorization with partial vectors
9070 # and @code{vect-partial-vector-usage} is nonzero.
9071
9072 proc check_effective_target_vect_partial_vectors { } {
9073 return [expr { ([check_effective_target_vect_fully_masked]
9074 || [check_effective_target_vect_len_load_store])
9075 && [check_vect_partial_vector_usage] != 0 }]
9076 }
9077
9078 # Return 1 if the target doesn't prefer any alignment beyond element
9079 # alignment during vectorization.
9080
9081 proc check_effective_target_vect_element_align_preferred { } {
9082 return [expr { ([check_effective_target_aarch64_sve]
9083 && [check_effective_target_vect_variable_length])
9084 || [check_effective_target_riscv_v] }]
9085 }
9086
9087 # Return true if vectorization of v2qi/v4qi/v8qi/v16qi/v2hi store is enabed.
9088 # Return zero if the desirable pattern isn't found.
9089 # It's used by Warray-bounds/Wstringop-overflow testcases which are
9090 # regressed by O2 vectorization, refer to PR102697/PR102462/PR102706
9091 proc check_vect_slp_store_usage { pattern macro } {
9092 global tool
9093
9094 set result [check_compile slp_aligned_store_usage assembly {
9095 extern void sink (void* );
9096 #define Ac8 (AC8){ 0, 1, 2, 3, 4, 5, 6, 7 }
9097 #define Ac16 (AC16){ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
9098 #ifdef TEST_V16QI
9099 typedef struct AC16 { char a[16]; } AC16;
9100 extern char a16[16];
9101 void
9102 foo1 ()
9103 {
9104 *(AC16*)a16 = Ac16;
9105 }
9106 #elif TEST_V8QI
9107 typedef struct AC8 { char a[8]; } AC8;
9108 extern char a8[8];
9109 void
9110 foo ()
9111 {
9112 *(AC8*)a8 = Ac8;
9113 }
9114 #elif TEST_V4QI
9115 struct A1
9116 {
9117 char n;
9118 char a[3];
9119 };
9120
9121 extern void sink (void*);
9122 void
9123 foo2 ()
9124 {
9125 struct A1 a = { 0, { } };
9126 a.a[0] = 3;
9127 a.a[1] = 4;
9128 a.a[2] = 5;
9129 sink (&a);
9130 }
9131 #elif TEST_V4QI_2
9132 extern char p[4];
9133 void
9134 foo2_2 ()
9135 {
9136 p[0] = 0;
9137 p[1] = 1;
9138 p[2] = 2;
9139 p[3] = 3;
9140 }
9141 #elif TEST_V4QI_3
9142 #define Ac4 (AC4){ 0, 1, 2, 3 }
9143 typedef struct AC4 { char a[4]; } AC4;
9144 extern char a[4];
9145 void
9146 foo ()
9147 {
9148 *(AC4*)a = Ac4;
9149 }
9150 #elif TEST_V2QI
9151 struct A2
9152 {
9153 char a[2];
9154 };
9155 void
9156 foo3 ()
9157 {
9158 struct A2 a;
9159 a.a[0] = 3;
9160 a.a[1] = 4;
9161 sink (&a);
9162 }
9163 #elif TEST_V2QI_2
9164 extern char p[2];
9165 void
9166 foo3_2 ()
9167 {
9168 p[0] = 0;
9169 p[1] = 1;
9170 }
9171 #elif TEST_V4HI
9172 struct Ax
9173 {
9174 int n;
9175 short a[4];
9176 };
9177 void
9178 foo5 (struct Ax *p)
9179 {
9180 p->a[0] = 0;
9181 p->a[1] = 1;
9182 p->a[2] = 2;
9183 p->a[3] = 3;
9184 }
9185 #elif TEST_V2HI
9186 extern char b[4];
9187 void
9188 foo4 ()
9189 {
9190 *(short*) b = 0;
9191 *(short*) (b + 2) = 1;
9192 }
9193 #elif TEST_V2HI_2
9194 struct Ax
9195 {
9196 int n;
9197 short a[2];
9198 };
9199 void
9200 foo4_2 (struct Ax *p)
9201 {
9202 p->a[0] = 0;
9203 p->a[1] = 1;
9204 }
9205 #elif TEST_V4SI
9206 struct A { int i; };
9207 struct B { int j; struct A a[4]; };
9208
9209 struct C
9210 {
9211 struct B b1;
9212 struct B b2;
9213 };
9214 char cbuf2[2 * sizeof (struct C)] = { };
9215 void
9216 foo6 ()
9217 {
9218 struct C *p = (struct C*)&cbuf2;
9219 p->b2.a[0].i = 0;
9220 p->b2.a[1].i = 0;
9221 p->b2.a[2].i = 0;
9222 p->b2.a[3].i = 0;
9223 }
9224 #elif TEST_V2SI
9225 struct A { int i; };
9226 struct B { int j; struct A a[2]; };
9227
9228 struct C
9229 {
9230 struct B b1;
9231 struct B b2;
9232 };
9233 char cbuf2[2 * sizeof (struct C)] = { };
9234 void
9235 foo6 ()
9236 {
9237 struct C *p = (struct C*)&cbuf2;
9238 p->b2.a[0].i = 0;
9239 p->b2.a[1].i = 0;
9240 }
9241
9242 #endif
9243 } "-O2 -fopt-info-all -D$macro" ]
9244
9245 # Get compiler emitted messages and delete generated file.
9246 set lines [lindex $result 0]
9247 set output [lindex $result 1]
9248 remote_file build delete $output
9249
9250 # Check pattern exits in lines, set it to zero if not found.
9251 if { [regexp $pattern $lines] } then {
9252 return 1
9253 }
9254
9255 return 0
9256 }
9257
9258 # Return the true if target support vectorization of 2-byte char stores
9259 # with 2-byte aligned address at plain O2.
9260 # NB: This target should be removed after real issues are fixed for
9261 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9262 # this target since tests in check_vect_slp_store_usage
9263 # is the exact match of relative testcases
9264 proc check_effective_target_vect_slp_v2qi_store_align { } {
9265 set pattern {add new stmt: MEM <vector\(2\) char>}
9266 set macro "TEST_V2QI"
9267 return [check_cached_effective_target vect_slp_v2qi_store_align {
9268 expr [check_vect_slp_store_usage $pattern $macro] }]
9269 }
9270
9271 # Return the true if target support vectorization of 2-byte char stores
9272 # with unaligned address at plain O2.
9273 proc check_effective_target_vect_slp_v2qi_store_unalign { } {
9274 set pattern {add new stmt: MEM <vector\(2\) char>}
9275 set macro "TEST_V2QI_2"
9276 return [check_cached_effective_target vect_slp_v2qi_store_unalign {
9277 expr [check_vect_slp_store_usage $pattern $macro ] }]
9278 }
9279
9280 # Return the true if target support vectorization of 4-byte char stores
9281 # with 4-byte aligned address at plain O2.
9282 # NB: This target should be removed after real issues are fixed for
9283 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9284 # this target since tests in check_vect_slp_store_usage
9285 # is the exact match of relative testcases
9286 proc check_effective_target_vect_slp_v4qi_store_align { } {
9287 set pattern {add new stmt: MEM <vector\(4\) char>}
9288 set macro "TEST_V4QI"
9289 return [check_cached_effective_target vect_slp_v4qi_store_align {
9290 expr [check_vect_slp_store_usage $pattern $macro ] }]
9291 }
9292
9293 # Return the true if target support vectorization of 4-byte char stores
9294 # with unaligned address at plain O2.
9295 proc check_effective_target_vect_slp_v4qi_store_unalign { } {
9296 set pattern {add new stmt: MEM <vector\(4\) char>}
9297 set macro "TEST_V4QI_2"
9298 return [check_cached_effective_target vect_slp_v4qi_store_unalign {
9299 expr [check_vect_slp_store_usage $pattern $macro ] }]
9300 }
9301
9302 # Return the true if target support block move for
9303 # 8-byte aligned 4-byte size struct initialization.
9304 proc check_effective_target_struct_4char_block_move { } {
9305 set pattern {not vectorized: more than one data ref in stmt:}
9306 set macro "TEST_V4QI_3"
9307 return [check_cached_effective_target struct_4char_block_move {
9308 expr [check_vect_slp_store_usage $pattern $macro ] }]
9309 }
9310
9311 # Return the true if target support vectorization of 4-byte char stores
9312 # with unaligned address or store them with a constant pool at plain O2.
9313 proc check_effective_target_vect_slp_v4qi_store_unalign_1 { } {
9314 set pattern {add new stmt: MEM <vector\(4\) char>}
9315 set macro "TEST_V4QI_3"
9316 return [check_cached_effective_target vect_slp_v4qi_store_unalign_1 {
9317 expr { [check_vect_slp_store_usage $pattern $macro ]
9318 || [check_effective_target_struct_4char_block_move] } }]
9319 }
9320
9321 # Return the true if target support block move for
9322 # 8-byte aligned 8-byte size struct initialization.
9323 proc check_effective_target_struct_8char_block_move { } {
9324 set pattern {not vectorized: more than one data ref in stmt:}
9325 set macro "TEST_V8QI"
9326 return [check_cached_effective_target struct_8char_block_move {
9327 expr [check_vect_slp_store_usage $pattern $macro ] }]
9328 }
9329
9330 # Return the true if target support vectorization of 8-byte char stores
9331 # with unaligned address or store them with a constant pool at plain O2.
9332 # NB: This target should be removed after real issues are fixed for
9333 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9334 # this target since tests in check_vect_slp_store_usage
9335 # is the exact match of relative testcases
9336 proc check_effective_target_vect_slp_v8qi_store_unalign_1 { } {
9337 set pattern {add new stmt: MEM <vector\(8\) char>}
9338 set macro "TEST_V8QI"
9339 return [check_cached_effective_target vect_slp_v8qi_store_unalign_1 {
9340 expr { [check_vect_slp_store_usage $pattern $macro ]
9341 || [check_effective_target_struct_8char_block_move] } }]
9342 }
9343
9344 # Return the true if target support block move for
9345 # 8-byte aligned 16-byte size struct initialization.
9346 proc check_effective_target_struct_16char_block_move { } {
9347 set pattern {not vectorized: more than one data ref in stmt:}
9348 set macro "TEST_V16QI"
9349 return [check_cached_effective_target struct_16char_block_move {
9350 expr [check_vect_slp_store_usage $pattern $macro ] }]
9351 }
9352
9353 # Return the true if target support vectorization of 16-byte char stores
9354 # with unaligned address or store them with a constant pool at plain O2.
9355 # NB: This target should be removed after real issues are fixed for
9356 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9357 # this target since tests in check_vect_slp_store_usage
9358 # is the exact match of relative testcases
9359 proc check_effective_target_vect_slp_v16qi_store_unalign_1 { } {
9360 set pattern {add new stmt: MEM <vector\(16\) char>}
9361 set macro "TEST_V16QI"
9362 return [check_cached_effective_target vect_slp_v16qi_store_unalign_1 {
9363 expr { [check_vect_slp_store_usage $pattern $macro ]
9364 || [check_effective_target_struct_16char_block_move] } }]
9365 }
9366
9367 # Return the true if target support vectorization of 4-byte short stores
9368 # with unaligned address at plain O2.
9369 # NB: This target should be removed after real issues are fixed for
9370 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9371 # this target since tests in check_vect_slp_store_usage
9372 # is the exact match of relative testcases
9373 proc check_effective_target_vect_slp_v2hi_store_unalign { } {
9374 set pattern {add new stmt: MEM <vector\(2\) short int>}
9375 set macro "TEST_V2HI"
9376 return [check_cached_effective_target vect_slp_v2hi_store_unalign {
9377 expr [check_vect_slp_store_usage $pattern $macro ] }]
9378 }
9379
9380 # Return the true if target support vectorization of 4-byte short stores
9381 # with 4-byte aligned address at plain O2.
9382 proc check_effective_target_vect_slp_v2hi_store_align { } {
9383 set pattern {add new stmt: MEM <vector\(2\) short int>}
9384 set macro "TEST_V2HI_2"
9385 return [check_cached_effective_target vect_slp_v2hi_store_align {
9386 expr [check_vect_slp_store_usage $pattern $macro ] }]
9387 }
9388
9389 # Return the true if target support vectorization of 8-byte short stores
9390 # with unaligned address at plain O2.
9391 # NB: This target should be removed after real issues are fixed for
9392 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9393 # this target since tests in check_vect_slp_store_usage
9394 # is the exact match of relative testcases
9395 proc check_effective_target_vect_slp_v4hi_store_unalign { } {
9396 set pattern {add new stmt: MEM <vector\(4\) short int>}
9397 set macro "TEST_V4HI"
9398 return [check_cached_effective_target vect_slp_v4hi_store_unalign {
9399 expr [check_vect_slp_store_usage $pattern $macro ] }]
9400 }
9401
9402 # Return the true if target support vectorization of 8-byte int stores
9403 # with 8-byte aligned address at plain O2.
9404 # NB: This target should be removed after real issues are fixed for
9405 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9406 # this target since tests in check_vect_slp_store_usage
9407 # is the exact match of relative testcases
9408 proc check_effective_target_vect_slp_v2si_store_align { } {
9409 set pattern {add new stmt: MEM <vector\(2\) int>}
9410 set macro "TEST_V2SI"
9411 return [check_cached_effective_target vect_slp_v2si_store_align {
9412 expr [check_vect_slp_store_usage $pattern $macro ] }]
9413 }
9414
9415 # Return the true if target support vectorization of 16-byte int stores
9416 # with unaligned address at plain O2.
9417 # NB: This target should be removed after real issues are fixed for
9418 # -Wstringop-overflow with O2 vect. Be careful if you want to reuse
9419 # this target since tests in check_vect_slp_store_usage
9420 # is the exact match of relative testcases
9421 proc check_effective_target_vect_slp_v4si_store_unalign { } {
9422 set pattern {add new stmt: MEM <vector\(4\) int>}
9423 set macro "TEST_V4SI"
9424 return [check_cached_effective_target vect_slp_v4si_store_unalign {
9425 expr [check_vect_slp_store_usage $pattern $macro ] }]
9426 }
9427
9428 # Return 1 if we can align stack data to the preferred vector alignment.
9429
9430 proc check_effective_target_vect_align_stack_vars { } {
9431 if { [check_effective_target_aarch64_sve] } {
9432 return [check_effective_target_vect_variable_length]
9433 }
9434 return 1
9435 }
9436
9437 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
9438
9439 proc check_effective_target_vector_alignment_reachable { } {
9440 set et_vector_alignment_reachable 0
9441 if { [check_effective_target_vect_aligned_arrays]
9442 || [check_effective_target_natural_alignment_32] } {
9443 set et_vector_alignment_reachable 1
9444 }
9445 verbose "check_effective_target_vector_alignment_reachable:\
9446 returning $et_vector_alignment_reachable" 2
9447 return $et_vector_alignment_reachable
9448 }
9449
9450 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
9451
9452 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
9453 set et_vector_alignment_reachable_for_64bit 0
9454 if { [check_effective_target_vect_aligned_arrays]
9455 || [check_effective_target_natural_alignment_64] } {
9456 set et_vector_alignment_reachable_for_64bit 1
9457 }
9458 verbose "check_effective_target_vector_alignment_reachable_for_64bit:\
9459 returning $et_vector_alignment_reachable_for_64bit" 2
9460 return $et_vector_alignment_reachable_for_64bit
9461 }
9462
9463 # Return 1 if the target only requires element alignment for vector accesses
9464
9465 proc check_effective_target_vect_element_align { } {
9466 return [check_cached_effective_target_indexed vect_element_align {
9467 expr { ([istarget arm*-*-*]
9468 && ![check_effective_target_arm_vect_no_misalign])
9469 || [check_effective_target_vect_hw_misalign] }}]
9470 }
9471
9472 # Return 1 if we expect to see unaligned accesses in at least some
9473 # vector dumps.
9474
9475 proc check_effective_target_vect_unaligned_possible { } {
9476 return [expr { ![check_effective_target_vect_element_align_preferred]
9477 && (![check_effective_target_vect_no_align]
9478 || [check_effective_target_vect_hw_misalign]) }]
9479 }
9480
9481 # Return 1 if the target supports vector LOAD_LANES operations, 0 otherwise.
9482
9483 proc check_effective_target_vect_load_lanes { } {
9484 # We don't support load_lanes correctly on big-endian arm.
9485 return [check_cached_effective_target vect_load_lanes {
9486 expr { ([check_effective_target_arm_little_endian]
9487 && [check_effective_target_arm_neon_ok])
9488 || [istarget aarch64*-*-*]
9489 || [istarget riscv*-*-*] }}]
9490 }
9491
9492 # Return 1 if the target supports vector masked loads.
9493
9494 proc check_effective_target_vect_masked_load { } {
9495 return [expr { [check_avx_available]
9496 || [check_effective_target_aarch64_sve]
9497 || [istarget amdgcn*-*-*]
9498 || [check_effective_target_riscv_v] } ]
9499 }
9500
9501 # Return 1 if the target supports vector masked stores.
9502
9503 proc check_effective_target_vect_masked_store { } {
9504 return [expr { [check_avx_available]
9505 || [check_effective_target_aarch64_sve]
9506 || [istarget amdgcn*-*-*]
9507 || [check_effective_target_riscv_v] }]
9508 }
9509
9510 # Return 1 if the target supports vector gather loads via internal functions.
9511
9512 proc check_effective_target_vect_gather_load_ifn { } {
9513 return [expr { [check_effective_target_aarch64_sve]
9514 || [istarget amdgcn*-*-*]
9515 || [check_effective_target_riscv_v] }]
9516 }
9517
9518 # Return 1 if the target supports vector scatter stores.
9519
9520 proc check_effective_target_vect_scatter_store { } {
9521 return [expr { [check_effective_target_aarch64_sve]
9522 || [istarget amdgcn*-*-*]
9523 || [check_effective_target_riscv_v]
9524 || [check_effective_target_loongarch_sx] }]
9525 }
9526
9527 # Return 1 if the target supports vector conditional operations, 0 otherwise.
9528
9529 proc check_effective_target_vect_condition { } {
9530 return [check_cached_effective_target_indexed vect_condition {
9531 expr { [istarget aarch64*-*-*]
9532 || [istarget powerpc*-*-*]
9533 || [istarget ia64-*-*]
9534 || [check_effective_target_x86]
9535 || ([istarget mips*-*-*]
9536 && [et-is-effective-target mips_msa])
9537 || [check_effective_target_arm_neon_ok]
9538 || ([istarget s390*-*-*]
9539 && [check_effective_target_s390_vx])
9540 || [istarget amdgcn-*-*]
9541 || ([istarget riscv*-*-*]
9542 && [check_effective_target_riscv_v])
9543 || ([istarget loongarch*-*-*]
9544 && [check_effective_target_loongarch_sx]) }}]
9545 }
9546
9547 # Return 1 if the target supports vector conditional operations where
9548 # the comparison has different type from the lhs, 0 otherwise.
9549
9550 proc check_effective_target_vect_cond_mixed { } {
9551 return [check_cached_effective_target_indexed vect_cond_mixed {
9552 expr { [check_effective_target_x86]
9553 || [istarget aarch64*-*-*]
9554 || [istarget powerpc*-*-*]
9555 || [check_effective_target_arm_neon_ok]
9556 || ([istarget mips*-*-*]
9557 && [et-is-effective-target mips_msa])
9558 || ([istarget s390*-*-*]
9559 && [check_effective_target_s390_vx])
9560 || [istarget amdgcn-*-*]
9561 || ([istarget riscv*-*-*]
9562 && [check_effective_target_riscv_v])
9563 || ([istarget loongarch*-*-*]
9564 && [check_effective_target_loongarch_sx]) }}]
9565 }
9566
9567 # Return 1 if the target supports vector char multiplication, 0 otherwise.
9568
9569 proc check_effective_target_vect_char_mult { } {
9570 return [check_cached_effective_target_indexed vect_char_mult {
9571 expr { [istarget aarch64*-*-*]
9572 || [istarget ia64-*-*]
9573 || [check_effective_target_x86]
9574 || [check_effective_target_arm32]
9575 || [check_effective_target_powerpc_altivec]
9576 || ([istarget mips*-*-*]
9577 && [et-is-effective-target mips_msa])
9578 || ([istarget s390*-*-*]
9579 && [check_effective_target_s390_vx])
9580 || [istarget amdgcn-*-*]
9581 || ([istarget riscv*-*-*]
9582 && [check_effective_target_riscv_v])
9583 || ([istarget loongarch*-*-*]
9584 && [check_effective_target_loongarch_sx]) }}]
9585 }
9586
9587 # Return 1 if the target supports vector short multiplication, 0 otherwise.
9588
9589 proc check_effective_target_vect_short_mult { } {
9590 return [check_cached_effective_target_indexed vect_short_mult {
9591 expr { [istarget ia64-*-*]
9592 || [check_effective_target_x86]
9593 || [istarget powerpc*-*-*]
9594 || [istarget aarch64*-*-*]
9595 || [check_effective_target_arm32]
9596 || ([istarget mips*-*-*]
9597 && ([et-is-effective-target mips_msa]
9598 || [et-is-effective-target mips_loongson_mmi]))
9599 || ([istarget s390*-*-*]
9600 && [check_effective_target_s390_vx])
9601 || [istarget amdgcn-*-*]
9602 || ([istarget riscv*-*-*]
9603 && [check_effective_target_riscv_v])
9604 || ([istarget loongarch*-*-*]
9605 && [check_effective_target_loongarch_sx]) }}]
9606 }
9607
9608 # Return 1 if the target supports vector int multiplication, 0 otherwise.
9609
9610 proc check_effective_target_vect_int_mult { } {
9611 return [check_cached_effective_target_indexed vect_int_mult {
9612 expr { [istarget powerpc*-*-*]
9613 || [check_effective_target_x86]
9614 || [istarget ia64-*-*]
9615 || [istarget aarch64*-*-*]
9616 || ([istarget mips*-*-*]
9617 && [et-is-effective-target mips_msa])
9618 || [check_effective_target_arm32]
9619 || ([istarget s390*-*-*]
9620 && [check_effective_target_s390_vx])
9621 || [istarget amdgcn-*-*]
9622 || ([istarget riscv*-*-*]
9623 && [check_effective_target_riscv_v])
9624 || ([istarget loongarch*-*-*]
9625 && [check_effective_target_loongarch_sx]) }}]
9626 }
9627
9628 # Return 1 if the target supports 64 bit hardware vector
9629 # multiplication of long operands with a long result, 0 otherwise.
9630 #
9631 # This can change for different subtargets so do not cache the result.
9632
9633 proc check_effective_target_vect_long_mult { } {
9634 if { [check_effective_target_x86]
9635 || ([istarget powerpc*-*-*]
9636 && ([check_effective_target_ilp32]
9637 || ([check_effective_target_powerpc_vsx_ok]
9638 && [check_effective_target_has_arch_pwr10])))
9639 || [is-effective-target arm_neon]
9640 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
9641 || ([istarget aarch64*-*-*]
9642 && ([check_effective_target_ilp32]
9643 || [check_effective_target_aarch64_sve]))
9644 || ([istarget mips*-*-*]
9645 && [et-is-effective-target mips_msa])
9646 || ([istarget riscv*-*-*]
9647 && [check_effective_target_riscv_v])
9648 || ([istarget loongarch*-*-*]
9649 && [check_effective_target_loongarch_sx])
9650 || [istarget amdgcn-*-*] } {
9651 set answer 1
9652 } else {
9653 set answer 0
9654 }
9655
9656 verbose "check_effective_target_vect_long_mult: returning $answer" 2
9657 return $answer
9658 }
9659
9660 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
9661
9662 proc check_effective_target_vect_extract_even_odd { } {
9663 return [check_cached_effective_target_indexed extract_even_odd {
9664 expr { [istarget aarch64*-*-*]
9665 || [istarget powerpc*-*-*]
9666 || [is-effective-target arm_neon]
9667 || [check_effective_target_x86]
9668 || [istarget ia64-*-*]
9669 || ([istarget mips*-*-*]
9670 && ([et-is-effective-target mips_msa]
9671 || [et-is-effective-target mpaired_single]))
9672 || ([istarget s390*-*-*]
9673 && [check_effective_target_s390_vx])
9674 || ([istarget riscv*-*-*]
9675 && [check_effective_target_riscv_v])
9676 || ([istarget loongarch*-*-*]
9677 && [check_effective_target_loongarch_sx]) }}]
9678 }
9679
9680 # Return 1 if the target supports vector interleaving, 0 otherwise.
9681
9682 proc check_effective_target_vect_interleave { } {
9683 return [check_cached_effective_target_indexed vect_interleave {
9684 expr { [istarget aarch64*-*-*]
9685 || [istarget powerpc*-*-*]
9686 || [is-effective-target arm_neon]
9687 || [check_effective_target_x86]
9688 || [istarget ia64-*-*]
9689 || ([istarget mips*-*-*]
9690 && ([et-is-effective-target mpaired_single]
9691 || [et-is-effective-target mips_msa]))
9692 || ([istarget s390*-*-*]
9693 && [check_effective_target_s390_vx])
9694 || ([istarget riscv*-*-*]
9695 && [check_effective_target_riscv_v])
9696 || ([istarget loongarch*-*-*]
9697 && [check_effective_target_loongarch_sx]) }}]
9698 }
9699
9700 foreach N {2 3 4 5 6 7 8} {
9701 eval [string map [list N $N] {
9702 # Return 1 if the target supports 2-vector interleaving
9703 proc check_effective_target_vect_stridedN { } {
9704 return [check_cached_effective_target_indexed vect_stridedN {
9705 if { (N & -N) == N
9706 && [check_effective_target_vect_interleave]
9707 && [check_effective_target_vect_extract_even_odd] } {
9708 return 1
9709 }
9710 if { ([istarget arm*-*-*]
9711 || [istarget aarch64*-*-*]) && N >= 2 && N <= 4 } {
9712 return 1
9713 }
9714 if { ([istarget riscv*-*-*]) && N >= 2 && N <= 8 } {
9715 return 1
9716 }
9717 if [check_effective_target_vect_fully_masked] {
9718 return 1
9719 }
9720 return 0
9721 }]
9722 }
9723 }]
9724 }
9725
9726 # Return the list of vector sizes (in bits) that each target supports.
9727 # A vector length of "0" indicates variable-length vectors.
9728
9729 proc available_vector_sizes { } {
9730 set result {}
9731 if { [istarget aarch64*-*-*] } {
9732 if { [check_effective_target_aarch64_sve] } {
9733 lappend result [aarch64_sve_bits]
9734 }
9735 lappend result 128 64
9736 } elseif { [check_effective_target_arm_neon_ok] } {
9737 lappend result 128 64
9738 } elseif { [check_effective_target_x86] } {
9739 if { [check_avx_available] && ![check_prefer_avx128] } {
9740 lappend result 256
9741 }
9742 lappend result 128
9743 if { ![is-effective-target ia32] } {
9744 lappend result 64
9745 }
9746 lappend result 32
9747 } elseif { [istarget sparc*-*-*] } {
9748 lappend result 64
9749 } elseif { [istarget amdgcn*-*-*] } {
9750 # 6 different lane counts, and 4 element sizes
9751 lappend result 4096 2048 1024 512 256 128 64 32 16 8 4 2
9752 } elseif { [istarget riscv*-*-*] } {
9753 if { [check_effective_target_riscv_v] } {
9754 lappend result 0 32 64 128
9755 }
9756 lappend result 128
9757 } else {
9758 # The traditional default asumption.
9759 lappend result 128
9760 }
9761 return $result
9762 }
9763
9764 # Return 1 if the target supports multiple vector sizes
9765
9766 proc check_effective_target_vect_multiple_sizes { } {
9767 return [expr { [llength [available_vector_sizes]] > 1 }]
9768 }
9769
9770 # Return true if variable-length vectors are supported.
9771
9772 proc check_effective_target_vect_variable_length { } {
9773 return [expr { [lindex [available_vector_sizes] 0] == 0 }]
9774 }
9775
9776 # Return 1 if the target supports vectors of 1024 bits.
9777
9778 proc check_effective_target_vect1024 { } {
9779 return [expr { [lsearch -exact [available_vector_sizes] 1024] >= 0 }]
9780 }
9781
9782 # Return 1 if the target supports vectors of 512 bits.
9783
9784 proc check_effective_target_vect512 { } {
9785 return [expr { [lsearch -exact [available_vector_sizes] 512] >= 0 }]
9786 }
9787
9788 # Return 1 if the target supports vectors of 256 bits.
9789
9790 proc check_effective_target_vect256 { } {
9791 return [expr { [lsearch -exact [available_vector_sizes] 256] >= 0 }]
9792 }
9793
9794 # Return 1 if the target supports vectors of 128 bits.
9795
9796 proc check_effective_target_vect128 { } {
9797 return [expr { [lsearch -exact [available_vector_sizes] 128] >= 0 }]
9798 }
9799
9800 # Return 1 if the target supports vectors of 64 bits.
9801
9802 proc check_effective_target_vect64 { } {
9803 return [expr { [lsearch -exact [available_vector_sizes] 64] >= 0 }]
9804 }
9805
9806 # Return 1 if the target supports vectors of 32 bits.
9807
9808 proc check_effective_target_vect32 { } {
9809 return [expr { [lsearch -exact [available_vector_sizes] 32] >= 0 }]
9810 }
9811
9812 # Return 1 if the target supports vector copysignf calls.
9813
9814 proc check_effective_target_vect_call_copysignf { } {
9815 return [check_cached_effective_target_indexed vect_call_copysignf {
9816 expr { [check_effective_target_x86]
9817 || [istarget powerpc*-*-*]
9818 || [istarget aarch64*-*-*]
9819 || [istarget amdgcn-*-*]
9820 || ([istarget riscv*-*-*]
9821 && [check_effective_target_riscv_v])
9822 || ([istarget loongarch*-*-*]
9823 && [check_effective_target_loongarch_sx]) }}]
9824 }
9825
9826 # Return 1 if the target supports hardware square root instructions.
9827
9828 proc check_effective_target_sqrt_insn { } {
9829 return [check_cached_effective_target sqrt_insn {
9830 expr { [check_effective_target_x86]
9831 || [check_effective_target_powerpc_sqrt]
9832 || [istarget aarch64*-*-*]
9833 || ([istarget arm*-*-*] && [check_effective_target_arm_vfp_ok])
9834 || ([istarget s390*-*-*]
9835 && [check_effective_target_s390_vx])
9836 || [istarget amdgcn-*-*] }}]
9837 }
9838
9839 # Return any additional options to enable square root intructions.
9840
9841 proc add_options_for_sqrt_insn { flags } {
9842 if { [istarget amdgcn*-*-*] } {
9843 return "$flags -ffast-math"
9844 }
9845 if { [istarget arm*-*-*] } {
9846 return [add_options_for_arm_vfp "$flags"]
9847 }
9848 return $flags
9849 }
9850
9851 # Return 1 if the target supports vector sqrtf calls.
9852
9853 proc check_effective_target_vect_call_sqrtf { } {
9854 return [check_cached_effective_target_indexed vect_call_sqrtf {
9855 expr { [istarget aarch64*-*-*]
9856 || [check_effective_target_x86]
9857 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
9858 || ([istarget s390*-*-*]
9859 && [check_effective_target_s390_vx])
9860 || [istarget amdgcn-*-*]
9861 || ([istarget riscv*-*-*]
9862 && [check_effective_target_riscv_v])
9863 || ([istarget loongarch*-*-*]
9864 && [check_effective_target_loongarch_sx]) }}]
9865 }
9866
9867 # Return 1 if the target supports vector lrint calls.
9868
9869 proc check_effective_target_vect_call_lrint { } {
9870 set et_vect_call_lrint 0
9871 if { ([check_effective_target_x86]
9872 && [check_effective_target_ilp32])
9873 || [istarget amdgcn-*-*]
9874 || [istarget loongarch*-*-*] } {
9875 set et_vect_call_lrint 1
9876 }
9877
9878 verbose "check_effective_target_vect_call_lrint: returning $et_vect_call_lrint" 2
9879 return $et_vect_call_lrint
9880 }
9881
9882 # Return 1 if the target supports vector btrunc calls.
9883
9884 proc check_effective_target_vect_call_btrunc { } {
9885 return [check_cached_effective_target_indexed vect_call_btrunc {
9886 expr { [istarget aarch64*-*-*]
9887 || [istarget amdgcn-*-*] }}]
9888 }
9889
9890 # Return 1 if the target supports vector btruncf calls.
9891
9892 proc check_effective_target_vect_call_btruncf { } {
9893 return [check_cached_effective_target_indexed vect_call_btruncf {
9894 expr { [istarget aarch64*-*-*]
9895 || [istarget amdgcn-*-*] }}]
9896 }
9897
9898 # Return 1 if the target supports vector ceil calls.
9899
9900 proc check_effective_target_vect_call_ceil { } {
9901 return [check_cached_effective_target_indexed vect_call_ceil {
9902 expr { [istarget aarch64*-*-*]
9903 || [istarget amdgcn-*-*] }}]
9904 }
9905
9906 # Return 1 if the target supports vector ceilf calls.
9907
9908 proc check_effective_target_vect_call_ceilf { } {
9909 return [check_cached_effective_target_indexed vect_call_ceilf {
9910 expr { [istarget aarch64*-*-*]
9911 || [istarget amdgcn-*-*] }}]
9912 }
9913
9914 # Return 1 if the target supports vector floor calls.
9915
9916 proc check_effective_target_vect_call_floor { } {
9917 return [check_cached_effective_target_indexed vect_call_floor {
9918 expr { [istarget aarch64*-*-*]
9919 || [istarget amdgcn-*-*] }}]
9920 }
9921
9922 # Return 1 if the target supports vector floorf calls.
9923
9924 proc check_effective_target_vect_call_floorf { } {
9925 return [check_cached_effective_target_indexed vect_call_floorf {
9926 expr { [istarget aarch64*-*-*]
9927 || [istarget amdgcn-*-*] }}]
9928 }
9929
9930 # Return 1 if the target supports vector lceil calls.
9931
9932 proc check_effective_target_vect_call_lceil { } {
9933 return [check_cached_effective_target_indexed vect_call_lceil {
9934 expr { [istarget aarch64*-*-*] }}]
9935 }
9936
9937 # Return 1 if the target supports vector lfloor calls.
9938
9939 proc check_effective_target_vect_call_lfloor { } {
9940 return [check_cached_effective_target_indexed vect_call_lfloor {
9941 expr { [istarget aarch64*-*-*] }}]
9942 }
9943
9944 # Return 1 if the target supports vector nearbyint calls.
9945
9946 proc check_effective_target_vect_call_nearbyint { } {
9947 return [check_cached_effective_target_indexed vect_call_nearbyint {
9948 expr { [istarget aarch64*-*-*] }}]
9949 }
9950
9951 # Return 1 if the target supports vector nearbyintf calls.
9952
9953 proc check_effective_target_vect_call_nearbyintf { } {
9954 return [check_cached_effective_target_indexed vect_call_nearbyintf {
9955 expr { [istarget aarch64*-*-*] }}]
9956 }
9957
9958 # Return 1 if the target supports vector round calls.
9959
9960 proc check_effective_target_vect_call_round { } {
9961 return [check_cached_effective_target_indexed vect_call_round {
9962 expr { [istarget aarch64*-*-*] }}]
9963 }
9964
9965 # Return 1 if the target supports vector roundf calls.
9966
9967 proc check_effective_target_vect_call_roundf { } {
9968 return [check_cached_effective_target_indexed vect_call_roundf {
9969 expr { [istarget aarch64*-*-*] }}]
9970 }
9971
9972 # Return 1 if the target supports AND, OR and XOR reduction.
9973
9974 proc check_effective_target_vect_logical_reduc { } {
9975 return [expr { [check_effective_target_aarch64_sve]
9976 || [istarget amdgcn-*-*]
9977 || [check_effective_target_riscv_v]
9978 || [check_effective_target_loongarch_sx]
9979 || [check_effective_target_x86]}]
9980 }
9981
9982 # Return 1 if the target supports the fold_extract_last optab.
9983
9984 proc check_effective_target_vect_fold_extract_last { } {
9985 return [expr { [check_effective_target_aarch64_sve]
9986 || [istarget amdgcn*-*-*]
9987 || [check_effective_target_riscv_v] }]
9988 }
9989
9990 # Return 1 if the target supports section-anchors
9991
9992 proc check_effective_target_section_anchors { } {
9993 return [check_cached_effective_target section_anchors {
9994 expr { [istarget powerpc*-*-*]
9995 || [istarget arm*-*-*]
9996 || [istarget aarch64*-*-*]
9997 || [istarget loongarch*-*-*] }}]
9998 }
9999
10000 # Return 1 if the target supports atomic operations on "int_128" values.
10001
10002 proc check_effective_target_sync_int_128 { } {
10003 return 0
10004 }
10005
10006 # Return 1 if the target supports atomic operations on "int_128" values
10007 # and can execute them.
10008 # This requires support for both compare-and-swap and true atomic loads.
10009
10010 proc check_effective_target_sync_int_128_runtime { } {
10011 return 0
10012 }
10013
10014 # Return 1 if the target supports atomic operations on "long long".
10015 #
10016 # Note: 32bit x86 targets require -march=pentium in dg-options.
10017 # Note: 32bit s390 targets require -mzarch in dg-options.
10018
10019 proc check_effective_target_sync_long_long { } {
10020 if { [check_effective_target_x86]
10021 || [istarget aarch64*-*-*]
10022 || [istarget arm*-*-*]
10023 || [istarget alpha*-*-*]
10024 || ([istarget sparc*-*-*] && [check_effective_target_lp64])
10025 || [istarget s390*-*-*] } {
10026 return 1
10027 } else {
10028 return 0
10029 }
10030 }
10031
10032 # Return 1 if the target supports popcount on long.
10033
10034 proc check_effective_target_popcountl { } {
10035 return [check_no_messages_and_pattern popcountl "!\\(call" rtl-expand {
10036 int foo (long b)
10037 {
10038 return __builtin_popcountl (b);
10039 }
10040 } "" ]
10041 }
10042
10043 # Return 1 if the target supports popcount on long long.
10044
10045 proc check_effective_target_popcountll { } {
10046 return [check_no_messages_and_pattern popcountll "!\\(call" rtl-expand {
10047 int foo (long long b)
10048 {
10049 return __builtin_popcountll (b);
10050 }
10051 } "" ]
10052 }
10053
10054
10055 # Return 1 if the target supports popcount on int.
10056
10057 proc check_effective_target_popcount { } {
10058 return [check_no_messages_and_pattern popcount "!\\(call" rtl-expand {
10059 int foo (int b)
10060 {
10061 return __builtin_popcount (b);
10062 }
10063 } "" ]
10064 }
10065
10066 # Return 1 if the target supports clz on int.
10067
10068 proc check_effective_target_clz { } {
10069 return [check_no_messages_and_pattern clz "!\\(call" rtl-expand {
10070 int foo (int b)
10071 {
10072 return __builtin_clz (b);
10073 }
10074 } "" ]
10075 }
10076
10077 # Return 1 if the target supports clz on long.
10078
10079 proc check_effective_target_clzl { } {
10080 return [check_no_messages_and_pattern clzl "!\\(call" rtl-expand {
10081 int foo (long b)
10082 {
10083 return __builtin_clzl (b);
10084 }
10085 } "" ]
10086 }
10087
10088 # Return 1 if the target supports clz on long long.
10089
10090 proc check_effective_target_clzll { } {
10091 return [check_no_messages_and_pattern clzll "!\\(call" rtl-expand {
10092 int foo (long long b)
10093 {
10094 return __builtin_clzll (b);
10095 }
10096 } "" ]
10097 }
10098
10099 # Return 1 if the target supports ctz on int.
10100
10101 proc check_effective_target_ctz { } {
10102 return [check_no_messages_and_pattern ctz "!\\(call" rtl-expand {
10103 int foo (int b)
10104 {
10105 return __builtin_ctz (b);
10106 }
10107 } "" ]
10108 }
10109
10110 # Return 1 if the target supports ctz on long.
10111
10112 proc check_effective_target_ctzl { } {
10113 return [check_no_messages_and_pattern ctzl "!\\(call" rtl-expand {
10114 int foo (long b)
10115 {
10116 return __builtin_ctzl (b);
10117 }
10118 } "" ]
10119 }
10120
10121 # Return 1 if the target supports ctz on long long.
10122
10123 proc check_effective_target_ctzll { } {
10124 return [check_no_messages_and_pattern ctzll "!\\(call" rtl-expand {
10125 int foo (long long b)
10126 {
10127 return __builtin_ctzll (b);
10128 }
10129 } "" ]
10130 }
10131
10132 # Return 1 if the target supports atomic operations on "long long"
10133 # and can execute them.
10134 #
10135 # Note: 32bit x86 targets require -march=pentium in dg-options.
10136
10137 proc check_effective_target_sync_long_long_runtime { } {
10138 if { ([check_effective_target_x86]
10139 && [check_cached_effective_target sync_long_long_available {
10140 check_runtime_nocache sync_long_long_available {
10141 #include "cpuid.h"
10142 int main ()
10143 {
10144 unsigned int eax, ebx, ecx, edx;
10145 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
10146 return !(edx & bit_CMPXCHG8B);
10147 return 1;
10148 }
10149 } ""
10150 }])
10151 || [istarget aarch64*-*-*]
10152 || [istarget arm*-*-uclinuxfdpiceabi]
10153 || ([istarget arm*-*-linux-*]
10154 && [check_runtime sync_longlong_runtime {
10155 #include <stdlib.h>
10156 int main ()
10157 {
10158 long long l1;
10159
10160 if (sizeof (long long) != 8)
10161 exit (1);
10162
10163 /* Just check for native;
10164 checking for kernel fallback is tricky. */
10165 asm volatile ("ldrexd r0,r1, [%0]"
10166 : : "r" (&l1) : "r0", "r1");
10167 exit (0);
10168 }
10169 } "" ])
10170 || [istarget alpha*-*-*]
10171 || ([istarget sparc*-*-*]
10172 && [check_effective_target_lp64]
10173 && [check_effective_target_ultrasparc_hw])
10174 || ([istarget powerpc*-*-*] && [check_effective_target_lp64]) } {
10175 return 1
10176 } else {
10177 return 0
10178 }
10179 }
10180
10181 # Return 1 if the target supports byte swap instructions.
10182
10183 proc check_effective_target_bswap { } {
10184 return [check_cached_effective_target bswap {
10185 expr { [istarget aarch64*-*-*]
10186 || [istarget alpha*-*-*]
10187 || [check_effective_target_x86]
10188 || [istarget m68k-*-*]
10189 || [istarget powerpc*-*-*]
10190 || [istarget rs6000-*-*]
10191 || [istarget s390*-*-*]
10192 || ([istarget riscv*-*-*]
10193 && [check_no_compiler_messages_nocache riscv_zbb object {
10194 #if __riscv_zbb <= 0
10195 #error ZBB is not enabled
10196 #endif
10197 int i;
10198 } ""])
10199 || ([istarget arm*-*-*]
10200 && [check_no_compiler_messages_nocache arm_v6_or_later object {
10201 #if __ARM_ARCH < 6
10202 #error not armv6 or later
10203 #endif
10204 int i;
10205 } ""]) }}]
10206 }
10207
10208 # Return 1 if the target supports atomic operations on "int" and "long".
10209
10210 proc check_effective_target_sync_int_long { } {
10211 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
10212 # load-reserved/store-conditional instructions.
10213 return [check_cached_effective_target sync_int_long {
10214 expr { [istarget ia64-*-*]
10215 || [check_effective_target_x86]
10216 || [istarget aarch64*-*-*]
10217 || [istarget alpha*-*-*]
10218 || [istarget arm*-*-linux-*]
10219 || [istarget arm*-*-uclinuxfdpiceabi]
10220 || ([istarget arm*-*-*]
10221 && [check_effective_target_arm_acq_rel])
10222 || [istarget bfin*-*linux*]
10223 || [istarget hppa*-*linux*]
10224 || [istarget s390*-*-*]
10225 || [istarget powerpc*-*-*]
10226 || [istarget cris-*-*]
10227 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
10228 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
10229 || [check_effective_target_mips_llsc]
10230 || [istarget nvptx*-*-*]
10231 }}]
10232 }
10233
10234 # Return 1 if the target supports atomic operations on "int" and "long" on
10235 # stack addresses.
10236
10237 proc check_effective_target_sync_int_long_stack { } {
10238 return [check_cached_effective_target sync_int_long_stack {
10239 expr { ![istarget nvptx*-*-*]
10240 && [check_effective_target_sync_int_long]
10241 }}]
10242 }
10243
10244 # Return 1 if the target supports atomic operations on "char" and "short".
10245
10246 proc check_effective_target_sync_char_short { } {
10247 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
10248 # load-reserved/store-conditional instructions.
10249 return [check_cached_effective_target sync_char_short {
10250 expr { [istarget aarch64*-*-*]
10251 || [istarget ia64-*-*]
10252 || [check_effective_target_x86]
10253 || [istarget alpha*-*-*]
10254 || [istarget arm*-*-linux-*]
10255 || [istarget arm*-*-uclinuxfdpiceabi]
10256 || ([istarget arm*-*-*]
10257 && [check_effective_target_arm_acq_rel])
10258 || [istarget hppa*-*linux*]
10259 || [istarget s390*-*-*]
10260 || [istarget powerpc*-*-*]
10261 || [istarget cris-*-*]
10262 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
10263 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
10264 || [istarget loongarch*-*-*]
10265 || ([istarget riscv*-*-*]
10266 && ([check_effective_target_riscv_zalrsc]
10267 || [check_effective_target_riscv_zabha]))
10268 || [check_effective_target_mips_llsc] }}]
10269 }
10270
10271 # Return 1 if thread_fence does not rely on __sync_synchronize
10272 # library function
10273
10274 proc check_effective_target_thread_fence {} {
10275 return [check_no_compiler_messages thread_fence executable {
10276 int main () {
10277 __atomic_thread_fence (__ATOMIC_SEQ_CST);
10278 return 0;
10279 }
10280 } ""]
10281 }
10282
10283 # Return 1 if the target uses a ColdFire FPU.
10284
10285 proc check_effective_target_coldfire_fpu { } {
10286 return [check_no_compiler_messages coldfire_fpu assembly {
10287 #ifndef __mcffpu__
10288 #error !__mcffpu__
10289 #endif
10290 }]
10291 }
10292
10293 # Return true if this is a uClibc target.
10294
10295 proc check_effective_target_uclibc {} {
10296 return [check_no_compiler_messages uclibc object {
10297 #include <features.h>
10298 #if !defined (__UCLIBC__)
10299 #error !__UCLIBC__
10300 #endif
10301 }]
10302 }
10303
10304 # Return true if this is a uclibc target and if the uclibc feature
10305 # described by __$feature__ is not present.
10306
10307 proc check_missing_uclibc_feature {feature} {
10308 return [check_no_compiler_messages $feature object "
10309 #include <features.h>
10310 #if !defined (__UCLIBC) || defined (__${feature}__)
10311 #error FOO
10312 #endif
10313 "]
10314 }
10315
10316 # Return true if this is a Newlib target.
10317
10318 proc check_effective_target_newlib {} {
10319 return [check_no_compiler_messages newlib object {
10320 #include <newlib.h>
10321 }]
10322 }
10323
10324 # Return true if GCC was configured with --enable-newlib-nano-formatted-io
10325 proc check_effective_target_newlib_nano_io { } {
10326 return [check_configured_with "--enable-newlib-nano-formatted-io"]
10327 }
10328
10329 # Some newlib versions don't provide a frexpl and instead depend
10330 # on frexp to implement long double conversions in their printf-like
10331 # functions. This leads to broken results. Detect such versions here.
10332
10333 proc check_effective_target_newlib_broken_long_double_io {} {
10334 if { [is-effective-target newlib] && ![is-effective-target frexpl] } {
10335 return 1
10336 }
10337 return 0
10338 }
10339
10340 # Return true if this is NOT a Bionic target.
10341
10342 proc check_effective_target_non_bionic {} {
10343 return [check_no_compiler_messages non_bionic object {
10344 #include <ctype.h>
10345 #if defined (__BIONIC__)
10346 #error FOO
10347 #endif
10348 }]
10349 }
10350
10351 # Return true if this target has error.h header.
10352
10353 proc check_effective_target_error_h {} {
10354 return [check_no_compiler_messages error_h object {
10355 #include <error.h>
10356 }]
10357 }
10358
10359 # Return true if this target has tgmath.h header.
10360
10361 proc check_effective_target_tgmath_h {} {
10362 return [check_no_compiler_messages tgmath_h object {
10363 #include <tgmath.h>
10364 }]
10365 }
10366
10367 # Return true if target's libc supports complex functions.
10368
10369 proc check_effective_target_libc_has_complex_functions {} {
10370 return [check_no_compiler_messages libc_has_complex_functions object {
10371 #include <complex.h>
10372 }]
10373 }
10374
10375 # Return 1 if
10376 # (a) an error of a few ULP is expected in string to floating-point
10377 # conversion functions; and
10378 # (b) overflow is not always detected correctly by those functions.
10379
10380 proc check_effective_target_lax_strtofp {} {
10381 # By default, assume that all uClibc targets suffer from this.
10382 return [check_effective_target_uclibc]
10383 }
10384
10385 # Return 1 if this is a target for which wcsftime is a dummy
10386 # function that always returns 0.
10387
10388 proc check_effective_target_dummy_wcsftime {} {
10389 # By default, assume that all uClibc targets suffer from this.
10390 return [check_effective_target_uclibc]
10391 }
10392
10393 # Return 1 if constructors with initialization priority arguments are
10394 # supposed on this target.
10395
10396 proc check_effective_target_init_priority {} {
10397 return [check_no_compiler_messages init_priority assembly "
10398 void f() __attribute__((constructor (1000)));
10399 void f() \{\}
10400 "]
10401 }
10402
10403 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
10404 # This can be used with any check_* proc that takes no argument and
10405 # returns only 1 or 0. It could be used with check_* procs that take
10406 # arguments with keywords that pass particular arguments.
10407
10408 proc is-effective-target { arg } {
10409 global et_index
10410 set selected 0
10411 if { ![info exists et_index] } {
10412 # Initialize the effective target index that is used in some
10413 # check_effective_target_* procs.
10414 set et_index 0
10415 }
10416 if { [info procs check_effective_target_${arg}] != [list] } {
10417 set selected [check_effective_target_${arg}]
10418 } else {
10419 switch $arg {
10420 "vmx_hw" { set selected [check_vmx_hw_available] }
10421 "vsx_hw" { set selected [check_vsx_hw_available] }
10422 "p8vector_hw" { set selected [check_p8vector_hw_available] }
10423 "p9vector_hw" { set selected [check_p9vector_hw_available] }
10424 "p9modulo_hw" { set selected [check_p9modulo_hw_available] }
10425 "power10_hw" { set selected [check_power10_hw_available] }
10426 "ppc_float128_sw" { set selected [check_ppc_float128_sw_available] }
10427 "ppc_float128_hw" { set selected [check_ppc_float128_hw_available] }
10428 "ppc_recip_hw" { set selected [check_ppc_recip_hw_available] }
10429 "ppc_cpu_supports_hw" { set selected [check_ppc_cpu_supports_hw_available] }
10430 "ppc_mma_hw" { set selected [check_ppc_mma_hw_available] }
10431 "dfp_hw" { set selected [check_dfp_hw_available] }
10432 "htm_hw" { set selected [check_htm_hw_available] }
10433 "named_sections" { set selected [check_named_sections_available] }
10434 "gc_sections" { set selected [check_gc_sections_available] }
10435 "linker_plugin" { set selected [check_linker_plugin_available] }
10436 "cxa_atexit" { set selected [check_cxa_atexit_available] }
10437 default { error "unknown effective target keyword `$arg'" }
10438 }
10439 }
10440
10441 verbose "is-effective-target: $arg $selected" 2
10442 return $selected
10443 }
10444
10445 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
10446
10447 proc is-effective-target-keyword { arg } {
10448 if { [info procs check_effective_target_${arg}] != [list] } {
10449 return 1
10450 } else {
10451 # These have different names for their check_* procs.
10452 switch $arg {
10453 "vmx_hw" { return 1 }
10454 "vsx_hw" { return 1 }
10455 "p8vector_hw" { return 1 }
10456 "p9vector_hw" { return 1 }
10457 "p9modulo_hw" { return 1 }
10458 "power10_hw" { return 1 }
10459 "ppc_float128_sw" { return 1 }
10460 "ppc_float128_hw" { return 1 }
10461 "ppc_recip_hw" { return 1 }
10462 "ppc_mma_hw" { return 1 }
10463 "dfp_hw" { return 1 }
10464 "htm_hw" { return 1 }
10465 "named_sections" { return 1 }
10466 "gc_sections" { return 1 }
10467 "cxa_atexit" { return 1 }
10468 "ppc_cpu_supports_hw" { return 1 }
10469 default { return 0 }
10470 }
10471 }
10472 }
10473
10474 # Execute tests for all targets in EFFECTIVE_TARGETS list. Set et_index to
10475 # indicate what target is currently being processed. This is for
10476 # the vectorizer tests, e.g. vect_int, to keep track what target supports
10477 # a given feature.
10478
10479 proc et-dg-runtest { runtest testcases flags default-extra-flags } {
10480 global dg-do-what-default
10481 global EFFECTIVE_TARGETS
10482 global et_index
10483
10484 if { [llength $EFFECTIVE_TARGETS] > 0 } {
10485 foreach target $EFFECTIVE_TARGETS {
10486 set target_flags $flags
10487 set dg-do-what-default compile
10488 set et_index [lsearch -exact $EFFECTIVE_TARGETS $target]
10489 if { [info procs add_options_for_${target}] != [list] } {
10490 set target_flags [add_options_for_${target} "$flags"]
10491 }
10492 if { [info procs check_effective_target_${target}_runtime]
10493 != [list] && [check_effective_target_${target}_runtime] } {
10494 set dg-do-what-default run
10495 }
10496 $runtest $testcases $target_flags ${default-extra-flags}
10497 }
10498 } else {
10499 set et_index 0
10500 $runtest $testcases $flags ${default-extra-flags}
10501 }
10502 }
10503
10504 # Return 1 if a target matches the target in EFFECTIVE_TARGETS at index
10505 # et_index, 0 otherwise.
10506
10507 proc et-is-effective-target { target } {
10508 global EFFECTIVE_TARGETS
10509 global et_index
10510
10511 if { [info exists EFFECTIVE_TARGETS] } {
10512 if { [llength $EFFECTIVE_TARGETS] > $et_index
10513 && [lindex $EFFECTIVE_TARGETS $et_index] == $target } {
10514 return 1
10515 } else {
10516 return 0
10517 }
10518 } else {
10519 return [check_effective_target_${target}]
10520 }
10521 }
10522
10523 # Return 1 if target default to short enums
10524
10525 proc check_effective_target_short_enums { } {
10526 return [check_no_compiler_messages short_enums assembly {
10527 enum foo { bar };
10528 int s[sizeof (enum foo) == 1 ? 1 : -1];
10529 }]
10530 }
10531
10532 # Return 1 if target supports merging string constants at link time.
10533
10534 proc check_effective_target_string_merging { } {
10535 return [check_no_messages_and_pattern string_merging \
10536 "rodata\\.str" assembly {
10537 const char *var = "String";
10538 } {-O2}]
10539 }
10540
10541 # Return 1 if target has the basic signed and unsigned types in
10542 # <stdint.h>, 0 otherwise. This will be obsolete when GCC ensures a
10543 # working <stdint.h> for all targets.
10544
10545 proc check_effective_target_stdint_types { } {
10546 return [check_no_compiler_messages stdint_types assembly {
10547 #include <stdint.h>
10548 int8_t a; int16_t b; int32_t c; int64_t d;
10549 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
10550 }]
10551 }
10552
10553 # Like check_effective_target_stdint_types, but test what happens when
10554 # -mbig-endian is passed. This test only makes sense on targets that
10555 # support -mbig-endian; it will fail elsewhere.
10556
10557 proc check_effective_target_stdint_types_mbig_endian { } {
10558 return [check_no_compiler_messages stdint_types_mbig_endian assembly {
10559 #include <stdint.h>
10560 int8_t a; int16_t b; int32_t c; int64_t d;
10561 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
10562 } "-mbig-endian"]
10563 }
10564
10565 # Return 1 if target has the basic signed and unsigned types in
10566 # <inttypes.h>, 0 otherwise. This is for tests that GCC's notions of
10567 # these types agree with those in the header, as some systems have
10568 # only <inttypes.h>.
10569
10570 proc check_effective_target_inttypes_types { } {
10571 return [check_no_compiler_messages inttypes_types assembly {
10572 #include <inttypes.h>
10573 int8_t a; int16_t b; int32_t c; int64_t d;
10574 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
10575 }]
10576 }
10577
10578 # Return 1 if programs are intended to be run on a simulator
10579 # (i.e. slowly) rather than hardware (i.e. fast).
10580
10581 proc check_effective_target_simulator { } {
10582
10583 # All "src/sim" simulators set this one.
10584 if [board_info target exists is_simulator] {
10585 return [board_info target is_simulator]
10586 }
10587
10588 # The "sid" simulators don't set that one, but at least they set
10589 # this one.
10590 if [board_info target exists slow_simulator] {
10591 return [board_info target slow_simulator]
10592 }
10593
10594 return 0
10595 }
10596
10597 # Return 1 if programs are intended to be run on hardware rather than
10598 # on a simulator
10599
10600 proc check_effective_target_hw { } {
10601
10602 # All "src/sim" simulators set this one.
10603 if [board_info target exists is_simulator] {
10604 if [board_info target is_simulator] {
10605 return 0
10606 } else {
10607 return 1
10608 }
10609 }
10610
10611 # The "sid" simulators don't set that one, but at least they set
10612 # this one.
10613 if [board_info target exists slow_simulator] {
10614 if [board_info target slow_simulator] {
10615 return 0
10616 } else {
10617 return 1
10618 }
10619 }
10620
10621 return 1
10622 }
10623
10624 # Return 1 if the target is a VxWorks kernel.
10625
10626 proc check_effective_target_vxworks_kernel { } {
10627 return [check_no_compiler_messages vxworks_kernel assembly {
10628 #if !defined __vxworks || defined __RTP__
10629 #error NO
10630 #endif
10631 }]
10632 }
10633
10634 # Return 1 if the target is a VxWorks RTP.
10635
10636 proc check_effective_target_vxworks_rtp { } {
10637 return [check_no_compiler_messages vxworks_rtp assembly {
10638 #if !defined __vxworks || !defined __RTP__
10639 #error NO
10640 #endif
10641 }]
10642 }
10643
10644 # Return 1 if the target is expected to provide wide character support.
10645
10646 proc check_effective_target_wchar { } {
10647 if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
10648 return 0
10649 }
10650 return [check_no_compiler_messages wchar assembly {
10651 #include <wchar.h>
10652 }]
10653 }
10654
10655 # Return 1 if the target has <pthread.h>.
10656
10657 proc check_effective_target_pthread_h { } {
10658 return [check_no_compiler_messages pthread_h assembly {
10659 #include <pthread.h>
10660 }]
10661 }
10662
10663 # Return 1 if the target can truncate a file from a file-descriptor,
10664 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
10665 # chsize. We test for a trivially functional truncation; no stubs.
10666 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
10667 # different function to be used.
10668
10669 proc check_effective_target_fd_truncate { } {
10670 set prog {
10671 #define _FILE_OFFSET_BITS 64
10672 #include <unistd.h>
10673 #include <stdio.h>
10674 #include <stdlib.h>
10675 #include <string.h>
10676 int main ()
10677 {
10678 FILE *f = fopen ("tst.tmp", "wb");
10679 int fd;
10680 const char t[] = "test writing more than ten characters";
10681 char s[11];
10682 int status = 0;
10683 fd = fileno (f);
10684 write (fd, t, sizeof (t) - 1);
10685 lseek (fd, 0, 0);
10686 if (ftruncate (fd, 10) != 0)
10687 status = 1;
10688 close (fd);
10689 fclose (f);
10690 if (status)
10691 {
10692 unlink ("tst.tmp");
10693 exit (status);
10694 }
10695 f = fopen ("tst.tmp", "rb");
10696 if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
10697 status = 1;
10698 fclose (f);
10699 unlink ("tst.tmp");
10700 exit (status);
10701 }
10702 }
10703
10704 if { [check_runtime ftruncate $prog] } {
10705 return 1;
10706 }
10707
10708 regsub "ftruncate" $prog "chsize" prog
10709 return [check_runtime chsize $prog]
10710 }
10711
10712 # Add to FLAGS all the target-specific flags needed to enable
10713 # full IEEE compliance mode.
10714
10715 proc add_options_for_ieee { flags } {
10716 if { [istarget alpha*-*-*]
10717 || [istarget sh*-*-*] } {
10718 return "$flags -mieee"
10719 }
10720 if { [istarget rx-*-*] } {
10721 return "$flags -mnofpu"
10722 }
10723 return $flags
10724 }
10725
10726 if {![info exists flags_to_postpone]} {
10727 set flags_to_postpone ""
10728 }
10729
10730 # Add to FLAGS the flags needed to enable functions to bind locally
10731 # when using pic/PIC passes in the testsuite.
10732 proc add_options_for_bind_pic_locally { flags } {
10733 global flags_to_postpone
10734
10735 # Instead of returning 'flags' with the -fPIE or -fpie appended, we save it
10736 # in 'flags_to_postpone' and append it later in gcc_target_compile procedure in
10737 # order to make sure that the multilib_flags doesn't override this.
10738
10739 if {[check_no_compiler_messages using_pic2 assembly {
10740 #if __PIC__ != 2
10741 #error __PIC__ != 2
10742 #endif
10743 }]} {
10744 set flags_to_postpone "-fPIE"
10745 return $flags
10746 }
10747 if {[check_no_compiler_messages using_pic1 assembly {
10748 #if __PIC__ != 1
10749 #error __PIC__ != 1
10750 #endif
10751 }]} {
10752 set flags_to_postpone "-fpie"
10753 return $flags
10754 }
10755 return $flags
10756 }
10757
10758 # Add to FLAGS the flags needed to enable 64-bit vectors.
10759
10760 proc add_options_for_double_vectors { flags } {
10761 if [is-effective-target arm_neon_ok] {
10762 return "$flags -mvectorize-with-neon-double"
10763 }
10764
10765 return $flags
10766 }
10767
10768 # Add to FLAGS the flags needed to define the STACK_SIZE macro.
10769
10770 proc add_options_for_stack_size { flags } {
10771 if [is-effective-target stack_size] {
10772 set stack_size [dg-effective-target-value stack_size]
10773 return "$flags -DSTACK_SIZE=$stack_size"
10774 }
10775
10776 return $flags
10777 }
10778
10779 # Return 1 if the target provides a full C99 runtime.
10780
10781 proc check_effective_target_c99_runtime { } {
10782 return [check_cached_effective_target c99_runtime {
10783 global srcdir
10784
10785 set file [open "$srcdir/gcc.dg/builtins-config.h"]
10786 set contents [read $file]
10787 close $file
10788 append contents {
10789 #ifndef HAVE_C99_RUNTIME
10790 #error !HAVE_C99_RUNTIME
10791 #endif
10792 }
10793 check_no_compiler_messages_nocache c99_runtime assembly $contents
10794 }]
10795 }
10796
10797 # Return 1 if the target supports DWARF CFI directives.
10798
10799 proc check_effective_target_cfi { } {
10800 return [check_no_compiler_messages cfi assembly {
10801 #ifdef __GCC_HAVE_DWARF2_CFI_ASM
10802 /* ok */
10803 #else
10804 #error unsupported
10805 #endif
10806 } ""]
10807 }
10808
10809 # Return 1 if the target provides the D runtime.
10810
10811 proc check_effective_target_d_runtime { } {
10812 return [check_no_compiler_messages d_runtime executable {
10813 // D
10814 module mod;
10815
10816 extern(C) int main() {
10817 return 0;
10818 }
10819 }]
10820 }
10821
10822 # Return 1 if the target provides the D standard library.
10823
10824 proc check_effective_target_d_runtime_has_std_library { } {
10825 return [check_no_compiler_messages d_runtime_has_std_library executable {
10826 // D
10827 module mod;
10828
10829 extern(C) int main() {
10830 import std.math;
10831 real function(real) pcos = &cos;
10832 return 0;
10833 }
10834 }]
10835 }
10836
10837 # Return 1 if target wchar_t is at least 4 bytes.
10838
10839 proc check_effective_target_4byte_wchar_t { } {
10840 return [check_no_compiler_messages 4byte_wchar_t object {
10841 int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
10842 }]
10843 }
10844
10845 # Return 1 if the target supports automatic stack alignment.
10846
10847 proc check_effective_target_automatic_stack_alignment { } {
10848 # Ordinarily x86 supports automatic stack alignment ...
10849 if { [check_effective_target_x86] } then {
10850 if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
10851 # ... except Win64 SEH doesn't. Succeed for Win32 though.
10852 return [check_effective_target_ilp32];
10853 }
10854 return 1;
10855 }
10856 return 0;
10857 }
10858
10859 # Return true if we are compiling for AVX target.
10860
10861 proc check_avx_available { } {
10862 if { [check_no_compiler_messages avx_available assembly {
10863 #ifndef __AVX__
10864 #error unsupported
10865 #endif
10866 } ""] } {
10867 return 1;
10868 }
10869 return 0;
10870 }
10871
10872 # Return true if we are compiling for AVX2 target.
10873
10874 proc check_avx2_available { } {
10875 if { [check_no_compiler_messages avx2_available assembly {
10876 #ifndef __AVX2__
10877 #error unsupported
10878 #endif
10879 } ""] } {
10880 return 1;
10881 }
10882 return 0;
10883 }
10884
10885 # Return true if we are compiling for SSSE3 target.
10886
10887 proc check_ssse3_available { } {
10888 if { [check_no_compiler_messages sse3a_available assembly {
10889 #ifndef __SSSE3__
10890 #error unsupported
10891 #endif
10892 } ""] } {
10893 return 1;
10894 }
10895 return 0;
10896 }
10897
10898 # Return true if 32- and 16-bytes vectors are available.
10899
10900 proc check_effective_target_vect_sizes_32B_16B { } {
10901 return [expr { [available_vector_sizes] == [list 256 128] }]
10902 }
10903
10904 # Return true if 16- and 8-bytes vectors are available.
10905
10906 proc check_effective_target_vect_sizes_16B_8B { } {
10907 if { [check_avx_available]
10908 || [is-effective-target arm_neon]
10909 || [istarget aarch64*-*-*]
10910 || [check_effective_target_riscv_v] } {
10911 return 1;
10912 } else {
10913 return 0;
10914 }
10915 }
10916
10917
10918 # Return true if 128-bits vectors are preferred even if 256-bits vectors
10919 # are available.
10920
10921 proc check_prefer_avx128 { } {
10922 if ![check_avx_available] {
10923 return 0;
10924 }
10925 return [check_no_messages_and_pattern avx_explicit "xmm" assembly {
10926 float a[1024],b[1024],c[1024];
10927 void foo (void) { int i; for (i = 0; i < 1024; i++) a[i]=b[i]+c[i];}
10928 } "-O2 -ftree-vectorize"]
10929 }
10930
10931
10932 # Return 1 if avx512fp16 instructions can be compiled.
10933
10934 proc check_effective_target_avx512fp16 { } {
10935 return [check_no_compiler_messages avx512fp16 object {
10936 void foo (void)
10937 {
10938 asm volatile ("vmovw %edi, %xmm0");
10939 asm volatile ("vfcmulcph %xmm1, %xmm2, %xmm3{%k1}");
10940 }
10941 } "-O2 -mavx512fp16" ]
10942 }
10943
10944 # Return 1 if avx512f instructions can be compiled.
10945
10946 proc check_effective_target_avx512f { } {
10947 return [check_no_compiler_messages avx512f object {
10948 typedef double __m512d __attribute__ ((__vector_size__ (64)));
10949 typedef double __m128d __attribute__ ((__vector_size__ (16)));
10950
10951 __m512d _mm512_add (__m512d a)
10952 {
10953 return __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
10954 }
10955
10956 __m128d _mm128_add (__m128d a)
10957 {
10958 return __builtin_ia32_addsd_round (a, a, 8);
10959 }
10960
10961 __m128d _mm128_getmant (__m128d a)
10962 {
10963 return __builtin_ia32_getmantsd_round (a, a, 0, 8);
10964 }
10965 } "-O2 -mavx512f" ]
10966 }
10967
10968 # Return 1 if avx instructions can be compiled.
10969
10970 proc check_effective_target_avx { } {
10971 if { ![check_effective_target_x86] } {
10972 return 0
10973 }
10974 return [check_no_compiler_messages avx object {
10975 void _mm256_zeroall (void)
10976 {
10977 __builtin_ia32_vzeroall ();
10978 }
10979 } "-O2 -mavx" ]
10980 }
10981
10982 # Return 1 if avx2 instructions can be compiled.
10983 proc check_effective_target_avx2 { } {
10984 return [check_no_compiler_messages avx2 object {
10985 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
10986 __v4di
10987 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
10988 {
10989 return __builtin_ia32_andnotsi256 (__X, __Y);
10990 }
10991 } "-O0 -mavx2" ]
10992 }
10993
10994 # Return 1 if avxvnni instructions can be compiled.
10995 proc check_effective_target_avxvnni { } {
10996 return [check_no_compiler_messages avxvnni object {
10997 typedef int __v8si __attribute__ ((__vector_size__ (32)));
10998 __v8si
10999 _mm256_dpbusd_epi32 (__v8si __A, __v8si __B, __v8si __C)
11000 {
11001 return __builtin_ia32_vpdpbusd_v8si (__A, __B, __C);
11002 }
11003 } "-mavxvnni" ]
11004 }
11005
11006 # Return 1 if avxifma instructions can be compiled.
11007 proc check_effective_target_avxifma { } {
11008 return [check_no_compiler_messages avxifma object {
11009 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
11010 __v4di
11011 _mm256_maddlo_epu64 (__v4di __A, __v4di __B, __v4di __C)
11012 {
11013 return __builtin_ia32_vpmadd52luq256 (__A, __B, __C);
11014 }
11015 } "-O0 -mavxifma" ]
11016 }
11017
11018 # Return 1 if avxvnniint8 instructions can be compiled.
11019 proc check_effective_target_avxvnniint8 { } {
11020 return [check_no_compiler_messages avxvnniint8 object {
11021 typedef int __v8si __attribute__ ((__vector_size__ (32)));
11022 __v8si
11023 _mm256_dpbssd_epi32 (__v8si __A, __v8si __B, __v8si __C)
11024 {
11025 return __builtin_ia32_vpdpbssd256 (__A, __B, __C);
11026 }
11027 } "-O0 -mavxvnniint8" ]
11028 }
11029
11030 # Return 1 if avxneconvert instructions can be compiled.
11031 proc check_effective_target_avxneconvert { } {
11032 return [check_no_compiler_messages avxneconvert object {
11033 typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
11034 __m128
11035 _mm_bcstnebf16_ps (const void *__P)
11036 {
11037 return (__m128) __builtin_ia32_vbcstnebf162ps128 ((const __bf16 *) __P);
11038 }
11039 } "-O0 -mavxneconvert" ]
11040 }
11041
11042 # Return 1 if cmpccxadd instructions can be compiled.
11043 proc check_effective_target_cmpccxadd { } {
11044 return [check_no_compiler_messages cmpccxadd object {
11045 int _cmpccxadd_epi32 (int *__A, int __B, int __C, const int __D)
11046 {
11047 return (int)__builtin_ia32_cmpccxadd (__A, __B, __C, 1);
11048 }
11049 } "-mcmpccxadd" ]
11050 }
11051
11052 # Return 1 if raoint instructions can be compiled.
11053 proc check_effective_target_raoint { } {
11054 return [check_no_compiler_messages raoint object {
11055 void
11056 _aadd_si32 (int *__A, int __B)
11057 {
11058 return __builtin_ia32_aadd32((int *)__A, __B);
11059 }
11060 } "-mraoint" ]
11061 }
11062
11063 # Return 1 if amx-complex instructions can be compiled.
11064 proc check_effective_target_amx_complex { } {
11065 return [check_no_compiler_messages amx_complex object {
11066 void
11067 foo ()
11068 {
11069 __asm__ volatile ("tcmmimfp16ps\t%%tmm1, %%tmm2, %%tmm3" ::);
11070 }
11071 } "-mamx-complex" ]
11072 }
11073
11074 # Return 1 if avxvnniint16 instructions can be compiled.
11075 proc check_effective_target_avxvnniint16 { } {
11076 return [check_no_compiler_messages avxvnniint16 object {
11077 typedef int __v8si __attribute__ ((__vector_size__ (32)));
11078 __v8si
11079 _mm256_dpwsud_avx_epi32 (__v8si __A, __v8si __B, __v8si __C)
11080 {
11081 return __builtin_ia32_vpdpwsud256 (__A, __B, __C);
11082 }
11083 } "-O0 -mavxvnniint16" ]
11084 }
11085
11086 # Return 1 if sm3 instructions can be compiled.
11087 proc check_effective_target_sm3 { } {
11088 return [check_no_compiler_messages sm3 object {
11089 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11090 typedef int __v4si __attribute__ ((__vector_size__ (16)));
11091 __m128i
11092 _mm_sm3msg1_epi32 (__m128i __A, __m128i __B, __m128i __C)
11093 {
11094 return (__m128i) __builtin_ia32_vsm3msg1 ((__v4si) __A,
11095 (__v4si) __B,
11096 (__v4si) __C);
11097 }
11098 } "-msm3" ]
11099 }
11100
11101 # Return 1 if sha512 instructions can be compiled.
11102 proc check_effective_target_sha512 { } {
11103 return [check_no_compiler_messages sha512 object {
11104 typedef long long __m256i __attribute__ ((__vector_size__ (32)));
11105 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
11106 __m256i
11107 _mm256_sha512msg2_epi64 (__m256i __A, __m256i __B)
11108 {
11109 return (__m256i) __builtin_ia32_vsha512msg2 ((__v4di) __A,
11110 (__v4di) __B);
11111 }
11112 } "-msha512" ]
11113 }
11114
11115 # Return 1 if sm4 instructions can be compiled.
11116 proc check_effective_target_sm4 { } {
11117 return [check_no_compiler_messages sm4 object {
11118 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11119 typedef int __v4si __attribute__ ((__vector_size__ (16)));
11120 __m128i
11121 _mm_sm4key4_epi32 (__m128i __A, __m128i __B)
11122 {
11123 return (__m128i) __builtin_ia32_vsm4key4128 ((__v4si) __A,
11124 (__v4si) __B);
11125 }
11126 } "-msm4" ]
11127 }
11128
11129 proc check_effective_target_apxf { } {
11130 return [check_no_compiler_messages apxf object {
11131 void
11132 foo ()
11133 {
11134 __asm__ volatile ("movq\t%r16, %rax");
11135 __asm__ volatile ("push2p\t%r15, %r14");
11136 __asm__ volatile ("addq\t%r16, %r31, %r17");
11137 __asm__ volatile ("{nf} addq\t%r16, %r31");
11138 __asm__ volatile ("setzule\t%al");
11139 __asm__ volatile ("cfcmoveq\t%r16, %r31");
11140 __asm__ volatile ("ccmpleq\t{dfv=sf} %r16, %r31");
11141 }
11142 } "-mapxf" ]
11143 }
11144
11145 # Return 1 if avx10.2 instructions can be compiled.
11146 proc check_effective_target_avx10_2 { } {
11147 return [check_no_compiler_messages avx10.2 object {
11148 void
11149 foo ()
11150 {
11151 __asm__ volatile ("vdpphps\t%ymm4, %ymm5, %ymm6");
11152 __asm__ volatile ("vcvthf82ph\t%xmm5, %ymm6");
11153 __asm__ volatile ("vaddbf16\t%ymm4, %ymm5, %ymm6");
11154 __asm__ volatile ("vcvtph2ibs\t%ymm5, %ymm6");
11155 __asm__ volatile ("vminmaxpd\t$123, %ymm4, %ymm5, %ymm6");
11156 __asm__ volatile ("vdpphps\t%zmm4, %zmm5, %zmm6");
11157 __asm__ volatile ("vcvthf82ph\t%ymm5, %zmm6");
11158 __asm__ volatile ("vaddbf16\t%zmm4, %zmm5, %zmm6");
11159 __asm__ volatile ("vcvtph2ibs\t%zmm5, %zmm6");
11160 __asm__ volatile ("vminmaxpd\t$123, %zmm4, %zmm5, %zmm6");
11161 }
11162 } "" ]
11163 }
11164
11165 # Return 1 if amx-avx512 instructions can be compiled.
11166 proc check_effective_target_amx_avx512 { } {
11167 return [check_no_compiler_messages amx_avx512 object {
11168 void
11169 foo ()
11170 {
11171 __asm__ volatile ("tilemovrow\t%%edx, %%tmm2, %%zmm1" ::);
11172 }
11173 } "-mamx-avx512" ]
11174 }
11175
11176 # Return 1 if amx-tf32 instructions can be compiled.
11177 proc check_effective_target_amx_tf32 { } {
11178 return [check_no_compiler_messages amx_tf32 object {
11179 void
11180 foo ()
11181 {
11182 __asm__ volatile ("tmmultf32ps\t%%tmm1, %%tmm2, %%tmm3" ::);
11183 }
11184 } "-mamx-tf32" ]
11185 }
11186
11187 # Return 1 if amx-transpose instructions can be compiled.
11188 proc check_effective_target_amx_transpose { } {
11189 return [check_no_compiler_messages amx_transpose object {
11190 void
11191 foo ()
11192 {
11193 __asm__ volatile ("ttransposed\t%%tmm1, %%tmm2" ::);
11194 }
11195 } "-mamx-transpose" ]
11196 }
11197
11198 # Return 1 if amx-fp8 instructions can be compiled.
11199 proc check_effective_target_amx_fp8 { } {
11200 return [check_no_compiler_messages amx_fp8 object {
11201 void
11202 foo ()
11203 {
11204 __asm__ volatile ("tdpbf8ps\t%%tmm1, %%tmm2, %%tmm3" ::);
11205 }
11206 } "-mamx-fp8" ]
11207 }
11208
11209 # Return 1 if amx-movrs instructions can be compiled.
11210 proc check_effective_target_amx_movrs { } {
11211 return [check_no_compiler_messages amx_movrs object {
11212 void
11213 foo ()
11214 {
11215 __asm__ volatile ("tileloaddrs\t(%%r9), %%tmm3" ::);
11216 }
11217 } "-mamx-movrs" ]
11218 }
11219
11220 # Return 1 if sse instructions can be compiled.
11221 proc check_effective_target_sse { } {
11222 return [check_no_compiler_messages sse object {
11223 int main ()
11224 {
11225 __builtin_ia32_stmxcsr ();
11226 return 0;
11227 }
11228 } "-O2 -msse" ]
11229 }
11230
11231 # Return 1 if sse2 instructions can be compiled.
11232 proc check_effective_target_sse2 { } {
11233 return [check_no_compiler_messages sse2 object {
11234 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11235
11236 __m128i _mm_srli_si128 (__m128i __A, int __N)
11237 {
11238 return (__m128i)__builtin_ia32_psrldqi128 (__A, 8);
11239 }
11240 } "-O2 -msse2" ]
11241 }
11242
11243 # Return 1 if sse4.1 instructions can be compiled.
11244 proc check_effective_target_sse4 { } {
11245 return [check_no_compiler_messages sse4.1 object {
11246 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11247 typedef int __v4si __attribute__ ((__vector_size__ (16)));
11248
11249 __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
11250 {
11251 return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
11252 (__v4si)__Y);
11253 }
11254 } "-O2 -msse4.1" ]
11255 }
11256
11257 # Return 1 if F16C instructions can be compiled.
11258
11259 proc check_effective_target_f16c { } {
11260 return [check_no_compiler_messages f16c object {
11261 #include "immintrin.h"
11262 float
11263 foo (unsigned short val)
11264 {
11265 return _cvtsh_ss (val);
11266 }
11267 } "-O2 -mf16c" ]
11268 }
11269
11270 proc check_effective_target_ms_hook_prologue { } {
11271 if { [check_no_compiler_messages ms_hook_prologue object {
11272 void __attribute__ ((__ms_hook_prologue__)) foo ();
11273 } ""] } {
11274 return 1
11275 } else {
11276 return 0
11277 }
11278 }
11279
11280 # Return 1 if 3dnow instructions can be compiled.
11281 proc check_effective_target_3dnow { } {
11282 return [check_no_compiler_messages 3dnow object {
11283 typedef int __m64 __attribute__ ((__vector_size__ (8)));
11284 typedef float __v2sf __attribute__ ((__vector_size__ (8)));
11285
11286 __m64 _m_pfadd (__m64 __A, __m64 __B)
11287 {
11288 return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
11289 }
11290 } "-O2 -m3dnow" ]
11291 }
11292
11293 # Return 1 if sse3 instructions can be compiled.
11294 proc check_effective_target_sse3 { } {
11295 return [check_no_compiler_messages sse3 object {
11296 typedef double __m128d __attribute__ ((__vector_size__ (16)));
11297 typedef double __v2df __attribute__ ((__vector_size__ (16)));
11298
11299 __m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
11300 {
11301 return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
11302 }
11303 } "-O2 -msse3" ]
11304 }
11305
11306 # Return 1 if ssse3 instructions can be compiled.
11307 proc check_effective_target_ssse3 { } {
11308 return [check_no_compiler_messages ssse3 object {
11309 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11310 typedef int __v4si __attribute__ ((__vector_size__ (16)));
11311
11312 __m128i _mm_abs_epi32 (__m128i __X)
11313 {
11314 return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
11315 }
11316 } "-O2 -mssse3" ]
11317 }
11318
11319 # Return 1 if aes instructions can be compiled.
11320 proc check_effective_target_aes { } {
11321 return [check_no_compiler_messages aes object {
11322 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11323 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
11324
11325 __m128i _mm_aesimc_si128 (__m128i __X)
11326 {
11327 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
11328 }
11329 } "-O2 -maes" ]
11330 }
11331
11332 # Return 1 if vaes instructions can be compiled.
11333 proc check_effective_target_vaes { } {
11334 return [check_no_compiler_messages vaes object {
11335 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11336 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
11337
11338 __m128i _mm_aesimc_si128 (__m128i __X)
11339 {
11340 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
11341 }
11342 } "-O2 -maes -mavx" ]
11343 }
11344
11345 # Return 1 if pclmul instructions can be compiled.
11346 proc check_effective_target_pclmul { } {
11347 return [check_no_compiler_messages pclmul object {
11348 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11349 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
11350
11351 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
11352 {
11353 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
11354 (__v2di)__Y,
11355 1);
11356 }
11357 } "-O2 -mpclmul" ]
11358 }
11359
11360 # Return 1 if vpclmul instructions can be compiled.
11361 proc check_effective_target_vpclmul { } {
11362 return [check_no_compiler_messages vpclmul object {
11363 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11364 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
11365
11366 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
11367 {
11368 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
11369 (__v2di)__Y,
11370 1);
11371 }
11372 } "-O2 -mpclmul -mavx" ]
11373 }
11374
11375 # Return 1 if sse4a instructions can be compiled.
11376 proc check_effective_target_sse4a { } {
11377 return [check_no_compiler_messages sse4a object {
11378 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11379 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
11380
11381 __m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
11382 {
11383 return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
11384 }
11385 } "-O2 -msse4a" ]
11386 }
11387
11388 # Return 1 if fma4 instructions can be compiled.
11389 proc check_effective_target_fma4 { } {
11390 return [check_no_compiler_messages fma4 object {
11391 typedef float __m128 __attribute__ ((__vector_size__ (16)));
11392 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
11393 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
11394 {
11395 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
11396 (__v4sf)__B,
11397 (__v4sf)__C);
11398 }
11399 } "-O2 -mfma4" ]
11400 }
11401
11402 # Return 1 if fma instructions can be compiled.
11403 proc check_effective_target_fma { } {
11404 return [check_no_compiler_messages fma object {
11405 typedef float __m128 __attribute__ ((__vector_size__ (16)));
11406 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
11407 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
11408 {
11409 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
11410 (__v4sf)__B,
11411 (__v4sf)__C);
11412 }
11413 } "-O2 -mfma" ]
11414 }
11415
11416 # Return 1 if xop instructions can be compiled.
11417 proc check_effective_target_xop { } {
11418 return [check_no_compiler_messages xop object {
11419 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11420 typedef short __v8hi __attribute__ ((__vector_size__ (16)));
11421 __m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
11422 {
11423 return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
11424 (__v8hi)__B,
11425 (__v8hi)__C);
11426 }
11427 } "-O2 -mxop" ]
11428 }
11429
11430 # Return 1 if lzcnt instruction can be compiled.
11431 proc check_effective_target_lzcnt { } {
11432 return [check_no_compiler_messages lzcnt object {
11433 unsigned short _lzcnt (unsigned short __X)
11434 {
11435 return __builtin_clzs (__X);
11436 }
11437 } "-mlzcnt" ]
11438 }
11439
11440 # Return 1 if bmi instructions can be compiled.
11441 proc check_effective_target_bmi { } {
11442 return [check_no_compiler_messages bmi object {
11443 unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
11444 {
11445 return __builtin_ia32_bextr_u32 (__X, __Y);
11446 }
11447 } "-mbmi" ]
11448 }
11449
11450 # Return 1 if ADX instructions can be compiled.
11451 proc check_effective_target_adx { } {
11452 return [check_no_compiler_messages adx object {
11453 unsigned char
11454 _adxcarry_u32 (unsigned char __CF, unsigned int __X,
11455 unsigned int __Y, unsigned int *__P)
11456 {
11457 return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
11458 }
11459 } "-madx" ]
11460 }
11461
11462 # Return 1 if rtm instructions can be compiled.
11463 proc check_effective_target_rtm { } {
11464 return [check_no_compiler_messages rtm object {
11465 void
11466 _rtm_xend (void)
11467 {
11468 return __builtin_ia32_xend ();
11469 }
11470 } "-mrtm" ]
11471 }
11472
11473 # Return 1 if avx512vl instructions can be compiled.
11474 proc check_effective_target_avx512vl { } {
11475 return [check_no_compiler_messages avx512vl object {
11476 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
11477 __v4di
11478 mm256_and_epi64 (__v4di __X, __v4di __Y)
11479 {
11480 __v4di __W;
11481 return __builtin_ia32_pandq256_mask (__X, __Y, __W, -1);
11482 }
11483 } "-mavx512vl" ]
11484 }
11485
11486 # Return 1 if avx512cd instructions can be compiled.
11487 proc check_effective_target_avx512cd { } {
11488 return [check_no_compiler_messages avx512cd_trans object {
11489 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
11490 __v8di
11491 _mm512_conflict_epi64 (__v8di __W, __v8di __A)
11492 {
11493 return (__v8di) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A,
11494 (__v8di) __W,
11495 -1);
11496 }
11497 } "-Wno-psabi -mavx512cd" ]
11498 }
11499
11500 # Return 1 if avx512er instructions can be compiled.
11501 proc check_effective_target_avx512er { } {
11502 return [check_no_compiler_messages avx512er_trans object {
11503 typedef float __v16sf __attribute__ ((__vector_size__ (64)));
11504 __v16sf
11505 mm512_exp2a23_ps (__v16sf __X)
11506 {
11507 return __builtin_ia32_exp2ps_mask (__X, __X, -1, 4);
11508 }
11509 } "-Wno-psabi -mavx512er" ]
11510 }
11511
11512 # Return 1 if sha instructions can be compiled.
11513 proc check_effective_target_sha { } {
11514 return [check_no_compiler_messages sha object {
11515 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
11516 typedef int __v4si __attribute__ ((__vector_size__ (16)));
11517
11518 __m128i _mm_sha1msg1_epu32 (__m128i __X, __m128i __Y)
11519 {
11520 return (__m128i) __builtin_ia32_sha1msg1 ((__v4si)__X,
11521 (__v4si)__Y);
11522 }
11523 } "-O2 -msha" ]
11524 }
11525
11526 # Return 1 if avx512dq instructions can be compiled.
11527 proc check_effective_target_avx512dq { } {
11528 return [check_no_compiler_messages avx512dq object {
11529 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
11530 __v8di
11531 _mm512_mask_mullo_epi64 (__v8di __W, __v8di __A, __v8di __B)
11532 {
11533 return (__v8di) __builtin_ia32_pmullq512_mask ((__v8di) __A,
11534 (__v8di) __B,
11535 (__v8di) __W,
11536 -1);
11537 }
11538 } "-mavx512dq" ]
11539 }
11540
11541 # Return 1 if avx512bw instructions can be compiled.
11542 proc check_effective_target_avx512bw { } {
11543 return [check_no_compiler_messages avx512bw object {
11544 typedef short __v32hi __attribute__ ((__vector_size__ (64)));
11545 __v32hi
11546 _mm512_mask_mulhrs_epi16 (__v32hi __W, __v32hi __A, __v32hi __B)
11547 {
11548 return (__v32hi) __builtin_ia32_pmulhrsw512_mask ((__v32hi) __A,
11549 (__v32hi) __B,
11550 (__v32hi) __W,
11551 -1);
11552 }
11553 } "-mavx512bw" ]
11554 }
11555
11556 # Return 1 if -Wa,-march=+noavx512bw is supported.
11557 proc check_effective_target_assembler_march_noavx512bw {} {
11558 if { [check_effective_target_x86] } {
11559 return [check_no_compiler_messages assembler_march_noavx512bw object {
11560 void foo (void) {}
11561 } "-mno-avx512bw -Wa,-march=+noavx512bw"]
11562 }
11563 return 0
11564 }
11565
11566 # Return 1 if avx512vp2intersect instructions can be compiled.
11567 proc check_effective_target_avx512vp2intersect { } {
11568 return [check_no_compiler_messages avx512vp2intersect object {
11569 typedef int __v16si __attribute__ ((__vector_size__ (64)));
11570 typedef short __mmask16;
11571 void
11572 _mm512_2intersect_epi32 (__v16si __A, __v16si __B, __mmask16 *__U,
11573 __mmask16 *__M)
11574 {
11575 __builtin_ia32_2intersectd512 (__U, __M, (__v16si) __A, (__v16si) __B);
11576 }
11577 } "-mavx512vp2intersect" ]
11578 }
11579
11580 # Return 1 if avx512ifma instructions can be compiled.
11581 proc check_effective_target_avx512ifma { } {
11582 return [check_no_compiler_messages avx512ifma object {
11583 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
11584 __v8di
11585 _mm512_madd52lo_epu64 (__v8di __X, __v8di __Y, __v8di __Z)
11586 {
11587 return (__v8di) __builtin_ia32_vpmadd52luq512_mask ((__v8di) __X,
11588 (__v8di) __Y,
11589 (__v8di) __Z,
11590 -1);
11591 }
11592 } "-mavx512ifma" ]
11593 }
11594
11595 # Return 1 if avx512vbmi instructions can be compiled.
11596 proc check_effective_target_avx512vbmi { } {
11597 return [check_no_compiler_messages avx512vbmi object {
11598 typedef char __v64qi __attribute__ ((__vector_size__ (64)));
11599 __v64qi
11600 _mm512_multishift_epi64_epi8 (__v64qi __X, __v64qi __Y)
11601 {
11602 return (__v64qi) __builtin_ia32_vpmultishiftqb512_mask ((__v64qi) __X,
11603 (__v64qi) __Y,
11604 (__v64qi) __Y,
11605 -1);
11606 }
11607 } "-mavx512vbmi" ]
11608 }
11609
11610 # Return 1 if avx512_4fmaps instructions can be compiled.
11611 proc check_effective_target_avx5124fmaps { } {
11612 return [check_no_compiler_messages avx5124fmaps object {
11613 typedef float __v16sf __attribute__ ((__vector_size__ (64)));
11614 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
11615
11616 __v16sf
11617 _mm512_mask_4fmadd_ps (__v16sf __DEST, __v16sf __A, __v16sf __B, __v16sf __C,
11618 __v16sf __D, __v16sf __E, __v4sf *__F)
11619 {
11620 return (__v16sf) __builtin_ia32_4fmaddps_mask ((__v16sf) __A,
11621 (__v16sf) __B,
11622 (__v16sf) __C,
11623 (__v16sf) __D,
11624 (__v16sf) __E,
11625 (const __v4sf *) __F,
11626 (__v16sf) __DEST,
11627 0xffff);
11628 }
11629 } "-mavx5124fmaps" ]
11630 }
11631
11632 # Return 1 if avx512_4vnniw instructions can be compiled.
11633 proc check_effective_target_avx5124vnniw { } {
11634 return [check_no_compiler_messages avx5124vnniw object {
11635 typedef int __v16si __attribute__ ((__vector_size__ (64)));
11636 typedef int __v4si __attribute__ ((__vector_size__ (16)));
11637
11638 __v16si
11639 _mm512_4dpwssd_epi32 (__v16si __A, __v16si __B, __v16si __C,
11640 __v16si __D, __v16si __E, __v4si *__F)
11641 {
11642 return (__v16si) __builtin_ia32_vp4dpwssd ((__v16si) __B,
11643 (__v16si) __C,
11644 (__v16si) __D,
11645 (__v16si) __E,
11646 (__v16si) __A,
11647 (const __v4si *) __F);
11648 }
11649 } "-mavx5124vnniw" ]
11650 }
11651
11652 # Return 1 if avx512_vpopcntdq instructions can be compiled.
11653 proc check_effective_target_avx512vpopcntdq { } {
11654 return [check_no_compiler_messages avx512vpopcntdq object {
11655 typedef int __v16si __attribute__ ((__vector_size__ (64)));
11656
11657 __v16si
11658 _mm512_popcnt_epi32 (__v16si __A)
11659 {
11660 return (__v16si) __builtin_ia32_vpopcountd_v16si ((__v16si) __A);
11661 }
11662 } "-mavx512vpopcntdq" ]
11663 }
11664
11665 # Return 1 if 128 or 256-bit avx512_vpopcntdq instructions can be compiled.
11666 proc check_effective_target_avx512vpopcntdqvl { } {
11667 return [check_no_compiler_messages avx512vpopcntdqvl object {
11668 typedef int __v8si __attribute__ ((__vector_size__ (32)));
11669
11670 __v8si
11671 _mm256_popcnt_epi32 (__v8si __A)
11672 {
11673 return (__v8si) __builtin_ia32_vpopcountd_v8si ((__v8si) __A);
11674 }
11675 } "-mavx512vpopcntdq -mavx512vl" ]
11676 }
11677
11678 # Return 1 if gfni instructions can be compiled.
11679 proc check_effective_target_gfni { } {
11680 return [check_no_compiler_messages gfni object {
11681 typedef char __v16qi __attribute__ ((__vector_size__ (16)));
11682
11683 __v16qi
11684 _mm_gf2p8affineinv_epi64_epi8 (__v16qi __A, __v16qi __B, const int __C)
11685 {
11686 return (__v16qi) __builtin_ia32_vgf2p8affineinvqb_v16qi ((__v16qi) __A,
11687 (__v16qi) __B,
11688 0);
11689 }
11690 } "-mgfni" ]
11691 }
11692
11693 # Return 1 if avx512vbmi2 instructions can be compiled.
11694 proc check_effective_target_avx512vbmi2 { } {
11695 return [check_no_compiler_messages avx512vbmi2 object {
11696 typedef char __v16qi __attribute__ ((__vector_size__ (16)));
11697 typedef unsigned long long __mmask16;
11698
11699 __v16qi
11700 _mm_mask_compress_epi8 (__v16qi __A, __mmask16 __B, __v16qi __C)
11701 {
11702 return (__v16qi) __builtin_ia32_compressqi128_mask((__v16qi)__C,
11703 (__v16qi)__A,
11704 (__mmask16)__B);
11705 }
11706 } "-mavx512vbmi2 -mavx512vl" ]
11707 }
11708
11709 # Return 1 if avx512vbmi2 instructions can be compiled.
11710 proc check_effective_target_avx512vnni { } {
11711 return [check_no_compiler_messages avx512vnni object {
11712 typedef int __v16si __attribute__ ((__vector_size__ (64)));
11713
11714 __v16si
11715 _mm_mask_compress_epi8 (__v16si __A, __v16si __B, __v16si __C)
11716 {
11717 return (__v16si) __builtin_ia32_vpdpbusd_v16si ((__v16si)__A,
11718 (__v16si)__B,
11719 (__v16si)__C);
11720 }
11721 } "-mavx512vnni -mavx512f" ]
11722 }
11723
11724 # Return 1 if vaes instructions can be compiled.
11725 proc check_effective_target_avx512vaes { } {
11726 return [check_no_compiler_messages avx512vaes object {
11727
11728 typedef int __v16si __attribute__ ((__vector_size__ (64)));
11729
11730 __v32qi
11731 _mm256_aesdec_epi128 (__v32qi __A, __v32qi __B)
11732 {
11733 return (__v32qi)__builtin_ia32_vaesdec_v32qi ((__v32qi) __A, (__v32qi) __B);
11734 }
11735 } "-mvaes" ]
11736 }
11737
11738 # Return 1 if amx-tile instructions can be compiled.
11739 proc check_effective_target_amx_tile { } {
11740 return [check_no_compiler_messages amx_tile object {
11741 void
11742 foo ()
11743 {
11744 __asm__ volatile ("tilerelease" ::);
11745 }
11746 } "-mamx-tile" ]
11747 }
11748
11749 # Return 1 if amx-int8 instructions can be compiled.
11750 proc check_effective_target_amx_int8 { } {
11751 return [check_no_compiler_messages amx_int8 object {
11752 void
11753 foo ()
11754 {
11755 __asm__ volatile ("tdpbssd\t%%tmm1, %%tmm2, %%tmm3" ::);
11756 }
11757 } "-mamx-int8" ]
11758 }
11759
11760 # Return 1 if amx-bf16 instructions can be compiled.
11761 proc check_effective_target_amx_bf16 { } {
11762 return [check_no_compiler_messages amx_bf16 object {
11763 void
11764 foo ()
11765 {
11766 __asm__ volatile ("tdpbf16ps\t%%tmm1, %%tmm2, %%tmm3" ::);
11767 }
11768 } "-mamx-bf16" ]
11769 }
11770
11771 # Return 1 if amx-fp16 instructions can be compiled.
11772 proc check_effective_target_amx_fp16 { } {
11773 return [check_no_compiler_messages amx_fp16 object {
11774 void
11775 foo ()
11776 {
11777 __asm__ volatile ("tdpfp16ps\t%%tmm1, %%tmm2, %%tmm3" ::);
11778 }
11779 } "-mamx-fp16" ]
11780 }
11781
11782 # Return 1 if vpclmulqdq instructions can be compiled.
11783 proc check_effective_target_vpclmulqdq { } {
11784 return [check_no_compiler_messages vpclmulqdq object {
11785 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
11786
11787 __v4di
11788 _mm256_clmulepi64_epi128 (__v4di __A, __v4di __B)
11789 {
11790 return (__v4di) __builtin_ia32_vpclmulqdq_v4di (__A, __B, 0);
11791 }
11792 } "-mvpclmulqdq -mavx512vl" ]
11793 }
11794
11795 # Return 1 if avx512_bitalg instructions can be compiled.
11796 proc check_effective_target_avx512bitalg { } {
11797 return [check_no_compiler_messages avx512bitalg object {
11798 typedef short int __v32hi __attribute__ ((__vector_size__ (64)));
11799
11800 __v32hi
11801 _mm512_popcnt_epi16 (__v32hi __A)
11802 {
11803 return (__v32hi) __builtin_ia32_vpopcountw_v32hi ((__v32hi) __A);
11804 }
11805 } "-mavx512bitalg" ]
11806 }
11807
11808 # Return 1 if C wchar_t type is compatible with char16_t.
11809
11810 proc check_effective_target_wchar_t_char16_t_compatible { } {
11811 return [check_no_compiler_messages wchar_t_char16_t object {
11812 __WCHAR_TYPE__ wc;
11813 __CHAR16_TYPE__ *p16 = &wc;
11814 char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
11815 }]
11816 }
11817
11818 # Return 1 if C wchar_t type is compatible with char32_t.
11819
11820 proc check_effective_target_wchar_t_char32_t_compatible { } {
11821 return [check_no_compiler_messages wchar_t_char32_t object {
11822 __WCHAR_TYPE__ wc;
11823 __CHAR32_TYPE__ *p32 = &wc;
11824 char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
11825 }]
11826 }
11827
11828 # Return 1 if pow10 function exists.
11829
11830 proc check_effective_target_pow10 { } {
11831 return [check_runtime pow10 {
11832 #include <math.h>
11833 int main () {
11834 double x;
11835 x = pow10 (1);
11836 return 0;
11837 }
11838 } "-lm" ]
11839 }
11840
11841 # Return 1 if frexpl function exists.
11842
11843 proc check_effective_target_frexpl { } {
11844 return [check_runtime frexpl {
11845 #include <math.h>
11846 int main () {
11847 long double x;
11848 int y;
11849 x = frexpl (5.0, &y);
11850 return 0;
11851 }
11852 } "-lm" ]
11853 }
11854
11855
11856 # Return 1 if issignaling function exists.
11857 proc check_effective_target_issignaling {} {
11858 return [check_runtime issignaling {
11859 #define _GNU_SOURCE
11860 #include <math.h>
11861 int main ()
11862 {
11863 return issignaling (0.0);
11864 }
11865 } "-lm" ]
11866 }
11867
11868 # Return 1 if current options generate DFP instructions, 0 otherwise.
11869 proc check_effective_target_hard_dfp {} {
11870 return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
11871 typedef float d64 __attribute__((mode(DD)));
11872 d64 x, y, z;
11873 void foo (void) { z = x + y; }
11874 }]
11875 }
11876
11877 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
11878 # for strchr etc. functions.
11879
11880 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
11881 return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
11882 #include <string.h>
11883 #include <wchar.h>
11884 #if !defined(__cplusplus) \
11885 || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
11886 || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
11887 ISO C++ correct string.h and wchar.h protos not supported.
11888 #else
11889 int i;
11890 #endif
11891 }]
11892 }
11893
11894 # Return 1 if GNU as is used.
11895
11896 proc check_effective_target_gas { } {
11897 global use_gas_saved
11898 global tool
11899
11900 if {![info exists use_gas_saved]} {
11901 # Check if the as used by gcc is GNU as.
11902 set options [list "additional_flags=-print-prog-name=as"]
11903 set gcc_as [lindex [${tool}_target_compile "" "" "none" $options] 0]
11904 # Provide /dev/null as input, otherwise gas times out reading from
11905 # stdin.
11906 set status [remote_exec host "$gcc_as" "-v /dev/null"]
11907 set as_output [lindex $status 1]
11908 if { [ string first "GNU" $as_output ] >= 0 } {
11909 # Some Darwin versions have an assembler which is based on an old
11910 # version of GAS (and reports GNU assembler in its -v output) but
11911 # but doesn't support many of the modern GAS features.
11912 if { [ string first "cctools" $as_output ] >= 0 } {
11913 set use_gas_saved 0
11914 } else {
11915 set use_gas_saved 1
11916 }
11917 } else {
11918 set use_gas_saved 0
11919 }
11920 }
11921 return $use_gas_saved
11922 }
11923
11924 # Return 1 if GNU ld is used.
11925
11926 proc check_effective_target_gld { } {
11927 global use_gld_saved
11928 global tool
11929
11930 if {![info exists use_gld_saved]} {
11931 # Check if the ld used by gcc is GNU ld.
11932 set options [list "additional_flags=-print-prog-name=ld"]
11933 set gcc_ld [lindex [${tool}_target_compile "" "" "none" $options] 0]
11934 set status [remote_exec host "$gcc_ld" "--version"]
11935 set ld_output [lindex $status 1]
11936 if { [ string first "GNU" $ld_output ] >= 0 } {
11937 set use_gld_saved 1
11938 } else {
11939 set use_gld_saved 0
11940 }
11941 }
11942 return $use_gld_saved
11943 }
11944
11945 # Return 1 if the compiler has been configure with link-time optimization
11946 # (LTO) support.
11947
11948 proc check_effective_target_lto { } {
11949 if { [istarget *-*-vxworks*] } {
11950 # No LTO on VxWorks, with kernel modules
11951 # built with partial links
11952 return 0
11953 }
11954 if { [istarget nvptx-*-*]
11955 || [istarget amdgcn-*-*] } {
11956 return 0;
11957 }
11958 return [check_no_compiler_messages lto object {
11959 void foo (void) { }
11960 } "-flto"]
11961 }
11962
11963 # Return 1 if the compiler and linker support incremental link-time
11964 # optimization.
11965
11966 proc check_effective_target_lto_incremental { } {
11967 if ![check_effective_target_lto] {
11968 return 0
11969 }
11970 return [check_no_compiler_messages lto_incremental executable {
11971 int main () { return 0; }
11972 } "-flto -r -nostdlib"]
11973 }
11974
11975 # Return 1 if the compiler has been configured with analyzer support.
11976
11977 proc check_effective_target_analyzer { } {
11978 return [check_no_compiler_messages analyzer object {
11979 void foo (void) { }
11980 } "-fanalyzer"]
11981 }
11982
11983 # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
11984
11985 proc check_effective_target_maybe_x32 { } {
11986 return [check_no_compiler_messages maybe_x32 object {
11987 void foo (void) {}
11988 } "-mx32 -maddress-mode=short"]
11989 }
11990
11991 # Return 1 if this target supports the -fsplit-stack option, 0
11992 # otherwise.
11993
11994 proc check_effective_target_split_stack {} {
11995 return [check_no_compiler_messages split_stack object {
11996 void foo (void) { }
11997 } "-fsplit-stack"]
11998 }
11999
12000 # Return 1 if this target supports the -masm=intel option, 0
12001 # otherwise
12002
12003 proc check_effective_target_masm_intel {} {
12004 return [check_no_compiler_messages masm_intel object {
12005 extern void abort (void);
12006 } "-masm=intel"]
12007 }
12008
12009 # Return 1 if the language for the compiler under test is C.
12010
12011 proc check_effective_target_c { } {
12012 global tool
12013 if [string match $tool "gcc"] {
12014 return 1
12015 }
12016 return 0
12017 }
12018
12019 # Return 1 if the language for the compiler under test is C++.
12020
12021 proc check_effective_target_c++ { } {
12022 global tool
12023 if { [string match $tool "g++"] || [string match $tool "libstdc++"] } {
12024 return 1
12025 }
12026 return 0
12027 }
12028
12029 set cxx_default "c++17"
12030 # Check whether the current active language standard supports the features
12031 # of C++11/C++14 by checking for the presence of one of the -std flags.
12032 # This assumes that the default for the compiler is $cxx_default, and that
12033 # there will never be multiple -std= arguments on the command line.
12034 proc check_effective_target_c++11_only { } {
12035 global cxx_default
12036 if ![check_effective_target_c++] {
12037 return 0
12038 }
12039 if [check-flags { { } { } { -std=c++0x -std=gnu++0x -std=c++11 -std=gnu++11 } }] {
12040 return 1
12041 }
12042 if { $cxx_default == "c++11" && [check-flags { { } { } { } { -std=* } }] } {
12043 return 1
12044 }
12045 return 0
12046 }
12047 proc check_effective_target_c++11 { } {
12048 if [check_effective_target_c++11_only] {
12049 return 1
12050 }
12051 return [check_effective_target_c++14]
12052 }
12053 proc check_effective_target_c++11_down { } {
12054 if ![check_effective_target_c++] {
12055 return 0
12056 }
12057 return [expr ![check_effective_target_c++14] ]
12058 }
12059
12060 proc check_effective_target_c++14_only { } {
12061 global cxx_default
12062 if ![check_effective_target_c++] {
12063 return 0
12064 }
12065 if [check-flags { { } { } { -std=c++14 -std=gnu++14 -std=c++14 -std=gnu++14 } }] {
12066 return 1
12067 }
12068 if { $cxx_default == "c++14" && [check-flags { { } { } { } { -std=* } }] } {
12069 return 1
12070 }
12071 return 0
12072 }
12073
12074 proc check_effective_target_c++14 { } {
12075 if [check_effective_target_c++14_only] {
12076 return 1
12077 }
12078 return [check_effective_target_c++17]
12079 }
12080 proc check_effective_target_c++14_down { } {
12081 if ![check_effective_target_c++] {
12082 return 0
12083 }
12084 return [expr ![check_effective_target_c++17] ]
12085 }
12086
12087 proc check_effective_target_c++98_only { } {
12088 global cxx_default
12089 if ![check_effective_target_c++] {
12090 return 0
12091 }
12092 if [check-flags { { } { } { -std=c++98 -std=gnu++98 -std=c++03 -std=gnu++03 } }] {
12093 return 1
12094 }
12095 if { $cxx_default == "c++98" && [check-flags { { } { } { } { -std=* } }] } {
12096 return 1
12097 }
12098 return 0
12099 }
12100
12101 proc check_effective_target_c++17_only { } {
12102 global cxx_default
12103 if ![check_effective_target_c++] {
12104 return 0
12105 }
12106 if [check-flags { { } { } { -std=c++17 -std=gnu++17 -std=c++1z -std=gnu++1z } }] {
12107 return 1
12108 }
12109 if { $cxx_default == "c++17" && [check-flags { { } { } { } { -std=* } }] } {
12110 return 1
12111 }
12112 return 0
12113 }
12114
12115 proc check_effective_target_c++17 { } {
12116 if [check_effective_target_c++17_only] {
12117 return 1
12118 }
12119 return [check_effective_target_c++2a]
12120 }
12121 proc check_effective_target_c++17_down { } {
12122 if ![check_effective_target_c++] {
12123 return 0
12124 }
12125 return [expr ![check_effective_target_c++2a] ]
12126 }
12127
12128 proc check_effective_target_c++2a_only { } {
12129 global cxx_default
12130 if ![check_effective_target_c++] {
12131 return 0
12132 }
12133 if [check-flags { { } { } { -std=c++2a -std=gnu++2a -std=c++20 -std=gnu++20 } }] {
12134 return 1
12135 }
12136 if { $cxx_default == "c++20" && [check-flags { { } { } { } { -std=* } }] } {
12137 return 1
12138 }
12139 return 0
12140 }
12141 proc check_effective_target_c++2a { } {
12142 if [check_effective_target_c++2a_only] {
12143 return 1
12144 }
12145 return [check_effective_target_c++23]
12146 }
12147
12148 proc check_effective_target_c++20_only { } {
12149 return [check_effective_target_c++2a_only]
12150 }
12151
12152 proc check_effective_target_c++20 { } {
12153 return [check_effective_target_c++2a]
12154 }
12155 proc check_effective_target_c++20_down { } {
12156 if ![check_effective_target_c++] {
12157 return 0
12158 }
12159 return [expr ![check_effective_target_c++23] ]
12160 }
12161
12162 proc check_effective_target_c++23_only { } {
12163 global cxx_default
12164 if ![check_effective_target_c++] {
12165 return 0
12166 }
12167 if [check-flags { { } { } { -std=c++23 -std=gnu++23 -std=c++2b -std=gnu++2b } }] {
12168 return 1
12169 }
12170 if { $cxx_default == "c++23" && [check-flags { { } { } { } { -std=* } }] } {
12171 return 1
12172 }
12173 return 0
12174 }
12175 proc check_effective_target_c++23 { } {
12176 if [check_effective_target_c++23_only] {
12177 return 1
12178 }
12179 return [check_effective_target_c++26]
12180 }
12181
12182 proc check_effective_target_c++23_down { } {
12183 if ![check_effective_target_c++] {
12184 return 0
12185 }
12186 return [expr ![check_effective_target_c++26] ]
12187 }
12188
12189 proc check_effective_target_c++26_only { } {
12190 global cxx_default
12191 if ![check_effective_target_c++] {
12192 return 0
12193 }
12194 if [check-flags { { } { } { -std=c++26 -std=gnu++26 -std=c++2c -std=gnu++2c } }] {
12195 return 1
12196 }
12197 if { $cxx_default == "c++26" && [check-flags { { } { } { } { -std=* } }] } {
12198 return 1
12199 }
12200 return 0
12201 }
12202
12203 proc check_effective_target_c++26 { } {
12204 return [check_effective_target_c++26_only]
12205 }
12206
12207 # Check for C++ Concepts support, i.e. -fconcepts flag.
12208 proc check_effective_target_concepts { } {
12209 if [check_effective_target_c++2a] {
12210 return 1
12211 }
12212 return [check-flags { "" { } { -fconcepts } }]
12213 }
12214
12215 proc check_effective_target_implicit_constexpr { } {
12216 return [check-flags { "" { } { -fimplicit-constexpr } }]
12217 }
12218
12219 # Return 1 if expensive testcases should be run.
12220
12221 proc check_effective_target_run_expensive_tests { } {
12222 if { [getenv GCC_TEST_RUN_EXPENSIVE] != "" } {
12223 return 1
12224 }
12225 return 0
12226 }
12227
12228 # Returns 1 if "mempcpy" is available on the target system.
12229
12230 proc check_effective_target_mempcpy {} {
12231 if { [istarget *-*-vxworks*] } {
12232 # VxWorks doesn't have mempcpy but our way to test fails
12233 # to detect as we're doing partial links for kernel modules.
12234 return 0
12235 }
12236 return [check_function_available "mempcpy"]
12237 }
12238
12239 # Returns 1 if "stpcpy" is available on the target system.
12240
12241 proc check_effective_target_stpcpy {} {
12242 return [check_function_available "stpcpy"]
12243 }
12244
12245 # Returns 1 if "strndup" is available on the target system.
12246
12247 proc check_effective_target_strndup {} {
12248 if { [istarget *-*-vxworks*] } {
12249 # VxWorks doesn't have strndup but our way to test fails
12250 # to detect as we're doing partial links for kernel modules.
12251 return 0
12252 }
12253 return [check_function_available "strndup"]
12254 }
12255
12256 # Returns 1 if "sigsetjmp" is available on the target system.
12257 # Also check if "__sigsetjmp" is defined since that's what glibc
12258 # uses.
12259
12260 proc check_effective_target_sigsetjmp {} {
12261 if { [check_function_available "sigsetjmp"]
12262 || [check_function_available "__sigsetjmp"] } {
12263 return 1
12264 }
12265 return 0
12266 }
12267
12268 # Check whether the vectorizer tests are supported by the target and
12269 # append additional target-dependent compile flags to DEFAULT_VECTCFLAGS.
12270 # If a port wants to execute the tests more than once it should append
12271 # the supported target to EFFECTIVE_TARGETS instead, and the compile flags
12272 # will be added by a call to add_options_for_<target>.
12273 # Set dg-do-what-default to either compile or run, depending on target
12274 # capabilities. Do not set this if the supported target is appended to
12275 # EFFECTIVE_TARGETS. Flags and this variable will be set by et-dg-runtest
12276 # automatically. Return the number of effective targets if vectorizer tests
12277 # are supported, 0 otherwise.
12278
12279 proc check_vect_support_and_set_flags { } {
12280 global DEFAULT_VECTCFLAGS
12281 global dg-do-what-default
12282 global EFFECTIVE_TARGETS
12283
12284 if [istarget powerpc*-*-*] {
12285 # Skip targets not supporting -maltivec.
12286 if ![is-effective-target powerpc_altivec_ok] {
12287 return 0
12288 }
12289
12290 lappend DEFAULT_VECTCFLAGS "-maltivec"
12291 if [check_p9vector_hw_available] {
12292 # For power10 and up, don't specify -mcpu=power9, so that we
12293 # can have more testing coverage with higher cpu types.
12294 if ![check_power10_hw_available] {
12295 lappend DEFAULT_VECTCFLAGS "-mcpu=power9"
12296 }
12297 } elseif [check_p8vector_hw_available] {
12298 lappend DEFAULT_VECTCFLAGS "-mcpu=power8"
12299 } elseif [check_vsx_hw_available] {
12300 lappend DEFAULT_VECTCFLAGS "-mvsx" "-mno-allow-movmisalign"
12301 }
12302
12303 if [check_vmx_hw_available] {
12304 set dg-do-what-default run
12305 } else {
12306 if [is-effective-target ilp32] {
12307 # Specify a cpu that supports VMX for compile-only tests.
12308 # Place -mcpu=970 first to avoid possible overriding on
12309 # some other cpu type specified above.
12310 set DEFAULT_VECTCFLAGS [linsert $DEFAULT_VECTCFLAGS 0 "-mcpu=970"]
12311 }
12312 set dg-do-what-default compile
12313 }
12314 } elseif { [check_effective_target_x86] } {
12315 lappend DEFAULT_VECTCFLAGS "-msse2"
12316 if { [check_effective_target_sse2_runtime] } {
12317 set dg-do-what-default run
12318 } else {
12319 set dg-do-what-default compile
12320 }
12321 } elseif { [istarget mips*-*-*]
12322 && [check_effective_target_nomips16] } {
12323 if { [check_effective_target_mpaired_single "-mpaired-single"] } {
12324 lappend EFFECTIVE_TARGETS mpaired_single
12325 }
12326 if { [check_effective_target_mips_loongson_mmi "-mloongson-mmi"] } {
12327 lappend EFFECTIVE_TARGETS mips_loongson_mmi
12328 }
12329 if { [check_effective_target_mips_msa "-mmsa"] } {
12330 lappend EFFECTIVE_TARGETS mips_msa
12331 }
12332 return [llength $EFFECTIVE_TARGETS]
12333 } elseif [istarget sparc*-*-*] {
12334 lappend DEFAULT_VECTCFLAGS "-mcpu=ultrasparc" "-mvis"
12335 if [check_effective_target_ultrasparc_hw] {
12336 set dg-do-what-default run
12337 } else {
12338 set dg-do-what-default compile
12339 }
12340 } elseif [istarget alpha*-*-*] {
12341 # Alpha's vectorization capabilities are extremely limited.
12342 # It's more effort than its worth disabling all of the tests
12343 # that it cannot pass. But if you actually want to see what
12344 # does work, command out the return.
12345 return 0
12346
12347 lappend DEFAULT_VECTCFLAGS "-mmax"
12348 if [check_alpha_max_hw_available] {
12349 set dg-do-what-default run
12350 } else {
12351 set dg-do-what-default compile
12352 }
12353 } elseif [istarget ia64-*-*] {
12354 set dg-do-what-default run
12355 } elseif [is-effective-target arm_neon_ok] {
12356 eval lappend DEFAULT_VECTCFLAGS [add_options_for_arm_neon ""]
12357 # NEON does not support denormals, so is not used for vectorization by
12358 # default to avoid loss of precision. We must pass -ffast-math to test
12359 # vectorization of float operations.
12360 lappend DEFAULT_VECTCFLAGS "-ffast-math"
12361 if [is-effective-target arm_neon_hw] {
12362 set dg-do-what-default run
12363 } else {
12364 set dg-do-what-default compile
12365 }
12366 } elseif [istarget aarch64*-*-*] {
12367 set dg-do-what-default run
12368 } elseif [istarget s390*-*-*] {
12369 # The S/390 backend set a default of 2 for that value.
12370 # Override it to have the same situation as with other
12371 # targets.
12372 lappend DEFAULT_VECTCFLAGS "--param" "min-vect-loop-bound=1"
12373 lappend DEFAULT_VECTCFLAGS "--param" "max-unrolled-insns=200"
12374 lappend DEFAULT_VECTCFLAGS "--param" "max-unroll-times=8"
12375 lappend DEFAULT_VECTCFLAGS "--param" "max-completely-peeled-insns=200"
12376 lappend DEFAULT_VECTCFLAGS "--param" "max-completely-peel-times=16"
12377 if [check_effective_target_s390_vxe2] {
12378 lappend DEFAULT_VECTCFLAGS "-march=z15" "-mzarch"
12379 set dg-do-what-default run
12380 } elseif [check_effective_target_s390_vxe] {
12381 lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch"
12382 set dg-do-what-default run
12383 } elseif [check_effective_target_s390_vx] {
12384 lappend DEFAULT_VECTCFLAGS "-march=z13" "-mzarch"
12385 set dg-do-what-default run
12386 } else {
12387 lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch"
12388 set dg-do-what-default compile
12389 }
12390 } elseif [istarget amdgcn-*-*] {
12391 set dg-do-what-default run
12392 } elseif [istarget riscv*-*-*] {
12393 if [check_effective_target_riscv_v] {
12394 set dg-do-what-default run
12395 if [check_effective_target_riscv_v_misalign_ok] {
12396 lappend DEFAULT_VECTCFLAGS "-mno-vector-strict-align"
12397 }
12398 } elseif [check_effective_target_riscv_v_ok] {
12399 foreach item [add_options_for_riscv_v ""] {
12400 lappend DEFAULT_VECTCFLAGS $item
12401 }
12402 set dg-do-what-default compile
12403 } else {
12404 # Current architecture cannot support vectors (e.g. the
12405 # dependent D extension is missing).
12406 return 0
12407 }
12408 } elseif [istarget loongarch*-*-*] {
12409 # Set the default vectorization option to "-mlsx" due to the problem
12410 # of non-aligned memory access when using 256-bit vectorization.
12411 lappend DEFAULT_VECTCFLAGS "-mdouble-float" "-mlsx"
12412 if [check_effective_target_loongarch_sx_hw] {
12413 set dg-do-what-default run
12414 } else {
12415 set dg-do-what-default compile
12416 }
12417 } else {
12418 return 0
12419 }
12420
12421 return 1
12422 }
12423
12424 # Return 1 if the target does *not* require strict alignment.
12425
12426 proc check_effective_target_non_strict_align {} {
12427
12428 # On ARM, the default is to use STRICT_ALIGNMENT, but there
12429 # are interfaces defined for misaligned access and thus
12430 # depending on the architecture levels unaligned access is
12431 # available.
12432 if [istarget "arm*-*-*"] {
12433 return [check_effective_target_arm_unaligned]
12434 }
12435
12436 return [check_no_compiler_messages non_strict_align assembly {
12437 char *y;
12438 typedef char __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) c;
12439 c *z;
12440 void foo(void) { z = (c *) y; }
12441 } "-Wcast-align"]
12442 }
12443
12444 # Return 1 if the target supports -mstrict-align (and -mno-strict-align).
12445
12446 proc check_effective_target_opt_mstrict_align {} {
12447 return [check_no_compiler_messages opt_mstrict_align assembly {
12448 void foo(void) {}
12449 } "-mstrict-align -mno-strict-align"]
12450 }
12451
12452 # Return 1 if the target has <ucontext.h>.
12453
12454 proc check_effective_target_ucontext_h { } {
12455 return [check_no_compiler_messages ucontext_h assembly {
12456 #include <ucontext.h>
12457 }]
12458 }
12459
12460 proc check_effective_target_aarch64_tiny { } {
12461 if { [istarget aarch64*-*-*] } {
12462 return [check_no_compiler_messages aarch64_tiny object {
12463 #ifdef __AARCH64_CMODEL_TINY__
12464 int dummy;
12465 #else
12466 #error target not AArch64 tiny code model
12467 #endif
12468 }]
12469 } else {
12470 return 0
12471 }
12472 }
12473
12474 # Create functions to check that the AArch64 assembler supports the
12475 # various architecture extensions via the .arch_extension pseudo-op.
12476
12477 set exts {
12478 "bf16" "crc" "crypto" "dotprod" "f32mm" "f64mm" "fp" "fp8"
12479 "fp8dot2" "fp8dot4" "fp8fma" "i8mm" "ls64" "lse" "lut" "sb" "simd"
12480 "sve-b16b16" "sve" "sve2"
12481 }
12482
12483 # We don't support SME without SVE2, so we'll use armv9 as the base
12484 # archiecture for SME and the features that require it.
12485 set exts_sve2 {
12486 "sme-b16b16" "sme-f16f16" "sme-i16i64" "sme" "sme2" "sme2p1"
12487 "ssve-fp8dot2" "ssve-fp8dot4" "ssve-fp8fma"
12488 }
12489
12490 foreach { aarch64_ext } $exts {
12491 eval [string map [list FUNC $aarch64_ext] {
12492 proc check_effective_target_aarch64_asm_FUNC_ok { } {
12493 if { [istarget aarch64*-*-*] } {
12494 return [check_no_compiler_messages aarch64_FUNC_assembler object {
12495 __asm__ (".arch_extension FUNC");
12496 } "-march=armv8-a+FUNC"]
12497 } else {
12498 return 0
12499 }
12500 }
12501 }]
12502 }
12503
12504 foreach { aarch64_ext } $exts_sve2 {
12505 eval [string map [list FUNC $aarch64_ext] {
12506 proc check_effective_target_aarch64_asm_FUNC_ok { } {
12507 if { [istarget aarch64*-*-*] } {
12508 return [check_no_compiler_messages aarch64_FUNC_assembler object {
12509 __asm__ (".arch_extension FUNC");
12510 } "-march=armv9-a+FUNC"]
12511 } else {
12512 return 0
12513 }
12514 }
12515 }]
12516 }
12517
12518 proc check_effective_target_aarch64_asm_sve2p1_ok { } {
12519 if { [istarget aarch64*-*-*] } {
12520 return [check_no_compiler_messages aarch64_sve2p1_assembler object {
12521 __asm__ (".arch_extension sve2p1; ld1w {z0.q},p7/z,[x0]");
12522 } "-march=armv8-a+sve2p1"]
12523 } else {
12524 return 0
12525 }
12526 }
12527
12528 proc check_effective_target_aarch64_small { } {
12529 if { [istarget aarch64*-*-*] } {
12530 return [check_no_compiler_messages aarch64_small object {
12531 #ifdef __AARCH64_CMODEL_SMALL__
12532 int dummy;
12533 #else
12534 #error target not AArch64 small code model
12535 #endif
12536 }]
12537 } else {
12538 return 0
12539 }
12540 }
12541
12542 proc check_effective_target_aarch64_large { } {
12543 if { [istarget aarch64*-*-*] } {
12544 return [check_no_compiler_messages aarch64_large object {
12545 #ifdef __AARCH64_CMODEL_LARGE__
12546 int dummy;
12547 #else
12548 #error target not AArch64 large code model
12549 #endif
12550 }]
12551 } else {
12552 return 0
12553 }
12554 }
12555
12556 # Return 1 if the assembler accepts the aarch64 .variant_pcs directive.
12557
12558 proc check_effective_target_aarch64_variant_pcs { } {
12559 if { [istarget aarch64*-*-*] } {
12560 return [check_no_compiler_messages aarch64_variant_pcs object {
12561 __asm__ (".variant_pcs foo");
12562 }]
12563 } else {
12564 return 0
12565 }
12566 }
12567
12568 # Return 1 if this is a reduced AVR Tiny core. Such cores have different
12569 # register set, instruction set, addressing capabilities and ABI.
12570
12571 proc check_effective_target_avr_tiny { } {
12572 if { [istarget avr*-*-*] } {
12573 return [check_no_compiler_messages avr_tiny object {
12574 #ifdef __AVR_TINY__
12575 int dummy;
12576 #else
12577 #error target not a reduced AVR Tiny core
12578 #endif
12579 }]
12580 } else {
12581 return 0
12582 }
12583 }
12584
12585 # Return 1 if <fenv.h> is available.
12586
12587 proc check_effective_target_fenv {} {
12588 return [check_no_compiler_messages fenv object {
12589 #include <fenv.h>
12590 } [add_options_for_ieee "-std=gnu99"]]
12591 }
12592
12593 # Return 1 if <fenv.h> is available with all the standard IEEE
12594 # exceptions and floating-point exceptions are raised by arithmetic
12595 # operations. (If the target requires special options for "inexact"
12596 # exceptions, those need to be specified in the testcases.)
12597
12598 proc check_effective_target_fenv_exceptions {} {
12599 return [check_runtime fenv_exceptions {
12600 #include <fenv.h>
12601 #include <stdlib.h>
12602 #ifndef FE_DIVBYZERO
12603 # error Missing FE_DIVBYZERO
12604 #endif
12605 #ifndef FE_INEXACT
12606 # error Missing FE_INEXACT
12607 #endif
12608 #ifndef FE_INVALID
12609 # error Missing FE_INVALID
12610 #endif
12611 #ifndef FE_OVERFLOW
12612 # error Missing FE_OVERFLOW
12613 #endif
12614 #ifndef FE_UNDERFLOW
12615 # error Missing FE_UNDERFLOW
12616 #endif
12617 volatile float a = 0.0f, r;
12618 int
12619 main (void)
12620 {
12621 r = a / a;
12622 if (fetestexcept (FE_INVALID))
12623 exit (0);
12624 else
12625 abort ();
12626 }
12627 } [add_options_for_ieee "-std=gnu99"]]
12628 }
12629
12630 # Return 1 if <fenv.h> is available with all the standard IEEE
12631 # exceptions and floating-point exceptions are raised by arithmetic
12632 # operations for decimal floating point. (If the target requires
12633 # special options for "inexact" exceptions, those need to be specified
12634 # in the testcases.)
12635
12636 proc check_effective_target_fenv_exceptions_dfp {} {
12637 return [check_runtime fenv_exceptions_dfp {
12638 #include <fenv.h>
12639 #include <stdlib.h>
12640 #ifndef FE_DIVBYZERO
12641 # error Missing FE_DIVBYZERO
12642 #endif
12643 #ifndef FE_INEXACT
12644 # error Missing FE_INEXACT
12645 #endif
12646 #ifndef FE_INVALID
12647 # error Missing FE_INVALID
12648 #endif
12649 #ifndef FE_OVERFLOW
12650 # error Missing FE_OVERFLOW
12651 #endif
12652 #ifndef FE_UNDERFLOW
12653 # error Missing FE_UNDERFLOW
12654 #endif
12655 volatile _Decimal64 a = 0.0DD, r;
12656 int
12657 main (void)
12658 {
12659 r = a / a;
12660 if (fetestexcept (FE_INVALID))
12661 exit (0);
12662 else
12663 abort ();
12664 }
12665 } [add_options_for_ieee "-std=gnu99"]]
12666 }
12667
12668 # Return 1 if <fenv.h> is available with all the standard IEEE
12669 # exceptions and floating-point exceptions are raised by arithmetic
12670 # operations. (If the target requires special options for "inexact"
12671 # exceptions, those need to be specified in the testcases.)
12672
12673 proc check_effective_target_fenv_exceptions_double {} {
12674 return [check_runtime fenv_exceptions_double {
12675 #include <fenv.h>
12676 #include <stdlib.h>
12677 #ifndef FE_DIVBYZERO
12678 # error Missing FE_DIVBYZERO
12679 #endif
12680 #ifndef FE_INEXACT
12681 # error Missing FE_INEXACT
12682 #endif
12683 #ifndef FE_INVALID
12684 # error Missing FE_INVALID
12685 #endif
12686 #ifndef FE_OVERFLOW
12687 # error Missing FE_OVERFLOW
12688 #endif
12689 #ifndef FE_UNDERFLOW
12690 # error Missing FE_UNDERFLOW
12691 #endif
12692 volatile double a = 0.0f, r;
12693 int
12694 main (void)
12695 {
12696 r = a / a;
12697 if (fetestexcept (FE_INVALID))
12698 exit (0);
12699 else
12700 abort ();
12701 }
12702 } [add_options_for_ieee "-std=gnu99"]]
12703 }
12704
12705 # Return 1 if <fenv.h> is available with all the standard IEEE
12706 # exceptions and floating-point exceptions are raised by arithmetic
12707 # operations. (If the target requires special options for "inexact"
12708 # exceptions, those need to be specified in the testcases.)
12709
12710 proc check_effective_target_fenv_exceptions_long_double {} {
12711 return [check_runtime fenv_exceptions_long_double {
12712 #include <fenv.h>
12713 #include <stdlib.h>
12714 #ifndef FE_DIVBYZERO
12715 # error Missing FE_DIVBYZERO
12716 #endif
12717 #ifndef FE_INEXACT
12718 # error Missing FE_INEXACT
12719 #endif
12720 #ifndef FE_INVALID
12721 # error Missing FE_INVALID
12722 #endif
12723 #ifndef FE_OVERFLOW
12724 # error Missing FE_OVERFLOW
12725 #endif
12726 #ifndef FE_UNDERFLOW
12727 # error Missing FE_UNDERFLOW
12728 #endif
12729 volatile long double a = 0.0f, r;
12730 int
12731 main (void)
12732 {
12733 r = a / a;
12734 if (fetestexcept (FE_INVALID))
12735 exit (0);
12736 else
12737 abort ();
12738 }
12739 } [add_options_for_ieee "-std=gnu99"]]
12740 }
12741
12742 # Check whether the target supports exception handling.
12743 # Note that this is orthogonal to effective-target 'exceptions_enabled'.
12744
12745 proc check_effective_target_exceptions {} {
12746 if { [istarget amdgcn*-*-*]
12747 || [istarget bpf-*-*]
12748 || [istarget nvptx-*-*] } {
12749 return 0
12750 }
12751 return 1
12752 }
12753
12754 # Check whether the testing configuration has exception handling enabled.
12755 # Returns 0 if exception handling is disabled (e.g. by passing
12756 # -fno-exceptions). Returns 1 if exception handling is enabled.
12757 # Note that this is orthogonal to effective-target 'exceptions'.
12758
12759 proc check_effective_target_exceptions_enabled {} {
12760 return [check_cached_effective_target exceptions_enabled {
12761 return [check_no_compiler_messages exceptions_enabled assembly {
12762 // C++
12763 void foo (void)
12764 {
12765 throw 1;
12766 }
12767 }]
12768 }]
12769 }
12770
12771 proc check_effective_target_tiny {} {
12772 return [check_cached_effective_target tiny {
12773 if { [istarget aarch64*-*-*]
12774 && [check_effective_target_aarch64_tiny] } {
12775 return 1
12776 }
12777 if { [istarget avr-*-*]
12778 && [check_effective_target_avr_tiny] } {
12779 return 1
12780 }
12781 # PRU Program Counter is 16-bits, and trampolines are not supported.
12782 # Hence directly declare as a tiny target.
12783 if [istarget pru-*-*] {
12784 return 1
12785 }
12786 return 0
12787 }]
12788 }
12789
12790 # Return 1 if the target supports -mbranch-cost=N option.
12791
12792 proc check_effective_target_branch_cost {} {
12793 if { [ istarget arm*-*-*]
12794 || [istarget avr*-*-*]
12795 || [istarget csky*-*-*]
12796 || [istarget epiphany*-*-*]
12797 || [istarget frv*-*-*]
12798 || [check_effective_target_x86]
12799 || [istarget loongarch*-*-*]
12800 || [istarget mips*-*-*]
12801 || [istarget s390*-*-*]
12802 || [istarget riscv*-*-*]
12803 || [istarget sh*-*-*] } {
12804 return 1
12805 }
12806 return 0
12807 }
12808
12809 # Record that dg-final test TEST requires convential compilation.
12810
12811 proc set_required_options_for { test } {
12812 if { [info proc $test] == "" } {
12813 perror "$test does not exist"
12814 exit 1
12815 }
12816 proc ${test}_required_options {} {
12817 global gcc_set_required_options
12818 upvar 1 extra_tool_flags extra_tool_flags
12819 if {[regexp -- "^scan-assembler" [info level 0]]
12820 && ![string match "*-fident*" $extra_tool_flags]} {
12821 # Do not let .ident confuse assembler scan tests
12822 return [list $gcc_set_required_options "-fno-ident"]
12823 }
12824 return $gcc_set_required_options
12825 }
12826 }
12827
12828 # Record that dg-final test scan-ltrans-tree-dump* requires -flto-partition=one
12829 # in order to force a single partition, allowing scan-ltrans-tree-dump* to scan
12830 # a dump file *.exe.ltrans0.*.
12831
12832 proc scan-ltrans-tree-dump_required_options {} {
12833 return "-flto-partition=one"
12834 }
12835 proc scan-ltrans-tree-dump-times_required_options {} {
12836 return "-flto-partition=one"
12837 }
12838 proc scan-ltrans-tree-dump-not_required_options {} {
12839 return "-flto-partition=one"
12840 }
12841 proc scan-ltrans-tree-dump-dem_required_options {} {
12842 return "-flto-partition=one"
12843 }
12844 proc scan-ltrans-tree-dump-dem-not_required_options {} {
12845 return "-flto-partition=one"
12846 }
12847
12848 # Return 1 if the x86-64 target supports PIE with copy reloc, 0
12849 # otherwise. Cache the result.
12850
12851 proc check_effective_target_pie_copyreloc { } {
12852 global tool
12853 global GCC_UNDER_TEST
12854
12855 if { ![check_effective_target_x86] } {
12856 return 0
12857 }
12858
12859 # Need auto-host.h to check linker support.
12860 if { ![file exists ../../auto-host.h ] } {
12861 return 0
12862 }
12863
12864 return [check_cached_effective_target pie_copyreloc {
12865 # Set up and compile to see if linker supports PIE with copy
12866 # reloc. Include the current process ID in the file names to
12867 # prevent conflicts with invocations for multiple testsuites.
12868
12869 set src pie[pid].c
12870 set obj pie[pid].o
12871
12872 set f [open $src "w"]
12873 puts $f "#include \"../../auto-host.h\""
12874 puts $f "#if HAVE_LD_PIE_COPYRELOC == 0"
12875 puts $f "# error Linker does not support PIE with copy reloc."
12876 puts $f "#endif"
12877 close $f
12878
12879 verbose "check_effective_target_pie_copyreloc compiling testfile $src" 2
12880 set lines [${tool}_target_compile $src $obj object ""]
12881
12882 file delete $src
12883 file delete $obj
12884
12885 if [string match "" $lines] then {
12886 verbose "check_effective_target_pie_copyreloc testfile compilation passed" 2
12887 return 1
12888 } else {
12889 verbose "check_effective_target_pie_copyreloc testfile compilation failed" 2
12890 return 0
12891 }
12892 }]
12893 }
12894
12895 # Return 1 if the x86-64 target supports R_X86_64_CODE_6_GOTTPOFF
12896 # relocation, 0 otherwise. Cache the result.
12897
12898 proc check_effective_target_code_6_gottpoff_reloc { } {
12899 global tool
12900 global GCC_UNDER_TEST
12901
12902 if { ![check_effective_target_x86] } {
12903 return 0
12904 }
12905
12906 # Need auto-host.h to check linker support.
12907 if { ![file exists ../../auto-host.h ] } {
12908 return 0
12909 }
12910
12911 return [check_cached_effective_target code_6_gottpoff_reloc {
12912 # Include the current process ID in the file names to prevent
12913 # conflicts with invocations for multiple testsuites.
12914
12915 set src code_6_gottpoff[pid].c
12916 set obj code_6_gottpoff[pid].o
12917
12918 set f [open $src "w"]
12919 puts $f "#include \"../../auto-host.h\""
12920 puts $f "#if HAVE_AS_R_X86_64_CODE_6_GOTTPOFF == 0"
12921 puts $f "# error Assembler does not support R_X86_64_CODE_6_GOTTPOFF."
12922 puts $f "#endif"
12923 close $f
12924
12925 verbose "check_effective_target_code_6_gottpoff_reloc compiling testfile $src" 2
12926 set lines [${tool}_target_compile $src $obj object ""]
12927
12928 file delete $src
12929 file delete $obj
12930
12931 if [string match "" $lines] then {
12932 verbose "check_effective_target_code_6_gottpoff_reloc testfile compilation passed" 2
12933 return 1
12934 } else {
12935 verbose "check_effective_target_code_6_gottpoff_reloc testfile compilation failed" 2
12936 return 0
12937 }
12938 }]
12939
12940 return $code_6_gottpoff_reloc_available_saved
12941 }
12942
12943 # Return 1 if the x86 target supports R_386_GOT32X relocation, 0
12944 # otherwise. Cache the result.
12945
12946 proc check_effective_target_got32x_reloc { } {
12947 global tool
12948 global GCC_UNDER_TEST
12949
12950 if { ![check_effective_target_x86] } {
12951 return 0
12952 }
12953
12954 # Need auto-host.h to check linker support.
12955 if { ![file exists ../../auto-host.h ] } {
12956 return 0
12957 }
12958
12959 return [check_cached_effective_target got32x_reloc {
12960 # Include the current process ID in the file names to prevent
12961 # conflicts with invocations for multiple testsuites.
12962
12963 set src got32x[pid].c
12964 set obj got32x[pid].o
12965
12966 set f [open $src "w"]
12967 puts $f "#include \"../../auto-host.h\""
12968 puts $f "#if HAVE_AS_IX86_GOT32X == 0"
12969 puts $f "# error Assembler does not support R_386_GOT32X."
12970 puts $f "#endif"
12971 close $f
12972
12973 verbose "check_effective_target_got32x_reloc compiling testfile $src" 2
12974 set lines [${tool}_target_compile $src $obj object ""]
12975
12976 file delete $src
12977 file delete $obj
12978
12979 if [string match "" $lines] then {
12980 verbose "check_effective_target_got32x_reloc testfile compilation passed" 2
12981 return 1
12982 } else {
12983 verbose "check_effective_target_got32x_reloc testfile compilation failed" 2
12984 return 0
12985 }
12986 }]
12987
12988 return $got32x_reloc_available_saved
12989 }
12990
12991 # Return 1 if the x86 target supports calling ___tls_get_addr via GOT,
12992 # 0 otherwise. Cache the result.
12993
12994 proc check_effective_target_tls_get_addr_via_got { } {
12995 global tool
12996 global GCC_UNDER_TEST
12997
12998 if { ![check_effective_target_x86] } {
12999 return 0
13000 }
13001
13002 # Need auto-host.h to check linker support.
13003 if { ![file exists ../../auto-host.h ] } {
13004 return 0
13005 }
13006
13007 return [check_cached_effective_target tls_get_addr_via_got {
13008 # Include the current process ID in the file names to prevent
13009 # conflicts with invocations for multiple testsuites.
13010
13011 set src tls_get_addr_via_got[pid].c
13012 set obj tls_get_addr_via_got[pid].o
13013
13014 set f [open $src "w"]
13015 puts $f "#include \"../../auto-host.h\""
13016 puts $f "#if HAVE_AS_IX86_TLS_GET_ADDR_GOT == 0"
13017 puts $f "# error Assembler/linker do not support calling ___tls_get_addr via GOT."
13018 puts $f "#endif"
13019 close $f
13020
13021 verbose "check_effective_target_tls_get_addr_via_got compiling testfile $src" 2
13022 set lines [${tool}_target_compile $src $obj object ""]
13023
13024 file delete $src
13025 file delete $obj
13026
13027 if [string match "" $lines] then {
13028 verbose "check_effective_target_tls_get_addr_via_got testfile compilation passed" 2
13029 return 1
13030 } else {
13031 verbose "check_effective_target_tls_get_addr_via_got testfile compilation failed" 2
13032 return 0
13033 }
13034 }]
13035 }
13036
13037 # Return 1 if the target uses comdat groups.
13038
13039 proc check_effective_target_comdat_group {} {
13040 return [check_no_messages_and_pattern comdat_group "\.section\[^\n\r]*,comdat|\.group\[^\n\r]*,#comdat" assembly {
13041 // C++
13042 inline int foo () { return 1; }
13043 int (*fn) () = foo;
13044 }]
13045 }
13046
13047 # Return 1 if target supports __builtin_eh_return
13048 proc check_effective_target_builtin_eh_return { } {
13049 return [check_no_compiler_messages builtin_eh_return object {
13050 void test (long l, void *p)
13051 {
13052 __builtin_eh_return (l, p);
13053 }
13054 } "" ]
13055 }
13056
13057 # Return 1 if the target supports max reduction for vectors.
13058
13059 proc check_effective_target_vect_max_reduc { } {
13060 if { [istarget aarch64*-*-*] || [is-effective-target arm_neon]
13061 || [check_effective_target_riscv_v]
13062 || [check_effective_target_loongarch_sx] } {
13063 return 1
13064 }
13065 return 0
13066 }
13067
13068 # Return 1 if the compiler has been configured with nvptx offloading.
13069
13070 proc check_effective_target_offload_nvptx { } {
13071 return [check_no_compiler_messages offload_nvptx assembly {
13072 int main () {return 0;}
13073 } "-foffload=nvptx-none" ]
13074 }
13075
13076 # Return 1 if the compiler has been configured with gcn offloading.
13077
13078 proc check_effective_target_offload_gcn { } {
13079 return [check_no_compiler_messages offload_gcn assembly {
13080 int main () {return 0;}
13081 } "-foffload=amdgcn-amdhsa" ]
13082 }
13083
13084 # Return 1 if the target support -fprofile-update=atomic
13085 proc check_effective_target_profile_update_atomic {} {
13086 return [check_no_compiler_messages profile_update_atomic assembly {
13087 int main (void) { return 0; }
13088 } "-fprofile-update=atomic -fprofile-generate"]
13089 }
13090
13091 # Return 1 if the target has a vector facility.
13092 proc check_effective_target_s390_mvx { } {
13093 if ![istarget s390*-*-*] then {
13094 return 0;
13095 }
13096
13097 return [check_no_compiler_messages_nocache s390_mvx assembly {
13098 #if !defined __VX__
13099 #error no vector facility.
13100 #endif
13101 int dummy;
13102 } [current_compiler_flags]]
13103 }
13104
13105 # Return 1 if vector (va - vector add) instructions are understood by
13106 # the assembler and can be executed. This also covers checking for
13107 # the VX kernel feature. A kernel without that feature does not
13108 # enable the vector facility and the following check will die with a
13109 # signal.
13110 proc check_effective_target_s390_vx { } {
13111 if ![istarget s390*-*-*] then {
13112 return 0;
13113 }
13114
13115 return [check_runtime s390_check_vx {
13116 int main (void)
13117 {
13118 asm ("va %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
13119 return 0;
13120 }
13121 } "-march=z13 -mzarch" ]
13122 }
13123
13124 # Same as above but for the z14 vector enhancement facility. Test
13125 # is performed with the vector nand instruction.
13126 proc check_effective_target_s390_vxe { } {
13127 if ![istarget s390*-*-*] then {
13128 return 0;
13129 }
13130
13131 return [check_runtime s390_check_vxe {
13132 int main (void)
13133 {
13134 asm ("vnn %%v24, %%v26, %%v28" : : : "v24", "v26", "v28");
13135 return 0;
13136 }
13137 } "-march=z14 -mzarch" ]
13138 }
13139
13140 # Same as above but for the arch13 vector enhancement facility. Test
13141 # is performed with the vector shift left double by bit instruction.
13142 proc check_effective_target_s390_vxe2 { } {
13143 if ![istarget s390*-*-*] then {
13144 return 0;
13145 }
13146
13147 return [check_runtime s390_check_vxe2 {
13148 int main (void)
13149 {
13150 asm ("vsld %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
13151 return 0;
13152 }
13153 } "-march=arch13 -mzarch" ]
13154 }
13155
13156 # Same as above but for the arch15 vector enhancement facility. Test
13157 # is performed with the vector divide instruction.
13158 proc check_effective_target_s390_vxe3 { } {
13159 if ![istarget s390*-*-*] then {
13160 return 0;
13161 }
13162
13163 return [check_runtime s390_check_vxe3 {
13164 int main (void)
13165 {
13166 asm ("vd %%v24, %%v26, %%v28, 2, 0" : : : "v24", "v26", "v28");
13167 return 0;
13168 }
13169 } "-march=arch15 -mzarch" ]
13170 }
13171
13172 # Same as above but for the arch14 NNPA facility.
13173 proc check_effective_target_s390_nnpa { } {
13174 if ![istarget s390*-*-*] then {
13175 return 0;
13176 }
13177
13178 return [check_runtime s390_check_nnpa {
13179 int main (void)
13180 {
13181 asm ("vzero %%v24\n\t"
13182 "vcrnf %%v24,%%v24,%%v24,0,2" : : : "v24");
13183 return 0;
13184 }
13185 } "-march=arch14 -mzarch" ]
13186 }
13187
13188 #For versions of ARM architectures that have hardware div insn,
13189 #disable the divmod transform
13190
13191 proc check_effective_target_arm_divmod_simode { } {
13192 return [check_no_compiler_messages arm_divmod assembly {
13193 #ifdef __ARM_ARCH_EXT_IDIV__
13194 #error has div insn
13195 #endif
13196 int i;
13197 }]
13198 }
13199
13200 # Return 1 if target supports divmod hardware insn or divmod libcall.
13201
13202 proc check_effective_target_divmod { } {
13203 #TODO: Add checks for all targets that have either hardware divmod insn
13204 # or define libfunc for divmod.
13205 if { [istarget arm*-*-*]
13206 || [check_effective_target_x86]
13207 || [istarget amdgcn-*-*] } {
13208 return 1
13209 }
13210 return 0
13211 }
13212
13213 # Return 1 if target supports divmod for SImode. The reason for
13214 # separating this from check_effective_target_divmod is that
13215 # some versions of ARM architecture define div instruction
13216 # only for simode, and for these archs, we do not want to enable
13217 # divmod transform for simode.
13218
13219 proc check_effective_target_divmod_simode { } {
13220 if { [istarget arm*-*-*] } {
13221 return [check_effective_target_arm_divmod_simode]
13222 }
13223
13224 return [check_effective_target_divmod]
13225 }
13226
13227 # Return 1 if store merging optimization is applicable for target.
13228 # Store merging is not profitable for targets like the avr which
13229 # can load/store only one byte at a time. Use int size as a proxy
13230 # for the number of bytes the target can write, and skip for targets
13231 # with a smallish (< 32) size.
13232
13233 proc check_effective_target_store_merge { } {
13234 if { [is-effective-target non_strict_align ] && [is-effective-target int32plus] } {
13235 return 1
13236 }
13237
13238 return 0
13239 }
13240
13241 # Return 1 if we're able to assemble rdrand
13242
13243 proc check_effective_target_rdrand { } {
13244 return [check_no_compiler_messages_nocache rdrand object {
13245 unsigned int
13246 __foo(void)
13247 {
13248 unsigned int val;
13249 __builtin_ia32_rdrand32_step(&val);
13250 return val;
13251 }
13252 } "-mrdrnd" ]
13253 }
13254
13255 # Return 1 if the target supports coprocessor instructions: cdp, ldc, ldcl,
13256 # stc, stcl, mcr and mrc.
13257 proc check_effective_target_arm_coproc1_ok_nocache { } {
13258 if { ![istarget arm*-*-*] } {
13259 return 0
13260 }
13261 return [check_no_compiler_messages_nocache arm_coproc1_ok assembly {
13262 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 4
13263 #error FOO
13264 #endif
13265 #include <arm_acle.h>
13266 }]
13267 }
13268
13269 proc check_effective_target_arm_coproc1_ok { } {
13270 return [check_cached_effective_target arm_coproc1_ok \
13271 check_effective_target_arm_coproc1_ok_nocache]
13272 }
13273
13274 # Return 1 if the target supports all coprocessor instructions checked by
13275 # check_effective_target_arm_coproc1_ok in addition to the following: cdp2,
13276 # ldc2, ldc2l, stc2, stc2l, mcr2 and mrc2.
13277 proc check_effective_target_arm_coproc2_ok_nocache { } {
13278 if { ![check_effective_target_arm_coproc1_ok] } {
13279 return 0
13280 }
13281 return [check_no_compiler_messages_nocache arm_coproc2_ok assembly {
13282 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 5
13283 #error FOO
13284 #endif
13285 #include <arm_acle.h>
13286 }]
13287 }
13288
13289 proc check_effective_target_arm_coproc2_ok { } {
13290 return [check_cached_effective_target arm_coproc2_ok \
13291 check_effective_target_arm_coproc2_ok_nocache]
13292 }
13293
13294 # Return 1 if the target supports all coprocessor instructions checked by
13295 # check_effective_target_arm_coproc2_ok in addition the following: mcrr and
13296 # mrrc.
13297 proc check_effective_target_arm_coproc3_ok_nocache { } {
13298 if { ![check_effective_target_arm_coproc2_ok] } {
13299 return 0
13300 }
13301 return [check_no_compiler_messages_nocache arm_coproc3_ok assembly {
13302 #if (__thumb__ && !__thumb2__) \
13303 || (__ARM_ARCH < 6 && !defined (__ARM_ARCH_5TE__))
13304 #error FOO
13305 #endif
13306 #include <arm_acle.h>
13307 }]
13308 }
13309
13310 proc check_effective_target_arm_coproc3_ok { } {
13311 return [check_cached_effective_target arm_coproc3_ok \
13312 check_effective_target_arm_coproc3_ok_nocache]
13313 }
13314
13315 # Return 1 if the target supports all coprocessor instructions checked by
13316 # check_effective_target_arm_coproc3_ok in addition the following: mcrr2 and
13317 # mrcc2.
13318 proc check_effective_target_arm_coproc4_ok_nocache { } {
13319 if { ![check_effective_target_arm_coproc3_ok] } {
13320 return 0
13321 }
13322 return [check_no_compiler_messages_nocache arm_coproc4_ok assembly {
13323 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 6
13324 #error FOO
13325 #endif
13326 #include <arm_acle.h>
13327 }]
13328 }
13329
13330 proc check_effective_target_arm_coproc4_ok { } {
13331 return [check_cached_effective_target arm_coproc4_ok \
13332 check_effective_target_arm_coproc4_ok_nocache]
13333 }
13334
13335 # Return 1 if the target supports the auto_inc_dec optimization pass.
13336 proc check_effective_target_autoincdec { } {
13337 if { ![check_no_compiler_messages auto_incdec assembly { void f () { }
13338 } "-O2 -fdump-rtl-auto_inc_dec" ] } {
13339 return 0
13340 }
13341
13342 set dumpfile [glob -nocomplain "auto_incdec[pid].c.\[0-9\]\[0-9\]\[0-9\]r.auto_inc_dec"]
13343 if { [file exists $dumpfile ] } {
13344 file delete $dumpfile
13345 return 1
13346 }
13347 return 0
13348 }
13349
13350 # Return 1 if the target has support for stack probing designed
13351 # to avoid stack-clash style attacks.
13352 #
13353 # This is used to restrict the stack-clash mitigation tests to
13354 # just those targets that have been explicitly supported.
13355 #
13356 # In addition to the prologue work on those targets, each target's
13357 # properties should be described in the functions below so that
13358 # tests do not become a mess of unreadable target conditions.
13359 #
13360 proc check_effective_target_supports_stack_clash_protection { } {
13361
13362 if { [check_effective_target_x86]
13363 || [istarget powerpc*-*-*] || [istarget rs6000*-*-*]
13364 || [istarget aarch64*-**] || [istarget s390*-*-*]
13365 || [istarget loongarch64*-**] || [istarget riscv64*-**] } {
13366 return 1
13367 }
13368 return 0
13369 }
13370
13371 # Return 1 if the target creates a frame pointer for non-leaf functions
13372 # Note we ignore cases where we apply tail call optimization here.
13373 proc check_effective_target_frame_pointer_for_non_leaf { } {
13374 # Solaris/x86 defaults to -fno-omit-frame-pointer.
13375 if { [check_effective_target_x86] && [istarget *-*-solaris*] } {
13376 return 1
13377 }
13378
13379 return 0
13380 }
13381
13382 # Return 1 if the target can perform tail-call optimizations of the
13383 # most trivial type.
13384 proc check_effective_target_tail_call { } {
13385 return [check_no_messages_and_pattern tail_call ",SIBCALL" rtl-expand {
13386 __attribute__((__noipa__)) void foo (void);
13387 __attribute__((__noipa__)) void bar (void) { foo(); }
13388 } {-O2 -fdump-rtl-expand-all}] ;# The "SIBCALL" note requires a detailed dump.
13389 }
13390
13391 # Return 1 if the target can perform musttail optimizations of the
13392 # most trivial type. This is separate from tail_call because musttail
13393 # is supported at -O0.
13394 proc check_effective_target_musttail { } {
13395 return [check_no_messages_and_pattern musttail ",SIBCALL" rtl-expand {
13396 __attribute__((__noipa__)) void foo (void);
13397 __attribute__((__noipa__)) void bar (void) { [[gnu::musttail]] return foo(); }
13398 } {-fdump-rtl-expand-all}] ;# The "SIBCALL" note requires a detailed dump.
13399 }
13400
13401 # Return 1 if the target can perform musttail for externals
13402 proc check_effective_target_external_musttail { } {
13403 return [check_no_messages_and_pattern external_musttail ",SIBCALL" rtl-expand {
13404 extern __attribute__((__noipa__)) void foo (void);
13405 __attribute__((__noipa__)) void bar (void) { [[gnu::musttail]] return foo(); }
13406 } {-fdump-rtl-expand-all}] ;# The "SIBCALL" note requires a detailed dump.
13407 }
13408
13409 # Return 1 if the target can perform musttail optimizations for structures
13410 # checking with C++ because the C++ compiler has less tail call ability
13411 # due to PR115606 on some targets
13412 proc check_effective_target_struct_musttail { } {
13413 return [check_no_messages_and_pattern struct_musttail ",SIBCALL" rtl-expand {
13414 // C++
13415 struct foo { int a, b; };
13416 extern __attribute__((__noipa__)) struct foo foo (void);
13417 __attribute__((__noipa__)) struct foo bar (void) { [[gnu::musttail]] return foo(); }
13418 } {-fdump-rtl-expand-all}] ;# The "SIBCALL" note requires a detailed dump.
13419 }
13420
13421 # Return 1 if the target's calling sequence or its ABI
13422 # create implicit stack probes at or prior to function entry.
13423 proc check_effective_target_caller_implicit_probes { } {
13424
13425 # On x86/x86_64 the call instruction itself pushes the return
13426 # address onto the stack. That is an implicit probe of *sp.
13427 if { [check_effective_target_x86] } {
13428 return 1
13429 }
13430
13431 # On PPC, the ABI mandates that the address of the outer
13432 # frame be stored at *sp. Thus each allocation of stack
13433 # space is itself an implicit probe of *sp.
13434 if { [istarget powerpc*-*-*] || [istarget rs6000*-*-*] } {
13435 return 1
13436 }
13437
13438 # s390's ABI has a register save area allocated by the
13439 # caller for use by the callee. The mere existence does
13440 # not constitute a probe by the caller, but when the slots
13441 # used by the callee those stores are implicit probes.
13442 if { [istarget s390*-*-*] } {
13443 return 1
13444 }
13445
13446 # Not strictly true on aarch64, but we have agreed that we will
13447 # consider any function that pushes SP more than 3kbytes into
13448 # the guard page as broken. This essentially means that we can
13449 # consider the aarch64 as having a caller implicit probe at
13450 # *(sp + 1k).
13451 if { [istarget aarch64*-*-*] } {
13452 return 1;
13453 }
13454
13455 if { [istarget riscv64*-*-*] } {
13456 return 1;
13457 }
13458
13459 if { [istarget loongarch64*-*-*] } {
13460 return 1;
13461 }
13462
13463 return 0
13464 }
13465
13466 # Targets that potentially realign the stack pointer often cause residual
13467 # stack allocations and make it difficult to elimination loops or residual
13468 # allocations for dynamic stack allocations
13469 proc check_effective_target_callee_realigns_stack { } {
13470 if { [check_effective_target_x86] } {
13471 return 1
13472 }
13473 return 0
13474 }
13475
13476 # Return 1 if CET instructions can be compiled.
13477 proc check_effective_target_cet { } {
13478 if { ![check_effective_target_x86] } {
13479 return 0
13480 }
13481 return [check_no_compiler_messages cet object {
13482 void foo (void)
13483 {
13484 asm ("setssbsy");
13485 }
13486 } "-O2 -fcf-protection" ]
13487 }
13488
13489 # Return 1 if target supports floating point "infinite"
13490 proc check_effective_target_inf { } {
13491 return [check_no_compiler_messages supports_inf assembly {
13492 const double pinf = __builtin_inf ();
13493 }]
13494 }
13495
13496 # Return 1 if target supports floating point "infinite" for float.
13497 proc check_effective_target_inff { } {
13498 return [check_no_compiler_messages supports_inff assembly {
13499 const float pinf = __builtin_inff ();
13500 }]
13501 }
13502
13503 # Return 1 if the target supports ARMv8.3 Adv.SIMD Complex instructions
13504 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
13505 # Record the command line options needed.
13506
13507 proc check_effective_target_arm_v8_3a_complex_neon_ok_nocache { } {
13508 global et_arm_v8_3a_complex_neon_flags
13509 set et_arm_v8_3a_complex_neon_flags ""
13510
13511 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
13512 return 0;
13513 }
13514
13515 if { [istarget arm*-*-*] } {
13516 set flag_opts {
13517 ""
13518 "-mcpu=unset -march=armv8.3-a+simd"
13519 "-mfloat-abi=softfp -mfpu=auto -mcpu=unset -march=armv8.3-a+simd"
13520 "-mfloat-abi=hard -mfpu=auto -mcpu=unset -march=armv8.3-a+simd"
13521 }
13522 } else {
13523 set flag_opts { "" "-march=armv8.3-a" }
13524 }
13525
13526 # Iterate through sets of options to find the compiler flags that
13527 # need to be added to the -march option.
13528 foreach flags $flag_opts {
13529 if { [check_no_compiler_messages_nocache \
13530 arm_v8_3a_complex_neon_ok assembly {
13531 #if !defined (__ARM_FEATURE_COMPLEX)
13532 #error "__ARM_FEATURE_COMPLEX not defined"
13533 #endif
13534 } "$flags"] } {
13535 set et_arm_v8_3a_complex_neon_flags "$flags"
13536 return 1;
13537 }
13538 }
13539
13540 return 0;
13541 }
13542
13543 proc check_effective_target_arm_v8_3a_complex_neon_ok { } {
13544 return [check_cached_effective_target arm_v8_3a_complex_neon_ok \
13545 check_effective_target_arm_v8_3a_complex_neon_ok_nocache]
13546 }
13547
13548 proc add_options_for_arm_v8_3a_complex_neon { flags } {
13549 if { ! [check_effective_target_arm_v8_3a_complex_neon_ok] } {
13550 return "$flags"
13551 }
13552 global et_arm_v8_3a_complex_neon_flags
13553 return "$flags $et_arm_v8_3a_complex_neon_flags"
13554 }
13555
13556 # Return 1 if the target supports ARMv8.3 Adv.SIMD + FP16 Complex instructions
13557 # instructions, 0 otherwise. The test is valid for ARM and for AArch64.
13558 # Record the command line options needed.
13559
13560 proc check_effective_target_arm_v8_3a_fp16_complex_neon_ok_nocache { } {
13561 global et_arm_v8_3a_fp16_complex_neon_flags
13562 set et_arm_v8_3a_fp16_complex_neon_flags ""
13563
13564 if { ![istarget arm*-*-*] && ![istarget aarch64*-*-*] } {
13565 return 0;
13566 }
13567
13568 if { [istarget arm*-*-*] } {
13569 set flag_opts {
13570 ""
13571 "-mfpu=auto -mcpu=unset -march=armv8.3-a+fp16+simd"
13572 "-mfloat-abi=softfp -mfpu=auto -mcpu=unset -march=armv8.3-a+fp16+simd"
13573 "-mfloat-abi=hard -mfpu=auto -mcpu=unset -march=armv8.3-a+fp16+simd"
13574 }
13575 } else {
13576 set flag_opts { "" "-march=armv8.3-a+fp16" }
13577 }
13578
13579 # Iterate through sets of options to find the compiler flags that
13580 # need to be added to the -march option.
13581 foreach flags $flag_opts {
13582 if { [check_no_compiler_messages_nocache \
13583 arm_v8_3a_fp16_complex_neon_ok assembly {
13584 #if !defined (__ARM_FEATURE_COMPLEX)
13585 #error "__ARM_FEATURE_COMPLEX not defined"
13586 #endif
13587 } "$flags"] } {
13588 set et_arm_v8_3a_fp16_complex_neon_flags "$flags"
13589 return 1;
13590 }
13591 }
13592
13593 return 0;
13594 }
13595
13596 proc check_effective_target_arm_v8_3a_fp16_complex_neon_ok { } {
13597 return [check_cached_effective_target arm_v8_3a_fp16_complex_neon_ok \
13598 check_effective_target_arm_v8_3a_fp16_complex_neon_ok_nocache]
13599 }
13600
13601 proc add_options_for_arm_v8_3a_fp16_complex_neon { flags } {
13602 if { ! [check_effective_target_arm_v8_3a_fp16_complex_neon_ok] } {
13603 return "$flags"
13604 }
13605 global et_arm_v8_3a_fp16_complex_neon_flags
13606 return "$flags $et_arm_v8_3a_fp16_complex_neon_flags"
13607 }
13608
13609
13610 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.3
13611 # with the complex instruction extension, 0 otherwise. The test is valid for
13612 # ARM and for AArch64.
13613
13614 proc check_effective_target_arm_v8_3a_complex_neon_hw { } {
13615 if { ![check_effective_target_arm_v8_3a_complex_neon_ok] } {
13616 return 0;
13617 }
13618 return [check_runtime arm_v8_3a_complex_neon_hw_available {
13619 #include "arm_neon.h"
13620 int
13621 main (void)
13622 {
13623
13624 float32x2_t results = {-4.0,5.0};
13625 float32x2_t a = {1.0,3.0};
13626 float32x2_t b = {2.0,5.0};
13627
13628 #ifdef __ARM_ARCH_ISA_A64
13629 asm ("fcadd %0.2s, %1.2s, %2.2s, #90"
13630 : "=w"(results)
13631 : "w"(a), "w"(b)
13632 : /* No clobbers. */);
13633
13634 #else
13635 asm ("vcadd.f32 %P0, %P1, %P2, #90"
13636 : "=w"(results)
13637 : "w"(a), "w"(b)
13638 : /* No clobbers. */);
13639 #endif
13640
13641 return (results[0] == 8 && results[1] == 24) ? 0 : 1;
13642 }
13643 } [add_options_for_arm_v8_3a_complex_neon ""]]
13644 }
13645
13646 # Return 1 if the assembler supports assembling the Armv8.3 pointer authentication B key directive
13647 proc check_effective_target_arm_v8_3a_bkey_directive { } {
13648 return [check_no_compiler_messages cet object {
13649 int main(void) {
13650 asm (".cfi_b_key_frame");
13651 return 0;
13652 }
13653 }]
13654 }
13655
13656 # Return 1 if the target supports executing the Armv8.1-M Mainline Low
13657 # Overhead Loop, 0 otherwise. The test is valid for ARM.
13658
13659 proc check_effective_target_arm_v8_1m_lob_hw { } {
13660 if { ![check_effective_target_arm_cortex_m] } {
13661 return 0;
13662 } else {
13663 return [check_runtime arm_v8_1m_lob_hw_available {
13664 int
13665 main (void)
13666 { int i = 0;
13667 asm ("movw r3, #10\n\t" /* movs? */
13668 "dls lr, r3" : : : "r3", "lr");
13669 loop:
13670 i++;
13671 asm goto ("le lr, %l0" : : : "lr" : loop);
13672 return i != 10;
13673 }
13674 } "-mcpu=unset -march=armv8.1-m.main -mthumb" ]
13675 }
13676 }
13677
13678 # Return 1 if this is an ARM target where Thumb-2 is used without
13679 # options added by the test and the target does not support executing
13680 # the Armv8.1-M Mainline Low Overhead Loop, 0 otherwise. The test is
13681 # valid for ARM.
13682
13683 proc check_effective_target_arm_thumb2_no_arm_v8_1m_lob { } {
13684 if { [check_effective_target_arm_thumb2]
13685 && ![check_effective_target_arm_v8_1m_lob_hw] } {
13686 return 1
13687 }
13688 return 0
13689 }
13690
13691 # Return 1 if this is an ARM target where -mthumb causes Thumb-2 to be
13692 # used and the target does not support executing the Armv8.1-M
13693 # Mainline Low Overhead Loop, 0 otherwise. The test is valid for ARM.
13694
13695 proc check_effective_target_arm_thumb2_ok_no_arm_v8_1m_lob { } {
13696 if { [check_effective_target_arm_thumb2_ok]
13697 && ![check_effective_target_arm_v8_1m_lob_hw] } {
13698 return 1
13699 }
13700 return 0
13701 }
13702
13703 # Returns 1 if the target is using glibc, 0 otherwise.
13704
13705 proc check_effective_target_glibc { } {
13706 return [check_no_compiler_messages glibc_object assembly {
13707 #include <stdlib.h>
13708 #if !defined(__GLIBC__)
13709 #error undefined
13710 #endif
13711 }]
13712 }
13713
13714 # Return 1 if the target plus current options supports a vector
13715 # complex addition with rotate of half and single float modes, 0 otherwise.
13716 #
13717 # This won't change for different subtargets so cache the result.
13718
13719 foreach N {hf sf} {
13720 eval [string map [list N $N] {
13721 proc check_effective_target_vect_complex_rot_N { } {
13722 return [check_cached_effective_target_indexed vect_complex_rot_N {
13723 expr { [istarget aarch64*-*-*]
13724 || [istarget arm*-*-*] }}]
13725 }
13726 }]
13727 }
13728
13729 # Return 1 if the target plus current options supports a vector
13730 # complex addition with rotate of double float modes, 0 otherwise.
13731 #
13732 # This won't change for different subtargets so cache the result.
13733
13734 foreach N {df} {
13735 eval [string map [list N $N] {
13736 proc check_effective_target_vect_complex_rot_N { } {
13737 return [check_cached_effective_target_indexed vect_complex_rot_N {
13738 expr { [istarget aarch64*-*-*] }}]
13739 }
13740 }]
13741 }
13742
13743 # Return 1 if this target uses an LLVM assembler and/or linker
13744 proc check_effective_target_llvm_binutils { } {
13745 return [check_cached_effective_target llvm_binutils {
13746 expr { [istarget amdgcn*-*-*]
13747 || [check_effective_target_offload_gcn] }}]
13748 }
13749
13750 # Return 1 if the compiler supports '-mfentry'.
13751
13752 proc check_effective_target_mfentry { } {
13753 if { ![check_effective_target_x86] } {
13754 return 0
13755 }
13756 return [check_no_compiler_messages mfentry object {
13757 void foo (void) { }
13758 } "-mfentry"]
13759 }
13760
13761 # Return 1 if this target supports indirect calls
13762 proc check_effective_target_indirect_calls { } {
13763 if { [istarget bpf-*-*] } {
13764 return 0
13765 }
13766 return 1
13767 }
13768
13769 # Return 1 if we can use the -lgccjit option, 0 otherwise.
13770
13771 proc check_effective_target_lgccjit { } {
13772 if { [info procs jit_target_compile] == "" } then {
13773 global GCC_UNDER_TEST
13774 if ![info exists GCC_UNDER_TEST] {
13775 set GCC_UNDER_TEST "[find_gcc]"
13776 }
13777 proc jit_target_compile { source dest type options } [info body gcc_target_compile]
13778 }
13779 return [check_no_compiler_messages lgccjit executable {
13780 int main() { return 0; }
13781 } "-lgccjit"]
13782 }
13783
13784 # Return 1 if the MSP430 small memory model is in use.
13785 proc check_effective_target_msp430_small {} {
13786 return [check_no_compiler_messages msp430_small assembly {
13787 #if (!defined __MSP430__ || defined __MSP430X_LARGE__)
13788 #error !msp430 || __MSP430X_LARGE__
13789 #endif
13790 } ""]
13791 }
13792
13793 # Return 1 if the MSP430 large memory model is in use.
13794 proc check_effective_target_msp430_large {} {
13795 return [check_no_compiler_messages msp430_large assembly {
13796 #ifndef __MSP430X_LARGE__
13797 #error __MSP430X_LARGE__
13798 #endif
13799 } ""]
13800 }
13801
13802 # Return 1 if GCC was configured with --with-tune=cortex-a76
13803 proc check_effective_target_tune_cortex_a76 { } {
13804 return [check_configured_with "with-tune=cortex-a76"]
13805 }
13806
13807 # Return 1 if the target has an efficient means to encode large initializers
13808 # in the assembly.
13809
13810 proc check_effective_target_large_initializer { } {
13811 if { [istarget nvptx*-*-*] } {
13812 return 0
13813 }
13814
13815 return 1
13816 }
13817
13818 # Return 1 if the target allows function prototype mismatches
13819 # in the assembly.
13820
13821 proc check_effective_target_non_strict_prototype { } {
13822 if { [istarget nvptx*-*-*] } {
13823 return 0
13824 }
13825
13826 return 1
13827 }
13828
13829 # Returns 1 if the target toolchain supports extended
13830 # syntax of .symver directive, 0 otherwise.
13831
13832 proc check_symver_available { } {
13833 return [check_no_compiler_messages symver_available object {
13834 int foo(void) { return 0; }
13835 int main (void) {
13836 asm volatile (".symver foo,foo@VER_1, local");
13837 return 0;
13838 }
13839 }]
13840 }
13841
13842 # Return 1 if emitted assembly contains .ident directive.
13843
13844 proc check_effective_target_ident_directive {} {
13845 return [check_no_messages_and_pattern ident_directive \
13846 "(?n)^\[\t\]+\\.ident" assembly {
13847 int i;
13848 }]
13849 }
13850
13851 # Return 1 if we're able to assemble movdiri and movdir64b
13852
13853 proc check_effective_target_movdir { } {
13854 return [check_no_compiler_messages movdir object {
13855 void
13856 foo (unsigned int *d, unsigned int s)
13857 {
13858 __builtin_ia32_directstoreu_u32 (d, s);
13859 }
13860 void
13861 bar (void *d, const void *s)
13862 {
13863 __builtin_ia32_movdir64b (d, s);
13864 }
13865 } "-mmovdiri -mmovdir64b" ]
13866 }
13867
13868 # Return 1 if the target does not support address sanitizer, 0 otherwise
13869
13870 proc check_effective_target_no_fsanitize_address {} {
13871 if ![check_no_compiler_messages fsanitize_address executable {
13872 int main (void) { return 0; }
13873 } "-fsanitize=address" ] {
13874 return 1;
13875 }
13876
13877 return 0;
13878 }
13879
13880 # Return 1 if this target supports 'R' flag in .section directive, 0
13881 # otherwise. Cache the result.
13882
13883 proc check_effective_target_R_flag_in_section { } {
13884 global tool
13885 global GCC_UNDER_TEST
13886
13887 # Need auto-host.h to check linker support.
13888 if { ![file exists ../../auto-host.h ] } {
13889 return 0
13890 }
13891
13892 return [check_cached_effective_target R_flag_in_section {
13893
13894 set src pie[pid].c
13895 set obj pie[pid].o
13896
13897 set f [open $src "w"]
13898 puts $f "#include \"../../auto-host.h\""
13899 puts $f "#if HAVE_GAS_SHF_GNU_RETAIN == 0 || HAVE_INITFINI_ARRAY_SUPPORT == 0"
13900 puts $f "# error Assembler does not support 'R' flag in .section directive."
13901 puts $f "#endif"
13902 close $f
13903
13904 verbose "check_effective_target_R_flag_in_section compiling testfile $src" 2
13905 set lines [${tool}_target_compile $src $obj assembly ""]
13906
13907 file delete $src
13908 file delete $obj
13909
13910 if [string match "" $lines] then {
13911 verbose "check_effective_target_R_flag_in_section testfile compilation passed" 2
13912 return 1
13913 } else {
13914 verbose "check_effective_target_R_flag_in_section testfile compilation failed" 2
13915 return 0
13916 }
13917 }]
13918 }
13919
13920 # Return 1 if this target supports 'o' flag in .section directive, 0
13921 # otherwise. Cache the result.
13922
13923 proc check_effective_target_o_flag_in_section { } {
13924 global tool
13925 global GCC_UNDER_TEST
13926
13927 # Need auto-host.h to check linker support.
13928 if { ![file exists ../../auto-host.h ] } {
13929 return 0
13930 }
13931
13932 return [check_cached_effective_target o_flag_in_section {
13933
13934 set src pie[pid].c
13935 set obj pie[pid].o
13936
13937 set f [open $src "w"]
13938 puts $f "#include \"../../auto-host.h\""
13939 puts $f "#if HAVE_GAS_SECTION_LINK_ORDER == 0"
13940 puts $f "# error Assembler does not support 'o' flag in .section directive."
13941 puts $f "#endif"
13942 close $f
13943
13944 verbose "check_effective_target_o_flag_in_section compiling testfile $src" 2
13945 set lines [${tool}_target_compile $src $obj object ""]
13946
13947 file delete $src
13948 file delete $obj
13949
13950 if [string match "" $lines] then {
13951 verbose "check_effective_target_o_flag_in_section testfile compilation passed" 2
13952 return 1
13953 } else {
13954 verbose "check_effective_target_o_flag_in_section testfile compilation failed" 2
13955 return 0
13956 }
13957 }]
13958 }
13959
13960 # Return 1 if the given assembler supports hardware transactional memory
13961 # instructions with machine type Power10, 0 otherwise. Cache the result.
13962
13963 proc check_effective_target_powerpc_as_p10_htm { } {
13964 global tool
13965 global GCC_UNDER_TEST
13966
13967 # Need auto-host.h to check linker support.
13968 if { ![file exists ../../auto-host.h ] } {
13969 return 0
13970 }
13971
13972 return [check_cached_effective_target powerpc_as_p10_htm {
13973
13974 set src pie[pid].c
13975 set obj pie[pid].o
13976
13977 set f [open $src "w"]
13978 puts $f "#include \"../../auto-host.h\""
13979 puts $f "#if HAVE_AS_POWER10_HTM == 0"
13980 puts $f "# error Assembler does not support htm insns with power10."
13981 puts $f "#endif"
13982 close $f
13983
13984 verbose "check_effective_target_powerpc_as_p10_htm compiling testfile $src" 2
13985 set lines [${tool}_target_compile $src $obj object ""]
13986
13987 file delete $src
13988 file delete $obj
13989
13990 if [string match "" $lines] then {
13991 verbose "check_effective_target_powerpc_as_p10_htm testfile compilation passed" 2
13992 return 1
13993 } else {
13994 verbose "check_effective_target_powerpc_as_p10_htm testfile compilation failed" 2
13995 return 0
13996 }
13997 }]
13998 }
13999
14000 # Return 1 if LRA is supported. This must not be called (results in ERROR) for
14001 # targets that don't do register allocation, and therefore neither use nor
14002 # don't use LRA.
14003
14004 proc check_effective_target_lra { } {
14005 # Start with heavily used targets which are known to always use LRA.
14006 if { [check_effective_target_x86]
14007 || [istarget aarch64*-*-*] || [istarget arm*-*-*]
14008 || [istarget powerpc*-*-*] || [istarget riscv*-*-*] } {
14009 return 1
14010 }
14011
14012 # Otherwise check the reload dump for messages emitted solely by LRA.
14013 return [check_no_messages_and_pattern lra "\\\*{9} Local #1: \\\*{9}" rtl-reload {
14014 void foo (void) {}
14015 } {-O2 -fdump-rtl-reload-details}] ;# LRA notes requires a detailed dump.
14016 }
14017
14018 # Return 1 if 'asm goto' with outputs is supported, 0 otherwise.
14019
14020 proc check_effective_target_asm_goto_with_outputs { } {
14021 if { [istarget nvptx-*-*] } {
14022 return 1
14023 }
14024 return [check_effective_target_lra]
14025 }
14026
14027 # Test whether optimizations are enabled ('__OPTIMIZE__') per the
14028 # 'current_compiler_flags' (thus don't cache).
14029
14030 proc check_effective_target___OPTIMIZE__ {} {
14031 return [check_no_compiler_messages_nocache __OPTIMIZE__ assembly {
14032 #ifndef __OPTIMIZE__
14033 # error nein
14034 #endif
14035 /* Avoid pedwarn about empty TU. */
14036 int dummy;
14037 } [current_compiler_flags]]
14038 }
14039
14040 # Return 1 if python3 (>= 3.6) is available.
14041
14042 proc check_effective_target_recent_python3 { } {
14043 set result [remote_exec host "python3 -c \"import sys; assert sys.version_info >= (3, 6)\""]
14044 set status [lindex $result 0]
14045 if { $status == 0 } then {
14046 return 1;
14047 } else {
14048 return 0;
14049 }
14050 }
14051
14052 # Return 1 if python3 contains a module
14053
14054 proc check_effective_target_python3_module { module } {
14055 set result [remote_exec host "python3 -c \"import $module\""]
14056 set status [lindex $result 0]
14057 if { $status == 0 } then {
14058 return 1;
14059 } else {
14060 return 0;
14061 }
14062 }
14063
14064 # Return 1 if pytest module is available for python3.
14065
14066 proc check_effective_target_pytest3 { } {
14067 set result [remote_exec host "python3 -m pytest --color=no -rap -s --tb=no --version"]
14068 set status [lindex $result 0]
14069 if { $status == 0 } then {
14070 return 1;
14071 } else {
14072 return 0;
14073 }
14074 }
14075
14076 proc check_effective_target_property_1_needed { } {
14077 return [check_no_compiler_messages property_1_needed executable {
14078 /* Assembly code */
14079 #ifdef __LP64__
14080 # define __PROPERTY_ALIGN 3
14081 #else
14082 # define __PROPERTY_ALIGN 2
14083 #endif
14084
14085 .section ".note.gnu.property", "a"
14086 .p2align __PROPERTY_ALIGN
14087 .long 1f - 0f /* name length. */
14088 .long 4f - 1f /* data length. */
14089 /* NT_GNU_PROPERTY_TYPE_0. */
14090 .long 5 /* note type. */
14091 0:
14092 .asciz "GNU" /* vendor name. */
14093 1:
14094 .p2align __PROPERTY_ALIGN
14095 /* GNU_PROPERTY_1_NEEDED. */
14096 .long 0xb0008000 /* pr_type. */
14097 .long 3f - 2f /* pr_datasz. */
14098 2:
14099 /* GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS. */
14100 .long 1
14101 3:
14102 .p2align __PROPERTY_ALIGN
14103 4:
14104 .text
14105 .globl main
14106 main:
14107 .byte 0
14108 } ""]
14109 }
14110
14111 # Return 1 if this target has prog named "$prog", 0 otherwise.
14112
14113 proc check_is_prog_name_available { prog } {
14114 global tool
14115
14116 set options [list "additional_flags=-print-prog-name=$prog"]
14117 set output [lindex [${tool}_target_compile "" "" "none" $options] 0]
14118
14119 if { $output == $prog } {
14120 return 0
14121 }
14122
14123 return 1
14124 }
14125
14126 # returns 1 if target does selects a readonly section for const volatile variables.
14127 proc check_effective_target_const_volatile_readonly_section { } {
14128
14129 if { [istarget powerpc-*-*]
14130 || [check-flags { "" { powerpc64-*-* } { -m32 } }] } {
14131 return 0
14132 }
14133 return 1
14134 }
14135
14136 # Return 1 if the CORE-V MAC extension is available.
14137 proc check_effective_target_cv_mac { } {
14138 if { !([istarget riscv*-*-*]) } {
14139 return 0
14140 }
14141 return [check_no_compiler_messages cv_mac object {
14142 void foo (void)
14143 {
14144 asm ("cv.mac t0, t1, t2");
14145 }
14146 } "-march=rv32i_xcvmac" ]
14147 }
14148
14149 # Return 1 if the CORE-V ALU extension is available.
14150 proc check_effective_target_cv_alu { } {
14151 if { !([istarget riscv*-*-*]) } {
14152 return 0
14153 }
14154 return [check_no_compiler_messages cv_alu object {
14155 void foo (void)
14156 {
14157 asm ("cv.addn t0, t1, t2, 0");
14158 }
14159 } "-march=rv32i_xcvalu" ]
14160 }
14161
14162 # Return 1 if the CORE-V ELW extension is available.
14163 proc check_effective_target_cv_elw { } {
14164 if { !([istarget riscv*-*-*]) } {
14165 return 0
14166 }
14167 return [check_no_compiler_messages cv_elw object {
14168 void foo (void)
14169 {
14170 asm ("cv.elw x0, 0(x0)");
14171 }
14172 } "-march=rv32i_xcvelw" ]
14173 }
14174
14175 # Return 1 if the CORE-V SIMD extension is available.
14176 proc check_effective_target_cv_simd { } {
14177 if { !([istarget riscv*-*-*]) } {
14178 return 0
14179 }
14180 return [check_no_compiler_messages cv_simd object {
14181 void foo (void)
14182 {
14183 asm ("cv.add.sc.b x0, x0, x0");
14184 }
14185 } "-march=rv32i_xcvsimd" ]
14186 }
14187
14188 # Return 1 if the CORE-V BI extension is available
14189 proc check_effective_target_cv_bi { } {
14190 if { !([istarget riscv*-*-*]) } {
14191 return 0
14192 }
14193 return [check_no_compiler_messages cv_bi object {
14194 void foo (void)
14195 {
14196 asm ("cv.beqimm t0, -16, foo");
14197 }
14198 } "-march=rv32i_xcvbi" ]
14199 }
14200
14201 proc check_effective_target_loongarch_sx { } {
14202 return [check_no_compiler_messages loongarch_lsx assembly {
14203 #if !defined(__loongarch_sx)
14204 #error "LSX not defined"
14205 #endif
14206 } "-mlsx"]
14207 }
14208
14209 proc check_effective_target_loongarch_sx_as { } {
14210 return [check_no_compiler_messages loongarch_sx_as object {
14211 #include <lsxintrin.h>
14212 int main (void)
14213 {
14214 __m128i a, b, c;
14215 c = __lsx_vand_v (a, b);
14216 return 0;
14217 }
14218 } "-mlsx"]
14219 }
14220
14221 proc check_effective_target_loongarch_sx_hw { } {
14222 return [check_runtime loongarch_sx_hw {
14223 #include <lsxintrin.h>
14224 int main (void)
14225 {
14226 __m128i a, b, c;
14227 c = __lsx_vand_v (a, b);
14228 return 0;
14229 }
14230 } "-mlsx"]
14231 }
14232
14233 proc check_effective_target_loongarch_asx { } {
14234 return [check_no_compiler_messages loongarch_asx assembly {
14235 #if !defined(__loongarch_asx)
14236 #error "LASX not defined"
14237 #endif
14238 } "-mlasx"]
14239 }
14240
14241 proc check_effective_target_loongarch_asx_hw { } {
14242 return [check_runtime loongarch_asx_hw {
14243 #include <lasxintrin.h>
14244 int main (void)
14245 {
14246 __m256i a, b, c;
14247 c = __lasx_xvand_v (a, b);
14248 return 0;
14249 }
14250 } "-mlasx"]
14251 }
14252
14253 # Check whether LoongArch binutils supports call36 relocation.
14254 proc check_effective_target_loongarch_call36_support { } {
14255 return [check_no_compiler_messages loongarch_call36_support object {
14256 /* Assembly code */
14257 pcaddu18i $r1,%call36(a)
14258 jirl $r1,$r1,0
14259 } ""]
14260 }
14261
14262 # Returns 1 if binutils supports TLS le Relax, 0 otherwise.
14263 proc check_effective_target_tls_le_relax { } {
14264 if [check_effective_target_tls_native] {
14265 return [check_no_compiler_messages loongarch_tls_le_relax object {
14266 /* Assembly code */
14267 lu12i.w $r12, %le_hi20_r(a)
14268 }]
14269 }
14270
14271 return 0;
14272 }
14273
14274 # Appends necessary Python flags to extra-tool-flags if Python.h is supported.
14275 # Otherwise, modifies dg-do-what.
14276 proc dg-require-python-h { args } {
14277 upvar dg-extra-tool-flags extra-tool-flags
14278
14279 verbose "ENTER dg-require-python-h" 2
14280
14281 set supported 0
14282 set result [remote_exec host "python3-config --includes"]
14283 set status [lindex $result 0]
14284 if { $status == 0 } {
14285 # Remove trailing newline from python3-config output.
14286 set python_flags [string trim [lindex $result 1]]
14287 if [check_no_compiler_messages python_h assembly {
14288 #include <Python.h>
14289 int main (void) { return 0; }
14290 } $python_flags] {
14291 set supported 1
14292 }
14293 }
14294
14295 if { $supported == 0 } {
14296 verbose "Python.h not supported" 2
14297 upvar dg-do-what dg-do-what
14298 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
14299 return
14300 }
14301
14302 verbose "Python flags are: $python_flags" 2
14303
14304 verbose "Before appending, extra-tool-flags: ${extra-tool-flags}" 3
14305 eval lappend extra-tool-flags $python_flags
14306 verbose "After appending, extra-tool-flags: ${extra-tool-flags}" 3
14307 }
14308
14309 # Return 1 if the target supports heap-trampoline, 0 otherwise.
14310 proc check_effective_target_heap_trampoline {} {
14311 if { [istarget aarch64*-*-linux*]
14312 || ([check_effective_target_x86]
14313 && ([istarget *-*-darwin*]
14314 || [istarget *-*-linux*])) } {
14315 return 1
14316 }
14317 return 0
14318 }
14319
14320 # Return 1 if check-jsonschema is available.
14321
14322 proc check_effective_target_check_jsonschema { } {
14323 set result [remote_exec host "check-jsonschema --version"]
14324 set status [lindex $result 0]
14325 if { $status == 0 } then {
14326 return 1;
14327 } else {
14328 return 0;
14329 }
14330 }
14331
14332 # Return 1 if nvptx code by default compiles for at least PTX ISA version
14333 # major.minor.
14334
14335 proc check_nvptx_default_ptx_isa_version_at_least { major minor } {
14336 set name nvptx_default_ptx_isa_version_at_least_${major}_${minor}
14337
14338 set supported_p \
14339 [concat \
14340 "((__PTX_ISA_VERSION_MAJOR__ == $major" \
14341 " && __PTX_ISA_VERSION_MINOR__ >= $minor)" \
14342 " || (__PTX_ISA_VERSION_MAJOR__ > $major))"]
14343
14344 set src \
14345 [list \
14346 "#if $supported_p" \
14347 "#else" \
14348 "#error unsupported" \
14349 "#endif"]
14350 set src [join $src "\n"]
14351
14352 set res [check_no_compiler_messages $name assembly $src ""]
14353
14354 return $res
14355 }
14356
14357 # Return 1 if nvptx code by default compiles for at least PTX ISA version 6.0.
14358
14359 proc check_effective_target_nvptx_default_ptx_isa_version_at_least_6_0 { } {
14360 return [check_nvptx_default_ptx_isa_version_at_least 6 0]
14361 }
14362
14363 # Return 1 if nvptx code by default compiles for at least the specified PTX ISA
14364 # target architecture.
14365
14366 proc check_nvptx_default_ptx_isa_target_architecture_at_least { ta } {
14367 set name nvptx_default_ptx_isa_target_architecture_at_least_${ta}
14368
14369 if [regexp {^sm_(\d+)$} $ta dummy ptx_sm] {
14370 set ptx_sm "${ptx_sm}0"
14371 } else {
14372 error "check_nvptx_default_ptx_isa_target_architecture_at_least: illegal argument: $ta"
14373 }
14374
14375 set supported_p \
14376 [concat \
14377 "(__PTX_SM__ >= $ptx_sm)"]
14378
14379 set src \
14380 [list \
14381 "#if $supported_p" \
14382 "#else" \
14383 "#error unsupported" \
14384 "#endif"]
14385 set src [join $src "\n"]
14386
14387 set res [check_no_compiler_messages $name assembly $src ""]
14388
14389 return $res
14390 }
14391
14392 # Return 1 if nvptx '-msoft-stack' is enabled.
14393
14394 proc check_effective_target_nvptx_softstack { } {
14395 return [check_no_compiler_messages nvptx_softstack assembly {
14396 #if !defined(__nvptx_softstack__)
14397 #error !__nvptx_softstack__
14398 #endif
14399 }]
14400 }
14401
14402 # Return 1 if nvptx code with PTX ISA version major.minor or higher can be run.
14403
14404 proc check_nvptx_runtime_ptx_isa_version_at_least { major minor } {
14405 set name nvptx_runtime_ptx_isa_version_${major}_${minor}
14406
14407 set default \
14408 [check_nvptx_default_ptx_isa_version_at_least \
14409 ${major} ${minor}]
14410
14411 if { $default } {
14412 set flag ""
14413 } else {
14414 set flag "-mptx=$major.$minor"
14415 }
14416
14417 set res [check_runtime $name {
14418 int main (void) { return 0; }
14419 } $flag]
14420
14421 return $res
14422 }
14423
14424 # Return 1 if nvptx code with the specified PTX ISA target architecture or
14425 # higher can be run.
14426
14427 proc check_nvptx_runtime_ptx_isa_target_architecture_at_least { ta } {
14428 set name nvptx_runtime_ptx_isa_target_architecture_${ta}
14429
14430 set default \
14431 [check_nvptx_default_ptx_isa_target_architecture_at_least ${ta}]
14432
14433 if { $default } {
14434 set flag ""
14435 } else {
14436 set flag "-march=$ta -mptx=_"
14437 }
14438
14439 set res [check_runtime $name {
14440 int main (void) { return 0; }
14441 } $flag]
14442
14443 return $res
14444 }
14445
14446 # Return 1 if the nvptx runtime environment supports the PTX ISA directive
14447 # '.alias'.
14448
14449 proc check_effective_target_nvptx_runtime_alias_ptx { } {
14450 return [check_nvptx_runtime_ptx_isa_version_at_least 6 3]
14451 }
14452
14453 # Return 1 if the nvptx runtime environment supports PTX 'alloca'.
14454
14455 proc check_effective_target_nvptx_runtime_alloca_ptx { } {
14456 return [expr { [check_nvptx_runtime_ptx_isa_version_at_least 7 3]
14457 && [check_nvptx_runtime_ptx_isa_target_architecture_at_least sm_52] }]
14458 }
14459
14460 # Add options to enable nvptx using the PTX ISA directive '.alias'.
14461
14462 proc add_options_for_nvptx_alias_ptx { flags } {
14463 append flags " -malias"
14464
14465 if { ![check_nvptx_default_ptx_isa_version_at_least 6 3] } {
14466 append flags " -mptx=6.3"
14467 }
14468
14469 return $flags
14470 }
14471
14472 # Add options to enable nvptx using PTX 'alloca'.
14473
14474 proc add_options_for_nvptx_alloca_ptx { flags } {
14475 # We don't add '-mno-soft-stack' here; the users should take care of that
14476 # explicitly.
14477
14478 if { ![check_nvptx_default_ptx_isa_version_at_least 7 3] } {
14479 append flags " -mptx=7.3"
14480 }
14481
14482 if { ![check_nvptx_default_ptx_isa_target_architecture_at_least sm_52] } {
14483 append flags " -march=sm_52"
14484 }
14485
14486 return $flags
14487 }
14488
14489 # Return true if alarm is supported on the target.
14490
14491 proc check_effective_target_alarm { } {
14492 if { ![check_effective_target_signal] } {
14493 return 0
14494 }
14495
14496 return [check_no_compiler_messages alarm executable {
14497 #include <signal.h>
14498 #include <stdlib.h>
14499 #include <unistd.h>
14500 void do_exit(int i) { exit (0); }
14501 int main (void) {
14502 struct sigaction s;
14503 sigemptyset (&s.sa_mask);
14504 s.sa_handler = exit;
14505 s.sa_flags = 0;
14506 sigaction (SIGALRM, &s, NULL);
14507 alarm (1);
14508
14509 /* Infinite loop to simulate work... */
14510 while (1);
14511 abort ();
14512 }
14513 }]
14514 }
14515
14516 # Return true if a speculation barrier is defined on the target.
14517 proc check_effective_target_speculation_barrier_defined { } {
14518 return [check_no_compiler_messages speculation_barrier_defined assembly {
14519 int main (int argc, char **argv) {
14520 return __builtin_speculation_safe_value (argc);
14521 }
14522 }]
14523 }
14524
14525 # Check if valgrind executable exists in PATH on host
14526 proc check_effective_target_valgrind { } {
14527 if { [which valgrind] != 0 } {
14528 return 1
14529 }
14530 return 0
14531 }