You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

trmmkernel_rvv_v1x8.c 24 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /***************************************************************************
  2. Copyright (c) 2022, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #include "common.h"
  28. #if !defined(DOUBLE)
  29. #define VSETVL(n) vsetvl_e32m2(n)
  30. #define FLOAT_V_T vfloat32m2_t
  31. #define VLEV_FLOAT vle32_v_f32m2
  32. #define VSEV_FLOAT vse32_v_f32m2
  33. #define VFMVVF_FLOAT vfmv_v_f_f32m2
  34. #define VFMACCVF_FLOAT vfmacc_vf_f32m2
  35. #define VFMULVF_FLOAT vfmul_vf_f32m2
  36. #else
  37. #define VSETVL(n) vsetvl_e64m2(n)
  38. #define FLOAT_V_T vfloat64m2_t
  39. #define VLEV_FLOAT vle64_v_f64m2
  40. #define VSEV_FLOAT vse64_v_f64m2
  41. #define VFMVVF_FLOAT vfmv_v_f_f64m2
  42. #define VFMACCVF_FLOAT vfmacc_vf_f64m2
  43. #define VFMULVF_FLOAT vfmul_vf_f64m2
  44. #endif
  45. // Optimizes the implementation in ../generic/trmmkernel_8x8.c
  46. int CNAME(BLASLONG bm,BLASLONG bn,BLASLONG bk,FLOAT alpha,FLOAT* ba,FLOAT* bb,FLOAT* C,BLASLONG ldc ,BLASLONG offset)
  47. {
  48. //fprintf(stderr, "%s, %s, bm=%4ld bn=%4ld bk=%4ld alpha=%f ldc=%ld\n", __FILE__, __FUNCTION__, bm, bn, bk, alpha, ldc);
  49. BLASLONG i,j,k;
  50. FLOAT *C0,*C1,*C2,*C3,*C4,*C5,*C6,*C7,*ptrba,*ptrbb;
  51. FLOAT_V_T va0, va1, va2, va3, va4, va5, va6, va7;
  52. FLOAT_V_T vres0, vres1, vres2, vres3, vres4, vres5, vres6, vres7;
  53. size_t vl;
  54. BLASLONG off, temp;
  55. #if !defined(LEFT)
  56. off = -offset;
  57. #else
  58. off = 0;
  59. #endif
  60. for (j = bn/8; j > 0; j--)
  61. {
  62. C0 = C;
  63. C1 = C0+ldc;
  64. C2 = C1+ldc;
  65. C3 = C2+ldc;
  66. C4 = C3+ldc;
  67. C5 = C4+ldc;
  68. C6 = C5+ldc;
  69. C7 = C6+ldc;
  70. #if defined(TRMMKERNEL) && defined(LEFT)
  71. off = offset;
  72. #endif
  73. ptrba = ba;
  74. for (i = bm; i > 0; i -= vl)
  75. {
  76. vl = VSETVL(i);
  77. #if (defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  78. ptrbb = bb;
  79. #else
  80. ptrba += off*vl;
  81. ptrbb = bb + off*8;
  82. #endif
  83. vres0 = VFMVVF_FLOAT(0.0, vl);
  84. vres1 = VFMVVF_FLOAT(0.0, vl);
  85. vres2 = VFMVVF_FLOAT(0.0, vl);
  86. vres3 = VFMVVF_FLOAT(0.0, vl);
  87. vres4 = VFMVVF_FLOAT(0.0, vl);
  88. vres5 = VFMVVF_FLOAT(0.0, vl);
  89. vres6 = VFMVVF_FLOAT(0.0, vl);
  90. vres7 = VFMVVF_FLOAT(0.0, vl);
  91. #if (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA))
  92. temp = bk-off;
  93. #elif defined(LEFT)
  94. temp = off+vl; // number of values in A
  95. #else
  96. temp = off+8; // number of values in B
  97. #endif
  98. for (k = temp/8; k > 0; k--) {
  99. va0 = VLEV_FLOAT(ptrba, vl);
  100. ptrba += vl;
  101. va1 = VLEV_FLOAT(ptrba, vl);
  102. ptrba += vl;
  103. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  104. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va0, vl);
  105. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va0, vl);
  106. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va0, vl);
  107. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va0, vl);
  108. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va0, vl);
  109. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va0, vl);
  110. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va0, vl);
  111. ptrbb += 8;
  112. va2 = VLEV_FLOAT(ptrba, vl);
  113. ptrba += vl;
  114. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va1, vl);
  115. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va1, vl);
  116. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va1, vl);
  117. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va1, vl);
  118. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va1, vl);
  119. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va1, vl);
  120. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va1, vl);
  121. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va1, vl);
  122. ptrbb += 8;
  123. va3 = VLEV_FLOAT(ptrba, vl);
  124. ptrba += vl;
  125. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va2, vl);
  126. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va2, vl);
  127. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va2, vl);
  128. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va2, vl);
  129. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va2, vl);
  130. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va2, vl);
  131. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va2, vl);
  132. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va2, vl);
  133. ptrbb += 8;
  134. va4 = VLEV_FLOAT(ptrba, vl);
  135. ptrba += vl;
  136. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va3, vl);
  137. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va3, vl);
  138. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va3, vl);
  139. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va3, vl);
  140. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va3, vl);
  141. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va3, vl);
  142. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va3, vl);
  143. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va3, vl);
  144. ptrbb += 8;
  145. va5 = VLEV_FLOAT(ptrba, vl);
  146. ptrba += vl;
  147. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va4, vl);
  148. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va4, vl);
  149. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va4, vl);
  150. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va4, vl);
  151. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va4, vl);
  152. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va4, vl);
  153. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va4, vl);
  154. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va4, vl);
  155. ptrbb += 8;
  156. va6 = VLEV_FLOAT(ptrba, vl);
  157. ptrba += vl;
  158. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va5, vl);
  159. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va5, vl);
  160. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va5, vl);
  161. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va5, vl);
  162. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va5, vl);
  163. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va5, vl);
  164. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va5, vl);
  165. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va5, vl);
  166. ptrbb += 8;
  167. va7 = VLEV_FLOAT(ptrba, vl);
  168. ptrba += vl;
  169. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va6, vl);
  170. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va6, vl);
  171. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va6, vl);
  172. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va6, vl);
  173. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va6, vl);
  174. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va6, vl);
  175. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va6, vl);
  176. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va6, vl);
  177. ptrbb += 8;
  178. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va7, vl);
  179. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va7, vl);
  180. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va7, vl);
  181. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va7, vl);
  182. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va7, vl);
  183. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va7, vl);
  184. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va7, vl);
  185. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va7, vl);
  186. ptrbb += 8;
  187. }
  188. for (k = temp&7; k > 0; k--) {
  189. va0 = VLEV_FLOAT(ptrba, vl); // M:8 (should be vlen);
  190. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  191. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va0, vl);
  192. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va0, vl);
  193. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va0, vl);
  194. vres4 = VFMACCVF_FLOAT(vres4, *(ptrbb + 4), va0, vl);
  195. vres5 = VFMACCVF_FLOAT(vres5, *(ptrbb + 5), va0, vl);
  196. vres6 = VFMACCVF_FLOAT(vres6, *(ptrbb + 6), va0, vl);
  197. vres7 = VFMACCVF_FLOAT(vres7, *(ptrbb + 7), va0, vl);
  198. ptrbb += 8;
  199. ptrba += vl;
  200. }
  201. va0 = VFMULVF_FLOAT(vres0, alpha, vl);
  202. VSEV_FLOAT(C0, va0, vl);
  203. va1 = VFMULVF_FLOAT(vres1, alpha, vl);
  204. VSEV_FLOAT(C1, va1, vl);
  205. va2 = VFMULVF_FLOAT(vres2, alpha, vl);
  206. VSEV_FLOAT(C2, va2, vl);
  207. va3 = VFMULVF_FLOAT(vres3, alpha, vl);
  208. VSEV_FLOAT(C3, va3, vl);
  209. va4 = VFMULVF_FLOAT(vres4, alpha, vl);
  210. VSEV_FLOAT(C4, va4, vl);
  211. va5 = VFMULVF_FLOAT(vres5, alpha, vl);
  212. VSEV_FLOAT(C5, va5, vl);
  213. va6 = VFMULVF_FLOAT(vres6, alpha, vl);
  214. VSEV_FLOAT(C6, va6, vl);
  215. va7 = VFMULVF_FLOAT(vres7, alpha, vl);
  216. VSEV_FLOAT(C7, va7, vl);
  217. #if ( defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  218. temp = bk - off;
  219. #ifdef LEFT
  220. temp -= vl; // number of values in A
  221. #else
  222. temp -= 8; // number of values in B
  223. #endif
  224. ptrba += temp*vl;
  225. ptrbb += temp*8;
  226. #endif
  227. #ifdef LEFT
  228. off += vl; // number of values in A
  229. #endif
  230. C0 += vl;
  231. C1 += vl;
  232. C2 += vl;
  233. C3 += vl;
  234. C4 += vl;
  235. C5 += vl;
  236. C6 += vl;
  237. C7 += vl;
  238. }
  239. #if defined(TRMMKERNEL) && !defined(LEFT)
  240. off += 8;
  241. #endif
  242. bb += (bk<<3);
  243. C += (ldc<<3);
  244. }
  245. if (bn & 4)
  246. {
  247. C0 = C;
  248. C1 = C0+ldc;
  249. C2 = C1+ldc;
  250. C3 = C2+ldc;
  251. #if defined(TRMMKERNEL) && defined(LEFT)
  252. off = offset;
  253. #endif
  254. ptrba = ba;
  255. for (i = bm; i > 0; i -= vl)
  256. {
  257. vl = VSETVL(i);
  258. #if (defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  259. ptrbb = bb;
  260. #else
  261. ptrba += off*vl;
  262. ptrbb = bb + off*4;
  263. #endif
  264. vres0 = VFMVVF_FLOAT(0.0, vl);
  265. vres1 = VFMVVF_FLOAT(0.0, vl);
  266. vres2 = VFMVVF_FLOAT(0.0, vl);
  267. vres3 = VFMVVF_FLOAT(0.0, vl);
  268. #if (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA))
  269. temp = bk-off;
  270. #elif defined(LEFT)
  271. temp = off+vl; // number of values in A
  272. #else
  273. temp = off+4; // number of values in B
  274. #endif
  275. for (k = temp/8; k > 0; k--) {
  276. va0 = VLEV_FLOAT(ptrba, vl);
  277. ptrba += vl;
  278. va1 = VLEV_FLOAT(ptrba, vl);
  279. ptrba += vl;
  280. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  281. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va0, vl);
  282. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va0, vl);
  283. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va0, vl);
  284. ptrbb += 4;
  285. va2 = VLEV_FLOAT(ptrba, vl);
  286. ptrba += vl;
  287. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va1, vl);
  288. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va1, vl);
  289. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va1, vl);
  290. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va1, vl);
  291. ptrbb += 4;
  292. va3 = VLEV_FLOAT(ptrba, vl);
  293. ptrba += vl;
  294. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va2, vl);
  295. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va2, vl);
  296. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va2, vl);
  297. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va2, vl);
  298. ptrbb += 4;
  299. va4 = VLEV_FLOAT(ptrba, vl);
  300. ptrba += vl;
  301. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va3, vl);
  302. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va3, vl);
  303. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va3, vl);
  304. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va3, vl);
  305. ptrbb += 4;
  306. va5 = VLEV_FLOAT(ptrba, vl);
  307. ptrba += vl;
  308. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va4, vl);
  309. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va4, vl);
  310. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va4, vl);
  311. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va4, vl);
  312. ptrbb += 4;
  313. va6 = VLEV_FLOAT(ptrba, vl);
  314. ptrba += vl;
  315. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va5, vl);
  316. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va5, vl);
  317. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va5, vl);
  318. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va5, vl);
  319. ptrbb += 4;
  320. va7 = VLEV_FLOAT(ptrba, vl);
  321. ptrba += vl;
  322. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va6, vl);
  323. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va6, vl);
  324. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va6, vl);
  325. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va6, vl);
  326. ptrbb += 4;
  327. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va7, vl);
  328. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va7, vl);
  329. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va7, vl);
  330. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va7, vl);
  331. ptrbb += 4;
  332. }
  333. // K remainder
  334. for (k = temp&7; k > 0; k--) {
  335. va0 = VLEV_FLOAT(ptrba, vl);
  336. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  337. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va0, vl);
  338. vres2 = VFMACCVF_FLOAT(vres2, *(ptrbb + 2), va0, vl);
  339. vres3 = VFMACCVF_FLOAT(vres3, *(ptrbb + 3), va0, vl);
  340. ptrbb += 4;
  341. ptrba += vl;
  342. }
  343. va0 = VFMULVF_FLOAT(vres0, alpha, vl);
  344. VSEV_FLOAT(C0, va0, vl);
  345. va1 = VFMULVF_FLOAT(vres1, alpha, vl);
  346. VSEV_FLOAT(C1, va1, vl);
  347. va2 = VFMULVF_FLOAT(vres2, alpha, vl);
  348. VSEV_FLOAT(C2, va2, vl);
  349. va3 = VFMULVF_FLOAT(vres3, alpha, vl);
  350. VSEV_FLOAT(C3, va3, vl);
  351. #if ( defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  352. temp = bk - off;
  353. #ifdef LEFT
  354. temp -= vl; // number of values in A
  355. #else
  356. temp -= 4; // number of values in B
  357. #endif
  358. ptrba += temp*vl;
  359. ptrbb += temp*4;
  360. #endif
  361. #ifdef LEFT
  362. off += vl; // number of values in A
  363. #endif
  364. C0 += vl;
  365. C1 += vl;
  366. C2 += vl;
  367. C3 += vl;
  368. }
  369. #if defined(TRMMKERNEL) && !defined(LEFT)
  370. off += 4;
  371. #endif
  372. bb += (bk<<2);
  373. C += (ldc<<2);
  374. }
  375. if (bn & 2)
  376. {
  377. C0 = C;
  378. C1 = C0+ldc;
  379. #if defined(TRMMKERNEL) && defined(LEFT)
  380. off = offset;
  381. #endif
  382. ptrba = ba;
  383. for (i = bm; i > 0; i -= vl)
  384. {
  385. vl = VSETVL(i);
  386. #if (defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  387. ptrbb = bb;
  388. #else
  389. ptrba += off*vl;
  390. ptrbb = bb + off*2;
  391. #endif
  392. vres0 = VFMVVF_FLOAT(0.0, vl);
  393. vres1 = VFMVVF_FLOAT(0.0, vl);
  394. #if (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA))
  395. temp = bk-off;
  396. #elif defined(LEFT)
  397. temp = off+vl; // number of values in A
  398. #else
  399. temp = off+2; // number of values in B
  400. #endif
  401. for (k = temp/8; k > 0; k--) {
  402. va0 = VLEV_FLOAT(ptrba, vl);
  403. ptrba += vl;
  404. va1 = VLEV_FLOAT(ptrba, vl);
  405. ptrba += vl;
  406. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  407. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va0, vl);
  408. ptrbb += 2;
  409. va2 = VLEV_FLOAT(ptrba, vl);
  410. ptrba += vl;
  411. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va1, vl);
  412. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va1, vl);
  413. ptrbb += 2;
  414. va3 = VLEV_FLOAT(ptrba, vl);
  415. ptrba += vl;
  416. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va2, vl);
  417. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va2, vl);
  418. ptrbb += 2;
  419. va4 = VLEV_FLOAT(ptrba, vl);
  420. ptrba += vl;
  421. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va3, vl);
  422. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va3, vl);
  423. ptrbb += 2;
  424. va5 = VLEV_FLOAT(ptrba, vl);
  425. ptrba += vl;
  426. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va4, vl);
  427. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va4, vl);
  428. ptrbb += 2;
  429. va6 = VLEV_FLOAT(ptrba, vl);
  430. ptrba += vl;
  431. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va5, vl);
  432. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va5, vl);
  433. ptrbb += 2;
  434. va7 = VLEV_FLOAT(ptrba, vl);
  435. ptrba += vl;
  436. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va6, vl);
  437. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va6, vl);
  438. ptrbb += 2;
  439. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va7, vl);
  440. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va7, vl);
  441. ptrbb += 2;
  442. }
  443. // K remainder
  444. for (k = temp&7; k > 0; k--) {
  445. va0 = VLEV_FLOAT(ptrba, vl);
  446. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  447. vres1 = VFMACCVF_FLOAT(vres1, *(ptrbb + 1), va0, vl);
  448. ptrbb += 2;
  449. ptrba += vl;
  450. }
  451. va0 = VFMULVF_FLOAT(vres0, alpha, vl);
  452. VSEV_FLOAT(C0, va0, vl);
  453. va1 = VFMULVF_FLOAT(vres1, alpha, vl);
  454. VSEV_FLOAT(C1, va1, vl);
  455. #if ( defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  456. temp = bk - off;
  457. #ifdef LEFT
  458. temp -= vl; // number of values in A
  459. #else
  460. temp -= 2; // number of values in B
  461. #endif
  462. ptrba += temp*vl;
  463. ptrbb += temp*2;
  464. #endif
  465. #ifdef LEFT
  466. off += vl; // number of values in A
  467. #endif
  468. C0 += vl;
  469. C1 += vl;
  470. }
  471. #if defined(TRMMKERNEL) && !defined(LEFT)
  472. off += 2;
  473. #endif
  474. bb += (bk<<1);
  475. C += (ldc<<1);
  476. }
  477. if (bn & 1)
  478. {
  479. C0 = C;
  480. #if defined(TRMMKERNEL) && defined(LEFT)
  481. off = offset;
  482. #endif
  483. ptrba = ba;
  484. for (i = bm; i > 0; i -= vl)
  485. {
  486. vl = VSETVL(i);
  487. #if (defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  488. ptrbb = bb;
  489. #else
  490. ptrba += off*vl;
  491. ptrbb = bb + off*1;
  492. #endif
  493. vres0 = VFMVVF_FLOAT(0.0, vl);
  494. #if (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA))
  495. temp = bk-off;
  496. #elif defined(LEFT)
  497. temp = off+vl; // number of values in A
  498. #else
  499. temp = off+1; // number of values in B
  500. #endif
  501. for (k = temp/8; k > 0; k--) {
  502. va0 = VLEV_FLOAT(ptrba, vl);
  503. ptrba += vl;
  504. va1 = VLEV_FLOAT(ptrba, vl);
  505. ptrba += vl;
  506. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  507. ptrbb += 1;
  508. va2 = VLEV_FLOAT(ptrba, vl);
  509. ptrba += vl;
  510. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va1, vl);
  511. ptrbb += 1;
  512. va3 = VLEV_FLOAT(ptrba, vl);
  513. ptrba += vl;
  514. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va2, vl);
  515. ptrbb += 1;
  516. va4 = VLEV_FLOAT(ptrba, vl);
  517. ptrba += vl;
  518. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va3, vl);
  519. ptrbb += 1;
  520. va5 = VLEV_FLOAT(ptrba, vl);
  521. ptrba += vl;
  522. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va4, vl);
  523. ptrbb += 1;
  524. va6 = VLEV_FLOAT(ptrba, vl);
  525. ptrba += vl;
  526. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va5, vl);
  527. ptrbb += 1;
  528. va7 = VLEV_FLOAT(ptrba, vl);
  529. ptrba += vl;
  530. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va6, vl);
  531. ptrbb += 1;
  532. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va7, vl);
  533. ptrbb += 1;
  534. }
  535. // K remainder
  536. for (k = temp&7; k > 0; k--) {
  537. va0 = VLEV_FLOAT(ptrba, vl);
  538. vres0 = VFMACCVF_FLOAT(vres0, *(ptrbb + 0), va0, vl);
  539. ptrbb += 1;
  540. ptrba += vl;
  541. }
  542. va0 = VFMULVF_FLOAT(vres0, alpha, vl);
  543. VSEV_FLOAT(C0, va0, vl);
  544. #if ( defined(LEFT) && defined(TRANSA)) || (!defined(LEFT) && !defined(TRANSA))
  545. temp = bk - off;
  546. #ifdef LEFT
  547. temp -= vl; // number of values in A
  548. #else
  549. temp -= 1; // number of values in B
  550. #endif
  551. ptrba += temp*vl;
  552. ptrbb += temp*1;
  553. #endif
  554. #ifdef LEFT
  555. off += vl; // number of values in A
  556. #endif
  557. C0 += vl;
  558. }
  559. #if defined(TRMMKERNEL) && !defined(LEFT)
  560. off += 1;
  561. #endif
  562. bb += (bk);
  563. C += (ldc);
  564. }
  565. return 0;
  566. }