1# Copyright (C) 2007-2018 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 19global torture_current_flags 20set torture_current_flags "" 21 22# Exit immediately if this isn't a s390 target. 23if ![istarget s390*-*-*] then { 24 return 25} 26 27# Load support procs. 28load_lib gcc-dg.exp 29load_lib target-supports.exp 30 31# Return 1 if the the assembler understands .machine and .machinemode. The 32# target attribute needs that feature to work. 33proc check_effective_target_target_attribute { } { 34 if { ![check_runtime s390_check_machine_machinemode [subst { 35 int main (void) 36 { 37 asm (".machine push" : : ); 38 asm (".machine pop" : : ); 39 asm (".machinemode push" : : ); 40 asm (".machinemode pop" : : ); 41 return 0; 42 } 43 }] "" ] } { return 0 } else { return 1 } 44} 45 46# Return 1 if htm (etnd - extract nesting depth) instructions are 47# understood by the assembler and can be executed. 48proc check_effective_target_htm { } { 49 if { ![check_runtime s390_check_htm [subst { 50 int main (void) 51 { 52 unsigned int nd; 53 asm ("etnd %0" : "=d" (nd)); 54 return nd; 55 } 56 }] "-march=zEC12 -mzarch" ] } { return 0 } else { return 1 } 57} 58 59global s390_cached_flags 60set s390_cached_flags "" 61global s390_cached_value 62set s390_cached_value "" 63global s390_cached_value_noflags 64set s390_cached_value_noflags "" 65 66# Return 1 if a program using the full instruction set allowed by 67# the compiler option can be executed. 68proc check_effective_target_s390_useable_hw { } { 69 global torture_current_flags 70 global s390_cached_flags 71 global s390_cached_value 72 global s390_cached_value_noflags 73 74 # Remove -Ox options and whitespace. 75 set flags [regsub -all {[-]O[0-9s]} "$torture_current_flags" ""] 76 set flags [regsub -all {[ \\t\\n]+} "$flags" " "] 77 set flags [regsub -all {(^ )|( $)} "$flags" ""] 78 if { "$s390_cached_flags" != "" && "$flags" == "$s390_cached_flags" } { 79 return $s390_cached_value 80 } 81 # Extra cache for (frequent) calls with empty torture_current_flags. 82 if { "$flags" == "" && $s390_cached_value_noflags != "" } { 83 return $s390_cached_value_noflags 84 } 85 if { ![check_runtime_nocache s390_check_useable_hw [subst { 86 int main (void) 87 { 88 asm (".machinemode zarch" : : ); 89 #if __ARCH__ >= 11 90 asm ("lcbb %%r2,0(%%r15),0" : : ); 91 #elif __ARCH__ >= 10 92 asm ("risbgn %%r2,%%r2,0,0,0" : : ); 93 #elif __ARCH__ >= 9 94 asm ("sgrk %%r2,%%r2,%%r2" : : ); 95 #elif __ARCH__ >= 8 96 asm ("rosbg %%r2,%%r2,0,0,0" : : ); 97 #elif __ARCH__ >= 7 98 asm ("nilf %%r2,0" : : ); 99 #elif __ARCH__ >= 6 100 asm ("lay %%r2,0(%%r15)" : : ); 101 #elif __ARCH__ >= 5 102 asm ("tam" : : ); 103 #endif 104 #ifdef __HTM__ 105 { 106 unsigned int nd; 107 asm ("etnd %0" : "=d" (nd)); 108 } 109 #endif 110 #ifdef __VX__ 111 asm ("vzero %%v0" : : ); 112 #endif 113 return 0; 114 } 115 }] "$flags" ] } { set result 0 } else { set result 1 } 116 if { "$flags" == "" } { 117 set s390_cached_value_noflags "$result" 118 } else { 119 set s390_cached_flags "$flags" 120 set s390_cached_value "$result" 121 } 122 return $result 123} 124 125# Return 1 if -march=... specific instructions are understood by 126# the assembler and can be executed. 127proc check_effective_target_s390_z900_hw { } { 128 if { ![check_runtime s390_check_s390_z900_hw [subst { 129 int main (void) 130 { 131 asm ("tam" : : ); 132 return 0; 133 } 134 }] "-march=z900 -m64 -mzarch" ] } { return 0 } else { return 1 } 135} 136proc check_effective_target_s390_z990_hw { } { 137 if { ![check_runtime s390_check_s390_z990_hw [subst { 138 int main (void) 139 { 140 asm ("lay %%r2,0(%%r15)" : : ); 141 return 0; 142 } 143 }] "-march=z990 -m64 -mzarch" ] } { return 0 } else { return 1 } 144} 145proc check_effective_target_s390_z9_ec_hw { } { 146 if { ![check_runtime s390_check_s390_z9_ec_hw [subst { 147 int main (void) 148 { 149 asm ("nilf %%r2,0" : : ); 150 return 0; 151 } 152 }] "-march=z9-ec -m64 -mzarch" ] } { return 0 } else { return 1 } 153} 154proc check_effective_target_s390_z10_hw { } { 155 if { ![check_runtime s390_check_s390_z10_hw [subst { 156 int main (void) 157 { 158 asm ("rosbg %%r2,%%r2,0,0,0" : : ); 159 return 0; 160 } 161 }] "-march=z10 -m64 -mzarch" ] } { return 0 } else { return 1 } 162} 163proc check_effective_target_s390_z196_hw { } { 164 if { ![check_runtime s390_check_s390_z196_hw [subst { 165 int main (void) 166 { 167 asm ("sgrk %%r2,%%r2,%%r2" : : ); 168 return 0; 169 } 170 }] "-march=z196 -m64 -mzarch" ] } { return 0 } else { return 1 } 171} 172proc check_effective_target_s390_zEC12_hw { } { 173 if { ![check_runtime s390_check_s390_zEC12_hw [subst { 174 int main (void) 175 { 176 asm ("risbgn %%r2,%%r2,0,0,0" : : ); 177 return 0; 178 } 179 }] "-march=zEC12 -m64 -mzarch" ] } { return 0 } else { return 1 } 180} 181proc check_effective_target_s390_z13_hw { } { 182 if { ![check_runtime s390_check_s390_z13_hw [subst { 183 int main (void) 184 { 185 asm ("lcbb %%r2,0(%%r15),0" : : ); 186 return 0; 187 } 188 }] "-march=z13 -m64 -mzarch" ] } { return 0 } else { return 1 } 189} 190 191# If a testcase doesn't have special options, use these. 192global DEFAULT_CFLAGS 193if ![info exists DEFAULT_CFLAGS] then { 194 set DEFAULT_CFLAGS " -ansi -pedantic-errors" 195} 196 197# Initialize `dg'. 198dg-init 199 200set md_tests $srcdir/$subdir/md/*.c 201 202# C++ tests belong into g++.dg with a target check. Do NOT add C to 203# these regexps! 204 205# Main loop. 206dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.{c,S}] \ 207 $md_tests]] "" $DEFAULT_CFLAGS 208 209dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.{c,S}]] \ 210 "" $DEFAULT_CFLAGS 211 212dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/target-attribute/*.{c,S}]] \ 213 "" $DEFAULT_CFLAGS 214 215dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/arch12/*.{c,S}]] \ 216 "" "-O3 -march=arch12 -mzarch" 217 218dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/vxe/*.{c,S}]] \ 219 "" "-O3 -march=arch12 -mzarch" 220 221dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/md/*.{c,S}]] \ 222 "" $DEFAULT_CFLAGS 223 224# Additional hotpatch torture tests. 225torture-init 226set-torture-options [list -Os -O1 -O2 -O3] 227gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/hotpatch-\[0-9\]*.c]] \ 228 "" $DEFAULT_CFLAGS 229torture-finish 230 231# Additional md torture tests. 232# (Note: Split into a separate torture test for each -march= option to improve 233# cacheability.) 234torture-init 235set MD_TEST_OPTS [list \ 236 {-Os} {-Os -march=z900} \ 237 {-O0} {-O0 -march=z900} \ 238 {-O1} {-O1 -march=z900} \ 239 {-O2} {-O2 -march=z900} \ 240 {-O3} {-O3 -march=z900} ] 241set-torture-options $MD_TEST_OPTS 242gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS" 243torture-finish 244torture-init 245set MD_TEST_OPTS [list \ 246 {-Os -march=z13} \ 247 {-O0 -march=z13} \ 248 {-O1 -march=z13} \ 249 {-O2 -march=z13} \ 250 {-O3 -march=z13} ] 251set-torture-options $MD_TEST_OPTS 252gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" "$DEFAULT_CFLAGS" 253torture-finish 254 255# All done. 256dg-finish 257