1 #include "bli_config.h"
2 #include "bli_system.h"
3 #include "bli_type_defs.h"
4 #include "bli_cblas.h"
5 #ifdef BLIS_ENABLE_CBLAS
6 /*
7 * cblas_zgemv.c
8 * The program is a C interface of zgemv
9 *
10 * Keita Teranishi 5/20/98
11 *
12 */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include "cblas.h"
16 #include "cblas_f77.h"
17 void cblas_zgemv(const enum CBLAS_ORDER order,
18 const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
19 const void *alpha, const void *A, const int lda,
20 const void *X, const int incX, const void *beta,
21 void *Y, const int incY)
22 {
23 char TA;
24 #ifdef F77_CHAR
25 F77_CHAR F77_TA;
26 #else
27 #define F77_TA &TA
28 #endif
29 #ifdef F77_INT
30 F77_INT F77_M=M, F77_N=N, F77_lda=lda, F77_incX=incX, F77_incY=incY;
31 #else
32 #define F77_M M
33 #define F77_N N
34 #define F77_lda lda
35 #define F77_incX incx
36 #define F77_incY incY
37 #endif
39 int n, i=0;
40 const double *xx= (double *)X, *alp= (double *)alpha, *bet = (double *)beta;
41 double ALPHA[2],BETA[2];
42 int tincY, tincx;
43 double *x=(double *)X, *y=(double *)Y, *st=0, *tx;
44 extern int CBLAS_CallFromC;
45 extern int RowMajorStrg;
46 RowMajorStrg = 0;
48 CBLAS_CallFromC = 1;
50 if (order == CblasColMajor)
51 {
52 if (TransA == CblasNoTrans) TA = 'N';
53 else if (TransA == CblasTrans) TA = 'T';
54 else if (TransA == CblasConjTrans) TA = 'C';
55 else
56 {
57 cblas_xerbla(2, "cblas_zgemv","Illegal TransA setting, %d\n", TransA);
58 CBLAS_CallFromC = 0;
59 RowMajorStrg = 0;
60 return;
61 }
62 #ifdef F77_CHAR
63 F77_TA = C2F_CHAR(&TA);
64 #endif
65 F77_zgemv(F77_TA, &F77_M, &F77_N, alpha, A, &F77_lda, X, &F77_incX,
66 beta, Y, &F77_incY);
67 }
68 else if (order == CblasRowMajor)
69 {
70 RowMajorStrg = 1;
72 if (TransA == CblasNoTrans) TA = 'T';
73 else if (TransA == CblasTrans) TA = 'N';
74 else if (TransA == CblasConjTrans)
75 {
76 ALPHA[0]= *alp;
77 ALPHA[1]= -alp[1];
78 BETA[0]= *bet;
79 BETA[1]= -bet[1];
80 TA = 'N';
81 if (M > 0)
82 {
83 n = M << 1;
84 x = malloc(n*sizeof(double));
85 tx = x;
86 if( incX > 0 ) {
87 i = incX << 1 ;
88 tincx = 2;
89 st= x+n;
90 } else {
91 i = incX *(-2);
92 tincx = -2;
93 st = x-2;
94 x +=(n-2);
95 }
97 do
98 {
99 *x = *xx;
100 x[1] = -xx[1];
101 x += tincx ;
102 xx += i;
103 }
104 while (x != st);
105 x=tx;
107 #ifdef F77_INT
108 F77_incX = 1;
109 #else
110 incx = 1;
111 #endif
113 if(incY > 0)
114 tincY = incY;
115 else
116 tincY = -incY;
118 y++;
120 if (N > 0)
121 {
122 i = tincY << 1;
123 n = i * N ;
124 st = y + n;
125 do {
126 *y = -(*y);
127 y += i;
128 } while(y != st);
129 y -= n;
130 }
131 }
132 else x = (double *) X;
133 }
134 else
135 {
136 cblas_xerbla(2, "cblas_zgemv","Illegal TransA setting, %d\n", TransA);
137 CBLAS_CallFromC = 0;
138 RowMajorStrg = 0;
139 return;
140 }
141 #ifdef F77_CHAR
142 F77_TA = C2F_CHAR(&TA);
143 #endif
144 if (TransA == CblasConjTrans)
145 F77_zgemv(F77_TA, &F77_N, &F77_M, ALPHA, A, &F77_lda, x,
146 &F77_incX, BETA, Y, &F77_incY);
147 else
148 F77_zgemv(F77_TA, &F77_N, &F77_M, alpha, A, &F77_lda, x,
149 &F77_incX, beta, Y, &F77_incY);
151 if (TransA == CblasConjTrans)
152 {
153 if (x != (double *)X) free(x);
154 if (N > 0)
155 {
156 do
157 {
158 *y = -(*y);
159 y += i;
160 }
161 while (y != st);
162 }
163 }
164 }
165 else cblas_xerbla(1, "cblas_zgemv", "Illegal Order setting, %d\n", order);
166 CBLAS_CallFromC = 0;
167 RowMajorStrg = 0;
168 return;
169 }
170 #endif