xref: /openbmc/qemu/tests/tcg/aarch64/sme-fmopa-3.c (revision f103eccc)
1 /*
2  * SME outer product, [ 1 2 3 4 ] squared
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  */
5 
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <string.h>
9 #include <math.h>
10 
11 static const float i_1234[4] = {
12     1.0f, 2.0f, 3.0f, 4.0f
13 };
14 
15 static const float expected[4] = {
16     4.515625f, 5.750000f, 6.984375f, 8.218750f
17 };
18 
test_fmopa(float * result)19 static void test_fmopa(float *result)
20 {
21     asm(".arch_extension sme\n\t"
22         "smstart\n\t"               /* ZArray cleared */
23         "ptrue p2.b, vl16\n\t"      /* Limit vector length to 16 */
24         "ld1w {z0.s}, p2/z, [%1]\n\t"
25         "mov w15, #0\n\t"
26         "mov za3h.s[w15, 0], p2/m, z0.s\n\t"
27         "mov za3h.s[w15, 1], p2/m, z0.s\n\t"
28         "mov w15, #2\n\t"
29         "mov za3h.s[w15, 0], p2/m, z0.s\n\t"
30         "mov za3h.s[w15, 1], p2/m, z0.s\n\t"
31         "msr fpcr, xzr\n\t"
32         "fmopa za3.s, p2/m, p2/m, z0.h, z0.h\n\t"
33         "mov w15, #0\n\t"
34         "st1w {za3h.s[w15, 0]}, p2, [%0]\n"
35         "add %0, %0, #16\n\t"
36         "st1w {za3h.s[w15, 1]}, p2, [%0]\n\t"
37         "mov w15, #2\n\t"
38         "add %0, %0, #16\n\t"
39         "st1w {za3h.s[w15, 0]}, p2, [%0]\n\t"
40         "add %0, %0, #16\n\t"
41         "st1w {za3h.s[w15, 1]}, p2, [%0]\n\t"
42         "smstop"
43         : "+r"(result) : "r"(i_1234)
44         : "x15", "x16", "p2", "d0", "memory");
45 }
46 
main(void)47 int main(void)
48 {
49     float result[4 * 4] = { };
50     int ret = 0;
51 
52     test_fmopa(result);
53 
54     for (int i = 0; i < 4; i++) {
55         float actual = result[i];
56         if (fabsf(actual - expected[i]) > 0.001f) {
57             printf("Test failed at element %d: Expected %f, got %f\n",
58                    i, expected[i], actual);
59             ret = 1;
60         }
61     }
62     return ret;
63 }
64