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.

cdot_msa.c 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*******************************************************************************
  2. Copyright (c) 2016, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *******************************************************************************/
  27. #include "common.h"
  28. #include "macros_msa.h"
  29. #if !defined(CONJ)
  30. #define OP1 -=
  31. #define OP2 +=
  32. #define OP3 -
  33. #define OP4 +
  34. #else
  35. #define OP1 +=
  36. #define OP2 -=
  37. #define OP3 +
  38. #define OP4 -
  39. #endif
  40. OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  41. {
  42. BLASLONG i = 0;
  43. FLOAT dot[2];
  44. BLASLONG inc_x2, inc_y2;
  45. FLOAT x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, y6, y7;
  46. v4f32 vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7, vx8, vx9, vx10, vx11;
  47. v4f32 vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7, vy8, vy9, vy10, vy11;
  48. v4f32 vx0r, vx0i, vx1r, vx1i, vx2r, vx2i, vx3r, vx3i;
  49. v4f32 vy0r, vy0i, vy1r, vy1i, vy2r, vy2i, vy3r, vy3i;
  50. v4f32 dot0 = {0, 0, 0, 0};
  51. v4f32 dot1 = {0, 0, 0, 0};
  52. v4f32 dot2 = {0, 0, 0, 0};
  53. v4f32 dot3 = {0, 0, 0, 0};
  54. v4f32 dot4 = {0, 0, 0, 0};
  55. v4f32 dot5 = {0, 0, 0, 0};
  56. v4f32 dot6 = {0, 0, 0, 0};
  57. v4f32 dot7 = {0, 0, 0, 0};
  58. OPENBLAS_COMPLEX_FLOAT result;
  59. dot[0] = 0.0;
  60. dot[1] = 0.0;
  61. CREAL(result) = 0.0;
  62. CIMAG(result) = 0.0;
  63. if (n < 1) return (result);
  64. if ((1 == inc_x) && (1 == inc_y))
  65. {
  66. if (n > 15)
  67. {
  68. FLOAT *x_pref, *y_pref;
  69. BLASLONG pref_offset;
  70. pref_offset = (BLASLONG)x & (L1_DATA_LINESIZE - 1);
  71. if (pref_offset > 0)
  72. {
  73. pref_offset = L1_DATA_LINESIZE - pref_offset;
  74. pref_offset = pref_offset / sizeof(FLOAT);
  75. }
  76. x_pref = x + pref_offset + 64 + 16;
  77. pref_offset = (BLASLONG)y & (L1_DATA_LINESIZE - 1);
  78. if (pref_offset > 0)
  79. {
  80. pref_offset = L1_DATA_LINESIZE - pref_offset;
  81. pref_offset = pref_offset / sizeof(FLOAT);
  82. }
  83. y_pref = y + pref_offset + 64 + 16;
  84. LD_SP4_INC(x, 4, vx0, vx1, vx2, vx3);
  85. LD_SP4_INC(y, 4, vy0, vy1, vy2, vy3);
  86. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  87. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  88. for (i = (n >> 4) - 1; i--;)
  89. {
  90. PREF_OFFSET(x_pref, 0);
  91. PREF_OFFSET(x_pref, 32);
  92. PREF_OFFSET(x_pref, 64);
  93. PREF_OFFSET(x_pref, 96);
  94. PREF_OFFSET(y_pref, 0);
  95. PREF_OFFSET(y_pref, 32);
  96. PREF_OFFSET(y_pref, 64);
  97. PREF_OFFSET(y_pref, 96);
  98. x_pref += 32;
  99. y_pref += 32;
  100. vx4 = LD_SP(x); x += 4;
  101. vx1r = (v4f32) __msa_pckev_w((v4i32) vx3, (v4i32) vx2);
  102. dot0 += (vx0r * vy0r);
  103. vx5 = LD_SP(x); x += 4;
  104. vx1i = (v4f32) __msa_pckod_w((v4i32) vx3, (v4i32) vx2);
  105. dot1 OP2 (vx0i * vy0r);
  106. vy4 = LD_SP(y); y += 4;
  107. vy1r = (v4f32) __msa_pckev_w((v4i32) vy3, (v4i32) vy2);
  108. dot2 += (vx1r * vy1r);
  109. vy5 = LD_SP(y); y += 4;
  110. vy1i = (v4f32) __msa_pckod_w((v4i32) vy3, (v4i32) vy2);
  111. dot3 OP2 (vx1i * vy1r);
  112. vx6 = LD_SP(x); x += 4;
  113. vx7 = LD_SP(x); x += 4;
  114. vy6 = LD_SP(y); y += 4;
  115. vy7 = LD_SP(y); y += 4;
  116. vx8 = LD_SP(x); x += 4;
  117. dot0 OP1 (vx0i * vy0i);
  118. vx9 = LD_SP(x); x += 4;
  119. vx2r = (v4f32) __msa_pckev_w((v4i32) vx5, (v4i32) vx4);
  120. dot1 += (vx0r * vy0i);
  121. vy8 = LD_SP(y); y += 4;
  122. vx2i = (v4f32) __msa_pckod_w((v4i32) vx5, (v4i32) vx4);
  123. dot2 OP1 (vx1i * vy1i);
  124. vy9 = LD_SP(y); y += 4;
  125. vy2r = (v4f32) __msa_pckev_w((v4i32) vy5, (v4i32) vy4);
  126. dot3 += (vx1r * vy1i);
  127. vx10 = LD_SP(x); x += 4;
  128. vy2i = (v4f32) __msa_pckod_w((v4i32) vy5, (v4i32) vy4);
  129. vx11 = LD_SP(x); x += 4;
  130. vx3r = (v4f32) __msa_pckev_w((v4i32) vx7, (v4i32) vx6);
  131. dot4 += (vx2r * vy2r);
  132. vy10 = LD_SP(y); y += 4;
  133. vx3i = (v4f32) __msa_pckod_w((v4i32) vx7, (v4i32) vx6);
  134. dot5 OP2 (vx2i * vy2r);
  135. vy11 = LD_SP(y); y += 4;
  136. vy3r = (v4f32) __msa_pckev_w((v4i32) vy7, (v4i32) vy6);
  137. vy3i = (v4f32) __msa_pckod_w((v4i32) vy7, (v4i32) vy6);
  138. dot6 += (vx3r * vy3r);
  139. vx0r = (v4f32) __msa_pckev_w((v4i32) vx9, (v4i32) vx8);
  140. dot7 OP2 (vx3i * vy3r);
  141. vx0i = (v4f32) __msa_pckod_w((v4i32) vx9, (v4i32) vx8);
  142. vy0r = (v4f32) __msa_pckev_w((v4i32) vy9, (v4i32) vy8);
  143. vx2 = vx10;
  144. vy0i = (v4f32) __msa_pckod_w((v4i32) vy9, (v4i32) vy8);
  145. vx3 = vx11;
  146. dot4 OP1 (vx2i * vy2i);
  147. vy2 = vy10;
  148. dot5 += (vx2r * vy2i);
  149. vy3 = vy11;
  150. dot6 OP1 (vx3i * vy3i);
  151. dot7 += (vx3r * vy3i);
  152. }
  153. vx4 = LD_SP(x); x += 4;
  154. vx1r = (v4f32) __msa_pckev_w((v4i32) vx3, (v4i32) vx2);
  155. dot0 += (vx0r * vy0r);
  156. vx5 = LD_SP(x); x += 4;
  157. vx1i = (v4f32) __msa_pckod_w((v4i32) vx3, (v4i32) vx2);
  158. dot1 OP2 (vx0i * vy0r);
  159. vy4 = LD_SP(y); y += 4;
  160. vy1r = (v4f32) __msa_pckev_w((v4i32) vy3, (v4i32) vy2);
  161. dot2 += (vx1r * vy1r);
  162. vy5 = LD_SP(y); y += 4;
  163. vy1i = (v4f32) __msa_pckod_w((v4i32) vy3, (v4i32) vy2);
  164. dot3 OP2 (vx1i * vy1r);
  165. vx6 = LD_SP(x); x += 4;
  166. vx7 = LD_SP(x); x += 4;
  167. vy6 = LD_SP(y); y += 4;
  168. vy7 = LD_SP(y); y += 4;
  169. dot0 OP1 (vx0i * vy0i);
  170. vx2r = (v4f32) __msa_pckev_w((v4i32) vx5, (v4i32) vx4);
  171. dot1 += (vx0r * vy0i);
  172. vx2i = (v4f32) __msa_pckod_w((v4i32) vx5, (v4i32) vx4);
  173. dot2 OP1 (vx1i * vy1i);
  174. vy2r = (v4f32) __msa_pckev_w((v4i32) vy5, (v4i32) vy4);
  175. dot3 += (vx1r * vy1i);
  176. vy2i = (v4f32) __msa_pckod_w((v4i32) vy5, (v4i32) vy4);
  177. vx3r = (v4f32) __msa_pckev_w((v4i32) vx7, (v4i32) vx6);
  178. dot4 += (vx2r * vy2r);
  179. vx3i = (v4f32) __msa_pckod_w((v4i32) vx7, (v4i32) vx6);
  180. dot5 OP2 (vx2i * vy2r);
  181. vy3r = (v4f32) __msa_pckev_w((v4i32) vy7, (v4i32) vy6);
  182. vy3i = (v4f32) __msa_pckod_w((v4i32) vy7, (v4i32) vy6);
  183. dot6 += (vx3r * vy3r);
  184. dot7 OP2 (vx3i * vy3r);
  185. dot4 OP1 (vx2i * vy2i);
  186. dot5 += (vx2r * vy2i);
  187. dot6 OP1 (vx3i * vy3i);
  188. dot7 += (vx3r * vy3i);
  189. }
  190. if (n & 15)
  191. {
  192. if (n & 8)
  193. {
  194. LD_SP4_INC(x, 4, vx0, vx1, vx2, vx3);
  195. LD_SP4_INC(y, 4, vy0, vy1, vy2, vy3);
  196. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  197. PCKEVOD_W2_SP(vx3, vx2, vx1r, vx1i);
  198. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  199. PCKEVOD_W2_SP(vy3, vy2, vy1r, vy1i);
  200. dot0 += (vx0r * vy0r);
  201. dot0 OP1 (vx0i * vy0i);
  202. dot1 OP2 (vx0i * vy0r);
  203. dot1 += (vx0r * vy0i);
  204. dot2 += (vx1r * vy1r);
  205. dot2 OP1 (vx1i * vy1i);
  206. dot3 OP2 (vx1i * vy1r);
  207. dot3 += (vx1r * vy1i);
  208. }
  209. if (n & 4)
  210. {
  211. LD_SP2_INC(x, 4, vx0, vx1);
  212. LD_SP2_INC(y, 4, vy0, vy1);
  213. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  214. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  215. dot0 += (vx0r * vy0r);
  216. dot0 OP1 (vx0i * vy0i);
  217. dot1 OP2 (vx0i * vy0r);
  218. dot1 += (vx0r * vy0i);
  219. }
  220. if (n & 2)
  221. {
  222. LD_GP4_INC(x, 1, x0, x1, x2, x3);
  223. LD_GP4_INC(y, 1, y0, y1, y2, y3);
  224. dot[0] += (x0 * y0 OP3 x1 * y1);
  225. dot[1] OP2 (x1 * y0 OP4 x0 * y1);
  226. dot[0] += (x2 * y2 OP3 x3 * y3);
  227. dot[1] OP2 (x3 * y2 OP4 x2 * y3);
  228. }
  229. if (n & 1)
  230. {
  231. LD_GP2_INC(x, 1, x0, x1);
  232. LD_GP2_INC(y, 1, y0, y1);
  233. dot[0] += (x0 * y0 OP3 x1 * y1);
  234. dot[1] OP2 (x1 * y0 OP4 x0 * y1);
  235. }
  236. }
  237. dot0 += dot2 + dot4 + dot6;
  238. dot1 += dot3 + dot5 + dot7;
  239. dot[0] += (dot0[0] + dot0[1] + dot0[2] + dot0[3]);
  240. dot[1] += (dot1[0] + dot1[1] + dot1[2] + dot1[3]);
  241. }
  242. else
  243. {
  244. inc_x2 = 2 * inc_x;
  245. inc_y2 = 2 * inc_y;
  246. for (i = (n >> 2); i--;)
  247. {
  248. x0 = *x;
  249. x1 = *(x + 1);
  250. x += inc_x2;
  251. x2 = *x;
  252. x3 = *(x + 1);
  253. x += inc_x2;
  254. x4 = *x;
  255. x5 = *(x + 1);
  256. x += inc_x2;
  257. x6 = *x;
  258. x7 = *(x + 1);
  259. x += inc_x2;
  260. y0 = *y;
  261. y1 = *(y + 1);
  262. y += inc_y2;
  263. y2 = *y;
  264. y3 = *(y + 1);
  265. y += inc_y2;
  266. y4 = *y;
  267. y5 = *(y + 1);
  268. y += inc_y2;
  269. y6 = *y;
  270. y7 = *(y + 1);
  271. y += inc_y2;
  272. dot[0] += (x0 * y0 OP3 x1 * y1);
  273. dot[1] OP2 (x1 * y0 OP4 x0 * y1);
  274. dot[0] += (x2 * y2 OP3 x3 * y3);
  275. dot[1] OP2 (x3 * y2 OP4 x2 * y3);
  276. dot[0] += (x4 * y4 OP3 x5 * y5);
  277. dot[1] OP2 (x5 * y4 OP4 x4 * y5);
  278. dot[0] += (x6 * y6 OP3 x7 * y7);
  279. dot[1] OP2 (x7 * y6 OP4 x6 * y7);
  280. }
  281. if (n & 2)
  282. {
  283. x0 = *x;
  284. x1 = *(x + 1);
  285. x += inc_x2;
  286. x2 = *x;
  287. x3 = *(x + 1);
  288. x += inc_x2;
  289. y0 = *y;
  290. y1 = *(y + 1);
  291. y += inc_y2;
  292. y2 = *y;
  293. y3 = *(y + 1);
  294. y += inc_y2;
  295. dot[0] += (x0 * y0 OP3 x1 * y1);
  296. dot[1] OP2 (x1 * y0 OP4 x0 * y1);
  297. dot[0] += (x2 * y2 OP3 x3 * y3);
  298. dot[1] OP2 (x3 * y2 OP4 x2 * y3);
  299. }
  300. if (n & 1)
  301. {
  302. x0 = *x;
  303. x1 = *(x + 1);
  304. x += inc_x2;
  305. y0 = *y;
  306. y1 = *(y + 1);
  307. y += inc_y2;
  308. dot[0] += (x0 * y0 OP3 x1 * y1);
  309. dot[1] OP2 (x1 * y0 OP4 x0 * y1);
  310. }
  311. }
  312. CREAL(result) = dot[0];
  313. CIMAG(result) = dot[1];
  314. return (result);
  315. }