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 ZA contents not being available for AArch64's
19 Scalable Matrix Extension. */
23 #include <sys/prctl.h>
28 #define HWCAP_SVE (1 << 22)
32 #define HWCAP2_SME (1 << 23)
36 #define PR_SVE_SET_VL 50
37 #define PR_SVE_GET_VL 51
38 #define PR_SVE_VL_LEN_MASK 0xffff
42 #define PR_SME_SET_VL 63
43 #define PR_SME_GET_VL 64
44 #define PR_SME_VL_LEN_MASK 0xffff
47 static int get_vl_size ()
49 int res
= prctl (PR_SVE_GET_VL
, 0, 0, 0, 0);
52 printf ("FAILED to PR_SVE_GET_VL (%d)\n", res
);
55 return (res
& PR_SVE_VL_LEN_MASK
);
58 static int get_svl_size ()
60 int res
= prctl (PR_SME_GET_VL
, 0, 0, 0, 0);
63 printf ("FAILED to PR_SME_GET_VL (%d)\n", res
);
66 return (res
& PR_SVE_VL_LEN_MASK
);
69 static int set_vl_size (int new_vl
)
71 int res
= prctl (PR_SVE_SET_VL
, new_vl
, 0, 0, 0, 0);
74 printf ("FAILED to PR_SVE_SET_VL (%d)\n", res
);
81 printf ("Unexpected VL value (%d)\n", res
);
88 static int set_svl_size (int new_svl
)
90 int res
= prctl (PR_SME_SET_VL
, new_svl
, 0, 0, 0, 0);
93 printf ("FAILED to PR_SME_SET_VL (%d)\n", res
);
97 res
= get_svl_size ();
100 printf ("Unexpected SVL value (%d)\n", res
);
108 test_id_to_vl (int id
)
110 return 16 << ((id
/ 5) % 5);
114 test_id_to_svl (int id
)
116 return 16 << (id
% 5);
125 main (int argc
, char **argv
)
127 if (getauxval (AT_HWCAP
) & HWCAP_SVE
&& getauxval (AT_HWCAP2
) & HWCAP2_SME
)
129 int id_start
= ID_START
;
132 for (int id
= id_start
; id
<= id_end
; id
++)
134 int vl
= test_id_to_vl (id
);
135 int svl
= test_id_to_svl (id
);
137 if (set_vl_size (vl
) == -1 || set_svl_size (svl
) == -1)
140 dummy (); /* stop 1 */
143 dummy (); /* stop 2 */
147 printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n");