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