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.

zlaswp_ncopy_2.c 8.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. #define a2 (a1 + 2)
  41. #define a4 (a3 + 2)
  42. int CNAME(BLASLONG n, BLASLONG k1, BLASLONG k2, FLOAT *a, BLASLONG lda, blasint *ipiv, FLOAT *buffer){
  43. BLASLONG i, j, ip1, ip2;
  44. blasint *piv;
  45. FLOAT *a1, *a3;
  46. FLOAT *b1, *b2, *b3, *b4;
  47. FLOAT A1, A2, A3, A4;
  48. FLOAT A5, A6, A7, A8;
  49. FLOAT B1, B2, B3, B4;
  50. FLOAT B5, B6, B7, B8;
  51. a -= 2;
  52. lda *= 2;
  53. k1 --;
  54. ipiv += k1;
  55. if (n <= 0) return 0;
  56. j = (n >> 1);
  57. if (j > 0) {
  58. do {
  59. piv = ipiv;
  60. a1 = a + (k1 + 1) * 2;
  61. a3 = a1 + lda;
  62. ip1 = *(piv + 0) * 2;
  63. ip2 = *(piv + 1) * 2;
  64. piv += 2;
  65. b1 = a + ip1;
  66. b2 = a + ip2;
  67. b3 = b1 + lda;
  68. b4 = b2 + lda;
  69. i = ((k2 - k1) >> 1);
  70. if (i > 0) {
  71. do {
  72. A1 = *(a1 + 0);
  73. A2 = *(a1 + 1);
  74. A3 = *(a2 + 0);
  75. A4 = *(a2 + 1);
  76. A5 = *(a3 + 0);
  77. A6 = *(a3 + 1);
  78. A7 = *(a4 + 0);
  79. A8 = *(a4 + 1);
  80. B1 = *(b1 + 0);
  81. B2 = *(b1 + 1);
  82. B3 = *(b2 + 0);
  83. B4 = *(b2 + 1);
  84. B5 = *(b3 + 0);
  85. B6 = *(b3 + 1);
  86. B7 = *(b4 + 0);
  87. B8 = *(b4 + 1);
  88. ip1 = *(piv + 0) * 2;
  89. ip2 = *(piv + 1) * 2;
  90. piv += 2;
  91. if (b1 == a1) {
  92. if (b2 == a2) {
  93. *(buffer + 0) = A1;
  94. *(buffer + 1) = A2;
  95. *(buffer + 2) = A5;
  96. *(buffer + 3) = A6;
  97. *(buffer + 4) = A3;
  98. *(buffer + 5) = A4;
  99. *(buffer + 6) = A7;
  100. *(buffer + 7) = A8;
  101. } else {
  102. *(buffer + 0) = A1;
  103. *(buffer + 1) = A2;
  104. *(buffer + 2) = A5;
  105. *(buffer + 3) = A6;
  106. *(buffer + 4) = B3;
  107. *(buffer + 5) = B4;
  108. *(buffer + 6) = B7;
  109. *(buffer + 7) = B8;
  110. *(b2 + 0) = A3;
  111. *(b2 + 1) = A4;
  112. *(b4 + 0) = A7;
  113. *(b4 + 1) = A8;
  114. }
  115. } else
  116. if (b1 == a2) {
  117. if (b2 == a2) {
  118. *(buffer + 0) = A3;
  119. *(buffer + 1) = A4;
  120. *(buffer + 2) = A7;
  121. *(buffer + 3) = A8;
  122. *(buffer + 4) = A1;
  123. *(buffer + 5) = A2;
  124. *(buffer + 6) = A5;
  125. *(buffer + 7) = A6;
  126. } else {
  127. *(buffer + 0) = A3;
  128. *(buffer + 1) = A4;
  129. *(buffer + 2) = A7;
  130. *(buffer + 3) = A8;
  131. *(buffer + 4) = B3;
  132. *(buffer + 5) = B4;
  133. *(buffer + 6) = B7;
  134. *(buffer + 7) = B8;
  135. *(b2 + 0) = A1;
  136. *(b2 + 1) = A2;
  137. *(b4 + 0) = A5;
  138. *(b4 + 1) = A6;
  139. }
  140. } else {
  141. if (b2 == a2) {
  142. *(buffer + 0) = B1;
  143. *(buffer + 1) = B2;
  144. *(buffer + 2) = B5;
  145. *(buffer + 3) = B6;
  146. *(buffer + 4) = A3;
  147. *(buffer + 5) = A4;
  148. *(buffer + 6) = A7;
  149. *(buffer + 7) = A8;
  150. *(b1 + 0) = A1;
  151. *(b1 + 1) = A2;
  152. *(b3 + 0) = A5;
  153. *(b3 + 1) = A6;
  154. } else
  155. if (b2 == b1) {
  156. *(buffer + 0) = B1;
  157. *(buffer + 1) = B2;
  158. *(buffer + 2) = B5;
  159. *(buffer + 3) = B6;
  160. *(buffer + 4) = A1;
  161. *(buffer + 5) = A2;
  162. *(buffer + 6) = A5;
  163. *(buffer + 7) = A6;
  164. *(b1 + 0) = A3;
  165. *(b1 + 1) = A4;
  166. *(b3 + 0) = A7;
  167. *(b3 + 1) = A8;
  168. } else {
  169. *(buffer + 0) = B1;
  170. *(buffer + 1) = B2;
  171. *(buffer + 2) = B5;
  172. *(buffer + 3) = B6;
  173. *(buffer + 4) = B3;
  174. *(buffer + 5) = B4;
  175. *(buffer + 6) = B7;
  176. *(buffer + 7) = B8;
  177. *(b1 + 0) = A1;
  178. *(b1 + 1) = A2;
  179. *(b2 + 0) = A3;
  180. *(b2 + 1) = A4;
  181. *(b3 + 0) = A5;
  182. *(b3 + 1) = A6;
  183. *(b4 + 0) = A7;
  184. *(b4 + 1) = A8;
  185. }
  186. }
  187. buffer += 8;
  188. b1 = a + ip1;
  189. b2 = a + ip2;
  190. b3 = b1 + lda;
  191. b4 = b2 + lda;
  192. a1 += 4;
  193. a3 += 4;
  194. i --;
  195. } while (i > 0);
  196. }
  197. i = ((k2 - k1) & 1);
  198. if (i > 0) {
  199. A1 = *(a1 + 0);
  200. A2 = *(a1 + 1);
  201. B1 = *(b1 + 0);
  202. B2 = *(b1 + 1);
  203. A3 = *(a3 + 0);
  204. A4 = *(a3 + 1);
  205. B3 = *(b3 + 0);
  206. B4 = *(b3 + 1);
  207. if (a1 == b1) {
  208. *(buffer + 0) = A1;
  209. *(buffer + 1) = A2;
  210. *(buffer + 2) = A3;
  211. *(buffer + 3) = A4;
  212. } else {
  213. *(buffer + 0) = B1;
  214. *(buffer + 1) = B2;
  215. *(buffer + 2) = B3;
  216. *(buffer + 3) = B4;
  217. *(b1 + 0) = A1;
  218. *(b1 + 1) = A2;
  219. *(b3 + 0) = A3;
  220. *(b3 + 1) = A4;
  221. }
  222. buffer += 4;
  223. }
  224. a += 2 * lda;
  225. j --;
  226. } while (j > 0);
  227. }
  228. if (n & 1) {
  229. piv = ipiv;
  230. a1 = a + (k1 + 1) * 2;
  231. ip1 = *(piv + 0) * 2;
  232. ip2 = *(piv + 1) * 2;
  233. piv += 2;
  234. b1 = a + ip1;
  235. b2 = a + ip2;
  236. i = ((k2 - k1) >> 1);
  237. if (i > 0) {
  238. do {
  239. A1 = *(a1 + 0);
  240. A2 = *(a1 + 1);
  241. A3 = *(a2 + 0);
  242. A4 = *(a2 + 1);
  243. B1 = *(b1 + 0);
  244. B2 = *(b1 + 1);
  245. B3 = *(b2 + 0);
  246. B4 = *(b2 + 1);
  247. ip1 = *(piv + 0) * 2;
  248. ip2 = *(piv + 1) * 2;
  249. piv += 2;
  250. if (b1 == a1) {
  251. if (b2 == a2) {
  252. *(buffer + 0) = A1;
  253. *(buffer + 1) = A2;
  254. *(buffer + 2) = A3;
  255. *(buffer + 3) = A4;
  256. } else {
  257. *(buffer + 0) = A1;
  258. *(buffer + 1) = A2;
  259. *(buffer + 2) = B3;
  260. *(buffer + 3) = B4;
  261. *(b2 + 0) = A3;
  262. *(b2 + 1) = A4;
  263. }
  264. } else
  265. if (b1 == a2) {
  266. if (b2 == a2) {
  267. *(buffer + 0) = A3;
  268. *(buffer + 1) = A4;
  269. *(buffer + 2) = A1;
  270. *(buffer + 3) = A2;
  271. } else {
  272. *(buffer + 0) = A3;
  273. *(buffer + 1) = A4;
  274. *(buffer + 2) = B3;
  275. *(buffer + 3) = B4;
  276. *(b2 + 0) = A1;
  277. *(b2 + 1) = A2;
  278. }
  279. } else {
  280. if (b2 == a2) {
  281. *(buffer + 0) = B1;
  282. *(buffer + 1) = B2;
  283. *(buffer + 2) = A3;
  284. *(buffer + 3) = A4;
  285. *(b1 + 0) = A1;
  286. *(b1 + 1) = A2;
  287. } else
  288. if (b2 == b1) {
  289. *(buffer + 0) = B1;
  290. *(buffer + 1) = B2;
  291. *(buffer + 2) = A1;
  292. *(buffer + 3) = A2;
  293. *(b1 + 0) = A3;
  294. *(b1 + 1) = A4;
  295. } else {
  296. *(buffer + 0) = B1;
  297. *(buffer + 1) = B2;
  298. *(buffer + 2) = B3;
  299. *(buffer + 3) = B4;
  300. *(b1 + 0) = A1;
  301. *(b1 + 1) = A2;
  302. *(b2 + 0) = A3;
  303. *(b2 + 1) = A4;
  304. }
  305. }
  306. buffer += 4;
  307. b1 = a + ip1;
  308. b2 = a + ip2;
  309. a1 += 4;
  310. i --;
  311. } while (i > 0);
  312. }
  313. i = ((k2 - k1) & 1);
  314. if (i > 0) {
  315. A1 = *(a1 + 0);
  316. A2 = *(a1 + 1);
  317. B1 = *(b1 + 0);
  318. B2 = *(b1 + 1);
  319. if (a1 == b1) {
  320. *(buffer + 0) = A1;
  321. *(buffer + 1) = A2;
  322. } else {
  323. *(buffer + 0) = B1;
  324. *(buffer + 1) = B2;
  325. *(b1 + 0) = A1;
  326. *(b1 + 1) = A2;
  327. }
  328. // buffer += 2;
  329. }
  330. }
  331. return 0;
  332. }