xref: /linux/tools/testing/selftests/powerpc/math/mma.c (revision 8a922b7728a93d837954315c98b84f6b78de0c4f)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Test basic matrix multiply assist (MMA) functionality if available.
4  *
5  * Copyright 2020, Alistair Popple, IBM Corp.
6  */
7 #include <stdio.h>
8 #include <stdint.h>
9 
10 #include "utils.h"
11 
12 extern void test_mma(uint16_t (*)[8], uint16_t (*)[8], uint32_t (*)[4*4]);
13 
14 static int mma(void)
15 {
16 	int i;
17 	int rc = 0;
18 	uint16_t x[] = {1, 0, 2, 0, 3, 0, 4, 0};
19 	uint16_t y[] = {1, 0, 2, 0, 3, 0, 4, 0};
20 	uint32_t z[4*4];
21 	uint32_t exp[4*4] = {1, 2, 3, 4,
22 			     2, 4, 6, 8,
23 			     3, 6, 9, 12,
24 			     4, 8, 12, 16};
25 
26 	SKIP_IF_MSG(!have_hwcap2(PPC_FEATURE2_ARCH_3_1), "Need ISAv3.1");
27 	SKIP_IF_MSG(!have_hwcap2(PPC_FEATURE2_MMA), "Need MMA");
28 
29 	test_mma(&x, &y, &z);
30 
31 	for (i = 0; i < 16; i++) {
32 		printf("MMA[%d] = %d ", i, z[i]);
33 
34 		if (z[i] == exp[i]) {
35 			printf(" (Correct)\n");
36 		} else {
37 			printf(" (Incorrect)\n");
38 			rc = 1;
39 		}
40 	}
41 
42 	return rc;
43 }
44 
45 int main(int argc, char *argv[])
46 {
47 	return test_harness(mma, "mma");
48 }
49