1*f103ecccSDaniyal Khan /*
2*f103ecccSDaniyal Khan * SME outer product, 1 x 1.
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
foo(float * dst)8*f103ecccSDaniyal Khan static void foo(float *dst)
9*f103ecccSDaniyal Khan {
10*f103ecccSDaniyal Khan asm(".arch_extension sme\n\t"
11*f103ecccSDaniyal Khan "smstart\n\t"
12*f103ecccSDaniyal Khan "ptrue p0.s, vl4\n\t"
13*f103ecccSDaniyal Khan "fmov z0.s, #1.0\n\t"
14*f103ecccSDaniyal Khan /*
15*f103ecccSDaniyal Khan * An outer product of a vector of 1.0 by itself should be a matrix of 1.0.
16*f103ecccSDaniyal Khan * Note that we are using tile 1 here (za1.s) rather than tile 0.
17*f103ecccSDaniyal Khan */
18*f103ecccSDaniyal Khan "zero {za}\n\t"
19*f103ecccSDaniyal Khan "fmopa za1.s, p0/m, p0/m, z0.s, z0.s\n\t"
20*f103ecccSDaniyal Khan /*
21*f103ecccSDaniyal Khan * Read the first 4x4 sub-matrix of elements from tile 1:
22*f103ecccSDaniyal Khan * Note that za1h should be interchangeable here.
23*f103ecccSDaniyal Khan */
24*f103ecccSDaniyal Khan "mov w12, #0\n\t"
25*f103ecccSDaniyal Khan "mova z0.s, p0/m, za1v.s[w12, #0]\n\t"
26*f103ecccSDaniyal Khan "mova z1.s, p0/m, za1v.s[w12, #1]\n\t"
27*f103ecccSDaniyal Khan "mova z2.s, p0/m, za1v.s[w12, #2]\n\t"
28*f103ecccSDaniyal Khan "mova z3.s, p0/m, za1v.s[w12, #3]\n\t"
29*f103ecccSDaniyal Khan /*
30*f103ecccSDaniyal Khan * And store them to the input pointer (dst in the C code):
31*f103ecccSDaniyal Khan */
32*f103ecccSDaniyal Khan "st1w {z0.s}, p0, [%0]\n\t"
33*f103ecccSDaniyal Khan "add x0, x0, #16\n\t"
34*f103ecccSDaniyal Khan "st1w {z1.s}, p0, [x0]\n\t"
35*f103ecccSDaniyal Khan "add x0, x0, #16\n\t"
36*f103ecccSDaniyal Khan "st1w {z2.s}, p0, [x0]\n\t"
37*f103ecccSDaniyal Khan "add x0, x0, #16\n\t"
38*f103ecccSDaniyal Khan "st1w {z3.s}, p0, [x0]\n\t"
39*f103ecccSDaniyal Khan "smstop"
40*f103ecccSDaniyal Khan : : "r"(dst)
41*f103ecccSDaniyal Khan : "x12", "d0", "d1", "d2", "d3", "memory");
42*f103ecccSDaniyal Khan }
43*f103ecccSDaniyal Khan
main()44*f103ecccSDaniyal Khan int main()
45*f103ecccSDaniyal Khan {
46*f103ecccSDaniyal Khan float dst[16] = { };
47*f103ecccSDaniyal Khan
48*f103ecccSDaniyal Khan foo(dst);
49*f103ecccSDaniyal Khan
50*f103ecccSDaniyal Khan for (int i = 0; i < 16; i++) {
51*f103ecccSDaniyal Khan if (dst[i] != 1.0f) {
52*f103ecccSDaniyal Khan goto failure;
53*f103ecccSDaniyal Khan }
54*f103ecccSDaniyal Khan }
55*f103ecccSDaniyal Khan /* success */
56*f103ecccSDaniyal Khan return 0;
57*f103ecccSDaniyal Khan
58*f103ecccSDaniyal Khan failure:
59*f103ecccSDaniyal Khan for (int i = 0; i < 16; i++) {
60*f103ecccSDaniyal Khan printf("%f%c", dst[i], i % 4 == 3 ? '\n' : ' ');
61*f103ecccSDaniyal Khan }
62*f103ecccSDaniyal Khan return 1;
63*f103ecccSDaniyal Khan }
64