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

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