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