1 # Copyright (C) 2023-2024 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.
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 this program. If not, see <http://www.gnu.org/licenses/>.
16 # Exercise the following:
17 # - Printing ZA registers when there is no ZA state.
18 # - Setting values of ZA registers when there is no ZA state.
19 # - Validating ZA state is activated when we write to ZA registers.
20 # - Validate that reading ZT0 without an active ZA state works as expected.
22 load_lib aarch64-scalable.exp
25 # Validate that the ZA registers have the expected state.
27 proc_with_prefix check_regs
{ vl svl
} {
28 # Check VG to make sure it is correct
29 set expected_vg
[expr $vl / 8]
30 gdb_test
"print \$vg" "= ${expected_vg}"
32 # Check SVG to make sure it is correct
33 set expected_svg
[expr $svl / 8]
34 gdb_test
"print \$svg" "= ${expected_svg}"
36 # Make sure there is no SM or ZA state.
37 if [gdb_test
"print \$svcr" "= \\\[ \\\]"] {
38 fail
"incorrect ZA state"
42 # Check the size of ZA.
43 set expected_za_size
[expr $svl * $svl]
44 gdb_test
"print sizeof \$za" " = $expected_za_size"
46 # Check the size of Z0.
47 gdb_test
"print sizeof \$z0" " = $vl"
49 # Set the expected ZA pattern.
50 set za_pattern
[string_to_regexp
[2d_array_value_pattern
0 $svl $svl]]
53 gdb_test
"print \$za" $za_pattern
55 # Exercise reading/writing the tile slice pseudo-registers.
59 set expected_size
$svl
60 foreach_with_prefix granularity
{"b" "h" "s" "d" "q"} {
61 set pattern
[string_to_regexp
[1d_array_value_pattern
0 $elements]]
62 for {set tile
0} {$tile < $last_tile} {incr tile
} {
63 for {set slice
0} {$slice < $last_slice} {incr slice
} {
64 foreach_with_prefix direction
{"h" "v"} {
65 set register_name
"\$za${tile}${direction}${granularity}${slice}"
67 gdb_test
"print sizeof ${register_name}" " = ${expected_size}"
68 gdb_test
"print ${register_name}" $pattern
72 set last_tile
[expr $last_tile * 2]
73 set last_slice
[expr ($last_slice / 2)]
74 set elements
[expr ($elements / 2)]
77 # Exercise reading/writing the tile pseudo-registers.
80 set expected_size
[expr $svl * $svl]
81 foreach_with_prefix granularity
{"b" "h" "s" "d" "q"} {
82 set pattern
[string_to_regexp
[2d_array_value_pattern
0 $elements $elements]]
83 for {set tile
0} {$tile < $last_tile} {incr tile
} {
84 set register_name
"\$za${tile}${granularity}"
86 gdb_test
"print sizeof ${register_name}" " = ${expected_size}"
87 gdb_test
"print ${register_name}" $pattern
89 set last_tile
[expr $last_tile * 2]
90 set expected_size
[expr $expected_size / 2]
91 set elements
[expr ($elements / 2)]
94 # Exercise reading from SME2 registers.
95 if [is_sme2_available
] {
96 # The target supports SME2.
98 gdb_test
"print sizeof \$zt0" " = $zt_size"
100 # If ZA is not active, ZT0 will always be zero.
101 set zt_pattern
[string_to_regexp
[1d_array_value_pattern
0 $zt_size]]
102 gdb_test
"print \$zt0" " = $zt_pattern"
107 # Cycle through all ZA registers and pseudo-registers and validate that their
108 # contents are unavailable (zeroed out) for vector length SVL.
110 proc test_sme_registers_unavailable
{ id_start id_end
} {
112 set compile_flags
{"debug" "macros"}
113 lappend compile_flags
"additional_flags=-DID_START=${id_start}"
114 lappend compile_flags
"additional_flags=-DID_END=${id_end}"
116 standard_testfile
${::srcdir}/${::subdir}/aarch64-sme-regs-unavailable.c
117 set executable
"${::testfile}-${id_start}-${id_end}"
118 if {[prepare_for_testing
"failed to prepare" ${executable
} ${::srcfile} ${compile_flags
}]} {
121 set binfile
[standard_output_file
${executable
}]
123 # Check if we are talking to a remote target. If so, bail out, as right now
124 # remote targets can't communicate vector length (vl or svl) changes to gdb
125 # via the RSP. When this restriction is lifted, we can remove this guard.
126 if {[gdb_protocol_is_remote
]} {
127 unsupported
"aarch64 sve/sme tests not supported for remote targets"
132 untested
"could not run to main"
136 gdb_test_no_output
"set print repeats 1"
138 set prctl_breakpoint
"stop 1"
139 gdb_breakpoint
[gdb_get_line_number
$prctl_breakpoint]
141 for {set id
$id_start} {$id <= $id_end} {incr id
} {
142 set vl
[test_id_to_vl
$id]
143 set svl
[test_id_to_svl
$id]
145 set skip_unsupported
0
146 if {![aarch64_supports_sve_vl
$vl]
147 ||
![aarch64_supports_sme_svl
$svl]} {
148 # We have a vector length or streaming vector length that
149 # is not supported by this target. Skip to the next iteration
150 # since it is no use running tests for an unsupported vector
152 if {![aarch64_supports_sve_vl
$vl]} {
153 verbose
-log "SVE vector length $vl not supported."
154 } elseif
{![aarch64_supports_sme_svl
$svl]} {
155 verbose
-log "SME streaming vector length $svl not supported."
157 verbose
-log "Skipping test."
158 set skip_unsupported
1
161 with_test_prefix
"prctl, vl=${vl} svl=${svl}" {
162 # If the SVE or SME vector length is not supported, just skip
164 if {$skip_unsupported} {
165 untested
"unsupported configuration on target"
169 # Run the program until it has adjusted svl.
170 gdb_continue_to_breakpoint
$prctl_breakpoint
176 set non_prctl_breakpoint
"stop 2"
177 gdb_breakpoint
[gdb_get_line_number
$non_prctl_breakpoint]
178 gdb_continue_to_breakpoint
$non_prctl_breakpoint
180 for {set id
$id_start} {$id <= $id_end} {incr id
} {
181 set vl
[test_id_to_vl
$id]
182 set svl
[test_id_to_svl
$id]
184 set skip_unsupported
0
185 if {![aarch64_supports_sve_vl
$vl]
186 ||
![aarch64_supports_sme_svl
$svl]} {
187 # We have a vector length or streaming vector length that
188 # is not supported by this target. Skip to the next iteration
189 # since it is no use running tests for an unsupported vector
191 if {![aarch64_supports_sve_vl
$vl]} {
192 verbose
-log "SVE vector length $vl not supported."
193 } elseif
{![aarch64_supports_sme_svl
$svl]} {
194 verbose
-log "SME streaming vector length $svl not supported."
196 verbose
-log "Skipping test."
197 set skip_unsupported
1
200 with_test_prefix
"gdb, vl=${vl} svl=${svl}" {
202 # If the SVE or SME vector length is not supported, just skip
204 if {$skip_unsupported} {
205 untested
"unsupported configuration on target"
210 set vg_value
[expr $vl / 8]
211 set svg_value
[expr $svl / 8]
212 gdb_test_no_output
"set \$vg = ${vg_value}"
213 gdb_test_no_output
"set \$svg = ${svg_value}"
220 require is_aarch64_target
221 require allow_aarch64_sve_tests
222 require allow_aarch64_sme_tests
224 test_sme_registers_unavailable
$id_start $id_end