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.

sgemv_t_msa.c 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*******************************************************************************
  2. Copyright (c) 2016, 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. #include "macros_msa.h"
  29. #define SGEMV_T_8x8() \
  30. { \
  31. LD_SP2(pa0 + k, 4, t0, t1); \
  32. LD_SP2(pa1 + k, 4, t2, t3); \
  33. LD_SP2(pa2 + k, 4, t4, t5); \
  34. LD_SP2(pa3 + k, 4, t6, t7); \
  35. LD_SP2(pa4 + k, 4, t8, t9); \
  36. LD_SP2(pa5 + k, 4, t10, t11); \
  37. LD_SP2(pa6 + k, 4, t12, t13); \
  38. LD_SP2(pa7 + k, 4, t14, t15); \
  39. \
  40. tp0 += x0 * t0; \
  41. tp0 += x1 * t1; \
  42. \
  43. tp1 += x0 * t2; \
  44. tp1 += x1 * t3; \
  45. \
  46. tp2 += x0 * t4; \
  47. tp2 += x1 * t5; \
  48. \
  49. tp3 += x0 * t6; \
  50. tp3 += x1 * t7; \
  51. \
  52. tp4 += x0 * t8; \
  53. tp4 += x1 * t9; \
  54. \
  55. tp5 += x0 * t10; \
  56. tp5 += x1 * t11; \
  57. \
  58. tp6 += x0 * t12; \
  59. tp6 += x1 * t13; \
  60. \
  61. tp7 += x0 * t14; \
  62. tp7 += x1 * t15; \
  63. }
  64. #define SGEMV_T_8x4() \
  65. { \
  66. t0 = LD_SP(pa0 + k); \
  67. t2 = LD_SP(pa1 + k); \
  68. t4 = LD_SP(pa2 + k); \
  69. t6 = LD_SP(pa3 + k); \
  70. t8 = LD_SP(pa4 + k); \
  71. t10 = LD_SP(pa5 + k); \
  72. t12 = LD_SP(pa6 + k); \
  73. t14 = LD_SP(pa7 + k); \
  74. \
  75. tp0 += x0 * t0; \
  76. tp1 += x0 * t2; \
  77. tp2 += x0 * t4; \
  78. tp3 += x0 * t6; \
  79. tp4 += x0 * t8; \
  80. tp5 += x0 * t10; \
  81. tp6 += x0 * t12; \
  82. tp7 += x0 * t14; \
  83. }
  84. #define SGEMV_T_4x8() \
  85. { \
  86. LD_SP2(pa0 + k, 4, t0, t1); \
  87. LD_SP2(pa1 + k, 4, t2, t3); \
  88. LD_SP2(pa2 + k, 4, t4, t5); \
  89. LD_SP2(pa3 + k, 4, t6, t7); \
  90. \
  91. tp0 += x0 * t0; \
  92. tp0 += x1 * t1; \
  93. \
  94. tp1 += x0 * t2; \
  95. tp1 += x1 * t3; \
  96. \
  97. tp2 += x0 * t4; \
  98. tp2 += x1 * t5; \
  99. \
  100. tp3 += x0 * t6; \
  101. tp3 += x1 * t7; \
  102. }
  103. #define SGEMV_T_4x4() \
  104. { \
  105. t0 = LD_SP(pa0 + k); \
  106. t2 = LD_SP(pa1 + k); \
  107. t4 = LD_SP(pa2 + k); \
  108. t6 = LD_SP(pa3 + k); \
  109. \
  110. tp0 += x0 * t0; \
  111. tp1 += x0 * t2; \
  112. tp2 += x0 * t4; \
  113. tp3 += x0 * t6; \
  114. }
  115. #define SGEMV_T_2x8() \
  116. { \
  117. LD_SP2(pa0 + k, 4, t0, t1); \
  118. LD_SP2(pa1 + k, 4, t2, t3); \
  119. \
  120. tp0 += x0 * t0; \
  121. tp0 += x1 * t1; \
  122. \
  123. tp1 += x0 * t2; \
  124. tp1 += x1 * t3; \
  125. }
  126. #define SGEMV_T_2x4() \
  127. { \
  128. t0 = LD_SP(pa0 + k); \
  129. t2 = LD_SP(pa1 + k); \
  130. \
  131. tp0 += x0 * t0; \
  132. tp1 += x0 * t2; \
  133. }
  134. #define SLOAD_X8_GP() \
  135. x0 = (v4f32) __msa_insert_w((v4i32) tp0, 0, *((int *)(x + 0 * inc_x))); \
  136. x0 = (v4f32) __msa_insert_w((v4i32) x0, 1, *((int *)(x + 1 * inc_x))); \
  137. x0 = (v4f32) __msa_insert_w((v4i32) x0, 2, *((int *)(x + 2 * inc_x))); \
  138. x0 = (v4f32) __msa_insert_w((v4i32) x0, 3, *((int *)(x + 3 * inc_x))); \
  139. x1 = (v4f32) __msa_insert_w((v4i32) tp0, 0, *((int *)(x + 4 * inc_x))); \
  140. x1 = (v4f32) __msa_insert_w((v4i32) x1, 1, *((int *)(x + 5 * inc_x))); \
  141. x1 = (v4f32) __msa_insert_w((v4i32) x1, 2, *((int *)(x + 6 * inc_x))); \
  142. x1 = (v4f32) __msa_insert_w((v4i32) x1, 3, *((int *)(x + 7 * inc_x))); \
  143. #define SLOAD_X4_GP() \
  144. x0 = (v4f32) __msa_insert_w((v4i32) tp0, 0, *((int *)(x + 0 * inc_x))); \
  145. x0 = (v4f32) __msa_insert_w((v4i32) x0, 1, *((int *)(x + 1 * inc_x))); \
  146. x0 = (v4f32) __msa_insert_w((v4i32) x0, 2, *((int *)(x + 2 * inc_x))); \
  147. x0 = (v4f32) __msa_insert_w((v4i32) x0, 3, *((int *)(x + 3 * inc_x))); \
  148. #define SLOAD_X8_VECTOR() LD_SP2(x, 4, x0, x1);
  149. #define SLOAD_X4_VECTOR() x0 = LD_SP(x);
  150. #define SGEMV_T_MSA() \
  151. for (j = (n >> 3); j--;) \
  152. { \
  153. tp0 = zero; \
  154. tp1 = zero; \
  155. tp2 = zero; \
  156. tp3 = zero; \
  157. tp4 = zero; \
  158. tp5 = zero; \
  159. tp6 = zero; \
  160. tp7 = zero; \
  161. \
  162. k = 0; \
  163. x = srcx_org; \
  164. \
  165. for (i = (m >> 3); i--;) \
  166. { \
  167. SLOAD_X8(); \
  168. SGEMV_T_8x8(); \
  169. \
  170. x += 8 * inc_x; \
  171. k += 8; \
  172. } \
  173. \
  174. if (m & 4) \
  175. { \
  176. SLOAD_X4(); \
  177. SGEMV_T_8x4(); \
  178. \
  179. x += 4 * inc_x; \
  180. k += 4; \
  181. } \
  182. \
  183. TRANSPOSE4x4_SP_SP(tp0, tp1, tp2, tp3, \
  184. tp0, tp1, tp2, tp3); \
  185. TRANSPOSE4x4_SP_SP(tp4, tp5, tp6, tp7, \
  186. tp4, tp5, tp6, tp7); \
  187. tp0 += tp1; \
  188. tp0 += tp2; \
  189. tp0 += tp3; \
  190. tp4 += tp5; \
  191. tp4 += tp6; \
  192. tp4 += tp7; \
  193. \
  194. temp0 = tp0[0]; \
  195. temp1 = tp0[1]; \
  196. temp2 = tp0[2]; \
  197. temp3 = tp0[3]; \
  198. temp4 = tp4[0]; \
  199. temp5 = tp4[1]; \
  200. temp6 = tp4[2]; \
  201. temp7 = tp4[3]; \
  202. \
  203. for (i = (m & 3); i--;) \
  204. { \
  205. temp0 += pa0[k] * x[0]; \
  206. temp1 += pa1[k] * x[0]; \
  207. temp2 += pa2[k] * x[0]; \
  208. temp3 += pa3[k] * x[0]; \
  209. temp4 += pa4[k] * x[0]; \
  210. temp5 += pa5[k] * x[0]; \
  211. temp6 += pa6[k] * x[0]; \
  212. temp7 += pa7[k] * x[0]; \
  213. \
  214. x += inc_x; \
  215. k++; \
  216. } \
  217. \
  218. res0 = y[0 * inc_y]; \
  219. res1 = y[1 * inc_y]; \
  220. res2 = y[2 * inc_y]; \
  221. res3 = y[3 * inc_y]; \
  222. res4 = y[4 * inc_y]; \
  223. res5 = y[5 * inc_y]; \
  224. res6 = y[6 * inc_y]; \
  225. res7 = y[7 * inc_y]; \
  226. \
  227. res0 += alpha * temp0; \
  228. res1 += alpha * temp1; \
  229. res2 += alpha * temp2; \
  230. res3 += alpha * temp3; \
  231. res4 += alpha * temp4; \
  232. res5 += alpha * temp5; \
  233. res6 += alpha * temp6; \
  234. res7 += alpha * temp7; \
  235. \
  236. y[0 * inc_y] = res0; \
  237. y[1 * inc_y] = res1; \
  238. y[2 * inc_y] = res2; \
  239. y[3 * inc_y] = res3; \
  240. y[4 * inc_y] = res4; \
  241. y[5 * inc_y] = res5; \
  242. y[6 * inc_y] = res6; \
  243. y[7 * inc_y] = res7; \
  244. \
  245. y += 8 * inc_y; \
  246. \
  247. pa0 += 8 * lda; \
  248. pa1 += 8 * lda; \
  249. pa2 += 8 * lda; \
  250. pa3 += 8 * lda; \
  251. pa4 += 8 * lda; \
  252. pa5 += 8 * lda; \
  253. pa6 += 8 * lda; \
  254. pa7 += 8 * lda; \
  255. } \
  256. \
  257. if (n & 4) \
  258. { \
  259. tp0 = zero; \
  260. tp1 = zero; \
  261. tp2 = zero; \
  262. tp3 = zero; \
  263. \
  264. k = 0; \
  265. x = srcx_org; \
  266. \
  267. for (i = (m >> 3); i--;) \
  268. { \
  269. SLOAD_X8(); \
  270. SGEMV_T_4x8(); \
  271. \
  272. x += 8 * inc_x; \
  273. k += 8; \
  274. } \
  275. \
  276. if (m & 4) \
  277. { \
  278. SLOAD_X4(); \
  279. SGEMV_T_4x4(); \
  280. \
  281. x += 4 * inc_x; \
  282. k += 4; \
  283. } \
  284. \
  285. TRANSPOSE4x4_SP_SP(tp0, tp1, tp2, tp3, \
  286. tp0, tp1, tp2, tp3); \
  287. tp0 += tp1; \
  288. tp0 += tp2; \
  289. tp0 += tp3; \
  290. \
  291. temp0 = tp0[0]; \
  292. temp1 = tp0[1]; \
  293. temp2 = tp0[2]; \
  294. temp3 = tp0[3]; \
  295. \
  296. for (i = (m & 3); i--;) \
  297. { \
  298. temp0 += pa0[k] * x[0]; \
  299. temp1 += pa1[k] * x[0]; \
  300. temp2 += pa2[k] * x[0]; \
  301. temp3 += pa3[k] * x[0]; \
  302. \
  303. x += inc_x; \
  304. k++; \
  305. } \
  306. \
  307. res0 = y[0 * inc_y]; \
  308. res1 = y[1 * inc_y]; \
  309. res2 = y[2 * inc_y]; \
  310. res3 = y[3 * inc_y]; \
  311. \
  312. res0 += alpha * temp0; \
  313. res1 += alpha * temp1; \
  314. res2 += alpha * temp2; \
  315. res3 += alpha * temp3; \
  316. \
  317. y[0 * inc_y] = res0; \
  318. y[1 * inc_y] = res1; \
  319. y[2 * inc_y] = res2; \
  320. y[3 * inc_y] = res3; \
  321. \
  322. y += 4 * inc_y; \
  323. \
  324. pa0 += 4 * lda; \
  325. pa1 += 4 * lda; \
  326. pa2 += 4 * lda; \
  327. pa3 += 4 * lda; \
  328. } \
  329. \
  330. if (n & 2) \
  331. { \
  332. tp0 = zero; \
  333. tp1 = zero; \
  334. \
  335. k = 0; \
  336. x = srcx_org; \
  337. \
  338. for (i = (m >> 3); i--;) \
  339. { \
  340. SLOAD_X8(); \
  341. SGEMV_T_2x8(); \
  342. \
  343. x += 8 * inc_x; \
  344. k += 8; \
  345. } \
  346. \
  347. if (m & 4) \
  348. { \
  349. SLOAD_X4(); \
  350. SGEMV_T_2x4(); \
  351. \
  352. x += 4 * inc_x; \
  353. k += 4; \
  354. } \
  355. \
  356. ILVRL_W2_SP(tp1, tp0, tp2, tp3); \
  357. \
  358. tp2 += tp3; \
  359. \
  360. temp0 = tp2[0] + tp2[2]; \
  361. temp1 = tp2[1] + tp2[3]; \
  362. \
  363. for (i = (m & 3); i--;) \
  364. { \
  365. temp0 += pa0[k] * x[0]; \
  366. temp1 += pa1[k] * x[0]; \
  367. \
  368. x += inc_x; \
  369. k++; \
  370. } \
  371. \
  372. res0 = y[0 * inc_y]; \
  373. res1 = y[1 * inc_y]; \
  374. \
  375. res0 += alpha * temp0; \
  376. res1 += alpha * temp1; \
  377. \
  378. y[0 * inc_y] = res0; \
  379. y[1 * inc_y] = res1; \
  380. \
  381. y += 2 * inc_y; \
  382. \
  383. pa0 += 2 * lda; \
  384. pa1 += 2 * lda; \
  385. } \
  386. \
  387. if (n & 1) \
  388. { \
  389. temp0 = 0.0; \
  390. \
  391. k = 0; \
  392. x = srcx_org; \
  393. \
  394. for (i = m; i--;) \
  395. { \
  396. temp0 += pa0[k] * x[0]; \
  397. \
  398. x += inc_x; \
  399. k++; \
  400. } \
  401. \
  402. y[0] += alpha * temp0; \
  403. y += inc_y; \
  404. pa0 += lda; \
  405. }
  406. int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *A,
  407. BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y,
  408. FLOAT *buffer)
  409. {
  410. BLASLONG i, j, k;
  411. FLOAT *srcx_org = x;
  412. FLOAT *pa0, *pa1, *pa2, *pa3, *pa4, *pa5, *pa6, *pa7;
  413. FLOAT temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
  414. FLOAT res0, res1, res2, res3, res4, res5, res6, res7;
  415. v4f32 x0, x1;
  416. v4f32 t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
  417. v4f32 tp0, tp1, tp2, tp3, tp4, tp5, tp6, tp7;
  418. v4f32 zero = {0};
  419. pa0 = A + 0 * lda;
  420. pa1 = A + 1 * lda;
  421. pa2 = A + 2 * lda;
  422. pa3 = A + 3 * lda;
  423. pa4 = A + 4 * lda;
  424. pa5 = A + 5 * lda;
  425. pa6 = A + 6 * lda;
  426. pa7 = A + 7 * lda;
  427. if (1 == inc_x)
  428. {
  429. #define SLOAD_X8 SLOAD_X8_VECTOR
  430. #define SLOAD_X4 SLOAD_X4_VECTOR
  431. SGEMV_T_MSA();
  432. #undef SLOAD_X8
  433. #undef SLOAD_X4
  434. }
  435. else
  436. {
  437. #define SLOAD_X8 SLOAD_X8_GP
  438. #define SLOAD_X4 SLOAD_X4_GP
  439. SGEMV_T_MSA();
  440. #undef SLOAD_X8
  441. #undef SLOAD_X4
  442. }
  443. return(0);
  444. }