diagnostics: move output formats from diagnostic.{c,h} to their own files
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / mma-double-test.c
blob254af7f8f79e2766fd1bdad9a518b6e3d7c85031
1 /* { dg-do run { target { power10_hw } } } */
2 /* { dg-do link { target { ! power10_hw } } } */
3 /* { dg-require-effective-target power10_ok } */
4 /* { dg-require-effective-target ppc_mma_hw } */
5 /* { dg-options "-mdejagnu-cpu=power10 -O2" } */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <altivec.h>
11 typedef unsigned char vec_t __attribute__ ((vector_size (16)));
12 typedef double v4sf_t __attribute__ ((vector_size (16)));
13 #define SAVE_ACC(ACC, ldc, J) \
14 __builtin_mma_disassemble_acc (result, ACC); \
15 rowC = (v4sf_t *) &CO[0*ldc+J]; \
16 rowC[0] += result[0]; \
17 rowC = (v4sf_t *) &CO[1*ldc+J]; \
18 rowC[0] += result[1]; \
19 rowC = (v4sf_t *) &CO[2*ldc+J]; \
20 rowC[0] += result[2]; \
21 rowC = (v4sf_t *) &CO[3*ldc+J]; \
22 rowC[0] += result[3];
24 void
25 MMA (int m, int n, int k, double *A, double *B, double *C)
27 __vector_quad acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7;
28 v4sf_t result[4];
29 v4sf_t *rowC;
30 for (int l = 0; l < n; l += 4)
32 double *CO;
33 double *AO;
34 AO = A;
35 CO = C;
36 C += m * 4;
37 for (int j = 0; j < m; j += 16)
39 double *BO = B;
40 __builtin_mma_xxsetaccz (&acc0);
41 __builtin_mma_xxsetaccz (&acc1);
42 __builtin_mma_xxsetaccz (&acc2);
43 __builtin_mma_xxsetaccz (&acc3);
44 __builtin_mma_xxsetaccz (&acc4);
45 __builtin_mma_xxsetaccz (&acc5);
46 __builtin_mma_xxsetaccz (&acc6);
47 __builtin_mma_xxsetaccz (&acc7);
48 unsigned long i;
50 for (i = 0; i < k; i++)
52 vec_t *rowA = (vec_t *) & AO[i * 16];
53 __vector_pair rowB;
54 vec_t *rb = (vec_t *) & BO[i * 4];
55 __builtin_mma_assemble_pair (&rowB, rb[1], rb[0]);
56 __builtin_mma_xvf64gerpp (&acc0, rowB, rowA[0]);
57 __builtin_mma_xvf64gerpp (&acc1, rowB, rowA[1]);
58 __builtin_mma_xvf64gerpp (&acc2, rowB, rowA[2]);
59 __builtin_mma_xvf64gerpp (&acc3, rowB, rowA[3]);
60 __builtin_mma_xvf64gerpp (&acc4, rowB, rowA[4]);
61 __builtin_mma_xvf64gerpp (&acc5, rowB, rowA[5]);
62 __builtin_mma_xvf64gerpp (&acc6, rowB, rowA[6]);
63 __builtin_mma_xvf64gerpp (&acc7, rowB, rowA[7]);
65 SAVE_ACC (&acc0, m, 0);
66 SAVE_ACC (&acc2, m, 4);
67 SAVE_ACC (&acc1, m, 2);
68 SAVE_ACC (&acc3, m, 6);
69 SAVE_ACC (&acc4, m, 8);
70 SAVE_ACC (&acc6, m, 12);
71 SAVE_ACC (&acc5, m, 10);
72 SAVE_ACC (&acc7, m, 14);
73 AO += k * 16;
74 BO += k * 4;
75 CO += 16;
77 B += k * 4;
81 void
82 init (double *matrix, int row, int column)
84 for (int j = 0; j < column; j++)
86 for (int i = 0; i < row; i++)
88 matrix[j * row + i] = (i * 16 + 2 + j) / 0.123;
93 void
94 init0 (double *matrix, double *matrix1, int row, int column)
96 for (int j = 0; j < column; j++)
97 for (int i = 0; i < row; i++)
98 matrix[j * row + i] = matrix1[j * row + i] = 0;
102 void
103 print (const char *name, const double *matrix, int row, int column)
105 printf ("Matrix %s has %d rows and %d columns:\n", name, row, column);
106 for (int i = 0; i < row; i++)
108 for (int j = 0; j < column; j++)
110 printf ("%f ", matrix[j * row + i]);
112 printf ("\n");
114 printf ("\n");
118 main (int argc, char *argv[])
120 int rowsA, colsB, common;
121 int i, j, k;
122 int ret = 0;
124 for (int t = 16; t <= 128; t += 16)
126 for (int t1 = 4; t1 <= 16; t1 += 4)
128 rowsA = t;
129 colsB = t1;
130 common = 1;
131 /* printf ("Running test for rows = %d,cols = %d\n", t, t1); */
132 double A[rowsA * common];
133 double B[common * colsB];
134 double C[rowsA * colsB];
135 double D[rowsA * colsB];
138 init (A, rowsA, common);
139 init (B, common, colsB);
140 init0 (C, D, rowsA, colsB);
141 MMA (rowsA, colsB, common, A, B, C);
143 for (i = 0; i < colsB; i++)
145 for (j = 0; j < rowsA; j++)
147 D[i * rowsA + j] = 0;
148 for (k = 0; k < common; k++)
150 D[i * rowsA + j] +=
151 A[k * rowsA + j] * B[k + common * i];
155 for (i = 0; i < colsB; i++)
157 for (j = 0; j < rowsA; j++)
159 for (k = 0; k < common; k++)
161 if (D[i * rowsA + j] != C[i * rowsA + j])
163 printf ("Error %d,%d,%d\n",i,j,k);
164 ret++;
169 if (ret)
171 print ("A", A, rowsA, common);
172 print ("B", B, common, colsB);
173 print ("C", C, rowsA, colsB);
174 print ("D", D, rowsA, colsB);
179 #ifdef VERBOSE
180 if (ret)
181 printf ("MMA double test fail: %d errors\n",ret);
182 else
183 printf ("MMA single test success: 0 MMA errors\n");
184 #else
185 if (ret)
186 abort();
187 #endif
189 return ret;