summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/s390/s390.exp
blob: d76d80dd0f3b2c7d88f7573cc0634c5aefee1d96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# Copyright (C) 2007-2020 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# GCC testsuite that uses the `dg.exp' driver.

global torture_current_flags
set torture_current_flags ""

# Exit immediately if this isn't a s390 target.
if ![istarget s390*-*-*] then {
  return
}

# Load support procs.
load_lib gcc-dg.exp
load_lib target-supports.exp
load_lib gfortran-dg.exp

# Return 1 if the the assembler understands .machine and .machinemode.  The
# target attribute needs that feature to work.
proc check_effective_target_target_attribute { } {
    if { ![check_runtime s390_check_machine_machinemode [subst {
	int main (void)
	{
	    asm (".machine push" : : );
	    asm (".machine pop" : : );
	    asm (".machinemode push" : : );
	    asm (".machinemode pop" : : );
	    return 0;
	}
    }] "" ] } { return 0 } else { return 1 }
}

# Return 1 if htm (etnd - extract nesting depth) instructions are
# understood by the assembler and can be executed.
proc check_effective_target_htm { } {
    if { ![check_runtime s390_check_htm [subst {
	int main (void)
	{
	    unsigned int nd;
	    asm ("etnd %0" : "=d" (nd));
	    return nd;
	}
    }] "-march=zEC12 -mzarch" ] } { return 0 } else { return 1 }
}

global s390_cached_flags
set s390_cached_flags ""
global s390_cached_value
set s390_cached_value ""
global s390_cached_value_noflags
set s390_cached_value_noflags ""

# Return 1 if a program using the full instruction set allowed by
# the compiler option can be executed.
proc check_effective_target_s390_useable_hw { } {
    global torture_current_flags
    global s390_cached_flags
    global s390_cached_value
    global s390_cached_value_noflags

    # Remove -Ox options and whitespace.
    set flags [regsub -all {[-]O[0-9s]} "$torture_current_flags" ""]
    set flags [regsub -all {[ \\t\\n]+} "$flags" " "]
    set flags [regsub -all {(^ )|( $)} "$flags" ""]
    if { "$s390_cached_flags" != "" && "$flags" == "$s390_cached_flags" } {
      return $s390_cached_value
    }
    # Extra cache for (frequent) calls with empty torture_current_flags.
    if { "$flags" == "" && $s390_cached_value_noflags != "" } {
      return $s390_cached_value_noflags
    }
    if { ![check_runtime_nocache s390_check_useable_hw [subst {
	int main (void)
	{
	    asm (".machinemode zarch" : : );
	#if __ARCH__ >= 13
	    asm ("ncrk %%r2,%%r2,%%r2" : : : "r2");
	#elif __ARCH__ >= 12
	    asm ("agh %%r2,0(%%r15)" : : : "r2");
	#elif __ARCH__ >= 11
	    asm ("lochiz %%r2,42" : : : "r2");
	#elif __ARCH__ >= 10
	    asm ("risbgn %%r2,%%r2,0,0,0" : : : "r2");
	#elif __ARCH__ >= 9
	    asm ("sgrk %%r2,%%r2,%%r2" : : : "r2");
	#elif __ARCH__ >= 8
	    asm ("rosbg %%r2,%%r2,0,0,0" : : : "r2");
	#elif __ARCH__ >= 7
	    asm ("nilf %%r2,0" : : : "r2");
	#elif __ARCH__ >= 6
	    asm ("lay %%r2,0(%%r15)" : : : "r2");
	#elif __ARCH__ >= 5
	    asm ("tam" : : );
	#endif
	#ifdef __HTM__
	  {
	    unsigned int nd;
	    asm ("etnd %0" : "=d" (nd));
	  }
	#endif
	#if defined (__VX__) && defined (__zarch__)
	    asm ("vzero %%v0" : : : "v0");
	#endif
	  return 0;
	}
    }] "$flags" ] } { set result 0 } else { set result 1 }
    if { "$flags" == "" } {
      set s390_cached_value_noflags "$result"
    } else {
      set s390_cached_flags "$flags"
      set s390_cached_value "$result"
    }
    return $result
}

