Merge pull request #1762 from martin-frbg/issue1710-2
[platform/upstream/openblas.git] / interface / omatcopy.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/09 Saar
30 ***********************************************************/
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include "common.h"
35 #ifdef FUNCTION_PROFILE
36 #include "functable.h"
37 #endif
38
39 #if defined(DOUBLE)
40 #define ERROR_NAME "DOMATCOPY"
41 #else
42 #define ERROR_NAME "SOMATCOPY"
43 #endif
44
45 #define BlasRowMajor 0
46 #define BlasColMajor 1
47 #define BlasNoTrans  0
48 #define BlasTrans    1
49
50 #ifndef CBLAS 
51 void NAME( char* ORDER, char* TRANS, blasint *rows, blasint *cols, FLOAT *alpha, FLOAT *a, blasint *lda, FLOAT *b, blasint *ldb)
52 {
53
54         char Order, Trans;
55         int order=-1,trans=-1;
56         blasint info = -1;
57
58         Order = *ORDER;
59         Trans = *TRANS;
60
61         TOUPPER(Order);
62         TOUPPER(Trans);
63
64         if ( Order == 'C' ) order = BlasColMajor;
65         if ( Order == 'R' ) order = BlasRowMajor;
66         if ( Trans == 'N' ) trans = BlasNoTrans;
67         if ( Trans == 'R' ) trans = BlasNoTrans;
68         if ( Trans == 'T' ) trans = BlasTrans;
69         if ( Trans == 'C' ) trans = BlasTrans;
70 #else 
71 void CNAME(enum CBLAS_ORDER CORDER, enum CBLAS_TRANSPOSE CTRANS, blasint crows, blasint ccols, FLOAT calpha, FLOAT *a, blasint clda, FLOAT *b, blasint cldb)
72 {
73         blasint *rows, *cols, *lda, *ldb; 
74         FLOAT   *alpha; 
75         int order=-1,trans=-1;
76         blasint info = -1;
77
78         if ( CORDER == CblasColMajor ) order = BlasColMajor; 
79         if ( CORDER == CblasRowMajor ) order = BlasRowMajor; 
80
81         if ( CTRANS == CblasNoTrans || CTRANS == CblasConjNoTrans ) trans = BlasNoTrans; 
82         if ( CTRANS == CblasTrans   || CTRANS == CblasConjTrans   ) trans = BlasTrans; 
83
84         rows = &crows; 
85         cols = &ccols; 
86         lda  = &clda; 
87         ldb  = &cldb; 
88         alpha = &calpha; 
89
90 #endif
91         if ( order == BlasColMajor)
92         {
93                 if ( trans == BlasNoTrans  &&  *ldb < *rows ) info = 9;
94                 if ( trans == BlasTrans    &&  *ldb < *cols ) info = 9;
95         }
96         if ( order == BlasRowMajor)
97         {
98                 if ( trans == BlasNoTrans  &&  *ldb < *cols ) info = 9;
99                 if ( trans == BlasTrans    &&  *ldb < *rows ) info = 9;
100         }
101
102         if ( order == BlasColMajor &&  *lda < *rows ) info = 7;
103         if ( order == BlasRowMajor &&  *lda < *cols ) info = 7;
104         if ( *cols <= 0 ) info = 4;
105         if ( *rows <= 0 ) info = 3;
106         if ( trans < 0  ) info = 2;
107         if ( order < 0  ) info = 1;
108
109         if (info >= 0) {
110                 BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
111                 return;
112         }
113
114         if ( order == BlasColMajor )
115         {
116                 if ( trans == BlasNoTrans )
117                 {
118                         OMATCOPY_K_CN(*rows, *cols, *alpha, a, *lda, b, *ldb );
119                 }
120                 else
121                 {
122                         OMATCOPY_K_CT(*rows, *cols, *alpha, a, *lda, b, *ldb );
123                 }
124         }
125         else
126         {
127                 if ( trans == BlasNoTrans )
128                 {
129                         OMATCOPY_K_RN(*rows, *cols, *alpha, a, *lda, b, *ldb );
130                 }
131                 else
132                 {
133                         OMATCOPY_K_RT(*rows, *cols, *alpha, a, *lda, b, *ldb );
134                 }
135         }
136
137         return;
138
139 }
140
141