1 1.1 christos # Copyright (C) 2023-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Exercise reading/writing ZA registers when there is ZA state. 17 1.1 christos # Exercise reading/writing to ZT0 when there is ZA state available. 18 1.1 christos 19 1.1 christos load_lib aarch64-scalable.exp 20 1.1 christos 21 1.1 christos require is_aarch64_target 22 1.1 christos require allow_aarch64_sve_tests 23 1.1 christos require allow_aarch64_sme_tests 24 1.1 christos 25 1.1 christos # Remote targets can't communicate vector length (vl or svl) changes 26 1.1 christos # to GDB via the RSP. 27 1.1 christos require !gdb_protocol_is_remote 28 1.1 christos 29 1.1 christos # 30 1.1 christos # Cycle through all ZA registers and pseudo-registers and validate that their 31 1.1 christos # contents are available for vector length SVL. 32 1.1 christos # 33 1.1 christos # Make sure reading/writing to ZA registers work as expected. 34 1.1 christos # 35 1.1 christos proc check_regs { mode vl svl } { 36 1.1 christos # Check VG to make sure it is correct 37 1.1 christos set expected_vg [expr $vl / 8] 38 1.1 christos gdb_test "print \$vg" "= ${expected_vg}" 39 1.1 christos 40 1.1 christos # Check SVG to make sure it is correct 41 1.1 christos set expected_svg [expr $svl / 8] 42 1.1 christos gdb_test "print \$svg" "= ${expected_svg}" 43 1.1 christos 44 1.1 christos # If svl is adjusted by prctl, we will have ZA enabled. If gdb is 45 1.1 christos # adjusting svl, ZA will not be enabled by default. It will only be 46 1.1 christos # enabled when ZA is written to. 47 1.1 christos set za_state "= \\\[ ZA \\\]" 48 1.1 christos if {$mode == "gdb"} { 49 1.1 christos set za_state "= \\\[ \\\]" 50 1.1 christos } 51 1.1 christos 52 1.1 christos # Check SVCR. 53 1.1 christos if [gdb_test "print \$svcr" $za_state "svcr before assignments" ] { 54 1.1 christos fail "incorrect za state" 55 1.1 christos return -1 56 1.1 christos } 57 1.1 christos 58 1.1 christos # Check the size of ZA. 59 1.1 christos set expected_za_size [expr $svl * $svl] 60 1.1 christos gdb_test "print sizeof \$za" " = $expected_za_size" 61 1.1 christos 62 1.1 christos # Check the size of Z0. 63 1.1 christos gdb_test "print sizeof \$z0" " = $vl" 64 1.1 christos 65 1.1 christos # Exercise reading/writing from/to ZA. 66 1.1 christos initialize_2d_array "\$za" 255 $svl $svl 67 1.1 christos set pattern [string_to_regexp [2d_array_value_pattern 255 $svl $svl]] 68 1.1 christos gdb_test "print \$za" " = $pattern" "read back from za" 69 1.1 christos 70 1.1 christos # Exercise reading/writing from/to the tile pseudo-registers. 71 1.1 christos set last_tile 1 72 1.1 christos set expected_size [expr $svl * $svl] 73 1.1 christos set tile_svl $svl 74 1.1 christos set za_state "= \\\[ ZA \\\]" 75 1.1 christos foreach_with_prefix granularity {"b" "h" "s" "d" "q"} { 76 1.1 christos for {set tile 0} {$tile < $last_tile} {incr tile} { 77 1.1 christos set register_name "\$za${tile}${granularity}" 78 1.1 christos 79 1.1 christos # Test the size. 80 1.1 christos gdb_test "print sizeof ${register_name}" " = ${expected_size}" 81 1.1 christos 82 1.1 christos # Test reading/writing 83 1.1 christos initialize_2d_array $register_name 255 $tile_svl $tile_svl 84 1.1 christos 85 1.1 christos # Make sure we have ZA state. 86 1.1 christos if [gdb_test "print \$svcr" $za_state "svcr after assignment to ${register_name}" ] { 87 1.1 christos fail "incorrect za state" 88 1.1 christos return -1 89 1.1 christos } 90 1.1 christos 91 1.1 christos set pattern [string_to_regexp [2d_array_value_pattern 255 $tile_svl $tile_svl]] 92 1.1 christos gdb_test "print $register_name" " = $pattern" "read back from $register_name" 93 1.1 christos } 94 1.1 christos set last_tile [expr $last_tile * 2] 95 1.1 christos set expected_size [expr $expected_size / 2] 96 1.1 christos set tile_svl [expr $tile_svl / 2] 97 1.1 christos } 98 1.1 christos 99 1.1 christos # Exercise reading/writing from/to the tile slice pseudo-registers. 100 1.1 christos set last_tile 1 101 1.1 christos set last_slice $svl 102 1.1 christos set expected_size $svl 103 1.1 christos set num_elements $svl 104 1.1 christos foreach_with_prefix granularity {"b" "h" "s" "d" "q"} { 105 1.1 christos for {set tile 0} {$tile < $last_tile} {incr tile} { 106 1.1 christos for {set slice 0} {$slice < $last_slice} {incr slice} { 107 1.1 christos foreach_with_prefix direction {"h" "v"} { 108 1.1 christos set register_name "\$za${tile}${direction}${granularity}${slice}" 109 1.1 christos 110 1.1 christos # Test the size. 111 1.1 christos gdb_test "print sizeof ${register_name}" " = ${expected_size}" 112 1.1 christos 113 1.1 christos # Test reading/writing 114 1.1 christos initialize_1d_array $register_name 255 $num_elements 115 1.1 christos 116 1.1 christos # Make sure we have ZA state. 117 1.1 christos if [gdb_test "print \$svcr" $za_state "svcr after assignment of ${register_name}" ] { 118 1.1 christos fail "incorrect za state" 119 1.1 christos return -1 120 1.1 christos } 121 1.1 christos 122 1.1 christos set pattern [string_to_regexp [1d_array_value_pattern 255 $num_elements]] 123 1.1 christos gdb_test "print $register_name" " = $pattern" "read back from $register_name" 124 1.1 christos } 125 1.1 christos } 126 1.1 christos } 127 1.1 christos set last_tile [expr $last_tile * 2] 128 1.1 christos set last_slice [expr ($last_slice / 2)] 129 1.1 christos set num_elements [expr $num_elements / 2] 130 1.1 christos } 131 1.1 christos 132 1.1 christos # Exercise reading/writing from/to SME2 registers. 133 1.1 christos if [is_sme2_available] { 134 1.1 christos # The target supports SME2. 135 1.1 christos set zt_size 64 136 1.1 christos gdb_test "print sizeof \$zt0" " = $zt_size" 137 1.1 christos 138 1.1 christos # Initially, when ZA is activated, ZT0 will be all zeroes. 139 1.1 christos set zt_pattern [string_to_regexp [1d_array_value_pattern 0 $zt_size]] 140 1.1 christos gdb_test "print \$zt0" " = $zt_pattern" "validate zeroed zt0" 141 1.1 christos 142 1.1 christos # Validate that writing to ZT0 does the right thing. 143 1.1 christos initialize_1d_array "\$zt0" 255 $zt_size 144 1.1 christos set zt_pattern [string_to_regexp [1d_array_value_pattern 255 $zt_size]] 145 1.1 christos gdb_test "print \$zt0" " = $zt_pattern" "read back from zt0" 146 1.1 christos } 147 1.1 christos } 148 1.1 christos 149 1.1 christos # 150 1.1 christos # Cycle through all ZA registers and pseudo-registers and validate their 151 1.1 christos # contents. 152 1.1 christos # 153 1.1 christos proc test_sme_registers_available { id_start id_end } { 154 1.1 christos 155 1.1 christos set compile_flags {"debug" "macros"} 156 1.1 christos lappend compile_flags "additional_flags=-DID_START=${id_start}" 157 1.1 christos lappend compile_flags "additional_flags=-DID_END=${id_end}" 158 1.1 christos 159 1.1 christos standard_testfile ${::srcdir}/${::subdir}/aarch64-sme-regs-available.c 160 1.1 christos set executable "${::testfile}-${id_start}-${id_end}" 161 1.1 christos if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} { 162 1.1 christos return -1 163 1.1 christos } 164 1.1 christos set binfile [standard_output_file ${executable}] 165 1.1 christos 166 1.1 christos if ![runto_main] { 167 1.1 christos untested "could not run to main" 168 1.1 christos return -1 169 1.1 christos } 170 1.1 christos 171 1.1 christos gdb_test_no_output "set print repeats 1" 172 1.1 christos 173 1.1 christos set prctl_breakpoint "stop 1" 174 1.1 christos gdb_breakpoint [gdb_get_line_number $prctl_breakpoint] 175 1.1 christos 176 1.1 christos for {set id $id_start} {$id <= $id_end} {incr id} { 177 1.1 christos set vl [test_id_to_vl $id] 178 1.1 christos set svl [test_id_to_svl $id] 179 1.1 christos 180 1.1 christos set skip_unsupported 0 181 1.1 christos if {![aarch64_supports_sve_vl $vl] 182 1.1 christos || ![aarch64_supports_sme_svl $svl]} { 183 1.1 christos # We have a vector length or streaming vector length that 184 1.1 christos # is not supported by this target. Skip to the next iteration 185 1.1 christos # since it is no use running tests for an unsupported vector 186 1.1 christos # length. 187 1.1 christos if {![aarch64_supports_sve_vl $vl]} { 188 1.1 christos verbose -log "SVE vector length $vl not supported." 189 1.1 christos } elseif {![aarch64_supports_sme_svl $svl]} { 190 1.1 christos verbose -log "SME streaming vector length $svl not supported." 191 1.1 christos } 192 1.1 christos verbose -log "Skipping test." 193 1.1 christos set skip_unsupported 1 194 1.1 christos } 195 1.1 christos 196 1.1 christos set mode "prctl" 197 1.1 christos with_test_prefix "$mode, vl=${vl} svl=${svl}" { 198 1.1 christos # If the SVE or SME vector length is not supported, just skip 199 1.1 christos # these next tests. 200 1.1 christos if {$skip_unsupported} { 201 1.1 christos untested "unsupported configuration on target" 202 1.1 christos continue 203 1.1 christos } 204 1.1 christos 205 1.1 christos # Run the program until it has adjusted svl. 206 1.1 christos gdb_continue_to_breakpoint $prctl_breakpoint 207 1.1 christos check_regs $mode $vl $svl 208 1.1 christos } 209 1.1 christos } 210 1.1 christos 211 1.1 christos set non_prctl_breakpoint "stop 2" 212 1.1 christos gdb_breakpoint [gdb_get_line_number $non_prctl_breakpoint] 213 1.1 christos 214 1.1 christos for {set id $id_start} {$id <= $id_end} {incr id} { 215 1.1 christos set vl [test_id_to_vl $id] 216 1.1 christos set svl [test_id_to_svl $id] 217 1.1 christos 218 1.1 christos set skip_unsupported 0 219 1.1 christos if {![aarch64_supports_sve_vl $vl] 220 1.1 christos || ![aarch64_supports_sme_svl $svl]} { 221 1.1 christos # We have a vector length or streaming vector length that 222 1.1 christos # is not supported by this target. Skip to the next iteration 223 1.1 christos # since it is no use running tests for an unsupported vector 224 1.1 christos # length. 225 1.1 christos if {![aarch64_supports_sve_vl $vl]} { 226 1.1 christos verbose -log "SVE vector length $vl not supported." 227 1.1 christos } elseif {![aarch64_supports_sme_svl $svl]} { 228 1.1 christos verbose -log "SME streaming vector length $svl not supported." 229 1.1 christos } 230 1.1 christos verbose -log "Skipping test." 231 1.1 christos set skip_unsupported 1 232 1.1 christos } 233 1.1 christos 234 1.1 christos set mode "gdb" 235 1.1 christos with_test_prefix "$mode, vl=${vl} svl=${svl}" { 236 1.1 christos # If the SVE or SME vector length is not supported, just skip 237 1.1 christos # these next tests. 238 1.1 christos if {$skip_unsupported} { 239 1.1 christos untested "unsupported configuration on target" 240 1.1 christos continue 241 1.1 christos } 242 1.1 christos 243 1.1 christos # Run the program until we stop at the point where gdb should 244 1.1 christos # adjust the SVE and SME vector lengths. 245 1.1 christos gdb_continue_to_breakpoint $non_prctl_breakpoint 246 1.1 christos 247 1.1 christos # Adjust svl via gdb. 248 1.1 christos set vg_value [expr $vl / 8] 249 1.1 christos set svg_value [expr $svl / 8] 250 1.1 christos gdb_test_no_output "set \$vg = ${vg_value}" 251 1.1 christos gdb_test_no_output "set \$svg = ${svg_value}" 252 1.1 christos 253 1.1 christos check_regs $mode $vl $svl 254 1.1 christos } 255 1.1 christos } 256 1.1 christos } 257 1.1 christos 258 1.1 christos test_sme_registers_available $id_start $id_end 259