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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
/* -*- mode: C -*- */
/* Some "inline" functions for generic scalar types */
#ifdef TRANSPOSE_2D_ARRAY
static SLang_Array_Type *TRANSPOSE_2D_ARRAY (SLang_Array_Type *at, SLang_Array_Type *bt)
{
GENERIC_TYPE *a_data, *b_data;
int nr, nc, i;
nr = at->dims[0];
nc = at->dims[1];
a_data = (GENERIC_TYPE *) at->data;
b_data = (GENERIC_TYPE *) bt->data;
for (i = 0; i < nr; i++)
{
GENERIC_TYPE *offset = b_data + i;
int j;
for (j = 0; j < nc; j++)
{
*offset = *a_data++;
offset += nr;
}
}
return bt;
}
#undef TRANSPOSE_2D_ARRAY
#endif
#ifdef INNERPROD_FUNCTION
static void INNERPROD_FUNCTION
(SLang_Array_Type *at, SLang_Array_Type *bt, SLang_Array_Type *ct,
unsigned int a_loops, unsigned int a_stride,
unsigned int b_loops, unsigned int b_inc,
unsigned int inner_loops)
{
GENERIC_TYPE_A *a;
GENERIC_TYPE_B *b;
GENERIC_TYPE_C *c;
c = (GENERIC_TYPE_C *) ct->data;
b = (GENERIC_TYPE_B *) bt->data;
a = (GENERIC_TYPE_A *) at->data;
while (a_loops--)
{
GENERIC_TYPE_B *bb;
unsigned int j;
bb = b;
for (j = 0; j < inner_loops; j++)
{
double x = (double) a[j];
if (x != 0.0)
{
unsigned int k;
for (k = 0; k < b_loops; k++)
c[k] += x * bb[k];
}
bb += b_inc;
}
c += b_loops;
a += a_stride;
}
}
#undef INNERPROD_FUNCTION
#undef GENERIC_TYPE_A
#undef GENERIC_TYPE_B
#undef GENERIC_TYPE_C
#endif
#ifdef INNERPROD_COMPLEX_A
static void INNERPROD_COMPLEX_A
(SLang_Array_Type *at, SLang_Array_Type *bt, SLang_Array_Type *ct,
unsigned int a_loops, unsigned int a_stride,
unsigned int b_loops, unsigned int b_inc,
unsigned int inner_loops)
{
double *a;
GENERIC_TYPE *b;
double *c;
c = (double *) ct->data;
b = (GENERIC_TYPE *) bt->data;
a = (double *) at->data;
a_stride *= 2;
while (a_loops--)
{
GENERIC_TYPE *bb;
unsigned int bb_loops;
bb = b;
bb_loops = b_loops;
while (bb_loops--)
{
double real_sum;
double imag_sum;
unsigned int iloops;
double *aa;
GENERIC_TYPE *bbb;
aa = a;
bbb = bb;
iloops = inner_loops;
real_sum = 0.0;
imag_sum = 0.0;
while (iloops--)
{
real_sum += aa[0] * (double)bbb[0];
imag_sum += aa[1] * (double)bbb[0];
aa += 2;
bbb += b_inc;
}
*c++ = real_sum;
*c++ = imag_sum;
bb++;
}
a += a_stride;
}
}
static void INNERPROD_A_COMPLEX
(SLang_Array_Type *at, SLang_Array_Type *bt, SLang_Array_Type *ct,
unsigned int a_loops, unsigned int a_stride,
unsigned int b_loops, unsigned int b_inc,
unsigned int inner_loops)
{
GENERIC_TYPE *a;
double *b;
double *c;
c = (double *) ct->data;
b = (double *) bt->data;
a = (GENERIC_TYPE *) at->data;
b_inc *= 2;
while (a_loops--)
{
double *bb;
unsigned int bb_loops;
bb = b;
bb_loops = b_loops;
while (bb_loops--)
{
double real_sum;
double imag_sum;
unsigned int iloops;
GENERIC_TYPE *aa;
double *bbb;
aa = a;
bbb = bb;
iloops = inner_loops;
real_sum = 0.0;
imag_sum = 0.0;
while (iloops--)
{
real_sum += (double)aa[0] * bbb[0];
imag_sum += (double)aa[0] * bbb[1];
aa += 1;
bbb += b_inc;
}
*c++ = real_sum;
*c++ = imag_sum;
bb += 2;
}
a += a_stride;
}
}
#undef INNERPROD_A_COMPLEX
#undef INNERPROD_COMPLEX_A
#endif /* INNERPROD_COMPLEX_A */
#ifdef INNERPROD_COMPLEX_COMPLEX
static void INNERPROD_COMPLEX_COMPLEX
(SLang_Array_Type *at, SLang_Array_Type *bt, SLang_Array_Type *ct,
unsigned int a_loops, unsigned int a_stride,
unsigned int b_loops, unsigned int b_inc,
unsigned int inner_loops)
{
double *a;
double *b;
double *c;
c = (double *) ct->data;
b = (double *) bt->data;
a = (double *) at->data;
a_stride *= 2;
b_inc *= 2;
while (a_loops--)
{
double *bb;
unsigned int bb_loops;
bb = b;
bb_loops = b_loops;
while (bb_loops--)
{
double real_sum;
double imag_sum;
unsigned int iloops;
double *aa;
double *bbb;
aa = a;
bbb = bb;
iloops = inner_loops;
real_sum = 0.0;
imag_sum = 0.0;
while (iloops--)
{
real_sum += aa[0]*bbb[0] - aa[1]*bbb[1];
imag_sum += aa[0]*bbb[1] + aa[1]*bbb[0];
aa += 2;
bbb += b_inc;
}
*c++ = real_sum;
*c++ = imag_sum;
bb += 2;
}
a += a_stride;
}
}
#undef INNERPROD_COMPLEX_COMPLEX
#endif
#ifdef GENERIC_TYPE
# undef GENERIC_TYPE
#endif
|