Add CPUID identification of Intel Ice Lake
[platform/upstream/openblas.git] / interface / zhbmv.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 "XHBMV "
48 #elif defined(DOUBLE)
49 #define ERROR_NAME "ZHBMV "
50 #else
51 #define ERROR_NAME "CHBMV "
52 #endif
53
54 static  int (*hbmv[])(BLASLONG, BLASLONG, FLOAT, FLOAT, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, void *) = {
55 #ifdef XDOUBLE
56   xhbmv_U, xhbmv_L, xhbmv_V, xhbmv_M,
57 #elif defined(DOUBLE)
58   zhbmv_U, zhbmv_L, zhbmv_V, zhbmv_M,
59 #else
60   chbmv_U, chbmv_L, chbmv_V, chbmv_M,
61 #endif
62 };
63
64 #ifdef SMPBUG
65 static  int (*hbmv_thread[])(BLASLONG, BLASLONG, FLOAT *, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
66 #ifdef XDOUBLE
67   xhbmv_thread_U, xhbmv_thread_L, xhbmv_thread_V, xhbmv_thread_M,
68 #elif defined(DOUBLE)
69   zhbmv_thread_U, zhbmv_thread_L, zhbmv_thread_V, zhbmv_thread_M,
70 #else
71   chbmv_thread_U, chbmv_thread_L, chbmv_thread_V, chbmv_thread_M,
72 #endif
73 };
74 #endif
75
76 #ifndef CBLAS
77
78 void NAME(char *UPLO, blasint *N, blasint *K, FLOAT  *ALPHA, FLOAT *a, blasint *LDA,
79             FLOAT  *x, blasint *INCX, FLOAT *BETA, FLOAT *y, blasint *INCY){
80
81   char uplo_arg = *UPLO;
82   blasint n     = *N;
83   blasint k     = *K;
84   FLOAT alpha_r = ALPHA[0];
85   FLOAT alpha_i = ALPHA[1];
86   blasint lda   = *LDA;
87   blasint incx  = *INCX;
88   FLOAT beta_r  = BETA[0];
89   FLOAT beta_i  = BETA[1];
90   blasint incy  = *INCY;
91
92   blasint info;
93   int uplo;
94   FLOAT *buffer;
95 #ifdef SMPBUG
96   int nthreads;
97 #endif
98
99   PRINT_DEBUG_NAME;
100
101   TOUPPER(uplo_arg);
102   uplo  = -1;
103
104   if (uplo_arg  == 'U') uplo  = 0;
105   if (uplo_arg  == 'L') uplo  = 1;
106   if (uplo_arg  == 'V') uplo  = 2;
107   if (uplo_arg  == 'M') uplo  = 3;
108
109   info = 0;
110
111   if (incy == 0)          info = 11;
112   if (incx == 0)          info =  8;
113   if (lda  < k + 1)       info =  6;
114   if (k < 0)              info =  3;
115   if (n < 0)              info =  2;
116   if (uplo  < 0)          info =  1;
117
118   if (info != 0) {
119     BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
120     return;
121   }
122
123 #else
124
125 void CNAME(enum CBLAS_ORDER order,
126            enum CBLAS_UPLO Uplo,
127            blasint n, blasint k,
128            void *VALPHA,
129            void  *va, blasint lda,
130            void  *vx, blasint incx,
131            void *VBETA,
132            void  *vy, blasint incy){
133
134   FLOAT* ALPHA = (FLOAT*) VALPHA;
135   FLOAT* BETA = (FLOAT*) VBETA;
136   FLOAT* a = (FLOAT*) va;
137   FLOAT* x = (FLOAT*) vx;
138   FLOAT* y = (FLOAT*) vy;
139
140   FLOAT alpha_r = ALPHA[0];
141   FLOAT alpha_i = ALPHA[1];
142   FLOAT beta_r  = BETA[0];
143   FLOAT beta_i  = BETA[1];
144   FLOAT *buffer;
145   int uplo;
146   blasint info;
147 #ifdef SMPBUG
148   int nthreads;
149 #endif
150
151   PRINT_DEBUG_CNAME;
152
153   uplo  = -1;
154   info  =  0;
155
156   if (order == CblasColMajor) {
157     if (Uplo == CblasUpper)         uplo  = 0;
158     if (Uplo == CblasLower)         uplo  = 1;
159
160     info = -1;
161
162     if (incy == 0)          info = 11;
163     if (incx == 0)          info =  8;
164     if (lda  < k + 1)       info =  6;
165     if (k < 0)              info =  3;
166     if (n < 0)              info =  2;
167     if (uplo  < 0)          info =  1;
168   }
169
170   if (order == CblasRowMajor) {
171     if (Uplo == CblasUpper)         uplo  = 3;
172     if (Uplo == CblasLower)         uplo  = 2;
173
174     info = -1;
175
176     if (incy == 0)          info = 11;
177     if (incx == 0)          info =  8;
178     if (lda  < k + 1)       info =  6;
179     if (k < 0)              info =  3;
180     if (n < 0)              info =  2;
181     if (uplo  < 0)          info =  1;
182   }
183
184   if (info >= 0) {
185     BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
186     return;
187   }
188
189 #endif
190
191   if (n == 0) return;
192
193   if ((beta_r != ONE) || (beta_i != ZERO)) SCAL_K(n, 0, 0, beta_r, beta_i, y, blasabs(incy), NULL, 0, NULL, 0);
194
195   if ((alpha_r == ZERO) && (alpha_i == ZERO)) return;
196
197   IDEBUG_START;
198
199   FUNCTION_PROFILE_START();
200
201   if (incx < 0 ) x -= (n - 1) * incx * COMPSIZE;
202   if (incy < 0 ) y -= (n - 1) * incy * COMPSIZE;
203
204   buffer = (FLOAT *)blas_memory_alloc(1);
205
206 #ifdef SMPBUG
207   nthreads = num_cpu_avail(2);
208
209   if (nthreads == 1) {
210 #endif
211
212     (hbmv[uplo])(n, k, alpha_r, alpha_i, a, lda, x, incx, y, incy, buffer);
213
214 #ifdef SMPBUG
215   } else {
216
217     (hbmv_thread[uplo])(n, k, ALPHA, a, lda, x, incx, y, incy, buffer, nthreads);
218
219   }
220 #endif
221
222   blas_memory_free(buffer);
223
224   FUNCTION_PROFILE_END(4, n * k / 2 + n,  n * k);
225
226   IDEBUG_END;
227
228   return;
229 }