Eigen  5.0.1-dev+284dcc12
 
Loading...
Searching...
No Matches
Complex.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2010 Konstantinos Margaritis <markos@freevec.org>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_COMPLEX_NEON_H
12#define EIGEN_COMPLEX_NEON_H
13
14// IWYU pragma: private
15#include "../../InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21inline uint32x4_t p4ui_CONJ_XOR() {
22// See bug 1325, clang fails to call vld1q_u64.
23#if EIGEN_COMP_CLANG || EIGEN_COMP_CASTXML
24 uint32x4_t ret = {0x00000000, 0x80000000, 0x00000000, 0x80000000};
25 return ret;
26#else
27 static const uint32_t conj_XOR_DATA[] = {0x00000000, 0x80000000, 0x00000000, 0x80000000};
28 return vld1q_u32(conj_XOR_DATA);
29#endif
30}
31
32inline uint32x2_t p2ui_CONJ_XOR() {
33 static const uint32_t conj_XOR_DATA[] = {0x00000000, 0x80000000};
34 return vld1_u32(conj_XOR_DATA);
35}
36
37//---------- float ----------
38
39struct Packet1cf {
40 EIGEN_STRONG_INLINE Packet1cf() {}
41 EIGEN_STRONG_INLINE explicit Packet1cf(const Packet2f& a) : v(a) {}
42 Packet2f v;
43};
44struct Packet2cf {
45 EIGEN_STRONG_INLINE Packet2cf() {}
46 EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
47 Packet4f v;
48};
49
50template <>
51struct packet_traits<std::complex<float> > : default_packet_traits {
52 typedef Packet2cf type;
53 typedef Packet1cf half;
54 enum {
55 Vectorizable = 1,
56 AlignedOnScalar = 1,
57 size = 2,
58
59 HasAdd = 1,
60 HasSub = 1,
61 HasMul = 1,
62 HasDiv = 1,
63 HasNegate = 1,
64 HasSqrt = 1,
65 HasLog = 1,
66 HasExp = 1,
67 HasAbs = 0,
68 HasAbs2 = 0,
69 HasMin = 0,
70 HasMax = 0,
71 HasSetLinear = 0
72 };
73};
74
75template <>
76struct unpacket_traits<Packet1cf> : neon_unpacket_default<Packet1cf, std::complex<float>> {
77 using as_real = Packet2f;
78};
79template <>
80struct unpacket_traits<Packet2cf> : neon_unpacket_default<Packet2cf, std::complex<float>> {
81 using half = Packet1cf;
82 using as_real = Packet4f;
83};
84
85template <>
86EIGEN_STRONG_INLINE Packet1cf pcast<float, Packet1cf>(const float& a) {
87 return Packet1cf(vset_lane_f32(a, vdup_n_f32(0.f), 0));
88}
89template <>
90EIGEN_STRONG_INLINE Packet2cf pcast<Packet2f, Packet2cf>(const Packet2f& a) {
91 return Packet2cf(vreinterpretq_f32_u64(vmovl_u32(vreinterpret_u32_f32(a))));
92}
93
94template <>
95EIGEN_STRONG_INLINE Packet1cf pzero(const Packet1cf& /*a*/) {
96 return Packet1cf(vdup_n_f32(0.0f));
97}
98
99template <>
100EIGEN_STRONG_INLINE Packet2cf pzero(const Packet2cf& /*a*/) {
101 return Packet2cf(vdupq_n_f32(0.0f));
102}
103
104template <>
105EIGEN_STRONG_INLINE Packet1cf pset1<Packet1cf>(const std::complex<float>& from) {
106 return Packet1cf(vld1_f32(reinterpret_cast<const float*>(&from)));
107}
108template <>
109EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) {
110 const float32x2_t r64 = vld1_f32(reinterpret_cast<const float*>(&from));
111 return Packet2cf(vcombine_f32(r64, r64));
112}
113
114template <>
115EIGEN_STRONG_INLINE Packet1cf padd<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
116 return Packet1cf(padd<Packet2f>(a.v, b.v));
117}
118template <>
119EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
120 return Packet2cf(padd<Packet4f>(a.v, b.v));
121}
122
123template <>
124EIGEN_STRONG_INLINE Packet1cf psub<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
125 return Packet1cf(psub<Packet2f>(a.v, b.v));
126}
127template <>
128EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
129 return Packet2cf(psub<Packet4f>(a.v, b.v));
130}
131
132template <>
133EIGEN_STRONG_INLINE Packet1cf pnegate(const Packet1cf& a) {
134 return Packet1cf(pnegate<Packet2f>(a.v));
135}
136template <>
137EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) {
138 return Packet2cf(pnegate<Packet4f>(a.v));
139}
140
141template <>
142EIGEN_STRONG_INLINE Packet1cf pconj(const Packet1cf& a) {
143 const Packet2ui b = Packet2ui(vreinterpret_u32_f32(a.v));
144 return Packet1cf(vreinterpret_f32_u32(veor_u32(b, p2ui_CONJ_XOR())));
145}
146template <>
147EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) {
148 const Packet4ui b = Packet4ui(vreinterpretq_u32_f32(a.v));
149 return Packet2cf(vreinterpretq_f32_u32(veorq_u32(b, p4ui_CONJ_XOR())));
150}
151
152#ifdef __ARM_FEATURE_COMPLEX
153template <>
154EIGEN_STRONG_INLINE Packet1cf pmadd<Packet1cf>(const Packet1cf& a, const Packet1cf& b, const Packet1cf& c) {
155 Packet1cf result;
156 result.v = vcmla_f32(c.v, a.v, b.v);
157 result.v = vcmla_rot90_f32(result.v, a.v, b.v);
158 return result;
159}
160
161template <>
162EIGEN_STRONG_INLINE Packet1cf pmul<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
163 return pmadd(a, b, pzero(a));
164}
165#else
166template <>
167EIGEN_STRONG_INLINE Packet1cf pmul<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
168 Packet2f v1, v2;
169
170 // Get the real values of a | a1_re | a1_re |
171 v1 = vdup_lane_f32(a.v, 0);
172 // Get the imag values of a | a1_im | a1_im |
173 v2 = vdup_lane_f32(a.v, 1);
174 // Multiply the real a with b
175 v1 = vmul_f32(v1, b.v);
176 // Multiply the imag a with b
177 v2 = vmul_f32(v2, b.v);
178 // Conjugate v2
179 v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR()));
180 // Swap real/imag elements in v2.
181 v2 = vrev64_f32(v2);
182 // Add and return the result
183 return Packet1cf(vadd_f32(v1, v2));
184}
185#endif
186
187#ifdef __ARM_FEATURE_COMPLEX
188template <>
189EIGEN_STRONG_INLINE Packet2cf pmadd<Packet2cf>(const Packet2cf& a, const Packet2cf& b, const Packet2cf& c) {
190 Packet2cf result;
191 result.v = vcmlaq_f32(c.v, a.v, b.v);
192 result.v = vcmlaq_rot90_f32(result.v, a.v, b.v);
193 return result;
194}
195
196template <>
197EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
198 return pmadd(a, b, pzero(a));
199}
200#else
201template <>
202EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
203 Packet4f v1, v2;
204
205 // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
206 v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0));
207 // Get the imag values of a | a1_im | a1_im | a2_im | a2_im |
208 v2 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 1), vdup_lane_f32(vget_high_f32(a.v), 1));
209 // Multiply the real a with b
210 v1 = vmulq_f32(v1, b.v);
211 // Multiply the imag a with b
212 v2 = vmulq_f32(v2, b.v);
213 // Conjugate v2
214 v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR()));
215 // Swap real/imag elements in v2.
216 v2 = vrev64q_f32(v2);
217 // Add and return the result
218 return Packet2cf(vaddq_f32(v1, v2));
219}
220#endif
221
222template <>
223EIGEN_STRONG_INLINE Packet1cf pcmp_eq(const Packet1cf& a, const Packet1cf& b) {
224 // Compare real and imaginary parts of a and b to get the mask vector:
225 // [re(a[0])==re(b[0]), im(a[0])==im(b[0])]
226 Packet2f eq = pcmp_eq<Packet2f>(a.v, b.v);
227 // Swap real/imag elements in the mask in to get:
228 // [im(a[0])==im(b[0]), re(a[0])==re(b[0])]
229 Packet2f eq_swapped = vrev64_f32(eq);
230 // Return re(a)==re(b) && im(a)==im(b) by computing bitwise AND of eq and eq_swapped
231 return Packet1cf(pand<Packet2f>(eq, eq_swapped));
232}
233template <>
234EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) {
235 // Compare real and imaginary parts of a and b to get the mask vector:
236 // [re(a[0])==re(b[0]), im(a[0])==im(b[0]), re(a[1])==re(b[1]), im(a[1])==im(b[1])]
237 Packet4f eq = pcmp_eq<Packet4f>(a.v, b.v);
238 // Swap real/imag elements in the mask in to get:
239 // [im(a[0])==im(b[0]), re(a[0])==re(b[0]), im(a[1])==im(b[1]), re(a[1])==re(b[1])]
240 Packet4f eq_swapped = vrev64q_f32(eq);
241 // Return re(a)==re(b) && im(a)==im(b) by computing bitwise AND of eq and eq_swapped
242 return Packet2cf(pand<Packet4f>(eq, eq_swapped));
243}
244
245template <>
246EIGEN_STRONG_INLINE Packet1cf pand<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
247 return Packet1cf(vreinterpret_f32_u32(vand_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v))));
248}
249template <>
250EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
251 return Packet2cf(vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v))));
252}
253
254template <>
255EIGEN_STRONG_INLINE Packet1cf por<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
256 return Packet1cf(vreinterpret_f32_u32(vorr_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v))));
257}
258template <>
259EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
260 return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v))));
261}
262
263template <>
264EIGEN_STRONG_INLINE Packet1cf pxor<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
265 return Packet1cf(vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v))));
266}
267template <>
268EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
269 return Packet2cf(vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v))));
270}
271
272template <>
273EIGEN_STRONG_INLINE Packet1cf pandnot<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
274 return Packet1cf(vreinterpret_f32_u32(vbic_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v))));
275}
276template <>
277EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
278 return Packet2cf(vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v))));
279}
280
281template <>
282EIGEN_STRONG_INLINE Packet1cf pload<Packet1cf>(const std::complex<float>* from) {
283 EIGEN_ASSUME_ALIGNED(from, unpacket_traits<Packet1cf>::alignment);
284 EIGEN_DEBUG_ALIGNED_LOAD return Packet1cf(pload<Packet2f>((const float*)from));
285}
286template <>
287EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) {
288 EIGEN_ASSUME_ALIGNED(from, unpacket_traits<Packet2cf>::alignment);
289 EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(reinterpret_cast<const float*>(from)));
290}
291
292template <>
293EIGEN_STRONG_INLINE Packet1cf ploadu<Packet1cf>(const std::complex<float>* from) {
294 EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cf(ploadu<Packet2f>((const float*)from));
295}
296template <>
297EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) {
298 EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(reinterpret_cast<const float*>(from)));
299}
300
301template <>
302EIGEN_STRONG_INLINE Packet1cf ploaddup<Packet1cf>(const std::complex<float>* from) {
303 return pset1<Packet1cf>(*from);
304}
305template <>
306EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) {
307 return pset1<Packet2cf>(*from);
308}
309
310template <>
311EIGEN_STRONG_INLINE void pstore<std::complex<float> >(std::complex<float>* to, const Packet1cf& from) {
312 EIGEN_ASSUME_ALIGNED(to, unpacket_traits<Packet1cf>::alignment);
313 EIGEN_DEBUG_ALIGNED_STORE pstore((float*)to, from.v);
314}
315template <>
316EIGEN_STRONG_INLINE void pstore<std::complex<float> >(std::complex<float>* to, const Packet2cf& from) {
317 EIGEN_ASSUME_ALIGNED(to, unpacket_traits<Packet2cf>::alignment);
318 EIGEN_DEBUG_ALIGNED_STORE pstore(reinterpret_cast<float*>(to), from.v);
319}
320
321template <>
322EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, const Packet1cf& from) {
323 EIGEN_DEBUG_UNALIGNED_STORE pstoreu((float*)to, from.v);
324}
325template <>
326EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, const Packet2cf& from) {
327 EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<float*>(to), from.v);
328}
329
330template <>
331EIGEN_DEVICE_FUNC inline Packet1cf pgather<std::complex<float>, Packet1cf>(const std::complex<float>* from,
332 Index stride) {
333 const Packet2f tmp = vdup_n_f32(std::real(from[0 * stride]));
334 return Packet1cf(vset_lane_f32(std::imag(from[0 * stride]), tmp, 1));
335}
336template <>
337EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from,
338 Index stride) {
339 Packet4f res = vdupq_n_f32(std::real(from[0 * stride]));
340 res = vsetq_lane_f32(std::imag(from[0 * stride]), res, 1);
341 res = vsetq_lane_f32(std::real(from[1 * stride]), res, 2);
342 res = vsetq_lane_f32(std::imag(from[1 * stride]), res, 3);
343 return Packet2cf(res);
344}
345
346template <>
347EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet1cf>(std::complex<float>* to, const Packet1cf& from,
348 Index stride) {
349 to[stride * 0] = std::complex<float>(vget_lane_f32(from.v, 0), vget_lane_f32(from.v, 1));
350}
351template <>
352EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from,
353 Index stride) {
354 to[stride * 0] = std::complex<float>(vgetq_lane_f32(from.v, 0), vgetq_lane_f32(from.v, 1));
355 to[stride * 1] = std::complex<float>(vgetq_lane_f32(from.v, 2), vgetq_lane_f32(from.v, 3));
356}
357
358template <>
359EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float>* addr) {
360 EIGEN_ARM_PREFETCH(reinterpret_cast<const float*>(addr));
361}
362
363template <>
364EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet1cf>(const Packet1cf& a) {
365 EIGEN_ALIGN16 std::complex<float> x;
366 vst1_f32(reinterpret_cast<float*>(&x), a.v);
367 return x;
368}
369template <>
370EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) {
371 EIGEN_ALIGN16 std::complex<float> x[2];
372 vst1q_f32(reinterpret_cast<float*>(x), a.v);
373 return x[0];
374}
375
376template <>
377EIGEN_STRONG_INLINE Packet1cf preverse(const Packet1cf& a) {
378 return a;
379}
380template <>
381EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) {
382 return Packet2cf(vcombine_f32(vget_high_f32(a.v), vget_low_f32(a.v)));
383}
384
385template <>
386EIGEN_STRONG_INLINE Packet1cf pcplxflip<Packet1cf>(const Packet1cf& a) {
387 return Packet1cf(vrev64_f32(a.v));
388}
389template <>
390EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a) {
391 return Packet2cf(vrev64q_f32(a.v));
392}
393
394template <>
395EIGEN_STRONG_INLINE std::complex<float> predux<Packet1cf>(const Packet1cf& a) {
396 std::complex<float> s;
397 vst1_f32((float*)&s, a.v);
398 return s;
399}
400template <>
401EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) {
402 std::complex<float> s;
403 vst1_f32(reinterpret_cast<float*>(&s), vadd_f32(vget_low_f32(a.v), vget_high_f32(a.v)));
404 return s;
405}
406
407template <>
408EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet1cf>(const Packet1cf& a) {
409 std::complex<float> s;
410 vst1_f32((float*)&s, a.v);
411 return s;
412}
413template <>
414EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) {
415 float32x2_t a1, a2, v1, v2, prod;
416 std::complex<float> s;
417
418 a1 = vget_low_f32(a.v);
419 a2 = vget_high_f32(a.v);
420 // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
421 v1 = vdup_lane_f32(a1, 0);
422 // Get the real values of a | a1_im | a1_im | a2_im | a2_im |
423 v2 = vdup_lane_f32(a1, 1);
424 // Multiply the real a with b
425 v1 = vmul_f32(v1, a2);
426 // Multiply the imag a with b
427 v2 = vmul_f32(v2, a2);
428 // Conjugate v2
429 v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR()));
430 // Swap real/imag elements in v2.
431 v2 = vrev64_f32(v2);
432 // Add v1, v2
433 prod = vadd_f32(v1, v2);
434
435 vst1_f32(reinterpret_cast<float*>(&s), prod);
436
437 return s;
438}
439
440EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cf, Packet2f)
441EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf, Packet4f)
442
443template <>
444EIGEN_STRONG_INLINE Packet1cf pdiv<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
445 return pdiv_complex(a, b);
446}
447template <>
448EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
449 return pdiv_complex(a, b);
450}
451
452EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet1cf, 1>& /*kernel*/) {}
453EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2cf, 2>& kernel) {
454 Packet4f tmp = vcombine_f32(vget_high_f32(kernel.packet[0].v), vget_high_f32(kernel.packet[1].v));
455 kernel.packet[0].v = vcombine_f32(vget_low_f32(kernel.packet[0].v), vget_low_f32(kernel.packet[1].v));
456 kernel.packet[1].v = tmp;
457}
458
459template <>
460EIGEN_STRONG_INLINE Packet1cf psqrt<Packet1cf>(const Packet1cf& a) {
461 return psqrt_complex<Packet1cf>(a);
462}
463
464template <>
465EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(const Packet2cf& a) {
466 return psqrt_complex<Packet2cf>(a);
467}
468
469template <>
470EIGEN_STRONG_INLINE Packet1cf plog<Packet1cf>(const Packet1cf& a) {
471 return plog_complex(a);
472}
473
474template <>
475EIGEN_STRONG_INLINE Packet2cf plog<Packet2cf>(const Packet2cf& a) {
476 return plog_complex(a);
477}
478
479template <>
480EIGEN_STRONG_INLINE Packet1cf pexp<Packet1cf>(const Packet1cf& a) {
481 return pexp_complex(a);
482}
483
484template <>
485EIGEN_STRONG_INLINE Packet2cf pexp<Packet2cf>(const Packet2cf& a) {
486 return pexp_complex(a);
487}
488
489//---------- double ----------
490#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
491
492inline uint64x2_t p2ul_CONJ_XOR() {
493 static const uint64_t p2ul_conj_XOR_DATA[] = {0x0, 0x8000000000000000};
494 return vld1q_u64(p2ul_conj_XOR_DATA);
495}
496
497struct Packet1cd {
498 EIGEN_STRONG_INLINE Packet1cd() {}
499 EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {}
500 Packet2d v;
501};
502
503template <>
504struct packet_traits<std::complex<double> > : default_packet_traits {
505 typedef Packet1cd type;
506 typedef Packet1cd half;
507 enum {
508 Vectorizable = 1,
509 AlignedOnScalar = 0,
510 size = 1,
511
512 HasAdd = 1,
513 HasSub = 1,
514 HasMul = 1,
515 HasDiv = 1,
516 HasNegate = 1,
517 HasSqrt = 1,
518 HasLog = 1,
519 HasAbs = 0,
520 HasAbs2 = 0,
521 HasMin = 0,
522 HasMax = 0,
523 HasSetLinear = 0
524 };
525};
526
527template <>
528struct unpacket_traits<Packet1cd> : neon_unpacket_default<Packet1cd, std::complex<double>> {
529 using as_real = Packet2d;
530};
531
532template <>
533EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(const std::complex<double>* from) {
534 EIGEN_ASSUME_ALIGNED(from, unpacket_traits<Packet1cd>::alignment);
535 EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>(reinterpret_cast<const double*>(from)));
536}
537
538template <>
539EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) {
540 EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>(reinterpret_cast<const double*>(from)));
541}
542
543template <>
544EIGEN_STRONG_INLINE Packet1cd pzero<Packet1cd>(const Packet1cd& /*a*/) {
545 return Packet1cd(vdupq_n_f64(0.0));
546}
547
548template <>
549EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) {
550 /* here we really have to use unaligned loads :( */
551 return ploadu<Packet1cd>(&from);
552}
553
554template <>
555EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
556 return Packet1cd(padd<Packet2d>(a.v, b.v));
557}
558
559template <>
560EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
561 return Packet1cd(psub<Packet2d>(a.v, b.v));
562}
563
564template <>
565EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) {
566 return Packet1cd(pnegate<Packet2d>(a.v));
567}
568
569template <>
570EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) {
571 return Packet1cd(vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a.v), p2ul_CONJ_XOR())));
572}
573
574#ifdef __ARM_FEATURE_COMPLEX
575template <>
576EIGEN_STRONG_INLINE Packet1cd pmadd<Packet1cd>(const Packet1cd& a, const Packet1cd& b, const Packet1cd& c) {
577 Packet1cd result;
578 result.v = vcmlaq_f64(c.v, a.v, b.v);
579 result.v = vcmlaq_rot90_f64(result.v, a.v, b.v);
580 return result;
581}
582
583template <>
584EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
585 return pmadd(a, b, pzero(a));
586}
587#else
588template <>
589EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
590 Packet2d v1, v2;
591
592 // Get the real values of a
593 v1 = vdupq_lane_f64(vget_low_f64(a.v), 0);
594 // Get the imag values of a
595 v2 = vdupq_lane_f64(vget_high_f64(a.v), 0);
596 // Multiply the real a with b
597 v1 = vmulq_f64(v1, b.v);
598 // Multiply the imag a with b
599 v2 = vmulq_f64(v2, b.v);
600 // Conjugate v2
601 v2 = vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(v2), p2ul_CONJ_XOR()));
602 // Swap real/imag elements in v2.
603 v2 = preverse<Packet2d>(v2);
604 // Add and return the result
605 return Packet1cd(vaddq_f64(v1, v2));
606}
607#endif
608
609template <>
610EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) {
611 // Compare real and imaginary parts of a and b to get the mask vector:
612 // [re(a)==re(b), im(a)==im(b)]
613 Packet2d eq = pcmp_eq<Packet2d>(a.v, b.v);
614 // Swap real/imag elements in the mask in to get:
615 // [im(a)==im(b), re(a)==re(b)]
616 Packet2d eq_swapped = vreinterpretq_f64_u32(vrev64q_u32(vreinterpretq_u32_f64(eq)));
617 // Return re(a)==re(b) & im(a)==im(b) by computing bitwise AND of eq and eq_swapped
618 return Packet1cd(pand<Packet2d>(eq, eq_swapped));
619}
620
621template <>
622EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
623 return Packet1cd(vreinterpretq_f64_u64(vandq_u64(vreinterpretq_u64_f64(a.v), vreinterpretq_u64_f64(b.v))));
624}
625
626template <>
627EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
628 return Packet1cd(vreinterpretq_f64_u64(vorrq_u64(vreinterpretq_u64_f64(a.v), vreinterpretq_u64_f64(b.v))));
629}
630
631template <>
632EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
633 return Packet1cd(vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a.v), vreinterpretq_u64_f64(b.v))));
634}
635
636template <>
637EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
638 return Packet1cd(vreinterpretq_f64_u64(vbicq_u64(vreinterpretq_u64_f64(a.v), vreinterpretq_u64_f64(b.v))));
639}
640
641template <>
642EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) {
643 return pset1<Packet1cd>(*from);
644}
645
646template <>
647EIGEN_STRONG_INLINE void pstore<std::complex<double> >(std::complex<double>* to, const Packet1cd& from) {
648 EIGEN_ASSUME_ALIGNED(to, unpacket_traits<Packet1cd>::alignment);
649 EIGEN_DEBUG_ALIGNED_STORE pstore(reinterpret_cast<double*>(to), from.v);
650}
651
652template <>
653EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double>* to, const Packet1cd& from) {
654 EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<double*>(to), from.v);
655}
656
657template <>
658EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double>* addr) {
659 EIGEN_ARM_PREFETCH(reinterpret_cast<const double*>(addr));
660}
661
662template <>
663EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(const std::complex<double>* from,
664 Index stride) {
665 Packet2d res = pset1<Packet2d>(0.0);
666 res = vsetq_lane_f64(std::real(from[0 * stride]), res, 0);
667 res = vsetq_lane_f64(std::imag(from[0 * stride]), res, 1);
668 return Packet1cd(res);
669}
670
671template <>
672EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, const Packet1cd& from,
673 Index stride) {
674 to[stride * 0] = std::complex<double>(vgetq_lane_f64(from.v, 0), vgetq_lane_f64(from.v, 1));
675}
676
677template <>
678EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) {
679 EIGEN_ALIGN16 std::complex<double> res;
680 pstore<std::complex<double> >(&res, a);
681 return res;
682}
683
684template <>
685EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) {
686 return a;
687}
688
689template <>
690EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) {
691 return pfirst(a);
692}
693
694template <>
695EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) {
696 return pfirst(a);
697}
698
699EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd, Packet2d)
700
701template <>
702EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
703 return pdiv_complex(a, b);
704}
705
706EIGEN_STRONG_INLINE Packet1cd pcplxflip /*<Packet1cd>*/ (const Packet1cd& x) {
707 return Packet1cd(preverse(Packet2d(x.v)));
708}
709
710EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd, 2>& kernel) {
711 Packet2d tmp = vcombine_f64(vget_high_f64(kernel.packet[0].v), vget_high_f64(kernel.packet[1].v));
712 kernel.packet[0].v = vcombine_f64(vget_low_f64(kernel.packet[0].v), vget_low_f64(kernel.packet[1].v));
713 kernel.packet[1].v = tmp;
714}
715
716template <>
717EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(const Packet1cd& a) {
718 return psqrt_complex<Packet1cd>(a);
719}
720
721template <>
722EIGEN_STRONG_INLINE Packet1cd plog<Packet1cd>(const Packet1cd& a) {
723 return plog_complex(a);
724}
725
726#endif // EIGEN_ARCH_ARM64
727
728} // end namespace internal
729
730} // end namespace Eigen
731
732#endif // EIGEN_COMPLEX_NEON_H
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82