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

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