Fix build with riscv-gcc version 4.9
[riscv-tests.git] / benchmarks / mm / mm_main.c
1 #include "common.h"
2 #include <assert.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include "util.h"
6
7 void thread_entry(int cid, int nc)
8 {
9 const int R = 8;
10 int m, n, p;
11
12 if (have_vec) {
13 m = HCBM;
14 n = HCBN;
15 p = HCBK;
16 } else {
17 m = CBM;
18 n = CBN;
19 p = CBK;
20 }
21
22 t a[m*p];
23 t b[p*n];
24 t c[m*n];
25
26 for (size_t i = 0; i < m; i++)
27 for (size_t j = 0; j < p; j++)
28 a[i*p+j] = i+j;
29 for (size_t i = 0; i < p; i++)
30 for (size_t j = 0; j < n; j++)
31 b[i*n+j] = i-j;
32 memset(c, 0, m*n*sizeof(c[0]));
33
34 size_t instret, cycles;
35 if (have_vec) {
36 for (int i = 0; i < R; i++)
37 {
38 instret = -rdinstret();
39 cycles = -rdcycle();
40 mm_rb_hwacha(m, n, p, a, p, b, n, c, n);
41 instret += rdinstret();
42 cycles += rdcycle();
43 }
44 } else {
45 for (int i = 0; i < R; i++)
46 {
47 instret = -rdinstret();
48 cycles = -rdcycle();
49 mm(m, n, p, a, p, b, n, c, n);
50 instret += rdinstret();
51 cycles += rdcycle();
52 }
53 }
54
55 printf("C%d: reg block %dx%dx%d, cache block %dx%dx%d\n",
56 cid, RBM, RBN, RBK, CBM, CBN, CBK);
57 printf("C%d: %d instructions\n", cid, (int)(instret));
58 printf("C%d: %d cycles\n", cid, (int)(cycles));
59 printf("C%d: %d flops\n", cid, 2*m*n*p);
60 printf("C%d: %d Mflops @ 1 GHz\n", cid, 2000*m*n*p/(cycles));
61
62 #if 1
63 for (size_t i = 0; i < m; i++)
64 {
65 for (size_t j = 0; j < n; j++)
66 {
67 t s = 0;
68 for (size_t aik = i, bkj = -j; aik < i+p; aik++, bkj++)
69 s += (t)aik*(t)bkj;
70 if (fabs(c[i*n+j]-s*R) > 1e-6*s)
71 {
72 printf("C%d: c[%lu][%lu] %f != %f\n", cid, i, j, c[i*n+j], s);
73 exit(1);
74 }
75 }
76 }
77 #endif
78
79 barrier(nc);
80 exit(0);
81 }