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