tests/tcg/aarch64: Add test cases for SME FMOPA (widening)
[qemu/ar7.git] / tests / tcg / aarch64 / sme-fmopa-1.c
blob652c4ea090274bc8103dcd5cf83bca64444be1bf
1 /*
2 * SME outer product, 1 x 1.
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
6 #include <stdio.h>
8 static void foo(float *dst)
10 asm(".arch_extension sme\n\t"
11 "smstart\n\t"
12 "ptrue p0.s, vl4\n\t"
13 "fmov z0.s, #1.0\n\t"
15 * An outer product of a vector of 1.0 by itself should be a matrix of 1.0.
16 * Note that we are using tile 1 here (za1.s) rather than tile 0.
18 "zero {za}\n\t"
19 "fmopa za1.s, p0/m, p0/m, z0.s, z0.s\n\t"
21 * Read the first 4x4 sub-matrix of elements from tile 1:
22 * Note that za1h should be interchangeable here.
24 "mov w12, #0\n\t"
25 "mova z0.s, p0/m, za1v.s[w12, #0]\n\t"
26 "mova z1.s, p0/m, za1v.s[w12, #1]\n\t"
27 "mova z2.s, p0/m, za1v.s[w12, #2]\n\t"
28 "mova z3.s, p0/m, za1v.s[w12, #3]\n\t"
30 * And store them to the input pointer (dst in the C code):
32 "st1w {z0.s}, p0, [%0]\n\t"
33 "add x0, x0, #16\n\t"
34 "st1w {z1.s}, p0, [x0]\n\t"
35 "add x0, x0, #16\n\t"
36 "st1w {z2.s}, p0, [x0]\n\t"
37 "add x0, x0, #16\n\t"
38 "st1w {z3.s}, p0, [x0]\n\t"
39 "smstop"
40 : : "r"(dst)
41 : "x12", "d0", "d1", "d2", "d3", "memory");
44 int main()
46 float dst[16] = { };
48 foo(dst);
50 for (int i = 0; i < 16; i++) {
51 if (dst[i] != 1.0f) {
52 goto failure;
55 /* success */
56 return 0;
58 failure:
59 for (int i = 0; i < 16; i++) {
60 printf("%f%c", dst[i], i % 4 == 3 ? '\n' : ' ');
62 return 1;