-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrot.c
More file actions
216 lines (183 loc) · 5.43 KB
/
rot.c
File metadata and controls
216 lines (183 loc) · 5.43 KB
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
//------------------------------------------------------
//
// Copyright 2023 Mark Seminatore. All rights reserved.
//------------------------------------------------------
#include "cblas.h"
//------------------------------------------------------
// single-precision rot kernel incx == incy == 1
//------------------------------------------------------
void cblas_srot_k_noinc(cblas_args_t* args)
{
float* x = args->x;
float* y = args->y;
register CBLAS_INDEX n = args->n;
float c = *(float*)args->alpha;
float s = *(float*)args->beta;
CBLAS_INDEX i = 0;
for (; i + 4 <= n; i += 4)
{
float temp0 = c * x[i] + s * y[i];
float temp1 = c * x[i+1] + s * y[i+1];
float temp2 = c * x[i+2] + s * y[i+2];
float temp3 = c * x[i+3] + s * y[i+3];
y[i] = c * y[i] - s * x[i];
y[i+1] = c * y[i+1] - s * x[i+1];
y[i+2] = c * y[i+2] - s * x[i+2];
y[i+3] = c * y[i+3] - s * x[i+3];
x[i] = temp0;
x[i+1] = temp1;
x[i+2] = temp2;
x[i+3] = temp3;
}
for (; i < n; i++)
{
float temp = c * x[i] + s * y[i];
y[i] = c * y[i] - s * x[i];
x[i] = temp;
}
}
//------------------------------------------------------
// single-precision rot kernel
//------------------------------------------------------
void cblas_srot_k(cblas_args_t* args)
{
float* x = args->x;
float* y = args->y;
register CBLAS_INDEX incx = args->incx, incy = args->incy, n = args->n;
float c = *(float*)args->alpha;
float s = *(float*)args->beta;
for (CBLAS_INDEX i = 0; i < n; i++)
{
float temp = c * *x + s * *y;
*y = c * *y - s * *x;
*x = temp;
x += incx;
y += incy;
}
}
//------------------------------------------------------
// double-precision rot kernel incx == incy == 1
//------------------------------------------------------
void cblas_drot_k_noinc(cblas_args_t* args)
{
double* x = args->x;
double* y = args->y;
register CBLAS_INDEX n = args->n;
double c = *(double*)args->alpha;
double s = *(double*)args->beta;
CBLAS_INDEX i = 0;
for (; i + 4 <= n; i += 4)
{
double temp0 = c * x[i] + s * y[i];
double temp1 = c * x[i+1] + s * y[i+1];
double temp2 = c * x[i+2] + s * y[i+2];
double temp3 = c * x[i+3] + s * y[i+3];
y[i] = c * y[i] - s * x[i];
y[i+1] = c * y[i+1] - s * x[i+1];
y[i+2] = c * y[i+2] - s * x[i+2];
y[i+3] = c * y[i+3] - s * x[i+3];
x[i] = temp0;
x[i+1] = temp1;
x[i+2] = temp2;
x[i+3] = temp3;
}
for (; i < n; i++)
{
double temp = c * x[i] + s * y[i];
y[i] = c * y[i] - s * x[i];
x[i] = temp;
}
}
//------------------------------------------------------
// double-precision rot kernel
//------------------------------------------------------
void cblas_drot_k(cblas_args_t* args)
{
double* x = args->x;
double* y = args->y;
register CBLAS_INDEX incx = args->incx, incy = args->incy, n = args->n;
double c = *(double*)args->alpha;
double s = *(double*)args->beta;
for (CBLAS_INDEX i = 0; i < n; i++)
{
double temp = c * *x + s * *y;
*y = c * *y - s * *x;
*x = temp;
x += incx;
y += incy;
}
}
//------------------------------------------------------
// Level-1 single-precision apply rotation
//------------------------------------------------------
void cblas_srot(CBLAS_INDEX n, float *x, CBLAS_INDEX incx, float *y, CBLAS_INDEX incy, float c, float s)
{
CBLAS_VALIDATE_VEC2(n, x, incx, y, incy, );
CBLAS_STATS_START();
#ifdef MT_ENABLED
int mt_used = (n > CBLAS_MT_COPY && cblas_get_num_threads() > 1) ? 1 : 0;
#else
int mt_used = 0;
#endif
kernel_function kernel = blas_kernels.srot_k;
// special case kernel for no increments
if (incx == 1 && incy == 1)
{
kernel = blas_kernels.srot_k_noinc;
}
mt_used = 0; // disable multithreading!
if (mt_used)
{
cblas_level1_exec(sizeof(float), kernel, n, x, incx, y, incy, &c, &s, "SROT");
}
else
{
cblas_args_t args;
args.n = n;
args.x = x;
args.incx = incx;
args.y = y;
args.incy = incy;
args.alpha = &c;
args.beta = &s;
kernel(&args);
}
CBLAS_STATS_END("srot", n, mt_used);
}
//------------------------------------------------------
// Level-1 double-precision apply rotation
//------------------------------------------------------
void cblas_drot(CBLAS_INDEX n, double *x, CBLAS_INDEX incx, double *y, CBLAS_INDEX incy, double c, double s)
{
CBLAS_VALIDATE_VEC2(n, x, incx, y, incy, );
CBLAS_STATS_START();
#ifdef MT_ENABLED
int mt_used = (n > CBLAS_MT_COPY && cblas_get_num_threads() > 1) ? 1 : 0;
#else
int mt_used = 0;
#endif
kernel_function kernel = blas_kernels.drot_k;
// special case kernel for no increments
if (incx == 1 && incy == 1)
{
kernel = blas_kernels.drot_k_noinc;
}
mt_used = 0; // disable multithreading!
if (mt_used)
{
cblas_level1_exec(sizeof(double), kernel, n, x, incx, y, incy, &c, &s, "DROT");
}
else
{
cblas_args_t args;
args.n = n;
args.x = x;
args.incx = incx;
args.y = y;
args.incy = incy;
args.alpha = &c;
args.beta = &s;
kernel(&args);
}
CBLAS_STATS_END("drot", n, mt_used);
}