| 1 |
# Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation; either version 3 of the License, or |
| 6 |
# (at your option) any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with GCC; see the file COPYING3. If not see |
| 15 |
# <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
# GCC testsuite that uses the `dg.exp' driver. |
| 18 |
|
| 19 |
global torture_current_flags |
| 20 |
set torture_current_flags "" |
| 21 |
|
| 22 |
# Exit immediately if this isn't a s390 target. |
| 23 |
if ![istarget s390*-*-*] then { |
| 24 |
return |
| 25 |
} |
| 26 |
|
| 27 |
# Load support procs. |
| 28 |
load_lib gcc-dg.exp |
| 29 |
load_lib target-supports.exp |
| 30 |
load_lib gfortran-dg.exp |
| 31 |
load_lib atomic-dg.exp |
| 32 |
|
| 33 |
# Return 1 if the assembler understands .machine and .machinemode. The |
| 34 |
# target attribute needs that feature to work. |
| 35 |
proc check_effective_target_target_attribute { } { |
| 36 |
if { ![check_runtime s390_check_machine_machinemode [subst { |
| 37 |
int main (void) |
| 38 |
{ |
| 39 |
asm (".machine push" : : ); |
| 40 |
asm (".machine pop" : : ); |
| 41 |
asm (".machinemode push" : : ); |
| 42 |
asm (".machinemode pop" : : ); |
| 43 |
return 0; |
| 44 |
} |
| 45 |
}] "" ] } { return 0 } else { return 1 } |
| 46 |
} |
| 47 |
|
| 48 |
# Return 1 if htm (etnd - extract nesting depth) instructions are |
| 49 |
# understood by the assembler and can be executed. |
| 50 |
proc check_effective_target_htm { } { |
| 51 |
if { ![check_runtime s390_check_htm [subst { |
| 52 |
int main (void) |
| 53 |
{ |
| 54 |
unsigned int nd; |
| 55 |
asm ("etnd %0" : "=d" (nd)); |
| 56 |
return nd; |
| 57 |
} |
| 58 |
}] "-march=zEC12 -mzarch" ] } { return 0 } else { return 1 } |
| 59 |
} |
| 60 |
|
| 61 |
global s390_cached_flags |
| 62 |
set s390_cached_flags "" |
| 63 |
global s390_cached_value |
| 64 |
set s390_cached_value "" |
| 65 |
global s390_cached_value_noflags |
| 66 |
set s390_cached_value_noflags "" |
| 67 |
|
| 68 |
# Return 1 if a program using the full instruction set allowed by |
| 69 |
# the compiler option can be executed. |
| 70 |
proc check_effective_target_s390_useable_hw { } { |
| 71 |
global torture_current_flags |
| 72 |
global s390_cached_flags |
| 73 |
global s390_cached_value |
| 74 |
global s390_cached_value_noflags |
| 75 |
|
| 76 |
# Remove -Ox options and whitespace. |
| 77 |
set flags [regsub -all {[-]O[0-9s]} "$torture_current_flags" ""] |
| 78 |
set flags [regsub -all {[ \\t\\n]+} "$flags" " "] |
| 79 |
set flags [regsub -all {(^ )|( $)} "$flags" ""] |
| 80 |
if { "$s390_cached_flags" != "" && "$flags" == "$s390_cached_flags" } { |
| 81 |
return $s390_cached_value |
| 82 |
} |
| 83 |
# Extra cache for (frequent) calls with empty torture_current_flags. |
| 84 |
if { "$flags" == "" && $s390_cached_value_noflags != "" } { |
| 85 |
return $s390_cached_value_noflags |
| 86 |
} |
| 87 |
if { ![check_runtime_nocache s390_check_useable_hw [subst { |
| 88 |
int main (void) |
| 89 |
{ |
| 90 |
asm (".machinemode zarch" : : ); |
| 91 |
#if __ARCH__ >= 13 |
| 92 |
asm ("ncrk %%r2,%%r2,%%r2" : : : "r2"); |
| 93 |
#elif __ARCH__ >= 12 |
| 94 |
asm ("agh %%r2,0(%%r15)" : : : "r2"); |
| 95 |
#elif __ARCH__ >= 11 |
| 96 |
asm ("lochiz %%r2,42" : : : "r2"); |
| 97 |
#elif __ARCH__ >= 10 |
| 98 |
asm ("risbgn %%r2,%%r2,0,0,0" : : : "r2"); |
| 99 |
#elif __ARCH__ >= 9 |
| 100 |
asm ("sgrk %%r2,%%r2,%%r2" : : : "r2"); |
| 101 |
#elif __ARCH__ >= 8 |
| 102 |
asm ("rosbg %%r2,%%r2,0,0,0" : : : "r2"); |
| 103 |
#elif __ARCH__ >= 7 |
| 104 |
asm ("nilf %%r2,0" : : : "r2"); |
| 105 |
#elif __ARCH__ >= 6 |
| 106 |
asm ("lay %%r2,0(%%r15)" : : : "r2"); |
| 107 |
#elif __ARCH__ >= 5 |
| 108 |
asm ("tam" : : ); |
| 109 |
#endif |
| 110 |
#ifdef __HTM__ |
| 111 |
{ |
| 112 |
unsigned int nd; |
| 113 |
asm ("etnd %0" : "=d" (nd)); |
| 114 |
} |
| 115 |
#endif |
| 116 |
#if defined (__VX__) && defined (__zarch__) |
| 117 |
asm ("vzero %%v0" : : : "v0"); |
| 118 |
#endif |
| 119 |
return 0; |
| 120 |
} |
| 121 |
}] "$flags" ] } { set result 0 } else { set result 1 } |
| 122 |
if { "$flags" == "" } { |
| 123 |
set s390_cached_value_noflags "$result" |
| 124 |
} else { |
| 125 |
set s390_cached_flags "$flags" |
| 126 |
set s390_cached_value "$result" |
| 127 |
} |
| 128 |
return $result |
| 129 |
} |
| 130 |
|
| 131 |
# Return 1 if -march=... specific instructions are understood by |
| 132 |
# the assembler and can be executed. |
| 133 |
proc check_effective_target_s390_z900_hw { } { |
| 134 |
if { ![check_runtime s390_check_s390_z900_hw [subst { |
| 135 |
int main (void) |
| 136 |
{ |
| 137 |
asm ("tam" : : ); |
| 138 |
return 0; |
| 139 |
} |
| 140 |
}] "-march=z900 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 141 |
} |
| 142 |
proc check_effective_target_s390_z990_hw { } { |
| 143 |
if { ![check_runtime s390_check_s390_z990_hw [subst { |
| 144 |
int main (void) |
| 145 |
{ |
| 146 |
asm ("lay %%r2,0(%%r15)" : : ); |
| 147 |
return 0; |
| 148 |
} |
| 149 |
}] "-march=z990 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 150 |
} |
| 151 |
proc check_effective_target_s390_z9_ec_hw { } { |
| 152 |
if { ![check_runtime s390_check_s390_z9_ec_hw [subst { |
| 153 |
int main (void) |
| 154 |
{ |
| 155 |
asm ("nilf %%r2,0" : : ); |
| 156 |
return 0; |
| 157 |
} |
| 158 |
}] "-march=z9-ec -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 159 |
} |
| 160 |
proc check_effective_target_s390_z10_hw { } { |
| 161 |
if { ![check_runtime s390_check_s390_z10_hw [subst { |
| 162 |
int main (void) |
| 163 |
{ |
| 164 |
asm ("rosbg %%r2,%%r2,0,0,0" : : ); |
| 165 |
return 0; |
| 166 |
} |
| 167 |
}] "-march=z10 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 168 |
} |
| 169 |
proc check_effective_target_s390_z196_hw { } { |
| 170 |
if { ![check_runtime s390_check_s390_z196_hw [subst { |
| 171 |
int main (void) |
| 172 |
{ |
| 173 |
asm ("sgrk %%r2,%%r2,%%r2" : : ); |
| 174 |
return 0; |
| 175 |
} |
| 176 |
}] "-march=z196 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 177 |
} |
| 178 |
proc check_effective_target_s390_zEC12_hw { } { |
| 179 |
if { ![check_runtime s390_check_s390_zEC12_hw [subst { |
| 180 |
int main (void) |
| 181 |
{ |
| 182 |
asm ("risbgn %%r2,%%r2,0,0,0" : : ); |
| 183 |
return 0; |
| 184 |
} |
| 185 |
}] "-march=zEC12 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 186 |
} |
| 187 |
proc check_effective_target_s390_z13_hw { } { |
| 188 |
if { ![check_runtime s390_check_s390_z13_hw [subst { |
| 189 |
int main (void) |
| 190 |
{ |
| 191 |
asm ("lcbb %%r2,0(%%r15),0" : : ); |
| 192 |
return 0; |
| 193 |
} |
| 194 |
}] "-march=z13 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 195 |
} |
| 196 |
proc check_effective_target_s390_z14_hw { } { |
| 197 |
if { ![check_runtime s390_check_s390_z14_hw [subst { |
| 198 |
int main (void) |
| 199 |
{ |
| 200 |
int x = 0; |
| 201 |
asm ("msgrkc %0,%0,%0" : "+r" (x) : ); |
| 202 |
return x; |
| 203 |
} |
| 204 |
}] "-march=z14 -m64 -mzarch" ] } { return 0 } else { return 1 } |
| 205 |
} |
| 206 |
# Return 1 if the default compiler options enable z/Architecture mode |
| 207 |
proc check_effective_target_s390_zarch { } { |
| 208 |
return [check_no_compiler_messages s390_zarch object { |
| 209 |
int dummy[sizeof (int __attribute__((__mode__(__word__)))) == 8 |
| 210 |
? 1 : -1]; |
| 211 |
}] |
| 212 |
} |
| 213 |
|
| 214 |
# If a testcase doesn't have special options, use these. |
| 215 |
global DEFAULT_CFLAGS |
| 216 |
if ![info exists DEFAULT_CFLAGS] then { |
| 217 |
set DEFAULT_CFLAGS " -ansi -pedantic-errors" |
| 218 |
} |
| 219 |
global DEFAULT_FFLAGS |
| 220 |
if ![info exists DEFAULT_FFLAGS] then { |
| 221 |
set DEFAULT_FFLAGS " -pedantic-errors" |
| 222 |
} |
| 223 |
|
| 224 |
# Initialize `dg'. |
| 225 |
dg-init |
| 226 |
|
| 227 |
set md_tests $srcdir/$subdir/md/*.c |
| 228 |
|
| 229 |
# C++ tests belong into g++.dg with a target check. Do NOT add C to |
| 230 |
# these regexps! |
| 231 |
|
| 232 |
# Main loop. |
| 233 |
dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.{c,S}] \ |
| 234 |
$md_tests]] "" $DEFAULT_CFLAGS |
| 235 |
|
| 236 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.{c,S}]] \ |
| 237 |
"" $DEFAULT_CFLAGS |
| 238 |
|
| 239 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/partial/*.{c,S}]] \ |
| 240 |
"" $DEFAULT_CFLAGS |
| 241 |
|
| 242 |
gfortran-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.F90]] \ |
| 243 |
"" $DEFAULT_FFLAGS |
| 244 |
|
| 245 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/target-attribute/*.{c,S}]] \ |
| 246 |
"" $DEFAULT_CFLAGS |
| 247 |
|
| 248 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/arch12/*.{c,S}]] \ |
| 249 |
"" "-O3 -march=arch12 -mzarch" |
| 250 |
|
| 251 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/arch13/*.{c,S}]] \ |
| 252 |
"" "-O3 -march=arch13 -mzarch" |
| 253 |
|
| 254 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/vxe/*.{c,S}]] \ |
| 255 |
"" "-O3 -march=arch12 -mzarch" |
| 256 |
|
| 257 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/vxe2/*.{c,S}]] \ |
| 258 |
"" "-O3 -march=arch13 -mzarch" |
| 259 |
|
| 260 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/vxe3/*.{c,S}]] \ |
| 261 |
"" "-O3 -march=arch15 -mzarch" |
| 262 |
|
| 263 |
# Some md tests require libatomic |
| 264 |
atomic_init |
| 265 |
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/md/*.{c,S}]] \ |
| 266 |
"" $DEFAULT_CFLAGS |
| 267 |
|
| 268 |
# Additional hotpatch torture tests. |
| 269 |
torture-init |
| 270 |
set-torture-options [list -Os -O1 -O2 -O3] |
| 271 |
gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/hotpatch-\[0-9\]*.c]] \ |
| 272 |
"" $DEFAULT_CFLAGS |
| 273 |
torture-finish |
| 274 |
|
| 275 |
# Additional md torture tests. |
| 276 |
# (Note: Split into a separate torture test for each -march= option to improve |
| 277 |
# cacheability.) |
| 278 |
torture-init |
| 279 |
set MD_TEST_OPTS [list \ |
| 280 |
{-Os} {-Os -march=z900} \ |
| 281 |
{-O0} {-O0 -march=z900} \ |
| 282 |
{-O1} {-O1 -march=z900} \ |
| 283 |
{-O2} {-O2 -march=z900} \ |
| 284 |
{-O3} {-O3 -march=z900} ] |
| 285 |
set-torture-options $MD_TEST_OPTS |
| 286 |
gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS" |
| 287 |
torture-finish |
| 288 |
torture-init |
| 289 |
set MD_TEST_OPTS [list \ |
| 290 |
{-Os -march=z13} \ |
| 291 |
{-O0 -march=z13} \ |
| 292 |
{-O1 -march=z13} \ |
| 293 |
{-O2 -march=z13} \ |
| 294 |
{-O3 -march=z13} ] |
| 295 |
set-torture-options $MD_TEST_OPTS |
| 296 |
gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS" |
| 297 |
torture-finish |
| 298 |
|
| 299 |
# Tests that should pass on all optimization levels. |
| 300 |
foreach t [list $srcdir/$subdir/pr80080-3.c] { |
| 301 |
torture-init |
| 302 |
set-torture-options [list -O1 -O2 -O3 -O0 -Os -Ofast -Og] |
| 303 |
gcc-dg-runtest [list $t] \ |
| 304 |
"" $DEFAULT_CFLAGS |
| 305 |
torture-finish |
| 306 |
} |
| 307 |
|
| 308 |
# All done. |
| 309 |
atomic_finish |
| 310 |
dg-finish |