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
43 // const static FLOAT dm1 = -1.;
44
CNAME(BLASLONG m,FLOAT * a,FLOAT * b,BLASLONG incb,void * buffer)45 int CNAME(BLASLONG m, FLOAT *a, FLOAT *b, BLASLONG incb, void *buffer){
46
47 BLASLONG i;
48 #if (TRANSA == 2) || (TRANSA == 4)
49 OPENBLAS_COMPLEX_FLOAT result;
50 #endif
51 #ifndef UNIT
52 FLOAT ar, ai, br, bi, ratio, den;
53 #endif
54 FLOAT *B = b;
55
56 if (incb != 1) {
57 B = buffer;
58 COPY_K(m, b, incb, buffer, 1);
59 }
60
61 for (i = 0; i < m; i++) {
62
63 #if (TRANSA == 2) || (TRANSA == 4)
64 if (i > 0) {
65 #if TRANSA == 2
66 result = DOTU_K(i, a, 1, B, 1);
67 #else
68 result = DOTC_K(i, a, 1, B, 1);
69 #endif
70
71 B[i * COMPSIZE + 0] -= CREAL(result);
72 B[i * COMPSIZE + 1] -= CIMAG(result);
73 }
74 #endif
75
76 #ifndef UNIT
77 #if (TRANSA == 1) || (TRANSA == 3)
78 ar = a[0];
79 ai = a[1];
80 #else
81 ar = a[i * COMPSIZE + 0];
82 ai = a[i * COMPSIZE + 1];
83 #endif
84
85 if (fabs(ar) >= fabs(ai)){
86 ratio = ai / ar;
87 den = 1./(ar * ( 1 + ratio * ratio));
88
89 ar = den;
90 #if TRANSA < 3
91 ai = -ratio * den;
92 #else
93 ai = ratio * den;
94 #endif
95 } else {
96 ratio = ar / ai;
97 den = 1./(ai * ( 1 + ratio * ratio));
98 ar = ratio * den;
99 #if TRANSA < 3
100 ai = -den;
101 #else
102 ai = den;
103 #endif
104 }
105
106 br = B[i * COMPSIZE + 0];
107 bi = B[i * COMPSIZE + 1];
108
109 B[i * COMPSIZE + 0] = ar*br - ai*bi;
110 B[i * COMPSIZE + 1] = ar*bi + ai*br;
111 #endif
112
113 #if (TRANSA == 1) || (TRANSA == 3)
114 if (i < m - 1) {
115 #if TRANSA == 1
116 AXPYU_K(m - i - 1 , 0, 0,
117 - B[i * COMPSIZE + 0], - B[i * COMPSIZE + 1],
118 a + COMPSIZE, 1, B + (i + 1) * COMPSIZE, 1, NULL, 0);
119 #else
120 AXPYC_K(m - i - 1 , 0, 0,
121 - B[i * COMPSIZE + 0], - B[i * COMPSIZE + 1],
122 a + COMPSIZE, 1, B + (i + 1) * COMPSIZE, 1, NULL, 0);
123 #endif
124 }
125 #endif
126
127 #if (TRANSA == 1) || (TRANSA == 3)
128 a += (m - i) * 2;
129 #else
130 a += (i + 1) * 2;
131 #endif
132 }
133
134 if (incb != 1) {
135 COPY_K(m, buffer, 1, b, incb);
136 }
137
138 return 0;
139 }
140
141