-
Notifications
You must be signed in to change notification settings - Fork 18
/
zmachine.c
203 lines (185 loc) · 4.99 KB
/
zmachine.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**************************************************************************
**
** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
**
** Meschach Library
**
** This Meschach Library is provided "as is" without any express
** or implied warranty of any kind with respect to this software.
** In particular the authors shall not be liable for any direct,
** indirect, special, incidental or consequential damages arising
** in any way from use of the software.
**
** Everyone is granted permission to copy, modify and redistribute this
** Meschach Library, provided:
** 1. All copies contain this copyright notice.
** 2. All modified copies shall carry a notice stating who
** made the last modification and the date of such modification.
** 3. No charge is made for this software or works derived from it.
** This clause shall not be construed as constraining other software
** distributed on the same medium as this software, nor is a
** distribution fee considered a charge.
**
***************************************************************************/
/*
This file contains basic routines which are used by the functions
involving complex vectors.
These are the routines that should be modified in order to take
full advantage of specialised architectures (pipelining, vector
processors etc).
*/
static char *rcsid = "$Id: zmachine.c,v 1.1 1994/01/13 04:25:41 des Exp $";
#include <math.h>
#include "machine.h"
#include "zmatrix.h"
/* __zconj__ -- complex conjugate */
#ifndef ANSI_C
void __zconj__(zp,len)
complex *zp;
int len;
#else
void __zconj__(complex zp[], int len)
#endif
{
int i;
for ( i = 0; i < len; i++ )
zp[i].im = - zp[i].im;
}
/* __zip__ -- inner product
-- computes sum_i zp1[i].zp2[i] if flag == 0
sum_i zp1[i]*.zp2[i] if flag != 0 */
#ifndef ANSI_C
complex __zip__(zp1,zp2,len,flag)
complex *zp1, *zp2;
int flag, len;
#else
complex __zip__(const complex *zp1, const complex *zp2, int len, int flag)
#endif
{
complex sum;
int i;
sum.re = sum.im = 0.0;
if ( flag )
{
for ( i = 0; i < len; i++ )
{
sum.re += zp1[i].re*zp2[i].re + zp1[i].im*zp2[i].im;
sum.im += zp1[i].re*zp2[i].im - zp1[i].im*zp2[i].re;
}
}
else
{
for ( i = 0; i < len; i++ )
{
sum.re += zp1[i].re*zp2[i].re - zp1[i].im*zp2[i].im;
sum.im += zp1[i].re*zp2[i].im + zp1[i].im*zp2[i].re;
}
}
return sum;
}
/* __zmltadd__ -- scalar multiply and add i.e. complex saxpy
-- computes zp1[i] += s.zp2[i] if flag == 0
-- computes zp1[i] += s.zp2[i]* if flag != 0 */
#ifndef ANSI_C
void __zmltadd__(zp1,zp2,s,len,flag)
complex *zp1, *zp2, s;
int flag, len;
#else
void __zmltadd__(complex *zp1, const complex *zp2, complex s,
int len, int flag)
#endif
{
int i;
LongReal t_re, t_im;
if ( ! flag )
{
for ( i = 0; i < len; i++ )
{
t_re = zp1[i].re + s.re*zp2[i].re - s.im*zp2[i].im;
t_im = zp1[i].im + s.re*zp2[i].im + s.im*zp2[i].re;
zp1[i].re = t_re;
zp1[i].im = t_im;
}
}
else
{
for ( i = 0; i < len; i++ )
{
t_re = zp1[i].re + s.re*zp2[i].re + s.im*zp2[i].im;
t_im = zp1[i].im - s.re*zp2[i].im + s.im*zp2[i].re;
zp1[i].re = t_re;
zp1[i].im = t_im;
}
}
}
/* __zmlt__ scalar complex multiply array c.f. sv_mlt() */
#ifndef ANSI_C
void __zmlt__(zp,s,out,len)
complex *zp, s, *out;
register int len;
#else
void __zmlt__(const complex *zp, complex s, complex *out, int len)
#endif
{
int i;
LongReal t_re, t_im;
for ( i = 0; i < len; i++ )
{
t_re = s.re*zp[i].re - s.im*zp[i].im;
t_im = s.re*zp[i].im + s.im*zp[i].re;
out[i].re = t_re;
out[i].im = t_im;
}
}
/* __zadd__ -- add complex arrays c.f. v_add() */
#ifndef ANSI_C
void __zadd__(zp1,zp2,out,len)
complex *zp1, *zp2, *out;
int len;
#else
void __zadd__(const complex *zp1, const complex *zp2, complex *out, int len)
#endif
{
int i;
for ( i = 0; i < len; i++ )
{
out[i].re = zp1[i].re + zp2[i].re;
out[i].im = zp1[i].im + zp2[i].im;
}
}
/* __zsub__ -- subtract complex arrays c.f. v_sub() */
#ifndef ANSI_C
void __zsub__(zp1,zp2,out,len)
complex *zp1, *zp2, *out;
int len;
#else
void __zsub__(const complex *zp1, const complex *zp2, complex *out, int len)
#endif
{
int i;
for ( i = 0; i < len; i++ )
{
out[i].re = zp1[i].re - zp2[i].re;
out[i].im = zp1[i].im - zp2[i].im;
}
}
/* __zzero__ -- zeros an array of complex numbers */
#ifndef ANSI_C
void __zzero__(zp,len)
complex *zp;
int len;
#else
void __zzero__(complex *zp, int len)
#endif
{
/* if a Real precision zero is equivalent to a string of nulls */
MEM_ZERO((char *)zp,len*sizeof(complex));
/* else, need to zero the array entry by entry */
/******************************
while ( len-- )
{
zp->re = zp->im = 0.0;
zp++;
}
******************************/
}