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