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" } */
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]; \
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
;
30 for (int l
= 0; l
< n
; l
+= 4)
37 for (int j
= 0; j
< m
; j
+= 16)
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
);
50 for (i
= 0; i
< k
; i
++)
52 vec_t
*rowA
= (vec_t
*) & AO
[i
* 16];
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);
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;
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;
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
]);
118 main (int argc
, char *argv
[])
120 int rowsA
, colsB
, common
;
124 for (int t
= 16; t
<= 128; t
+= 16)
126 for (int t1
= 4; t1
<= 16; t1
+= 4)
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
++)
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
);
171 print ("A", A
, rowsA
, common
);
172 print ("B", B
, common
, colsB
);
173 print ("C", C
, rowsA
, colsB
);
174 print ("D", D
, rowsA
, colsB
);
181 printf ("MMA double test fail: %d errors\n",ret
);
183 printf ("MMA single test success: 0 MMA errors\n");