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.

ztbmv.c 8.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 <ctype.h>
  40. #include "common.h"
  41. #ifdef FUNCTION_PROFILE
  42. #include "functable.h"
  43. #endif
  44. #ifdef XDOUBLE
  45. #define ERROR_NAME "XTBMV "
  46. #elif defined(DOUBLE)
  47. #define ERROR_NAME "ZTBMV "
  48. #else
  49. #define ERROR_NAME "CTBMV "
  50. #endif
  51. static int (*tbmv[])(BLASLONG, BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, void *) = {
  52. #ifdef XDOUBLE
  53. xtbmv_NUU, xtbmv_NUN, xtbmv_NLU, xtbmv_NLN,
  54. xtbmv_TUU, xtbmv_TUN, xtbmv_TLU, xtbmv_TLN,
  55. xtbmv_RUU, xtbmv_RUN, xtbmv_RLU, xtbmv_RLN,
  56. xtbmv_CUU, xtbmv_CUN, xtbmv_CLU, xtbmv_CLN,
  57. #elif defined(DOUBLE)
  58. ztbmv_NUU, ztbmv_NUN, ztbmv_NLU, ztbmv_NLN,
  59. ztbmv_TUU, ztbmv_TUN, ztbmv_TLU, ztbmv_TLN,
  60. ztbmv_RUU, ztbmv_RUN, ztbmv_RLU, ztbmv_RLN,
  61. ztbmv_CUU, ztbmv_CUN, ztbmv_CLU, ztbmv_CLN,
  62. #else
  63. ctbmv_NUU, ctbmv_NUN, ctbmv_NLU, ctbmv_NLN,
  64. ctbmv_TUU, ctbmv_TUN, ctbmv_TLU, ctbmv_TLN,
  65. ctbmv_RUU, ctbmv_RUN, ctbmv_RLU, ctbmv_RLN,
  66. ctbmv_CUU, ctbmv_CUN, ctbmv_CLU, ctbmv_CLN,
  67. #endif
  68. };
  69. #ifdef SMP
  70. static int (*tbmv_thread[])(BLASLONG, BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
  71. #ifdef XDOUBLE
  72. xtbmv_thread_NUU, xtbmv_thread_NUN, xtbmv_thread_NLU, xtbmv_thread_NLN,
  73. xtbmv_thread_TUU, xtbmv_thread_TUN, xtbmv_thread_TLU, xtbmv_thread_TLN,
  74. xtbmv_thread_RUU, xtbmv_thread_RUN, xtbmv_thread_RLU, xtbmv_thread_RLN,
  75. xtbmv_thread_CUU, xtbmv_thread_CUN, xtbmv_thread_CLU, xtbmv_thread_CLN,
  76. #elif defined(DOUBLE)
  77. ztbmv_thread_NUU, ztbmv_thread_NUN, ztbmv_thread_NLU, ztbmv_thread_NLN,
  78. ztbmv_thread_TUU, ztbmv_thread_TUN, ztbmv_thread_TLU, ztbmv_thread_TLN,
  79. ztbmv_thread_RUU, ztbmv_thread_RUN, ztbmv_thread_RLU, ztbmv_thread_RLN,
  80. ztbmv_thread_CUU, ztbmv_thread_CUN, ztbmv_thread_CLU, ztbmv_thread_CLN,
  81. #else
  82. ctbmv_thread_NUU, ctbmv_thread_NUN, ctbmv_thread_NLU, ctbmv_thread_NLN,
  83. ctbmv_thread_TUU, ctbmv_thread_TUN, ctbmv_thread_TLU, ctbmv_thread_TLN,
  84. ctbmv_thread_RUU, ctbmv_thread_RUN, ctbmv_thread_RLU, ctbmv_thread_RLN,
  85. ctbmv_thread_CUU, ctbmv_thread_CUN, ctbmv_thread_CLU, ctbmv_thread_CLN,
  86. #endif
  87. };
  88. #endif
  89. #ifndef CBLAS
  90. void NAME(char *UPLO, char *TRANS, char *DIAG,
  91. blasint *N, blasint *K,
  92. FLOAT *a, blasint *LDA, FLOAT *x, blasint *INCX){
  93. char uplo_arg = *UPLO;
  94. char trans_arg = *TRANS;
  95. char diag_arg = *DIAG;
  96. blasint n = *N;
  97. blasint k = *K;
  98. blasint lda = *LDA;
  99. blasint incx = *INCX;
  100. blasint info;
  101. int uplo;
  102. int unit;
  103. int trans;
  104. FLOAT *buffer;
  105. #ifdef SMP
  106. int nthreads;
  107. #endif
  108. PRINT_DEBUG_NAME;
  109. TOUPPER(uplo_arg);
  110. TOUPPER(trans_arg);
  111. TOUPPER(diag_arg);
  112. trans = -1;
  113. unit = -1;
  114. uplo = -1;
  115. if (trans_arg == 'N') trans = 0;
  116. if (trans_arg == 'T') trans = 1;
  117. if (trans_arg == 'R') trans = 2;
  118. if (trans_arg == 'C') trans = 3;
  119. if (diag_arg == 'U') unit = 0;
  120. if (diag_arg == 'N') unit = 1;
  121. if (uplo_arg == 'U') uplo = 0;
  122. if (uplo_arg == 'L') uplo = 1;
  123. info = 0;
  124. if (incx == 0) info = 9;
  125. if (lda < k + 1) info = 7;
  126. if (k < 0) info = 5;
  127. if (n < 0) info = 4;
  128. if (unit < 0) info = 3;
  129. if (trans < 0) info = 2;
  130. if (uplo < 0) info = 1;
  131. if (info != 0) {
  132. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  133. return;
  134. }
  135. #else
  136. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo,
  137. enum CBLAS_TRANSPOSE TransA, enum CBLAS_DIAG Diag,
  138. blasint n, blasint k, FLOAT *a, blasint lda, FLOAT *x, blasint incx) {
  139. int trans, uplo, unit;
  140. blasint info;
  141. FLOAT *buffer;
  142. #ifdef SMP
  143. int nthreads;
  144. #endif
  145. PRINT_DEBUG_CNAME;
  146. unit = -1;
  147. uplo = -1;
  148. trans = -1;
  149. info = 0;
  150. if (order == CblasColMajor) {
  151. if (Uplo == CblasUpper) uplo = 0;
  152. if (Uplo == CblasLower) uplo = 1;
  153. if (TransA == CblasNoTrans) trans = 0;
  154. if (TransA == CblasTrans) trans = 1;
  155. if (TransA == CblasConjNoTrans) trans = 2;
  156. if (TransA == CblasConjTrans) trans = 3;
  157. if (Diag == CblasUnit) unit = 0;
  158. if (Diag == CblasNonUnit) unit = 1;
  159. info = -1;
  160. if (incx == 0) info = 9;
  161. if (lda < k + 1) info = 7;
  162. if (k < 0) info = 5;
  163. if (n < 0) info = 4;
  164. if (unit < 0) info = 3;
  165. if (trans < 0) info = 2;
  166. if (uplo < 0) info = 1;
  167. }
  168. if (order == CblasRowMajor) {
  169. if (Uplo == CblasUpper) uplo = 1;
  170. if (Uplo == CblasLower) uplo = 0;
  171. if (TransA == CblasNoTrans) trans = 1;
  172. if (TransA == CblasTrans) trans = 0;
  173. if (TransA == CblasConjNoTrans) trans = 3;
  174. if (TransA == CblasConjTrans) trans = 2;
  175. if (Diag == CblasUnit) unit = 0;
  176. if (Diag == CblasNonUnit) unit = 1;
  177. info = -1;
  178. if (incx == 0) info = 9;
  179. if (lda < k + 1) info = 7;
  180. if (k < 0) info = 5;
  181. if (n < 0) info = 4;
  182. if (unit < 0) info = 3;
  183. if (trans < 0) info = 2;
  184. if (uplo < 0) info = 1;
  185. }
  186. if (info >= 0) {
  187. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  188. return;
  189. }
  190. #endif
  191. if (n == 0) return;
  192. IDEBUG_START;
  193. FUNCTION_PROFILE_START();
  194. if (incx < 0 ) x -= (n - 1) * incx * 2;
  195. buffer = (FLOAT *)blas_memory_alloc(1);
  196. #ifdef SMP
  197. nthreads = num_cpu_avail(2);
  198. if (nthreads == 1) {
  199. #endif
  200. (tbmv[(trans<<2) | (uplo<<1) | unit])(n, k, a, lda, x, incx, buffer);
  201. #ifdef SMP
  202. } else {
  203. (tbmv_thread[(trans<<2) | (uplo<<1) | unit])(n, k, a, lda, x, incx, buffer, nthreads);
  204. }
  205. #endif
  206. blas_memory_free(buffer);
  207. FUNCTION_PROFILE_END(4, n * k / 2 + n, n * k);
  208. IDEBUG_END;
  209. return;
  210. }

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.