10 #ifndef EIGEN_COMPLEX_SSE_H 11 #define EIGEN_COMPLEX_SSE_H 20 EIGEN_STRONG_INLINE Packet2cf() {}
21 EIGEN_STRONG_INLINE
explicit Packet2cf(
const __m128& a) : v(a) {}
27 #ifndef EIGEN_VECTORIZE_AVX 28 template<>
struct packet_traits<
std::complex<float> > : default_packet_traits
30 typedef Packet2cf type;
31 typedef Packet2cf half;
53 template<>
struct unpacket_traits<Packet2cf> {
typedef std::complex<float> type;
enum {size=2, alignment=
Aligned16};
typedef Packet2cf half; };
55 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(_mm_add_ps(a.v,b.v)); }
56 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(_mm_sub_ps(a.v,b.v)); }
57 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a)
59 const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
60 return Packet2cf(_mm_xor_ps(a.v,mask));
62 template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a)
64 const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
65 return Packet2cf(_mm_xor_ps(a.v,mask));
68 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
70 #ifdef EIGEN_VECTORIZE_SSE3 71 return Packet2cf(_mm_addsub_ps(_mm_mul_ps(_mm_moveldup_ps(a.v), b.v),
72 _mm_mul_ps(_mm_movehdup_ps(a.v),
73 vec4f_swizzle1(b.v, 1, 0, 3, 2))));
78 const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x00000000,0x80000000,0x00000000));
79 return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
80 _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
81 vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
85 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(_mm_and_ps(a.v,b.v)); }
86 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(_mm_or_ps(a.v,b.v)); }
87 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(_mm_xor_ps(a.v,b.v)); }
88 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(_mm_andnot_ps(a.v,b.v)); }
90 template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet2cf(pload<Packet4f>(&numext::real_ref(*from))); }
91 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet2cf(ploadu<Packet4f>(&numext::real_ref(*from))); }
93 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
96 #if EIGEN_GNUC_AT_MOST(4,2) 98 res.v = _mm_loadl_pi(_mm_set1_ps(0.0f), reinterpret_cast<const __m64*>(&from));
99 #elif EIGEN_GNUC_AT_LEAST(4,6) 101 #pragma GCC diagnostic push 102 #pragma GCC diagnostic ignored "-Wuninitialized" 103 res.v = _mm_loadl_pi(res.v, (
const __m64*)&from);
104 #pragma GCC diagnostic pop 106 res.v = _mm_loadl_pi(res.v, (
const __m64*)&from);
108 return Packet2cf(_mm_movelh_ps(res.v,res.v));
111 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
return pset1<Packet2cf>(*from); }
113 template<> EIGEN_STRONG_INLINE
void pstore <std::complex<float> >(std::complex<float> * to,
const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), Packet4f(from.v)); }
114 template<> EIGEN_STRONG_INLINE
void pstoreu<std::complex<float> >(std::complex<float> * to,
const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), Packet4f(from.v)); }
117 template<> EIGEN_DEVICE_FUNC
inline Packet2cf pgather<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
Index stride)
119 return Packet2cf(_mm_set_ps(std::imag(from[1*stride]), std::real(from[1*stride]),
120 std::imag(from[0*stride]), std::real(from[0*stride])));
123 template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
const Packet2cf& from,
Index stride)
125 to[stride*0] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 0)),
126 _mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 1)));
127 to[stride*1] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 2)),
128 _mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 3)));
131 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float> * addr) { _mm_prefetch((
const char*)(addr), _MM_HINT_T0); }
133 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a)
135 #if EIGEN_GNUC_AT_MOST(4,3) 138 EIGEN_ALIGN16 std::complex<float> res[2];
139 _mm_store_ps((
float*)res, a.v);
142 std::complex<float> res;
143 _mm_storel_pi((__m64*)&res, a.v);
148 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a) {
return Packet2cf(_mm_castpd_ps(preverse(Packet2d(_mm_castps_pd(a.v))))); }
150 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
152 return pfirst(Packet2cf(_mm_add_ps(a.v, _mm_movehl_ps(a.v,a.v))));
155 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(
const Packet2cf* vecs)
157 return Packet2cf(_mm_add_ps(_mm_movelh_ps(vecs[0].v,vecs[1].v), _mm_movehl_ps(vecs[1].v,vecs[0].v)));
160 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
162 return pfirst(pmul(a, Packet2cf(_mm_movehl_ps(a.v,a.v))));
166 struct palign_impl<Offset,Packet2cf>
168 static EIGEN_STRONG_INLINE
void run(Packet2cf& first,
const Packet2cf& second)
172 first.v = _mm_movehl_ps(first.v, first.v);
173 first.v = _mm_movelh_ps(first.v, second.v);
178 template<>
struct conj_helper<Packet2cf, Packet2cf, false,true>
180 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const 181 {
return padd(pmul(x,y),c); }
183 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const 185 #ifdef EIGEN_VECTORIZE_SSE3 186 return internal::pmul(a, pconj(b));
188 const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
189 return Packet2cf(_mm_add_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
190 _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
191 vec4f_swizzle1(b.v, 1, 0, 3, 2))));
196 template<>
struct conj_helper<Packet2cf, Packet2cf, true,false>
198 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const 199 {
return padd(pmul(x,y),c); }
201 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const 203 #ifdef EIGEN_VECTORIZE_SSE3 204 return internal::pmul(pconj(a), b);
206 const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
207 return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
208 _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
209 vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
214 template<>
struct conj_helper<Packet2cf, Packet2cf, true,true>
216 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const 217 {
return padd(pmul(x,y),c); }
219 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const 221 #ifdef EIGEN_VECTORIZE_SSE3 222 return pconj(internal::pmul(a, b));
224 const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
225 return Packet2cf(_mm_sub_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
226 _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
227 vec4f_swizzle1(b.v, 1, 0, 3, 2))));
232 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
234 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
237 Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
238 __m128 s = _mm_mul_ps(b.v,b.v);
239 return Packet2cf(_mm_div_ps(res.v,_mm_add_ps(s,_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(s), 0xb1)))));
242 EIGEN_STRONG_INLINE Packet2cf pcplxflip(
const Packet2cf& x)
244 return Packet2cf(vec4f_swizzle1(x.v, 1, 0, 3, 2));
251 EIGEN_STRONG_INLINE Packet1cd() {}
252 EIGEN_STRONG_INLINE
explicit Packet1cd(
const __m128d& a) : v(a) {}
258 #ifndef EIGEN_VECTORIZE_AVX 259 template<>
struct packet_traits<
std::complex<double> > : default_packet_traits
261 typedef Packet1cd type;
262 typedef Packet1cd half;
283 template<>
struct unpacket_traits<Packet1cd> {
typedef std::complex<double> type;
enum {size=1, alignment=
Aligned16};
typedef Packet1cd half; };
285 template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(_mm_add_pd(a.v,b.v)); }
286 template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(_mm_sub_pd(a.v,b.v)); }
287 template<> EIGEN_STRONG_INLINE Packet1cd pnegate(
const Packet1cd& a) {
return Packet1cd(pnegate(Packet2d(a.v))); }
288 template<> EIGEN_STRONG_INLINE Packet1cd pconj(
const Packet1cd& a)
290 const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
291 return Packet1cd(_mm_xor_pd(a.v,mask));
294 template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
296 #ifdef EIGEN_VECTORIZE_SSE3 297 return Packet1cd(_mm_addsub_pd(_mm_mul_pd(_mm_movedup_pd(a.v), b.v),
298 _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
299 vec2d_swizzle1(b.v, 1, 0))));
301 const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
302 return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
303 _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
304 vec2d_swizzle1(b.v, 1, 0)), mask)));
308 template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(_mm_and_pd(a.v,b.v)); }
309 template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(_mm_or_pd(a.v,b.v)); }
310 template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(_mm_xor_pd(a.v,b.v)); }
311 template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(_mm_andnot_pd(a.v,b.v)); }
314 template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(
const std::complex<double>* from)
315 { EIGEN_DEBUG_ALIGNED_LOAD
return Packet1cd(pload<Packet2d>((
const double*)from)); }
316 template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(
const std::complex<double>* from)
317 { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet1cd(ploadu<Packet2d>((
const double*)from)); }
318 template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(
const std::complex<double>& from)
319 {
return ploadu<Packet1cd>(&from); }
321 template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(
const std::complex<double>* from) {
return pset1<Packet1cd>(*from); }
324 template<> EIGEN_STRONG_INLINE
void pstore <std::complex<double> >(std::complex<double> * to,
const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((
double*)to, Packet2d(from.v)); }
325 template<> EIGEN_STRONG_INLINE
void pstoreu<std::complex<double> >(std::complex<double> * to,
const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((
double*)to, Packet2d(from.v)); }
327 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<double> >(
const std::complex<double> * addr) { _mm_prefetch((
const char*)(addr), _MM_HINT_T0); }
329 template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(
const Packet1cd& a)
331 EIGEN_ALIGN16
double res[2];
332 _mm_store_pd(res, a.v);
333 return std::complex<double>(res[0],res[1]);
336 template<> EIGEN_STRONG_INLINE Packet1cd preverse(
const Packet1cd& a) {
return a; }
338 template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(
const Packet1cd& a)
343 template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(
const Packet1cd* vecs)
348 template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(
const Packet1cd& a)
354 struct palign_impl<Offset,Packet1cd>
356 static EIGEN_STRONG_INLINE
void run(Packet1cd& ,
const Packet1cd& )
363 template<>
struct conj_helper<Packet1cd, Packet1cd, false,true>
365 EIGEN_STRONG_INLINE Packet1cd pmadd(
const Packet1cd& x,
const Packet1cd& y,
const Packet1cd& c)
const 366 {
return padd(pmul(x,y),c); }
368 EIGEN_STRONG_INLINE Packet1cd pmul(
const Packet1cd& a,
const Packet1cd& b)
const 370 #ifdef EIGEN_VECTORIZE_SSE3 371 return internal::pmul(a, pconj(b));
373 const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
374 return Packet1cd(_mm_add_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
375 _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
376 vec2d_swizzle1(b.v, 1, 0))));
381 template<>
struct conj_helper<Packet1cd, Packet1cd, true,false>
383 EIGEN_STRONG_INLINE Packet1cd pmadd(
const Packet1cd& x,
const Packet1cd& y,
const Packet1cd& c)
const 384 {
return padd(pmul(x,y),c); }
386 EIGEN_STRONG_INLINE Packet1cd pmul(
const Packet1cd& a,
const Packet1cd& b)
const 388 #ifdef EIGEN_VECTORIZE_SSE3 389 return internal::pmul(pconj(a), b);
391 const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
392 return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
393 _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
394 vec2d_swizzle1(b.v, 1, 0)), mask)));
399 template<>
struct conj_helper<Packet1cd, Packet1cd, true,true>
401 EIGEN_STRONG_INLINE Packet1cd pmadd(
const Packet1cd& x,
const Packet1cd& y,
const Packet1cd& c)
const 402 {
return padd(pmul(x,y),c); }
404 EIGEN_STRONG_INLINE Packet1cd pmul(
const Packet1cd& a,
const Packet1cd& b)
const 406 #ifdef EIGEN_VECTORIZE_SSE3 407 return pconj(internal::pmul(a, b));
409 const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
410 return Packet1cd(_mm_sub_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
411 _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
412 vec2d_swizzle1(b.v, 1, 0))));
417 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
419 template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
422 Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b);
423 __m128d s = _mm_mul_pd(b.v,b.v);
424 return Packet1cd(_mm_div_pd(res.v, _mm_add_pd(s,_mm_shuffle_pd(s, s, 0x1))));
427 EIGEN_STRONG_INLINE Packet1cd pcplxflip(
const Packet1cd& x)
429 return Packet1cd(preverse(Packet2d(x.v)));
432 EIGEN_DEVICE_FUNC
inline void 433 ptranspose(PacketBlock<Packet2cf,2>& kernel) {
434 __m128d w1 = _mm_castps_pd(kernel.packet[0].v);
435 __m128d w2 = _mm_castps_pd(kernel.packet[1].v);
437 __m128 tmp = _mm_castpd_ps(_mm_unpackhi_pd(w1, w2));
438 kernel.packet[0].v = _mm_castpd_ps(_mm_unpacklo_pd(w1, w2));
439 kernel.packet[1].v = tmp;
442 template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
443 __m128d result = pblend<Packet2d>(ifPacket, _mm_castps_pd(thenPacket.v), _mm_castps_pd(elsePacket.v));
444 return Packet2cf(_mm_castpd_ps(result));
447 template<> EIGEN_STRONG_INLINE Packet2cf pinsertfirst(
const Packet2cf& a, std::complex<float> b)
449 return Packet2cf(_mm_loadl_pi(a.v, reinterpret_cast<const __m64*>(&b)));
452 template<> EIGEN_STRONG_INLINE Packet1cd pinsertfirst(
const Packet1cd&, std::complex<double> b)
454 return pset1<Packet1cd>(b);
457 template<> EIGEN_STRONG_INLINE Packet2cf pinsertlast(
const Packet2cf& a, std::complex<float> b)
459 return Packet2cf(_mm_loadh_pi(a.v, reinterpret_cast<const __m64*>(&b)));
462 template<> EIGEN_STRONG_INLINE Packet1cd pinsertlast(
const Packet1cd&, std::complex<double> b)
464 return pset1<Packet1cd>(b);
471 #endif // EIGEN_COMPLEX_SSE_H Definition: Constants.h:230
Namespace containing all symbols from the Eigen library.
Definition: Core:287
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Eigen_Colamd.h:50