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