Merge pull request #1762 from martin-frbg/issue1710-2
[platform/upstream/openblas.git] / interface / zdot.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 "common.h"
41 #ifdef FUNCTION_PROFILE
42 #include "functable.h"
43 #endif
44
45 #ifdef RETURN_BY_STRUCT
46 #ifdef XDOUBLE
47 #define MYTYPE myxcomplex_t
48 #elif defined DOUBLE
49 #define MYTYPE myzcomplex_t
50 #else
51 #define MYTYPE myccomplex_t
52 #endif
53 #endif
54
55 #ifndef CBLAS
56
57 #ifdef RETURN_BY_STRUCT
58 MYTYPE         NAME(                        blasint *N, FLOAT *x, blasint *INCX, FLOAT *y, blasint *INCY) {
59 #elif defined RETURN_BY_STACK
60 void           NAME(OPENBLAS_COMPLEX_FLOAT *result, blasint *N, FLOAT *x, blasint *INCX, FLOAT *y, blasint *INCY) {
61 #else
62 OPENBLAS_COMPLEX_FLOAT NAME(                        blasint *N, FLOAT *x, blasint *INCX, FLOAT *y, blasint *INCY) {
63 #endif
64
65   BLASLONG n    = *N;
66   BLASLONG incx = *INCX;
67   BLASLONG incy = *INCY;
68 #ifndef RETURN_BY_STACK
69   OPENBLAS_COMPLEX_FLOAT ret;
70 #endif
71 #ifdef RETURN_BY_STRUCT
72   MYTYPE  myret;
73 #endif
74
75 #ifndef RETURN_BY_STRUCT
76   OPENBLAS_COMPLEX_FLOAT zero=OPENBLAS_MAKE_COMPLEX_FLOAT(0.0, 0.0);
77 #endif
78
79   PRINT_DEBUG_NAME;
80
81   if (n <= 0) {
82 #ifdef RETURN_BY_STRUCT
83     myret.r = 0.;
84     myret.i = 0.;
85     return myret;
86 #elif defined RETURN_BY_STACK
87     *result = zero;
88     return;
89 #else
90     return zero;
91 #endif
92   }
93
94   IDEBUG_START;
95
96   FUNCTION_PROFILE_START();
97
98   if (incx < 0) x -= (n - 1) * incx * 2;
99   if (incy < 0) y -= (n - 1) * incy * 2;
100
101 #ifdef RETURN_BY_STRUCT
102
103 #ifndef CONJ
104   ret = DOTU_K(n, x, incx, y, incy);
105 #else
106   ret = DOTC_K(n, x, incx, y, incy);
107 #endif
108
109   myret.r = CREAL ret;
110   myret.i = CIMAG ret;
111
112   FUNCTION_PROFILE_END(4, 2 * n, 2 * n);
113
114   IDEBUG_END;
115
116   return myret;
117
118 #elif defined RETURN_BY_STACK
119
120 #ifndef CONJ
121   *result = DOTU_K(n, x, incx, y, incy);
122 #else
123   *result = DOTC_K(n, x, incx, y, incy);
124 #endif
125
126   FUNCTION_PROFILE_END(4, 2 * n, 2 * n);
127
128   IDEBUG_END;
129
130 #else
131
132 #ifndef CONJ
133   ret = DOTU_K(n, x, incx, y, incy);
134 #else
135   ret = DOTC_K(n, x, incx, y, incy);
136 #endif
137
138   FUNCTION_PROFILE_END(4, 2 * n, 2 * n);
139
140   IDEBUG_END;
141
142   return ret;
143
144 #endif
145
146 }
147
148 #else
149
150 #ifdef FORCE_USE_STACK
151 void           CNAME(blasint n, void *vx, blasint incx, void *vy, blasint incy, void* vresult){
152 OPENBLAS_COMPLEX_FLOAT *result= (OPENBLAS_COMPLEX_FLOAT*)vresult;
153 #else
154 OPENBLAS_COMPLEX_FLOAT CNAME(blasint n, void *vx, blasint incx, void *vy, blasint incy){
155
156   OPENBLAS_COMPLEX_FLOAT ret;
157   OPENBLAS_COMPLEX_FLOAT zero=OPENBLAS_MAKE_COMPLEX_FLOAT(0.0, 0.0);
158 #endif
159   FLOAT *x = (FLOAT*) vx;
160   FLOAT *y = (FLOAT*) vy;
161
162   PRINT_DEBUG_CNAME;
163
164   if (n <= 0) {
165 #ifdef FORCE_USE_STACK
166     OPENBLAS_COMPLEX_FLOAT zero=OPENBLAS_MAKE_COMPLEX_FLOAT(0.0, 0.0);
167     *result = zero;
168 //      CREAL(*result) = 0.0;
169 //      CIMAG(*result) = 0.0;
170     return;
171 #else
172     return zero;
173 #endif
174   }
175
176   if (incx < 0) x -= (n - 1) * incx * 2;
177   if (incy < 0) y -= (n - 1) * incy * 2;
178
179   IDEBUG_START;
180
181   FUNCTION_PROFILE_START();
182
183 #ifdef FORCE_USE_STACK
184
185 #ifndef CONJ
186   *result = DOTU_K(n, x, incx, y, incy);
187 #else
188   *result = DOTC_K(n, x, incx, y, incy);
189 #endif
190
191   FUNCTION_PROFILE_END(4, 2 * n, 2 * n);
192
193   IDEBUG_END;
194
195 #else
196
197 #ifndef CONJ
198   ret = DOTU_K(n, x, incx, y, incy);
199 #else
200   ret = DOTC_K(n, x, incx, y, incy);
201 #endif
202
203   FUNCTION_PROFILE_END(4, 2 * n, 2 * n);
204
205   IDEBUG_END;
206
207   return ret;
208
209 #endif
210
211 }
212
213 #endif