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.

zgemm3m_tcopy_4.c 9.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include <stdio.h>
  39. #include "common.h"
  40. #ifndef USE_ALPHA
  41. #define REAL_PART(a, b) (a)
  42. #define IMAGE_PART(a, b) (b)
  43. #else
  44. #define REAL_PART(a, b) (alpha_r * (a) - alpha_i * (b))
  45. #define IMAGE_PART(a, b) (alpha_i * (a) + alpha_r * (b))
  46. #endif
  47. #if defined(REAL_ONLY)
  48. #define CMULT(a, b) (REAL_PART(a, b))
  49. #elif defined(IMAGE_ONLY)
  50. #define CMULT(a, b) (IMAGE_PART(a, b))
  51. #else
  52. #define CMULT(a, b) (REAL_PART(a, b) + IMAGE_PART(a, b))
  53. #endif
  54. int CNAME(BLASLONG m, BLASLONG n, FLOAT *a, BLASLONG lda,
  55. #ifdef USE_ALPHA
  56. FLOAT alpha_r, FLOAT alpha_i,
  57. #endif
  58. FLOAT *b){
  59. BLASLONG i, j;
  60. FLOAT *a_offset, *a_offset1, *a_offset2, *a_offset3, *a_offset4;
  61. FLOAT *b_offset, *b_offset1, *b_offset2, *b_offset3;
  62. FLOAT a1, a2, a3, a4, a5, a6, a7, a8;
  63. a_offset = a;
  64. b_offset = b;
  65. lda *= 2;
  66. b_offset2 = b + m * (n & ~3);
  67. b_offset3 = b + m * (n & ~1);
  68. j = (m >> 2);
  69. if (j > 0){
  70. do{
  71. a_offset1 = a_offset;
  72. a_offset2 = a_offset1 + lda;
  73. a_offset3 = a_offset2 + lda;
  74. a_offset4 = a_offset3 + lda;
  75. a_offset += 4 * lda;
  76. b_offset1 = b_offset;
  77. b_offset += 16;
  78. i = (n >> 2);
  79. if (i > 0){
  80. do{
  81. a1 = *(a_offset1 + 0);
  82. a2 = *(a_offset1 + 1);
  83. a3 = *(a_offset1 + 2);
  84. a4 = *(a_offset1 + 3);
  85. a5 = *(a_offset1 + 4);
  86. a6 = *(a_offset1 + 5);
  87. a7 = *(a_offset1 + 6);
  88. a8 = *(a_offset1 + 7);
  89. *(b_offset1 + 0) = CMULT(a1, a2);
  90. *(b_offset1 + 1) = CMULT(a3, a4);
  91. *(b_offset1 + 2) = CMULT(a5, a6);
  92. *(b_offset1 + 3) = CMULT(a7, a8);
  93. a1 = *(a_offset2 + 0);
  94. a2 = *(a_offset2 + 1);
  95. a3 = *(a_offset2 + 2);
  96. a4 = *(a_offset2 + 3);
  97. a5 = *(a_offset2 + 4);
  98. a6 = *(a_offset2 + 5);
  99. a7 = *(a_offset2 + 6);
  100. a8 = *(a_offset2 + 7);
  101. *(b_offset1 + 4) = CMULT(a1, a2);
  102. *(b_offset1 + 5) = CMULT(a3, a4);
  103. *(b_offset1 + 6) = CMULT(a5, a6);
  104. *(b_offset1 + 7) = CMULT(a7, a8);
  105. a1 = *(a_offset3 + 0);
  106. a2 = *(a_offset3 + 1);
  107. a3 = *(a_offset3 + 2);
  108. a4 = *(a_offset3 + 3);
  109. a5 = *(a_offset3 + 4);
  110. a6 = *(a_offset3 + 5);
  111. a7 = *(a_offset3 + 6);
  112. a8 = *(a_offset3 + 7);
  113. *(b_offset1 + 8) = CMULT(a1, a2);
  114. *(b_offset1 + 9) = CMULT(a3, a4);
  115. *(b_offset1 + 10) = CMULT(a5, a6);
  116. *(b_offset1 + 11) = CMULT(a7, a8);
  117. a1 = *(a_offset4 + 0);
  118. a2 = *(a_offset4 + 1);
  119. a3 = *(a_offset4 + 2);
  120. a4 = *(a_offset4 + 3);
  121. a5 = *(a_offset4 + 4);
  122. a6 = *(a_offset4 + 5);
  123. a7 = *(a_offset4 + 6);
  124. a8 = *(a_offset4 + 7);
  125. *(b_offset1 + 12) = CMULT(a1, a2);
  126. *(b_offset1 + 13) = CMULT(a3, a4);
  127. *(b_offset1 + 14) = CMULT(a5, a6);
  128. *(b_offset1 + 15) = CMULT(a7, a8);
  129. a_offset1 += 8;
  130. a_offset2 += 8;
  131. a_offset3 += 8;
  132. a_offset4 += 8;
  133. b_offset1 += m * 4;
  134. i --;
  135. }while(i > 0);
  136. }
  137. if (n & 2) {
  138. a1 = *(a_offset1 + 0);
  139. a2 = *(a_offset1 + 1);
  140. a3 = *(a_offset1 + 2);
  141. a4 = *(a_offset1 + 3);
  142. a5 = *(a_offset2 + 0);
  143. a6 = *(a_offset2 + 1);
  144. a7 = *(a_offset2 + 2);
  145. a8 = *(a_offset2 + 3);
  146. *(b_offset2 + 0) = CMULT(a1, a2);
  147. *(b_offset2 + 1) = CMULT(a3, a4);
  148. *(b_offset2 + 2) = CMULT(a5, a6);
  149. *(b_offset2 + 3) = CMULT(a7, a8);
  150. a1 = *(a_offset3 + 0);
  151. a2 = *(a_offset3 + 1);
  152. a3 = *(a_offset3 + 2);
  153. a4 = *(a_offset3 + 3);
  154. a5 = *(a_offset4 + 0);
  155. a6 = *(a_offset4 + 1);
  156. a7 = *(a_offset4 + 2);
  157. a8 = *(a_offset4 + 3);
  158. *(b_offset2 + 4) = CMULT(a1, a2);
  159. *(b_offset2 + 5) = CMULT(a3, a4);
  160. *(b_offset2 + 6) = CMULT(a5, a6);
  161. *(b_offset2 + 7) = CMULT(a7, a8);
  162. a_offset1 += 4;
  163. a_offset2 += 4;
  164. a_offset3 += 4;
  165. a_offset4 += 4;
  166. b_offset2 += 8;
  167. }
  168. if (n & 1) {
  169. a1 = *(a_offset1 + 0);
  170. a2 = *(a_offset1 + 1);
  171. a3 = *(a_offset2 + 0);
  172. a4 = *(a_offset2 + 1);
  173. a5 = *(a_offset3 + 0);
  174. a6 = *(a_offset3 + 1);
  175. a7 = *(a_offset4 + 0);
  176. a8 = *(a_offset4 + 1);
  177. *(b_offset3 + 0) = CMULT(a1, a2);
  178. *(b_offset3 + 1) = CMULT(a3, a4);
  179. *(b_offset3 + 2) = CMULT(a5, a6);
  180. *(b_offset3 + 3) = CMULT(a7, a8);
  181. b_offset3 += 4;
  182. }
  183. j--;
  184. }while(j > 0);
  185. }
  186. if (m & 2){
  187. a_offset1 = a_offset;
  188. a_offset2 = a_offset1 + lda;
  189. a_offset += 2 * lda;
  190. b_offset1 = b_offset;
  191. b_offset += 8;
  192. i = (n >> 2);
  193. if (i > 0){
  194. do{
  195. a1 = *(a_offset1 + 0);
  196. a2 = *(a_offset1 + 1);
  197. a3 = *(a_offset1 + 2);
  198. a4 = *(a_offset1 + 3);
  199. a5 = *(a_offset1 + 4);
  200. a6 = *(a_offset1 + 5);
  201. a7 = *(a_offset1 + 6);
  202. a8 = *(a_offset1 + 7);
  203. *(b_offset1 + 0) = CMULT(a1, a2);
  204. *(b_offset1 + 1) = CMULT(a3, a4);
  205. *(b_offset1 + 2) = CMULT(a5, a6);
  206. *(b_offset1 + 3) = CMULT(a7, a8);
  207. a1 = *(a_offset2 + 0);
  208. a2 = *(a_offset2 + 1);
  209. a3 = *(a_offset2 + 2);
  210. a4 = *(a_offset2 + 3);
  211. a5 = *(a_offset2 + 4);
  212. a6 = *(a_offset2 + 5);
  213. a7 = *(a_offset2 + 6);
  214. a8 = *(a_offset2 + 7);
  215. *(b_offset1 + 4) = CMULT(a1, a2);
  216. *(b_offset1 + 5) = CMULT(a3, a4);
  217. *(b_offset1 + 6) = CMULT(a5, a6);
  218. *(b_offset1 + 7) = CMULT(a7, a8);
  219. a_offset1 += 8;
  220. a_offset2 += 8;
  221. b_offset1 += m * 4;
  222. i --;
  223. }while(i > 0);
  224. }
  225. if (n & 2) {
  226. a1 = *(a_offset1 + 0);
  227. a2 = *(a_offset1 + 1);
  228. a3 = *(a_offset1 + 2);
  229. a4 = *(a_offset1 + 3);
  230. a5 = *(a_offset2 + 0);
  231. a6 = *(a_offset2 + 1);
  232. a7 = *(a_offset2 + 2);
  233. a8 = *(a_offset2 + 3);
  234. *(b_offset2 + 0) = CMULT(a1, a2);
  235. *(b_offset2 + 1) = CMULT(a3, a4);
  236. *(b_offset2 + 2) = CMULT(a5, a6);
  237. *(b_offset2 + 3) = CMULT(a7, a8);
  238. a_offset1 += 4;
  239. a_offset2 += 4;
  240. b_offset2 += 4;
  241. }
  242. if (n & 1) {
  243. a1 = *(a_offset1 + 0);
  244. a2 = *(a_offset1 + 1);
  245. a3 = *(a_offset2 + 0);
  246. a4 = *(a_offset2 + 1);
  247. *(b_offset3 + 0) = CMULT(a1, a2);
  248. *(b_offset3 + 1) = CMULT(a3, a4);
  249. b_offset3 += 2;
  250. }
  251. }
  252. if (m & 1){
  253. a_offset1 = a_offset;
  254. b_offset1 = b_offset;
  255. i = (n >> 2);
  256. if (i > 0){
  257. do{
  258. a1 = *(a_offset1 + 0);
  259. a2 = *(a_offset1 + 1);
  260. a3 = *(a_offset1 + 2);
  261. a4 = *(a_offset1 + 3);
  262. a5 = *(a_offset1 + 4);
  263. a6 = *(a_offset1 + 5);
  264. a7 = *(a_offset1 + 6);
  265. a8 = *(a_offset1 + 7);
  266. *(b_offset1 + 0) = CMULT(a1, a2);
  267. *(b_offset1 + 1) = CMULT(a3, a4);
  268. *(b_offset1 + 2) = CMULT(a5, a6);
  269. *(b_offset1 + 3) = CMULT(a7, a8);
  270. a_offset1 += 8;
  271. b_offset1 += 4 * m;
  272. i --;
  273. }while(i > 0);
  274. }
  275. if (n & 2) {
  276. a1 = *(a_offset1 + 0);
  277. a2 = *(a_offset1 + 1);
  278. a3 = *(a_offset1 + 2);
  279. a4 = *(a_offset1 + 3);
  280. *(b_offset2 + 0) = CMULT(a1, a2);
  281. *(b_offset2 + 1) = CMULT(a3, a4);
  282. a_offset1 += 4;
  283. }
  284. if (n & 1) {
  285. a1 = *(a_offset1 + 0);
  286. a2 = *(a_offset1 + 1);
  287. *(b_offset3 + 0) = CMULT(a1, a2);
  288. }
  289. }
  290. return 0;
  291. }