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.

ztpmv.c 7.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 "XTPMV "
  46. #elif defined(DOUBLE)
  47. #define ERROR_NAME "ZTPMV "
  48. #else
  49. #define ERROR_NAME "CTPMV "
  50. #endif
  51. static int (*tpmv[])(BLASLONG, FLOAT *, FLOAT *, BLASLONG, void *) = {
  52. #ifdef XDOUBLE
  53. xtpmv_NUU, xtpmv_NUN, xtpmv_NLU, xtpmv_NLN,
  54. xtpmv_TUU, xtpmv_TUN, xtpmv_TLU, xtpmv_TLN,
  55. xtpmv_RUU, xtpmv_RUN, xtpmv_RLU, xtpmv_RLN,
  56. xtpmv_CUU, xtpmv_CUN, xtpmv_CLU, xtpmv_CLN,
  57. #elif defined(DOUBLE)
  58. ztpmv_NUU, ztpmv_NUN, ztpmv_NLU, ztpmv_NLN,
  59. ztpmv_TUU, ztpmv_TUN, ztpmv_TLU, ztpmv_TLN,
  60. ztpmv_RUU, ztpmv_RUN, ztpmv_RLU, ztpmv_RLN,
  61. ztpmv_CUU, ztpmv_CUN, ztpmv_CLU, ztpmv_CLN,
  62. #else
  63. ctpmv_NUU, ctpmv_NUN, ctpmv_NLU, ctpmv_NLN,
  64. ctpmv_TUU, ctpmv_TUN, ctpmv_TLU, ctpmv_TLN,
  65. ctpmv_RUU, ctpmv_RUN, ctpmv_RLU, ctpmv_RLN,
  66. ctpmv_CUU, ctpmv_CUN, ctpmv_CLU, ctpmv_CLN,
  67. #endif
  68. };
  69. #ifdef SMP
  70. static int (*tpmv_thread[])(BLASLONG, FLOAT *, FLOAT *, BLASLONG, FLOAT *, int) = {
  71. #ifdef XDOUBLE
  72. xtpmv_thread_NUU, xtpmv_thread_NUN, xtpmv_thread_NLU, xtpmv_thread_NLN,
  73. xtpmv_thread_TUU, xtpmv_thread_TUN, xtpmv_thread_TLU, xtpmv_thread_TLN,
  74. xtpmv_thread_RUU, xtpmv_thread_RUN, xtpmv_thread_RLU, xtpmv_thread_RLN,
  75. xtpmv_thread_CUU, xtpmv_thread_CUN, xtpmv_thread_CLU, xtpmv_thread_CLN,
  76. #elif defined(DOUBLE)
  77. ztpmv_thread_NUU, ztpmv_thread_NUN, ztpmv_thread_NLU, ztpmv_thread_NLN,
  78. ztpmv_thread_TUU, ztpmv_thread_TUN, ztpmv_thread_TLU, ztpmv_thread_TLN,
  79. ztpmv_thread_RUU, ztpmv_thread_RUN, ztpmv_thread_RLU, ztpmv_thread_RLN,
  80. ztpmv_thread_CUU, ztpmv_thread_CUN, ztpmv_thread_CLU, ztpmv_thread_CLN,
  81. #else
  82. ctpmv_thread_NUU, ctpmv_thread_NUN, ctpmv_thread_NLU, ctpmv_thread_NLN,
  83. ctpmv_thread_TUU, ctpmv_thread_TUN, ctpmv_thread_TLU, ctpmv_thread_TLN,
  84. ctpmv_thread_RUU, ctpmv_thread_RUN, ctpmv_thread_RLU, ctpmv_thread_RLN,
  85. ctpmv_thread_CUU, ctpmv_thread_CUN, ctpmv_thread_CLU, ctpmv_thread_CLN,
  86. #endif
  87. };
  88. #endif
  89. #ifndef CBLAS
  90. void NAME(char *UPLO, char *TRANS, char *DIAG,
  91. blasint *N, FLOAT *a, FLOAT *x, blasint *INCX){
  92. char uplo_arg = *UPLO;
  93. char trans_arg = *TRANS;
  94. char diag_arg = *DIAG;
  95. blasint n = *N;
  96. blasint incx = *INCX;
  97. blasint info;
  98. int uplo;
  99. int unit;
  100. int trans;
  101. FLOAT *buffer;
  102. #ifdef SMP
  103. int nthreads;
  104. #endif
  105. PRINT_DEBUG_NAME;
  106. TOUPPER(uplo_arg);
  107. TOUPPER(trans_arg);
  108. TOUPPER(diag_arg);
  109. trans = -1;
  110. unit = -1;
  111. uplo = -1;
  112. if (trans_arg == 'N') trans = 0;
  113. if (trans_arg == 'T') trans = 1;
  114. if (trans_arg == 'R') trans = 2;
  115. if (trans_arg == 'C') trans = 3;
  116. if (diag_arg == 'U') unit = 0;
  117. if (diag_arg == 'N') unit = 1;
  118. if (uplo_arg == 'U') uplo = 0;
  119. if (uplo_arg == 'L') uplo = 1;
  120. info = 0;
  121. if (incx == 0) info = 7;
  122. if (n < 0) info = 4;
  123. if (unit < 0) info = 3;
  124. if (trans < 0) info = 2;
  125. if (uplo < 0) info = 1;
  126. if (info != 0) {
  127. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  128. return;
  129. }
  130. #else
  131. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo,
  132. enum CBLAS_TRANSPOSE TransA, enum CBLAS_DIAG Diag,
  133. blasint n, FLOAT *a, FLOAT *x, blasint incx) {
  134. int trans, uplo, unit;
  135. blasint info;
  136. FLOAT *buffer;
  137. PRINT_DEBUG_CNAME;
  138. unit = -1;
  139. uplo = -1;
  140. trans = -1;
  141. info = 0;
  142. #ifdef SMP
  143. int nthreads;
  144. #endif
  145. if (order == CblasColMajor) {
  146. if (Uplo == CblasUpper) uplo = 0;
  147. if (Uplo == CblasLower) uplo = 1;
  148. if (TransA == CblasNoTrans) trans = 0;
  149. if (TransA == CblasTrans) trans = 1;
  150. if (TransA == CblasConjNoTrans) trans = 2;
  151. if (TransA == CblasConjTrans) trans = 3;
  152. if (Diag == CblasUnit) unit = 0;
  153. if (Diag == CblasNonUnit) unit = 1;
  154. info = -1;
  155. if (incx == 0) info = 7;
  156. if (n < 0) info = 4;
  157. if (unit < 0) info = 3;
  158. if (trans < 0) info = 2;
  159. if (uplo < 0) info = 1;
  160. }
  161. if (order == CblasRowMajor) {
  162. if (Uplo == CblasUpper) uplo = 1;
  163. if (Uplo == CblasLower) uplo = 0;
  164. if (TransA == CblasNoTrans) trans = 1;
  165. if (TransA == CblasTrans) trans = 0;
  166. if (TransA == CblasConjNoTrans) trans = 3;
  167. if (TransA == CblasConjTrans) trans = 2;
  168. if (Diag == CblasUnit) unit = 0;
  169. if (Diag == CblasNonUnit) unit = 1;
  170. info = -1;
  171. if (incx == 0) info = 7;
  172. if (n < 0) info = 4;
  173. if (unit < 0) info = 3;
  174. if (trans < 0) info = 2;
  175. if (uplo < 0) info = 1;
  176. }
  177. if (info >= 0) {
  178. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  179. return;
  180. }
  181. #endif
  182. if (n == 0) return;
  183. IDEBUG_START;
  184. FUNCTION_PROFILE_START();
  185. if (incx < 0 ) x -= (n - 1) * incx * 2;
  186. buffer = (FLOAT *)blas_memory_alloc(1);
  187. #ifdef SMP
  188. nthreads = num_cpu_avail(2);
  189. if (nthreads == 1) {
  190. #endif
  191. (tpmv[(trans<<2) | (uplo<<1) | unit])(n, a, x, incx, buffer);
  192. #ifdef SMP
  193. } else {
  194. (tpmv_thread[(trans<<2) | (uplo<<1) | unit])(n, a, x, incx, buffer, nthreads);
  195. }
  196. #endif
  197. blas_memory_free(buffer);
  198. FUNCTION_PROFILE_END(4, n * n / 2 + n, n * n);
  199. IDEBUG_END;
  200. return;
  201. }