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