]>
Commit | Line | Data |
---|---|---|
16582a51 LM |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | Copyright 2023-2024 Free Software Foundation, Inc. |
16582a51 LM |
4 | |
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
17 | ||
18 | /* Exercise various cases of ZA contents not being available for AArch64's | |
19 | Scalable Matrix Extension. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <sys/auxv.h> | |
23 | #include <sys/prctl.h> | |
24 | #include <stdlib.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #ifndef HWCAP_SVE | |
28 | #define HWCAP_SVE (1 << 22) | |
29 | #endif | |
30 | ||
31 | #ifndef HWCAP2_SME | |
32 | #define HWCAP2_SME (1 << 23) | |
33 | #endif | |
34 | ||
35 | #ifndef PR_SVE_SET_VL | |
36 | #define PR_SVE_SET_VL 50 | |
37 | #define PR_SVE_GET_VL 51 | |
38 | #define PR_SVE_VL_LEN_MASK 0xffff | |
39 | #endif | |
40 | ||
41 | #ifndef PR_SME_SET_VL | |
42 | #define PR_SME_SET_VL 63 | |
43 | #define PR_SME_GET_VL 64 | |
44 | #define PR_SME_VL_LEN_MASK 0xffff | |
45 | #endif | |
46 | ||
47 | static int get_vl_size () | |
48 | { | |
49 | int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); | |
50 | if (res < 0) | |
51 | { | |
52 | printf ("FAILED to PR_SVE_GET_VL (%d)\n", res); | |
53 | return -1; | |
54 | } | |
55 | return (res & PR_SVE_VL_LEN_MASK); | |
56 | } | |
57 | ||
58 | static int get_svl_size () | |
59 | { | |
60 | int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0); | |
61 | if (res < 0) | |
62 | { | |
63 | printf ("FAILED to PR_SME_GET_VL (%d)\n", res); | |
64 | return -1; | |
65 | } | |
66 | return (res & PR_SVE_VL_LEN_MASK); | |
67 | } | |
68 | ||
69 | static int set_vl_size (int new_vl) | |
70 | { | |
71 | int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0); | |
72 | if (res < 0) | |
73 | { | |
74 | printf ("FAILED to PR_SVE_SET_VL (%d)\n", res); | |
75 | return -1; | |
76 | } | |
77 | ||
78 | res = get_vl_size (); | |
79 | if (res != new_vl) | |
80 | { | |
81 | printf ("Unexpected VL value (%d)\n", res); | |
82 | return -1; | |
83 | } | |
84 | ||
85 | return res; | |
86 | } | |
87 | ||
88 | static int set_svl_size (int new_svl) | |
89 | { | |
90 | int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0); | |
91 | if (res < 0) | |
92 | { | |
93 | printf ("FAILED to PR_SME_SET_VL (%d)\n", res); | |
94 | return -1; | |
95 | } | |
96 | ||
97 | res = get_svl_size (); | |
98 | if (res != new_svl) | |
99 | { | |
100 | printf ("Unexpected SVL value (%d)\n", res); | |
101 | return -1; | |
102 | } | |
103 | ||
104 | return res; | |
105 | } | |
106 | ||
107 | static int | |
108 | test_id_to_vl (int id) | |
109 | { | |
110 | return 16 << ((id / 5) % 5); | |
111 | } | |
112 | ||
113 | static int | |
114 | test_id_to_svl (int id) | |
115 | { | |
116 | return 16 << (id % 5); | |
117 | } | |
118 | ||
119 | static void | |
120 | dummy () | |
121 | { | |
122 | } | |
123 | ||
124 | int | |
125 | main (int argc, char **argv) | |
126 | { | |
127 | if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME) | |
128 | { | |
129 | int id_start = ID_START; | |
130 | int id_end = ID_END; | |
131 | ||
132 | for (int id = id_start; id <= id_end; id++) | |
133 | { | |
134 | int vl = test_id_to_vl (id); | |
135 | int svl = test_id_to_svl (id); | |
136 | ||
137 | if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1) | |
138 | continue; | |
139 | ||
140 | dummy (); /* stop 1 */ | |
141 | } | |
142 | ||
143 | dummy (); /* stop 2 */ | |
144 | } | |
145 | else | |
146 | { | |
147 | printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n"); | |
148 | return -1; | |
149 | } | |
150 | ||
151 | return 0; | |
152 | } |