Tweak directives in GCC tests for msp430-elf
[gcc.git] / gcc / testsuite / lib / target-supports.exp
1 # Copyright (C) 1999-2018 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"] } {
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 #if !defined (__ARM_FEATURE_DOTPROD)
4441 #error "__ARM_FEATURE_DOTPROD not defined"
4442 #endif
4443 } "$flags -march=armv8.2-a+dotprod"] } {
4444 set et_arm_v8_2a_dotprod_neon_flags "$flags -march=armv8.2-a+dotprod"
4445 return 1
4446 }
4447 }
4448
4449 return 0;
4450 }
4451
4452 proc check_effective_target_arm_v8_2a_dotprod_neon_ok { } {
4453 return [check_cached_effective_target arm_v8_2a_dotprod_neon_ok \
4454 check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache]
4455 }
4456
4457 proc add_options_for_arm_v8_2a_dotprod_neon { flags } {
4458 if { ! [check_effective_target_arm_v8_2a_dotprod_neon_ok] } {
4459 return "$flags"
4460 }
4461 global et_arm_v8_2a_dotprod_neon_flags
4462 return "$flags $et_arm_v8_2a_dotprod_neon_flags"
4463 }
4464
4465 # Return 1 if the target supports FP16 VFMAL and VFMSL
4466 # instructions, 0 otherwise.
4467 # Record the command line options needed.
4468
4469 proc check_effective_target_arm_fp16fml_neon_ok_nocache { } {
4470 global et_arm_fp16fml_neon_flags
4471 set et_arm_fp16fml_neon_flags ""
4472
4473 if { ![istarget arm*-*-*] } {
4474 return 0;
4475 }
4476
4477 # Iterate through sets of options to find the compiler flags that
4478 # need to be added to the -march option.
4479 foreach flags {"" "-mfloat-abi=softfp -mfpu=neon-fp-armv8" "-mfloat-abi=hard -mfpu=neon-fp-armv8"} {
4480 if { [check_no_compiler_messages_nocache \
4481 arm_fp16fml_neon_ok assembly {
4482 #include <arm_neon.h>
4483 float32x2_t
4484 foo (float32x2_t r, float16x4_t a, float16x4_t b)
4485 {
4486 return vfmlal_high_u32 (r, a, b);
4487 }
4488 } "$flags -march=armv8.2-a+fp16fml"] } {
4489 set et_arm_fp16fml_neon_flags "$flags -march=armv8.2-a+fp16fml"
4490 return 1
4491 }
4492 }
4493
4494 return 0;
4495 }
4496
4497 proc check_effective_target_arm_fp16fml_neon_ok { } {
4498 return [check_cached_effective_target arm_fp16fml_neon_ok \
4499 check_effective_target_arm_fp16fml_neon_ok_nocache]
4500 }
4501
4502 proc add_options_for_arm_fp16fml_neon { flags } {
4503 if { ! [check_effective_target_arm_fp16fml_neon_ok] } {
4504 return "$flags"
4505 }
4506 global et_arm_fp16fml_neon_flags
4507 return "$flags $et_arm_fp16fml_neon_flags"
4508 }
4509
4510 # Return 1 if the target supports executing ARMv8 NEON instructions, 0
4511 # otherwise.
4512
4513 proc check_effective_target_arm_v8_neon_hw { } {
4514 return [check_runtime arm_v8_neon_hw_available {
4515 #include "arm_neon.h"
4516 int
4517 main (void)
4518 {
4519 float32x2_t a = { 1.0f, 2.0f };
4520 #ifdef __ARM_ARCH_ISA_A64
4521 asm ("frinta %0.2s, %1.2s"
4522 : "=w" (a)
4523 : "w" (a));
4524 #else
4525 asm ("vrinta.f32 %P0, %P1"
4526 : "=w" (a)
4527 : "0" (a));
4528 #endif
4529 return a[0] == 2.0f;
4530 }
4531 } [add_options_for_arm_v8_neon ""]]
4532 }
4533
4534 # Return 1 if the target supports executing the ARMv8.1 Adv.SIMD extension, 0
4535 # otherwise. The test is valid for AArch64 and ARM.
4536
4537 proc check_effective_target_arm_v8_1a_neon_hw { } {
4538 if { ![check_effective_target_arm_v8_1a_neon_ok] } {
4539 return 0;
4540 }
4541 return [check_runtime arm_v8_1a_neon_hw_available {
4542 int
4543 main (void)
4544 {
4545 #ifdef __ARM_ARCH_ISA_A64
4546 __Int32x2_t a = {0, 1};
4547 __Int32x2_t b = {0, 2};
4548 __Int32x2_t result;
4549
4550 asm ("sqrdmlah %0.2s, %1.2s, %2.2s"
4551 : "=w"(result)
4552 : "w"(a), "w"(b)
4553 : /* No clobbers. */);
4554
4555 #else
4556
4557 __simd64_int32_t a = {0, 1};
4558 __simd64_int32_t b = {0, 2};
4559 __simd64_int32_t result;
4560
4561 asm ("vqrdmlah.s32 %P0, %P1, %P2"
4562 : "=w"(result)
4563 : "w"(a), "w"(b)
4564 : /* No clobbers. */);
4565 #endif
4566
4567 return result[0];
4568 }
4569 } [add_options_for_arm_v8_1a_neon ""]]
4570 }
4571
4572 # Return 1 if the target supports executing floating point instructions from
4573 # ARMv8.2 with the FP16 extension, 0 otherwise. The test is valid for ARM and
4574 # for AArch64.
4575
4576 proc check_effective_target_arm_v8_2a_fp16_scalar_hw { } {
4577 if { ![check_effective_target_arm_v8_2a_fp16_scalar_ok] } {
4578 return 0;
4579 }
4580 return [check_runtime arm_v8_2a_fp16_scalar_hw_available {
4581 int
4582 main (void)
4583 {
4584 __fp16 a = 1.0;
4585 __fp16 result;
4586
4587 #ifdef __ARM_ARCH_ISA_A64
4588
4589 asm ("fabs %h0, %h1"
4590 : "=w"(result)
4591 : "w"(a)
4592 : /* No clobbers. */);
4593
4594 #else
4595
4596 asm ("vabs.f16 %0, %1"
4597 : "=w"(result)
4598 : "w"(a)
4599 : /* No clobbers. */);
4600
4601 #endif
4602
4603 return (result == 1.0) ? 0 : 1;
4604 }
4605 } [add_options_for_arm_v8_2a_fp16_scalar ""]]
4606 }
4607
4608 # Return 1 if the target supports executing Adv.SIMD instructions from ARMv8.2
4609 # with the FP16 extension, 0 otherwise. The test is valid for ARM and for
4610 # AArch64.
4611
4612 proc check_effective_target_arm_v8_2a_fp16_neon_hw { } {
4613 if { ![check_effective_target_arm_v8_2a_fp16_neon_ok] } {
4614 return 0;
4615 }
4616 return [check_runtime arm_v8_2a_fp16_neon_hw_available {
4617 int
4618 main (void)
4619 {
4620 #ifdef __ARM_ARCH_ISA_A64
4621
4622 __Float16x4_t a = {1.0, -1.0, 1.0, -1.0};
4623 __Float16x4_t result;
4624
4625 asm ("fabs %0.4h, %1.4h"
4626 : "=w"(result)
4627 : "w"(a)
4628 : /* No clobbers. */);
4629
4630 #else
4631
4632 __simd64_float16_t a = {1.0, -1.0, 1.0, -1.0};
4633 __simd64_float16_t result;
4634
4635 asm ("vabs.f16 %P0, %P1"
4636 : "=w"(result)
4637 : "w"(a)
4638 : /* No clobbers. */);
4639
4640 #endif
4641
4642 return (result[0] == 1.0) ? 0 : 1;
4643 }
4644 } [add_options_for_arm_v8_2a_fp16_neon ""]]
4645 }
4646
4647 # Return 1 if the target supports executing AdvSIMD instructions from ARMv8.2
4648 # with the Dot Product extension, 0 otherwise. The test is valid for ARM and for
4649 # AArch64.
4650
4651 proc check_effective_target_arm_v8_2a_dotprod_neon_hw { } {
4652 if { ![check_effective_target_arm_v8_2a_dotprod_neon_ok] } {
4653 return 0;
4654 }
4655 return [check_runtime arm_v8_2a_dotprod_neon_hw_available {
4656 #include "arm_neon.h"
4657 int
4658 main (void)
4659 {
4660
4661 uint32x2_t results = {0,0};
4662 uint8x8_t a = {1,1,1,1,2,2,2,2};
4663 uint8x8_t b = {2,2,2,2,3,3,3,3};
4664
4665 #ifdef __ARM_ARCH_ISA_A64
4666 asm ("udot %0.2s, %1.8b, %2.8b"
4667 : "=w"(results)
4668 : "w"(a), "w"(b)
4669 : /* No clobbers. */);
4670
4671 #else
4672 asm ("vudot.u8 %P0, %P1, %P2"
4673 : "=w"(results)
4674 : "w"(a), "w"(b)
4675 : /* No clobbers. */);
4676 #endif
4677
4678 return (results[0] == 8 && results[1] == 24) ? 1 : 0;
4679 }
4680 } [add_options_for_arm_v8_2a_dotprod_neon ""]]
4681 }
4682
4683 # Return 1 if this is a ARM target with NEON enabled.
4684
4685 proc check_effective_target_arm_neon { } {
4686 if { [check_effective_target_arm32] } {
4687 return [check_no_compiler_messages arm_neon object {
4688 #ifndef __ARM_NEON__
4689 #error not NEON
4690 #else
4691 int dummy;
4692 #endif
4693 }]
4694 } else {
4695 return 0
4696 }
4697 }
4698
4699 proc check_effective_target_arm_neonv2 { } {
4700 if { [check_effective_target_arm32] } {
4701 return [check_no_compiler_messages arm_neon object {
4702 #ifndef __ARM_NEON__
4703 #error not NEON
4704 #else
4705 #ifndef __ARM_FEATURE_FMA
4706 #error not NEONv2
4707 #else
4708 int dummy;
4709 #endif
4710 #endif
4711 }]
4712 } else {
4713 return 0
4714 }
4715 }
4716
4717 # Return 1 if this is an ARM target with load acquire and store release
4718 # instructions for 8-, 16- and 32-bit types.
4719
4720 proc check_effective_target_arm_acq_rel { } {
4721 return [check_no_compiler_messages arm_acq_rel object {
4722 void
4723 load_acquire_store_release (void)
4724 {
4725 asm ("lda r0, [r1]\n\t"
4726 "stl r0, [r1]\n\t"
4727 "ldah r0, [r1]\n\t"
4728 "stlh r0, [r1]\n\t"
4729 "ldab r0, [r1]\n\t"
4730 "stlb r0, [r1]"
4731 : : : "r0", "memory");
4732 }
4733 }]
4734 }
4735
4736 # Add the options needed for MIPS Paired-Single.
4737
4738 proc add_options_for_mpaired_single { flags } {
4739 if { ! [check_effective_target_mpaired_single] } {
4740 return "$flags"
4741 }
4742 return "$flags -mpaired-single"
4743 }
4744
4745 # Add the options needed for MIPS SIMD Architecture.
4746
4747 proc add_options_for_mips_msa { flags } {
4748 if { ! [check_effective_target_mips_msa] } {
4749 return "$flags"
4750 }
4751 return "$flags -mmsa"
4752 }
4753
4754 # Add the options needed for MIPS Loongson MMI Architecture.
4755
4756 proc add_options_for_mips_loongson_mmi { flags } {
4757 if { ! [check_effective_target_mips_loongson_mmi] } {
4758 return "$flags"
4759 }
4760 return "$flags -mloongson-mmi"
4761 }
4762
4763
4764 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
4765 # the Loongson vector modes.
4766
4767 proc check_effective_target_mips_loongson_mmi { } {
4768 return [check_no_compiler_messages loongson assembly {
4769 #if !defined(__mips_loongson_mmi)
4770 #error !__mips_loongson_mmi
4771 #endif
4772 #if !defined(__mips_loongson_vector_rev)
4773 #error !__mips_loongson_vector_rev
4774 #endif
4775 }]
4776 }
4777
4778 # Return 1 if this is a MIPS target that supports the legacy NAN.
4779
4780 proc check_effective_target_mips_nanlegacy { } {
4781 return [check_no_compiler_messages nanlegacy assembly {
4782 #include <stdlib.h>
4783 int main () { return 0; }
4784 } "-mnan=legacy"]
4785 }
4786
4787 # Return 1 if an MSA program can be compiled to object
4788
4789 proc check_effective_target_mips_msa { } {
4790 if ![check_effective_target_nomips16] {
4791 return 0
4792 }
4793 return [check_no_compiler_messages msa object {
4794 #if !defined(__mips_msa)
4795 #error "MSA NOT AVAIL"
4796 #else
4797 #if !(((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2))
4798 #error "MSA NOT AVAIL FOR ISA REV < 2"
4799 #endif
4800 #if !defined(__mips_hard_float)
4801 #error "MSA HARD_FLOAT REQUIRED"
4802 #endif
4803 #if __mips_fpr != 64
4804 #error "MSA 64-bit FPR REQUIRED"
4805 #endif
4806 #include <msa.h>
4807
4808 int main()
4809 {
4810 v8i16 v = __builtin_msa_ldi_h (1);
4811
4812 return v[0];
4813 }
4814 #endif
4815 } "-mmsa" ]
4816 }
4817
4818 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
4819 # Architecture.
4820
4821 proc check_effective_target_arm_eabi { } {
4822 return [check_no_compiler_messages arm_eabi object {
4823 #ifndef __ARM_EABI__
4824 #error not EABI
4825 #else
4826 int dummy;
4827 #endif
4828 }]
4829 }
4830
4831 # Return 1 if this is an ARM target that adheres to the hard-float variant of
4832 # the ABI for the ARM Architecture (e.g. -mfloat-abi=hard).
4833
4834 proc check_effective_target_arm_hf_eabi { } {
4835 return [check_no_compiler_messages arm_hf_eabi object {
4836 #if !defined(__ARM_EABI__) || !defined(__ARM_PCS_VFP)
4837 #error not hard-float EABI
4838 #else
4839 int dummy;
4840 #endif
4841 }]
4842 }
4843
4844 # Return 1 if this is an ARM target that uses the soft float ABI
4845 # with no floating-point instructions at all (e.g. -mfloat-abi=soft).
4846
4847 proc check_effective_target_arm_softfloat { } {
4848 return [check_no_compiler_messages arm_softfloat object {
4849 #if !defined(__SOFTFP__)
4850 #error not soft-float EABI
4851 #else
4852 int dummy;
4853 #endif
4854 }]
4855 }
4856
4857 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
4858 # Some multilibs may be incompatible with this option.
4859
4860 proc check_effective_target_arm_iwmmxt_ok { } {
4861 if { [check_effective_target_arm32] } {
4862 return [check_no_compiler_messages arm_iwmmxt_ok object {
4863 int dummy;
4864 } "-mcpu=iwmmxt"]
4865 } else {
4866 return 0
4867 }
4868 }
4869
4870 # Return true if LDRD/STRD instructions are prefered over LDM/STM instructions
4871 # for an ARM target.
4872 proc check_effective_target_arm_prefer_ldrd_strd { } {
4873 if { ![check_effective_target_arm32] } {
4874 return 0;
4875 }
4876
4877 return [check_no_messages_and_pattern arm_prefer_ldrd_strd "strd\tr" assembly {
4878 void foo (void) { __asm__ ("" ::: "r4", "r5"); }
4879 } "-O2 -mthumb" ]
4880 }
4881
4882 # Return 1 if this is a PowerPC target supporting -meabi.
4883
4884 proc check_effective_target_powerpc_eabi_ok { } {
4885 if { [istarget powerpc*-*-*] } {
4886 return [check_no_compiler_messages powerpc_eabi_ok object {
4887 int dummy;
4888 } "-meabi"]
4889 } else {
4890 return 0
4891 }
4892 }
4893
4894 # Return 1 if this is a PowerPC target with floating-point registers.
4895
4896 proc check_effective_target_powerpc_fprs { } {
4897 if { [istarget powerpc*-*-*]
4898 || [istarget rs6000-*-*] } {
4899 return [check_no_compiler_messages powerpc_fprs object {
4900 #ifdef __NO_FPRS__
4901 #error no FPRs
4902 #else
4903 int dummy;
4904 #endif
4905 }]
4906 } else {
4907 return 0
4908 }
4909 }
4910
4911 # Return 1 if this is a PowerPC target with hardware double-precision
4912 # floating point.
4913
4914 proc check_effective_target_powerpc_hard_double { } {
4915 if { [istarget powerpc*-*-*]
4916 || [istarget rs6000-*-*] } {
4917 return [check_no_compiler_messages powerpc_hard_double object {
4918 #ifdef _SOFT_DOUBLE
4919 #error soft double
4920 #else
4921 int dummy;
4922 #endif
4923 }]
4924 } else {
4925 return 0
4926 }
4927 }
4928
4929 # Return 1 if this is a PowerPC target supporting -maltivec.
4930
4931 proc check_effective_target_powerpc_altivec_ok { } {
4932 if { ([istarget powerpc*-*-*]
4933 && ![istarget powerpc-*-linux*paired*])
4934 || [istarget rs6000-*-*] } {
4935 # AltiVec is not supported on AIX before 5.3.
4936 if { [istarget powerpc*-*-aix4*]
4937 || [istarget powerpc*-*-aix5.1*]
4938 || [istarget powerpc*-*-aix5.2*] } {
4939 return 0
4940 }
4941 return [check_no_compiler_messages powerpc_altivec_ok object {
4942 int dummy;
4943 } "-maltivec"]
4944 } else {
4945 return 0
4946 }
4947 }
4948
4949 # Return 1 if this is a PowerPC target supporting -mpower8-vector
4950
4951 proc check_effective_target_powerpc_p8vector_ok { } {
4952 if { ([istarget powerpc*-*-*]
4953 && ![istarget powerpc-*-linux*paired*])
4954 || [istarget rs6000-*-*] } {
4955 # AltiVec is not supported on AIX before 5.3.
4956 if { [istarget powerpc*-*-aix4*]
4957 || [istarget powerpc*-*-aix5.1*]
4958 || [istarget powerpc*-*-aix5.2*] } {
4959 return 0
4960 }
4961 return [check_no_compiler_messages powerpc_p8vector_ok object {
4962 int main (void) {
4963 #ifdef __MACH__
4964 asm volatile ("xxlorc vs0,vs0,vs0");
4965 #else
4966 asm volatile ("xxlorc 0,0,0");
4967 #endif
4968 return 0;
4969 }
4970 } "-mpower8-vector"]
4971 } else {
4972 return 0
4973 }
4974 }
4975
4976 # Return 1 if this is a PowerPC target supporting -mpower9-vector
4977
4978 proc check_effective_target_powerpc_p9vector_ok { } {
4979 if { ([istarget powerpc*-*-*]
4980 && ![istarget powerpc-*-linux*paired*])
4981 || [istarget rs6000-*-*] } {
4982 # AltiVec is not supported on AIX before 5.3.
4983 if { [istarget powerpc*-*-aix4*]
4984 || [istarget powerpc*-*-aix5.1*]
4985 || [istarget powerpc*-*-aix5.2*] } {
4986 return 0
4987 }
4988 return [check_no_compiler_messages powerpc_p9vector_ok object {
4989 int main (void) {
4990 long e = -1;
4991 vector double v = (vector double) { 0.0, 0.0 };
4992 asm ("xsxexpdp %0,%1" : "+r" (e) : "wa" (v));
4993 return e;
4994 }
4995 } "-mpower9-vector"]
4996 } else {
4997 return 0
4998 }
4999 }
5000
5001 # Return 1 if this is a PowerPC target supporting -mmodulo
5002
5003 proc check_effective_target_powerpc_p9modulo_ok { } {
5004 if { ([istarget powerpc*-*-*]
5005 && ![istarget powerpc-*-linux*paired*])
5006 || [istarget rs6000-*-*] } {
5007 # AltiVec is not supported on AIX before 5.3.
5008 if { [istarget powerpc*-*-aix4*]
5009 || [istarget powerpc*-*-aix5.1*]
5010 || [istarget powerpc*-*-aix5.2*] } {
5011 return 0
5012 }
5013 return [check_no_compiler_messages powerpc_p9modulo_ok object {
5014 int main (void) {
5015 int i = 5, j = 3, r = -1;
5016 asm ("modsw %0,%1,%2" : "+r" (r) : "r" (i), "r" (j));
5017 return (r == 2);
5018 }
5019 } "-mmodulo"]
5020 } else {
5021 return 0
5022 }
5023 }
5024
5025 # Return 1 if this is a PowerPC target supporting -mfloat128 via either
5026 # software emulation on power7/power8 systems or hardware support on power9.
5027
5028 proc check_effective_target_powerpc_float128_sw_ok { } {
5029 if { ([istarget powerpc*-*-*]
5030 && ![istarget powerpc-*-linux*paired*])
5031 || [istarget rs6000-*-*] } {
5032 # AltiVec is not supported on AIX before 5.3.
5033 if { [istarget powerpc*-*-aix4*]
5034 || [istarget powerpc*-*-aix5.1*]
5035 || [istarget powerpc*-*-aix5.2*] } {
5036 return 0
5037 }
5038 return [check_no_compiler_messages powerpc_float128_sw_ok object {
5039 volatile __float128 x = 1.0q;
5040 volatile __float128 y = 2.0q;
5041 int main() {
5042 __float128 z = x + y;
5043 return (z == 3.0q);
5044 }
5045 } "-mfloat128 -mvsx"]
5046 } else {
5047 return 0
5048 }
5049 }
5050
5051 # Return 1 if this is a PowerPC target supporting -mfloat128 via hardware
5052 # support on power9.
5053
5054 proc check_effective_target_powerpc_float128_hw_ok { } {
5055 if { ([istarget powerpc*-*-*]
5056 && ![istarget powerpc-*-linux*paired*])
5057 || [istarget rs6000-*-*] } {
5058 # AltiVec is not supported on AIX before 5.3.
5059 if { [istarget powerpc*-*-aix4*]
5060 || [istarget powerpc*-*-aix5.1*]
5061 || [istarget powerpc*-*-aix5.2*] } {
5062 return 0
5063 }
5064 return [check_no_compiler_messages powerpc_float128_hw_ok object {
5065 volatile __float128 x = 1.0q;
5066 volatile __float128 y = 2.0q;
5067 int main() {
5068 __float128 z;
5069 __asm__ ("xsaddqp %0,%1,%2" : "=v" (z) : "v" (x), "v" (y));
5070 return (z == 3.0q);
5071 }
5072 } "-mfloat128-hardware"]
5073 } else {
5074 return 0
5075 }
5076 }
5077
5078 # Return 1 if current options define float128, 0 otherwise.
5079
5080 proc check_effective_target_ppc_float128 { } {
5081 return [check_no_compiler_messages_nocache ppc_float128 object {
5082 #ifndef __FLOAT128__
5083 nope no good
5084 #endif
5085 }]
5086 }
5087
5088 # Return 1 if current options generate float128 insns, 0 otherwise.
5089
5090 proc check_effective_target_ppc_float128_insns { } {
5091 return [check_no_compiler_messages_nocache ppc_float128 object {
5092 #ifndef __FLOAT128_HARDWARE__
5093 nope no good
5094 #endif
5095 }]
5096 }
5097
5098 # Return 1 if current options generate VSX instructions, 0 otherwise.
5099
5100 proc check_effective_target_powerpc_vsx { } {
5101 return [check_no_compiler_messages_nocache powerpc_vsx object {
5102 #ifndef __VSX__
5103 nope no vsx
5104 #endif
5105 }]
5106 }
5107
5108 # Return 1 if this is a PowerPC target supporting -mvsx
5109
5110 proc check_effective_target_powerpc_vsx_ok { } {
5111 if { ([istarget powerpc*-*-*]
5112 && ![istarget powerpc-*-linux*paired*])
5113 || [istarget rs6000-*-*] } {
5114 # VSX is not supported on AIX before 7.1.
5115 if { [istarget powerpc*-*-aix4*]
5116 || [istarget powerpc*-*-aix5*]
5117 || [istarget powerpc*-*-aix6*] } {
5118 return 0
5119 }
5120 return [check_no_compiler_messages powerpc_vsx_ok object {
5121 int main (void) {
5122 #ifdef __MACH__
5123 asm volatile ("xxlor vs0,vs0,vs0");
5124 #else
5125 asm volatile ("xxlor 0,0,0");
5126 #endif
5127 return 0;
5128 }
5129 } "-mvsx"]
5130 } else {
5131 return 0
5132 }
5133 }
5134
5135 # Return 1 if this is a PowerPC target supporting -mhtm
5136
5137 proc check_effective_target_powerpc_htm_ok { } {
5138 if { ([istarget powerpc*-*-*]
5139 && ![istarget powerpc-*-linux*paired*])
5140 || [istarget rs6000-*-*] } {
5141 # HTM is not supported on AIX yet.
5142 if { [istarget powerpc*-*-aix*] } {
5143 return 0
5144 }
5145 return [check_no_compiler_messages powerpc_htm_ok object {
5146 int main (void) {
5147 asm volatile ("tbegin. 0");
5148 return 0;
5149 }
5150 } "-mhtm"]
5151 } else {
5152 return 0
5153 }
5154 }
5155
5156 # Return 1 if the target supports executing HTM hardware instructions,
5157 # 0 otherwise. Cache the result.
5158
5159 proc check_htm_hw_available { } {
5160 return [check_cached_effective_target htm_hw_available {
5161 # For now, disable on Darwin
5162 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
5163 expr 0
5164 } else {
5165 check_runtime_nocache htm_hw_available {
5166 int main()
5167 {
5168 __builtin_ttest ();
5169 return 0;
5170 }
5171 } "-mhtm"
5172 }
5173 }]
5174 }
5175 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
5176
5177 proc check_effective_target_powerpc_ppu_ok { } {
5178 if [check_effective_target_powerpc_altivec_ok] {
5179 return [check_no_compiler_messages cell_asm_available object {
5180 int main (void) {
5181 #ifdef __MACH__
5182 asm volatile ("lvlx v0,v0,v0");
5183 #else
5184 asm volatile ("lvlx 0,0,0");
5185 #endif
5186 return 0;
5187 }
5188 }]
5189 } else {
5190 return 0
5191 }
5192 }
5193
5194 # Return 1 if this is a PowerPC target that supports SPU.
5195
5196 proc check_effective_target_powerpc_spu { } {
5197 if { [istarget powerpc*-*-linux*] } {
5198 return [check_effective_target_powerpc_altivec_ok]
5199 } else {
5200 return 0
5201 }
5202 }
5203
5204 # Return 1 if this is a PowerPC SPE target. The check includes options
5205 # specified by dg-options for this test, so don't cache the result.
5206
5207 proc check_effective_target_powerpc_spe_nocache { } {
5208 if { [istarget powerpc*-*-*] } {
5209 return [check_no_compiler_messages_nocache powerpc_spe object {
5210 #ifndef __SPE__
5211 #error not SPE
5212 #else
5213 int dummy;
5214 #endif
5215 } [current_compiler_flags]]
5216 } else {
5217 return 0
5218 }
5219 }
5220
5221 # Return 1 if this is a PowerPC target with SPE enabled.
5222
5223 proc check_effective_target_powerpc_spe { } {
5224 if { [istarget powerpc*-*-*] } {
5225 return [check_no_compiler_messages powerpc_spe object {
5226 #ifndef __SPE__
5227 #error not SPE
5228 #else
5229 int dummy;
5230 #endif
5231 }]
5232 } else {
5233 return 0
5234 }
5235 }
5236
5237 # Return 1 if this is a PowerPC target with Altivec enabled.
5238
5239 proc check_effective_target_powerpc_altivec { } {
5240 if { [istarget powerpc*-*-*] } {
5241 return [check_no_compiler_messages powerpc_altivec object {
5242 #ifndef __ALTIVEC__
5243 #error not Altivec
5244 #else
5245 int dummy;
5246 #endif
5247 }]
5248 } else {
5249 return 0
5250 }
5251 }
5252
5253 # Return 1 if this is a PowerPC 405 target. The check includes options
5254 # specified by dg-options for this test, so don't cache the result.
5255
5256 proc check_effective_target_powerpc_405_nocache { } {
5257 if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
5258 return [check_no_compiler_messages_nocache powerpc_405 object {
5259 #ifdef __PPC405__
5260 int dummy;
5261 #else
5262 #error not a PPC405
5263 #endif
5264 } [current_compiler_flags]]
5265 } else {
5266 return 0
5267 }
5268 }
5269
5270 # Return 1 if this is a PowerPC target using the ELFv2 ABI.
5271
5272 proc check_effective_target_powerpc_elfv2 { } {
5273 if { [istarget powerpc*-*-*] } {
5274 return [check_no_compiler_messages powerpc_elfv2 object {
5275 #if _CALL_ELF != 2
5276 #error not ELF v2 ABI
5277 #else
5278 int dummy;
5279 #endif
5280 }]
5281 } else {
5282 return 0
5283 }
5284 }
5285
5286 # Return 1 if this is a SPU target with a toolchain that
5287 # supports automatic overlay generation.
5288
5289 proc check_effective_target_spu_auto_overlay { } {
5290 if { [istarget spu*-*-elf*] } {
5291 return [check_no_compiler_messages spu_auto_overlay executable {
5292 int main (void) { }
5293 } "-Wl,--auto-overlay" ]
5294 } else {
5295 return 0
5296 }
5297 }
5298
5299 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
5300 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables. Return 1 if the
5301 # test environment appears to run executables on such a simulator.
5302
5303 proc check_effective_target_ultrasparc_hw { } {
5304 return [check_runtime ultrasparc_hw {
5305 int main() { return 0; }
5306 } "-mcpu=ultrasparc"]
5307 }
5308
5309 # Return 1 if the test environment supports executing UltraSPARC VIS2
5310 # instructions. We check this by attempting: "bmask %g0, %g0, %g0"
5311
5312 proc check_effective_target_ultrasparc_vis2_hw { } {
5313 return [check_runtime ultrasparc_vis2_hw {
5314 int main() { __asm__(".word 0x81b00320"); return 0; }
5315 } "-mcpu=ultrasparc3"]
5316 }
5317
5318 # Return 1 if the test environment supports executing UltraSPARC VIS3
5319 # instructions. We check this by attempting: "addxc %g0, %g0, %g0"
5320
5321 proc check_effective_target_ultrasparc_vis3_hw { } {
5322 return [check_runtime ultrasparc_vis3_hw {
5323 int main() { __asm__(".word 0x81b00220"); return 0; }
5324 } "-mcpu=niagara3"]
5325 }
5326
5327 # Return 1 if this is a SPARC-V9 target.
5328
5329 proc check_effective_target_sparc_v9 { } {
5330 if { [istarget sparc*-*-*] } {
5331 return [check_no_compiler_messages sparc_v9 object {
5332 int main (void) {
5333 asm volatile ("return %i7+8");
5334 return 0;
5335 }
5336 }]
5337 } else {
5338 return 0
5339 }
5340 }
5341
5342 # Return 1 if this is a SPARC target with VIS enabled.
5343
5344 proc check_effective_target_sparc_vis { } {
5345 if { [istarget sparc*-*-*] } {
5346 return [check_no_compiler_messages sparc_vis object {
5347 #ifndef __VIS__
5348 #error not VIS
5349 #else
5350 int dummy;
5351 #endif
5352 }]
5353 } else {
5354 return 0
5355 }
5356 }
5357
5358 # Return 1 if the target supports hardware vector shift operation.
5359
5360 proc check_effective_target_vect_shift { } {
5361 return [check_cached_effective_target_indexed vect_shift {
5362 expr {([istarget powerpc*-*-*]
5363 && ![istarget powerpc-*-linux*paired*])
5364 || [istarget ia64-*-*]
5365 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5366 || [istarget aarch64*-*-*]
5367 || [is-effective-target arm_neon]
5368 || ([istarget mips*-*-*]
5369 && ([et-is-effective-target mips_msa]
5370 || [et-is-effective-target mips_loongson_mmi]))
5371 || ([istarget s390*-*-*]
5372 && [check_effective_target_s390_vx]) }}]
5373 }
5374
5375 # Return 1 if the target supports hardware vector shift by register operation.
5376
5377 proc check_effective_target_vect_var_shift { } {
5378 return [check_cached_effective_target_indexed vect_var_shift {
5379 expr {(([istarget i?86-*-*] || [istarget x86_64-*-*])
5380 && [check_avx2_available])
5381 }}]
5382 }
5383
5384 proc check_effective_target_whole_vector_shift { } {
5385 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5386 || [istarget ia64-*-*]
5387 || [istarget aarch64*-*-*]
5388 || [istarget powerpc64*-*-*]
5389 || ([is-effective-target arm_neon]
5390 && [check_effective_target_arm_little_endian])
5391 || ([istarget mips*-*-*]
5392 && [et-is-effective-target mips_loongson_mmi])
5393 || ([istarget s390*-*-*]
5394 && [check_effective_target_s390_vx]) } {
5395 set answer 1
5396 } else {
5397 set answer 0
5398 }
5399
5400 verbose "check_effective_target_vect_long: returning $answer" 2
5401 return $answer
5402 }
5403
5404 # Return 1 if the target supports vector bswap operations.
5405
5406 proc check_effective_target_vect_bswap { } {
5407 return [check_cached_effective_target_indexed vect_bswap {
5408 expr { [istarget aarch64*-*-*] || [is-effective-target arm_neon] }}]
5409 }
5410
5411 # Return 1 if the target supports hardware vector shift operation for char.
5412
5413 proc check_effective_target_vect_shift_char { } {
5414 return [check_cached_effective_target_indexed vect_shift_char {
5415 expr { ([istarget powerpc*-*-*]
5416 && ![istarget powerpc-*-linux*paired*])
5417 || [is-effective-target arm_neon]
5418 || ([istarget mips*-*-*]
5419 && [et-is-effective-target mips_msa])
5420 || ([istarget s390*-*-*]
5421 && [check_effective_target_s390_vx]) }}]
5422 }
5423
5424 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
5425 #
5426 # This can change for different subtargets so do not cache the result.
5427
5428 proc check_effective_target_vect_long { } {
5429 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
5430 || (([istarget powerpc*-*-*]
5431 && ![istarget powerpc-*-linux*paired*])
5432 && [check_effective_target_ilp32])
5433 || [is-effective-target arm_neon]
5434 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
5435 || [istarget aarch64*-*-*]
5436 || ([istarget mips*-*-*]
5437 && [et-is-effective-target mips_msa])
5438 || ([istarget s390*-*-*]
5439 && [check_effective_target_s390_vx]) } {
5440 set answer 1
5441 } else {
5442 set answer 0
5443 }
5444
5445 verbose "check_effective_target_vect_long: returning $answer" 2
5446 return $answer
5447 }
5448
5449 # Return 1 if the target supports hardware vectors of float when
5450 # -funsafe-math-optimizations is enabled, 0 otherwise.
5451 #
5452 # This won't change for different subtargets so cache the result.
5453
5454 proc check_effective_target_vect_float { } {
5455 return [check_cached_effective_target_indexed vect_float {
5456 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
5457 || [istarget powerpc*-*-*]
5458 || [istarget spu-*-*]
5459 || [istarget mips-sde-elf]
5460 || [istarget mipsisa64*-*-*]
5461 || [istarget ia64-*-*]
5462 || [istarget aarch64*-*-*]
5463 || ([istarget mips*-*-*]
5464 && [et-is-effective-target mips_msa])
5465 || [is-effective-target arm_neon]
5466 || ([istarget s390*-*-*]
5467 && [check_effective_target_s390_vxe]) }}]
5468 }
5469
5470 # Return 1 if the target supports hardware vectors of float without
5471 # -funsafe-math-optimizations being enabled, 0 otherwise.
5472
5473 proc check_effective_target_vect_float_strict { } {
5474 return [expr { [check_effective_target_vect_float]
5475 && ![istarget arm*-*-*] }]
5476 }
5477
5478 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
5479 #
5480 # This won't change for different subtargets so cache the result.
5481
5482 proc check_effective_target_vect_double { } {
5483 return [check_cached_effective_target_indexed vect_double {
5484 expr { (([istarget i?86-*-*] || [istarget x86_64-*-*])
5485 && [check_no_compiler_messages vect_double assembly {
5486 #ifdef __tune_atom__
5487 # error No double vectorizer support.
5488 #endif
5489 }])
5490 || [istarget aarch64*-*-*]
5491 || [istarget spu-*-*]
5492 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
5493 || ([istarget mips*-*-*]
5494 && [et-is-effective-target mips_msa])
5495 || ([istarget s390*-*-*]
5496 && [check_effective_target_s390_vx])} }]
5497 }
5498
5499 # Return 1 if the target supports conditional addition, subtraction,
5500 # multiplication, division, minimum and maximum on vectors of double,
5501 # via the cond_ optabs. Return 0 otherwise.
5502
5503 proc check_effective_target_vect_double_cond_arith { } {
5504 return [check_effective_target_aarch64_sve]
5505 }
5506
5507 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
5508 #
5509 # This won't change for different subtargets so cache the result.
5510
5511 proc check_effective_target_vect_long_long { } {
5512 return [check_cached_effective_target_indexed vect_long_long {
5513 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
5514 || ([istarget mips*-*-*]
5515 && [et-is-effective-target mips_msa])
5516 || ([istarget s390*-*-*]
5517 && [check_effective_target_s390_vx]) }}]
5518 }
5519
5520
5521 # Return 1 if the target plus current options does not support a vector
5522 # max instruction on "int", 0 otherwise.
5523 #
5524 # This won't change for different subtargets so cache the result.
5525
5526 proc check_effective_target_vect_no_int_min_max { } {
5527 return [check_cached_effective_target_indexed vect_no_int_min_max {
5528 expr { [istarget sparc*-*-*]
5529 || [istarget spu-*-*]
5530 || [istarget alpha*-*-*]
5531 || ([istarget mips*-*-*]
5532 && [et-is-effective-target mips_loongson_mmi]) }}]
5533 }
5534
5535 # Return 1 if the target plus current options does not support a vector
5536 # add instruction on "int", 0 otherwise.
5537 #
5538 # This won't change for different subtargets so cache the result.
5539
5540 proc check_effective_target_vect_no_int_add { } {
5541 # Alpha only supports vector add on V8QI and V4HI.
5542 return [check_cached_effective_target_indexed vect_no_int_add {
5543 expr { [istarget alpha*-*-*] }}]
5544 }
5545
5546 # Return 1 if the target plus current options does not support vector
5547 # bitwise instructions, 0 otherwise.
5548 #
5549 # This won't change for different subtargets so cache the result.
5550
5551 proc check_effective_target_vect_no_bitwise { } {
5552 return [check_cached_effective_target_indexed vect_no_bitwise { return 0 }]
5553 }
5554
5555 # Return 1 if the target plus current options supports vector permutation,
5556 # 0 otherwise.
5557 #
5558 # This won't change for different subtargets so cache the result.
5559
5560 proc check_effective_target_vect_perm { } {
5561 return [check_cached_effective_target_indexed vect_perm {
5562 expr { [is-effective-target arm_neon]
5563 || [istarget aarch64*-*-*]
5564 || [istarget powerpc*-*-*]
5565 || [istarget spu-*-*]
5566 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5567 || ([istarget mips*-*-*]
5568 && ([et-is-effective-target mpaired_single]
5569 || [et-is-effective-target mips_msa]))
5570 || ([istarget s390*-*-*]
5571 && [check_effective_target_s390_vx]) }}]
5572 }
5573
5574 # Return 1 if, for some VF:
5575 #
5576 # - the target's default vector size is VF * ELEMENT_BITS bits
5577 #
5578 # - it is possible to implement the equivalent of:
5579 #
5580 # int<ELEMENT_BITS>_t s1[COUNT][COUNT * VF], s2[COUNT * VF];
5581 # for (int i = 0; i < COUNT; ++i)
5582 # for (int j = 0; j < COUNT * VF; ++j)
5583 # s1[i][j] = s2[j - j % COUNT + i]
5584 #
5585 # using only a single 2-vector permute for each vector in s1.
5586 #
5587 # E.g. for COUNT == 3 and vector length 4, the two arrays would be:
5588 #
5589 # s2 | a0 a1 a2 a3 | b0 b1 b2 b3 | c0 c1 c2 c3
5590 # ------+-------------+-------------+------------
5591 # s1[0] | a0 a0 a0 a3 | a3 a3 b2 b2 | b2 c1 c1 c1
5592 # s1[1] | a1 a1 a1 b0 | b0 b0 b3 b3 | b3 c2 c2 c2
5593 # s1[2] | a2 a2 a2 b1 | b1 b1 c0 c0 | c0 c3 c3 c3
5594 #
5595 # Each s1 permute requires only two of a, b and c.
5596 #
5597 # The distance between the start of vector n in s1[0] and the start
5598 # of vector n in s2 is:
5599 #
5600 # A = (n * VF) % COUNT
5601 #
5602 # The corresponding value for the end of vector n is:
5603 #
5604 # B = (n * VF + VF - 1) % COUNT
5605 #
5606 # Subtracting i from each value gives the corresponding difference
5607 # for s1[i]. The condition being tested by this function is false
5608 # iff A - i > 0 and B - i < 0 for some i and n, such that the first
5609 # element for s1[i] comes from vector n - 1 of s2 and the last element
5610 # comes from vector n + 1 of s2. The condition is therefore true iff
5611 # A <= B for all n. This is turn means the condition is true iff:
5612 #
5613 # (n * VF) % COUNT + (VF - 1) % COUNT < COUNT
5614 #
5615 # for all n. COUNT - (n * VF) % COUNT is bounded by gcd (VF, COUNT),
5616 # and will be that value for at least one n in [0, COUNT), so we want:
5617 #
5618 # (VF - 1) % COUNT < gcd (VF, COUNT)
5619
5620 proc vect_perm_supported { count element_bits } {
5621 set vector_bits [lindex [available_vector_sizes] 0]
5622 # The number of vectors has to be a power of 2 when permuting
5623 # variable-length vectors.
5624 if { $vector_bits <= 0 && ($count & -$count) != $count } {
5625 return 0
5626 }
5627 set vf [expr { $vector_bits / $element_bits }]
5628
5629 # Compute gcd (VF, COUNT).
5630 set gcd $vf
5631 set temp1 $count
5632 while { $temp1 > 0 } {
5633 set temp2 [expr { $gcd % $temp1 }]
5634 set gcd $temp1
5635 set temp1 $temp2
5636 }
5637 return [expr { ($vf - 1) % $count < $gcd }]
5638 }
5639
5640 # Return 1 if the target supports SLP permutation of 3 vectors when each
5641 # element has 32 bits.
5642
5643 proc check_effective_target_vect_perm3_int { } {
5644 return [expr { [check_effective_target_vect_perm]
5645 && [vect_perm_supported 3 32] }]
5646 }
5647
5648 # Return 1 if the target plus current options supports vector permutation
5649 # on byte-sized elements, 0 otherwise.
5650 #
5651 # This won't change for different subtargets so cache the result.
5652
5653 proc check_effective_target_vect_perm_byte { } {
5654 return [check_cached_effective_target_indexed vect_perm_byte {
5655 expr { ([is-effective-target arm_neon]
5656 && [is-effective-target arm_little_endian])
5657 || ([istarget aarch64*-*-*]
5658 && [is-effective-target aarch64_little_endian])
5659 || [istarget powerpc*-*-*]
5660 || [istarget spu-*-*]
5661 || ([istarget mips-*.*]
5662 && [et-is-effective-target mips_msa])
5663 || ([istarget s390*-*-*]
5664 && [check_effective_target_s390_vx]) }}]
5665 }
5666
5667 # Return 1 if the target supports SLP permutation of 3 vectors when each
5668 # element has 8 bits.
5669
5670 proc check_effective_target_vect_perm3_byte { } {
5671 return [expr { [check_effective_target_vect_perm_byte]
5672 && [vect_perm_supported 3 8] }]
5673 }
5674
5675 # Return 1 if the target plus current options supports vector permutation
5676 # on short-sized elements, 0 otherwise.
5677 #
5678 # This won't change for different subtargets so cache the result.
5679
5680 proc check_effective_target_vect_perm_short { } {
5681 return [check_cached_effective_target_indexed vect_perm_short {
5682 expr { ([is-effective-target arm_neon]
5683 && [is-effective-target arm_little_endian])
5684 || ([istarget aarch64*-*-*]
5685 && [is-effective-target aarch64_little_endian])
5686 || [istarget powerpc*-*-*]
5687 || [istarget spu-*-*]
5688 || (([istarget i?86-*-*] || [istarget x86_64-*-*])
5689 && [check_ssse3_available])
5690 || ([istarget mips*-*-*]
5691 && [et-is-effective-target mips_msa])
5692 || ([istarget s390*-*-*]
5693 && [check_effective_target_s390_vx]) }}]
5694 }
5695
5696 # Return 1 if the target supports SLP permutation of 3 vectors when each
5697 # element has 16 bits.
5698
5699 proc check_effective_target_vect_perm3_short { } {
5700 return [expr { [check_effective_target_vect_perm_short]
5701 && [vect_perm_supported 3 16] }]
5702 }
5703
5704 # Return 1 if the target plus current options supports folding of
5705 # copysign into XORSIGN.
5706 #
5707 # This won't change for different subtargets so cache the result.
5708
5709 proc check_effective_target_xorsign { } {
5710 return [check_cached_effective_target_indexed xorsign {
5711 expr { [istarget aarch64*-*-*] || [istarget arm*-*-*] }}]
5712 }
5713
5714 # Return 1 if the target plus current options supports a vector
5715 # widening summation of *short* args into *int* result, 0 otherwise.
5716 #
5717 # This won't change for different subtargets so cache the result.
5718
5719 proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
5720 return [check_cached_effective_target_indexed vect_widen_sum_hi_to_si_pattern {
5721 expr { [istarget powerpc*-*-*]
5722 || ([istarget aarch64*-*-*]
5723 && ![check_effective_target_aarch64_sve])
5724 || [is-effective-target arm_neon]
5725 || [istarget ia64-*-*] }}]
5726 }
5727
5728 # Return 1 if the target plus current options supports a vector
5729 # widening summation of *short* args into *int* result, 0 otherwise.
5730 # A target can also support this widening summation if it can support
5731 # promotion (unpacking) from shorts to ints.
5732 #
5733 # This won't change for different subtargets so cache the result.
5734
5735 proc check_effective_target_vect_widen_sum_hi_to_si { } {
5736 return [check_cached_effective_target_indexed vect_widen_sum_hi_to_si {
5737 expr { [check_effective_target_vect_unpack]
5738 || [istarget powerpc*-*-*]
5739 || [istarget ia64-*-*] }}]
5740 }
5741
5742 # Return 1 if the target plus current options supports a vector
5743 # widening summation of *char* args into *short* result, 0 otherwise.
5744 # A target can also support this widening summation if it can support
5745 # promotion (unpacking) from chars to shorts.
5746 #
5747 # This won't change for different subtargets so cache the result.
5748
5749 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
5750 return [check_cached_effective_target_indexed vect_widen_sum_qi_to_hi {
5751 expr { [check_effective_target_vect_unpack]
5752 || [is-effective-target arm_neon]
5753 || [istarget ia64-*-*] }}]
5754 }
5755
5756 # Return 1 if the target plus current options supports a vector
5757 # widening summation of *char* args into *int* result, 0 otherwise.
5758 #
5759 # This won't change for different subtargets so cache the result.
5760
5761 proc check_effective_target_vect_widen_sum_qi_to_si { } {
5762 return [check_cached_effective_target_indexed vect_widen_sum_qi_to_si {
5763 expr { [istarget powerpc*-*-*] }}]
5764 }
5765
5766 # Return 1 if the target plus current options supports a vector
5767 # widening multiplication of *char* args into *short* result, 0 otherwise.
5768 # A target can also support this widening multplication if it can support
5769 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
5770 # multiplication of shorts).
5771 #
5772 # This won't change for different subtargets so cache the result.
5773
5774
5775 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
5776 return [check_cached_effective_target_indexed vect_widen_mult_qi_to_hi {
5777 expr { ([check_effective_target_vect_unpack]
5778 && [check_effective_target_vect_short_mult])
5779 || ([istarget powerpc*-*-*]
5780 || ([istarget aarch64*-*-*]
5781 && ![check_effective_target_aarch64_sve])
5782 || [is-effective-target arm_neon]
5783 || ([istarget s390*-*-*]
5784 && [check_effective_target_s390_vx])) }}]
5785 }
5786
5787 # Return 1 if the target plus current options supports a vector
5788 # widening multiplication of *short* args into *int* result, 0 otherwise.
5789 # A target can also support this widening multplication if it can support
5790 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
5791 # multiplication of ints).
5792 #
5793 # This won't change for different subtargets so cache the result.
5794
5795
5796 proc check_effective_target_vect_widen_mult_hi_to_si { } {
5797 return [check_cached_effective_target_indexed vect_widen_mult_hi_to_si {
5798 expr { ([check_effective_target_vect_unpack]
5799 && [check_effective_target_vect_int_mult])
5800 || ([istarget powerpc*-*-*]
5801 || [istarget spu-*-*]
5802 || [istarget ia64-*-*]
5803 || ([istarget aarch64*-*-*]
5804 && ![check_effective_target_aarch64_sve])
5805 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5806 || [is-effective-target arm_neon]
5807 || ([istarget s390*-*-*]
5808 && [check_effective_target_s390_vx])) }}]
5809 }
5810
5811 # Return 1 if the target plus current options supports a vector
5812 # widening multiplication of *char* args into *short* result, 0 otherwise.
5813 #
5814 # This won't change for different subtargets so cache the result.
5815
5816 proc check_effective_target_vect_widen_mult_qi_to_hi_pattern { } {
5817 return [check_cached_effective_target_indexed vect_widen_mult_qi_to_hi_pattern {
5818 expr { [istarget powerpc*-*-*]
5819 || ([is-effective-target arm_neon]
5820 && [check_effective_target_arm_little_endian])
5821 || ([istarget s390*-*-*]
5822 && [check_effective_target_s390_vx]) }}]
5823 }
5824
5825 # Return 1 if the target plus current options supports a vector
5826 # widening multiplication of *short* args into *int* result, 0 otherwise.
5827 #
5828 # This won't change for different subtargets so cache the result.
5829
5830 proc check_effective_target_vect_widen_mult_hi_to_si_pattern { } {
5831 return [check_cached_effective_target_indexed vect_widen_mult_hi_to_si_pattern {
5832 expr { [istarget powerpc*-*-*]
5833 || [istarget spu-*-*]
5834 || [istarget ia64-*-*]
5835 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5836 || ([is-effective-target arm_neon]
5837 && [check_effective_target_arm_little_endian])
5838 || ([istarget s390*-*-*]
5839 && [check_effective_target_s390_vx]) }}]
5840 }
5841
5842 # Return 1 if the target plus current options supports a vector
5843 # widening multiplication of *int* args into *long* result, 0 otherwise.
5844 #
5845 # This won't change for different subtargets so cache the result.
5846
5847 proc check_effective_target_vect_widen_mult_si_to_di_pattern { } {
5848 return [check_cached_effective_target_indexed vect_widen_mult_si_to_di_pattern {
5849 expr { [istarget ia64-*-*]
5850 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5851 || ([istarget s390*-*-*]
5852 && [check_effective_target_s390_vx]) }}]
5853 }
5854
5855 # Return 1 if the target plus current options supports a vector
5856 # widening shift, 0 otherwise.
5857 #
5858 # This won't change for different subtargets so cache the result.
5859
5860 proc check_effective_target_vect_widen_shift { } {
5861 return [check_cached_effective_target_indexed vect_widen_shift {
5862 expr { [is-effective-target arm_neon] }}]
5863 }
5864
5865 # Return 1 if the target plus current options supports a vector
5866 # dot-product of signed chars, 0 otherwise.
5867 #
5868 # This won't change for different subtargets so cache the result.
5869
5870 proc check_effective_target_vect_sdot_qi { } {
5871 return [check_cached_effective_target_indexed vect_sdot_qi {
5872 expr { [istarget ia64-*-*]
5873 || [istarget aarch64*-*-*]
5874 || [istarget arm*-*-*]
5875 || ([istarget mips*-*-*]
5876 && [et-is-effective-target mips_msa]) }}]
5877 }
5878
5879 # Return 1 if the target plus current options supports a vector
5880 # dot-product of unsigned chars, 0 otherwise.
5881 #
5882 # This won't change for different subtargets so cache the result.
5883
5884 proc check_effective_target_vect_udot_qi { } {
5885 return [check_cached_effective_target_indexed vect_udot_qi {
5886 expr { [istarget powerpc*-*-*]
5887 || [istarget aarch64*-*-*]
5888 || [istarget arm*-*-*]
5889 || [istarget ia64-*-*]
5890 || ([istarget mips*-*-*]
5891 && [et-is-effective-target mips_msa]) }}]
5892 }
5893
5894 # Return 1 if the target plus current options supports a vector
5895 # dot-product of signed shorts, 0 otherwise.
5896 #
5897 # This won't change for different subtargets so cache the result.
5898
5899 proc check_effective_target_vect_sdot_hi { } {
5900 return [check_cached_effective_target_indexed vect_sdot_hi {
5901 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
5902 || [istarget ia64-*-*]
5903 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5904 || ([istarget mips*-*-*]
5905 && [et-is-effective-target mips_msa]) }}]
5906 }
5907
5908 # Return 1 if the target plus current options supports a vector
5909 # dot-product of unsigned shorts, 0 otherwise.
5910 #
5911 # This won't change for different subtargets so cache the result.
5912
5913 proc check_effective_target_vect_udot_hi { } {
5914 return [check_cached_effective_target_indexed vect_udot_hi {
5915 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
5916 || ([istarget mips*-*-*]
5917 && [et-is-effective-target mips_msa]) }}]
5918 }
5919
5920 # Return 1 if the target plus current options supports a vector
5921 # sad operation of unsigned chars, 0 otherwise.
5922 #
5923 # This won't change for different subtargets so cache the result.
5924
5925 proc check_effective_target_vect_usad_char { } {
5926 return [check_cached_effective_target_indexed vect_usad_char {
5927 expr { [istarget i?86-*-*] || [istarget x86_64-*-*] }}]
5928 }
5929
5930 # Return 1 if the target plus current options supports both signed
5931 # and unsigned average operations on vectors of bytes.
5932
5933 proc check_effective_target_vect_avg_qi {} {
5934 return [expr { [istarget aarch64*-*-*]
5935 && ![check_effective_target_aarch64_sve] }]
5936 }
5937
5938 # Return 1 if the target plus current options supports a vector
5939 # demotion (packing) of shorts (to chars) and ints (to shorts)
5940 # using modulo arithmetic, 0 otherwise.
5941 #
5942 # This won't change for different subtargets so cache the result.
5943
5944 proc check_effective_target_vect_pack_trunc { } {
5945 return [check_cached_effective_target_indexed vect_pack_trunc {
5946 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
5947 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5948 || [istarget aarch64*-*-*]
5949 || [istarget spu-*-*]
5950 || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok]
5951 && [check_effective_target_arm_little_endian])
5952 || ([istarget mips*-*-*]
5953 && [et-is-effective-target mips_msa])
5954 || ([istarget s390*-*-*]
5955 && [check_effective_target_s390_vx]) }}]
5956 }
5957
5958 # Return 1 if the target plus current options supports a vector
5959 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
5960 #
5961 # This won't change for different subtargets so cache the result.
5962
5963 proc check_effective_target_vect_unpack { } {
5964 return [check_cached_effective_target_indexed vect_unpack {
5965 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
5966 || [istarget i?86-*-*] || [istarget x86_64-*-*]
5967 || [istarget spu-*-*]
5968 || [istarget ia64-*-*]
5969 || [istarget aarch64*-*-*]
5970 || ([istarget mips*-*-*]
5971 && [et-is-effective-target mips_msa])
5972 || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok]
5973 && [check_effective_target_arm_little_endian])
5974 || ([istarget s390*-*-*]
5975 && [check_effective_target_s390_vx]) }}]
5976 }
5977
5978 # Return 1 if the target plus current options does not guarantee
5979 # that its STACK_BOUNDARY is >= the reguired vector alignment.
5980 #
5981 # This won't change for different subtargets so cache the result.
5982
5983 proc check_effective_target_unaligned_stack { } {
5984 return [check_cached_effective_target_indexed unaligned_stack { expr 0 }]
5985 }
5986
5987 # Return 1 if the target plus current options does not support a vector
5988 # alignment mechanism, 0 otherwise.
5989 #
5990 # This won't change for different subtargets so cache the result.
5991
5992 proc check_effective_target_vect_no_align { } {
5993 return [check_cached_effective_target_indexed vect_no_align {
5994 expr { [istarget mipsisa64*-*-*]
5995 || [istarget mips-sde-elf]
5996 || [istarget sparc*-*-*]
5997 || [istarget ia64-*-*]
5998 || [check_effective_target_arm_vect_no_misalign]
5999 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
6000 || ([istarget mips*-*-*]
6001 && [et-is-effective-target mips_loongson_mmi]) }}]
6002 }
6003
6004 # Return 1 if the target supports a vector misalign access, 0 otherwise.
6005 #
6006 # This won't change for different subtargets so cache the result.
6007
6008 proc check_effective_target_vect_hw_misalign { } {
6009 return [check_cached_effective_target_indexed vect_hw_misalign {
6010 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6011 || ([istarget powerpc*-*-*] && [check_p8vector_hw_available])
6012 || [istarget aarch64*-*-*]
6013 || ([istarget mips*-*-*] && [et-is-effective-target mips_msa])
6014 || ([istarget s390*-*-*]
6015 && [check_effective_target_s390_vx]) } {
6016 return 1
6017 }
6018 if { [istarget arm*-*-*]
6019 && ![check_effective_target_arm_vect_no_misalign] } {
6020 return 1
6021 }
6022 return 0
6023 }]
6024 }
6025
6026
6027 # Return 1 if arrays are aligned to the vector alignment
6028 # boundary, 0 otherwise.
6029
6030 proc check_effective_target_vect_aligned_arrays { } {
6031 set et_vect_aligned_arrays 0
6032 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
6033 && !([is-effective-target ia32]
6034 || ([check_avx_available] && ![check_prefer_avx128])))
6035 || [istarget spu-*-*] } {
6036 set et_vect_aligned_arrays 1
6037 }
6038
6039 verbose "check_effective_target_vect_aligned_arrays:\
6040 returning $et_vect_aligned_arrays" 2
6041 return $et_vect_aligned_arrays
6042 }
6043
6044 # Return 1 if types of size 32 bit or less are naturally aligned
6045 # (aligned to their type-size), 0 otherwise.
6046 #
6047 # This won't change for different subtargets so cache the result.
6048
6049 proc check_effective_target_natural_alignment_32 { } {
6050 # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
6051 return [check_cached_effective_target_indexed natural_alignment_32 {
6052 if { ([istarget *-*-darwin*] && [is-effective-target lp64])
6053 || [istarget avr-*-*] } {
6054 return 0
6055 } else {
6056 return 1
6057 }
6058 }]
6059 }
6060
6061 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
6062 # type-size), 0 otherwise.
6063 #
6064 # This won't change for different subtargets so cache the result.
6065
6066 proc check_effective_target_natural_alignment_64 { } {
6067 return [check_cached_effective_target_indexed natural_alignment_64 {
6068 expr { ([is-effective-target lp64] && ![istarget *-*-darwin*])
6069 || [istarget spu-*-*] }
6070 }]
6071 }
6072
6073 # Return 1 if all vector types are naturally aligned (aligned to their
6074 # type-size), 0 otherwise.
6075
6076 proc check_effective_target_vect_natural_alignment { } {
6077 set et_vect_natural_alignment 1
6078 if { [check_effective_target_arm_eabi]
6079 || [istarget nvptx-*-*]
6080 || [istarget s390*-*-*] } {
6081 set et_vect_natural_alignment 0
6082 }
6083 verbose "check_effective_target_vect_natural_alignment:\
6084 returning $et_vect_natural_alignment" 2
6085 return $et_vect_natural_alignment
6086 }
6087
6088 # Return true if fully-masked loops are supported.
6089
6090 proc check_effective_target_vect_fully_masked { } {
6091 return [check_effective_target_aarch64_sve]
6092 }
6093
6094 # Return 1 if the target doesn't prefer any alignment beyond element
6095 # alignment during vectorization.
6096
6097 proc check_effective_target_vect_element_align_preferred { } {
6098 return [expr { [check_effective_target_aarch64_sve]
6099 && [check_effective_target_vect_variable_length] }]
6100 }
6101
6102 # Return 1 if we can align stack data to the preferred vector alignment.
6103
6104 proc check_effective_target_vect_align_stack_vars { } {
6105 if { [check_effective_target_aarch64_sve] } {
6106 return [check_effective_target_vect_variable_length]
6107 }
6108 return 1
6109 }
6110
6111 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
6112
6113 proc check_effective_target_vector_alignment_reachable { } {
6114 set et_vector_alignment_reachable 0
6115 if { [check_effective_target_vect_aligned_arrays]
6116 || [check_effective_target_natural_alignment_32] } {
6117 set et_vector_alignment_reachable 1
6118 }
6119 verbose "check_effective_target_vector_alignment_reachable:\
6120 returning $et_vector_alignment_reachable" 2
6121 return $et_vector_alignment_reachable
6122 }
6123
6124 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
6125
6126 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
6127 set et_vector_alignment_reachable_for_64bit 0
6128 if { [check_effective_target_vect_aligned_arrays]
6129 || [check_effective_target_natural_alignment_64] } {
6130 set et_vector_alignment_reachable_for_64bit 1
6131 }
6132 verbose "check_effective_target_vector_alignment_reachable_for_64bit:\
6133 returning $et_vector_alignment_reachable_for_64bit" 2
6134 return $et_vector_alignment_reachable_for_64bit
6135 }
6136
6137 # Return 1 if the target only requires element alignment for vector accesses
6138
6139 proc check_effective_target_vect_element_align { } {
6140 return [check_cached_effective_target_indexed vect_element_align {
6141 expr { ([istarget arm*-*-*]
6142 && ![check_effective_target_arm_vect_no_misalign])
6143 || [check_effective_target_vect_hw_misalign] }}]
6144 }
6145
6146 # Return 1 if we expect to see unaligned accesses in at least some
6147 # vector dumps.
6148
6149 proc check_effective_target_vect_unaligned_possible { } {
6150 return [expr { ![check_effective_target_vect_element_align_preferred]
6151 && (![check_effective_target_vect_no_align]
6152 || [check_effective_target_vect_hw_misalign]) }]
6153 }
6154
6155 # Return 1 if the target supports vector LOAD_LANES operations, 0 otherwise.
6156
6157 proc check_effective_target_vect_load_lanes { } {
6158 # We don't support load_lanes correctly on big-endian arm.
6159 return [check_cached_effective_target vect_load_lanes {
6160 expr { ([check_effective_target_arm_little_endian]
6161 && [check_effective_target_arm_neon_ok])
6162 || [istarget aarch64*-*-*] }}]
6163 }
6164
6165 # Return 1 if the target supports vector masked stores.
6166
6167 proc check_effective_target_vect_masked_store { } {
6168 return [check_effective_target_aarch64_sve]
6169 }
6170
6171 # Return 1 if the target supports vector scatter stores.
6172
6173 proc check_effective_target_vect_scatter_store { } {
6174 return [check_effective_target_aarch64_sve]
6175 }
6176
6177 # Return 1 if the target supports vector conditional operations, 0 otherwise.
6178
6179 proc check_effective_target_vect_condition { } {
6180 return [check_cached_effective_target_indexed vect_condition {
6181 expr { [istarget aarch64*-*-*]
6182 || [istarget powerpc*-*-*]
6183 || [istarget ia64-*-*]
6184 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6185 || [istarget spu-*-*]
6186 || ([istarget mips*-*-*]
6187 && [et-is-effective-target mips_msa])
6188 || ([istarget arm*-*-*]
6189 && [check_effective_target_arm_neon_ok])
6190 || ([istarget s390*-*-*]
6191 && [check_effective_target_s390_vx]) }}]
6192 }
6193
6194 # Return 1 if the target supports vector conditional operations where
6195 # the comparison has different type from the lhs, 0 otherwise.
6196
6197 proc check_effective_target_vect_cond_mixed { } {
6198 return [check_cached_effective_target_indexed vect_cond_mixed {
6199 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6200 || [istarget aarch64*-*-*]
6201 || [istarget powerpc*-*-*]
6202 || ([istarget mips*-*-*]
6203 && [et-is-effective-target mips_msa])
6204 || ([istarget s390*-*-*]
6205 && [check_effective_target_s390_vx]) }}]
6206 }
6207
6208 # Return 1 if the target supports vector char multiplication, 0 otherwise.
6209
6210 proc check_effective_target_vect_char_mult { } {
6211 return [check_cached_effective_target_indexed vect_char_mult {
6212 expr { [istarget aarch64*-*-*]
6213 || [istarget ia64-*-*]
6214 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6215 || [check_effective_target_arm32]
6216 || [check_effective_target_powerpc_altivec]
6217 || ([istarget mips*-*-*]
6218 && [et-is-effective-target mips_msa])
6219 || ([istarget s390*-*-*]
6220 && [check_effective_target_s390_vx]) }}]
6221 }
6222
6223 # Return 1 if the target supports vector short multiplication, 0 otherwise.
6224
6225 proc check_effective_target_vect_short_mult { } {
6226 return [check_cached_effective_target_indexed vect_short_mult {
6227 expr { [istarget ia64-*-*]
6228 || [istarget spu-*-*]
6229 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6230 || [istarget powerpc*-*-*]
6231 || [istarget aarch64*-*-*]
6232 || [check_effective_target_arm32]
6233 || ([istarget mips*-*-*]
6234 && ([et-is-effective-target mips_msa]
6235 || [et-is-effective-target mips_loongson_mmi]))
6236 || ([istarget s390*-*-*]
6237 && [check_effective_target_s390_vx]) }}]
6238 }
6239
6240 # Return 1 if the target supports vector int multiplication, 0 otherwise.
6241
6242 proc check_effective_target_vect_int_mult { } {
6243 return [check_cached_effective_target_indexed vect_int_mult {
6244 expr { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
6245 || [istarget spu-*-*]
6246 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6247 || [istarget ia64-*-*]
6248 || [istarget aarch64*-*-*]
6249 || ([istarget mips*-*-*]
6250 && [et-is-effective-target mips_msa])
6251 || [check_effective_target_arm32]
6252 || ([istarget s390*-*-*]
6253 && [check_effective_target_s390_vx]) }}]
6254 }
6255
6256 # Return 1 if the target supports 64 bit hardware vector
6257 # multiplication of long operands with a long result, 0 otherwise.
6258 #
6259 # This can change for different subtargets so do not cache the result.
6260
6261 proc check_effective_target_vect_long_mult { } {
6262 if { [istarget i?86-*-*] || [istarget x86_64-*-*]
6263 || (([istarget powerpc*-*-*]
6264 && ![istarget powerpc-*-linux*paired*])
6265 && [check_effective_target_ilp32])
6266 || [is-effective-target arm_neon]
6267 || ([istarget sparc*-*-*] && [check_effective_target_ilp32])
6268 || [istarget aarch64*-*-*]
6269 || ([istarget mips*-*-*]
6270 && [et-is-effective-target mips_msa]) } {
6271 set answer 1
6272 } else {
6273 set answer 0
6274 }
6275
6276 verbose "check_effective_target_vect_long_mult: returning $answer" 2
6277 return $answer
6278 }
6279
6280 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
6281
6282 proc check_effective_target_vect_extract_even_odd { } {
6283 return [check_cached_effective_target_indexed extract_even_odd {
6284 expr { [istarget aarch64*-*-*]
6285 || [istarget powerpc*-*-*]
6286 || [is-effective-target arm_neon]
6287 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6288 || [istarget ia64-*-*]
6289 || [istarget spu-*-*]
6290 || ([istarget mips*-*-*]
6291 && ([et-is-effective-target mips_msa]
6292 || [et-is-effective-target mpaired_single]))
6293 || ([istarget s390*-*-*]
6294 && [check_effective_target_s390_vx]) }}]
6295 }
6296
6297 # Return 1 if the target supports vector interleaving, 0 otherwise.
6298
6299 proc check_effective_target_vect_interleave { } {
6300 return [check_cached_effective_target_indexed vect_interleave {
6301 expr { [istarget aarch64*-*-*]
6302 || [istarget powerpc*-*-*]
6303 || [is-effective-target arm_neon]
6304 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6305 || [istarget ia64-*-*]
6306 || [istarget spu-*-*]
6307 || ([istarget mips*-*-*]
6308 && ([et-is-effective-target mpaired_single]
6309 || [et-is-effective-target mips_msa]))
6310 || ([istarget s390*-*-*]
6311 && [check_effective_target_s390_vx]) }}]
6312 }
6313
6314 foreach N {2 3 4 8} {
6315 eval [string map [list N $N] {
6316 # Return 1 if the target supports 2-vector interleaving
6317 proc check_effective_target_vect_stridedN { } {
6318 return [check_cached_effective_target_indexed vect_stridedN {
6319 if { (N & -N) == N
6320 && [check_effective_target_vect_interleave]
6321 && [check_effective_target_vect_extract_even_odd] } {
6322 return 1
6323 }
6324 if { ([istarget arm*-*-*]
6325 || [istarget aarch64*-*-*]) && N >= 2 && N <= 4 } {
6326 return 1
6327 }
6328 return 0
6329 }]
6330 }
6331 }]
6332 }
6333
6334 # Return the list of vector sizes (in bits) that each target supports.
6335 # A vector length of "0" indicates variable-length vectors.
6336
6337 proc available_vector_sizes { } {
6338 set result {}
6339 if { [istarget aarch64*-*-*] } {
6340 if { [check_effective_target_aarch64_sve] } {
6341 lappend result [aarch64_sve_bits]
6342 }
6343 lappend result 128 64
6344 } elseif { [istarget arm*-*-*]
6345 && [check_effective_target_arm_neon_ok] } {
6346 lappend result 128 64
6347 } elseif { (([istarget i?86-*-*] || [istarget x86_64-*-*])
6348 && ([check_avx_available] && ![check_prefer_avx128])) } {
6349 lappend result 256 128
6350 } elseif { [istarget sparc*-*-*] } {
6351 lappend result 64
6352 } else {
6353 # The traditional default asumption.
6354 lappend result 128
6355 }
6356 return $result
6357 }
6358
6359 # Return 1 if the target supports multiple vector sizes
6360
6361 proc check_effective_target_vect_multiple_sizes { } {
6362 return [expr { [llength [available_vector_sizes]] > 1 }]
6363 }
6364
6365 # Return true if variable-length vectors are supported.
6366
6367 proc check_effective_target_vect_variable_length { } {
6368 return [expr { [lindex [available_vector_sizes] 0] == 0 }]
6369 }
6370
6371 # Return 1 if the target supports vectors of 64 bits.
6372
6373 proc check_effective_target_vect64 { } {
6374 return [expr { [lsearch -exact [available_vector_sizes] 64] >= 0 }]
6375 }
6376
6377 # Return 1 if the target supports vector copysignf calls.
6378
6379 proc check_effective_target_vect_call_copysignf { } {
6380 return [check_cached_effective_target_indexed vect_call_copysignf {
6381 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6382 || [istarget powerpc*-*-*]
6383 || [istarget aarch64*-*-*] }}]
6384 }
6385
6386 # Return 1 if the target supports hardware square root instructions.
6387
6388 proc check_effective_target_sqrt_insn { } {
6389 return [check_cached_effective_target sqrt_insn {
6390 expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
6391 || [istarget powerpc*-*-*]
6392 || [istarget aarch64*-*-*]
6393 || ([istarget arm*-*-*] && [check_effective_target_arm_vfp_ok])
6394 || ([istarget s390*-*-*]
6395 && [check_effective_target_s390_vx]) }}]
6396 }
6397
6398 # Return 1 if the target supports vector sqrtf calls.
6399
6400 proc check_effective_target_vect_call_sqrtf { } {
6401 return [check_cached_effective_target_indexed vect_call_sqrtf {
6402 expr { [istarget aarch64*-*-*]
6403 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6404 || ([istarget powerpc*-*-*] && [check_vsx_hw_available])
6405 || ([istarget s390*-*-*]
6406 && [check_effective_target_s390_vx]) }}]
6407 }
6408
6409 # Return 1 if the target supports vector lrint calls.
6410
6411 proc check_effective_target_vect_call_lrint { } {
6412 set et_vect_call_lrint 0
6413 if { (([istarget i?86-*-*] || [istarget x86_64-*-*])
6414 && [check_effective_target_ilp32]) } {
6415 set et_vect_call_lrint 1
6416 }
6417
6418 verbose "check_effective_target_vect_call_lrint: returning $et_vect_call_lrint" 2
6419 return $et_vect_call_lrint
6420 }
6421
6422 # Return 1 if the target supports vector btrunc calls.
6423
6424 proc check_effective_target_vect_call_btrunc { } {
6425 return [check_cached_effective_target_indexed vect_call_btrunc {
6426 expr { [istarget aarch64*-*-*] }}]
6427 }
6428
6429 # Return 1 if the target supports vector btruncf calls.
6430
6431 proc check_effective_target_vect_call_btruncf { } {
6432 return [check_cached_effective_target_indexed vect_call_btruncf {
6433 expr { [istarget aarch64*-*-*] }}]
6434 }
6435
6436 # Return 1 if the target supports vector ceil calls.
6437
6438 proc check_effective_target_vect_call_ceil { } {
6439 return [check_cached_effective_target_indexed vect_call_ceil {
6440 expr { [istarget aarch64*-*-*] }}]
6441 }
6442
6443 # Return 1 if the target supports vector ceilf calls.
6444
6445 proc check_effective_target_vect_call_ceilf { } {
6446 return [check_cached_effective_target_indexed vect_call_ceilf {
6447 expr { [istarget aarch64*-*-*] }}]
6448 }
6449
6450 # Return 1 if the target supports vector floor calls.
6451
6452 proc check_effective_target_vect_call_floor { } {
6453 return [check_cached_effective_target_indexed vect_call_floor {
6454 expr { [istarget aarch64*-*-*] }}]
6455 }
6456
6457 # Return 1 if the target supports vector floorf calls.
6458
6459 proc check_effective_target_vect_call_floorf { } {
6460 return [check_cached_effective_target_indexed vect_call_floorf {
6461 expr { [istarget aarch64*-*-*] }}]
6462 }
6463
6464 # Return 1 if the target supports vector lceil calls.
6465
6466 proc check_effective_target_vect_call_lceil { } {
6467 return [check_cached_effective_target_indexed vect_call_lceil {
6468 expr { [istarget aarch64*-*-*] }}]
6469 }
6470
6471 # Return 1 if the target supports vector lfloor calls.
6472
6473 proc check_effective_target_vect_call_lfloor { } {
6474 return [check_cached_effective_target_indexed vect_call_lfloor {
6475 expr { [istarget aarch64*-*-*] }}]
6476 }
6477
6478 # Return 1 if the target supports vector nearbyint calls.
6479
6480 proc check_effective_target_vect_call_nearbyint { } {
6481 return [check_cached_effective_target_indexed vect_call_nearbyint {
6482 expr { [istarget aarch64*-*-*] }}]
6483 }
6484
6485 # Return 1 if the target supports vector nearbyintf calls.
6486
6487 proc check_effective_target_vect_call_nearbyintf { } {
6488 return [check_cached_effective_target_indexed vect_call_nearbyintf {
6489 expr { [istarget aarch64*-*-*] }}]
6490 }
6491
6492 # Return 1 if the target supports vector round calls.
6493
6494 proc check_effective_target_vect_call_round { } {
6495 return [check_cached_effective_target_indexed vect_call_round {
6496 expr { [istarget aarch64*-*-*] }}]
6497 }
6498
6499 # Return 1 if the target supports vector roundf calls.
6500
6501 proc check_effective_target_vect_call_roundf { } {
6502 return [check_cached_effective_target_indexed vect_call_roundf {
6503 expr { [istarget aarch64*-*-*] }}]
6504 }
6505
6506 # Return 1 if the target supports AND, OR and XOR reduction.
6507
6508 proc check_effective_target_vect_logical_reduc { } {
6509 return [check_effective_target_aarch64_sve]
6510 }
6511
6512 # Return 1 if the target supports the fold_extract_last optab.
6513
6514 proc check_effective_target_vect_fold_extract_last { } {
6515 return [check_effective_target_aarch64_sve]
6516 }
6517
6518 # Return 1 if the target supports section-anchors
6519
6520 proc check_effective_target_section_anchors { } {
6521 return [check_cached_effective_target section_anchors {
6522 expr { [istarget powerpc*-*-*]
6523 || [istarget arm*-*-*]
6524 || [istarget aarch64*-*-*] }}]
6525 }
6526
6527 # Return 1 if the target supports atomic operations on "int_128" values.
6528
6529 proc check_effective_target_sync_int_128 { } {
6530 if { [istarget spu-*-*] } {
6531 return 1
6532 } else {
6533 return 0
6534 }
6535 }
6536
6537 # Return 1 if the target supports atomic operations on "int_128" values
6538 # and can execute them.
6539 # This requires support for both compare-and-swap and true atomic loads.
6540
6541 proc check_effective_target_sync_int_128_runtime { } {
6542 if { [istarget spu-*-*] } {
6543 return 1
6544 } else {
6545 return 0
6546 }
6547 }
6548
6549 # Return 1 if the target supports atomic operations on "long long".
6550 #
6551 # Note: 32bit x86 targets require -march=pentium in dg-options.
6552 # Note: 32bit s390 targets require -mzarch in dg-options.
6553
6554 proc check_effective_target_sync_long_long { } {
6555 if { [istarget i?86-*-*] || [istarget x86_64-*-*])
6556 || [istarget aarch64*-*-*]
6557 || [istarget arm*-*-*]
6558 || [istarget alpha*-*-*]
6559 || ([istarget sparc*-*-*] && [check_effective_target_lp64])
6560 || [istarget s390*-*-*]
6561 || [istarget spu-*-*] } {
6562 return 1
6563 } else {
6564 return 0
6565 }
6566 }
6567
6568 # Return 1 if the target supports popcount on long.
6569
6570 proc check_effective_target_popcountl { } {
6571 return [check_no_messages_and_pattern popcountl "!\\(call" rtl-expand {
6572 int foo (long b)
6573 {
6574 return __builtin_popcountl (b);
6575 }
6576 } "" ]
6577 }
6578
6579 # Return 1 if the target supports atomic operations on "long long"
6580 # and can execute them.
6581 #
6582 # Note: 32bit x86 targets require -march=pentium in dg-options.
6583
6584 proc check_effective_target_sync_long_long_runtime { } {
6585 if { (([istarget x86_64-*-*] || [istarget i?86-*-*])
6586 && [check_cached_effective_target sync_long_long_available {
6587 check_runtime_nocache sync_long_long_available {
6588 #include "cpuid.h"
6589 int main ()
6590 {
6591 unsigned int eax, ebx, ecx, edx;
6592 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
6593 return !(edx & bit_CMPXCHG8B);
6594 return 1;
6595 }
6596 } ""
6597 }])
6598 || [istarget aarch64*-*-*]
6599 || ([istarget arm*-*-linux-*]
6600 && [check_runtime sync_longlong_runtime {
6601 #include <stdlib.h>
6602 int main ()
6603 {
6604 long long l1;
6605
6606 if (sizeof (long long) != 8)
6607 exit (1);
6608
6609 /* Just check for native;
6610 checking for kernel fallback is tricky. */
6611 asm volatile ("ldrexd r0,r1, [%0]"
6612 : : "r" (&l1) : "r0", "r1");
6613 exit (0);
6614 }
6615 } "" ])
6616 || [istarget alpha*-*-*]
6617 || ([istarget sparc*-*-*]
6618 && [check_effective_target_lp64]
6619 && [check_effective_target_ultrasparc_hw])
6620 || [istarget spu-*-*]
6621 || ([istarget powerpc*-*-*] && [check_effective_target_lp64]) } {
6622 return 1
6623 } else {
6624 return 0
6625 }
6626 }
6627
6628 # Return 1 if the target supports byte swap instructions.
6629
6630 proc check_effective_target_bswap { } {
6631 return [check_cached_effective_target bswap {
6632 expr { [istarget aarch64*-*-*]
6633 || [istarget alpha*-*-*]
6634 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6635 || [istarget m68k-*-*]
6636 || [istarget powerpc*-*-*]
6637 || [istarget rs6000-*-*]
6638 || [istarget s390*-*-*]
6639 || ([istarget arm*-*-*]
6640 && [check_no_compiler_messages_nocache arm_v6_or_later object {
6641 #if __ARM_ARCH < 6
6642 #error not armv6 or later
6643 #endif
6644 int i;
6645 } ""]) }}]
6646 }
6647
6648 # Return 1 if the target supports atomic operations on "int" and "long".
6649
6650 proc check_effective_target_sync_int_long { } {
6651 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
6652 # load-reserved/store-conditional instructions.
6653 return [check_cached_effective_target sync_int_long {
6654 expr { [istarget ia64-*-*]
6655 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6656 || [istarget aarch64*-*-*]
6657 || [istarget alpha*-*-*]
6658 || [istarget arm*-*-linux-*]
6659 || ([istarget arm*-*-*]
6660 && [check_effective_target_arm_acq_rel])
6661 || [istarget bfin*-*linux*]
6662 || [istarget hppa*-*linux*]
6663 || [istarget s390*-*-*]
6664 || [istarget powerpc*-*-*]
6665 || [istarget crisv32-*-*] || [istarget cris-*-*]
6666 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
6667 || [istarget spu-*-*]
6668 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
6669 || [check_effective_target_mips_llsc] }}]
6670 }
6671
6672 # Return 1 if the target supports atomic operations on "char" and "short".
6673
6674 proc check_effective_target_sync_char_short { } {
6675 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
6676 # load-reserved/store-conditional instructions.
6677 return [check_cached_effective_target sync_char_short {
6678 expr { [istarget aarch64*-*-*]
6679 || [istarget ia64-*-*]
6680 || [istarget i?86-*-*] || [istarget x86_64-*-*]
6681 || [istarget alpha*-*-*]
6682 || [istarget arm*-*-linux-*]
6683 || ([istarget arm*-*-*]
6684 && [check_effective_target_arm_acq_rel])
6685 || [istarget hppa*-*linux*]
6686 || [istarget s390*-*-*]
6687 || [istarget powerpc*-*-*]
6688 || [istarget crisv32-*-*] || [istarget cris-*-*]
6689 || ([istarget sparc*-*-*] && [check_effective_target_sparc_v9])
6690 || [istarget spu-*-*]
6691 || ([istarget arc*-*-*] && [check_effective_target_arc_atomic])
6692 || [check_effective_target_mips_llsc] }}]
6693 }
6694
6695 # Return 1 if the target uses a ColdFire FPU.
6696
6697 proc check_effective_target_coldfire_fpu { } {
6698 return [check_no_compiler_messages coldfire_fpu assembly {
6699 #ifndef __mcffpu__
6700 #error !__mcffpu__
6701 #endif
6702 }]
6703 }
6704
6705 # Return true if this is a uClibc target.
6706
6707 proc check_effective_target_uclibc {} {
6708 return [check_no_compiler_messages uclibc object {
6709 #include <features.h>
6710 #if !defined (__UCLIBC__)
6711 #error !__UCLIBC__
6712 #endif
6713 }]
6714 }
6715
6716 # Return true if this is a uclibc target and if the uclibc feature
6717 # described by __$feature__ is not present.
6718
6719 proc check_missing_uclibc_feature {feature} {
6720 return [check_no_compiler_messages $feature object "
6721 #include <features.h>
6722 #if !defined (__UCLIBC) || defined (__${feature}__)
6723 #error FOO
6724 #endif
6725 "]
6726 }
6727
6728 # Return true if this is a Newlib target.
6729
6730 proc check_effective_target_newlib {} {
6731 return [check_no_compiler_messages newlib object {
6732 #include <newlib.h>
6733 }]
6734 }
6735
6736 # Return true if GCC was configured with --enable-newlib-nano-formatted-io
6737 proc check_effective_target_newlib_nano_io { } {
6738 return [check_configured_with "--enable-newlib-nano-formatted-io"]
6739 }
6740
6741 # Some newlib versions don't provide a frexpl and instead depend
6742 # on frexp to implement long double conversions in their printf-like
6743 # functions. This leads to broken results. Detect such versions here.
6744
6745 proc check_effective_target_newlib_broken_long_double_io {} {
6746 if { [is-effective-target newlib] && ![is-effective-target frexpl] } {
6747 return 1
6748 }
6749 return 0
6750 }
6751
6752 # Return true if this is NOT a Bionic target.
6753
6754 proc check_effective_target_non_bionic {} {
6755 return [check_no_compiler_messages non_bionic object {
6756 #include <ctype.h>
6757 #if defined (__BIONIC__)
6758 #error FOO
6759 #endif
6760 }]
6761 }
6762
6763 # Return true if this target has error.h header.
6764
6765 proc check_effective_target_error_h {} {
6766 return [check_no_compiler_messages error_h object {
6767 #include <error.h>
6768 }]
6769 }
6770
6771 # Return true if this target has tgmath.h header.
6772
6773 proc check_effective_target_tgmath_h {} {
6774 return [check_no_compiler_messages tgmath_h object {
6775 #include <tgmath.h>
6776 }]
6777 }
6778
6779 # Return true if target's libc supports complex functions.
6780
6781 proc check_effective_target_libc_has_complex_functions {} {
6782 return [check_no_compiler_messages libc_has_complex_functions object {
6783 #include <complex.h>
6784 }]
6785 }
6786
6787 # Return 1 if
6788 # (a) an error of a few ULP is expected in string to floating-point
6789 # conversion functions; and
6790 # (b) overflow is not always detected correctly by those functions.
6791
6792 proc check_effective_target_lax_strtofp {} {
6793 # By default, assume that all uClibc targets suffer from this.
6794 return [check_effective_target_uclibc]
6795 }
6796
6797 # Return 1 if this is a target for which wcsftime is a dummy
6798 # function that always returns 0.
6799
6800 proc check_effective_target_dummy_wcsftime {} {
6801 # By default, assume that all uClibc targets suffer from this.
6802 return [check_effective_target_uclibc]
6803 }
6804
6805 # Return 1 if constructors with initialization priority arguments are
6806 # supposed on this target.
6807
6808 proc check_effective_target_init_priority {} {
6809 return [check_no_compiler_messages init_priority assembly "
6810 void f() __attribute__((constructor (1000)));
6811 void f() \{\}
6812 "]
6813 }
6814
6815 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
6816 # This can be used with any check_* proc that takes no argument and
6817 # returns only 1 or 0. It could be used with check_* procs that take
6818 # arguments with keywords that pass particular arguments.
6819
6820 proc is-effective-target { arg } {
6821 global et_index
6822 set selected 0
6823 if { ![info exists et_index] } {
6824 # Initialize the effective target index that is used in some
6825 # check_effective_target_* procs.
6826 set et_index 0
6827 }
6828 if { [info procs check_effective_target_${arg}] != [list] } {
6829 set selected [check_effective_target_${arg}]
6830 } else {
6831 switch $arg {
6832 "vmx_hw" { set selected [check_vmx_hw_available] }
6833 "vsx_hw" { set selected [check_vsx_hw_available] }
6834 "p8vector_hw" { set selected [check_p8vector_hw_available] }
6835 "p9vector_hw" { set selected [check_p9vector_hw_available] }
6836 "p9modulo_hw" { set selected [check_p9modulo_hw_available] }
6837 "ppc_float128_sw" { set selected [check_ppc_float128_sw_available] }
6838 "ppc_float128_hw" { set selected [check_ppc_float128_hw_available] }
6839 "ppc_recip_hw" { set selected [check_ppc_recip_hw_available] }
6840 "ppc_cpu_supports_hw" { set selected [check_ppc_cpu_supports_hw_available] }
6841 "dfp_hw" { set selected [check_dfp_hw_available] }
6842 "htm_hw" { set selected [check_htm_hw_available] }
6843 "named_sections" { set selected [check_named_sections_available] }
6844 "gc_sections" { set selected [check_gc_sections_available] }
6845 "cxa_atexit" { set selected [check_cxa_atexit_available] }
6846 default { error "unknown effective target keyword `$arg'" }
6847 }
6848 }
6849
6850 verbose "is-effective-target: $arg $selected" 2
6851 return $selected
6852 }
6853
6854 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
6855
6856 proc is-effective-target-keyword { arg } {
6857 if { [info procs check_effective_target_${arg}] != [list] } {
6858 return 1
6859 } else {
6860 # These have different names for their check_* procs.
6861 switch $arg {
6862 "vmx_hw" { return 1 }
6863 "vsx_hw" { return 1 }
6864 "p8vector_hw" { return 1 }
6865 "p9vector_hw" { return 1 }
6866 "p9modulo_hw" { return 1 }
6867 "ppc_float128_sw" { return 1 }
6868 "ppc_float128_hw" { return 1 }
6869 "ppc_recip_hw" { return 1 }
6870 "dfp_hw" { return 1 }
6871 "htm_hw" { return 1 }
6872 "named_sections" { return 1 }
6873 "gc_sections" { return 1 }
6874 "cxa_atexit" { return 1 }
6875 default { return 0 }
6876 }
6877 }
6878 }
6879
6880 # Execute tests for all targets in EFFECTIVE_TARGETS list. Set et_index to
6881 # indicate what target is currently being processed. This is for
6882 # the vectorizer tests, e.g. vect_int, to keep track what target supports
6883 # a given feature.
6884
6885 proc et-dg-runtest { runtest testcases flags default-extra-flags } {
6886 global dg-do-what-default
6887 global EFFECTIVE_TARGETS
6888 global et_index
6889
6890 if { [llength $EFFECTIVE_TARGETS] > 0 } {
6891 foreach target $EFFECTIVE_TARGETS {
6892 set target_flags $flags
6893 set dg-do-what-default compile
6894 set et_index [lsearch -exact $EFFECTIVE_TARGETS $target]
6895 if { [info procs add_options_for_${target}] != [list] } {
6896 set target_flags [add_options_for_${target} "$flags"]
6897 }
6898 if { [info procs check_effective_target_${target}_runtime]
6899 != [list] && [check_effective_target_${target}_runtime] } {
6900 set dg-do-what-default run
6901 }
6902 $runtest $testcases $target_flags ${default-extra-flags}
6903 }
6904 } else {
6905 set et_index 0
6906 $runtest $testcases $flags ${default-extra-flags}
6907 }
6908 }
6909
6910 # Return 1 if a target matches the target in EFFECTIVE_TARGETS at index
6911 # et_index, 0 otherwise.
6912
6913 proc et-is-effective-target { target } {
6914 global EFFECTIVE_TARGETS
6915 global et_index
6916
6917 if { [llength $EFFECTIVE_TARGETS] > $et_index
6918 && [lindex $EFFECTIVE_TARGETS $et_index] == $target } {
6919 return 1
6920 }
6921 return 0
6922 }
6923
6924 # Return 1 if target default to short enums
6925
6926 proc check_effective_target_short_enums { } {
6927 return [check_no_compiler_messages short_enums assembly {
6928 enum foo { bar };
6929 int s[sizeof (enum foo) == 1 ? 1 : -1];
6930 }]
6931 }
6932
6933 # Return 1 if target supports merging string constants at link time.
6934
6935 proc check_effective_target_string_merging { } {
6936 return [check_no_messages_and_pattern string_merging \
6937 "rodata\\.str" assembly {
6938 const char *var = "String";
6939 } {-O2}]
6940 }
6941
6942 # Return 1 if target has the basic signed and unsigned types in
6943 # <stdint.h>, 0 otherwise. This will be obsolete when GCC ensures a
6944 # working <stdint.h> for all targets.
6945
6946 proc check_effective_target_stdint_types { } {
6947 return [check_no_compiler_messages stdint_types assembly {
6948 #include <stdint.h>
6949 int8_t a; int16_t b; int32_t c; int64_t d;
6950 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
6951 }]
6952 }
6953
6954 # Return 1 if target has the basic signed and unsigned types in
6955 # <inttypes.h>, 0 otherwise. This is for tests that GCC's notions of
6956 # these types agree with those in the header, as some systems have
6957 # only <inttypes.h>.
6958
6959 proc check_effective_target_inttypes_types { } {
6960 return [check_no_compiler_messages inttypes_types assembly {
6961 #include <inttypes.h>
6962 int8_t a; int16_t b; int32_t c; int64_t d;
6963 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
6964 }]
6965 }
6966
6967 # Return 1 if programs are intended to be run on a simulator
6968 # (i.e. slowly) rather than hardware (i.e. fast).
6969
6970 proc check_effective_target_simulator { } {
6971
6972 # All "src/sim" simulators set this one.
6973 if [board_info target exists is_simulator] {
6974 return [board_info target is_simulator]
6975 }
6976
6977 # The "sid" simulators don't set that one, but at least they set
6978 # this one.
6979 if [board_info target exists slow_simulator] {
6980 return [board_info target slow_simulator]
6981 }
6982
6983 return 0
6984 }
6985
6986 # Return 1 if programs are intended to be run on hardware rather than
6987 # on a simulator
6988
6989 proc check_effective_target_hw { } {
6990
6991 # All "src/sim" simulators set this one.
6992 if [board_info target exists is_simulator] {
6993 if [board_info target is_simulator] {
6994 return 0
6995 } else {
6996 return 1
6997 }
6998 }
6999
7000 # The "sid" simulators don't set that one, but at least they set
7001 # this one.
7002 if [board_info target exists slow_simulator] {
7003 if [board_info target slow_simulator] {
7004 return 0
7005 } else {
7006 return 1
7007 }
7008 }
7009
7010 return 1
7011 }
7012
7013 # Return 1 if the target is a VxWorks kernel.
7014
7015 proc check_effective_target_vxworks_kernel { } {
7016 return [check_no_compiler_messages vxworks_kernel assembly {
7017 #if !defined __vxworks || defined __RTP__
7018 #error NO
7019 #endif
7020 }]
7021 }
7022
7023 # Return 1 if the target is a VxWorks RTP.
7024
7025 proc check_effective_target_vxworks_rtp { } {
7026 return [check_no_compiler_messages vxworks_rtp assembly {
7027 #if !defined __vxworks || !defined __RTP__
7028 #error NO
7029 #endif
7030 }]
7031 }
7032
7033 # Return 1 if the target is expected to provide wide character support.
7034
7035 proc check_effective_target_wchar { } {
7036 if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
7037 return 0
7038 }
7039 return [check_no_compiler_messages wchar assembly {
7040 #include <wchar.h>
7041 }]
7042 }
7043
7044 # Return 1 if the target has <pthread.h>.
7045
7046 proc check_effective_target_pthread_h { } {
7047 return [check_no_compiler_messages pthread_h assembly {
7048 #include <pthread.h>
7049 }]
7050 }
7051
7052 # Return 1 if the target can truncate a file from a file-descriptor,
7053 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
7054 # chsize. We test for a trivially functional truncation; no stubs.
7055 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
7056 # different function to be used.
7057
7058 proc check_effective_target_fd_truncate { } {
7059 set prog {
7060 #define _FILE_OFFSET_BITS 64
7061 #include <unistd.h>
7062 #include <stdio.h>
7063 #include <stdlib.h>
7064 #include <string.h>
7065 int main ()
7066 {
7067 FILE *f = fopen ("tst.tmp", "wb");
7068 int fd;
7069 const char t[] = "test writing more than ten characters";
7070 char s[11];
7071 int status = 0;
7072 fd = fileno (f);
7073 write (fd, t, sizeof (t) - 1);
7074 lseek (fd, 0, 0);
7075 if (ftruncate (fd, 10) != 0)
7076 status = 1;
7077 close (fd);
7078 fclose (f);
7079 if (status)
7080 {
7081 unlink ("tst.tmp");
7082 exit (status);
7083 }
7084 f = fopen ("tst.tmp", "rb");
7085 if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
7086 status = 1;
7087 fclose (f);
7088 unlink ("tst.tmp");
7089 exit (status);
7090 }
7091 }
7092
7093 if { [check_runtime ftruncate $prog] } {
7094 return 1;
7095 }
7096
7097 regsub "ftruncate" $prog "chsize" prog
7098 return [check_runtime chsize $prog]
7099 }
7100
7101 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
7102
7103 proc add_options_for_c99_runtime { flags } {
7104 if { [istarget *-*-solaris2*] } {
7105 return "$flags -std=c99"
7106 }
7107 if { [istarget powerpc-*-darwin*] } {
7108 return "$flags -mmacosx-version-min=10.3"
7109 }
7110 return $flags
7111 }
7112
7113 # Add to FLAGS all the target-specific flags needed to enable
7114 # full IEEE compliance mode.
7115
7116 proc add_options_for_ieee { flags } {
7117 if { [istarget alpha*-*-*]
7118 || [istarget sh*-*-*] } {
7119 return "$flags -mieee"
7120 }
7121 if { [istarget rx-*-*] } {
7122 return "$flags -mnofpu"
7123 }
7124 return $flags
7125 }
7126
7127 if {![info exists flags_to_postpone]} {
7128 set flags_to_postpone ""
7129 }
7130
7131 # Add to FLAGS the flags needed to enable functions to bind locally
7132 # when using pic/PIC passes in the testsuite.
7133 proc add_options_for_bind_pic_locally { flags } {
7134 global flags_to_postpone
7135
7136 # Instead of returning 'flags' with the -fPIE or -fpie appended, we save it
7137 # in 'flags_to_postpone' and append it later in gcc_target_compile procedure in
7138 # order to make sure that the multilib_flags doesn't override this.
7139
7140 if {[check_no_compiler_messages using_pic2 assembly {
7141 #if __PIC__ != 2
7142 #error __PIC__ != 2
7143 #endif
7144 }]} {
7145 set flags_to_postpone "-fPIE"
7146 return $flags
7147 }
7148 if {[check_no_compiler_messages using_pic1 assembly {
7149 #if __PIC__ != 1
7150 #error __PIC__ != 1
7151 #endif
7152 }]} {
7153 set flags_to_postpone "-fpie"
7154 return $flags
7155 }
7156 return $flags
7157 }
7158
7159 # Add to FLAGS the flags needed to enable 64-bit vectors.
7160
7161 proc add_options_for_double_vectors { flags } {
7162 if [is-effective-target arm_neon_ok] {
7163 return "$flags -mvectorize-with-neon-double"
7164 }
7165
7166 return $flags
7167 }
7168
7169 # Add to FLAGS the flags needed to define the STACK_SIZE macro.
7170
7171 proc add_options_for_stack_size { flags } {
7172 if [is-effective-target stack_size] {
7173 set stack_size [dg-effective-target-value stack_size]
7174 return "$flags -DSTACK_SIZE=$stack_size"
7175 }
7176
7177 return $flags
7178 }
7179
7180 # Return 1 if the target provides a full C99 runtime.
7181
7182 proc check_effective_target_c99_runtime { } {
7183 return [check_cached_effective_target c99_runtime {
7184 global srcdir
7185
7186 set file [open "$srcdir/gcc.dg/builtins-config.h"]
7187 set contents [read $file]
7188 close $file
7189 append contents {
7190 #ifndef HAVE_C99_RUNTIME
7191 #error !HAVE_C99_RUNTIME
7192 #endif
7193 }
7194 check_no_compiler_messages_nocache c99_runtime assembly \
7195 $contents [add_options_for_c99_runtime ""]
7196 }]
7197 }
7198
7199 # Return 1 if the target provides the D runtime.
7200
7201 proc check_effective_target_d_runtime { } {
7202 return [check_no_compiler_messages d_runtime executable {
7203 // D
7204 module mod;
7205
7206 extern(C) int main() {
7207 return 0;
7208 }
7209 }]
7210 }
7211
7212 # Return 1 if target wchar_t is at least 4 bytes.
7213
7214 proc check_effective_target_4byte_wchar_t { } {
7215 return [check_no_compiler_messages 4byte_wchar_t object {
7216 int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
7217 }]
7218 }
7219
7220 # Return 1 if the target supports automatic stack alignment.
7221
7222 proc check_effective_target_automatic_stack_alignment { } {
7223 # Ordinarily x86 supports automatic stack alignment ...
7224 if { [istarget i?86*-*-*] || [istarget x86_64-*-*] } then {
7225 if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
7226 # ... except Win64 SEH doesn't. Succeed for Win32 though.
7227 return [check_effective_target_ilp32];
7228 }
7229 return 1;
7230 }
7231 return 0;
7232 }
7233
7234 # Return true if we are compiling for AVX target.
7235
7236 proc check_avx_available { } {
7237 if { [check_no_compiler_messages avx_available assembly {
7238 #ifndef __AVX__
7239 #error unsupported
7240 #endif
7241 } ""] } {
7242 return 1;
7243 }
7244 return 0;
7245 }
7246
7247 # Return true if we are compiling for AVX2 target.
7248
7249 proc check_avx2_available { } {
7250 if { [check_no_compiler_messages avx_available assembly {
7251 #ifndef __AVX2__
7252 #error unsupported
7253 #endif
7254 } ""] } {
7255 return 1;
7256 }
7257 return 0;
7258 }
7259
7260 # Return true if we are compiling for SSSE3 target.
7261
7262 proc check_ssse3_available { } {
7263 if { [check_no_compiler_messages sse3a_available assembly {
7264 #ifndef __SSSE3__
7265 #error unsupported
7266 #endif
7267 } ""] } {
7268 return 1;
7269 }
7270 return 0;
7271 }
7272
7273 # Return true if 32- and 16-bytes vectors are available.
7274
7275 proc check_effective_target_vect_sizes_32B_16B { } {
7276 return [expr { [available_vector_sizes] == [list 256 128] }]
7277 }
7278
7279 # Return true if 16- and 8-bytes vectors are available.
7280
7281 proc check_effective_target_vect_sizes_16B_8B { } {
7282 if { [check_avx_available]
7283 || [is-effective-target arm_neon]
7284 || [istarget aarch64*-*-*] } {
7285 return 1;
7286 } else {
7287 return 0;
7288 }
7289 }
7290
7291
7292 # Return true if 128-bits vectors are preferred even if 256-bits vectors
7293 # are available.
7294
7295 proc check_prefer_avx128 { } {
7296 if ![check_avx_available] {
7297 return 0;
7298 }
7299 return [check_no_messages_and_pattern avx_explicit "xmm" assembly {
7300 float a[1024],b[1024],c[1024];
7301 void foo (void) { int i; for (i = 0; i < 1024; i++) a[i]=b[i]+c[i];}
7302 } "-O2 -ftree-vectorize"]
7303 }
7304
7305
7306 # Return 1 if avx512f instructions can be compiled.
7307
7308 proc check_effective_target_avx512f { } {
7309 return [check_no_compiler_messages avx512f object {
7310 typedef double __m512d __attribute__ ((__vector_size__ (64)));
7311 typedef double __m128d __attribute__ ((__vector_size__ (16)));
7312
7313 __m512d _mm512_add (__m512d a)
7314 {
7315 return __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
7316 }
7317
7318 __m128d _mm128_add (__m128d a)
7319 {
7320 return __builtin_ia32_addsd_round (a, a, 8);
7321 }
7322
7323 __m128d _mm128_getmant (__m128d a)
7324 {
7325 return __builtin_ia32_getmantsd_round (a, a, 0, 8);
7326 }
7327 } "-O2 -mavx512f" ]
7328 }
7329
7330 # Return 1 if avx instructions can be compiled.
7331
7332 proc check_effective_target_avx { } {
7333 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
7334 return 0
7335 }
7336 return [check_no_compiler_messages avx object {
7337 void _mm256_zeroall (void)
7338 {
7339 __builtin_ia32_vzeroall ();
7340 }
7341 } "-O2 -mavx" ]
7342 }
7343
7344 # Return 1 if avx2 instructions can be compiled.
7345 proc check_effective_target_avx2 { } {
7346 return [check_no_compiler_messages avx2 object {
7347 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
7348 __v4di
7349 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
7350 {
7351 return __builtin_ia32_andnotsi256 (__X, __Y);
7352 }
7353 } "-O0 -mavx2" ]
7354 }
7355
7356 # Return 1 if sse instructions can be compiled.
7357 proc check_effective_target_sse { } {
7358 return [check_no_compiler_messages sse object {
7359 int main ()
7360 {
7361 __builtin_ia32_stmxcsr ();
7362 return 0;
7363 }
7364 } "-O2 -msse" ]
7365 }
7366
7367 # Return 1 if sse2 instructions can be compiled.
7368 proc check_effective_target_sse2 { } {
7369 return [check_no_compiler_messages sse2 object {
7370 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7371
7372 __m128i _mm_srli_si128 (__m128i __A, int __N)
7373 {
7374 return (__m128i)__builtin_ia32_psrldqi128 (__A, 8);
7375 }
7376 } "-O2 -msse2" ]
7377 }
7378
7379 # Return 1 if sse4.1 instructions can be compiled.
7380 proc check_effective_target_sse4 { } {
7381 return [check_no_compiler_messages sse4.1 object {
7382 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7383 typedef int __v4si __attribute__ ((__vector_size__ (16)));
7384
7385 __m128i _mm_mullo_epi32 (__m128i __X, __m128i __Y)
7386 {
7387 return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X,
7388 (__v4si)__Y);
7389 }
7390 } "-O2 -msse4.1" ]
7391 }
7392
7393 # Return 1 if F16C instructions can be compiled.
7394
7395 proc check_effective_target_f16c { } {
7396 return [check_no_compiler_messages f16c object {
7397 #include "immintrin.h"
7398 float
7399 foo (unsigned short val)
7400 {
7401 return _cvtsh_ss (val);
7402 }
7403 } "-O2 -mf16c" ]
7404 }
7405
7406 proc check_effective_target_ms_hook_prologue { } {
7407 if { [check_no_compiler_messages ms_hook_prologue object {
7408 void __attribute__ ((__ms_hook_prologue__)) foo ();
7409 } ""] } {
7410 return 1
7411 } else {
7412 return 0
7413 }
7414 }
7415
7416 # Return 1 if 3dnow instructions can be compiled.
7417 proc check_effective_target_3dnow { } {
7418 return [check_no_compiler_messages 3dnow object {
7419 typedef int __m64 __attribute__ ((__vector_size__ (8)));
7420 typedef float __v2sf __attribute__ ((__vector_size__ (8)));
7421
7422 __m64 _m_pfadd (__m64 __A, __m64 __B)
7423 {
7424 return (__m64) __builtin_ia32_pfadd ((__v2sf)__A, (__v2sf)__B);
7425 }
7426 } "-O2 -m3dnow" ]
7427 }
7428
7429 # Return 1 if sse3 instructions can be compiled.
7430 proc check_effective_target_sse3 { } {
7431 return [check_no_compiler_messages sse3 object {
7432 typedef double __m128d __attribute__ ((__vector_size__ (16)));
7433 typedef double __v2df __attribute__ ((__vector_size__ (16)));
7434
7435 __m128d _mm_addsub_pd (__m128d __X, __m128d __Y)
7436 {
7437 return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y);
7438 }
7439 } "-O2 -msse3" ]
7440 }
7441
7442 # Return 1 if ssse3 instructions can be compiled.
7443 proc check_effective_target_ssse3 { } {
7444 return [check_no_compiler_messages ssse3 object {
7445 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7446 typedef int __v4si __attribute__ ((__vector_size__ (16)));
7447
7448 __m128i _mm_abs_epi32 (__m128i __X)
7449 {
7450 return (__m128i) __builtin_ia32_pabsd128 ((__v4si)__X);
7451 }
7452 } "-O2 -mssse3" ]
7453 }
7454
7455 # Return 1 if aes instructions can be compiled.
7456 proc check_effective_target_aes { } {
7457 return [check_no_compiler_messages aes object {
7458 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7459 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
7460
7461 __m128i _mm_aesimc_si128 (__m128i __X)
7462 {
7463 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
7464 }
7465 } "-O2 -maes" ]
7466 }
7467
7468 # Return 1 if vaes instructions can be compiled.
7469 proc check_effective_target_vaes { } {
7470 return [check_no_compiler_messages vaes object {
7471 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7472 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
7473
7474 __m128i _mm_aesimc_si128 (__m128i __X)
7475 {
7476 return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
7477 }
7478 } "-O2 -maes -mavx" ]
7479 }
7480
7481 # Return 1 if pclmul instructions can be compiled.
7482 proc check_effective_target_pclmul { } {
7483 return [check_no_compiler_messages pclmul object {
7484 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7485 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
7486
7487 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
7488 {
7489 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
7490 (__v2di)__Y,
7491 1);
7492 }
7493 } "-O2 -mpclmul" ]
7494 }
7495
7496 # Return 1 if vpclmul instructions can be compiled.
7497 proc check_effective_target_vpclmul { } {
7498 return [check_no_compiler_messages vpclmul object {
7499 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7500 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
7501
7502 __m128i pclmulqdq_test (__m128i __X, __m128i __Y)
7503 {
7504 return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
7505 (__v2di)__Y,
7506 1);
7507 }
7508 } "-O2 -mpclmul -mavx" ]
7509 }
7510
7511 # Return 1 if sse4a instructions can be compiled.
7512 proc check_effective_target_sse4a { } {
7513 return [check_no_compiler_messages sse4a object {
7514 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7515 typedef long long __v2di __attribute__ ((__vector_size__ (16)));
7516
7517 __m128i _mm_insert_si64 (__m128i __X,__m128i __Y)
7518 {
7519 return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
7520 }
7521 } "-O2 -msse4a" ]
7522 }
7523
7524 # Return 1 if fma4 instructions can be compiled.
7525 proc check_effective_target_fma4 { } {
7526 return [check_no_compiler_messages fma4 object {
7527 typedef float __m128 __attribute__ ((__vector_size__ (16)));
7528 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
7529 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
7530 {
7531 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
7532 (__v4sf)__B,
7533 (__v4sf)__C);
7534 }
7535 } "-O2 -mfma4" ]
7536 }
7537
7538 # Return 1 if fma instructions can be compiled.
7539 proc check_effective_target_fma { } {
7540 return [check_no_compiler_messages fma object {
7541 typedef float __m128 __attribute__ ((__vector_size__ (16)));
7542 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
7543 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
7544 {
7545 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
7546 (__v4sf)__B,
7547 (__v4sf)__C);
7548 }
7549 } "-O2 -mfma" ]
7550 }
7551
7552 # Return 1 if xop instructions can be compiled.
7553 proc check_effective_target_xop { } {
7554 return [check_no_compiler_messages xop object {
7555 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7556 typedef short __v8hi __attribute__ ((__vector_size__ (16)));
7557 __m128i _mm_maccs_epi16(__m128i __A, __m128i __B, __m128i __C)
7558 {
7559 return (__m128i) __builtin_ia32_vpmacssww ((__v8hi)__A,
7560 (__v8hi)__B,
7561 (__v8hi)__C);
7562 }
7563 } "-O2 -mxop" ]
7564 }
7565
7566 # Return 1 if lzcnt instruction can be compiled.
7567 proc check_effective_target_lzcnt { } {
7568 return [check_no_compiler_messages lzcnt object {
7569 unsigned short _lzcnt (unsigned short __X)
7570 {
7571 return __builtin_clzs (__X);
7572 }
7573 } "-mlzcnt" ]
7574 }
7575
7576 # Return 1 if bmi instructions can be compiled.
7577 proc check_effective_target_bmi { } {
7578 return [check_no_compiler_messages bmi object {
7579 unsigned int __bextr_u32 (unsigned int __X, unsigned int __Y)
7580 {
7581 return __builtin_ia32_bextr_u32 (__X, __Y);
7582 }
7583 } "-mbmi" ]
7584 }
7585
7586 # Return 1 if ADX instructions can be compiled.
7587 proc check_effective_target_adx { } {
7588 return [check_no_compiler_messages adx object {
7589 unsigned char
7590 _adxcarry_u32 (unsigned char __CF, unsigned int __X,
7591 unsigned int __Y, unsigned int *__P)
7592 {
7593 return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
7594 }
7595 } "-madx" ]
7596 }
7597
7598 # Return 1 if rtm instructions can be compiled.
7599 proc check_effective_target_rtm { } {
7600 return [check_no_compiler_messages rtm object {
7601 void
7602 _rtm_xend (void)
7603 {
7604 return __builtin_ia32_xend ();
7605 }
7606 } "-mrtm" ]
7607 }
7608
7609 # Return 1 if avx512vl instructions can be compiled.
7610 proc check_effective_target_avx512vl { } {
7611 return [check_no_compiler_messages avx512vl object {
7612 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
7613 __v4di
7614 mm256_and_epi64 (__v4di __X, __v4di __Y)
7615 {
7616 __v4di __W;
7617 return __builtin_ia32_pandq256_mask (__X, __Y, __W, -1);
7618 }
7619 } "-mavx512vl" ]
7620 }
7621
7622 # Return 1 if avx512cd instructions can be compiled.
7623 proc check_effective_target_avx512cd { } {
7624 return [check_no_compiler_messages avx512cd_trans object {
7625 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
7626 __v8di
7627 _mm512_conflict_epi64 (__v8di __W, __v8di __A)
7628 {
7629 return (__v8di) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A,
7630 (__v8di) __W,
7631 -1);
7632 }
7633 } "-Wno-psabi -mavx512cd" ]
7634 }
7635
7636 # Return 1 if avx512er instructions can be compiled.
7637 proc check_effective_target_avx512er { } {
7638 return [check_no_compiler_messages avx512er_trans object {
7639 typedef float __v16sf __attribute__ ((__vector_size__ (64)));
7640 __v16sf
7641 mm512_exp2a23_ps (__v16sf __X)
7642 {
7643 return __builtin_ia32_exp2ps_mask (__X, __X, -1, 4);
7644 }
7645 } "-Wno-psabi -mavx512er" ]
7646 }
7647
7648 # Return 1 if sha instructions can be compiled.
7649 proc check_effective_target_sha { } {
7650 return [check_no_compiler_messages sha object {
7651 typedef long long __m128i __attribute__ ((__vector_size__ (16)));
7652 typedef int __v4si __attribute__ ((__vector_size__ (16)));
7653
7654 __m128i _mm_sha1msg1_epu32 (__m128i __X, __m128i __Y)
7655 {
7656 return (__m128i) __builtin_ia32_sha1msg1 ((__v4si)__X,
7657 (__v4si)__Y);
7658 }
7659 } "-O2 -msha" ]
7660 }
7661
7662 # Return 1 if avx512dq instructions can be compiled.
7663 proc check_effective_target_avx512dq { } {
7664 return [check_no_compiler_messages avx512dq object {
7665 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
7666 __v8di
7667 _mm512_mask_mullo_epi64 (__v8di __W, __v8di __A, __v8di __B)
7668 {
7669 return (__v8di) __builtin_ia32_pmullq512_mask ((__v8di) __A,
7670 (__v8di) __B,
7671 (__v8di) __W,
7672 -1);
7673 }
7674 } "-mavx512dq" ]
7675 }
7676
7677 # Return 1 if avx512bw instructions can be compiled.
7678 proc check_effective_target_avx512bw { } {
7679 return [check_no_compiler_messages avx512bw object {
7680 typedef short __v32hi __attribute__ ((__vector_size__ (64)));
7681 __v32hi
7682 _mm512_mask_mulhrs_epi16 (__v32hi __W, __v32hi __A, __v32hi __B)
7683 {
7684 return (__v32hi) __builtin_ia32_pmulhrsw512_mask ((__v32hi) __A,
7685 (__v32hi) __B,
7686 (__v32hi) __W,
7687 -1);
7688 }
7689 } "-mavx512bw" ]
7690 }
7691
7692 # Return 1 if avx512ifma instructions can be compiled.
7693 proc check_effective_target_avx512ifma { } {
7694 return [check_no_compiler_messages avx512ifma object {
7695 typedef long long __v8di __attribute__ ((__vector_size__ (64)));
7696 __v8di
7697 _mm512_madd52lo_epu64 (__v8di __X, __v8di __Y, __v8di __Z)
7698 {
7699 return (__v8di) __builtin_ia32_vpmadd52luq512_mask ((__v8di) __X,
7700 (__v8di) __Y,
7701 (__v8di) __Z,
7702 -1);
7703 }
7704 } "-mavx512ifma" ]
7705 }
7706
7707 # Return 1 if avx512vbmi instructions can be compiled.
7708 proc check_effective_target_avx512vbmi { } {
7709 return [check_no_compiler_messages avx512vbmi object {
7710 typedef char __v64qi __attribute__ ((__vector_size__ (64)));
7711 __v64qi
7712 _mm512_multishift_epi64_epi8 (__v64qi __X, __v64qi __Y)
7713 {
7714 return (__v64qi) __builtin_ia32_vpmultishiftqb512_mask ((__v64qi) __X,
7715 (__v64qi) __Y,
7716 (__v64qi) __Y,
7717 -1);
7718 }
7719 } "-mavx512vbmi" ]
7720 }
7721
7722 # Return 1 if avx512_4fmaps instructions can be compiled.
7723 proc check_effective_target_avx5124fmaps { } {
7724 return [check_no_compiler_messages avx5124fmaps object {
7725 typedef float __v16sf __attribute__ ((__vector_size__ (64)));
7726 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
7727
7728 __v16sf
7729 _mm512_mask_4fmadd_ps (__v16sf __DEST, __v16sf __A, __v16sf __B, __v16sf __C,
7730 __v16sf __D, __v16sf __E, __v4sf *__F)
7731 {
7732 return (__v16sf) __builtin_ia32_4fmaddps_mask ((__v16sf) __A,
7733 (__v16sf) __B,
7734 (__v16sf) __C,
7735 (__v16sf) __D,
7736 (__v16sf) __E,
7737 (const __v4sf *) __F,
7738 (__v16sf) __DEST,
7739 0xffff);
7740 }
7741 } "-mavx5124fmaps" ]
7742 }
7743
7744 # Return 1 if avx512_4vnniw instructions can be compiled.
7745 proc check_effective_target_avx5124vnniw { } {
7746 return [check_no_compiler_messages avx5124vnniw object {
7747 typedef int __v16si __attribute__ ((__vector_size__ (64)));
7748 typedef int __v4si __attribute__ ((__vector_size__ (16)));
7749
7750 __v16si
7751 _mm512_4dpwssd_epi32 (__v16si __A, __v16si __B, __v16si __C,
7752 __v16si __D, __v16si __E, __v4si *__F)
7753 {
7754 return (__v16si) __builtin_ia32_vp4dpwssd ((__v16si) __B,
7755 (__v16si) __C,
7756 (__v16si) __D,
7757 (__v16si) __E,
7758 (__v16si) __A,
7759 (const __v4si *) __F);
7760 }
7761 } "-mavx5124vnniw" ]
7762 }
7763
7764 # Return 1 if avx512_vpopcntdq instructions can be compiled.
7765 proc check_effective_target_avx512vpopcntdq { } {
7766 return [check_no_compiler_messages avx512vpopcntdq object {
7767 typedef int __v16si __attribute__ ((__vector_size__ (64)));
7768
7769 __v16si
7770 _mm512_popcnt_epi32 (__v16si __A)
7771 {
7772 return (__v16si) __builtin_ia32_vpopcountd_v16si ((__v16si) __A);
7773 }
7774 } "-mavx512vpopcntdq" ]
7775 }
7776
7777 # Return 1 if 128 or 256-bit avx512_vpopcntdq instructions can be compiled.
7778 proc check_effective_target_avx512vpopcntdqvl { } {
7779 return [check_no_compiler_messages avx512vpopcntdqvl object {
7780 typedef int __v8si __attribute__ ((__vector_size__ (32)));
7781
7782 __v8si
7783 _mm256_popcnt_epi32 (__v8si __A)
7784 {
7785 return (__v8si) __builtin_ia32_vpopcountd_v8si ((__v8si) __A);
7786 }
7787 } "-mavx512vpopcntdq -mavx512vl" ]
7788 }
7789
7790 # Return 1 if gfni instructions can be compiled.
7791 proc check_effective_target_gfni { } {
7792 return [check_no_compiler_messages gfni object {
7793 typedef char __v16qi __attribute__ ((__vector_size__ (16)));
7794
7795 __v16qi
7796 _mm_gf2p8affineinv_epi64_epi8 (__v16qi __A, __v16qi __B, const int __C)
7797 {
7798 return (__v16qi) __builtin_ia32_vgf2p8affineinvqb_v16qi ((__v16qi) __A,
7799 (__v16qi) __B,
7800 0);
7801 }
7802 } "-mgfni" ]
7803 }
7804
7805 # Return 1 if avx512vbmi2 instructions can be compiled.
7806 proc check_effective_target_avx512vbmi2 { } {
7807 return [check_no_compiler_messages avx512vbmi2 object {
7808 typedef char __v16qi __attribute__ ((__vector_size__ (16)));
7809 typedef unsigned long long __mmask16;
7810
7811 __v16qi
7812 _mm_mask_compress_epi8 (__v16qi __A, __mmask16 __B, __v16qi __C)
7813 {
7814 return (__v16qi) __builtin_ia32_compressqi128_mask((__v16qi)__C,
7815 (__v16qi)__A,
7816 (__mmask16)__B);
7817 }
7818 } "-mavx512vbmi2 -mavx512vl" ]
7819 }
7820
7821 # Return 1 if avx512vbmi2 instructions can be compiled.
7822 proc check_effective_target_avx512vnni { } {
7823 return [check_no_compiler_messages avx512vnni object {
7824 typedef int __v16si __attribute__ ((__vector_size__ (64)));
7825
7826 __v16si
7827 _mm_mask_compress_epi8 (__v16si __A, __v16si __B, __v16si __C)
7828 {
7829 return (__v16si) __builtin_ia32_vpdpbusd_v16si ((__v16si)__A,
7830 (__v16si)__B,
7831 (__v16si)__C);
7832 }
7833 } "-mavx512vnni -mavx512f" ]
7834 }
7835
7836 # Return 1 if vaes instructions can be compiled.
7837 proc check_effective_target_avx512vaes { } {
7838 return [check_no_compiler_messages avx512vaes object {
7839
7840 typedef int __v16si __attribute__ ((__vector_size__ (64)));
7841
7842 __v32qi
7843 _mm256_aesdec_epi128 (__v32qi __A, __v32qi __B)
7844 {
7845 return (__v32qi)__builtin_ia32_vaesdec_v32qi ((__v32qi) __A, (__v32qi) __B);
7846 }
7847 } "-mvaes" ]
7848 }
7849
7850 # Return 1 if vpclmulqdq instructions can be compiled.
7851 proc check_effective_target_vpclmulqdq { } {
7852 return [check_no_compiler_messages vpclmulqdq object {
7853 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
7854
7855 __v4di
7856 _mm256_clmulepi64_epi128 (__v4di __A, __v4di __B)
7857 {
7858 return (__v4di) __builtin_ia32_vpclmulqdq_v4di (__A, __B, 0);
7859 }
7860 } "-mvpclmulqdq -mavx512vl" ]
7861 }
7862
7863 # Return 1 if avx512_bitalg instructions can be compiled.
7864 proc check_effective_target_avx512bitalg { } {
7865 return [check_no_compiler_messages avx512bitalg object {
7866 typedef short int __v32hi __attribute__ ((__vector_size__ (64)));
7867
7868 __v32hi
7869 _mm512_popcnt_epi16 (__v32hi __A)
7870 {
7871 return (__v32hi) __builtin_ia32_vpopcountw_v32hi ((__v32hi) __A);
7872 }
7873 } "-mavx512bitalg" ]
7874 }
7875
7876 # Return 1 if C wchar_t type is compatible with char16_t.
7877
7878 proc check_effective_target_wchar_t_char16_t_compatible { } {
7879 return [check_no_compiler_messages wchar_t_char16_t object {
7880 __WCHAR_TYPE__ wc;
7881 __CHAR16_TYPE__ *p16 = &wc;
7882 char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
7883 }]
7884 }
7885
7886 # Return 1 if C wchar_t type is compatible with char32_t.
7887
7888 proc check_effective_target_wchar_t_char32_t_compatible { } {
7889 return [check_no_compiler_messages wchar_t_char32_t object {
7890 __WCHAR_TYPE__ wc;
7891 __CHAR32_TYPE__ *p32 = &wc;
7892 char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
7893 }]
7894 }
7895
7896 # Return 1 if pow10 function exists.
7897
7898 proc check_effective_target_pow10 { } {
7899 return [check_runtime pow10 {
7900 #include <math.h>
7901 int main () {
7902 double x;
7903 x = pow10 (1);
7904 return 0;
7905 }
7906 } "-lm" ]
7907 }
7908
7909 # Return 1 if frexpl function exists.
7910
7911 proc check_effective_target_frexpl { } {
7912 return [check_runtime frexpl {
7913 #include <math.h>
7914 int main () {
7915 long double x;
7916 int y;
7917 x = frexpl (5.0, &y);
7918 return 0;
7919 }
7920 } "-lm" ]
7921 }
7922
7923
7924 # Return 1 if issignaling function exists.
7925 proc check_effective_target_issignaling {} {
7926 return [check_runtime issignaling {
7927 #define _GNU_SOURCE
7928 #include <math.h>
7929 int main ()
7930 {
7931 return issignaling (0.0);
7932 }
7933 } "-lm" ]
7934 }
7935
7936 # Return 1 if current options generate DFP instructions, 0 otherwise.
7937 proc check_effective_target_hard_dfp {} {
7938 return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
7939 typedef float d64 __attribute__((mode(DD)));
7940 d64 x, y, z;
7941 void foo (void) { z = x + y; }
7942 }]
7943 }
7944
7945 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
7946 # for strchr etc. functions.
7947
7948 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
7949 return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
7950 #include <string.h>
7951 #include <wchar.h>
7952 #if !defined(__cplusplus) \
7953 || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
7954 || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
7955 ISO C++ correct string.h and wchar.h protos not supported.
7956 #else
7957 int i;
7958 #endif
7959 }]
7960 }
7961
7962 # Return 1 if GNU as is used.
7963
7964 proc check_effective_target_gas { } {
7965 global use_gas_saved
7966 global tool
7967
7968 if {![info exists use_gas_saved]} {
7969 # Check if the as used by gcc is GNU as.
7970 set gcc_as [lindex [${tool}_target_compile "-print-prog-name=as" "" "none" ""] 0]
7971 # Provide /dev/null as input, otherwise gas times out reading from
7972 # stdin.
7973 set status [remote_exec host "$gcc_as" "-v /dev/null"]
7974 set as_output [lindex $status 1]
7975 if { [ string first "GNU" $as_output ] >= 0 } {
7976 set use_gas_saved 1
7977 } else {
7978 set use_gas_saved 0
7979 }
7980 }
7981 return $use_gas_saved
7982 }
7983
7984 # Return 1 if GNU ld is used.
7985
7986 proc check_effective_target_gld { } {
7987 global use_gld_saved
7988 global tool
7989
7990 if {![info exists use_gld_saved]} {
7991 # Check if the ld used by gcc is GNU ld.
7992 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=ld" "" "none" ""] 0]
7993 set status [remote_exec host "$gcc_ld" "--version"]
7994 set ld_output [lindex $status 1]
7995 if { [ string first "GNU" $ld_output ] >= 0 } {
7996 set use_gld_saved 1
7997 } else {
7998 set use_gld_saved 0
7999 }
8000 }
8001 return $use_gld_saved
8002 }
8003
8004 # Return 1 if the compiler has been configure with link-time optimization
8005 # (LTO) support.
8006
8007 proc check_effective_target_lto { } {
8008 if { [istarget nvptx-*-*] } {
8009 return 0;
8010 }
8011 return [check_no_compiler_messages lto object {
8012 void foo (void) { }
8013 } "-flto"]
8014 }
8015
8016 # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
8017
8018 proc check_effective_target_maybe_x32 { } {
8019 return [check_no_compiler_messages maybe_x32 object {
8020 void foo (void) {}
8021 } "-mx32 -maddress-mode=short"]
8022 }
8023
8024 # Return 1 if this target supports the -fsplit-stack option, 0
8025 # otherwise.
8026
8027 proc check_effective_target_split_stack {} {
8028 return [check_no_compiler_messages split_stack object {
8029 void foo (void) { }
8030 } "-fsplit-stack"]
8031 }
8032
8033 # Return 1 if this target supports the -masm=intel option, 0
8034 # otherwise
8035
8036 proc check_effective_target_masm_intel {} {
8037 return [check_no_compiler_messages masm_intel object {
8038 extern void abort (void);
8039 } "-masm=intel"]
8040 }
8041
8042 # Return 1 if the language for the compiler under test is C.
8043
8044 proc check_effective_target_c { } {
8045 global tool
8046 if [string match $tool "gcc"] {
8047 return 1
8048 }
8049 return 0
8050 }
8051
8052 # Return 1 if the language for the compiler under test is C++.
8053
8054 proc check_effective_target_c++ { } {
8055 global tool
8056 if { [string match $tool "g++"] || [string match $tool "libstdc++"] } {
8057 return 1
8058 }
8059 return 0
8060 }
8061
8062 set cxx_default "c++14"
8063 # Check whether the current active language standard supports the features
8064 # of C++11/C++14 by checking for the presence of one of the -std flags.
8065 # This assumes that the default for the compiler is $cxx_default, and that
8066 # there will never be multiple -std= arguments on the command line.
8067 proc check_effective_target_c++11_only { } {
8068 global cxx_default
8069 if ![check_effective_target_c++] {
8070 return 0
8071 }
8072 if [check-flags { { } { } { -std=c++0x -std=gnu++0x -std=c++11 -std=gnu++11 } }] {
8073 return 1
8074 }
8075 if { $cxx_default == "c++11" && [check-flags { { } { } { } { -std=* } }] } {
8076 return 1
8077 }
8078 return 0
8079 }
8080 proc check_effective_target_c++11 { } {
8081 if [check_effective_target_c++11_only] {
8082 return 1
8083 }
8084 return [check_effective_target_c++14]
8085 }
8086 proc check_effective_target_c++11_down { } {
8087 if ![check_effective_target_c++] {
8088 return 0
8089 }
8090 return [expr ![check_effective_target_c++14] ]
8091 }
8092
8093 proc check_effective_target_c++14_only { } {
8094 global cxx_default
8095 if ![check_effective_target_c++] {
8096 return 0
8097 }
8098 if [check-flags { { } { } { -std=c++14 -std=gnu++14 -std=c++14 -std=gnu++14 } }] {
8099 return 1
8100 }
8101 if { $cxx_default == "c++14" && [check-flags { { } { } { } { -std=* } }] } {
8102 return 1
8103 }
8104 return 0
8105 }
8106
8107 proc check_effective_target_c++14 { } {
8108 if [check_effective_target_c++14_only] {
8109 return 1
8110 }
8111 return [check_effective_target_c++17]
8112 }
8113 proc check_effective_target_c++14_down { } {
8114 if ![check_effective_target_c++] {
8115 return 0
8116 }
8117 return [expr ![check_effective_target_c++17] ]
8118 }
8119
8120 proc check_effective_target_c++98_only { } {
8121 global cxx_default
8122 if ![check_effective_target_c++] {
8123 return 0
8124 }
8125 if [check-flags { { } { } { -std=c++98 -std=gnu++98 -std=c++03 -std=gnu++03 } }] {
8126 return 1
8127 }
8128 if { $cxx_default == "c++98" && [check-flags { { } { } { } { -std=* } }] } {
8129 return 1
8130 }
8131 return 0
8132 }
8133
8134 proc check_effective_target_c++17_only { } {
8135 global cxx_default
8136 if ![check_effective_target_c++] {
8137 return 0
8138 }
8139 if [check-flags { { } { } { -std=c++17 -std=gnu++17 -std=c++1z -std=gnu++1z } }] {
8140 return 1
8141 }
8142 if { $cxx_default == "c++17" && [check-flags { { } { } { } { -std=* } }] } {
8143 return 1
8144 }
8145 return 0
8146 }
8147
8148 proc check_effective_target_c++17 { } {
8149 if [check_effective_target_c++17_only] {
8150 return 1
8151 }
8152 return [check_effective_target_c++2a]
8153 }
8154 proc check_effective_target_c++17_down { } {
8155 if ![check_effective_target_c++] {
8156 return 0
8157 }
8158 return [expr ![check_effective_target_c++2a] ]
8159 }
8160
8161 proc check_effective_target_c++2a_only { } {
8162 global cxx_default
8163 if ![check_effective_target_c++] {
8164 return 0
8165 }
8166 if [check-flags { { } { } { -std=c++2a -std=gnu++2a } }] {
8167 return 1
8168 }
8169 if { $cxx_default == "c++20" && [check-flags { { } { } { } { -std=* } }] } {
8170 return 1
8171 }
8172 return 0
8173 }
8174 proc check_effective_target_c++2a { } {
8175 return [check_effective_target_c++2a_only]
8176 }
8177
8178 # Check for C++ Concepts TS support, i.e. -fconcepts flag.
8179 proc check_effective_target_concepts { } {
8180 return [check-flags { "" { } { -fconcepts } }]
8181 }
8182
8183 # Return 1 if expensive testcases should be run.
8184
8185 proc check_effective_target_run_expensive_tests { } {
8186 if { [getenv GCC_TEST_RUN_EXPENSIVE] != "" } {
8187 return 1
8188 }
8189 return 0
8190 }
8191
8192 # Returns 1 if "mempcpy" is available on the target system.
8193
8194 proc check_effective_target_mempcpy {} {
8195 return [check_function_available "mempcpy"]
8196 }
8197
8198 # Returns 1 if "stpcpy" is available on the target system.
8199
8200 proc check_effective_target_stpcpy {} {
8201 return [check_function_available "stpcpy"]
8202 }
8203
8204 # Check whether the vectorizer tests are supported by the target and
8205 # append additional target-dependent compile flags to DEFAULT_VECTCFLAGS.
8206 # If a port wants to execute the tests more than once it should append
8207 # the supported target to EFFECTIVE_TARGETS instead, and the compile flags
8208 # will be added by a call to add_options_for_<target>.
8209 # Set dg-do-what-default to either compile or run, depending on target
8210 # capabilities. Do not set this if the supported target is appended to
8211 # EFFECTIVE_TARGETS. Flags and this variable will be set by et-dg-runtest
8212 # automatically. Return the number of effective targets if vectorizer tests
8213 # are supported, 0 otherwise.
8214
8215 proc check_vect_support_and_set_flags { } {
8216 global DEFAULT_VECTCFLAGS
8217 global dg-do-what-default
8218 global EFFECTIVE_TARGETS
8219
8220 if [istarget powerpc-*paired*] {
8221 lappend DEFAULT_VECTCFLAGS "-mpaired"
8222 if [check_750cl_hw_available] {
8223 set dg-do-what-default run
8224 } else {
8225 set dg-do-what-default compile
8226 }
8227 } elseif [istarget powerpc*-*-*] {
8228 # Skip targets not supporting -maltivec.
8229 if ![is-effective-target powerpc_altivec_ok] {
8230 return 0
8231 }
8232
8233 lappend DEFAULT_VECTCFLAGS "-maltivec"
8234 if [check_p9vector_hw_available] {
8235 lappend DEFAULT_VECTCFLAGS "-mpower9-vector"
8236 } elseif [check_p8vector_hw_available] {
8237 lappend DEFAULT_VECTCFLAGS "-mpower8-vector"
8238 } elseif [check_vsx_hw_available] {
8239 lappend DEFAULT_VECTCFLAGS "-mvsx" "-mno-allow-movmisalign"
8240 }
8241
8242 if [check_vmx_hw_available] {
8243 set dg-do-what-default run
8244 } else {
8245 if [is-effective-target ilp32] {
8246 # Specify a cpu that supports VMX for compile-only tests.
8247 lappend DEFAULT_VECTCFLAGS "-mcpu=970"
8248 }
8249 set dg-do-what-default compile
8250 }
8251 } elseif { [istarget spu-*-*] } {
8252 set dg-do-what-default run
8253 } elseif { [istarget i?86-*-*] || [istarget x86_64-*-*] } {
8254 lappend DEFAULT_VECTCFLAGS "-msse2"
8255 if { [check_effective_target_sse2_runtime] } {
8256 set dg-do-what-default run
8257 } else {
8258 set dg-do-what-default compile
8259 }
8260 } elseif { [istarget mips*-*-*]
8261 && [check_effective_target_nomips16] } {
8262 if { [check_effective_target_mpaired_single] } {
8263 lappend EFFECTIVE_TARGETS mpaired_single
8264 }
8265 if { [check_effective_target_mips_loongson_mmi] } {
8266 lappend EFFECTIVE_TARGETS mips_loongson_mmi
8267 }
8268 if { [check_effective_target_mips_msa] } {
8269 lappend EFFECTIVE_TARGETS mips_msa
8270 }
8271 return [llength $EFFECTIVE_TARGETS]
8272 } elseif [istarget sparc*-*-*] {
8273 lappend DEFAULT_VECTCFLAGS "-mcpu=ultrasparc" "-mvis"
8274 if [check_effective_target_ultrasparc_hw] {
8275 set dg-do-what-default run
8276 } else {
8277 set dg-do-what-default compile
8278 }
8279 } elseif [istarget alpha*-*-*] {
8280 # Alpha's vectorization capabilities are extremely limited.
8281 # It's more effort than its worth disabling all of the tests
8282 # that it cannot pass. But if you actually want to see what
8283 # does work, command out the return.
8284 return 0
8285
8286 lappend DEFAULT_VECTCFLAGS "-mmax"
8287 if [check_alpha_max_hw_available] {
8288 set dg-do-what-default run
8289 } else {
8290 set dg-do-what-default compile
8291 }
8292 } elseif [istarget ia64-*-*] {
8293 set dg-do-what-default run
8294 } elseif [is-effective-target arm_neon_ok] {
8295 eval lappend DEFAULT_VECTCFLAGS [add_options_for_arm_neon ""]
8296 # NEON does not support denormals, so is not used for vectorization by
8297 # default to avoid loss of precision. We must pass -ffast-math to test
8298 # vectorization of float operations.
8299 lappend DEFAULT_VECTCFLAGS "-ffast-math"
8300 if [is-effective-target arm_neon_hw] {
8301 set dg-do-what-default run
8302 } else {
8303 set dg-do-what-default compile
8304 }
8305 } elseif [istarget "aarch64*-*-*"] {
8306 set dg-do-what-default run
8307 } elseif [istarget s390*-*-*] {
8308 # The S/390 backend set a default of 2 for that value.
8309 # Override it to have the same situation as with other
8310 # targets.
8311 lappend DEFAULT_VECTCFLAGS "--param" "min-vect-loop-bound=1"
8312 lappend DEFAULT_VECTCFLAGS "--param" "max-unrolled-insns=200"
8313 lappend DEFAULT_VECTCFLAGS "--param" "max-unroll-times=8"
8314 lappend DEFAULT_VECTCFLAGS "--param" "max-completely-peeled-insns=200"
8315 lappend DEFAULT_VECTCFLAGS "--param" "max-completely-peel-times=16"
8316 if [check_effective_target_s390_vxe] {
8317 lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch"
8318 set dg-do-what-default run
8319 } elseif [check_effective_target_s390_vx] {
8320 lappend DEFAULT_VECTCFLAGS "-march=z13" "-mzarch"
8321 set dg-do-what-default run
8322 } else {
8323 lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch"
8324 set dg-do-what-default compile
8325 }
8326 } else {
8327 return 0
8328 }
8329
8330 return 1
8331 }
8332
8333 # Return 1 if the target does *not* require strict alignment.
8334
8335 proc check_effective_target_non_strict_align {} {
8336
8337 # On ARM, the default is to use STRICT_ALIGNMENT, but there
8338 # are interfaces defined for misaligned access and thus
8339 # depending on the architecture levels unaligned access is
8340 # available.
8341 if [istarget "arm*-*-*"] {
8342 return [check_effective_target_arm_unaligned]
8343 }
8344
8345 return [check_no_compiler_messages non_strict_align assembly {
8346 char *y;
8347 typedef char __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) c;
8348 c *z;
8349 void foo(void) { z = (c *) y; }
8350 } "-Wcast-align"]
8351 }
8352
8353 # Return 1 if the target has <ucontext.h>.
8354
8355 proc check_effective_target_ucontext_h { } {
8356 return [check_no_compiler_messages ucontext_h assembly {
8357 #include <ucontext.h>
8358 }]
8359 }
8360
8361 proc check_effective_target_aarch64_tiny { } {
8362 if { [istarget aarch64*-*-*] } {
8363 return [check_no_compiler_messages aarch64_tiny object {
8364 #ifdef __AARCH64_CMODEL_TINY__
8365 int dummy;
8366 #else
8367 #error target not AArch64 tiny code model
8368 #endif
8369 }]
8370 } else {
8371 return 0
8372 }
8373 }
8374
8375 # Create functions to check that the AArch64 assembler supports the
8376 # various architecture extensions via the .arch_extension pseudo-op.
8377
8378 foreach { aarch64_ext } { "fp" "simd" "crypto" "crc" "lse" "dotprod" "sve"} {
8379 eval [string map [list FUNC $aarch64_ext] {
8380 proc check_effective_target_aarch64_asm_FUNC_ok { } {
8381 if { [istarget aarch64*-*-*] } {
8382 return [check_no_compiler_messages aarch64_FUNC_assembler object {
8383 __asm__ (".arch_extension FUNC");
8384 } "-march=armv8-a+FUNC"]
8385 } else {
8386 return 0
8387 }
8388 }
8389 }]
8390 }
8391
8392 proc check_effective_target_aarch64_small { } {
8393 if { [istarget aarch64*-*-*] } {
8394 return [check_no_compiler_messages aarch64_small object {
8395 #ifdef __AARCH64_CMODEL_SMALL__
8396 int dummy;
8397 #else
8398 #error target not AArch64 small code model
8399 #endif
8400 }]
8401 } else {
8402 return 0
8403 }
8404 }
8405
8406 proc check_effective_target_aarch64_large { } {
8407 if { [istarget aarch64*-*-*] } {
8408 return [check_no_compiler_messages aarch64_large object {
8409 #ifdef __AARCH64_CMODEL_LARGE__
8410 int dummy;
8411 #else
8412 #error target not AArch64 large code model
8413 #endif
8414 }]
8415 } else {
8416 return 0
8417 }
8418 }
8419
8420
8421 # Return 1 if this is a reduced AVR Tiny core. Such cores have different
8422 # register set, instruction set, addressing capabilities and ABI.
8423
8424 proc check_effective_target_avr_tiny { } {
8425 if { [istarget avr*-*-*] } {
8426 return [check_no_compiler_messages avr_tiny object {
8427 #ifdef __AVR_TINY__
8428 int dummy;
8429 #else
8430 #error target not a reduced AVR Tiny core
8431 #endif
8432 }]
8433 } else {
8434 return 0
8435 }
8436 }
8437
8438 # Return 1 if <fenv.h> is available with all the standard IEEE
8439 # exceptions and floating-point exceptions are raised by arithmetic
8440 # operations. (If the target requires special options for "inexact"
8441 # exceptions, those need to be specified in the testcases.)
8442
8443 proc check_effective_target_fenv_exceptions {} {
8444 return [check_runtime fenv_exceptions {
8445 #include <fenv.h>
8446 #include <stdlib.h>
8447 #ifndef FE_DIVBYZERO
8448 # error Missing FE_DIVBYZERO
8449 #endif
8450 #ifndef FE_INEXACT
8451 # error Missing FE_INEXACT
8452 #endif
8453 #ifndef FE_INVALID
8454 # error Missing FE_INVALID
8455 #endif
8456 #ifndef FE_OVERFLOW
8457 # error Missing FE_OVERFLOW
8458 #endif
8459 #ifndef FE_UNDERFLOW
8460 # error Missing FE_UNDERFLOW
8461 #endif
8462 volatile float a = 0.0f, r;
8463 int
8464 main (void)
8465 {
8466 r = a / a;
8467 if (fetestexcept (FE_INVALID))
8468 exit (0);
8469 else
8470 abort ();
8471 }
8472 } [add_options_for_ieee "-std=gnu99"]]
8473 }
8474
8475 proc check_effective_target_tiny {} {
8476 return [check_cached_effective_target tiny {
8477 if { [istarget aarch64*-*-*]
8478 && [check_effective_target_aarch64_tiny] } {
8479 return 1
8480 }
8481 if { [istarget avr-*-*]
8482 && [check_effective_target_avr_tiny] } {
8483 return 1
8484 }
8485 return 0
8486 }]
8487 }
8488
8489 # Return 1 if LOGICAL_OP_NON_SHORT_CIRCUIT is set to 0 for the current target.
8490
8491 proc check_effective_target_logical_op_short_circuit {} {
8492 if { [istarget mips*-*-*]
8493 || [istarget arc*-*-*]
8494 || [istarget avr*-*-*]
8495 || [istarget crisv32-*-*] || [istarget cris-*-*]
8496 || [istarget csky*-*-*]
8497 || [istarget mmix-*-*]
8498 || [istarget msp430-*-*]
8499 || [istarget s390*-*-*]
8500 || [istarget powerpc*-*-*]
8501 || [istarget nios2*-*-*]
8502 || [istarget riscv*-*-*]
8503 || [istarget v850*-*-*]
8504 || [istarget visium-*-*]
8505 || [istarget or1k*-*-*]
8506 || [check_effective_target_arm_cortex_m] } {
8507 return 1
8508 }
8509 return 0
8510 }
8511
8512 # Return 1 if the target supports -mbranch-cost=N option.
8513
8514 proc check_effective_target_branch_cost {} {
8515 if { [ istarget arm*-*-*]
8516 || [istarget avr*-*-*]
8517 || [istarget csky*-*-*]
8518 || [istarget epiphany*-*-*]
8519 || [istarget frv*-*-*]
8520 || [istarget i?86-*-*] || [istarget x86_64-*-*]
8521 || [istarget mips*-*-*]
8522 || [istarget s390*-*-*]
8523 || [istarget riscv*-*-*]
8524 || [istarget sh*-*-*]
8525 || [istarget spu*-*-*] } {
8526 return 1
8527 }
8528 return 0
8529 }
8530
8531 # Record that dg-final test TEST requires convential compilation.
8532
8533 proc force_conventional_output_for { test } {
8534 if { [info proc $test] == "" } {
8535 perror "$test does not exist"
8536 exit 1
8537 }
8538 proc ${test}_required_options {} {
8539 global gcc_force_conventional_output
8540 upvar 1 extra_tool_flags extra_tool_flags
8541 if {[regexp -- "^scan-assembler" [info level 0]]
8542 && ![string match "*-fident*" $extra_tool_flags]} {
8543 # Do not let .ident confuse assembler scan tests
8544 return [list $gcc_force_conventional_output "-fno-ident"]
8545 }
8546 return $gcc_force_conventional_output
8547 }
8548 }
8549
8550 # Record that dg-final test scan-ltrans-tree-dump* requires -flto-partition=one
8551 # in order to force a single partition, allowing scan-ltrans-tree-dump* to scan
8552 # a dump file *.exe.ltrans0.*.
8553
8554 proc scan-ltrans-tree-dump_required_options {} {
8555 return "-flto-partition=one"
8556 }
8557 proc scan-ltrans-tree-dump-times_required_options {} {
8558 return "-flto-partition=one"
8559 }
8560 proc scan-ltrans-tree-dump-not_required_options {} {
8561 return "-flto-partition=one"
8562 }
8563 proc scan-ltrans-tree-dump-dem_required_options {} {
8564 return "-flto-partition=one"
8565 }
8566 proc scan-ltrans-tree-dump-dem-not_required_options {} {
8567 return "-flto-partition=one"
8568 }
8569
8570 # Return 1 if the x86-64 target supports PIE with copy reloc, 0
8571 # otherwise. Cache the result.
8572
8573 proc check_effective_target_pie_copyreloc { } {
8574 global tool
8575 global GCC_UNDER_TEST
8576
8577 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8578 return 0
8579 }
8580
8581 # Need auto-host.h to check linker support.
8582 if { ![file exists ../../auto-host.h ] } {
8583 return 0
8584 }
8585
8586 return [check_cached_effective_target pie_copyreloc {
8587 # Set up and compile to see if linker supports PIE with copy
8588 # reloc. Include the current process ID in the file names to
8589 # prevent conflicts with invocations for multiple testsuites.
8590
8591 set src pie[pid].c
8592 set obj pie[pid].o
8593
8594 set f [open $src "w"]
8595 puts $f "#include \"../../auto-host.h\""
8596 puts $f "#if HAVE_LD_PIE_COPYRELOC == 0"
8597 puts $f "# error Linker does not support PIE with copy reloc."
8598 puts $f "#endif"
8599 close $f
8600
8601 verbose "check_effective_target_pie_copyreloc compiling testfile $src" 2
8602 set lines [${tool}_target_compile $src $obj object ""]
8603
8604 file delete $src
8605 file delete $obj
8606
8607 if [string match "" $lines] then {
8608 verbose "check_effective_target_pie_copyreloc testfile compilation passed" 2
8609 return 1
8610 } else {
8611 verbose "check_effective_target_pie_copyreloc testfile compilation failed" 2
8612 return 0
8613 }
8614 }]
8615 }
8616
8617 # Return 1 if the x86 target supports R_386_GOT32X relocation, 0
8618 # otherwise. Cache the result.
8619
8620 proc check_effective_target_got32x_reloc { } {
8621 global tool
8622 global GCC_UNDER_TEST
8623
8624 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8625 return 0
8626 }
8627
8628 # Need auto-host.h to check linker support.
8629 if { ![file exists ../../auto-host.h ] } {
8630 return 0
8631 }
8632
8633 return [check_cached_effective_target got32x_reloc {
8634 # Include the current process ID in the file names to prevent
8635 # conflicts with invocations for multiple testsuites.
8636
8637 set src got32x[pid].c
8638 set obj got32x[pid].o
8639
8640 set f [open $src "w"]
8641 puts $f "#include \"../../auto-host.h\""
8642 puts $f "#if HAVE_AS_IX86_GOT32X == 0"
8643 puts $f "# error Assembler does not support R_386_GOT32X."
8644 puts $f "#endif"
8645 close $f
8646
8647 verbose "check_effective_target_got32x_reloc compiling testfile $src" 2
8648 set lines [${tool}_target_compile $src $obj object ""]
8649
8650 file delete $src
8651 file delete $obj
8652
8653 if [string match "" $lines] then {
8654 verbose "check_effective_target_got32x_reloc testfile compilation passed" 2
8655 return 1
8656 } else {
8657 verbose "check_effective_target_got32x_reloc testfile compilation failed" 2
8658 return 0
8659 }
8660 }]
8661
8662 return $got32x_reloc_available_saved
8663 }
8664
8665 # Return 1 if the x86 target supports calling ___tls_get_addr via GOT,
8666 # 0 otherwise. Cache the result.
8667
8668 proc check_effective_target_tls_get_addr_via_got { } {
8669 global tool
8670 global GCC_UNDER_TEST
8671
8672 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
8673 return 0
8674 }
8675
8676 # Need auto-host.h to check linker support.
8677 if { ![file exists ../../auto-host.h ] } {
8678 return 0
8679 }
8680
8681 return [check_cached_effective_target tls_get_addr_via_got {
8682 # Include the current process ID in the file names to prevent
8683 # conflicts with invocations for multiple testsuites.
8684
8685 set src tls_get_addr_via_got[pid].c
8686 set obj tls_get_addr_via_got[pid].o
8687
8688 set f [open $src "w"]
8689 puts $f "#include \"../../auto-host.h\""
8690 puts $f "#if HAVE_AS_IX86_TLS_GET_ADDR_GOT == 0"
8691 puts $f "# error Assembler/linker do not support calling ___tls_get_addr via GOT."
8692 puts $f "#endif"
8693 close $f
8694
8695 verbose "check_effective_target_tls_get_addr_via_got compiling testfile $src" 2
8696 set lines [${tool}_target_compile $src $obj object ""]
8697
8698 file delete $src
8699 file delete $obj
8700
8701 if [string match "" $lines] then {
8702 verbose "check_effective_target_tls_get_addr_via_got testfile compilation passed" 2
8703 return 1
8704 } else {
8705 verbose "check_effective_target_tls_get_addr_via_got testfile compilation failed" 2
8706 return 0
8707 }
8708 }]
8709 }
8710
8711 # Return 1 if the target uses comdat groups.
8712
8713 proc check_effective_target_comdat_group {} {
8714 return [check_no_messages_and_pattern comdat_group "\.section\[^\n\r]*,comdat|\.group\[^\n\r]*,#comdat" assembly {
8715 // C++
8716 inline int foo () { return 1; }
8717 int (*fn) () = foo;
8718 }]
8719 }
8720
8721 # Return 1 if target supports __builtin_eh_return
8722 proc check_effective_target_builtin_eh_return { } {
8723 return [check_no_compiler_messages builtin_eh_return object {
8724 void test (long l, void *p)
8725 {
8726 __builtin_eh_return (l, p);
8727 }
8728 } "" ]
8729 }
8730
8731 # Return 1 if the target supports max reduction for vectors.
8732
8733 proc check_effective_target_vect_max_reduc { } {
8734 if { [istarget aarch64*-*-*] || [is-effective-target arm_neon] } {
8735 return 1
8736 }
8737 return 0
8738 }
8739
8740 # Return 1 if there is an nvptx offload compiler.
8741
8742 proc check_effective_target_offload_nvptx { } {
8743 return [check_no_compiler_messages offload_nvptx object {
8744 int main () {return 0;}
8745 } "-foffload=nvptx-none" ]
8746 }
8747
8748 # Return 1 if the compiler has been configured with hsa offloading.
8749
8750 proc check_effective_target_offload_hsa { } {
8751 return [check_no_compiler_messages offload_hsa assembly {
8752 int main () {return 0;}
8753 } "-foffload=hsa" ]
8754 }
8755
8756 # Return 1 if the target support -fprofile-update=atomic
8757 proc check_effective_target_profile_update_atomic {} {
8758 return [check_no_compiler_messages profile_update_atomic assembly {
8759 int main (void) { return 0; }
8760 } "-fprofile-update=atomic -fprofile-generate"]
8761 }
8762
8763 # Return 1 if vector (va - vector add) instructions are understood by
8764 # the assembler and can be executed. This also covers checking for
8765 # the VX kernel feature. A kernel without that feature does not
8766 # enable the vector facility and the following check will die with a
8767 # signal.
8768 proc check_effective_target_s390_vx { } {
8769 if ![istarget s390*-*-*] then {
8770 return 0;
8771 }
8772
8773 return [check_runtime s390_check_vx {
8774 int main (void)
8775 {
8776 asm ("va %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
8777 return 0;
8778 }
8779 } "-march=z13 -mzarch" ]
8780 }
8781
8782 # Same as above but for the z14 vector enhancement facility. Test
8783 # is performed with the vector nand instruction.
8784 proc check_effective_target_s390_vxe { } {
8785 if ![istarget s390*-*-*] then {
8786 return 0;
8787 }
8788
8789 return [check_runtime s390_check_vxe {
8790 int main (void)
8791 {
8792 asm ("vnn %%v24, %%v26, %%v28" : : : "v24", "v26", "v28");
8793 return 0;
8794 }
8795 } "-march=z14 -mzarch" ]
8796 }
8797
8798 #For versions of ARM architectures that have hardware div insn,
8799 #disable the divmod transform
8800
8801 proc check_effective_target_arm_divmod_simode { } {
8802 return [check_no_compiler_messages arm_divmod assembly {
8803 #ifdef __ARM_ARCH_EXT_IDIV__
8804 #error has div insn
8805 #endif
8806 int i;
8807 }]
8808 }
8809
8810 # Return 1 if target supports divmod hardware insn or divmod libcall.
8811
8812 proc check_effective_target_divmod { } {
8813 #TODO: Add checks for all targets that have either hardware divmod insn
8814 # or define libfunc for divmod.
8815 if { [istarget arm*-*-*]
8816 || [istarget i?86-*-*] || [istarget x86_64-*-*] } {
8817 return 1
8818 }
8819 return 0
8820 }
8821
8822 # Return 1 if target supports divmod for SImode. The reason for
8823 # separating this from check_effective_target_divmod is that
8824 # some versions of ARM architecture define div instruction
8825 # only for simode, and for these archs, we do not want to enable
8826 # divmod transform for simode.
8827
8828 proc check_effective_target_divmod_simode { } {
8829 if { [istarget arm*-*-*] } {
8830 return [check_effective_target_arm_divmod_simode]
8831 }
8832
8833 return [check_effective_target_divmod]
8834 }
8835
8836 # Return 1 if store merging optimization is applicable for target.
8837 # Store merging is not profitable for targets like the avr which
8838 # can load/store only one byte at a time. Use int size as a proxy
8839 # for the number of bytes the target can write, and skip for targets
8840 # with a smallish (< 32) size.
8841
8842 proc check_effective_target_store_merge { } {
8843 if { [is-effective-target non_strict_align ] && [is-effective-target int32plus] } {
8844 return 1
8845 }
8846
8847 return 0
8848 }
8849
8850 # Return 1 if we're able to assemble rdrand
8851
8852 proc check_effective_target_rdrand { } {
8853 return [check_no_compiler_messages_nocache rdrand object {
8854 unsigned int
8855 __foo(void)
8856 {
8857 unsigned int val;
8858 __builtin_ia32_rdrand32_step(&val);
8859 return val;
8860 }
8861 } "-mrdrnd" ]
8862 }
8863
8864 # Return 1 if the target supports coprocessor instructions: cdp, ldc, ldcl,
8865 # stc, stcl, mcr and mrc.
8866 proc check_effective_target_arm_coproc1_ok_nocache { } {
8867 if { ![istarget arm*-*-*] } {
8868 return 0
8869 }
8870 return [check_no_compiler_messages_nocache arm_coproc1_ok assembly {
8871 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 4
8872 #error FOO
8873 #endif
8874 }]
8875 }
8876
8877 proc check_effective_target_arm_coproc1_ok { } {
8878 return [check_cached_effective_target arm_coproc1_ok \
8879 check_effective_target_arm_coproc1_ok_nocache]
8880 }
8881
8882 # Return 1 if the target supports all coprocessor instructions checked by
8883 # check_effective_target_arm_coproc1_ok in addition to the following: cdp2,
8884 # ldc2, ldc2l, stc2, stc2l, mcr2 and mrc2.
8885 proc check_effective_target_arm_coproc2_ok_nocache { } {
8886 if { ![check_effective_target_arm_coproc1_ok] } {
8887 return 0
8888 }
8889 return [check_no_compiler_messages_nocache arm_coproc2_ok assembly {
8890 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 5
8891 #error FOO
8892 #endif
8893 }]
8894 }
8895
8896 proc check_effective_target_arm_coproc2_ok { } {
8897 return [check_cached_effective_target arm_coproc2_ok \
8898 check_effective_target_arm_coproc2_ok_nocache]
8899 }
8900
8901 # Return 1 if the target supports all coprocessor instructions checked by
8902 # check_effective_target_arm_coproc2_ok in addition the following: mcrr and
8903 # mrrc.
8904 proc check_effective_target_arm_coproc3_ok_nocache { } {
8905 if { ![check_effective_target_arm_coproc2_ok] } {
8906 return 0
8907 }
8908 return [check_no_compiler_messages_nocache arm_coproc3_ok assembly {
8909 #if (__thumb__ && !__thumb2__) \
8910 || (__ARM_ARCH < 6 && !defined (__ARM_ARCH_5TE__))
8911 #error FOO
8912 #endif
8913 }]
8914 }
8915
8916 proc check_effective_target_arm_coproc3_ok { } {
8917 return [check_cached_effective_target arm_coproc3_ok \
8918 check_effective_target_arm_coproc3_ok_nocache]
8919 }
8920
8921 # Return 1 if the target supports all coprocessor instructions checked by
8922 # check_effective_target_arm_coproc3_ok in addition the following: mcrr2 and
8923 # mrcc2.
8924 proc check_effective_target_arm_coproc4_ok_nocache { } {
8925 if { ![check_effective_target_arm_coproc3_ok] } {
8926 return 0
8927 }
8928 return [check_no_compiler_messages_nocache arm_coproc4_ok assembly {
8929 #if (__thumb__ && !__thumb2__) || __ARM_ARCH < 6
8930 #error FOO
8931 #endif
8932 }]
8933 }
8934
8935 proc check_effective_target_arm_coproc4_ok { } {
8936 return [check_cached_effective_target arm_coproc4_ok \
8937 check_effective_target_arm_coproc4_ok_nocache]
8938 }
8939
8940 # Return 1 if the target supports the auto_inc_dec optimization pass.
8941 proc check_effective_target_autoincdec { } {
8942 if { ![check_no_compiler_messages auto_incdec assembly { void f () { }
8943 } "-O2 -fdump-rtl-auto_inc_dec" ] } {
8944 return 0
8945 }
8946
8947 set dumpfile [glob -nocomplain "auto_incdec[pid].c.\[0-9\]\[0-9\]\[0-9\]r.auto_inc_dec"]
8948 if { [file exists $dumpfile ] } {
8949 file delete $dumpfile
8950 return 1
8951 }
8952 return 0
8953 }
8954
8955 # Return 1 if the target has support for stack probing designed
8956 # to avoid stack-clash style attacks.
8957 #
8958 # This is used to restrict the stack-clash mitigation tests to
8959 # just those targets that have been explicitly supported.
8960 #
8961 # In addition to the prologue work on those targets, each target's
8962 # properties should be described in the functions below so that
8963 # tests do not become a mess of unreadable target conditions.
8964 #
8965 proc check_effective_target_supports_stack_clash_protection { } {
8966
8967 if { [istarget x86_64-*-*] || [istarget i?86-*-*]
8968 || [istarget powerpc*-*-*] || [istarget rs6000*-*-*]
8969 || [istarget aarch64*-**] || [istarget s390*-*-*] } {
8970 return 1
8971 }
8972 return 0
8973 }
8974
8975 # Return 1 if the target creates a frame pointer for non-leaf functions
8976 # Note we ignore cases where we apply tail call optimization here.
8977 proc check_effective_target_frame_pointer_for_non_leaf { } {
8978 # Solaris/x86 defaults to -fno-omit-frame-pointer.
8979 if { [istarget i?86-*-solaris*] || [istarget x86_64-*-solaris*] } {
8980 return 1
8981 }
8982
8983 return 0
8984 }
8985
8986 # Return 1 if the target's calling sequence or its ABI
8987 # create implicit stack probes at or prior to function entry.
8988 proc check_effective_target_caller_implicit_probes { } {
8989
8990 # On x86/x86_64 the call instruction itself pushes the return
8991 # address onto the stack. That is an implicit probe of *sp.
8992 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
8993 return 1
8994 }
8995
8996 # On PPC, the ABI mandates that the address of the outer
8997 # frame be stored at *sp. Thus each allocation of stack
8998 # space is itself an implicit probe of *sp.
8999 if { [istarget powerpc*-*-*] || [istarget rs6000*-*-*] } {
9000 return 1
9001 }
9002
9003 # s390's ABI has a register save area allocated by the
9004 # caller for use by the callee. The mere existence does
9005 # not constitute a probe by the caller, but when the slots
9006 # used by the callee those stores are implicit probes.
9007 if { [istarget s390*-*-*] } {
9008 return 1
9009 }
9010
9011 # Not strictly true on aarch64, but we have agreed that we will
9012 # consider any function that pushes SP more than 3kbytes into
9013 # the guard page as broken. This essentially means that we can
9014 # consider the aarch64 as having a caller implicit probe at
9015 # *(sp + 1k).
9016 if { [istarget aarch64*-*-*] } {
9017 return 1;
9018 }
9019
9020 return 0
9021 }
9022
9023 # Targets that potentially realign the stack pointer often cause residual
9024 # stack allocations and make it difficult to elimination loops or residual
9025 # allocations for dynamic stack allocations
9026 proc check_effective_target_callee_realigns_stack { } {
9027 if { [istarget x86_64-*-*] || [istarget i?86-*-*] } {
9028 return 1
9029 }
9030 return 0
9031 }
9032
9033 # Return 1 if CET instructions can be compiled.
9034 proc check_effective_target_cet { } {
9035 if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
9036 return 0
9037 }
9038 return [check_no_compiler_messages cet object {
9039 void foo (void)
9040 {
9041 asm ("setssbsy");
9042 }
9043 } "-O2" ]
9044 }
9045
9046 # Return 1 if target supports floating point "infinite"
9047 proc check_effective_target_inf { } {
9048 return [check_no_compiler_messages supports_inf assembly {
9049 const double pinf = __builtin_inf ();
9050 }]
9051 }