xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.exp.tcl (revision 32d1c65c71fbdb65a012e8392a62a757dd6853e9)
1# Copyright (C) 2023-2024 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 this program.  If not, see <http://www.gnu.org/licenses/>.
15
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.
21
22load_lib aarch64-scalable.exp
23
24#
25# Validate that the ZA registers have the expected state.
26#
27proc_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}"
31
32    # Check SVG to make sure it is correct
33    set expected_svg [expr $svl / 8]
34    gdb_test "print \$svg" "= ${expected_svg}"
35
36    # Make sure there is no SM or ZA state.
37    if [gdb_test "print \$svcr" "= \\\[ \\\]"] {
38	fail "incorrect ZA state"
39	return -1
40    }
41
42    # Check the size of ZA.
43    set expected_za_size [expr $svl * $svl]
44    gdb_test "print sizeof \$za" " = $expected_za_size"
45
46    # Check the size of Z0.
47    gdb_test "print sizeof \$z0" " = $vl"
48
49    # Set the expected ZA pattern.
50    set za_pattern [string_to_regexp [2d_array_value_pattern 0 $svl $svl]]
51
52    # Check ZA.
53    gdb_test "print \$za" $za_pattern
54
55    # Exercise reading/writing the tile slice pseudo-registers.
56    set last_tile 1
57    set last_slice $svl
58    set elements $svl
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}"
66		    # Test the size.
67		    gdb_test "print sizeof ${register_name}" " = ${expected_size}"
68		    gdb_test "print ${register_name}" $pattern
69		}
70	    }
71	}
72	set last_tile [expr $last_tile * 2]
73	set last_slice [expr ($last_slice / 2)]
74	set elements [expr ($elements / 2)]
75    }
76
77    # Exercise reading/writing the tile pseudo-registers.
78    set last_tile 1
79    set elements $svl
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}"
85	    # Test the size.
86	    gdb_test "print sizeof ${register_name}" " = ${expected_size}"
87	    gdb_test "print ${register_name}" $pattern
88	}
89	set last_tile [expr $last_tile * 2]
90	set expected_size [expr $expected_size / 2]
91	set elements [expr ($elements / 2)]
92    }
93
94    # Exercise reading from SME2 registers.
95    if [is_sme2_available] {
96	# The target supports SME2.
97	set zt_size 64
98	gdb_test "print sizeof \$zt0" " = $zt_size"
99
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"
103    }
104}
105
106#
107# Cycle through all ZA registers and pseudo-registers and validate that their
108# contents are unavailable (zeroed out) for vector length SVL.
109#
110proc test_sme_registers_unavailable { id_start id_end } {
111
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}"
115
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}]} {
119	return -1
120    }
121    set binfile [standard_output_file ${executable}]
122
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"
128	return -1
129    }
130
131    if ![runto_main] {
132	untested "could not run to main"
133	return -1
134    }
135
136    gdb_test_no_output "set print repeats 1"
137
138    set prctl_breakpoint "stop 1"
139    gdb_breakpoint [gdb_get_line_number $prctl_breakpoint]
140
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]
144
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
151	    # length.
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."
156	    }
157	    verbose -log "Skipping test."
158	    set skip_unsupported 1
159	}
160
161	with_test_prefix "prctl, vl=${vl} svl=${svl}" {
162	    # If the SVE or SME vector length is not supported, just skip
163	    # these next tests.
164	    if {$skip_unsupported} {
165		untested "unsupported configuration on target"
166		continue
167	    }
168
169	    # Run the program until it has adjusted svl.
170	    gdb_continue_to_breakpoint $prctl_breakpoint
171
172	    check_regs $vl $svl
173	}
174    }
175
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
179
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]
183
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
190	    # length.
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."
195	    }
196	    verbose -log "Skipping test."
197	    set skip_unsupported 1
198	}
199
200	with_test_prefix "gdb, vl=${vl} svl=${svl}" {
201
202	    # If the SVE or SME vector length is not supported, just skip
203	    # these next tests.
204	    if {$skip_unsupported} {
205		untested "unsupported configuration on target"
206		continue
207	    }
208
209	    # Adjust vg and svg.
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}"
214
215	    check_regs $vl $svl
216	}
217    }
218}
219
220require is_aarch64_target
221require allow_aarch64_sve_tests
222require allow_aarch64_sme_tests
223
224test_sme_registers_unavailable $id_start $id_end
225