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