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.

laswp_ncopy_2.c 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 PREFETCHSIZE 12
  41. #define a2 (a1 + 1)
  42. #define a4 (a3 + 1)
  43. int CNAME(BLASLONG n, BLASLONG k1, BLASLONG k2, FLOAT *a, BLASLONG lda, blasint *ipiv, FLOAT *buffer){
  44. BLASLONG i, j, ip1, ip2;
  45. blasint *piv;
  46. FLOAT *a1, *a3;
  47. FLOAT *b1, *b2, *b3, *b4;
  48. FLOAT A1, A2, B1, B2, A3, A4, B3, B4;
  49. a--;
  50. k1 --;
  51. ipiv += k1;
  52. if (n <= 0) return 0;
  53. j = (n >> 1);
  54. if (j > 0) {
  55. do {
  56. piv = ipiv;
  57. a1 = a + k1 + 1;
  58. a3 = a1 + 1 * lda;
  59. ip1 = *(piv + 0);
  60. ip2 = *(piv + 1);
  61. piv += 2;
  62. b1 = a + ip1;
  63. b2 = a + ip2;
  64. b3 = b1 + 1 * lda;
  65. b4 = b2 + 1 * lda;
  66. i = ((k2 - k1) >> 1);
  67. if (i > 0) {
  68. do {
  69. #ifdef __GNUC__
  70. __builtin_prefetch(a1 + PREFETCHSIZE, 0, 0);
  71. __builtin_prefetch(a3 + PREFETCHSIZE, 0, 0);
  72. #endif
  73. A1 = *a1;
  74. A2 = *a2;
  75. A3 = *a3;
  76. A4 = *a4;
  77. B1 = *b1;
  78. B2 = *b2;
  79. B3 = *b3;
  80. B4 = *b4;
  81. ip1 = *(piv + 0);
  82. ip2 = *(piv + 1);
  83. piv += 2;
  84. if (b1 == a1) {
  85. if (b2 == a2) {
  86. *(buffer + 0) = A1;
  87. *(buffer + 1) = A3;
  88. *(buffer + 2) = A2;
  89. *(buffer + 3) = A4;
  90. } else {
  91. *(buffer + 0) = A1;
  92. *(buffer + 1) = A3;
  93. *(buffer + 2) = B2;
  94. *(buffer + 3) = B4;
  95. *b2 = A2;
  96. *b4 = A4;
  97. }
  98. } else {
  99. if (b1 == a2) {
  100. if (b2 == a2) {
  101. *(buffer + 0) = A2;
  102. *(buffer + 1) = A4;
  103. *(buffer + 2) = A1;
  104. *(buffer + 3) = A3;
  105. } else {
  106. *(buffer + 0) = A2;
  107. *(buffer + 1) = A4;
  108. *(buffer + 2) = B2;
  109. *(buffer + 3) = B4;
  110. *b2 = A1;
  111. *b4 = A3;
  112. }
  113. } else {
  114. if (b2 == a2) {
  115. *(buffer + 0) = B1;
  116. *(buffer + 1) = B3;
  117. *(buffer + 2) = A2;
  118. *(buffer + 3) = A4;
  119. *b1 = A1;
  120. *b3 = A3;
  121. } else {
  122. if (b2 == b1) {
  123. *(buffer + 0) = B1;
  124. *(buffer + 1) = B3;
  125. *(buffer + 2) = A1;
  126. *(buffer + 3) = A3;
  127. *b1 = A2;
  128. *b3 = A4;
  129. } else {
  130. *(buffer + 0) = B1;
  131. *(buffer + 1) = B3;
  132. *(buffer + 2) = B2;
  133. *(buffer + 3) = B4;
  134. *b1 = A1;
  135. *b2 = A2;
  136. *b3 = A3;
  137. *b4 = A4;
  138. }
  139. }
  140. }
  141. }
  142. buffer += 4;
  143. b1 = a + ip1;
  144. b2 = a + ip2;
  145. b3 = b1 + 1 * lda;
  146. b4 = b2 + 1 * lda;
  147. a1 += 2;
  148. a3 += 2;
  149. i --;
  150. } while (i > 0);
  151. }
  152. i = ((k2 - k1) & 1);
  153. if (i > 0) {
  154. A1 = *a1;
  155. B1 = *b1;
  156. A3 = *a3;
  157. B3 = *b3;
  158. if (a1 == b1) {
  159. *(buffer + 0) = A1;
  160. *(buffer + 1) = A3;
  161. } else {
  162. *(buffer + 0) = B1;
  163. *(buffer + 1) = B3;
  164. *b1 = A1;
  165. *b3 = A3;
  166. }
  167. buffer += 2;
  168. }
  169. a += 2 * lda;
  170. j --;
  171. } while (j > 0);
  172. }
  173. if (n & 1) {
  174. piv = ipiv;
  175. a1 = a + k1 + 1;
  176. ip1 = *(piv + 0);
  177. ip2 = *(piv + 1);
  178. piv += 2;
  179. b1 = a + ip1;
  180. b2 = a + ip2;
  181. i = ((k2 - k1) >> 1);
  182. if (i > 0) {
  183. do {
  184. A1 = *a1;
  185. A2 = *a2;
  186. B1 = *b1;
  187. B2 = *b2;
  188. ip1 = *(piv + 0);
  189. ip2 = *(piv + 1);
  190. piv += 2;
  191. if (b1 == a1) {
  192. if (b2 == a2) {
  193. *(buffer + 0) = A1;
  194. *(buffer + 1) = A2;
  195. } else {
  196. *(buffer + 0) = A1;
  197. *(buffer + 1) = B2;
  198. *b2 = A2;
  199. }
  200. } else
  201. if (b1 == a2) {
  202. if (b2 == a2) {
  203. *(buffer + 0) = A2;
  204. *(buffer + 1) = A1;
  205. } else {
  206. *(buffer + 0) = A2;
  207. *(buffer + 1) = B2;
  208. *b2 = A1;
  209. }
  210. } else {
  211. if (b2 == a2) {
  212. *(buffer + 0) = B1;
  213. *(buffer + 1) = A2;
  214. *b1 = A1;
  215. } else
  216. if (b2 == b1) {
  217. *(buffer + 0) = B1;
  218. *(buffer + 1) = A1;
  219. *b1 = A2;
  220. } else {
  221. *(buffer + 0) = B1;
  222. *(buffer + 1) = B2;
  223. *b1 = A1;
  224. *b2 = A2;
  225. }
  226. }
  227. buffer += 2;
  228. b1 = a + ip1;
  229. b2 = a + ip2;
  230. a1 += 2;
  231. i --;
  232. } while (i > 0);
  233. }
  234. i = ((k2 - k1) & 1);
  235. if (i > 0) {
  236. A1 = *a1;
  237. B1 = *b1;
  238. if (a1 == b1) {
  239. *(buffer + 0) = A1;
  240. } else {
  241. *(buffer + 0) = B1;
  242. *b1 = A1;
  243. }
  244. }
  245. }
  246. return 0;
  247. }