1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2023-2024 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Exercise various cases of reading/writing ZA contents for AArch64's
19 Scalable Matrix Extension. */
23 #include <sys/prctl.h>
29 #define HWCAP_SVE (1 << 22)
33 #define HWCAP2_SME (1 << 23)
37 #define PR_SVE_SET_VL 50
38 #define PR_SVE_GET_VL 51
39 #define PR_SVE_VL_LEN_MASK 0xffff
43 #define PR_SME_SET_VL 63
44 #define PR_SME_GET_VL 64
45 #define PR_SME_VL_LEN_MASK 0xffff
52 __asm
__volatile (".word 0xD503457F");
59 __asm
__volatile (".word 0xD503447F");
62 static int get_vl_size ()
64 int res
= prctl (PR_SVE_GET_VL
, 0, 0, 0, 0);
67 printf ("FAILED to PR_SVE_GET_VL (%d)\n", res
);
70 return (res
& PR_SVE_VL_LEN_MASK
);
73 static int get_svl_size ()
75 int res
= prctl (PR_SME_GET_VL
, 0, 0, 0, 0);
78 printf ("FAILED to PR_SME_GET_VL (%d)\n", res
);
81 return (res
& PR_SVE_VL_LEN_MASK
);
84 static int set_vl_size (int new_vl
)
86 int res
= prctl (PR_SVE_SET_VL
, new_vl
, 0, 0, 0, 0);
89 printf ("FAILED to PR_SVE_SET_VL (%d)\n", res
);
96 printf ("Unexpected VL value (%d)\n", res
);
103 static int set_svl_size (int new_svl
)
105 int res
= prctl (PR_SME_SET_VL
, new_svl
, 0, 0, 0, 0);
108 printf ("FAILED to PR_SME_SET_VL (%d)\n", res
);
112 res
= get_svl_size ();
115 printf ("Unexpected SVL value (%d)\n", res
);
123 test_id_to_vl (int id
)
125 return 16 << ((id
/ 5) % 5);
129 test_id_to_svl (int id
)
131 return 16 << (id
% 5);
140 main (int argc
, char **argv
)
142 if (getauxval (AT_HWCAP
) & HWCAP_SVE
&& getauxval (AT_HWCAP2
) & HWCAP2_SME
)
144 int id_start
= ID_START
;
147 for (int id
= id_start
; id
<= id_end
; id
++)
149 int vl
= test_id_to_vl (id
);
150 int svl
= test_id_to_svl (id
);
152 if (set_vl_size (vl
) == -1 || set_svl_size (svl
) == -1)
156 dummy (); /* stop 1 */
159 for (int id
= id_start
; id
<= id_end
; id
++)
161 int vl
= test_id_to_vl (id
);
162 int svl
= test_id_to_svl (id
);
164 if (set_vl_size (vl
) == -1 || set_svl_size (svl
) == -1)
168 dummy (); /* stop 2 */
173 printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n");