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