S/390: Rename __S390_ARCH_LEVEL__ to __ARCH__.
[official-gcc.git] / gcc / testsuite / gcc.target / s390 / s390.exp
blob107ba98c8d900693e34b3929a992e071ec08cda5
1 # Copyright (C) 2007-2017 Free Software Foundation, Inc.
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.
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/>.
17 # GCC testsuite that uses the `dg.exp' driver.
19 global torture_current_flags
20 set torture_current_flags ""
22 # Exit immediately if this isn't a s390 target.
23 if ![istarget s390*-*-*] then {
24 return
27 # Load support procs.
28 load_lib gcc-dg.exp
30 # Return 1 if the the assembler understands .machine and .machinemode. The
31 # target attribute needs that feature to work.
32 proc check_effective_target_target_attribute { } {
33 if { ![check_runtime s390_check_machine_machinemode [subst {
34 int main (void)
36 asm (".machine push" : : );
37 asm (".machine pop" : : );
38 asm (".machinemode push" : : );
39 asm (".machinemode pop" : : );
40 return 0;
42 }] "" ] } { return 0 } else { return 1 }
45 # Return 1 if htm (etnd - extract nesting depth) instructions are
46 # understood by the assembler and can be executed.
47 proc check_effective_target_htm { } {
48 if { ![check_runtime s390_check_htm [subst {
49 int main (void)
51 unsigned int nd;
52 asm ("etnd %0" : "=d" (nd));
53 return nd;
55 }] "-march=zEC12 -mzarch" ] } { return 0 } else { return 1 }
58 # Return 1 if vector (va - vector add) instructions are understood by
59 # the assembler and can be executed. This also covers checking for
60 # the VX kernel feature. A kernel without that feature does not
61 # enable the vector facility and the following check will die with a
62 # signal.
63 proc check_effective_target_vector { } {
64 if { ![check_runtime s390_check_vector [subst {
65 int main (void)
67 asm ("va %%v24, %%v26, %%v28, 3" : : : "v24", "v26", "v28");
68 return 0;
70 }] "-march=z13 -mzarch" ] } { return 0 } else { return 1 }
73 global s390_cached_flags
74 set s390_cached_flags ""
75 global s390_cached_value
76 set s390_cached_value ""
77 global s390_cached_value_noflags
78 set s390_cached_value_noflags ""
80 # Return 1 if a program using the full instruction set allowed by
81 # the compiler option can be executed.
82 proc check_effective_target_s390_useable_hw { } {
83 global torture_current_flags
84 global s390_cached_flags
85 global s390_cached_value
86 global s390_cached_value_noflags
88 # Remove -Ox options and whitespace.
89 set flags [regsub -all {[-]O[0-9s]} "$torture_current_flags" ""]
90 set flags [regsub -all {[ \\t\\n]+} "$flags" " "]
91 set flags [regsub -all {(^ )|( $)} "$flags" ""]
92 if { "$s390_cached_flags" != "" && "$flags" == "$s390_cached_flags" } {
93 return $s390_cached_value
95 # Extra cache for (frequent) calls with empty torture_current_flags.
96 if { "$flags" == "" && $s390_cached_value_noflags != "" } {
97 return $s390_cached_value_noflags
99 if { ![check_runtime_nocache s390_check_useable_hw [subst {
100 int main (void)
102 asm (".machinemode zarch" : : );
103 #if __ARCH__ >= 11
104 asm ("lcbb %%r2,0(%%r15),0" : : );
105 #elif __ARCH__ >= 10
106 asm ("risbgn %%r2,%%r2,0,0,0" : : );
107 #elif __ARCH__ >= 9
108 asm ("sgrk %%r2,%%r2,%%r2" : : );
109 #elif __ARCH__ >= 8
110 asm ("rosbg %%r2,%%r2,0,0,0" : : );
111 #elif __ARCH__ >= 7
112 asm ("nilf %%r2,0" : : );
113 #elif __ARCH__ >= 6
114 asm ("lay %%r2,0(%%r15)" : : );
115 #elif __ARCH__ >= 5
116 asm ("tam" : : );
117 #endif
118 #ifdef __HTM__
120 unsigned int nd;
121 asm ("etnd %0" : "=d" (nd));
123 #endif
124 #ifdef __S390_VX__
125 asm ("vzero %%v0" : : );
126 #endif
127 return 0;
129 }] "$flags" ] } { set result 0 } else { set result 1 }
130 if { "$flags" == "" } {
131 set s390_cached_value_noflags "$result"
132 } else {
133 set s390_cached_flags "$flags"
134 set s390_cached_value "$result"
136 return $result
139 # Return 1 if -march=... specific instructions are understood by
140 # the assembler and can be executed.
141 proc check_effective_target_s390_z900_hw { } {
142 if { ![check_runtime s390_check_s390_z900_hw [subst {
143 int main (void)
145 asm ("tam" : : );
146 return 0;
148 }] "-march=z900 -m64 -mzarch" ] } { return 0 } else { return 1 }
150 proc check_effective_target_s390_z990_hw { } {
151 if { ![check_runtime s390_check_s390_z990_hw [subst {
152 int main (void)
154 asm ("lay %%r2,0(%%r15)" : : );
155 return 0;
157 }] "-march=z990 -m64 -mzarch" ] } { return 0 } else { return 1 }
159 proc check_effective_target_s390_z9_ec_hw { } {
160 if { ![check_runtime s390_check_s390_z9_ec_hw [subst {
161 int main (void)
163 asm ("nilf %%r2,0" : : );
164 return 0;
166 }] "-march=z9-ec -m64 -mzarch" ] } { return 0 } else { return 1 }
168 proc check_effective_target_s390_z10_hw { } {
169 if { ![check_runtime s390_check_s390_z10_hw [subst {
170 int main (void)
172 asm ("rosbg %%r2,%%r2,0,0,0" : : );
173 return 0;
175 }] "-march=z10 -m64 -mzarch" ] } { return 0 } else { return 1 }
177 proc check_effective_target_s390_z196_hw { } {
178 if { ![check_runtime s390_check_s390_z196_hw [subst {
179 int main (void)
181 asm ("sgrk %%r2,%%r2,%%r2" : : );
182 return 0;
184 }] "-march=z196 -m64 -mzarch" ] } { return 0 } else { return 1 }
186 proc check_effective_target_s390_zEC12_hw { } {
187 if { ![check_runtime s390_check_s390_zEC12_hw [subst {
188 int main (void)
190 asm ("risbgn %%r2,%%r2,0,0,0" : : );
191 return 0;
193 }] "-march=zEC12 -m64 -mzarch" ] } { return 0 } else { return 1 }
195 proc check_effective_target_s390_z13_hw { } {
196 if { ![check_runtime s390_check_s390_z13_hw [subst {
197 int main (void)
199 asm ("lcbb %%r2,0(%%r15),0" : : );
200 return 0;
202 }] "-march=z13 -m64 -mzarch" ] } { return 0 } else { return 1 }
205 # If a testcase doesn't have special options, use these.
206 global DEFAULT_CFLAGS
207 if ![info exists DEFAULT_CFLAGS] then {
208 set DEFAULT_CFLAGS " -ansi -pedantic-errors"
211 # Initialize `dg'.
212 dg-init
214 set md_tests $srcdir/$subdir/md/*.c
216 # Main loop.
217 dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.{c,S,C}] \
218 $md_tests]] "" $DEFAULT_CFLAGS
220 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.]] \
221 "" $DEFAULT_CFLAGS
223 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/target-attribute/*.{c,S,C}]] \
224 "" $DEFAULT_CFLAGS
226 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/md/*.{c,S,C}]] \
227 "" $DEFAULT_CFLAGS
229 # Additional hotpatch torture tests.
230 torture-init
231 set-torture-options [list -Os -O0 -O1 -O2 -O3]
232 gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/hotpatch-\[0-9\]*.c]] \
233 "" $DEFAULT_CFLAGS
234 torture-finish
236 # Additional md torture tests.
237 # (Note: Split into a separate torture test for each -march= option to improve
238 # cacheability.)
239 torture-init
240 set MD_TEST_OPTS [list \
241 {-Os} {-Os -march=z900} \
242 {-O0} {-O0 -march=z900} \
243 {-O1} {-O1 -march=z900} \
244 {-O2} {-O2 -march=z900} \
245 {-O3} {-O3 -march=z900} ]
246 set-torture-options $MD_TEST_OPTS
247 gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS"
248 torture-finish
249 torture-init
250 set MD_TEST_OPTS [list \
251 {-Os -march=z13} \
252 {-O0 -march=z13} \
253 {-O1 -march=z13} \
254 {-O2 -march=z13} \
255 {-O3 -march=z13} ]
256 set-torture-options $MD_TEST_OPTS
257 gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS"
258 torture-finish
260 # All done.
261 dg-finish