c12d854bd70f26d4c2f6c7cdffae70523f8b48ad
[riscv-tests.git] / benchmarks / mm / hwacha.h
1 static const int HCBM = 18;
2 static const int HCBN = 80;
3 static const int HCBK = 16;
4
5 static const int HRBM = 18;
6 static const int HRBN = 80;
7 static const int HRBK = 1;
8
9 extern void hwacha_mm_0();
10 extern void hwacha_mm_1();
11 extern void hwacha_mm_2();
12 extern void hwacha_mm_3();
13 extern void hwacha_mm_4();
14 extern void hwacha_mm_5();
15 extern void hwacha_mm_6();
16 extern void hwacha_mm_7();
17 extern void hwacha_mm_8();
18 extern void hwacha_mm_9();
19 extern void hwacha_mm_10();
20 extern void hwacha_mm_11();
21 extern void hwacha_mm_12();
22 extern void hwacha_mm_13();
23 extern void hwacha_mm_14();
24 extern void hwacha_mm_15();
25 extern void hwacha_mm_16();
26 extern void hwacha_mm_17();
27
28 static inline void nloop(int s, int e, t* a, size_t lda, t* b, size_t ldb, t* c, size_t ldc)
29 {
30 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[0*lda]));
31 asm volatile ("vfld vf20, %[ptr]" : : [ptr]"r"(b) : );
32 if (s) asm volatile ("vfld vf0, %[ptr]" : : [ptr]"r"(&c[ldc*0]) : );
33 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_0) : );
34 if (e) asm volatile ("vfsd vf0, %[ptr]" : : [ptr]"r"(&c[ldc*0]) : );
35
36 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[1*lda]));
37 if (s) asm volatile ("vfld vf1, %[ptr]" : : [ptr]"r"(&c[ldc*1]) : );
38 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_1) : );
39 if (e) asm volatile ("vfsd vf1, %[ptr]" : : [ptr]"r"(&c[ldc*1]) : );
40
41 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[2*lda]));
42 if (s) asm volatile ("vfld vf2, %[ptr]" : : [ptr]"r"(&c[ldc*2]) : );
43 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_2) : );
44 if (e) asm volatile ("vfsd vf2, %[ptr]" : : [ptr]"r"(&c[ldc*2]) : );
45
46 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[3*lda]));
47 if (s) asm volatile ("vfld vf3, %[ptr]" : : [ptr]"r"(&c[ldc*3]) : );
48 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_3) : );
49 if (e) asm volatile ("vfsd vf3, %[ptr]" : : [ptr]"r"(&c[ldc*3]) : );
50
51 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[4*lda]));
52 if (s) asm volatile ("vfld vf4, %[ptr]" : : [ptr]"r"(&c[ldc*4]) : );
53 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_4) : );
54 if (e) asm volatile ("vfsd vf4, %[ptr]" : : [ptr]"r"(&c[ldc*4]) : );
55
56 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[5*lda]));
57 if (s) asm volatile ("vfld vf5, %[ptr]" : : [ptr]"r"(&c[ldc*5]) : );
58 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_5) : );
59 if (e) asm volatile ("vfsd vf5, %[ptr]" : : [ptr]"r"(&c[ldc*5]) : );
60
61 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[6*lda]));
62 if (s) asm volatile ("vfld vf6, %[ptr]" : : [ptr]"r"(&c[ldc*6]) : );
63 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_6) : );
64 if (e) asm volatile ("vfsd vf6, %[ptr]" : : [ptr]"r"(&c[ldc*6]) : );
65
66 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[7*lda]));
67 if (s) asm volatile ("vfld vf7, %[ptr]" : : [ptr]"r"(&c[ldc*7]) : );
68 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_7) : );
69 if (e) asm volatile ("vfsd vf7, %[ptr]" : : [ptr]"r"(&c[ldc*7]) : );
70
71 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[8*lda]));
72 if (s) asm volatile ("vfld vf8, %[ptr]" : : [ptr]"r"(&c[ldc*8]) : );
73 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_8) : );
74 if (e) asm volatile ("vfsd vf8, %[ptr]" : : [ptr]"r"(&c[ldc*8]) : );
75
76 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[9*lda]));
77 if (s) asm volatile ("vfld vf9, %[ptr]" : : [ptr]"r"(&c[ldc*9]) : );
78 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_9) : );
79 if (e) asm volatile ("vfsd vf9, %[ptr]" : : [ptr]"r"(&c[ldc*9]) : );
80
81 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[10*lda]));
82 if (s) asm volatile ("vfld vf10, %[ptr]" : : [ptr]"r"(&c[ldc*10]) : );
83 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_10) : );
84 if (e) asm volatile ("vfsd vf10, %[ptr]" : : [ptr]"r"(&c[ldc*10]) : );
85
86 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[11*lda]));
87 if (s) asm volatile ("vfld vf11, %[ptr]" : : [ptr]"r"(&c[ldc*11]) : );
88 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_11) : );
89 if (e) asm volatile ("vfsd vf11, %[ptr]" : : [ptr]"r"(&c[ldc*11]) : );
90
91 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[12*lda]));
92 if (s) asm volatile ("vfld vf12, %[ptr]" : : [ptr]"r"(&c[ldc*12]) : );
93 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_12) : );
94 if (e) asm volatile ("vfsd vf12, %[ptr]" : : [ptr]"r"(&c[ldc*12]) : );
95
96 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[13*lda]));
97 if (s) asm volatile ("vfld vf13, %[ptr]" : : [ptr]"r"(&c[ldc*13]) : );
98 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_13) : );
99 if (e) asm volatile ("vfsd vf13, %[ptr]" : : [ptr]"r"(&c[ldc*13]) : );
100
101 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[14*lda]));
102 if (s) asm volatile ("vfld vf14, %[ptr]" : : [ptr]"r"(&c[ldc*14]) : );
103 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_14) : );
104 if (e) asm volatile ("vfsd vf14, %[ptr]" : : [ptr]"r"(&c[ldc*14]) : );
105
106 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[15*lda]));
107 if (s) asm volatile ("vfld vf15, %[ptr]" : : [ptr]"r"(&c[ldc*15]) : );
108 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_15) : );
109 if (e) asm volatile ("vfsd vf15, %[ptr]" : : [ptr]"r"(&c[ldc*15]) : );
110
111 asm volatile ("vfmsv.d vf19, %[ptr]" : : [ptr]"r"(a[16*lda]));
112 if (s) asm volatile ("vfld vf16, %[ptr]" : : [ptr]"r"(&c[ldc*16]) : );
113 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_16) : );
114 if (e) asm volatile ("vfsd vf16, %[ptr]" : : [ptr]"r"(&c[ldc*16]) : );
115
116 asm volatile ("vfmsv.d vf18, %[ptr]" : : [ptr]"r"(a[17*lda]));
117 if (s) asm volatile ("vfld vf17, %[ptr]" : : [ptr]"r"(&c[ldc*17]) : );
118 asm volatile ("vf 0(%[vf_ptr])" : : [vf_ptr]"r"(&hwacha_mm_17) : );
119 if (e) asm volatile ("vfsd vf17, %[ptr]" : : [ptr]"r"(&c[ldc*17]) : );
120 }
121
122 static inline void mm_rb_hwacha(size_t m, size_t n, size_t p,
123 t* a, size_t lda, t* b, size_t ldb, t* c, size_t ldc)
124 {
125 int vl;
126 asm volatile ("vsetcfg 4, 21" : : : );
127 asm volatile ("vsetvl %[gvl], %[nvl]" : [gvl]"=r"(vl) : [nvl]"r"(n) : );
128
129 size_t mb = m/HRBM*HRBM, nk=p/HRBK*HRBK;
130
131 for (size_t i=0; i<mb; i+=HRBM)
132 {
133 for (size_t k=0; k<nk; k+=HRBK)
134 {
135 nloop(k==0, k==(p-1), a+i*lda+k, lda, b+k*ldb, ldb, c+i*ldc, ldc);
136 }
137 }
138 }