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