Add CPUID identification of Intel Ice Lake
[platform/upstream/openblas.git] / interface / imatcopy.c
1 /***************************************************************************
2 Copyright (c) 2014, The OpenBLAS Project
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 3. Neither the name of the OpenBLAS project nor the names of
14 its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *****************************************************************************/
27
28 /***********************************************************
29  * 2014-06-10 Saar
30  * 2015-09-07 grisuthedragon 
31 ***********************************************************/
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include "common.h"
36 #ifdef FUNCTION_PROFILE
37 #include "functable.h"
38 #endif
39
40 #if defined(DOUBLE)
41 #define ERROR_NAME "DIMATCOPY"
42 #else
43 #define ERROR_NAME "SIMATCOPY"
44 #endif
45
46 #define BlasRowMajor 0
47 #define BlasColMajor 1
48 #define BlasNoTrans  0
49 #define BlasTrans    1
50
51 #undef malloc
52 #undef free
53
54 /* Enables the New IMATCOPY code with inplace operation if lda == ldb   */
55 #define NEW_IMATCOPY
56
57 #ifndef CBLAS
58 void NAME( char* ORDER, char* TRANS, blasint *rows, blasint *cols, FLOAT *alpha, FLOAT *a, blasint *lda, blasint *ldb)
59 {
60
61         char Order, Trans;
62         int order=-1,trans=-1;
63         blasint info = -1;
64         FLOAT *b;
65         size_t msize;
66
67         Order = *ORDER;
68         Trans = *TRANS;
69
70         TOUPPER(Order);
71         TOUPPER(Trans);
72
73         if ( Order == 'C' ) order = BlasColMajor;
74         if ( Order == 'R' ) order = BlasRowMajor;
75         if ( Trans == 'N' ) trans = BlasNoTrans;
76         if ( Trans == 'R' ) trans = BlasNoTrans;
77         if ( Trans == 'T' ) trans = BlasTrans;
78         if ( Trans == 'C' ) trans = BlasTrans;
79 #else 
80 void CNAME( enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, blasint ccols, FLOAT calpha, FLOAT *a, blasint clda, blasint cldb)
81 {
82         int order=-1,trans=-1;
83         blasint info = -1;
84         FLOAT *b;
85         size_t msize;
86         blasint *lda, *ldb, *rows, *cols; 
87         FLOAT *alpha; 
88
89         if ( CORDER == CblasColMajor) order = BlasColMajor; 
90         if ( CORDER == CblasRowMajor) order = BlasRowMajor; 
91         if ( CTRANS == CblasNoTrans || CTRANS == CblasConjNoTrans) trans = BlasNoTrans; 
92         if ( CTRANS == CblasTrans   || CTRANS == CblasConjTrans  ) trans = BlasTrans; 
93
94         rows = &crows; 
95         cols = &ccols; 
96         alpha = &calpha; 
97         lda = &clda; 
98         ldb = &cldb;    
99 #endif 
100
101         if ( order == BlasColMajor)
102         {
103                 if ( trans == BlasNoTrans  &&  *ldb < *rows ) info = 9;
104                 if ( trans == BlasTrans    &&  *ldb < *cols ) info = 9;
105         }
106         if ( order == BlasRowMajor)
107         {
108                 if ( trans == BlasNoTrans  &&  *ldb < *cols ) info = 9;
109                 if ( trans == BlasTrans    &&  *ldb < *rows ) info = 9;
110         }
111
112         if ( order == BlasColMajor &&  *lda < *rows ) info = 7;
113         if ( order == BlasRowMajor &&  *lda < *cols ) info = 7;
114         if ( *cols <= 0 ) info = 4;
115         if ( *rows <= 0 ) info = 3;
116         if ( trans < 0  ) info = 2;
117         if ( order < 0  ) info = 1;
118
119         if (info >= 0) {
120                 BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
121                 return;
122         }
123 #ifdef NEW_IMATCOPY
124     if ( *lda == *ldb && *rows == *cols) {
125         if ( order == BlasColMajor )
126         {
127             if ( trans == BlasNoTrans )
128             {
129                 IMATCOPY_K_CN(*rows, *cols, *alpha, a, *lda );
130             }
131             else
132             {
133                 IMATCOPY_K_CT(*rows, *cols, *alpha, a, *lda );
134             }
135         }
136         else
137         {
138             if ( trans == BlasNoTrans )
139             {
140                 IMATCOPY_K_RN(*rows, *cols, *alpha, a, *lda );
141             }
142             else
143             {
144                 IMATCOPY_K_RT(*rows, *cols, *alpha, a, *lda );
145             }
146         }
147         return; 
148     }
149
150 #endif
151
152         if ( *lda >  *ldb )
153                 msize = (*lda) * (*ldb)  * sizeof(FLOAT);
154         else
155                 msize = (*ldb) * (*ldb)  * sizeof(FLOAT);
156
157         b = malloc(msize);
158         if ( b == NULL )
159         {
160                 printf("Memory alloc failed\n");
161                 exit(1);
162         }
163
164         if ( order == BlasColMajor )
165         {
166                 if ( trans == BlasNoTrans )
167                 {
168                         OMATCOPY_K_CN(*rows, *cols, *alpha, a, *lda, b, *ldb );
169                         OMATCOPY_K_CN(*rows, *cols, (FLOAT) 1.0 , b, *ldb, a, *ldb );
170                 }
171                 else
172                 {
173                         OMATCOPY_K_CT(*rows, *cols, *alpha, a, *lda, b, *ldb );
174                         OMATCOPY_K_CN(*cols, *rows, (FLOAT) 1.0, b, *ldb, a, *ldb );
175                 }
176         }
177         else
178         {
179                 if ( trans == BlasNoTrans )
180                 {
181                         OMATCOPY_K_RN(*rows, *cols, *alpha, a, *lda, b, *ldb );
182                         OMATCOPY_K_RN(*rows, *cols, (FLOAT) 1.0, b, *ldb, a, *ldb );
183                 }
184                 else
185                 {
186                         OMATCOPY_K_RT(*rows, *cols, *alpha, a, *lda, b, *ldb );
187                         OMATCOPY_K_RN(*cols, *rows, (FLOAT) 1.0, b, *ldb, a, *ldb );
188                 }
189         }
190
191         free(b);
192         return;
193
194 }
195
196