# Return 1 if -march=... specific instructions are understood by
# the assembler and can be executed.
proc check_effective_target_s390_z900_hw { } {
    if { ![check_runtime s390_check_s390_z900_hw [subst {
	int main (void)
	{
	    asm ("tam" : : );
	    return 0;
	}
    }] "-march=z900 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_z990_hw { } {
    if { ![check_runtime s390_check_s390_z990_hw [subst {
	int main (void)
	{
	    asm ("lay %%r2,0(%%r15)" : : );
	    return 0;
	}
    }] "-march=z990 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_z9_ec_hw { } {
    if { ![check_runtime s390_check_s390_z9_ec_hw [subst {
	int main (void)
	{
	    asm ("nilf %%r2,0" : : );
	    return 0;
	}
    }] "-march=z9-ec -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_z10_hw { } {
    if { ![check_runtime s390_check_s390_z10_hw [subst {
	int main (void)
	{
	    asm ("rosbg %%r2,%%r2,0,0,0" : : );
	    return 0;
	}
    }] "-march=z10 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_z196_hw { } {
    if { ![check_runtime s390_check_s390_z196_hw [subst {
	int main (void)
	{
	    asm ("sgrk %%r2,%%r2,%%r2" : : );
	    return 0;
	}
    }] "-march=z196 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_zEC12_hw { } {
    if { ![check_runtime s390_check_s390_zEC12_hw [subst {
	int main (void)
	{
	    asm ("risbgn %%r2,%%r2,0,0,0" : : );
	    return 0;
	}
    }] "-march=zEC12 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_z13_hw { } {
    if { ![check_runtime s390_check_s390_z13_hw [subst {
	int main (void)
	{
	    asm ("lcbb %%r2,0(%%r15),0" : : );
	    return 0;
	}
    }] "-march=z13 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
proc check_effective_target_s390_z14_hw { } {
    if { ![check_runtime s390_check_s390_z14_hw [subst {
	int main (void)
	{
	    int x = 0;
	    asm ("msgrkc %%0,%%0,%%0" : "+r" (x) : );
	    return x;
	}
    }] "-march=z14 -m64 -mzarch" ] } { return 0 } else { return 1 }
}
# Return 1 if the default compiler options enable z/Architecture mode
proc check_effective_target_s390_zarch { } {
    return [check_no_compiler_messages s390_zarch object {
	int dummy[sizeof (int __attribute__((__mode__(__word__)))) == 8
		  ? 1 : -1];
    }]
}

# If a testcase doesn't have special options, use these.
global DEFAULT_CFLAGS
if ![info exists DEFAULT_CFLAGS] then {
    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
}
global DEFAULT_FFLAGS
if ![info exists DEFAULT_FFLAGS] then {
    set DEFAULT_FFLAGS " -pedantic-errors"
}

# Initialize `dg'.
dg-init

set md_tests $srcdir/$subdir/md/*.c

# C++ tests belong into g++.dg with a target check.  Do NOT add C to
# these regexps!

# Main loop.
dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.{c,S}] \
			 $md_tests]] "" $DEFAULT_CFLAGS

dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.{c,S}]] \
	"" $DEFAULT_CFLAGS

gfortran-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.F90]] \
	"" $DEFAULT_FFLAGS

dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/target-attribute/*.{c,S}]] \
	"" $DEFAULT_CFLAGS

dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/arch12/*.{c,S}]] \
	"" "-O3 -march=arch12 -mzarch"

dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/arch13/*.{c,S}]] \
	"" "-O3 -march=arch13 -mzarch"

dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/vxe/*.{c,S}]] \
	"" "-O3 -march=arch12 -mzarch"

dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/md/*.{c,S}]] \
	"" $DEFAULT_CFLAGS

# Additional hotpatch torture tests.
torture-init
set-torture-options [list -Os -O1 -O2 -O3]
gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/hotpatch-\[0-9\]*.c]] \
	"" $DEFAULT_CFLAGS
torture-finish

# Additional md torture tests.
# (Note: Split into a separate torture test for each -march= option to improve
# cacheability.)
torture-init
set MD_TEST_OPTS [list \
	{-Os} {-Os -march=z900} \
	{-O0} {-O0 -march=z900} \
	{-O1} {-O1 -march=z900} \
	{-O2} {-O2 -march=z900} \
	{-O3} {-O3 -march=z900} ]
set-torture-options $MD_TEST_OPTS
gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS"
torture-finish
torture-init
set MD_TEST_OPTS [list \
	{-Os -march=z13} \
	{-O0 -march=z13} \
	{-O1 -march=z13} \
	{-O2 -march=z13} \
	{-O3 -march=z13} ]
set-torture-options $MD_TEST_OPTS
gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS"
torture-finish

# Tests that should pass on all optimization levels.
foreach t [list $srcdir/$subdir/pr80080-3.c] {
	torture-init
	set-torture-options [list -O1 -O2 -O3 -O0 -Os -Ofast -Og]
	gcc-dg-runtest [list $t] \
		"" $DEFAULT_CFLAGS
	torture-finish
}

# All done.
dg-finish