c48138daa5dacbcbba222bc0313269c030b8f5ce
[gcc.git] / gcc / testsuite / lib / target-supports.exp
1 # Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # gcc-patches@gcc.gnu.org
20
21 # This file defines procs for determining features supported by the target.
22
23 # Try to compile some code and return the messages printed by the compiler,
24 # and optionally the contents for assembly files. Either a string or
25 # a list of two strings are returned, depending on WANT_OUTPUT.
26 #
27 # BASENAME is a basename to use for temporary files.
28 # WANT_OUTPUT is a flag which is 0 to request returning just the
29 # compiler messages, or 1 to return the messages and the contents
30 # of the assembly file. TYPE should be "assembly" if WANT_OUTPUT
31 # is set.
32 # TYPE is the type of compilation to perform (see target_compile).
33 # CONTENTS gives the contents of the input file.
34 # The rest is optional:
35 # OPTIONS: additional compiler options to use.
36 proc get_compiler_messages {basename want_output type contents args} {
37 global tool
38
39 if { [llength $args] > 0 } {
40 set options [list "additional_flags=[lindex $args 0]"]
41 } else {
42 set options ""
43 }
44
45 set src ${basename}[pid].c
46 switch $type {
47 assembly { set output ${basename}[pid].s }
48 object { set output ${basename}[pid].o }
49 }
50 set f [open $src "w"]
51 puts $f $contents
52 close $f
53 set lines [${tool}_target_compile $src $output $type "$options"]
54 file delete $src
55
56 if { $want_output } {
57 if { $type != "assembly" } {
58 error "WANT_OUTPUT can only be used with assembly output"
59 } elseif { ![string match "" $lines] } {
60 # An error occurred.
61 set result [list $lines ""]
62 } else {
63 set text ""
64 set chan [open "$output"]
65 while {[gets $chan line] >= 0} {
66 append text "$line\n"
67 }
68 close $chan
69 set result [list $lines $text]
70 }
71 } else {
72 set result $lines
73 }
74
75 remote_file build delete $output
76 return $result
77 }
78
79 proc current_target_name { } {
80 global target_info
81 if [info exists target_info(target,name)] {
82 set answer $target_info(target,name)
83 } else {
84 set answer ""
85 }
86 return $answer
87 }
88
89 # Implement an effective-target check for property PROP by invoking
90 # the compiler and seeing if it prints any messages. Assume that the
91 # property holds if the compiler doesn't print anything. The other
92 # arguments are as for get_compiler_messages, starting with TYPE.
93 proc check_no_compiler_messages {prop args} {
94 global et_cache
95
96 set target [current_target_name]
97 if {![info exists et_cache($prop,target)]
98 || $et_cache($prop,target) != $target} {
99 verbose "check_no_compiler_messages $prop: compiling source for $target" 2
100 set et_cache($prop,target) $target
101 set et_cache($prop,value) \
102 [string match "" [eval get_compiler_messages $prop 0 $args]]
103 }
104 set value $et_cache($prop,value)
105 verbose "check_no_compiler_messages $prop: returning $value for $target" 2
106 return $value
107 }
108
109 # Similar to check_no_compiler_messages, but also verify that the regular
110 # expression PATTERN matches the compiler's output.
111 proc check_no_messages_and_pattern {prop pattern args} {
112 global et_cache
113
114 set target [current_target_name]
115 if {![info exists et_cache($prop,target)]
116 || $et_cache($prop,target) != $target} {
117 verbose "check_no_messages_and_pattern $prop: compiling source for $target" 2
118 set et_cache($prop,target) $target
119 set results [eval get_compiler_messages $prop 1 $args]
120 set et_cache($prop,value) \
121 [expr [string match "" [lindex $results 0]] \
122 && [regexp $pattern [lindex $results 1]]]
123 }
124 set value $et_cache($prop,value)
125 verbose "check_no_messages_and_pattern $prop: returning $value for $target" 2
126 return $value
127 }
128
129 ###############################
130 # proc check_weak_available { }
131 ###############################
132
133 # weak symbols are only supported in some configs/object formats
134 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
135
136 proc check_weak_available { } {
137 global target_triplet
138 global target_cpu
139
140 # All mips targets should support it
141
142 if { [ string first "mips" $target_cpu ] >= 0 } {
143 return 1
144 }
145
146 # All solaris2 targets should support it
147
148 if { [regexp ".*-solaris2.*" $target_triplet] } {
149 return 1
150 }
151
152 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
153
154 if { [regexp "alpha.*osf.*" $target_triplet] } {
155 return 1
156 }
157
158 # Windows targets Cygwin and MingW32 support it
159
160 if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
161 return 1
162 }
163
164 # HP-UX 10.X doesn't support it
165
166 if { [istarget "hppa*-*-hpux10*"] } {
167 return 0
168 }
169
170 # ELF and ECOFF support it. a.out does with gas/gld but may also with
171 # other linkers, so we should try it
172
173 set objformat [gcc_target_object_format]
174
175 switch $objformat {
176 elf { return 1 }
177 ecoff { return 1 }
178 a.out { return 1 }
179 mach-o { return 1 }
180 som { return 1 }
181 unknown { return -1 }
182 default { return 0 }
183 }
184 }
185
186 ###############################
187 # proc check_visibility_available { what_kind }
188 ###############################
189
190 # The visibility attribute is only support in some object formats
191 # This proc returns 1 if it is supported, 0 if not.
192 # The argument is the kind of visibility, default/protected/hidden/internal.
193
194 proc check_visibility_available { what_kind } {
195 global tool
196 global target_triplet
197
198 # On NetWare, support makes no sense.
199 if { [istarget *-*-netware*] } {
200 return 0
201 }
202
203 if [string match "" $what_kind] { set what_kind "hidden" }
204
205 return [check_no_compiler_messages visibility_available_$what_kind object "
206 void f() __attribute__((visibility(\"$what_kind\")));
207 void f() {}
208 "]
209 }
210
211 ###############################
212 # proc check_alias_available { }
213 ###############################
214
215 # Determine if the target toolchain supports the alias attribute.
216
217 # Returns 2 if the target supports aliases. Returns 1 if the target
218 # only supports weak aliased. Returns 0 if the target does not
219 # support aliases at all. Returns -1 if support for aliases could not
220 # be determined.
221
222 proc check_alias_available { } {
223 global alias_available_saved
224 global tool
225
226 if [info exists alias_available_saved] {
227 verbose "check_alias_available returning saved $alias_available_saved" 2
228 } else {
229 set src alias[pid].c
230 set obj alias[pid].o
231 verbose "check_alias_available compiling testfile $src" 2
232 set f [open $src "w"]
233 # Compile a small test program. The definition of "g" is
234 # necessary to keep the Solaris assembler from complaining
235 # about the program.
236 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
237 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
238 close $f
239 set lines [${tool}_target_compile $src $obj object ""]
240 file delete $src
241 remote_file build delete $obj
242
243 if [string match "" $lines] then {
244 # No error messages, everything is OK.
245 set alias_available_saved 2
246 } else {
247 if [regexp "alias definitions not supported" $lines] {
248 verbose "check_alias_available target does not support aliases" 2
249
250 set objformat [gcc_target_object_format]
251
252 if { $objformat == "elf" } {
253 verbose "check_alias_available but target uses ELF format, so it ought to" 2
254 set alias_available_saved -1
255 } else {
256 set alias_available_saved 0
257 }
258 } else {
259 if [regexp "only weak aliases are supported" $lines] {
260 verbose "check_alias_available target supports only weak aliases" 2
261 set alias_available_saved 1
262 } else {
263 set alias_available_saved -1
264 }
265 }
266 }
267
268 verbose "check_alias_available returning $alias_available_saved" 2
269 }
270
271 return $alias_available_saved
272 }
273
274 # Returns true if --gc-sections is supported on the target.
275
276 proc check_gc_sections_available { } {
277 global gc_sections_available_saved
278 global tool
279
280 if {![info exists gc_sections_available_saved]} {
281 # Some targets don't support gc-sections despite whatever's
282 # advertised by ld's options.
283 if { [istarget alpha*-*-*]
284 || [istarget ia64-*-*] } {
285 set gc_sections_available_saved 0
286 return 0
287 }
288
289 # elf2flt uses -q (--emit-relocs), which is incompatible with
290 # --gc-sections.
291 if { [board_info target exists ldflags]
292 && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
293 set gc_sections_available_saved 0
294 return 0
295 }
296
297 # VxWorks kernel modules are relocatable objects linked with -r,
298 # while RTP executables are linked with -q (--emit-relocs).
299 # Both of these options are incompatible with --gc-sections.
300 if { [istarget *-*-vxworks*] } {
301 set gc_sections_available_saved 0
302 return 0
303 }
304
305 # Check if the ld used by gcc supports --gc-sections.
306 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
307 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
308 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
309 set ld_output [remote_exec host "$gcc_ld" "--help"]
310 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
311 set gc_sections_available_saved 1
312 } else {
313 set gc_sections_available_saved 0
314 }
315 }
316 return $gc_sections_available_saved
317 }
318
319 # Return true if profiling is supported on the target.
320
321 proc check_profiling_available { test_what } {
322 global profiling_available_saved
323
324 verbose "Profiling argument is <$test_what>" 1
325
326 # These conditions depend on the argument so examine them before
327 # looking at the cache variable.
328
329 # Support for -p on solaris2 relies on mcrt1.o which comes with the
330 # vendor compiler. We cannot reliably predict the directory where the
331 # vendor compiler (and thus mcrt1.o) is installed so we can't
332 # necessarily find mcrt1.o even if we have it.
333 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
334 return 0
335 }
336
337 # Support for -p on irix relies on libprof1.a which doesn't appear to
338 # exist on any irix6 system currently posting testsuite results.
339 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
340 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
341 if { [istarget mips*-*-irix*]
342 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
343 return 0
344 }
345
346 # At present, there is no profiling support on NetWare.
347 if { [istarget *-*-netware*] } {
348 return 0
349 }
350
351 # uClibc does not have gcrt1.o.
352 if { [check_effective_target_uclibc]
353 && ([lindex $test_what 1] == "-p"
354 || [lindex $test_what 1] == "-pg") } {
355 return 0
356 }
357
358 # Now examine the cache variable.
359 if {![info exists profiling_available_saved]} {
360 # Some targets don't have any implementation of __bb_init_func or are
361 # missing other needed machinery.
362 if { [istarget mmix-*-*]
363 || [istarget arm*-*-eabi*]
364 || [istarget arm*-*-elf]
365 || [istarget arm*-*-symbianelf*]
366 || [istarget bfin-*-*]
367 || [istarget powerpc-*-eabi*]
368 || [istarget strongarm*-*-elf]
369 || [istarget xscale*-*-elf]
370 || [istarget cris-*-*]
371 || [istarget h8300-*-*]
372 || [istarget m32c-*-elf]
373 || [istarget m68k-*-elf]
374 || [istarget m68k-*-uclinux*]
375 || [istarget mips*-*-elf]
376 || [istarget xtensa-*-elf]
377 || [istarget *-*-vxworks*]
378 || [istarget *-*-windiss] } {
379 set profiling_available_saved 0
380 } else {
381 set profiling_available_saved 1
382 }
383 }
384
385 return $profiling_available_saved
386 }
387
388 # Return 1 if target has packed layout of structure members by
389 # default, 0 otherwise. Note that this is slightly different than
390 # whether the target has "natural alignment": both attributes may be
391 # false.
392
393 proc check_effective_target_default_packed { } {
394 return [check_no_compiler_messages default_packed assembly {
395 struct x { char a; long b; } c;
396 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
397 }]
398 }
399
400 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
401 # documentation, where the test also comes from.
402
403 proc check_effective_target_pcc_bitfield_type_matters { } {
404 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
405 # bitfields, but let's stick to the example code from the docs.
406 return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
407 struct foo1 { char x; char :0; char y; };
408 struct foo2 { char x; int :0; char y; };
409 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
410 }]
411 }
412
413 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
414 #
415 # This won't change for different subtargets so cache the result.
416
417 proc check_effective_target_tls {} {
418 global et_tls_saved
419 global tool
420
421 if [info exists et_tls_saved] {
422 verbose "check_effective_target_tls: using cached result" 2
423 } else {
424 set et_tls_saved 1
425
426 set src tls[pid].c
427 set asm tls[pid].S
428 verbose "check_effective_target_tls: compiling testfile $src" 2
429 set f [open $src "w"]
430 # Compile a small test program.
431 puts $f "__thread int i;\n"
432 close $f
433
434 # Test for thread-local data supported by the platform.
435 set comp_output [${tool}_target_compile $src $asm assembly ""]
436 file delete $src
437 if { [string match "*not supported*" $comp_output] } {
438 set et_tls_saved 0
439 } else {
440 set fd [open $asm r]
441 set text [read $fd]
442 close $fd
443 if { [string match "*emutls*" $text]} {
444 set et_tls_saved 0
445 } else {
446 set et_tls_saved 1
447 }
448 }
449 remove-build-file $asm
450 }
451 verbose "check_effective_target_tls: returning $et_tls_saved" 2
452 return $et_tls_saved
453 }
454
455 # Return 1 if TLS executables can run correctly, 0 otherwise.
456 #
457 # This won't change for different subtargets so cache the result.
458
459 proc check_effective_target_tls_runtime {} {
460 global et_tls_runtime_saved
461 global tool
462
463 if [info exists et_tls_runtime_saved] {
464 verbose "check_effective_target_tls_runtime: using cached result" 2
465 } else {
466 set et_tls_runtime_saved 0
467
468 set src tls_runtime[pid].c
469 set exe tls_runtime[pid].x
470 verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
471 set f [open $src "w"]
472 # Compile a small test program.
473 puts $f "__thread int thr = 0;\n"
474 puts $f "int main(void)\n {\n return thr;\n}"
475 close $f
476
477 set comp_output \
478 [${tool}_target_compile $src $exe executable ""]
479 file delete $src
480
481 if [string match "" $comp_output] then {
482 # No error messages, everything is OK.
483
484 set result [remote_load target "./$exe" "" ""]
485 set status [lindex $result 0]
486 remote_file build delete $exe
487
488 verbose "check_effective_target_tls_runtime status is <$status>" 2
489
490 if { $status == "pass" } {
491 set et_tls_runtime_saved 1
492 }
493
494 verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
495 }
496 }
497
498 return $et_tls_runtime_saved
499 }
500
501 # Return 1 if compilation with -fopenmp is error-free for trivial
502 # code, 0 otherwise.
503
504 proc check_effective_target_fopenmp {} {
505 return [check_no_compiler_messages fopenmp object {
506 void foo (void) { }
507 } "-fopenmp"]
508 }
509
510 # Return 1 if the target supports -fstack-protector
511 proc check_effective_target_fstack_protector {} {
512 global tool
513 set result ""
514
515 set src stack_prot[pid].c
516 set exe stack_prot[pid].x
517
518 verbose "check_effective_target_fstack_protector compiling testfile $src" 2
519
520 set f [open $src "w"]
521 # Compile a small test program.
522 puts $f "int main (void)\n { return 0; }\n"
523 close $f
524
525 set opts "additional_flags=-fstack-protector"
526 set lines [${tool}_target_compile $src $exe executable "$opts" ]
527 file delete $src
528
529 if [string match "" $lines] then {
530 # No error messages, everything is OK.
531 set result [${tool}_load "./$exe" "" ""]
532 set status [lindex $result 0]
533 remote_file build delete $exe
534 verbose "check_iconv_available status is <$status>" 2
535
536 if { $status == "pass" } then {
537 return 1
538 }
539 }
540 return 0
541 }
542
543 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
544 # for trivial code, 0 otherwise.
545
546 proc check_effective_target_freorder {} {
547 return [check_no_compiler_messages freorder object {
548 void foo (void) { }
549 } "-freorder-blocks-and-partition"]
550 }
551
552 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
553 # emitted, 0 otherwise. Whether a shared library can actually be built is
554 # out of scope for this test.
555
556 proc check_effective_target_fpic { } {
557 # Note that M68K has a multilib that supports -fpic but not
558 # -fPIC, so we need to check both. We test with a program that
559 # requires GOT references.
560 foreach arg {fpic fPIC} {
561 if [check_no_compiler_messages $arg object {
562 extern int foo (void); extern int bar;
563 int baz (void) { return foo () + bar; }
564 } "-$arg"] {
565 return 1
566 }
567 }
568 return 0
569 }
570
571 # Return true if the target supports -mpaired-single (as used on MIPS).
572
573 proc check_effective_target_mpaired_single { } {
574 return [check_no_compiler_messages mpaired_single object {
575 void foo (void) { }
576 } "-mpaired-single"]
577 }
578
579 # Return 1 if the current multilib does not generate PIC by default.
580
581 proc check_effective_target_nonpic { } {
582 return [check_no_compiler_messages nonpic assembly {
583 #if __PIC__
584 #error FOO
585 #endif
586 }]
587 }
588
589 # Return 1 if the target does not use a status wrapper.
590
591 proc check_effective_target_unwrapped { } {
592 if { [target_info needs_status_wrapper] != "" \
593 && [target_info needs_status_wrapper] != "0" } {
594 return 0
595 }
596 return 1
597 }
598
599 # Return true if iconv is supported on the target. In particular IBM1047.
600
601 proc check_iconv_available { test_what } {
602 global tool
603 global libiconv
604
605 set result ""
606
607 set src iconv[pid].c
608 set exe iconv[pid].x
609 verbose "check_iconv_available compiling testfile $src" 2
610 set f [open $src "w"]
611 # Compile a small test program.
612 puts $f "#include <iconv.h>\n"
613 puts $f "int main (void)\n {\n iconv_t cd; \n"
614 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
615 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
616 puts $f "return 0;\n}"
617 close $f
618
619 # If the tool configuration file has not set libiconv, try "-liconv"
620 if { ![info exists libiconv] } {
621 set libiconv "-liconv"
622 }
623 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
624 file delete $src
625
626 if [string match "" $lines] then {
627 # No error messages, everything is OK.
628
629 set result [${tool}_load "./$exe" "" ""]
630 set status [lindex $result 0]
631 remote_file build delete $exe
632
633 verbose "check_iconv_available status is <$status>" 2
634
635 if { $status == "pass" } then {
636 return 1
637 }
638 }
639
640 return 0
641 }
642
643 # Return true if named sections are supported on this target.
644
645 proc check_named_sections_available { } {
646 return [check_no_compiler_messages named_sections assembly {
647 int __attribute__ ((section("whatever"))) foo;
648 }]
649 }
650
651 # Return 1 if the target supports Fortran real kinds larger than real(8),
652 # 0 otherwise.
653 #
654 # When the target name changes, replace the cached result.
655
656 proc check_effective_target_fortran_large_real { } {
657 global et_fortran_large_real_saved
658 global et_fortran_large_real_target_name
659 global tool
660
661 if { ![info exists et_fortran_large_real_target_name] } {
662 set et_fortran_large_real_target_name ""
663 }
664
665 # If the target has changed since we set the cached value, clear it.
666 set current_target [current_target_name]
667 if { $current_target != $et_fortran_large_real_target_name } {
668 verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
669 set et_fortran_large_real_target_name $current_target
670 if [info exists et_fortran_large_real_saved] {
671 verbose "check_effective_target_fortran_large_real: removing cached result" 2
672 unset et_fortran_large_real_saved
673 }
674 }
675
676 if [info exists et_fortran_large_real_saved] {
677 verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
678 } else {
679 set et_fortran_large_real_saved 0
680
681 # Set up, compile, and execute a test program using large real
682 # kinds. Include the current process ID in the file names to
683 # prevent conflicts with invocations for multiple testsuites.
684 set src real[pid].f90
685 set exe real[pid].x
686
687 set f [open $src "w"]
688 puts $f "integer,parameter :: k = &"
689 puts $f " selected_real_kind (precision (0.0_8) + 1)"
690 puts $f "real(kind=k) :: x"
691 puts $f "x = cos (x);"
692 puts $f "end"
693 close $f
694
695 verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
696 set lines [${tool}_target_compile $src $exe executable ""]
697 file delete $src
698
699 if [string match "" $lines] then {
700 # No error message, compilation succeeded.
701 remote_file build delete $exe
702 set et_fortran_large_real_saved 1
703 }
704 }
705
706 return $et_fortran_large_real_saved
707 }
708
709 # Return 1 if the target supports Fortran integer kinds larger than
710 # integer(8), 0 otherwise.
711 #
712 # When the target name changes, replace the cached result.
713
714 proc check_effective_target_fortran_large_int { } {
715 global et_fortran_large_int_saved
716 global et_fortran_large_int_target_name
717 global tool
718
719 if { ![info exists et_fortran_large_int_target_name] } {
720 set et_fortran_large_int_target_name ""
721 }
722
723 # If the target has changed since we set the cached value, clear it.
724 set current_target [current_target_name]
725 if { $current_target != $et_fortran_large_int_target_name } {
726 verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
727 set et_fortran_large_int_target_name $current_target
728 if [info exists et_fortran_large_int_saved] {
729 verbose "check_effective_target_fortran_large_int: removing cached result" 2
730 unset et_fortran_large_int_saved
731 }
732 }
733
734 if [info exists et_fortran_large_int_saved] {
735 verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
736 } else {
737 set et_fortran_large_int_saved 0
738
739 # Set up, compile, and execute a test program using large integer
740 # kinds. Include the current process ID in the file names to
741 # prevent conflicts with invocations for multiple testsuites.
742 set src int[pid].f90
743 set exe int[pid].x
744
745 set f [open $src "w"]
746 puts $f "integer,parameter :: k = &"
747 puts $f " selected_int_kind (range (0_8) + 1)"
748 puts $f "integer(kind=k) :: i"
749 puts $f "end"
750 close $f
751
752 verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
753 set lines [${tool}_target_compile $src $exe executable ""]
754 file delete $src
755
756 if [string match "" $lines] then {
757 # No error message, compilation succeeded.
758 remote_file build delete $exe
759 set et_fortran_large_int_saved 1
760 }
761 }
762
763 return $et_fortran_large_int_saved
764 }
765
766 # Return 1 if we can statically link libgfortran, 0 otherwise.
767 #
768 # When the target name changes, replace the cached result.
769
770 proc check_effective_target_static_libgfortran { } {
771 global et_static_libgfortran
772 global et_static_libgfortran_target_name
773 global tool
774
775 if { ![info exists et_static_libgfortran_target_name] } {
776 set et_static_libgfortran_target_name ""
777 }
778
779 # If the target has changed since we set the cached value, clear it.
780 set current_target [current_target_name]
781 if { $current_target != $et_static_libgfortran_target_name } {
782 verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
783 set et_static_libgfortran_target_name $current_target
784 if [info exists et_static_libgfortran_saved] {
785 verbose "check_effective_target_static_libgfortran: removing cached result" 2
786 unset et_static_libgfortran_saved
787 }
788 }
789
790 if [info exists et_static_libgfortran_saved] {
791 verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
792 } else {
793 set et_static_libgfortran_saved 0
794
795 # Set up, compile, and execute a test program using static linking.
796 # Include the current process ID in the file names to prevent
797 # conflicts with invocations for multiple testsuites.
798 set opts "additional_flags=-static"
799 set src static[pid].f
800 set exe static[pid].x
801
802 set f [open $src "w"]
803 puts $f " print *, 'test'"
804 puts $f " end"
805 close $f
806
807 verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
808 set lines [${tool}_target_compile $src $exe executable "$opts"]
809 file delete $src
810
811 if [string match "" $lines] then {
812 # No error message, compilation succeeded.
813 remote_file build delete $exe
814 set et_static_libgfortran_saved 1
815 }
816 }
817
818 return $et_static_libgfortran_saved
819 }
820
821 # Return 1 if the target supports executing AltiVec instructions, 0
822 # otherwise. Cache the result.
823
824 proc check_vmx_hw_available { } {
825 global vmx_hw_available_saved
826 global tool
827
828 if [info exists vmx_hw_available_saved] {
829 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
830 } else {
831 set vmx_hw_available_saved 0
832
833 # Some simulators are known to not support VMX instructions.
834 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
835 verbose "check_hw_available returning 0" 2
836 return $vmx_hw_available_saved
837 }
838
839 # Set up, compile, and execute a test program containing VMX
840 # instructions. Include the current process ID in the file
841 # names to prevent conflicts with invocations for multiple
842 # testsuites.
843 set src vmx[pid].c
844 set exe vmx[pid].x
845
846 set f [open $src "w"]
847 puts $f "int main() {"
848 puts $f "#ifdef __MACH__"
849 puts $f " asm volatile (\"vor v0,v0,v0\");"
850 puts $f "#else"
851 puts $f " asm volatile (\"vor 0,0,0\");"
852 puts $f "#endif"
853 puts $f " return 0; }"
854 close $f
855
856 # Most targets don't require special flags for this test case, but
857 # Darwin does.
858 if [istarget *-*-darwin*] {
859 set opts "additional_flags=-maltivec"
860 } else {
861 set opts ""
862 }
863
864 verbose "check_vmx_hw_available compiling testfile $src" 2
865 set lines [${tool}_target_compile $src $exe executable "$opts"]
866 file delete $src
867
868 if [string match "" $lines] then {
869 # No error message, compilation succeeded.
870 set result [${tool}_load "./$exe" "" ""]
871 set status [lindex $result 0]
872 remote_file build delete $exe
873 verbose "check_vmx_hw_available testfile status is <$status>" 2
874
875 if { $status == "pass" } then {
876 set vmx_hw_available_saved 1
877 }
878 } else {
879 verbose "check_vmx_hw_availalble testfile compilation failed" 2
880 }
881 }
882
883 return $vmx_hw_available_saved
884 }
885
886 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
887 # complex float arguments. This affects gfortran tests that call cabsf
888 # in libm built by an earlier compiler. Return 1 if libm uses the same
889 # argument passing as the compiler under test, 0 otherwise.
890 #
891 # When the target name changes, replace the cached result.
892
893 proc check_effective_target_broken_cplxf_arg { } {
894 global et_broken_cplxf_arg_saved
895 global et_broken_cplxf_arg_target_name
896 global tool
897
898 # Skip the work for targets known not to be affected.
899 if { ![istarget powerpc64-*-linux*] } {
900 return 0
901 } elseif { [is-effective-target ilp32] } {
902 return 0
903 }
904
905 if { ![info exists et_broken_cplxf_arg_target_name] } {
906 set et_broken_cplxf_arg_target_name ""
907 }
908
909 # If the target has changed since we set the cached value, clear it.
910 set current_target [current_target_name]
911 if { $current_target != $et_broken_cplxf_arg_target_name } {
912 verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
913 set et_broken_cplxf_arg_target_name $current_target
914 if [info exists et_broken_cplxf_arg_saved] {
915 verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
916 unset et_broken_cplxf_arg_saved
917 }
918 }
919
920 if [info exists et_broken_cplxf_arg_saved] {
921 verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
922 } else {
923 set et_broken_cplxf_arg_saved 0
924 # This is only known to affect one target.
925 if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
926 set et_broken_cplxf_arg_saved 0
927 verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
928 return $et_broken_cplxf_arg_saved
929 }
930
931 # Set up, compile, and execute a C test program that calls cabsf.
932 set src cabsf[pid].c
933 set exe cabsf[pid].x
934
935 set f [open $src "w"]
936 puts $f "#include <complex.h>"
937 puts $f "extern void abort (void);"
938 puts $f "float fabsf (float);"
939 puts $f "float cabsf (_Complex float);"
940 puts $f "int main ()"
941 puts $f "{"
942 puts $f " _Complex float cf;"
943 puts $f " float f;"
944 puts $f " cf = 3 + 4.0fi;"
945 puts $f " f = cabsf (cf);"
946 puts $f " if (fabsf (f - 5.0) > 0.0001) abort ();"
947 puts $f " return 0;"
948 puts $f "}"
949 close $f
950
951 set lines [${tool}_target_compile $src $exe executable "-lm"]
952 file delete $src
953
954 if [string match "" $lines] {
955 # No error message, compilation succeeded.
956 set result [${tool}_load "./$exe" "" ""]
957 set status [lindex $result 0]
958 remote_file build delete $exe
959
960 verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
961
962 if { $status != "pass" } {
963 set et_broken_cplxf_arg_saved 1
964 }
965 } else {
966 verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
967 }
968 }
969 return $et_broken_cplxf_arg_saved
970 }
971
972 proc check_alpha_max_hw_available { } {
973 global alpha_max_hw_available_saved
974 global tool
975
976 if [info exists alpha_max_hw_available_saved] {
977 verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
978 } else {
979 set alpha_max_hw_available_saved 0
980
981 # Set up, compile, and execute a test program probing bit 8 of the
982 # architecture mask, which indicates presence of MAX instructions.
983 set src max[pid].c
984 set exe max[pid].x
985
986 set f [open $src "w"]
987 puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
988 close $f
989
990 verbose "check_alpha_max_hw_available compiling testfile $src" 2
991 set lines [${tool}_target_compile $src $exe executable ""]
992 file delete $src
993
994 if [string match "" $lines] then {
995 # No error message, compilation succeeded.
996 set result [${tool}_load "./$exe" "" ""]
997 set status [lindex $result 0]
998 remote_file build delete $exe
999 verbose "check_alpha_max_hw_available testfile status is <$status>" 2
1000
1001 if { $status == "pass" } then {
1002 set alpha_max_hw_available_saved 1
1003 }
1004 } else {
1005 verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
1006 }
1007 }
1008
1009 return $alpha_max_hw_available_saved
1010 }
1011
1012 # Returns true iff the FUNCTION is available on the target system.
1013 # (This is essentially a Tcl implementation of Autoconf's
1014 # AC_CHECK_FUNC.)
1015
1016 proc check_function_available { function } {
1017 set var "${function}_available_saved"
1018 global $var
1019 global tool
1020
1021 if {![info exists $var]} {
1022 # Assume it exists.
1023 set $var 1
1024 # Check to make sure.
1025 set src "function[pid].c"
1026 set exe "function[pid].exe"
1027
1028 set f [open $src "w"]
1029 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
1030 puts $f "char $function ();\n"
1031 puts $f "int main () { $function (); }"
1032 close $f
1033
1034 set lines [${tool}_target_compile $src $exe executable ""]
1035 file delete $src
1036 file delete $exe
1037
1038 if {![string match "" $lines]} then {
1039 set $var 0
1040 verbose -log "$function is not available"
1041 } else {
1042 verbose -log "$function is available"
1043 }
1044 }
1045
1046 eval return \$$var
1047 }
1048
1049 # Returns true iff "fork" is available on the target system.
1050
1051 proc check_fork_available {} {
1052 return [check_function_available "fork"]
1053 }
1054
1055 # Returns true iff "mkfifo" is available on the target system.
1056
1057 proc check_mkfifo_available {} {
1058 if {[istarget *-*-cygwin*]} {
1059 # Cygwin has mkfifo, but support is incomplete.
1060 return 0
1061 }
1062
1063 return [check_function_available "mkfifo"]
1064 }
1065
1066 # Returns true iff "__cxa_atexit" is used on the target system.
1067
1068 proc check_cxa_atexit_available { } {
1069 global et_cxa_atexit
1070 global et_cxa_atexit_target_name
1071 global tool
1072
1073 if { ![info exists et_cxa_atexit_target_name] } {
1074 set et_cxa_atexit_target_name ""
1075 }
1076
1077 # If the target has changed since we set the cached value, clear it.
1078 set current_target [current_target_name]
1079 if { $current_target != $et_cxa_atexit_target_name } {
1080 verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
1081 set et_cxa_atexit_target_name $current_target
1082 if [info exists et_cxa_atexit] {
1083 verbose "check_cxa_atexit_available: removing cached result" 2
1084 unset et_cxa_atexit
1085 }
1086 }
1087
1088 if [info exists et_cxa_atexit] {
1089 verbose "check_cxa_atexit_available: using cached result" 2
1090 } elseif { [istarget "hppa*-*-hpux10*"] } {
1091 # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1092 set et_cxa_atexit 0
1093 } else {
1094 set et_cxa_atexit 0
1095
1096 # Set up, compile, and execute a C++ test program that depends
1097 # on correct ordering of static object destructors. This is
1098 # indicative of the presence and use of __cxa_atexit.
1099 set src cxaatexit[pid].cc
1100 set exe cxaatexit[pid].x
1101
1102 set f [open $src "w"]
1103 puts $f "#include <stdlib.h>"
1104 puts $f "static unsigned int count;"
1105 puts $f "struct X"
1106 puts $f "{"
1107 puts $f " X() { count = 1; }"
1108 puts $f " ~X()"
1109 puts $f " {"
1110 puts $f " if (count != 3)"
1111 puts $f " exit(1);"
1112 puts $f " count = 4;"
1113 puts $f " }"
1114 puts $f "};"
1115 puts $f "void f()"
1116 puts $f "{"
1117 puts $f " static X x;"
1118 puts $f "}"
1119 puts $f "struct Y"
1120 puts $f "{"
1121 puts $f " Y() { f(); count = 2; }"
1122 puts $f " ~Y()"
1123 puts $f " {"
1124 puts $f " if (count != 2)"
1125 puts $f " exit(1);"
1126 puts $f " count = 3;"
1127 puts $f " }"
1128 puts $f "};"
1129 puts $f "Y y;"
1130 puts $f "int main()"
1131 puts $f "{ return 0; }"
1132 close $f
1133
1134 set lines [${tool}_target_compile $src $exe executable ""]
1135 file delete $src
1136
1137 if [string match "" $lines] {
1138 # No error message, compilation succeeded.
1139 set result [${tool}_load "./$exe" "" ""]
1140 set status [lindex $result 0]
1141 remote_file build delete $exe
1142
1143 verbose "check_cxa_atexit_available: status is <$status>" 2
1144
1145 if { $status == "pass" } {
1146 set et_cxa_atexit 1
1147 }
1148 } else {
1149 verbose "check_cxa_atexit_available: compilation failed" 2
1150 }
1151 }
1152 return $et_cxa_atexit
1153 }
1154
1155
1156 # Return 1 if we're generating 32-bit code using default options, 0
1157 # otherwise.
1158
1159 proc check_effective_target_ilp32 { } {
1160 return [check_no_compiler_messages ilp32 object {
1161 int dummy[sizeof (int) == 4
1162 && sizeof (void *) == 4
1163 && sizeof (long) == 4 ? 1 : -1];
1164 }]
1165 }
1166
1167 # Return 1 if we're generating 32-bit or larger integers using default
1168 # options, 0 otherwise.
1169
1170 proc check_effective_target_int32plus { } {
1171 return [check_no_compiler_messages int32plus object {
1172 int dummy[sizeof (int) >= 4 ? 1 : -1];
1173 }]
1174 }
1175
1176 # Return 1 if we're generating 32-bit or larger pointers using default
1177 # options, 0 otherwise.
1178
1179 proc check_effective_target_ptr32plus { } {
1180 return [check_no_compiler_messages ptr32plus object {
1181 int dummy[sizeof (void *) >= 4 ? 1 : -1];
1182 }]
1183 }
1184
1185 # Return 1 if we support 32-bit or larger array and structure sizes
1186 # using default options, 0 otherwise.
1187
1188 proc check_effective_target_size32plus { } {
1189 return [check_no_compiler_messages size32plus object {
1190 char dummy[65537];
1191 }]
1192 }
1193
1194 # Returns 1 if we're generating 16-bit or smaller integers with the
1195 # default options, 0 otherwise.
1196
1197 proc check_effective_target_int16 { } {
1198 return [check_no_compiler_messages int16 object {
1199 int dummy[sizeof (int) < 4 ? 1 : -1];
1200 }]
1201 }
1202
1203 # Return 1 if we're generating 64-bit code using default options, 0
1204 # otherwise.
1205
1206 proc check_effective_target_lp64 { } {
1207 return [check_no_compiler_messages lp64 object {
1208 int dummy[sizeof (int) == 4
1209 && sizeof (void *) == 8
1210 && sizeof (long) == 8 ? 1 : -1];
1211 }]
1212 }
1213
1214 # Return 1 if the target supports long double larger than double,
1215 # 0 otherwise.
1216
1217 proc check_effective_target_large_long_double { } {
1218 return [check_no_compiler_messages large_long_double object {
1219 int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1220 }]
1221 }
1222
1223
1224 # Return 1 if the target supports compiling decimal floating point,
1225 # 0 otherwise.
1226
1227 proc check_effective_target_dfp_nocache { } {
1228 verbose "check_effective_target_dfp_nocache: compiling source" 2
1229 set ret [string match "" [get_compiler_messages dfp 0 object {
1230 _Decimal32 x; _Decimal64 y; _Decimal128 z;
1231 }]]
1232 verbose "check_effective_target_dfp_nocache: returning $ret" 2
1233 return $ret
1234 }
1235
1236 proc check_effective_target_dfprt_nocache { } {
1237 global tool
1238
1239 set ret 0
1240
1241 verbose "check_effective_target_dfprt_nocache: compiling source" 2
1242 # Set up, compile, and execute a test program containing decimal
1243 # float operations.
1244 set src dfprt[pid].c
1245 set exe dfprt[pid].x
1246
1247 set f [open $src "w"]
1248 puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1249 puts $f "int main () { z = x + y; return 0; }"
1250 close $f
1251
1252 verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1253 set lines [${tool}_target_compile $src $exe executable ""]
1254 file delete $src
1255
1256 if [string match "" $lines] then {
1257 # No error message, compilation succeeded.
1258 set result [${tool}_load "./$exe" "" ""]
1259 set status [lindex $result 0]
1260 remote_file build delete $exe
1261 verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1262 if { $status == "pass" } then {
1263 set ret 1
1264 }
1265 }
1266 return $ret
1267 verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1268 }
1269
1270 # Return 1 if the target supports compiling Decimal Floating Point,
1271 # 0 otherwise.
1272 #
1273 # This won't change for different subtargets so cache the result.
1274
1275 proc check_effective_target_dfp { } {
1276 global et_dfp_saved
1277
1278 if [info exists et_dfp_saved] {
1279 verbose "check_effective_target_dfp: using cached result" 2
1280 } else {
1281 set et_dfp_saved [check_effective_target_dfp_nocache]
1282 }
1283 verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1284 return $et_dfp_saved
1285 }
1286
1287 # Return 1 if the target supports linking and executing Decimal Floating
1288 # Point, # 0 otherwise.
1289 #
1290 # This won't change for different subtargets so cache the result.
1291
1292 proc check_effective_target_dfprt { } {
1293 global et_dfprt_saved
1294 global tool
1295
1296 if [info exists et_dfprt_saved] {
1297 verbose "check_effective_target_dfprt: using cached result" 2
1298 } else {
1299 set et_dfprt_saved [check_effective_target_dfprt_nocache]
1300 }
1301 verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1302 return $et_dfprt_saved
1303 }
1304
1305 # Return 1 if the target needs a command line argument to enable a SIMD
1306 # instruction set.
1307
1308 proc check_effective_target_vect_cmdline_needed { } {
1309 global et_vect_cmdline_needed_saved
1310 global et_vect_cmdline_needed_target_name
1311
1312 if { ![info exists et_vect_cmdline_needed_target_name] } {
1313 set et_vect_cmdline_needed_target_name ""
1314 }
1315
1316 # If the target has changed since we set the cached value, clear it.
1317 set current_target [current_target_name]
1318 if { $current_target != $et_vect_cmdline_needed_target_name } {
1319 verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1320 set et_vect_cmdline_needed_target_name $current_target
1321 if { [info exists et_vect_cmdline_needed_saved] } {
1322 verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1323 unset et_vect_cmdline_needed_saved
1324 }
1325 }
1326
1327 if [info exists et_vect_cmdline_needed_saved] {
1328 verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1329 } else {
1330 set et_vect_cmdline_needed_saved 1
1331 if { [istarget ia64-*-*]
1332 || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1333 && [check_effective_target_lp64])
1334 || ([istarget powerpc*-*-*]
1335 && ([check_effective_target_powerpc_spe]
1336 || [check_effective_target_powerpc_altivec]))} {
1337 set et_vect_cmdline_needed_saved 0
1338 }
1339 }
1340
1341 verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1342 return $et_vect_cmdline_needed_saved
1343 }
1344
1345 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1346 #
1347 # This won't change for different subtargets so cache the result.
1348
1349 proc check_effective_target_vect_int { } {
1350 global et_vect_int_saved
1351
1352 if [info exists et_vect_int_saved] {
1353 verbose "check_effective_target_vect_int: using cached result" 2
1354 } else {
1355 set et_vect_int_saved 0
1356 if { [istarget i?86-*-*]
1357 || [istarget powerpc*-*-*]
1358 || [istarget spu-*-*]
1359 || [istarget x86_64-*-*]
1360 || [istarget sparc*-*-*]
1361 || [istarget alpha*-*-*]
1362 || [istarget ia64-*-*] } {
1363 set et_vect_int_saved 1
1364 }
1365 }
1366
1367 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1368 return $et_vect_int_saved
1369 }
1370
1371 # Return 1 if the target supports int->float conversion
1372 #
1373
1374 proc check_effective_target_vect_intfloat_cvt { } {
1375 global et_vect_intfloat_cvt_saved
1376
1377 if [info exists et_vect_intfloat_cvt_saved] {
1378 verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1379 } else {
1380 set et_vect_intfloat_cvt_saved 0
1381 if { [istarget i?86-*-*]
1382 || [istarget powerpc*-*-*]
1383 || [istarget x86_64-*-*] } {
1384 set et_vect_intfloat_cvt_saved 1
1385 }
1386 }
1387
1388 verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1389 return $et_vect_intfloat_cvt_saved
1390 }
1391
1392
1393 # Return 1 if the target supports float->int conversion
1394 #
1395
1396 proc check_effective_target_vect_floatint_cvt { } {
1397 global et_vect_floatint_cvt_saved
1398
1399 if [info exists et_vect_floatint_cvt_saved] {
1400 verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1401 } else {
1402 set et_vect_floatint_cvt_saved 0
1403 if { [istarget i?86-*-*]
1404 || [istarget x86_64-*-*] } {
1405 set et_vect_floatint_cvt_saved 1
1406 }
1407 }
1408
1409 verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1410 return $et_vect_floatint_cvt_saved
1411 }
1412
1413
1414 # Return 1 is this is an arm target using 32-bit instructions
1415 proc check_effective_target_arm32 { } {
1416 return [check_no_compiler_messages arm32 assembly {
1417 #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1418 #error FOO
1419 #endif
1420 }]
1421 }
1422
1423 # Return 1 if this is an ARM target supporting -mfpu=vfp
1424 # -mfloat-abi=softfp. Some multilibs may be incompatible with these
1425 # options.
1426
1427 proc check_effective_target_arm_vfp_ok { } {
1428 if { [check_effective_target_arm32] } {
1429 return [check_no_compiler_messages arm_vfp_ok object {
1430 int dummy;
1431 } "-mfpu=vfp -mfloat-abi=softfp"]
1432 } else {
1433 return 0
1434 }
1435 }
1436
1437 # Return 1 if this is an ARM target supporting -mfpu=neon
1438 # -mfloat-abi=softfp. Some multilibs may be incompatible with these
1439 # options.
1440
1441 proc check_effective_target_arm_neon_ok { } {
1442 if { [check_effective_target_arm32] } {
1443 return [check_no_compiler_messages arm_neon_ok object {
1444 int dummy;
1445 } "-mfpu=neon -mfloat-abi=softfp"]
1446 } else {
1447 return 0
1448 }
1449 }
1450
1451 # Return 1 if the target supports executing NEON instructions, 0
1452 # otherwise. Cache the result.
1453
1454 proc check_effective_target_arm_neon_hw { } {
1455 global arm_neon_hw_available_saved
1456 global tool
1457
1458 if [info exists arm_neon_hw_available_saved] {
1459 verbose "check_arm_neon_hw_available returning saved $arm_neon_hw_avail
1460 able_saved" 2
1461 } else {
1462 set arm_neon_hw_available_saved 0
1463
1464 # Set up, compile, and execute a test program containing NEON
1465 # instructions. Include the current process ID in the file
1466 # names to prevent conflicts with invocations for multiple
1467 # testsuites.
1468 set src neon[pid].c
1469 set exe neon[pid].x
1470
1471 set f [open $src "w"]
1472 puts $f "int main() {"
1473 puts $f " long long a = 0, b = 1;"
1474 puts $f " asm (\"vorr %P0, %P1, %P2\""
1475 puts $f " : \"=w\" (a)"
1476 puts $f " : \"0\" (a), \"w\" (b));"
1477 puts $f " return (a != 1);"
1478 puts $f "}"
1479 close $f
1480
1481 set opts "additional_flags=-mfpu=neon additional_flags=-mfloat-abi=softfp"
1482
1483 verbose "check_arm_neon_hw_available compiling testfile $src" 2
1484 set lines [${tool}_target_compile $src $exe executable "$opts"]
1485 file delete $src
1486
1487 if [string match "" $lines] then {
1488 # No error message, compilation succeeded.
1489 set result [${tool}_load "./$exe" "" ""]
1490 set status [lindex $result 0]
1491 remote_file build delete $exe
1492 verbose "check_arm_neon_hw_available testfile status is <$status>" 2
1493
1494 if { $status == "pass" } then {
1495 set arm_neon_hw_available_saved 1
1496 }
1497 } else {
1498 verbose "check_arm_neon_hw_available testfile compilation failed" 2
1499 }
1500 }
1501
1502 return $arm_neon_hw_available_saved
1503 }
1504
1505 # Return 1 if this is a PowerPC target with floating-point registers.
1506
1507 proc check_effective_target_powerpc_fprs { } {
1508 if { [istarget powerpc*-*-*]
1509 || [istarget rs6000-*-*] } {
1510 return [check_no_compiler_messages powerpc_fprs object {
1511 #ifdef __NO_FPRS__
1512 #error no FPRs
1513 #else
1514 int dummy;
1515 #endif
1516 }]
1517 } else {
1518 return 0
1519 }
1520 }
1521
1522 # Return 1 if this is a PowerPC target supporting -maltivec.
1523
1524 proc check_effective_target_powerpc_altivec_ok { } {
1525 if { [istarget powerpc*-*-*]
1526 || [istarget rs6000-*-*] } {
1527 # AltiVec is not supported on Aix.
1528 if { [istarget powerpc*-*-aix*] } {
1529 return 0
1530 }
1531 return [check_no_compiler_messages powerpc_altivec_ok object {
1532 int dummy;
1533 } "-maltivec"]
1534 } else {
1535 return 0
1536 }
1537 }
1538
1539 # Return 1 if this is a PowerPC target with SPE enabled.
1540
1541 proc check_effective_target_powerpc_spe { } {
1542 if { [istarget powerpc*-*-*] } {
1543 return [check_no_compiler_messages powerpc_spe object {
1544 #ifndef __SPE__
1545 #error not SPE
1546 #else
1547 int dummy;
1548 #endif
1549 }]
1550 } else {
1551 return 0
1552 }
1553 }
1554
1555 # Return 1 if this is a PowerPC target with Altivec enabled.
1556
1557 proc check_effective_target_powerpc_altivec { } {
1558 if { [istarget powerpc*-*-*] } {
1559 return [check_no_compiler_messages powerpc_altivec object {
1560 #ifndef __ALTIVEC__
1561 #error not Altivec
1562 #else
1563 int dummy;
1564 #endif
1565 }]
1566 } else {
1567 return 0
1568 }
1569 }
1570
1571 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
1572 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables. Return 1 if the
1573 # test environment appears to run executables on such a simulator.
1574
1575 proc check_effective_target_ultrasparc_hw { } {
1576 global et_ultrasparc_hw_saved
1577 global tool
1578
1579 if [info exists et_ultrasparc_hw_saved] {
1580 verbose "check_ultrasparc_hw_available returning saved $et_ultrasparc_hw_saved" 2
1581 } else {
1582 set et_ultrasparc_hw_saved 0
1583
1584 # Set up, compile, and execute a simple test program. The
1585 # program will be compiled with -mcpu=ultrasparc to instruct the
1586 # assembler to produce EM_SPARC32PLUS executables.
1587 set src svect[pid].c
1588 set exe svect[pid].x
1589
1590 set f [open $src "w"]
1591 puts $f "int main() { return 0; }"
1592 close $f
1593
1594 verbose "check_ultrasparc_hw_available compiling testfile $src" 2
1595 set lines [${tool}_target_compile $src $exe executable "additional_flags=-mcpu=ultrasparc"]
1596 file delete $src
1597
1598 if [string match "" $lines] then {
1599 # No error message, compilation succeeded.
1600 set result [${tool}_load "./$exe" "" ""]
1601 set status [lindex $result 0]
1602 remote_file build delete $exe
1603 verbose "check_ultrasparc_hw_available testfile status is <$status>" 2
1604
1605 if { $status == "pass" } then {
1606 set et_ultrasparc_hw_saved 1
1607 }
1608 } else {
1609 verbose "check_ultrasparc_hw_available testfile compilation failed" 2
1610 }
1611 }
1612
1613 return $et_ultrasparc_hw_saved
1614 }
1615
1616 # Return 1 if the target supports hardware vector shift operation.
1617
1618 proc check_effective_target_vect_shift { } {
1619 global et_vect_shift_saved
1620
1621 if [info exists et_vect_shift_saved] {
1622 verbose "check_effective_target_vect_shift: using cached result" 2
1623 } else {
1624 set et_vect_shift_saved 0
1625 if { [istarget powerpc*-*-*]
1626 || [istarget ia64-*-*]
1627 || [istarget i?86-*-*]
1628 || [istarget x86_64-*-*] } {
1629 set et_vect_shift_saved 1
1630 }
1631 }
1632
1633 verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1634 return $et_vect_shift_saved
1635 }
1636
1637 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1638 #
1639 # This can change for different subtargets so do not cache the result.
1640
1641 proc check_effective_target_vect_long { } {
1642 if { [istarget i?86-*-*]
1643 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1644 || [istarget x86_64-*-*]
1645 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1646 set answer 1
1647 } else {
1648 set answer 0
1649 }
1650
1651 verbose "check_effective_target_vect_long: returning $answer" 2
1652 return $answer
1653 }
1654
1655 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1656 #
1657 # This won't change for different subtargets so cache the result.
1658
1659 proc check_effective_target_vect_float { } {
1660 global et_vect_float_saved
1661
1662 if [info exists et_vect_float_saved] {
1663 verbose "check_effective_target_vect_float: using cached result" 2
1664 } else {
1665 set et_vect_float_saved 0
1666 if { [istarget i?86-*-*]
1667 || [istarget powerpc*-*-*]
1668 || [istarget spu-*-*]
1669 || [istarget mipsisa64*-*-*]
1670 || [istarget x86_64-*-*]
1671 || [istarget ia64-*-*] } {
1672 set et_vect_float_saved 1
1673 }
1674 }
1675
1676 verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1677 return $et_vect_float_saved
1678 }
1679
1680 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1681 #
1682 # This won't change for different subtargets so cache the result.
1683
1684 proc check_effective_target_vect_double { } {
1685 global et_vect_double_saved
1686
1687 if [info exists et_vect_double_saved] {
1688 verbose "check_effective_target_vect_double: using cached result" 2
1689 } else {
1690 set et_vect_double_saved 0
1691 if { [istarget i?86-*-*]
1692 || [istarget x86_64-*-*]
1693 || [istarget spu-*-*] } {
1694 set et_vect_double_saved 1
1695 }
1696 }
1697
1698 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1699 return $et_vect_double_saved
1700 }
1701
1702 # Return 1 if the target supports hardware comparison of vectors of double, 0 otherwise.
1703 #
1704 # This won't change for different subtargets so cache the result.
1705
1706 proc check_effective_target_vect_no_compare_double { } {
1707 global et_vect_no_compare_double_saved
1708
1709 if [info exists et_vect_no_compare_double_saved] {
1710 verbose "check_effective_target_vect_no_compare_double: using cached result" 2
1711 } else {
1712 set et_vect_no_compare_double_saved 0
1713 }
1714
1715 verbose "check_effective_target_vect_no_compare_double: returning $et_vect_no_compare_double_saved" 2
1716 return $et_vect_no_compare_double_saved
1717 }
1718
1719 # Return 1 if the target plus current options does not support a vector
1720 # max instruction on "int", 0 otherwise.
1721 #
1722 # This won't change for different subtargets so cache the result.
1723
1724 proc check_effective_target_vect_no_int_max { } {
1725 global et_vect_no_int_max_saved
1726
1727 if [info exists et_vect_no_int_max_saved] {
1728 verbose "check_effective_target_vect_no_int_max: using cached result" 2
1729 } else {
1730 set et_vect_no_int_max_saved 0
1731 if { [istarget sparc*-*-*]
1732 || [istarget spu-*-*]
1733 || [istarget alpha*-*-*] } {
1734 set et_vect_no_int_max_saved 1
1735 }
1736 }
1737 verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1738 return $et_vect_no_int_max_saved
1739 }
1740
1741 # Return 1 if the target plus current options does not support a vector
1742 # add instruction on "int", 0 otherwise.
1743 #
1744 # This won't change for different subtargets so cache the result.
1745
1746 proc check_effective_target_vect_no_int_add { } {
1747 global et_vect_no_int_add_saved
1748
1749 if [info exists et_vect_no_int_add_saved] {
1750 verbose "check_effective_target_vect_no_int_add: using cached result" 2
1751 } else {
1752 set et_vect_no_int_add_saved 0
1753 # Alpha only supports vector add on V8QI and V4HI.
1754 if { [istarget alpha*-*-*] } {
1755 set et_vect_no_int_add_saved 1
1756 }
1757 }
1758 verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1759 return $et_vect_no_int_add_saved
1760 }
1761
1762 # Return 1 if the target plus current options does not support vector
1763 # bitwise instructions, 0 otherwise.
1764 #
1765 # This won't change for different subtargets so cache the result.
1766
1767 proc check_effective_target_vect_no_bitwise { } {
1768 global et_vect_no_bitwise_saved
1769
1770 if [info exists et_vect_no_bitwise_saved] {
1771 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1772 } else {
1773 set et_vect_no_bitwise_saved 0
1774 }
1775 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1776 return $et_vect_no_bitwise_saved
1777 }
1778
1779 # Return 1 if the target plus current options supports a vector
1780 # widening summation of *short* args into *int* result, 0 otherwise.
1781 # A target can also support this widening summation if it can support
1782 # promotion (unpacking) from shorts to ints.
1783 #
1784 # This won't change for different subtargets so cache the result.
1785
1786 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1787 global et_vect_widen_sum_hi_to_si
1788
1789 if [info exists et_vect_widen_sum_hi_to_si_saved] {
1790 verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1791 } else {
1792 set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1793 if { [istarget powerpc*-*-*]
1794 || [istarget ia64-*-*] } {
1795 set et_vect_widen_sum_hi_to_si_saved 1
1796 }
1797 }
1798 verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1799 return $et_vect_widen_sum_hi_to_si_saved
1800 }
1801
1802 # Return 1 if the target plus current options supports a vector
1803 # widening summation of *char* args into *short* result, 0 otherwise.
1804 # A target can also support this widening summation if it can support
1805 # promotion (unpacking) from chars to shorts.
1806 #
1807 # This won't change for different subtargets so cache the result.
1808
1809 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1810 global et_vect_widen_sum_qi_to_hi
1811
1812 if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1813 verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1814 } else {
1815 set et_vect_widen_sum_qi_to_hi_saved 0
1816 if { [check_effective_target_vect_unpack]
1817 || [istarget ia64-*-*] } {
1818 set et_vect_widen_sum_qi_to_hi_saved 1
1819 }
1820 }
1821 verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1822 return $et_vect_widen_sum_qi_to_hi_saved
1823 }
1824
1825 # Return 1 if the target plus current options supports a vector
1826 # widening summation of *char* args into *int* result, 0 otherwise.
1827 #
1828 # This won't change for different subtargets so cache the result.
1829
1830 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1831 global et_vect_widen_sum_qi_to_si
1832
1833 if [info exists et_vect_widen_sum_qi_to_si_saved] {
1834 verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1835 } else {
1836 set et_vect_widen_sum_qi_to_si_saved 0
1837 if { [istarget powerpc*-*-*] } {
1838 set et_vect_widen_sum_qi_to_si_saved 1
1839 }
1840 }
1841 verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1842 return $et_vect_widen_sum_qi_to_si_saved
1843 }
1844
1845 # Return 1 if the target plus current options supports a vector
1846 # widening multiplication of *char* args into *short* result, 0 otherwise.
1847 # A target can also support this widening multplication if it can support
1848 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1849 # multiplication of shorts).
1850 #
1851 # This won't change for different subtargets so cache the result.
1852
1853
1854 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1855 global et_vect_widen_mult_qi_to_hi
1856
1857 if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1858 verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
1859 } else {
1860 if { [check_effective_target_vect_unpack]
1861 && [check_effective_target_vect_short_mult] } {
1862 set et_vect_widen_mult_qi_to_hi_saved 1
1863 } else {
1864 set et_vect_widen_mult_qi_to_hi_saved 0
1865 }
1866 if { [istarget powerpc*-*-*] } {
1867 set et_vect_widen_mult_qi_to_hi_saved 1
1868 }
1869 }
1870 verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1871 return $et_vect_widen_mult_qi_to_hi_saved
1872 }
1873
1874 # Return 1 if the target plus current options supports a vector
1875 # widening multiplication of *short* args into *int* result, 0 otherwise.
1876 # A target can also support this widening multplication if it can support
1877 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1878 # multiplication of ints).
1879 #
1880 # This won't change for different subtargets so cache the result.
1881
1882
1883 proc check_effective_target_vect_widen_mult_hi_to_si { } {
1884 global et_vect_widen_mult_hi_to_si
1885
1886 if [info exists et_vect_widen_mult_hi_to_si_saved] {
1887 verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1888 } else {
1889 if { [check_effective_target_vect_unpack]
1890 && [check_effective_target_vect_int_mult] } {
1891 set et_vect_widen_mult_hi_to_si_saved 1
1892 } else {
1893 set et_vect_widen_mult_hi_to_si_saved 0
1894 }
1895 if { [istarget powerpc*-*-*]
1896 || [istarget spu-*-*]
1897 || [istarget i?86-*-*]
1898 || [istarget x86_64-*-*] } {
1899 set et_vect_widen_mult_hi_to_si_saved 1
1900 }
1901 }
1902 verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1903 return $et_vect_widen_mult_hi_to_si_saved
1904 }
1905
1906 # Return 1 if the target plus current options supports a vector
1907 # dot-product of signed chars, 0 otherwise.
1908 #
1909 # This won't change for different subtargets so cache the result.
1910
1911 proc check_effective_target_vect_sdot_qi { } {
1912 global et_vect_sdot_qi
1913
1914 if [info exists et_vect_sdot_qi_saved] {
1915 verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1916 } else {
1917 set et_vect_sdot_qi_saved 0
1918 }
1919 verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1920 return $et_vect_sdot_qi_saved
1921 }
1922
1923 # Return 1 if the target plus current options supports a vector
1924 # dot-product of unsigned chars, 0 otherwise.
1925 #
1926 # This won't change for different subtargets so cache the result.
1927
1928 proc check_effective_target_vect_udot_qi { } {
1929 global et_vect_udot_qi
1930
1931 if [info exists et_vect_udot_qi_saved] {
1932 verbose "check_effective_target_vect_udot_qi: using cached result" 2
1933 } else {
1934 set et_vect_udot_qi_saved 0
1935 if { [istarget powerpc*-*-*] } {
1936 set et_vect_udot_qi_saved 1
1937 }
1938 }
1939 verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1940 return $et_vect_udot_qi_saved
1941 }
1942
1943 # Return 1 if the target plus current options supports a vector
1944 # dot-product of signed shorts, 0 otherwise.
1945 #
1946 # This won't change for different subtargets so cache the result.
1947
1948 proc check_effective_target_vect_sdot_hi { } {
1949 global et_vect_sdot_hi
1950
1951 if [info exists et_vect_sdot_hi_saved] {
1952 verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1953 } else {
1954 set et_vect_sdot_hi_saved 0
1955 if { [istarget powerpc*-*-*]
1956 || [istarget i?86-*-*]
1957 || [istarget x86_64-*-*] } {
1958 set et_vect_sdot_hi_saved 1
1959 }
1960 }
1961 verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1962 return $et_vect_sdot_hi_saved
1963 }
1964
1965 # Return 1 if the target plus current options supports a vector
1966 # dot-product of unsigned shorts, 0 otherwise.
1967 #
1968 # This won't change for different subtargets so cache the result.
1969
1970 proc check_effective_target_vect_udot_hi { } {
1971 global et_vect_udot_hi
1972
1973 if [info exists et_vect_udot_hi_saved] {
1974 verbose "check_effective_target_vect_udot_hi: using cached result" 2
1975 } else {
1976 set et_vect_udot_hi_saved 0
1977 if { [istarget powerpc*-*-*] } {
1978 set et_vect_udot_hi_saved 1
1979 }
1980 }
1981 verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1982 return $et_vect_udot_hi_saved
1983 }
1984
1985
1986 # Return 1 if the target plus current options supports a vector
1987 # demotion (packing) of shorts (to chars) and ints (to shorts)
1988 # using modulo arithmetic, 0 otherwise.
1989 #
1990 # This won't change for different subtargets so cache the result.
1991
1992 proc check_effective_target_vect_pack_trunc { } {
1993 global et_vect_pack_trunc
1994
1995 if [info exists et_vect_pack_trunc_saved] {
1996 verbose "check_effective_target_vect_pack_trunc: using cached result" 2
1997 } else {
1998 set et_vect_pack_trunc_saved 0
1999 if { [istarget powerpc*-*-*]
2000 || [istarget i?86-*-*]
2001 || [istarget x86_64-*-*] } {
2002 set et_vect_pack_trunc_saved 1
2003 }
2004 }
2005 verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
2006 return $et_vect_pack_trunc_saved
2007 }
2008
2009 # Return 1 if the target plus current options supports a vector
2010 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
2011 #
2012 # This won't change for different subtargets so cache the result.
2013
2014 proc check_effective_target_vect_unpack { } {
2015 global et_vect_unpack
2016
2017 if [info exists et_vect_unpack_saved] {
2018 verbose "check_effective_target_vect_unpack: using cached result" 2
2019 } else {
2020 set et_vect_unpack_saved 0
2021 if { [istarget powerpc*-*-*]
2022 || [istarget i?86-*-*]
2023 || [istarget x86_64-*-*] } {
2024 set et_vect_unpack_saved 1
2025 }
2026 }
2027 verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2
2028 return $et_vect_unpack_saved
2029 }
2030
2031 # Return 1 if the target plus current options does not support a vector
2032 # alignment mechanism, 0 otherwise.
2033 #
2034 # This won't change for different subtargets so cache the result.
2035
2036 proc check_effective_target_vect_no_align { } {
2037 global et_vect_no_align_saved
2038
2039 if [info exists et_vect_no_align_saved] {
2040 verbose "check_effective_target_vect_no_align: using cached result" 2
2041 } else {
2042 set et_vect_no_align_saved 0
2043 if { [istarget mipsisa64*-*-*]
2044 || [istarget sparc*-*-*]
2045 || [istarget ia64-*-*] } {
2046 set et_vect_no_align_saved 1
2047 }
2048 }
2049 verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
2050 return $et_vect_no_align_saved
2051 }
2052
2053 # Return 1 if arrays are aligned to the vector alignment
2054 # boundary, 0 otherwise.
2055 #
2056 # This won't change for different subtargets so cache the result.
2057
2058 proc check_effective_target_vect_aligned_arrays { } {
2059 global et_vect_aligned_arrays
2060
2061 if [info exists et_vect_aligned_arrays_saved] {
2062 verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
2063 } else {
2064 set et_vect_aligned_arrays_saved 0
2065 if { ([istarget x86_64-*-*]
2066 || [istarget i?86-*-*]) && [is-effective-target lp64] } {
2067 set et_vect_aligned_arrays_saved 1
2068 }
2069 }
2070 verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
2071 return $et_vect_aligned_arrays_saved
2072 }
2073
2074 # Return 1 if types are naturally aligned (aligned to their type-size),
2075 # 0 otherwise.
2076 #
2077 # This won't change for different subtargets so cache the result.
2078
2079 proc check_effective_target_natural_alignment { } {
2080 global et_natural_alignment
2081
2082 if [info exists et_natural_alignment_saved] {
2083 verbose "check_effective_target_natural_alignment: using cached result" 2
2084 } else {
2085 # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
2086 set et_natural_alignment_saved 1
2087 if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } {
2088 set et_natural_alignment_saved 0
2089 }
2090 }
2091 verbose "check_effective_target_natural_alignment: returning $et_natural_alignment_saved" 2
2092 return $et_natural_alignment_saved
2093 }
2094
2095 # Return 1 if vector alignment is reachable, 0 otherwise.
2096 #
2097 # This won't change for different subtargets so cache the result.
2098
2099 proc check_effective_target_vector_alignment_reachable { } {
2100 global et_vector_alignment_reachable
2101
2102 if [info exists et_vector_alignment_reachable_saved] {
2103 verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
2104 } else {
2105 if { [check_effective_target_vect_aligned_arrays]
2106 || [check_effective_target_natural_alignment] } {
2107 set et_vector_alignment_reachable_saved 1
2108 } else {
2109 set et_vector_alignment_reachable_saved 0
2110 }
2111 }
2112 verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
2113 return $et_vector_alignment_reachable_saved
2114 }
2115
2116 # Return 1 if vector alignment for soubles is reachable, 0 otherwise.
2117 #
2118 # This won't change for different subtargets so cache the result.
2119
2120 proc check_effective_target_vector_alignment_reachable_for_double { } {
2121 global et_vector_alignment_reachable_for_double
2122
2123 if [info exists et_vector_alignment_reachable_for_double_saved] {
2124 verbose "check_effective_target_vector_alignment_reachable_for_double: using cached result" 2
2125 } else {
2126 if { [check_effective_target_vect_aligned_arrays] } {
2127 set et_vector_alignment_reachable_for_double_saved 1
2128 } else {
2129 set et_vector_alignment_reachable_for_double_saved 0
2130 }
2131 }
2132 verbose "check_effective_target_vector_alignment_reachable_for_double: returning $et_vector_alignment_reachable_for_double_saved" 2
2133 return $et_vector_alignment_reachable_for_double_saved
2134 }
2135
2136 # Return 1 if the target supports vector conditional operations, 0 otherwise.
2137
2138 proc check_effective_target_vect_condition { } {
2139 global et_vect_cond_saved
2140
2141 if [info exists et_vect_cond_saved] {
2142 verbose "check_effective_target_vect_cond: using cached result" 2
2143 } else {
2144 set et_vect_cond_saved 0
2145 if { [istarget powerpc*-*-*]
2146 || [istarget ia64-*-*]
2147 || [istarget i?86-*-*]
2148 || [istarget spu-*-*]
2149 || [istarget x86_64-*-*] } {
2150 set et_vect_cond_saved 1
2151 }
2152 }
2153
2154 verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
2155 return $et_vect_cond_saved
2156 }
2157
2158 # Return 1 if the target supports vector char multiplication, 0 otherwise.
2159
2160 proc check_effective_target_vect_char_mult { } {
2161 global et_vect_char_mult_saved
2162
2163 if [info exists et_vect_char_mult_saved] {
2164 verbose "check_effective_target_vect_char_mult: using cached result" 2
2165 } else {
2166 set et_vect_char_mult_saved 0
2167 if { [istarget ia64-*-*]
2168 || [istarget i?86-*-*]
2169 || [istarget x86_64-*-*] } {
2170 set et_vect_char_mult_saved 1
2171 }
2172 }
2173
2174 verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
2175 return $et_vect_char_mult_saved
2176 }
2177
2178 # Return 1 if the target supports vector short multiplication, 0 otherwise.
2179
2180 proc check_effective_target_vect_short_mult { } {
2181 global et_vect_short_mult_saved
2182
2183 if [info exists et_vect_short_mult_saved] {
2184 verbose "check_effective_target_vect_short_mult: using cached result" 2
2185 } else {
2186 set et_vect_short_mult_saved 0
2187 if { [istarget ia64-*-*]
2188 || [istarget i?86-*-*]
2189 || [istarget x86_64-*-*] } {
2190 set et_vect_short_mult_saved 1
2191 }
2192 }
2193
2194 verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
2195 return $et_vect_short_mult_saved
2196 }
2197
2198 # Return 1 if the target supports vector int multiplication, 0 otherwise.
2199
2200 proc check_effective_target_vect_int_mult { } {
2201 global et_vect_int_mult_saved
2202
2203 if [info exists et_vect_int_mult_saved] {
2204 verbose "check_effective_target_vect_int_mult: using cached result" 2
2205 } else {
2206 set et_vect_int_mult_saved 0
2207 if { [istarget powerpc*-*-*]
2208 || [istarget spu-*-*]
2209 || [istarget i?86-*-*]
2210 || [istarget x86_64-*-*] } {
2211 set et_vect_int_mult_saved 1
2212 }
2213 }
2214
2215 verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
2216 return $et_vect_int_mult_saved
2217 }
2218
2219 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
2220
2221 proc check_effective_target_vect_extract_even_odd { } {
2222 global et_vect_extract_even_odd_saved
2223
2224 if [info exists et_vect_extract_even_odd_saved] {
2225 verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
2226 } else {
2227 set et_vect_extract_even_odd_saved 0
2228 if { [istarget powerpc*-*-*] } {
2229 set et_vect_extract_even_odd_saved 1
2230 }
2231 }
2232
2233 verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
2234 return $et_vect_extract_even_odd_saved
2235 }
2236
2237 # Return 1 if the target supports vector interleaving, 0 otherwise.
2238
2239 proc check_effective_target_vect_interleave { } {
2240 global et_vect_interleave_saved
2241
2242 if [info exists et_vect_interleave_saved] {
2243 verbose "check_effective_target_vect_interleave: using cached result" 2
2244 } else {
2245 set et_vect_interleave_saved 0
2246 if { [istarget powerpc*-*-*]
2247 || [istarget i?86-*-*]
2248 || [istarget x86_64-*-*] } {
2249 set et_vect_interleave_saved 1
2250 }
2251 }
2252
2253 verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
2254 return $et_vect_interleave_saved
2255 }
2256
2257 # Return 1 if the target supports section-anchors
2258
2259 proc check_effective_target_section_anchors { } {
2260 global et_section_anchors_saved
2261
2262 if [info exists et_section_anchors_saved] {
2263 verbose "check_effective_target_section_anchors: using cached result" 2
2264 } else {
2265 set et_section_anchors_saved 0
2266 if { [istarget powerpc*-*-*] } {
2267 set et_section_anchors_saved 1
2268 }
2269 }
2270
2271 verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
2272 return $et_section_anchors_saved
2273 }
2274
2275 # Return 1 if the target supports atomic operations on "int" and "long".
2276
2277 proc check_effective_target_sync_int_long { } {
2278 global et_sync_int_long_saved
2279
2280 if [info exists et_sync_int_long_saved] {
2281 verbose "check_effective_target_sync_int_long: using cached result" 2
2282 } else {
2283 set et_sync_int_long_saved 0
2284 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2285 # load-reserved/store-conditional instructions.
2286 if { [istarget ia64-*-*]
2287 || [istarget i?86-*-*]
2288 || [istarget x86_64-*-*]
2289 || [istarget alpha*-*-*]
2290 || [istarget s390*-*-*]
2291 || [istarget powerpc*-*-*]
2292 || [istarget sparc64-*-*]
2293 || [istarget sparcv9-*-*]
2294 || [istarget xtensa-*-*] } {
2295 set et_sync_int_long_saved 1
2296 }
2297 }
2298
2299 verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2300 return $et_sync_int_long_saved
2301 }
2302
2303 # Return 1 if the target supports atomic operations on "char" and "short".
2304
2305 proc check_effective_target_sync_char_short { } {
2306 global et_sync_char_short_saved
2307
2308 if [info exists et_sync_char_short_saved] {
2309 verbose "check_effective_target_sync_char_short: using cached result" 2
2310 } else {
2311 set et_sync_char_short_saved 0
2312 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2313 # load-reserved/store-conditional instructions.
2314 if { [istarget ia64-*-*]
2315 || [istarget i?86-*-*]
2316 || [istarget x86_64-*-*]
2317 || [istarget alpha*-*-*]
2318 || [istarget s390*-*-*]
2319 || [istarget powerpc*-*-*]
2320 || [istarget sparc64-*-*]
2321 || [istarget sparcv9-*-*]
2322 || [istarget xtensa-*-*] } {
2323 set et_sync_char_short_saved 1
2324 }
2325 }
2326
2327 verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2328 return $et_sync_char_short_saved
2329 }
2330
2331 # Return 1 if the target uses a ColdFire FPU.
2332
2333 proc check_effective_target_coldfire_fpu { } {
2334 return [check_no_compiler_messages coldfire_fpu assembly {
2335 #ifndef __mcffpu__
2336 #error FOO
2337 #endif
2338 }]
2339 }
2340
2341 # Return true if this is a uClibc target.
2342
2343 proc check_effective_target_uclibc {} {
2344 return [check_no_compiler_messages uclibc object {
2345 #include <features.h>
2346 #if !defined (__UCLIBC__)
2347 #error FOO
2348 #endif
2349 }]
2350 }
2351
2352 # Return true if this is a uclibc target and if the uclibc feature
2353 # described by __$feature__ is not present.
2354
2355 proc check_missing_uclibc_feature {feature} {
2356 return [check_no_compiler_messages $feature object "
2357 #include <features.h>
2358 #if !defined (__UCLIBC) || defined (__${feature}__)
2359 #error FOO
2360 #endif
2361 "]
2362 }
2363
2364 # Return true if this is a Newlib target.
2365
2366 proc check_effective_target_newlib {} {
2367 return [check_no_compiler_messages newlib object {
2368 #include <newlib.h>
2369 }]
2370 }
2371
2372 # Return 1 if
2373 # (a) an error of a few ULP is expected in string to floating-point
2374 # conversion functions; and
2375 # (b) overflow is not always detected correctly by those functions.
2376
2377 proc check_effective_target_lax_strtofp {} {
2378 # By default, assume that all uClibc targets suffer from this.
2379 return [check_effective_target_uclibc]
2380 }
2381
2382 # Return 1 if this is a target for which wcsftime is a dummy
2383 # function that always returns 0.
2384
2385 proc check_effective_target_dummy_wcsftime {} {
2386 # By default, assume that all uClibc targets suffer from this.
2387 return [check_effective_target_uclibc]
2388 }
2389
2390 # Return 1 if constructors with initialization priority arguments are
2391 # supposed on this target.
2392
2393 proc check_effective_target_init_priority {} {
2394 return [check_no_compiler_messages init_priority assembly "
2395 void f() __attribute__((constructor (1000)));
2396 void f() \{\}
2397 "]
2398 }
2399
2400 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2401 # This can be used with any check_* proc that takes no argument and
2402 # returns only 1 or 0. It could be used with check_* procs that take
2403 # arguments with keywords that pass particular arguments.
2404
2405 proc is-effective-target { arg } {
2406 set selected 0
2407 if { [info procs check_effective_target_${arg}] != [list] } {
2408 set selected [check_effective_target_${arg}]
2409 } else {
2410 switch $arg {
2411 "vmx_hw" { set selected [check_vmx_hw_available] }
2412 "named_sections" { set selected [check_named_sections_available] }
2413 "gc_sections" { set selected [check_gc_sections_available] }
2414 "cxa_atexit" { set selected [check_cxa_atexit_available] }
2415 default { error "unknown effective target keyword `$arg'" }
2416 }
2417 }
2418 verbose "is-effective-target: $arg $selected" 2
2419 return $selected
2420 }
2421
2422 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2423
2424 proc is-effective-target-keyword { arg } {
2425 if { [info procs check_effective_target_${arg}] != [list] } {
2426 return 1
2427 } else {
2428 # These have different names for their check_* procs.
2429 switch $arg {
2430 "vmx_hw" { return 1 }
2431 "named_sections" { return 1 }
2432 "gc_sections" { return 1 }
2433 "cxa_atexit" { return 1 }
2434 default { return 0 }
2435 }
2436 }
2437 }
2438
2439 # Return 1 if target default to short enums
2440
2441 proc check_effective_target_short_enums { } {
2442 return [check_no_compiler_messages short_enums assembly {
2443 enum foo { bar };
2444 int s[sizeof (enum foo) == 1 ? 1 : -1];
2445 }]
2446 }
2447
2448 # Return 1 if target supports merging string constants at link time.
2449
2450 proc check_effective_target_string_merging { } {
2451 return [check_no_messages_and_pattern string_merging \
2452 "rodata\\.str" assembly {
2453 const char *var = "String";
2454 } {-O2}]
2455 }
2456
2457 # Return 1 if target has the basic signed and unsigned types in
2458 # <stdint.h>, 0 otherwise.
2459
2460 proc check_effective_target_stdint_types { } {
2461 return [check_no_compiler_messages stdint_types assembly {
2462 #include <stdint.h>
2463 int8_t a; int16_t b; int32_t c; int64_t d;
2464 uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2465 }]
2466 }
2467
2468 # Return 1 if programs are intended to be run on a simulator
2469 # (i.e. slowly) rather than hardware (i.e. fast).
2470
2471 proc check_effective_target_simulator { } {
2472
2473 # All "src/sim" simulators set this one.
2474 if [board_info target exists is_simulator] {
2475 return [board_info target is_simulator]
2476 }
2477
2478 # The "sid" simulators don't set that one, but at least they set
2479 # this one.
2480 if [board_info target exists slow_simulator] {
2481 return [board_info target slow_simulator]
2482 }
2483
2484 return 0
2485 }
2486
2487 # Return 1 if the target is a VxWorks RTP.
2488
2489 proc check_effective_target_vxworks_kernel { } {
2490 return [check_no_compiler_messages vxworks_kernel assembly {
2491 #if !defined __vxworks || defined __RTP__
2492 #error NO
2493 #endif
2494 }]
2495 }
2496
2497 # Return 1 if the target is expected to provide wide character support.
2498
2499 proc check_effective_target_wchar { } {
2500 if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2501 return 0
2502 }
2503 return [check_no_compiler_messages wchar assembly {
2504 #include <wchar.h>
2505 }]
2506 }