forked from dealias/fftwpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmult-sse2.h
247 lines (194 loc) · 4.51 KB
/
cmult-sse2.h
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
/* SSE2 complex multiplication routines
Copyright (C) 2010 John C. Bowman, University of Alberta
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __cmult_sse2_h__
#define __cmult_sse2_h__ 1
#include "Complex.h"
namespace fftwpp {
#ifdef __SSE2__
#include <emmintrin.h>
typedef __m128d Vec;
union uvec {
unsigned u[4];
Vec v;
};
extern const union uvec sse2_pm;
extern const union uvec sse2_mm;
#if defined(__INTEL_COMPILER) || !defined(__GNUC__)
static inline Vec operator -(const Vec& a)
{
return _mm_xor_pd(sse2_mm.v,a);
}
static inline Vec operator +(const Vec& a, const Vec& b)
{
return _mm_add_pd(a,b);
}
static inline Vec operator -(const Vec& a, const Vec& b)
{
return _mm_sub_pd(a,b);
}
static inline Vec operator *(const Vec& a, const Vec& b)
{
return _mm_mul_pd(a,b);
}
static inline void operator +=(Vec& a, const Vec& b)
{
a=_mm_add_pd(a,b);
}
static inline void operator -=(Vec& a, const Vec& b)
{
a=_mm_sub_pd(a,b);
}
static inline void operator *=(Vec& a, const Vec& b)
{
a=_mm_mul_pd(a,b);
}
#endif
// Return (z.x,w.x)
static inline Vec UNPACKL(const Vec& z, const Vec& w)
{
return _mm_unpacklo_pd(z,w);
}
// Return (z.y,w.y)
static inline Vec UNPACKH(const Vec& z, const Vec& w)
{
return _mm_unpackhi_pd(z,w);
}
// Return (z.y,z.x)
static inline Vec FLIP(const Vec& z)
{
return _mm_shuffle_pd(z,z,1);
}
// Return (z.x,-z.y)
static inline Vec CONJ(const Vec& z)
{
return _mm_xor_pd(sse2_pm.v,z);
}
static inline Vec LOAD(double x)
{
return _mm_load1_pd(&x);
}
#else
class Vec {
public:
double x;
double y;
Vec() {};
Vec(double x, double y) : x(x), y(y) {};
Vec(const Vec &v) : x(v.x), y(v.y) {};
Vec(const Complex &z) : x(z.re), y(z.im) {};
const Vec& operator += (const Vec& v) {
x += v.x;
y += v.y;
return *this;
}
const Vec& operator -= (const Vec& v) {
x -= v.x;
y -= v.y;
return *this;
}
const Vec& operator *= (const Vec& v) {
x *= v.x;
y *= v.y;
return *this;
}
};
static inline Vec operator -(const Vec& a)
{
return Vec(-a.x,-a.y);
}
static inline Vec operator +(const Vec& a, const Vec& b)
{
return Vec(a.x+b.x,a.y+b.y);
}
static inline Vec operator -(const Vec& a, const Vec& b)
{
return Vec(a.x-b.x,a.y-b.y);
}
static inline Vec operator *(const Vec& a, const Vec& b)
{
return Vec(a.x*b.x,a.y*b.y);
}
static inline Vec UNPACKL(const Vec& z, const Vec& w)
{
return Vec(z.x,w.x);
}
static inline Vec UNPACKH(const Vec& z, const Vec& w)
{
return Vec(z.y,w.y);
}
static inline Vec FLIP(const Vec& z)
{
return Vec(z.y,z.x);
}
static inline Vec CONJ(const Vec& z)
{
return Vec(z.x,-z.y);
}
static inline Vec LOAD(double x)
{
return Vec(x,x);
}
#endif
static inline Vec LOAD(const Complex *z)
{
return *(const Vec *) z;
}
static inline void STORE(Complex *z, const Vec& v)
{
*(Vec *) z = v;
}
static inline Vec LOAD(const double *z)
{
return *(const Vec *) z;
}
static inline void STORE(double *z, const Vec& v)
{
*(Vec *) z = v;
}
// Return I*z.
static inline Vec ZMULTI(const Vec& z)
{
return FLIP(CONJ(z));
}
// Return the complex product of z and w.
static inline Vec ZMULT(const Vec& z, const Vec& w)
{
return w*UNPACKL(z,z)+UNPACKH(z,z)*ZMULTI(w);
}
// Return the complex product of CONJ(z) and w.
static inline Vec ZMULTC(const Vec& z, const Vec& w)
{
return w*UNPACKL(z,z)-UNPACKH(z,z)*ZMULTI(w);
}
// Return the complex product of z and I*w.
static inline Vec ZMULTI(const Vec& z, const Vec& w)
{
return ZMULTI(w)*UNPACKL(z,z)-UNPACKH(z,z)*w;
}
// Return the complex product of CONJ(z) and I*w.
static inline Vec ZMULTIC(const Vec& z, const Vec& w)
{
return ZMULTI(w)*UNPACKL(z,z)+UNPACKH(z,z)*w;
}
static inline Vec ZMULT(const Vec& x, const Vec& y, const Vec& w)
{
return x*w+y*FLIP(w);
}
static inline Vec ZMULTI(const Vec& x, const Vec& y, const Vec& w)
{
Vec z=CONJ(w);
return x*FLIP(z)+y*z;
}
}
#endif