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.

dgemv_t_power10.c 26 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /***************************************************************************
  2. Copyright (c) 2018, 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. #define NBMAX 1024
  29. //#define PREFETCH 1
  30. #include <altivec.h>
  31. #define HAVE_KERNEL4x8_ASM 1
  32. #if defined(HAVE_KERNEL4x8_ASM)
  33. static void dgemv_kernel_4x8(BLASLONG n, BLASLONG lda, double *ap, double *x, double *y, double alpha) {
  34. FLOAT *a0, *a1, *a2, *a3, *a4, *a5, *a6, *a7;
  35. BLASLONG off2;
  36. BLASLONG tempR;
  37. __asm__(
  38. "sldi %[temp],%[off], 4 \n\t" // lda * sizeof (double) *2
  39. "sldi %[off], %[off], 3 \n\t" // lda * sizeof (double)
  40. "xxlxor 34,34,34 \n\t"
  41. "xxlxor 35,34,34 \n\t"
  42. "add %[a2], %[a0], %[temp] \n\t"
  43. "add %[a1], %[a0], %[off] \n\t"
  44. "xxlxor 4,34,34 \n\t"
  45. "xxlxor 5,34,34 \n\t"
  46. "xxlxor 6,34,34 \n\t"
  47. "xxlxor 7,34,34 \n\t"
  48. "add %[a3], %[a2], %[off] \n\t"
  49. "add %[a4], %[a2], %[temp] \n\t"
  50. "xxlxor 8,34,34 \n\t"
  51. "xxlxor 9,34,34 \n\t"
  52. "add %[a5], %[a3], %[temp] \n\t"
  53. "li %[off],0 \n\t"
  54. "li %[off2],16 \n\t"
  55. "add %[a6], %[a4], %[temp] \n\t"
  56. "add %[a7], %[a5], %[temp] \n\t"
  57. "lxvp 32, 0(%[x]) \n\t"
  58. "lxvp 36, 0(%[a0]) \n\t"
  59. "lxvp 38, 0(%[a1]) \n\t"
  60. "lxvp 40, 0(%[a2]) \n\t"
  61. "lxvp 42, 0(%[a3]) \n\t"
  62. "lxvp 44, 0(%[a4]) \n\t"
  63. "lxvp 46, 0(%[a5]) \n\t"
  64. "lxvp 48, 0(%[a6]) \n\t"
  65. "lxvp 50, 0(%[a7]) \n\t"
  66. #if defined(PREFETCH)
  67. "li %[temp],896 \n\t"
  68. #endif
  69. "addic. %[n],%[n],-4 \n\t"
  70. "li %[off],32 \n\t"
  71. "ble- two%= \n\t"
  72. //--------------------------------------------------
  73. ".align 5 \n\t"
  74. "one%=: \n\t"
  75. "xvmaddadp 34,36,32 \n\t"
  76. "xvmaddadp 35,38,32 \n\t"
  77. "addi %[off2], %[off2],32 \n\t"
  78. "xvmaddadp 4,40,32 \n\t"
  79. "xvmaddadp 5,42,32 \n\t"
  80. "xvmaddadp 6,44,32 \n\t"
  81. "xvmaddadp 7,46,32 \n\t"
  82. "xvmaddadp 8,48,32 \n\t"
  83. "xvmaddadp 9,50,32 \n\t"
  84. "xvmaddadp 34,37,33 \n\t"
  85. "xvmaddadp 35,39,33 \n\t"
  86. "lxvp 36, 32(%[a0]) \n\t"
  87. "lxvp 38, 32(%[a1]) \n\t"
  88. "xvmaddadp 4,41,33 \n\t"
  89. "xvmaddadp 5,43,33 \n\t"
  90. "addi %[off], %[off],32 \n\t"
  91. "lxvp 40, 32(%[a2]) \n\t"
  92. "lxvp 42, 32(%[a3]) \n\t"
  93. "xvmaddadp 6,45,33 \n\t"
  94. "xvmaddadp 7,47,33 \n\t"
  95. "lxvp 44, 32(%[a4]) \n\t"
  96. "lxvp 46, 32(%[a5]) \n\t"
  97. "xvmaddadp 8,49,33 \n\t"
  98. "xvmaddadp 9,51,33 \n\t"
  99. "addic. %[n],%[n],-4 \n\t"
  100. "lxvp 48, 32(%[a6]) \n\t"
  101. "lxvp 50, 32(%[a7]) \n\t"
  102. "lxvp 32, 32(%[x]) \n\t"
  103. "ble- two%= \n\t"
  104. "xvmaddadp 34,36,32 \n\t"
  105. "xvmaddadp 35,38,32 \n\t"
  106. "addi %[off2], %[off2],32 \n\t"
  107. "xvmaddadp 4,40,32 \n\t"
  108. "xvmaddadp 5,42,32 \n\t"
  109. "xvmaddadp 6,44,32 \n\t"
  110. "xvmaddadp 7,46,32 \n\t"
  111. "xvmaddadp 8,48,32 \n\t"
  112. "xvmaddadp 9,50,32 \n\t"
  113. "xvmaddadp 34,37,33 \n\t"
  114. "xvmaddadp 35,39,33 \n\t"
  115. "lxvp 36, 64(%[a0]) \n\t"
  116. "lxvp 38, 64(%[a1]) \n\t"
  117. "xvmaddadp 4,41,33 \n\t"
  118. "xvmaddadp 5,43,33 \n\t"
  119. "addi %[off], %[off],32 \n\t"
  120. "lxvp 40, 64(%[a2]) \n\t"
  121. "lxvp 42, 64(%[a3]) \n\t"
  122. "xvmaddadp 6,45,33 \n\t"
  123. "xvmaddadp 7,47,33 \n\t"
  124. "lxvp 44, 64(%[a4]) \n\t"
  125. "lxvp 46, 64(%[a5]) \n\t"
  126. "xvmaddadp 8,49,33 \n\t"
  127. "xvmaddadp 9,51,33 \n\t"
  128. "addic. %[n],%[n],-4 \n\t"
  129. "lxvp 48, 64(%[a6]) \n\t"
  130. "lxvp 50, 64(%[a7]) \n\t"
  131. "lxvp 32, 64(%[x]) \n\t"
  132. "ble- two%= \n\t"
  133. "xvmaddadp 34,36,32 \n\t"
  134. "xvmaddadp 35,38,32 \n\t"
  135. #if defined(PREFETCH)
  136. "addi %[temp],%[temp],128 \n\t"
  137. #endif
  138. "addi %[off2], %[off2],32 \n\t"
  139. "xvmaddadp 4,40,32 \n\t"
  140. "xvmaddadp 5,42,32 \n\t"
  141. "xvmaddadp 6,44,32 \n\t"
  142. "xvmaddadp 7,46,32 \n\t"
  143. "xvmaddadp 8,48,32 \n\t"
  144. "xvmaddadp 9,50,32 \n\t"
  145. #if defined(PREFETCH)
  146. "dcbt %[temp],%[a0] \n\t"
  147. #endif
  148. "xvmaddadp 34,37,33 \n\t"
  149. "xvmaddadp 35,39,33 \n\t"
  150. "lxvp 36, 96(%[a0]) \n\t"
  151. "lxvp 38, 96(%[a1]) \n\t"
  152. "xvmaddadp 4,41,33 \n\t"
  153. "xvmaddadp 5,43,33 \n\t"
  154. #if defined(PREFETCH)
  155. "dcbt %[temp],%[a1] \n\t"
  156. #endif
  157. "lxvp 40, 96(%[a2]) \n\t"
  158. "lxvp 42, 96(%[a3]) \n\t"
  159. "addi %[off], %[off],32 \n\t"
  160. "xvmaddadp 6,45,33 \n\t"
  161. "xvmaddadp 7,47,33 \n\t"
  162. "lxvp 44, 96(%[a4]) \n\t"
  163. "lxvp 46, 96(%[a5]) \n\t"
  164. "xvmaddadp 8,49,33 \n\t"
  165. "xvmaddadp 9,51,33 \n\t"
  166. #if defined(PREFETCH)
  167. "dcbt %[temp],%[a3] \n\t"
  168. #endif
  169. "lxvp 48, 96(%[a6]) \n\t"
  170. "lxvp 50, 96(%[a7]) \n\t"
  171. "lxvp 32, 96(%[x]) \n\t"
  172. "addic. %[n],%[n],-4 \n\t"
  173. "ble- two%= \n\t"
  174. "addi %[off2], %[off2],32 \n\t"
  175. #if defined(PREFETCH)
  176. "dcbt %[temp],%[a2] \n\t"
  177. #endif
  178. "xvmaddadp 34,36,32 \n\t"
  179. "xvmaddadp 35,38,32 \n\t"
  180. "xvmaddadp 4,40,32 \n\t"
  181. "xvmaddadp 5,42,32 \n\t"
  182. #if defined(PREFETCH)
  183. "dcbt %[temp],%[a4] \n\t"
  184. #endif
  185. "xvmaddadp 6,44,32 \n\t"
  186. "xvmaddadp 7,46,32 \n\t"
  187. "xvmaddadp 8,48,32 \n\t"
  188. "xvmaddadp 9,50,32 \n\t"
  189. #if defined(PREFETCH)
  190. "dcbt %[temp],%[a5] \n\t"
  191. #endif
  192. "xvmaddadp 34,37,33 \n\t"
  193. "xvmaddadp 35,39,33 \n\t"
  194. "lxvp 36, 128(%[a0]) \n\t"
  195. "lxvp 38, 128(%[a1]) \n\t"
  196. "xvmaddadp 4,41,33 \n\t"
  197. "xvmaddadp 5,43,33 \n\t"
  198. "addi %[off], %[off],32 \n\t"
  199. "lxvp 40, 128(%[a2]) \n\t"
  200. "lxvp 42, 128(%[a3]) \n\t"
  201. #if defined(PREFETCH)
  202. "dcbt %[temp],%[a6] \n\t"
  203. #endif
  204. "xvmaddadp 6,45,33 \n\t"
  205. "xvmaddadp 7,47,33 \n\t"
  206. "lxvp 44, 128(%[a4]) \n\t"
  207. "lxvp 46, 128(%[a5]) \n\t"
  208. "xvmaddadp 8,49,33 \n\t"
  209. "xvmaddadp 9,51,33 \n\t"
  210. #if defined(PREFETCH)
  211. "dcbt %[temp],%[a7] \n\t"
  212. #endif
  213. "addic. %[n],%[n],-4 \n\t"
  214. "lxvp 48, 128(%[a6]) \n\t"
  215. "lxvp 50, 128(%[a7]) \n\t"
  216. "lxvp 32, 128(%[x]) \n\t"
  217. #if defined(PREFETCH)
  218. "dcbt %[temp],%[x] \n\t"
  219. #endif
  220. "addi %[a0], %[a0], 128 \n\t"
  221. "addi %[a1], %[a1], 128 \n\t"
  222. "addi %[a2], %[a2], 128 \n\t"
  223. "addi %[a3], %[a3], 128 \n\t"
  224. "addi %[a4], %[a4], 128 \n\t"
  225. "addi %[a5], %[a5], 128 \n\t"
  226. "addi %[a6], %[a6], 128 \n\t"
  227. "addi %[a7], %[a7], 128 \n\t"
  228. "addi %[x], %[x], 128 \n\t"
  229. "bgt+ one%= \n\t"
  230. ".align 5 \n\t"
  231. "two%=: \n\t"
  232. //--------------------------------------------
  233. "xvmaddadp 34,36,32 \n\t"
  234. "xvmaddadp 35,38,32 \n\t"
  235. "xvmaddadp 4,40,32 \n\t"
  236. "xvmaddadp 5,42,32 \n\t"
  237. "xvmaddadp 6,44,32 \n\t"
  238. "xvmaddadp 7,46,32 \n\t"
  239. "xvmaddadp 8,48,32 \n\t"
  240. "xvmaddadp 9,50,32 \n\t"
  241. XXSPLTD_S(36,%x[alpha],0)
  242. "xvmaddadp 34,37,33 \n\t"
  243. "xvmaddadp 35,39,33 \n\t"
  244. "xvmaddadp 4,41,33 \n\t"
  245. "xvmaddadp 5,43,33 \n\t"
  246. "xvmaddadp 6,45,33 \n\t"
  247. "xvmaddadp 7,47,33 \n\t"
  248. "xvmaddadp 8,49,33 \n\t"
  249. "xvmaddadp 9,51,33 \n\t"
  250. "lxvp 38, 0(%[y]) \n\t"
  251. "lxvp 40, 32(%[y]) \n\t"
  252. XXMRGLD_S(42,35,34)
  253. XXMRGHD_S(43,35,34)
  254. XXMRGLD_S(44,5,4)
  255. XXMRGHD_S(45,5,4)
  256. "xvadddp 42,42,43 \n\t"
  257. XXMRGLD_S(46,7,6)
  258. XXMRGHD_S(47,7,6)
  259. "xvadddp 44,44,45 \n\t"
  260. XXMRGLD_S(48,9,8)
  261. XXMRGHD_S(49,9,8)
  262. "xvadddp 46,46,47 \n\t"
  263. "xvmaddadp 39,42,36 \n\t"
  264. "xvmaddadp 38,44,36 \n\t"
  265. "xvadddp 48,48,49 \n\t"
  266. "xvmaddadp 41,46,36 \n\t"
  267. "stxvp 38, 0(%[y]) \n\t"
  268. "xvmaddadp 40,48,36 \n\t"
  269. "stxvp 40, 32(%[y]) \n\t"
  270. : [memy] "+m" (*(double (*)[8])y),
  271. [n] "+&r" (n),
  272. [a0] "=b" (a0),
  273. [a1] "=&b" (a1),
  274. [a2] "=&b" (a2),
  275. [a3] "=&b" (a3),
  276. [a4] "=&b" (a4),
  277. [a5] "=&b" (a5),
  278. [a6] "=&b" (a6),
  279. [a7] "=&b" (a7),
  280. [off] "+&b" (lda),
  281. [off2]"=&b" (off2),
  282. [temp] "=&b" (tempR)
  283. : [memx] "m" (*(const double (*)[n])x),
  284. [mem_ap] "m" (*(const double (*)[n*8]) ap),
  285. [alpha] "d" (alpha),
  286. "[a0]" (ap),
  287. [x] "b" (x),
  288. [y] "b" (y)
  289. : "cc","vs4","vs5","vs6","vs7","vs8","vs9" ,"vs32","vs33","vs34","vs35", "vs36", "vs37", "vs38", "vs39",
  290. "vs40", "vs41", "vs42", "vs43", "vs44", "vs45", "vs46", "vs47", "vs48", "vs49", "vs50", "vs51"
  291. );
  292. return;
  293. }
  294. #else
  295. static void dgemv_kernel_4x8(BLASLONG n, BLASLONG lda, FLOAT *ap, FLOAT *x, FLOAT *y, FLOAT alpha) {
  296. BLASLONG i;
  297. #if defined(PREFETCH)
  298. BLASLONG j, c, k;
  299. #endif
  300. FLOAT *a0, *a1, *a2, *a3, *a4, *a5, *a6, *a7;
  301. __vector double *va0, *va1, *va2, *va3, *va4, *va5, *va6, *va7, *v_x;
  302. register __vector double temp0 = {0, 0};
  303. register __vector double temp1 = {0, 0};
  304. register __vector double temp2 = {0, 0};
  305. register __vector double temp3 = {0, 0};
  306. register __vector double temp4 = {0, 0};
  307. register __vector double temp5 = {0, 0};
  308. register __vector double temp6 = {0, 0};
  309. register __vector double temp7 = {0, 0};
  310. a0 = ap;
  311. a1 = ap + lda;
  312. a2 = a1 + lda;
  313. a3 = a2 + lda;
  314. a4 = a3 + lda;
  315. a5 = a4 + lda;
  316. a6 = a5 + lda;
  317. a7 = a6 + lda;
  318. va0 = (__vector double*) a0;
  319. va1 = (__vector double*) a1;
  320. va2 = (__vector double*) a2;
  321. va3 = (__vector double*) a3;
  322. va4 = (__vector double*) a4;
  323. va5 = (__vector double*) a5;
  324. va6 = (__vector double*) a6;
  325. va7 = (__vector double*) a7;
  326. v_x = (__vector double*) x;
  327. #if defined(PREFETCH)
  328. c = n >> 1;
  329. for (j = 0; j < c; j += 64) {
  330. k = (c - j) > 64 ? 64 : (c - j);
  331. __builtin_prefetch(v_x + 64);
  332. __builtin_prefetch(va0 + 64);
  333. __builtin_prefetch(va1 + 64);
  334. __builtin_prefetch(va2 + 64);
  335. __builtin_prefetch(va3 + 64);
  336. __builtin_prefetch(va4 + 64);
  337. __builtin_prefetch(va5 + 64);
  338. __builtin_prefetch(va6 + 64);
  339. __builtin_prefetch(va7 + 64);
  340. for (i = 0; i < k; i += 2) {
  341. #else
  342. for (i = 0; i < n/2; i += 2) {
  343. #endif
  344. temp0 += v_x[i] * va0[i];
  345. temp1 += v_x[i] * va1[i];
  346. temp2 += v_x[i] * va2[i];
  347. temp3 += v_x[i] * va3[i];
  348. temp4 += v_x[i] * va4[i];
  349. temp5 += v_x[i] * va5[i];
  350. temp6 += v_x[i] * va6[i];
  351. temp7 += v_x[i] * va7[i];
  352. temp0 += v_x[i + 1] * va0[i + 1];
  353. temp1 += v_x[i + 1] * va1[i + 1];
  354. temp2 += v_x[i + 1] * va2[i + 1];
  355. temp3 += v_x[i + 1] * va3[i + 1];
  356. temp4 += v_x[i + 1] * va4[i + 1];
  357. temp5 += v_x[i + 1] * va5[i + 1];
  358. temp6 += v_x[i + 1] * va6[i + 1];
  359. temp7 += v_x[i + 1] * va7[i + 1];
  360. }
  361. #if defined(PREFETCH)
  362. va0 += 64;
  363. va1 += 64;
  364. va2 += 64;
  365. va3 += 64;
  366. va4 += 64;
  367. va5 += 64;
  368. va6 += 64;
  369. va7 += 64;
  370. v_x += 64;
  371. }
  372. #endif
  373. y[0] += alpha * (temp0[0] + temp0[1]);
  374. y[1] += alpha * (temp1[0] + temp1[1]);
  375. y[2] += alpha * (temp2[0] + temp2[1]);
  376. y[3] += alpha * (temp3[0] + temp3[1]);
  377. y[4] += alpha * (temp4[0] + temp4[1]);
  378. y[5] += alpha * (temp5[0] + temp5[1]);
  379. y[6] += alpha * (temp6[0] + temp6[1]);
  380. y[7] += alpha * (temp7[0] + temp7[1]);
  381. }
  382. #endif
  383. static void dgemv_kernel_4x4(BLASLONG n, BLASLONG lda, FLOAT *ap, FLOAT *x, FLOAT *y, FLOAT alpha) {
  384. BLASLONG i = 0;
  385. FLOAT *a0, *a1, *a2, *a3;
  386. a0 = ap;
  387. a1 = ap + lda;
  388. a2 = a1 + lda;
  389. a3 = a2 + lda;
  390. __vector double* va0 = (__vector double*) a0;
  391. __vector double* va1 = (__vector double*) a1;
  392. __vector double* va2 = (__vector double*) a2;
  393. __vector double* va3 = (__vector double*) a3;
  394. __vector double* v_x = (__vector double*) x;
  395. register __vector double temp0 = {0, 0};
  396. register __vector double temp1 = {0, 0};
  397. register __vector double temp2 = {0, 0};
  398. register __vector double temp3 = {0, 0};
  399. register __vector double temp4 = {0, 0};
  400. register __vector double temp5 = {0, 0};
  401. register __vector double temp6 = {0, 0};
  402. register __vector double temp7 = {0, 0};
  403. for (i = 0; i < n / 2; i += 2) {
  404. temp0 += v_x[i] * va0[i];
  405. temp1 += v_x[i] * va1[i];
  406. temp2 += v_x[i] * va2[i];
  407. temp3 += v_x[i] * va3[i];
  408. temp4 += v_x[i + 1] * va0[i + 1];
  409. temp5 += v_x[i + 1] * va1[i + 1];
  410. temp6 += v_x[i + 1] * va2[i + 1];
  411. temp7 += v_x[i + 1] * va3[i + 1];
  412. }
  413. temp0 += temp4;
  414. temp1 += temp5;
  415. temp2 += temp6;
  416. temp3 += temp7;
  417. y[0] += alpha * (temp0[0] + temp0[1]);
  418. y[1] += alpha * (temp1[0] + temp1[1]);
  419. y[2] += alpha * (temp2[0] + temp2[1]);
  420. y[3] += alpha * (temp3[0] + temp3[1]);
  421. }
  422. static void dgemv_kernel_4x2(BLASLONG n, BLASLONG lda, FLOAT *ap, FLOAT *x, FLOAT *y, FLOAT alpha, BLASLONG inc_y) {
  423. BLASLONG i;
  424. FLOAT *a0, *a1;
  425. a0 = ap;
  426. a1 = ap + lda;
  427. __vector double* va0 = (__vector double*) a0;
  428. __vector double* va1 = (__vector double*) a1;
  429. __vector double* v_x = (__vector double*) x;
  430. __vector double temp0 = {0, 0};
  431. __vector double temp1 = {0, 0};
  432. for (i = 0; i < n / 2; i += 2) {
  433. temp0 += v_x[i] * va0[i] + v_x[i + 1] * va0[i + 1];
  434. temp1 += v_x[i] * va1[i] + v_x[i + 1] * va1[i + 1];
  435. }
  436. y[0] += alpha * (temp0[0] + temp0[1]);
  437. y[inc_y] += alpha * (temp1[0] + temp1[1]);
  438. }
  439. static void dgemv_kernel_4x1(BLASLONG n, FLOAT *ap, FLOAT *x, FLOAT *y, FLOAT alpha) {
  440. BLASLONG i;
  441. FLOAT *a0;
  442. a0 = ap;
  443. __vector double* va0 = (__vector double*) a0;
  444. __vector double* v_x = (__vector double*) x;
  445. __vector double temp0 = {0, 0};
  446. for (i = 0; i < n / 2; i += 2) {
  447. temp0 += v_x[i] * va0[i] + v_x[i + 1] * va0[i + 1];
  448. }
  449. *y += alpha * (temp0[0] + temp0[1]);
  450. }
  451. static void copy_x(BLASLONG n, FLOAT *src, FLOAT *dest, BLASLONG inc_src) {
  452. BLASLONG i;
  453. for (i = 0; i < n; i++) {
  454. *dest++ = *src;
  455. src += inc_src;
  456. }
  457. }
  458. int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *buffer) {
  459. BLASLONG i;
  460. BLASLONG j;
  461. FLOAT *a_ptr;
  462. FLOAT *x_ptr;
  463. FLOAT *y_ptr;
  464. BLASLONG n1;
  465. BLASLONG m1;
  466. BLASLONG m2;
  467. BLASLONG m3;
  468. BLASLONG n2;
  469. FLOAT ybuffer[8] __attribute__((aligned(16)));
  470. FLOAT *xbuffer;
  471. if (m < 1) return (0);
  472. if (n < 1) return (0);
  473. xbuffer = buffer;
  474. n1 = n >> 3;
  475. n2 = n & 7;
  476. m3 = m & 3;
  477. m1 = m - m3;
  478. m2 = (m & (NBMAX - 1)) - m3;
  479. BLASLONG NB = NBMAX;
  480. while (NB == NBMAX) {
  481. m1 -= NB;
  482. if (m1 < 0) {
  483. if (m2 == 0) break;
  484. NB = m2;
  485. }
  486. y_ptr = y;
  487. a_ptr = a;
  488. x_ptr = x;
  489. if (inc_x != 1)
  490. copy_x(NB, x_ptr, xbuffer, inc_x);
  491. else
  492. xbuffer = x_ptr;
  493. BLASLONG lda8 = lda << 3;
  494. if (inc_y == 1) {
  495. for (i = 0; i < n1; i++) {
  496. dgemv_kernel_4x8(NB, lda, a_ptr, xbuffer, y_ptr, alpha);
  497. y_ptr += 8;
  498. a_ptr += lda8;
  499. #if defined(PREFETCH)
  500. __builtin_prefetch(y_ptr+64);
  501. #endif
  502. }
  503. } else {
  504. for (i = 0; i < n1; i++) {
  505. ybuffer[0] = 0;
  506. ybuffer[1] = 0;
  507. ybuffer[2] = 0;
  508. ybuffer[3] = 0;
  509. ybuffer[4] = 0;
  510. ybuffer[5] = 0;
  511. ybuffer[6] = 0;
  512. ybuffer[7] = 0;
  513. dgemv_kernel_4x8(NB, lda, a_ptr, xbuffer, ybuffer, alpha);
  514. *y_ptr += ybuffer[0];
  515. y_ptr += inc_y;
  516. *y_ptr += ybuffer[1];
  517. y_ptr += inc_y;
  518. *y_ptr += ybuffer[2];
  519. y_ptr += inc_y;
  520. *y_ptr += ybuffer[3];
  521. y_ptr += inc_y;
  522. *y_ptr += ybuffer[4];
  523. y_ptr += inc_y;
  524. *y_ptr += ybuffer[5];
  525. y_ptr += inc_y;
  526. *y_ptr += ybuffer[6];
  527. y_ptr += inc_y;
  528. *y_ptr += ybuffer[7];
  529. y_ptr += inc_y;
  530. a_ptr += lda8;
  531. }
  532. }
  533. if (n2 & 4) {
  534. ybuffer[0] = 0;
  535. ybuffer[1] = 0;
  536. ybuffer[2] = 0;
  537. ybuffer[3] = 0;
  538. dgemv_kernel_4x4(NB, lda, a_ptr, xbuffer, ybuffer, alpha);
  539. a_ptr += lda<<2;
  540. *y_ptr += ybuffer[0];
  541. y_ptr += inc_y;
  542. *y_ptr += ybuffer[1];
  543. y_ptr += inc_y;
  544. *y_ptr += ybuffer[2];
  545. y_ptr += inc_y;
  546. *y_ptr += ybuffer[3];
  547. y_ptr += inc_y;
  548. }
  549. if (n2 & 2) {
  550. dgemv_kernel_4x2(NB, lda, a_ptr, xbuffer, y_ptr, alpha, inc_y);
  551. a_ptr += lda << 1;
  552. y_ptr += 2 * inc_y;
  553. }
  554. if (n2 & 1) {
  555. dgemv_kernel_4x1(NB, a_ptr, xbuffer, y_ptr, alpha);
  556. a_ptr += lda;
  557. y_ptr += inc_y;
  558. }
  559. a += NB;
  560. x += NB * inc_x;
  561. }
  562. if (m3 == 0) return (0);
  563. x_ptr = x;
  564. a_ptr = a;
  565. if (m3 == 3) {
  566. FLOAT xtemp0 = *x_ptr * alpha;
  567. x_ptr += inc_x;
  568. FLOAT xtemp1 = *x_ptr * alpha;
  569. x_ptr += inc_x;
  570. FLOAT xtemp2 = *x_ptr * alpha;
  571. FLOAT *aj = a_ptr;
  572. y_ptr = y;
  573. if (lda == 3 && inc_y == 1) {
  574. for (j = 0; j < (n & -4); j += 4) {
  575. y_ptr[j] += aj[0] * xtemp0 + aj[1] * xtemp1 + aj[2] * xtemp2;
  576. y_ptr[j + 1] += aj[3] * xtemp0 + aj[4] * xtemp1 + aj[5] * xtemp2;
  577. y_ptr[j + 2] += aj[6] * xtemp0 + aj[7] * xtemp1 + aj[8] * xtemp2;
  578. y_ptr[j + 3] += aj[9] * xtemp0 + aj[10] * xtemp1 + aj[11] * xtemp2;
  579. aj += 12;
  580. }
  581. for (; j < n; j++) {
  582. y_ptr[j] += aj[0] * xtemp0 + aj[1] * xtemp1 + aj[2] * xtemp2;
  583. aj += 3;
  584. }
  585. } else {
  586. if (inc_y == 1) {
  587. BLASLONG register lda2 = lda << 1;
  588. BLASLONG register lda4 = lda << 2;
  589. BLASLONG register lda3 = lda2 + lda;
  590. for (j = 0; j < (n & -4); j += 4) {
  591. y_ptr[j] += *aj * xtemp0 + *(aj + 1) * xtemp1 + *(aj + 2) * xtemp2;
  592. y_ptr[j + 1] += *(aj + lda) * xtemp0 + *(aj + lda + 1) * xtemp1 + *(aj + lda + 2) * xtemp2;
  593. y_ptr[j + 2] += *(aj + lda2) * xtemp0 + *(aj + lda2 + 1) * xtemp1 + *(aj + lda2 + 2) * xtemp2;
  594. y_ptr[j + 3] += *(aj + lda3) * xtemp0 + *(aj + lda3 + 1) * xtemp1 + *(aj + lda3 + 2) * xtemp2;
  595. aj += lda4;
  596. }
  597. for (; j < n; j++) {
  598. y_ptr[j] += *aj * xtemp0 + *(aj + 1) * xtemp1 + *(aj + 2) * xtemp2;
  599. aj += lda;
  600. }
  601. } else {
  602. for (j = 0; j < n; j++) {
  603. *y_ptr += *aj * xtemp0 + *(aj + 1) * xtemp1 + *(aj + 2) * xtemp2;
  604. y_ptr += inc_y;
  605. aj += lda;
  606. }
  607. }
  608. }
  609. return (0);
  610. }
  611. if (m3 == 2) {
  612. FLOAT xtemp0 = *x_ptr * alpha;
  613. x_ptr += inc_x;
  614. FLOAT xtemp1 = *x_ptr * alpha;
  615. FLOAT *aj = a_ptr;
  616. y_ptr = y;
  617. if (lda == 2 && inc_y == 1) {
  618. for (j = 0; j < (n & -4); j += 4) {
  619. y_ptr[j] += aj[0] * xtemp0 + aj[1] * xtemp1;
  620. y_ptr[j + 1] += aj[2] * xtemp0 + aj[3] * xtemp1;
  621. y_ptr[j + 2] += aj[4] * xtemp0 + aj[5] * xtemp1;
  622. y_ptr[j + 3] += aj[6] * xtemp0 + aj[7] * xtemp1;
  623. aj += 8;
  624. }
  625. for (; j < n; j++) {
  626. y_ptr[j] += aj[0] * xtemp0 + aj[1] * xtemp1;
  627. aj += 2;
  628. }
  629. } else {
  630. if (inc_y == 1) {
  631. BLASLONG register lda2 = lda << 1;
  632. BLASLONG register lda4 = lda << 2;
  633. BLASLONG register lda3 = lda2 + lda;
  634. for (j = 0; j < (n & -4); j += 4) {
  635. y_ptr[j] += *aj * xtemp0 + *(aj + 1) * xtemp1;
  636. y_ptr[j + 1] += *(aj + lda) * xtemp0 + *(aj + lda + 1) * xtemp1;
  637. y_ptr[j + 2] += *(aj + lda2) * xtemp0 + *(aj + lda2 + 1) * xtemp1;
  638. y_ptr[j + 3] += *(aj + lda3) * xtemp0 + *(aj + lda3 + 1) * xtemp1;
  639. aj += lda4;
  640. }
  641. for (; j < n; j++) {
  642. y_ptr[j] += *aj * xtemp0 + *(aj + 1) * xtemp1;
  643. aj += lda;
  644. }
  645. } else {
  646. for (j = 0; j < n; j++) {
  647. *y_ptr += *aj * xtemp0 + *(aj + 1) * xtemp1;
  648. y_ptr += inc_y;
  649. aj += lda;
  650. }
  651. }
  652. }
  653. return (0);
  654. }
  655. FLOAT xtemp = *x_ptr * alpha;
  656. FLOAT *aj = a_ptr;
  657. y_ptr = y;
  658. if (lda == 1 && inc_y == 1) {
  659. for (j = 0; j < (n & -4); j += 4) {
  660. y_ptr[j] += aj[j] * xtemp;
  661. y_ptr[j + 1] += aj[j + 1] * xtemp;
  662. y_ptr[j + 2] += aj[j + 2] * xtemp;
  663. y_ptr[j + 3] += aj[j + 3] * xtemp;
  664. }
  665. for (; j < n; j++) {
  666. y_ptr[j] += aj[j] * xtemp;
  667. }
  668. } else {
  669. if (inc_y == 1) {
  670. BLASLONG register lda2 = lda << 1;
  671. BLASLONG register lda4 = lda << 2;
  672. BLASLONG register lda3 = lda2 + lda;
  673. for (j = 0; j < (n & -4); j += 4) {
  674. y_ptr[j] += *aj * xtemp;
  675. y_ptr[j + 1] += *(aj + lda) * xtemp;
  676. y_ptr[j + 2] += *(aj + lda2) * xtemp;
  677. y_ptr[j + 3] += *(aj + lda3) * xtemp;
  678. aj += lda4;
  679. }
  680. for (; j < n; j++) {
  681. y_ptr[j] += *aj * xtemp;
  682. aj += lda;
  683. }
  684. } else {
  685. for (j = 0; j < n; j++) {
  686. *y_ptr += *aj * xtemp;
  687. y_ptr += inc_y;
  688. aj += lda;
  689. }
  690. }
  691. }
  692. return (0);
  693. }