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 9.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 OP2 +=
  31. #define OP3 -
  32. #define OP4 +
  33. #else
  34. #define OP2 -=
  35. #define OP3 +
  36. #define OP4 -
  37. #endif
  38. #define DOT16_KERNEL(OPR0, OPR1) \
  39. dot0 += (vx0r * vy0r); \
  40. dot0 OPR0## = (vx0i * vy0i); \
  41. dot1 OPR1## = (vx0i * vy0r); \
  42. dot1 += (vx0r * vy0i); \
  43. \
  44. dot0 += (vx1r * vy1r); \
  45. dot0 OPR0## = (vx1i * vy1i); \
  46. dot1 OPR1## = (vx1i * vy1r); \
  47. dot1 += (vx1r * vy1i); \
  48. \
  49. dot0 += (vx2r * vy2r); \
  50. dot0 OPR0## = (vx2i * vy2i); \
  51. dot1 OPR1## = (vx2i * vy2r); \
  52. dot1 += (vx2r * vy2i); \
  53. \
  54. dot0 += (vx3r * vy3r); \
  55. dot0 OPR0## = (vx3i * vy3i); \
  56. dot1 OPR1## = (vx3i * vy3r); \
  57. dot1 += (vx3r * vy3i);
  58. #define DOT12_KERNEL(OPR0, OPR1) \
  59. dot0 += (vx0r * vy0r); \
  60. dot0 OPR0## = (vx0i * vy0i); \
  61. dot1 OPR1## = (vx0i * vy0r); \
  62. dot1 += (vx0r * vy0i); \
  63. \
  64. dot0 += (vx1r * vy1r); \
  65. dot0 OPR0## = (vx1i * vy1i); \
  66. dot1 OPR1## = (vx1i * vy1r); \
  67. dot1 += (vx1r * vy1i); \
  68. \
  69. dot0 += (vx2r * vy2r); \
  70. dot0 OPR0## = (vx2i * vy2i); \
  71. dot1 OPR1## = (vx2i * vy2r); \
  72. dot1 += (vx2r * vy2i);
  73. #define DOT8_KERNEL(OPR0, OPR1) \
  74. dot0 += (vx0r * vy0r); \
  75. dot0 OPR0## = (vx0i * vy0i); \
  76. dot1 OPR1## = (vx0i * vy0r); \
  77. dot1 += (vx0r * vy0i); \
  78. \
  79. dot0 += (vx1r * vy1r); \
  80. dot0 OPR0## = (vx1i * vy1i); \
  81. dot1 OPR1## = (vx1i * vy1r); \
  82. dot1 += (vx1r * vy1i);
  83. #define DOT4_KERNEL(OPR0, OPR1) \
  84. dot0 += (vx0r * vy0r); \
  85. dot0 OPR0## = (vx0i * vy0i); \
  86. dot1 OPR1## = (vx0i * vy0r); \
  87. dot1 += (vx0r * vy0i);
  88. /* return float, x,y float */
  89. /* cdotc - CONJ */
  90. /* cdotu - !CONJ */
  91. #ifndef _MSC_VER
  92. #include <complex.h>
  93. FLOAT _Complex CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  94. #else
  95. OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  96. #endif
  97. {
  98. BLASLONG i = 0;
  99. FLOAT dot[2];
  100. BLASLONG inc_x2;
  101. BLASLONG inc_y2;
  102. FLOAT x0, x1, x2, x3, x4, x5, x6, x7;
  103. FLOAT y0, y1, y2, y3, y4, y5, y6, y7;
  104. v4f32 vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7;
  105. v4f32 vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7;
  106. v4f32 vx0r, vx0i, vx1r, vx1i, vx2r, vx2i, vx3r, vx3i;
  107. v4f32 vy0r, vy0i, vy1r, vy1i, vy2r, vy2i, vy3r, vy3i;
  108. v4f32 dot0 = {0, 0, 0, 0};
  109. v4f32 dot1 = {0, 0, 0, 0};
  110. openblas_complex_float result;
  111. dot[0] = 0.0;
  112. dot[1] = 0.0;
  113. __real__(result) = 0.0;
  114. __imag__(result) = 0.0;
  115. if ( n < 1 ) return(result);
  116. if ((1 == inc_x) && (1 == inc_y))
  117. {
  118. for (i = (n >> 4); i--;)
  119. {
  120. LD_SP8_INC(x, 4, vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7);
  121. LD_SP8_INC(y, 4, vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7);
  122. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  123. PCKEVOD_W2_SP(vx3, vx2, vx1r, vx1i);
  124. PCKEVOD_W2_SP(vx5, vx4, vx2r, vx2i);
  125. PCKEVOD_W2_SP(vx7, vx6, vx3r, vx3i);
  126. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  127. PCKEVOD_W2_SP(vy3, vy2, vy1r, vy1i);
  128. PCKEVOD_W2_SP(vy5, vy4, vy2r, vy2i);
  129. PCKEVOD_W2_SP(vy7, vy6, vy3r, vy3i);
  130. #if !defined(CONJ)
  131. DOT16_KERNEL(-, +);
  132. #else
  133. DOT16_KERNEL(+, -);
  134. #endif
  135. }
  136. if (n & 15)
  137. {
  138. if ((n & 8) && (n & 4))
  139. {
  140. LD_SP4_INC(x, 4, vx0, vx1, vx2, vx3);
  141. LD_SP4_INC(y, 4, vy0, vy1, vy2, vy3);
  142. LD_SP2_INC(x, 4, vx4, vx5);
  143. LD_SP2_INC(y, 4, vy4, vy5);
  144. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  145. PCKEVOD_W2_SP(vx3, vx2, vx1r, vx1i);
  146. PCKEVOD_W2_SP(vx5, vx4, vx2r, vx2i);
  147. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  148. PCKEVOD_W2_SP(vy3, vy2, vy1r, vy1i);
  149. PCKEVOD_W2_SP(vy5, vy4, vy2r, vy2i);
  150. #if !defined(CONJ)
  151. DOT12_KERNEL(-, +);
  152. #else
  153. DOT12_KERNEL(+, -);
  154. #endif
  155. }
  156. else if (n & 8)
  157. {
  158. LD_SP4_INC(x, 4, vx0, vx1, vx2, vx3);
  159. LD_SP4_INC(y, 4, vy0, vy1, vy2, vy3);
  160. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  161. PCKEVOD_W2_SP(vx3, vx2, vx1r, vx1i);
  162. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  163. PCKEVOD_W2_SP(vy3, vy2, vy1r, vy1i);
  164. #if !defined(CONJ)
  165. DOT8_KERNEL(-, +);
  166. #else
  167. DOT8_KERNEL(+, -);
  168. #endif
  169. }
  170. else if (n & 4)
  171. {
  172. LD_SP2_INC(x, 4, vx0, vx1);
  173. LD_SP2_INC(y, 4, vy0, vy1);
  174. PCKEVOD_W2_SP(vx1, vx0, vx0r, vx0i);
  175. PCKEVOD_W2_SP(vy1, vy0, vy0r, vy0i);
  176. #if !defined(CONJ)
  177. DOT4_KERNEL(-, +);
  178. #else
  179. DOT4_KERNEL(+, -);
  180. #endif
  181. }
  182. if ((n & 2) && (n & 1))
  183. {
  184. LD_GP6_INC(x, 1, x0, x1, x2, x3, x4, x5);
  185. LD_GP6_INC(y, 1, y0, y1, y2, y3, y4, y5);
  186. dot[0] += ( x0 * y0 OP3 x1 * y1 );
  187. dot[1] OP2 ( x1 * y0 OP4 x0 * y1 );
  188. dot[0] += ( x2 * y2 OP3 x3 * y3 );
  189. dot[1] OP2 ( x3 * y2 OP4 x2 * y3 );
  190. dot[0] += ( x4 * y4 OP3 x5 * y5 );
  191. dot[1] OP2 ( x5 * y4 OP4 x4 * y5 );
  192. }
  193. else if (n & 2)
  194. {
  195. LD_GP4_INC(x, 1, x0, x1, x2, x3);
  196. LD_GP4_INC(y, 1, y0, y1, y2, y3);
  197. dot[0] += ( x0 * y0 OP3 x1 * y1 );
  198. dot[1] OP2 ( x1 * y0 OP4 x0 * y1 );
  199. dot[0] += ( x2 * y2 OP3 x3 * y3 );
  200. dot[1] OP2 ( x3 * y2 OP4 x2 * y3 );
  201. }
  202. else if (n & 1)
  203. {
  204. LD_GP2_INC(x, 1, x0, x1);
  205. LD_GP2_INC(y, 1, y0, y1);
  206. dot[0] += ( x0 * y0 OP3 x1 * y1 );
  207. dot[1] OP2 ( x1 * y0 OP4 x0 * y1 );
  208. }
  209. }
  210. dot[0] += (dot0[0] + dot0[1] + dot0[2] + dot0[3]);
  211. dot[1] += (dot1[0] + dot1[1] + dot1[2] + dot1[3]);
  212. }
  213. else
  214. {
  215. inc_x2 = 2 * inc_x;
  216. inc_y2 = 2 * inc_y;
  217. for (i = (n >> 2); i--;)
  218. {
  219. x0 = *x;
  220. x1 = *(x + 1);
  221. x += inc_x2;
  222. x2 = *x;
  223. x3 = *(x + 1);
  224. x += inc_x2;
  225. x4 = *x;
  226. x5 = *(x + 1);
  227. x += inc_x2;
  228. x6 = *x;
  229. x7 = *(x + 1);
  230. x += inc_x2;
  231. y0 = *y;
  232. y1 = *(y + 1);
  233. y += inc_y2;
  234. y2 = *y;
  235. y3 = *(y + 1);
  236. y += inc_y2;
  237. y4 = *y;
  238. y5 = *(y + 1);
  239. y += inc_y2;
  240. y6 = *y;
  241. y7 = *(y + 1);
  242. y += inc_y2;
  243. dot[0] += ( x0 * y0 OP3 x1 * y1 );
  244. dot[1] OP2 ( x1 * y0 OP4 x0 * y1 );
  245. dot[0] += ( x2 * y2 OP3 x3 * y3 );
  246. dot[1] OP2 ( x3 * y2 OP4 x2 * y3 );
  247. dot[0] += ( x4 * y4 OP3 x5 * y5 );
  248. dot[1] OP2 ( x5 * y4 OP4 x4 * y5 );
  249. dot[0] += ( x6 * y6 OP3 x7 * y7 );
  250. dot[1] OP2 ( x7 * y6 OP4 x6 * y7 );
  251. }
  252. if ((n & 2) && (n & 1))
  253. {
  254. x0 = *x;
  255. x1 = *(x + 1);
  256. x += inc_x2;
  257. x2 = *x;
  258. x3 = *(x + 1);
  259. x += inc_x2;
  260. x4 = *x;
  261. x5 = *(x + 1);
  262. x += inc_x2;
  263. y0 = *y;
  264. y1 = *(y + 1);
  265. y += inc_y2;
  266. y2 = *y;
  267. y3 = *(y + 1);
  268. y += inc_y2;
  269. y4 = *y;
  270. y5 = *(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. }
  279. else if (n & 2)
  280. {
  281. x0 = *x;
  282. x1 = *(x + 1);
  283. x += inc_x2;
  284. x2 = *x;
  285. x3 = *(x + 1);
  286. x += inc_x2;
  287. y0 = *y;
  288. y1 = *(y + 1);
  289. y += inc_y2;
  290. y2 = *y;
  291. y3 = *(y + 1);
  292. y += inc_y2;
  293. dot[0] += ( x0 * y0 OP3 x1 * y1 );
  294. dot[1] OP2 ( x1 * y0 OP4 x0 * y1 );
  295. dot[0] += ( x2 * y2 OP3 x3 * y3 );
  296. dot[1] OP2 ( x3 * y2 OP4 x2 * y3 );
  297. }
  298. else if (n & 1)
  299. {
  300. x0 = *x;
  301. x1 = *(x + 1);
  302. x += inc_x2;
  303. y0 = *y;
  304. y1 = *(y + 1);
  305. y += inc_y2;
  306. dot[0] += ( x0 * y0 OP3 x1 * y1 );
  307. dot[1] OP2 ( x1 * y0 OP4 x0 * y1 );
  308. }
  309. }
  310. __real__(result) = dot[0];
  311. __imag__(result) = dot[1];
  312. return(result);
  313. }