xref: /openbmc/qemu/tests/tcg/aarch64/sve-str.c (revision 1a1e889f)
1 #include <stdio.h>
2 #include <sys/prctl.h>
3 
4 #define N  (256 + 16)
5 
6 static int __attribute__((noinline)) test(int vl)
7 {
8     unsigned char buf[N];
9     int err = 0;
10 
11     for (int i = 0; i < N; ++i) {
12         buf[i] = (unsigned char)i;
13     }
14 
15     asm volatile (
16         "mov z0.b, #255\n\t"
17         "str z0, %0"
18         : : "m" (buf) : "z0", "memory");
19 
20     for (int i = 0; i < vl; ++i) {
21         if (buf[i] != 0xff) {
22             fprintf(stderr, "vl %d, index %d, expected 255, got %d\n",
23                     vl, i, buf[i]);
24             err = 1;
25         }
26     }
27 
28     for (int i = vl; i < N; ++i) {
29         if (buf[i] != (unsigned char)i) {
30             fprintf(stderr, "vl %d, index %d, expected %d, got %d\n",
31                     vl, i, (unsigned char)i, buf[i]);
32             err = 1;
33         }
34     }
35 
36     return err;
37 }
38 
39 int main()
40 {
41     int err = 0;
42 
43     for (int i = 16; i <= 256; i += 16) {
44         if (prctl(PR_SVE_SET_VL, i, 0, 0, 0, 0) == i) {
45             err |= test(i);
46         }
47     }
48     return err;
49 }
50