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.c 29 kB

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