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_k_1.c 6.2 kB

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