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