$darkmode
Eigen  5.0.1-dev
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 
17 namespace Eigen {
18 
19 namespace internal {
20 
21 inline 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 
32 inline 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 
39 struct Packet1cf {
40  EIGEN_STRONG_INLINE Packet1cf() {}
41  EIGEN_STRONG_INLINE explicit Packet1cf(const Packet2f& a) : v(a) {}
42  Packet2f v;
43 };
44 struct Packet2cf {
45  EIGEN_STRONG_INLINE Packet2cf() {}
46  EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
47  Packet4f v;
48 };
49 
50 template <>
51 struct 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 
75 template <>
76 struct unpacket_traits<Packet1cf> : neon_unpacket_default<Packet1cf, std::complex<float>> {
77  using as_real = Packet2f;
78 };
79 template <>
80 struct unpacket_traits<Packet2cf> : neon_unpacket_default<Packet2cf, std::complex<float>> {
81  using half = Packet1cf;
82  using as_real = Packet4f;
83 };
84 
85 template <>
86 EIGEN_STRONG_INLINE Packet1cf pcast<float, Packet1cf>(const float& a) {
87  return Packet1cf(vset_lane_f32(a, vdup_n_f32(0.f), 0));
88 }
89 template <>
90 EIGEN_STRONG_INLINE Packet2cf pcast<Packet2f, Packet2cf>(const Packet2f& a) {
91  return Packet2cf(vreinterpretq_f32_u64(vmovl_u32(vreinterpret_u32_f32(a))));
92 }
93 
94 template <>
95 EIGEN_STRONG_INLINE Packet1cf pzero(const Packet1cf& /*a*/) {
96  return Packet1cf(vdup_n_f32(0.0f));
97 }
98 
99 template <>
100 EIGEN_STRONG_INLINE Packet2cf pzero(const Packet2cf& /*a*/) {
101  return Packet2cf(vdupq_n_f32(0.0f));
102 }
103 
104 template <>
105 EIGEN_STRONG_INLINE Packet1cf pset1<Packet1cf>(const std::complex<float>& from) {
106  return Packet1cf(vld1_f32(reinterpret_cast<const float*>(&from)));
107 }
108 template <>
109 EIGEN_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 
114 template <>
115 EIGEN_STRONG_INLINE Packet1cf padd<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
116  return Packet1cf(padd<Packet2f>(a.v, b.v));
117 }
118 template <>
119 EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
120  return Packet2cf(padd<Packet4f>(a.v, b.v));
121 }
122 
123 template <>
124 EIGEN_STRONG_INLINE Packet1cf psub<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
125  return Packet1cf(psub<Packet2f>(a.v, b.v));
126 }
127 template <>
128 EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
129  return Packet2cf(psub<Packet4f>(a.v, b.v));
130 }
131 
132 template <>
133 EIGEN_STRONG_INLINE Packet1cf pnegate(const Packet1cf& a) {
134  return Packet1cf(pnegate<Packet2f>(a.v));
135 }
136 template <>
137 EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) {
138  return Packet2cf(pnegate<Packet4f>(a.v));
139 }
140 
141 template <>
142 EIGEN_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 }
146 template <>
147 EIGEN_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
153 template <>
154 EIGEN_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 
161 template <>
162 EIGEN_STRONG_INLINE Packet1cf pmul<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
163  return pmadd(a, b, pzero(a));
164 }
165 #else
166 template <>
167 EIGEN_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
188 template <>
189 EIGEN_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 
196 template <>
197 EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
198  return pmadd(a, b, pzero(a));
199 }
200 #else
201 template <>
202 EIGEN_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 
222 template <>
223 EIGEN_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 }
233 template <>
234 EIGEN_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 
245 template <>
246 EIGEN_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 }
249 template <>
250 EIGEN_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 
254 template <>
255 EIGEN_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 }
258 template <>
259 EIGEN_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 
263 template <>
264 EIGEN_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 }
267 template <>
268 EIGEN_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 
272 template <>
273 EIGEN_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 }
276 template <>
277 EIGEN_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 
281 template <>
282 EIGEN_STRONG_INLINE Packet1cf pload<Packet1cf>(const std::complex<float>* from) {
283  EIGEN_DEBUG_ALIGNED_LOAD return Packet1cf(
284  pload<Packet2f>(assume_aligned<unpacket_traits<Packet1cf>::alignment>(reinterpret_cast<const float*>(from))));
285 }
286 template <>
287 EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) {
288  EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(
289  pload<Packet4f>(assume_aligned<unpacket_traits<Packet2cf>::alignment>(reinterpret_cast<const float*>(from))));
290 }
291 
292 template <>
293 EIGEN_STRONG_INLINE Packet1cf ploadu<Packet1cf>(const std::complex<float>* from) {
294  EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cf(ploadu<Packet2f>((const float*)from));
295 }
296 template <>
297 EIGEN_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 
301 template <>
302 EIGEN_STRONG_INLINE Packet1cf ploaddup<Packet1cf>(const std::complex<float>* from) {
303  return pset1<Packet1cf>(*from);
304 }
305 template <>
306 EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) {
307  return pset1<Packet2cf>(*from);
308 }
309 
310 template <>
311 EIGEN_STRONG_INLINE void pstore<std::complex<float>>(std::complex<float>* to, const Packet1cf& from) {
312  EIGEN_DEBUG_ALIGNED_STORE pstore(assume_aligned<unpacket_traits<Packet1cf>::alignment>(reinterpret_cast<float*>(to)),
313  from.v);
314 }
315 template <>
316 EIGEN_STRONG_INLINE void pstore<std::complex<float>>(std::complex<float>* to, const Packet2cf& from) {
317  EIGEN_DEBUG_ALIGNED_STORE pstore(assume_aligned<unpacket_traits<Packet2cf>::alignment>(reinterpret_cast<float*>(to)),
318  from.v);
319 }
320 
321 template <>
322 EIGEN_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 }
325 template <>
326 EIGEN_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 
330 template <>
331 EIGEN_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 }
336 template <>
337 EIGEN_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 
346 template <>
347 EIGEN_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 }
351 template <>
352 EIGEN_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 
358 template <>
359 EIGEN_STRONG_INLINE void prefetch<std::complex<float>>(const std::complex<float>* addr) {
360  EIGEN_ARM_PREFETCH(reinterpret_cast<const float*>(addr));
361 }
362 
363 template <>
364 EIGEN_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 }
369 template <>
370 EIGEN_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 
376 template <>
377 EIGEN_STRONG_INLINE Packet1cf preverse(const Packet1cf& a) {
378  return a;
379 }
380 template <>
381 EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) {
382  return Packet2cf(vcombine_f32(vget_high_f32(a.v), vget_low_f32(a.v)));
383 }
384 
385 template <>
386 EIGEN_STRONG_INLINE Packet1cf pcplxflip<Packet1cf>(const Packet1cf& a) {
387  return Packet1cf(vrev64_f32(a.v));
388 }
389 template <>
390 EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a) {
391  return Packet2cf(vrev64q_f32(a.v));
392 }
393 
394 template <>
395 EIGEN_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 }
400 template <>
401 EIGEN_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 
407 template <>
408 EIGEN_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 }
413 template <>
414 EIGEN_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 
440 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cf, Packet2f)
441 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf, Packet4f)
442 
443 template <>
444 EIGEN_STRONG_INLINE Packet1cf pdiv<Packet1cf>(const Packet1cf& a, const Packet1cf& b) {
445  return pdiv_complex(a, b);
446 }
447 template <>
448 EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
449  return pdiv_complex(a, b);
450 }
451 
452 EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet1cf, 1>& /*kernel*/) {}
453 EIGEN_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 
459 template <>
460 EIGEN_STRONG_INLINE Packet1cf psqrt<Packet1cf>(const Packet1cf& a) {
461  return psqrt_complex<Packet1cf>(a);
462 }
463 
464 template <>
465 EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(const Packet2cf& a) {
466  return psqrt_complex<Packet2cf>(a);
467 }
468 
469 template <>
470 EIGEN_STRONG_INLINE Packet1cf plog<Packet1cf>(const Packet1cf& a) {
471  return plog_complex(a);
472 }
473 
474 template <>
475 EIGEN_STRONG_INLINE Packet2cf plog<Packet2cf>(const Packet2cf& a) {
476  return plog_complex(a);
477 }
478 
479 template <>
480 EIGEN_STRONG_INLINE Packet1cf pexp<Packet1cf>(const Packet1cf& a) {
481  return pexp_complex(a);
482 }
483 
484 template <>
485 EIGEN_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 
492 inline 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 
497 struct Packet1cd {
498  EIGEN_STRONG_INLINE Packet1cd() {}
499  EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {}
500  Packet2d v;
501 };
502 
503 template <>
504 struct 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 
527 template <>
528 struct unpacket_traits<Packet1cd> : neon_unpacket_default<Packet1cd, std::complex<double>> {
529  using as_real = Packet2d;
530 };
531 
532 template <>
533 EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(const std::complex<double>* from) {
534  EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(
535  pload<Packet2d>(assume_aligned<unpacket_traits<Packet1cd>::alignment>(reinterpret_cast<const double*>(from))));
536 }
537 
538 template <>
539 EIGEN_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 
543 template <>
544 EIGEN_STRONG_INLINE Packet1cd pzero<Packet1cd>(const Packet1cd& /*a*/) {
545  return Packet1cd(vdupq_n_f64(0.0));
546 }
547 
548 template <>
549 EIGEN_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 
554 template <>
555 EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
556  return Packet1cd(padd<Packet2d>(a.v, b.v));
557 }
558 
559 template <>
560 EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
561  return Packet1cd(psub<Packet2d>(a.v, b.v));
562 }
563 
564 template <>
565 EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) {
566  return Packet1cd(pnegate<Packet2d>(a.v));
567 }
568 
569 template <>
570 EIGEN_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
575 template <>
576 EIGEN_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 
583 template <>
584 EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
585  return pmadd(a, b, pzero(a));
586 }
587 #else
588 template <>
589 EIGEN_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 
609 template <>
610 EIGEN_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 
621 template <>
622 EIGEN_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 
626 template <>
627 EIGEN_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 
631 template <>
632 EIGEN_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 
636 template <>
637 EIGEN_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 
641 template <>
642 EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) {
643  return pset1<Packet1cd>(*from);
644 }
645 
646 template <>
647 EIGEN_STRONG_INLINE void pstore<std::complex<double>>(std::complex<double>* to, const Packet1cd& from) {
648  EIGEN_DEBUG_ALIGNED_STORE pstore(assume_aligned<unpacket_traits<Packet1cd>::alignment>(reinterpret_cast<double*>(to)),
649  from.v);
650 }
651 
652 template <>
653 EIGEN_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 
657 template <>
658 EIGEN_STRONG_INLINE void prefetch<std::complex<double>>(const std::complex<double>* addr) {
659  EIGEN_ARM_PREFETCH(reinterpret_cast<const double*>(addr));
660 }
661 
662 template <>
663 EIGEN_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 
671 template <>
672 EIGEN_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 
677 template <>
678 EIGEN_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 
684 template <>
685 EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) {
686  return a;
687 }
688 
689 template <>
690 EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) {
691  return pfirst(a);
692 }
693 
694 template <>
695 EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) {
696  return pfirst(a);
697 }
698 
699 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd, Packet2d)
700 
701 template <>
702 EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
703  return pdiv_complex(a, b);
704 }
705 
706 EIGEN_STRONG_INLINE Packet1cd pcplxflip /*<Packet1cd>*/ (const Packet1cd& x) {
707  return Packet1cd(preverse(Packet2d(x.v)));
708 }
709 
710 EIGEN_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 
716 template <>
717 EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(const Packet1cd& a) {
718  return psqrt_complex<Packet1cd>(a);
719 }
720 
721 template <>
722 EIGEN_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
Definition: BFloat16.h:231
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82