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_n_power10.c 8.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /***************************************************************************
  2. Copyright (c) 2020, 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 "dgemv_n_microk_power10.c"
  29. #define NBMAX 4096
  30. #ifndef HAVE_KERNEL_4x4
  31. static void dgemv_kernel_4x4(BLASLONG n, FLOAT *a_ptr, BLASLONG lda, FLOAT *xo, FLOAT *y, FLOAT alpha)
  32. {
  33. BLASLONG i;
  34. FLOAT x[4] __attribute__ ((aligned (16)));;
  35. FLOAT *a0 = a_ptr;
  36. FLOAT *a1 = a0 + lda;
  37. FLOAT *a2 = a1 + lda;
  38. FLOAT *a3 = a2 + lda;
  39. for ( i=0; i<4; i++)
  40. x[i] = xo[i] * alpha;
  41. for ( i=0; i< n; i+=4 )
  42. {
  43. y[i] += a0[i]*x[0] + a1[i]*x[1] + a2[i]*x[2] + a3[i]*x[3];
  44. y[i+1] += a0[i+1]*x[0] + a1[i+1]*x[1] + a2[i+1]*x[2] + a3[i+1]*x[3];
  45. y[i+2] += a0[i+2]*x[0] + a1[i+2]*x[1] + a2[i+2]*x[2] + a3[i+2]*x[3];
  46. y[i+3] += a0[i+3]*x[0] + a1[i+3]*x[1] + a2[i+3]*x[2] + a3[i+3]*x[3];
  47. }
  48. }
  49. #endif
  50. #ifndef HAVE_KERNEL_4x2
  51. static void dgemv_kernel_4x2(BLASLONG n, FLOAT *a0, FLOAT *a1, FLOAT *xo, FLOAT *y, FLOAT alpha)
  52. {
  53. BLASLONG i;
  54. FLOAT x[4] __attribute__ ((aligned (16)));;
  55. for ( i=0; i<2; i++)
  56. x[i] = xo[i] * alpha;
  57. for ( i=0; i< n; i+=4 )
  58. {
  59. y[i] += a0[i]*x[0] + a1[i]*x[1];
  60. y[i+1] += a0[i+1]*x[0] + a1[i+1]*x[1];
  61. y[i+2] += a0[i+2]*x[0] + a1[i+2]*x[1];
  62. y[i+3] += a0[i+3]*x[0] + a1[i+3]*x[1];
  63. }
  64. }
  65. #endif
  66. #ifndef HAVE_KERNEL_4x1
  67. static void dgemv_kernel_4x1(BLASLONG n, FLOAT *a0, FLOAT *xo, FLOAT *y, FLOAT alpha)
  68. {
  69. BLASLONG i;
  70. FLOAT x[4] __attribute__ ((aligned (16)));;
  71. for ( i=0; i<1; i++)
  72. x[i] = xo[i] * alpha;
  73. for ( i=0; i< n; i+=4 )
  74. {
  75. y[i] += a0[i]*x[0];
  76. y[i+1] += a0[i+1]*x[0];
  77. y[i+2] += a0[i+2]*x[0];
  78. y[i+3] += a0[i+3]*x[0];
  79. }
  80. }
  81. #endif
  82. static void add_y(BLASLONG n, FLOAT *src, FLOAT *dest, BLASLONG inc_dest)
  83. {
  84. BLASLONG i;
  85. if ( inc_dest != 1 )
  86. {
  87. for ( i=0; i<n; i++ )
  88. {
  89. *dest += *src;
  90. src++;
  91. dest += inc_dest;
  92. }
  93. return;
  94. }
  95. }
  96. 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)
  97. {
  98. BLASLONG i;
  99. FLOAT *a_ptr;
  100. FLOAT *x_ptr;
  101. FLOAT *y_ptr;
  102. BLASLONG m1;
  103. BLASLONG m2;
  104. BLASLONG m3;
  105. BLASLONG n2;
  106. BLASLONG lda4 = lda << 2;
  107. BLASLONG lda8 = lda << 3;
  108. FLOAT xbuffer[8] __attribute__ ((aligned (16)));
  109. FLOAT *ybuffer;
  110. if ( m < 1 ) return(0);
  111. if ( n < 1 ) return(0);
  112. ybuffer = buffer;
  113. BLASLONG n8 = n >> 3;
  114. n2 = n & 3;
  115. m3 = m & 3 ;
  116. m1 = m & -4 ;
  117. m2 = (m & (NBMAX-1)) - m3 ;
  118. y_ptr = y;
  119. BLASLONG NB = NBMAX;
  120. while ( NB == NBMAX )
  121. {
  122. m1 -= NB;
  123. if ( m1 < 0)
  124. {
  125. if ( m2 == 0 ) break;
  126. NB = m2;
  127. }
  128. a_ptr = a;
  129. x_ptr = x;
  130. if ( inc_y != 1 )
  131. memset(ybuffer,0,NB*8);
  132. else
  133. ybuffer = y_ptr;
  134. if ( inc_x == 1 )
  135. {
  136. for( i = 0; i < n8 ; i++)
  137. {
  138. dgemv_kernel_4x8(NB,a_ptr,lda,x_ptr,ybuffer,alpha);
  139. a_ptr += lda8;
  140. x_ptr += 8;
  141. }
  142. if( n & 4 )
  143. {
  144. dgemv_kernel_4x4(NB,a_ptr,lda,x_ptr,ybuffer,alpha);
  145. a_ptr += lda4;
  146. x_ptr += 4;
  147. }
  148. if ( n2 & 2 )
  149. {
  150. dgemv_kernel_4x2(NB,a_ptr,a_ptr+lda,x_ptr,ybuffer,alpha);
  151. a_ptr += lda*2;
  152. x_ptr += 2;
  153. }
  154. if ( n2 & 1 )
  155. {
  156. dgemv_kernel_4x1(NB,a_ptr,x_ptr,ybuffer,alpha);
  157. a_ptr += lda;
  158. x_ptr += 1;
  159. }
  160. }
  161. else
  162. {
  163. for( i = 0; i < n8 ; i++)
  164. {
  165. BLASLONG j;
  166. for ( j = 0; j < 8 ; j++)
  167. {
  168. xbuffer[j] = x_ptr[0];
  169. x_ptr += inc_x;
  170. }
  171. dgemv_kernel_4x8(NB,a_ptr,lda,xbuffer,ybuffer,alpha);
  172. a_ptr += lda8;
  173. }
  174. if( n & 4 )
  175. {
  176. xbuffer[0] = x_ptr[0];
  177. x_ptr += inc_x;
  178. xbuffer[1] = x_ptr[0];
  179. x_ptr += inc_x;
  180. xbuffer[2] = x_ptr[0];
  181. x_ptr += inc_x;
  182. xbuffer[3] = x_ptr[0];
  183. x_ptr += inc_x;
  184. dgemv_kernel_4x4(NB,a_ptr,lda,xbuffer,ybuffer,alpha);
  185. a_ptr += lda4;
  186. }
  187. for( i = 0; i < n2 ; i++)
  188. {
  189. xbuffer[0] = x_ptr[0];
  190. x_ptr += inc_x;
  191. dgemv_kernel_4x1(NB,a_ptr,xbuffer,ybuffer,alpha);
  192. a_ptr += lda;
  193. }
  194. }
  195. a += NB;
  196. if ( inc_y != 1 )
  197. {
  198. add_y(NB,ybuffer,y_ptr,inc_y);
  199. y_ptr += NB * inc_y;
  200. }
  201. else
  202. y_ptr += NB ;
  203. }
  204. if ( m3 == 0 ) return(0);
  205. if ( m3 == 3 )
  206. {
  207. a_ptr = a;
  208. x_ptr = x;
  209. FLOAT temp0 = 0.0;
  210. FLOAT temp1 = 0.0;
  211. FLOAT temp2 = 0.0;
  212. if ( lda == 3 && inc_x ==1 )
  213. {
  214. for( i = 0; i < ( n & -4 ); i+=4 )
  215. {
  216. temp0 += a_ptr[0] * x_ptr[0] + a_ptr[3] * x_ptr[1];
  217. temp1 += a_ptr[1] * x_ptr[0] + a_ptr[4] * x_ptr[1];
  218. temp2 += a_ptr[2] * x_ptr[0] + a_ptr[5] * x_ptr[1];
  219. temp0 += a_ptr[6] * x_ptr[2] + a_ptr[9] * x_ptr[3];
  220. temp1 += a_ptr[7] * x_ptr[2] + a_ptr[10] * x_ptr[3];
  221. temp2 += a_ptr[8] * x_ptr[2] + a_ptr[11] * x_ptr[3];
  222. a_ptr += 12;
  223. x_ptr += 4;
  224. }
  225. for( ; i < n; i++ )
  226. {
  227. temp0 += a_ptr[0] * x_ptr[0];
  228. temp1 += a_ptr[1] * x_ptr[0];
  229. temp2 += a_ptr[2] * x_ptr[0];
  230. a_ptr += 3;
  231. x_ptr ++;
  232. }
  233. }
  234. else
  235. {
  236. for( i = 0; i < n; i++ )
  237. {
  238. temp0 += a_ptr[0] * x_ptr[0];
  239. temp1 += a_ptr[1] * x_ptr[0];
  240. temp2 += a_ptr[2] * x_ptr[0];
  241. a_ptr += lda;
  242. x_ptr += inc_x;
  243. }
  244. }
  245. y_ptr[0] += alpha * temp0;
  246. y_ptr += inc_y;
  247. y_ptr[0] += alpha * temp1;
  248. y_ptr += inc_y;
  249. y_ptr[0] += alpha * temp2;
  250. return(0);
  251. }
  252. if ( m3 == 2 )
  253. {
  254. a_ptr = a;
  255. x_ptr = x;
  256. FLOAT temp0 = 0.0;
  257. FLOAT temp1 = 0.0;
  258. if ( lda == 2 && inc_x ==1 )
  259. {
  260. for( i = 0; i < (n & -4) ; i+=4 )
  261. {
  262. temp0 += a_ptr[0] * x_ptr[0] + a_ptr[2] * x_ptr[1];
  263. temp1 += a_ptr[1] * x_ptr[0] + a_ptr[3] * x_ptr[1];
  264. temp0 += a_ptr[4] * x_ptr[2] + a_ptr[6] * x_ptr[3];
  265. temp1 += a_ptr[5] * x_ptr[2] + a_ptr[7] * x_ptr[3];
  266. a_ptr += 8;
  267. x_ptr += 4;
  268. }
  269. for( ; i < n; i++ )
  270. {
  271. temp0 += a_ptr[0] * x_ptr[0];
  272. temp1 += a_ptr[1] * x_ptr[0];
  273. a_ptr += 2;
  274. x_ptr ++;
  275. }
  276. }
  277. else
  278. {
  279. for( i = 0; i < n; i++ )
  280. {
  281. temp0 += a_ptr[0] * x_ptr[0];
  282. temp1 += a_ptr[1] * x_ptr[0];
  283. a_ptr += lda;
  284. x_ptr += inc_x;
  285. }
  286. }
  287. y_ptr[0] += alpha * temp0;
  288. y_ptr += inc_y;
  289. y_ptr[0] += alpha * temp1;
  290. return(0);
  291. }
  292. if ( m3 == 1 )
  293. {
  294. a_ptr = a;
  295. x_ptr = x;
  296. FLOAT temp = 0.0;
  297. if ( lda == 1 && inc_x ==1 )
  298. {
  299. for( i = 0; i < (n & -4); i+=4 )
  300. {
  301. temp += a_ptr[i] * x_ptr[i] + a_ptr[i+1] * x_ptr[i+1] + a_ptr[i+2] * x_ptr[i+2] + a_ptr[i+3] * x_ptr[i+3];
  302. }
  303. for( ; i < n; i++ )
  304. {
  305. temp += a_ptr[i] * x_ptr[i];
  306. }
  307. }
  308. else
  309. {
  310. for( i = 0; i < n; i++ )
  311. {
  312. temp += a_ptr[0] * x_ptr[0];
  313. a_ptr += lda;
  314. x_ptr += inc_x;
  315. }
  316. }
  317. y_ptr[0] += alpha * temp;
  318. return(0);
  319. }
  320. return(0);
  321. }