Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
NEON/PacketMath.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2009 Gael Guennebaud <[email protected]>
5// Copyright (C) 2010 Konstantinos Margaritis <[email protected]>
6// Heavily based on Gael's SSE version.
7//
8// This Source Code Form is subject to the terms of the Mozilla
9// Public License v. 2.0. If a copy of the MPL was not distributed
10// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11
12#ifndef EIGEN_PACKET_MATH_NEON_H
13#define EIGEN_PACKET_MATH_NEON_H
14
15// IWYU pragma: private
16#include "../../InternalHeaderCheck.h"
17
18namespace Eigen {
19
20namespace internal {
21
22#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
23#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
24#endif
25
26#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
27#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
28#endif
29
30#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
31#if EIGEN_ARCH_ARM64
32#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
33#else
34#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 16
35#endif
36#endif
37
38#if EIGEN_COMP_MSVC_STRICT
39
40// In MSVC's arm_neon.h header file, all NEON vector types
41// are aliases to the same underlying type __n128.
42// We thus have to wrap them to make them different C++ types.
43// (See also bug 1428)
44typedef eigen_packet_wrapper<float32x2_t, 0> Packet2f;
45typedef eigen_packet_wrapper<float32x4_t, 1> Packet4f;
46typedef eigen_packet_wrapper<int32_t, 2> Packet4c;
47typedef eigen_packet_wrapper<int8x8_t, 3> Packet8c;
48typedef eigen_packet_wrapper<int8x16_t, 4> Packet16c;
49typedef eigen_packet_wrapper<uint32_t, 5> Packet4uc;
50typedef eigen_packet_wrapper<uint8x8_t, 6> Packet8uc;
51typedef eigen_packet_wrapper<uint8x16_t, 7> Packet16uc;
52typedef eigen_packet_wrapper<int16x4_t, 8> Packet4s;
53typedef eigen_packet_wrapper<int16x8_t, 9> Packet8s;
54typedef eigen_packet_wrapper<uint16x4_t, 10> Packet4us;
55typedef eigen_packet_wrapper<uint16x8_t, 11> Packet8us;
56typedef eigen_packet_wrapper<int32x2_t, 12> Packet2i;
57typedef eigen_packet_wrapper<int32x4_t, 13> Packet4i;
58typedef eigen_packet_wrapper<uint32x2_t, 14> Packet2ui;
59typedef eigen_packet_wrapper<uint32x4_t, 15> Packet4ui;
60typedef eigen_packet_wrapper<int64x2_t, 16> Packet2l;
61typedef eigen_packet_wrapper<uint64x2_t, 17> Packet2ul;
62
63EIGEN_ALWAYS_INLINE Packet4f make_packet4f(float a, float b, float c, float d) {
64 float from[4] = {a, b, c, d};
65 return vld1q_f32(from);
66}
67
68EIGEN_ALWAYS_INLINE Packet2f make_packet2f(float a, float b) {
69 float from[2] = {a, b};
70 return vld1_f32(from);
71}
72
73#else
74
75typedef float32x2_t Packet2f;
76typedef float32x4_t Packet4f;
77typedef eigen_packet_wrapper<int32_t, 2> Packet4c;
78typedef int8x8_t Packet8c;
79typedef int8x16_t Packet16c;
80typedef eigen_packet_wrapper<uint32_t, 5> Packet4uc;
81typedef uint8x8_t Packet8uc;
82typedef uint8x16_t Packet16uc;
83typedef int16x4_t Packet4s;
84typedef int16x8_t Packet8s;
85typedef uint16x4_t Packet4us;
86typedef uint16x8_t Packet8us;
87typedef int32x2_t Packet2i;
88typedef int32x4_t Packet4i;
89typedef uint32x2_t Packet2ui;
90typedef uint32x4_t Packet4ui;
91typedef int64x2_t Packet2l;
92typedef uint64x2_t Packet2ul;
93
94EIGEN_ALWAYS_INLINE Packet4f make_packet4f(float a, float b, float c, float d) { return Packet4f{a, b, c, d}; }
95EIGEN_ALWAYS_INLINE Packet2f make_packet2f(float a, float b) { return Packet2f{a, b}; }
96
97#endif // EIGEN_COMP_MSVC_STRICT
98
99EIGEN_STRONG_INLINE Packet4f shuffle1(const Packet4f& m, int mask) {
100 const float* a = reinterpret_cast<const float*>(&m);
101 Packet4f res =
102 make_packet4f(*(a + (mask & 3)), *(a + ((mask >> 2) & 3)), *(a + ((mask >> 4) & 3)), *(a + ((mask >> 6) & 3)));
103 return res;
104}
105
106// fuctionally equivalent to _mm_shuffle_ps in SSE when interleave
107// == false (i.e. shuffle<false>(m, n, mask) equals _mm_shuffle_ps(m, n, mask)),
108// interleave m and n when interleave == true. Currently used in LU/arch/InverseSize4.h
109// to enable a shared implementation for fast inversion of matrices of size 4.
110template <bool interleave>
111EIGEN_STRONG_INLINE Packet4f shuffle2(const Packet4f& m, const Packet4f& n, int mask) {
112 const float* a = reinterpret_cast<const float*>(&m);
113 const float* b = reinterpret_cast<const float*>(&n);
114 Packet4f res =
115 make_packet4f(*(a + (mask & 3)), *(a + ((mask >> 2) & 3)), *(b + ((mask >> 4) & 3)), *(b + ((mask >> 6) & 3)));
116 return res;
117}
118
119template <>
120EIGEN_STRONG_INLINE Packet4f shuffle2<true>(const Packet4f& m, const Packet4f& n, int mask) {
121 const float* a = reinterpret_cast<const float*>(&m);
122 const float* b = reinterpret_cast<const float*>(&n);
123 Packet4f res =
124 make_packet4f(*(a + (mask & 3)), *(b + ((mask >> 2) & 3)), *(a + ((mask >> 4) & 3)), *(b + ((mask >> 6) & 3)));
125 return res;
126}
127
128EIGEN_STRONG_INLINE static int eigen_neon_shuffle_mask(int p, int q, int r, int s) {
129 return ((s) << 6 | (r) << 4 | (q) << 2 | (p));
130}
131
132EIGEN_STRONG_INLINE Packet4f vec4f_swizzle1(const Packet4f& a, int p, int q, int r, int s) {
133 return shuffle1(a, eigen_neon_shuffle_mask(p, q, r, s));
134}
135EIGEN_STRONG_INLINE Packet4f vec4f_swizzle2(const Packet4f& a, const Packet4f& b, int p, int q, int r, int s) {
136 return shuffle2<false>(a, b, eigen_neon_shuffle_mask(p, q, r, s));
137}
138EIGEN_STRONG_INLINE Packet4f vec4f_movelh(const Packet4f& a, const Packet4f& b) {
139 return shuffle2<false>(a, b, eigen_neon_shuffle_mask(0, 1, 0, 1));
140}
141EIGEN_STRONG_INLINE Packet4f vec4f_movehl(const Packet4f& a, const Packet4f& b) {
142 return shuffle2<false>(b, a, eigen_neon_shuffle_mask(2, 3, 2, 3));
143}
144EIGEN_STRONG_INLINE Packet4f vec4f_unpacklo(const Packet4f& a, const Packet4f& b) {
145 return shuffle2<true>(a, b, eigen_neon_shuffle_mask(0, 0, 1, 1));
146}
147EIGEN_STRONG_INLINE Packet4f vec4f_unpackhi(const Packet4f& a, const Packet4f& b) {
148 return shuffle2<true>(a, b, eigen_neon_shuffle_mask(2, 2, 3, 3));
149}
150#define vec4f_duplane(a, p) Packet4f(vdupq_lane_f32(vget_low_f32(a), p))
151
152#define EIGEN_DECLARE_CONST_Packet4f(NAME, X) const Packet4f p4f_##NAME = pset1<Packet4f>(X)
153
154#define EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME, X) \
155 const Packet4f p4f_##NAME = vreinterpretq_f32_u32(pset1<int32_t>(X))
156
157#define EIGEN_DECLARE_CONST_Packet4i(NAME, X) const Packet4i p4i_##NAME = pset1<Packet4i>(X)
158
159#if EIGEN_ARCH_ARM64 && EIGEN_COMP_GNUC
160// __builtin_prefetch tends to do nothing on ARM64 compilers because the
161// prefetch instructions there are too detailed for __builtin_prefetch to map
162// meaningfully to them.
163#define EIGEN_ARM_PREFETCH(ADDR) __asm__ __volatile__("prfm pldl1keep, [%[addr]]\n" ::[addr] "r"(ADDR) :);
164#elif EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
165#define EIGEN_ARM_PREFETCH(ADDR) __builtin_prefetch(ADDR);
166#elif defined __pld
167#define EIGEN_ARM_PREFETCH(ADDR) __pld(ADDR)
168#elif EIGEN_ARCH_ARM
169#define EIGEN_ARM_PREFETCH(ADDR) __asm__ __volatile__("pld [%[addr]]\n" ::[addr] "r"(ADDR) :);
170#else
171// by default no explicit prefetching
172#define EIGEN_ARM_PREFETCH(ADDR)
173#endif
174
175template <>
176struct packet_traits<float> : default_packet_traits {
177 typedef Packet4f type;
178 typedef Packet2f half;
179 enum {
180 Vectorizable = 1,
181 AlignedOnScalar = 1,
182 size = 4,
183
184 HasCmp = 1,
185 HasAdd = 1,
186 HasSub = 1,
187 HasShift = 1,
188 HasMul = 1,
189 HasNegate = 1,
190 HasAbs = 1,
191 HasArg = 0,
192 HasAbs2 = 1,
193 HasAbsDiff = 1,
194 HasMin = 1,
195 HasMax = 1,
196 HasConj = 1,
197 HasSetLinear = 1,
198 HasBlend = 0,
199 HasDiv = 1,
200 HasSin = EIGEN_FAST_MATH,
201 HasCos = EIGEN_FAST_MATH,
202 HasACos = 1,
203 HasASin = 1,
204 HasATan = 1,
205 HasATanh = 1,
206 HasLog = 1,
207 HasExp = 1,
208 HasSqrt = 1,
209 HasRsqrt = 1,
210 HasTanh = EIGEN_FAST_MATH,
211 HasErf = EIGEN_FAST_MATH,
212 HasBessel = 0, // Issues with accuracy.
213 HasNdtri = 0
214 };
215};
216
217template <>
218struct packet_traits<int8_t> : default_packet_traits {
219 typedef Packet16c type;
220 typedef Packet8c half;
221 enum {
222 Vectorizable = 1,
223 AlignedOnScalar = 1,
224 size = 16,
225
226 HasCmp = 1,
227 HasAdd = 1,
228 HasSub = 1,
229 HasShift = 1,
230 HasMul = 1,
231 HasNegate = 1,
232 HasAbs = 1,
233 HasAbsDiff = 1,
234 HasArg = 0,
235 HasAbs2 = 1,
236 HasMin = 1,
237 HasMax = 1,
238 HasConj = 1,
239 HasSetLinear = 1,
240 HasBlend = 0
241 };
242};
243
244template <>
245struct packet_traits<uint8_t> : default_packet_traits {
246 typedef Packet16uc type;
247 typedef Packet8uc half;
248 enum {
249 Vectorizable = 1,
250 AlignedOnScalar = 1,
251 size = 16,
252
253 HasCmp = 1,
254 HasAdd = 1,
255 HasSub = 1,
256 HasShift = 1,
257 HasMul = 1,
258 HasNegate = 0,
259 HasAbs = 1,
260 HasAbsDiff = 1,
261 HasArg = 0,
262 HasAbs2 = 1,
263 HasMin = 1,
264 HasMax = 1,
265 HasConj = 1,
266 HasSetLinear = 1,
267 HasBlend = 0,
268
269 HasSqrt = 1
270 };
271};
272
273template <>
274struct packet_traits<int16_t> : default_packet_traits {
275 typedef Packet8s type;
276 typedef Packet4s half;
277 enum {
278 Vectorizable = 1,
279 AlignedOnScalar = 1,
280 size = 8,
281
282 HasCmp = 1,
283 HasAdd = 1,
284 HasSub = 1,
285 HasShift = 1,
286 HasMul = 1,
287 HasNegate = 1,
288 HasAbs = 1,
289 HasAbsDiff = 1,
290 HasArg = 0,
291 HasAbs2 = 1,
292 HasMin = 1,
293 HasMax = 1,
294 HasConj = 1,
295 HasSetLinear = 1,
296 HasBlend = 0
297 };
298};
299
300template <>
301struct packet_traits<uint16_t> : default_packet_traits {
302 typedef Packet8us type;
303 typedef Packet4us half;
304 enum {
305 Vectorizable = 1,
306 AlignedOnScalar = 1,
307 size = 8,
308
309 HasCmp = 1,
310 HasAdd = 1,
311 HasSub = 1,
312 HasShift = 1,
313 HasMul = 1,
314 HasNegate = 0,
315 HasAbs = 1,
316 HasAbsDiff = 1,
317 HasArg = 0,
318 HasAbs2 = 1,
319 HasMin = 1,
320 HasMax = 1,
321 HasConj = 1,
322 HasSetLinear = 1,
323 HasBlend = 0,
324 HasSqrt = 1
325 };
326};
327
328template <>
329struct packet_traits<int32_t> : default_packet_traits {
330 typedef Packet4i type;
331 typedef Packet2i half;
332 enum {
333 Vectorizable = 1,
334 AlignedOnScalar = 1,
335 size = 4,
336
337 HasCmp = 1,
338 HasAdd = 1,
339 HasSub = 1,
340 HasShift = 1,
341 HasMul = 1,
342 HasNegate = 1,
343 HasAbs = 1,
344 HasArg = 0,
345 HasAbs2 = 1,
346 HasAbsDiff = 1,
347 HasMin = 1,
348 HasMax = 1,
349 HasConj = 1,
350 HasSetLinear = 1,
351 HasBlend = 0
352 };
353};
354
355template <>
356struct packet_traits<uint32_t> : default_packet_traits {
357 typedef Packet4ui type;
358 typedef Packet2ui half;
359 enum {
360 Vectorizable = 1,
361 AlignedOnScalar = 1,
362 size = 4,
363
364 HasCmp = 1,
365 HasAdd = 1,
366 HasSub = 1,
367 HasShift = 1,
368 HasMul = 1,
369 HasNegate = 0,
370 HasAbs = 1,
371 HasArg = 0,
372 HasAbs2 = 1,
373 HasAbsDiff = 1,
374 HasMin = 1,
375 HasMax = 1,
376 HasConj = 1,
377 HasSetLinear = 1,
378 HasBlend = 0,
379
380 HasSqrt = 1
381 };
382};
383
384template <>
385struct packet_traits<int64_t> : default_packet_traits {
386 typedef Packet2l type;
387 typedef Packet2l half;
388 enum {
389 Vectorizable = 1,
390 AlignedOnScalar = 1,
391 size = 2,
392
393 HasCmp = 1,
394 HasAdd = 1,
395 HasSub = 1,
396 HasShift = 1,
397 HasMul = 1,
398 HasNegate = 1,
399 HasAbs = 1,
400 HasArg = 0,
401 HasAbs2 = 1,
402 HasAbsDiff = 1,
403 HasMin = 1,
404 HasMax = 1,
405 HasConj = 1,
406 HasSetLinear = 1,
407 HasBlend = 0
408 };
409};
410
411template <>
412struct packet_traits<uint64_t> : default_packet_traits {
413 typedef Packet2ul type;
414 typedef Packet2ul half;
415 enum {
416 Vectorizable = 1,
417 AlignedOnScalar = 1,
418 size = 2,
419
420 HasCmp = 1,
421 HasAdd = 1,
422 HasSub = 1,
423 HasShift = 1,
424 HasMul = 1,
425 HasNegate = 0,
426 HasAbs = 1,
427 HasArg = 0,
428 HasAbs2 = 1,
429 HasAbsDiff = 1,
430 HasMin = 1,
431 HasMax = 1,
432 HasConj = 1,
433 HasSetLinear = 1,
434 HasBlend = 0
435 };
436};
437
438template <>
439struct unpacket_traits<Packet2f> {
440 typedef float type;
441 typedef Packet2f half;
442 typedef Packet2i integer_packet;
443 enum {
444 size = 2,
445 alignment = Aligned16,
446 vectorizable = true,
447 masked_load_available = false,
448 masked_store_available = false
449 };
450};
451template <>
452struct unpacket_traits<Packet4f> {
453 typedef float type;
454 typedef Packet2f half;
455 typedef Packet4i integer_packet;
456 enum {
457 size = 4,
458 alignment = Aligned16,
459 vectorizable = true,
460 masked_load_available = false,
461 masked_store_available = false
462 };
463};
464template <>
465struct unpacket_traits<Packet4c> {
466 typedef int8_t type;
467 typedef Packet4c half;
468 enum {
469 size = 4,
470 alignment = Unaligned,
471 vectorizable = true,
472 masked_load_available = false,
473 masked_store_available = false
474 };
475};
476template <>
477struct unpacket_traits<Packet8c> {
478 typedef int8_t type;
479 typedef Packet4c half;
480 enum {
481 size = 8,
482 alignment = Aligned16,
483 vectorizable = true,
484 masked_load_available = false,
485 masked_store_available = false
486 };
487};
488template <>
489struct unpacket_traits<Packet16c> {
490 typedef int8_t type;
491 typedef Packet8c half;
492 enum {
493 size = 16,
494 alignment = Aligned16,
495 vectorizable = true,
496 masked_load_available = false,
497 masked_store_available = false
498 };
499};
500template <>
501struct unpacket_traits<Packet4uc> {
502 typedef uint8_t type;
503 typedef Packet4uc half;
504 enum {
505 size = 4,
506 alignment = Unaligned,
507 vectorizable = true,
508 masked_load_available = false,
509 masked_store_available = false
510 };
511};
512template <>
513struct unpacket_traits<Packet8uc> {
514 typedef uint8_t type;
515 typedef Packet4uc half;
516 enum {
517 size = 8,
518 alignment = Aligned16,
519 vectorizable = true,
520 masked_load_available = false,
521 masked_store_available = false
522 };
523};
524template <>
525struct unpacket_traits<Packet16uc> {
526 typedef uint8_t type;
527 typedef Packet8uc half;
528 enum {
529 size = 16,
530 alignment = Aligned16,
531 vectorizable = true,
532 masked_load_available = false,
533 masked_store_available = false
534 };
535};
536template <>
537struct unpacket_traits<Packet4s> {
538 typedef int16_t type;
539 typedef Packet4s half;
540 enum {
541 size = 4,
542 alignment = Aligned16,
543 vectorizable = true,
544 masked_load_available = false,
545 masked_store_available = false
546 };
547};
548template <>
549struct unpacket_traits<Packet8s> {
550 typedef int16_t type;
551 typedef Packet4s half;
552 enum {
553 size = 8,
554 alignment = Aligned16,
555 vectorizable = true,
556 masked_load_available = false,
557 masked_store_available = false
558 };
559};
560template <>
561struct unpacket_traits<Packet4us> {
562 typedef uint16_t type;
563 typedef Packet4us half;
564 enum {
565 size = 4,
566 alignment = Aligned16,
567 vectorizable = true,
568 masked_load_available = false,
569 masked_store_available = false
570 };
571};
572template <>
573struct unpacket_traits<Packet8us> {
574 typedef uint16_t type;
575 typedef Packet4us half;
576 enum {
577 size = 8,
578 alignment = Aligned16,
579 vectorizable = true,
580 masked_load_available = false,
581 masked_store_available = false
582 };
583};
584template <>
585struct unpacket_traits<Packet2i> {
586 typedef int32_t type;
587 typedef Packet2i half;
588 enum {
589 size = 2,
590 alignment = Aligned16,
591 vectorizable = true,
592 masked_load_available = false,
593 masked_store_available = false
594 };
595};
596template <>
597struct unpacket_traits<Packet4i> {
598 typedef int32_t type;
599 typedef Packet2i half;
600 enum {
601 size = 4,
602 alignment = Aligned16,
603 vectorizable = true,
604 masked_load_available = false,
605 masked_store_available = false
606 };
607};
608template <>
609struct unpacket_traits<Packet2ui> {
610 typedef uint32_t type;
611 typedef Packet2ui half;
612 enum {
613 size = 2,
614 alignment = Aligned16,
615 vectorizable = true,
616 masked_load_available = false,
617 masked_store_available = false
618 };
619};
620template <>
621struct unpacket_traits<Packet4ui> {
622 typedef uint32_t type;
623 typedef Packet2ui half;
624 enum {
625 size = 4,
626 alignment = Aligned16,
627 vectorizable = true,
628 masked_load_available = false,
629 masked_store_available = false
630 };
631};
632template <>
633struct unpacket_traits<Packet2l> {
634 typedef int64_t type;
635 typedef Packet2l half;
636 enum {
637 size = 2,
638 alignment = Aligned16,
639 vectorizable = true,
640 masked_load_available = false,
641 masked_store_available = false
642 };
643};
644template <>
645struct unpacket_traits<Packet2ul> {
646 typedef uint64_t type;
647 typedef Packet2ul half;
648 enum {
649 size = 2,
650 alignment = Aligned16,
651 vectorizable = true,
652 masked_load_available = false,
653 masked_store_available = false
654 };
655};
656
657template <>
658EIGEN_STRONG_INLINE Packet2f pset1<Packet2f>(const float& from) {
659 return vdup_n_f32(from);
660}
661template <>
662EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) {
663 return vdupq_n_f32(from);
664}
665template <>
666EIGEN_STRONG_INLINE Packet4c pset1<Packet4c>(const int8_t& from) {
667 return vget_lane_s32(vreinterpret_s32_s8(vdup_n_s8(from)), 0);
668}
669template <>
670EIGEN_STRONG_INLINE Packet8c pset1<Packet8c>(const int8_t& from) {
671 return vdup_n_s8(from);
672}
673template <>
674EIGEN_STRONG_INLINE Packet16c pset1<Packet16c>(const int8_t& from) {
675 return vdupq_n_s8(from);
676}
677template <>
678EIGEN_STRONG_INLINE Packet4uc pset1<Packet4uc>(const uint8_t& from) {
679 return vget_lane_u32(vreinterpret_u32_u8(vdup_n_u8(from)), 0);
680}
681template <>
682EIGEN_STRONG_INLINE Packet8uc pset1<Packet8uc>(const uint8_t& from) {
683 return vdup_n_u8(from);
684}
685template <>
686EIGEN_STRONG_INLINE Packet16uc pset1<Packet16uc>(const uint8_t& from) {
687 return vdupq_n_u8(from);
688}
689template <>
690EIGEN_STRONG_INLINE Packet4s pset1<Packet4s>(const int16_t& from) {
691 return vdup_n_s16(from);
692}
693template <>
694EIGEN_STRONG_INLINE Packet8s pset1<Packet8s>(const int16_t& from) {
695 return vdupq_n_s16(from);
696}
697template <>
698EIGEN_STRONG_INLINE Packet4us pset1<Packet4us>(const uint16_t& from) {
699 return vdup_n_u16(from);
700}
701template <>
702EIGEN_STRONG_INLINE Packet8us pset1<Packet8us>(const uint16_t& from) {
703 return vdupq_n_u16(from);
704}
705template <>
706EIGEN_STRONG_INLINE Packet2i pset1<Packet2i>(const int32_t& from) {
707 return vdup_n_s32(from);
708}
709template <>
710EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int32_t& from) {
711 return vdupq_n_s32(from);
712}
713template <>
714EIGEN_STRONG_INLINE Packet2ui pset1<Packet2ui>(const uint32_t& from) {
715 return vdup_n_u32(from);
716}
717template <>
718EIGEN_STRONG_INLINE Packet4ui pset1<Packet4ui>(const uint32_t& from) {
719 return vdupq_n_u32(from);
720}
721template <>
722EIGEN_STRONG_INLINE Packet2l pset1<Packet2l>(const int64_t& from) {
723 return vdupq_n_s64(from);
724}
725template <>
726EIGEN_STRONG_INLINE Packet2ul pset1<Packet2ul>(const uint64_t& from) {
727 return vdupq_n_u64(from);
728}
729
730template <>
731EIGEN_STRONG_INLINE Packet2f pset1frombits<Packet2f>(uint32_t from) {
732 return vreinterpret_f32_u32(vdup_n_u32(from));
733}
734template <>
735EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(uint32_t from) {
736 return vreinterpretq_f32_u32(vdupq_n_u32(from));
737}
738
739template <>
740EIGEN_STRONG_INLINE Packet2f plset<Packet2f>(const float& a) {
741 const float c[] = {0.0f, 1.0f};
742 return vadd_f32(pset1<Packet2f>(a), vld1_f32(c));
743}
744template <>
745EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) {
746 const float c[] = {0.0f, 1.0f, 2.0f, 3.0f};
747 return vaddq_f32(pset1<Packet4f>(a), vld1q_f32(c));
748}
749template <>
750EIGEN_STRONG_INLINE Packet4c plset<Packet4c>(const int8_t& a) {
751 return vget_lane_s32(vreinterpret_s32_s8(vadd_s8(vreinterpret_s8_u32(vdup_n_u32(0x03020100)), vdup_n_s8(a))), 0);
752}
753template <>
754EIGEN_STRONG_INLINE Packet8c plset<Packet8c>(const int8_t& a) {
755 const int8_t c[] = {0, 1, 2, 3, 4, 5, 6, 7};
756 return vadd_s8(pset1<Packet8c>(a), vld1_s8(c));
757}
758template <>
759EIGEN_STRONG_INLINE Packet16c plset<Packet16c>(const int8_t& a) {
760 const int8_t c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
761 return vaddq_s8(pset1<Packet16c>(a), vld1q_s8(c));
762}
763template <>
764EIGEN_STRONG_INLINE Packet4uc plset<Packet4uc>(const uint8_t& a) {
765 return vget_lane_u32(vreinterpret_u32_u8(vadd_u8(vreinterpret_u8_u32(vdup_n_u32(0x03020100)), vdup_n_u8(a))), 0);
766}
767template <>
768EIGEN_STRONG_INLINE Packet8uc plset<Packet8uc>(const uint8_t& a) {
769 const uint8_t c[] = {0, 1, 2, 3, 4, 5, 6, 7};
770 return vadd_u8(pset1<Packet8uc>(a), vld1_u8(c));
771}
772template <>
773EIGEN_STRONG_INLINE Packet16uc plset<Packet16uc>(const uint8_t& a) {
774 const uint8_t c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
775 return vaddq_u8(pset1<Packet16uc>(a), vld1q_u8(c));
776}
777template <>
778EIGEN_STRONG_INLINE Packet4s plset<Packet4s>(const int16_t& a) {
779 const int16_t c[] = {0, 1, 2, 3};
780 return vadd_s16(pset1<Packet4s>(a), vld1_s16(c));
781}
782template <>
783EIGEN_STRONG_INLINE Packet4us plset<Packet4us>(const uint16_t& a) {
784 const uint16_t c[] = {0, 1, 2, 3};
785 return vadd_u16(pset1<Packet4us>(a), vld1_u16(c));
786}
787template <>
788EIGEN_STRONG_INLINE Packet8s plset<Packet8s>(const int16_t& a) {
789 const int16_t c[] = {0, 1, 2, 3, 4, 5, 6, 7};
790 return vaddq_s16(pset1<Packet8s>(a), vld1q_s16(c));
791}
792template <>
793EIGEN_STRONG_INLINE Packet8us plset<Packet8us>(const uint16_t& a) {
794 const uint16_t c[] = {0, 1, 2, 3, 4, 5, 6, 7};
795 return vaddq_u16(pset1<Packet8us>(a), vld1q_u16(c));
796}
797template <>
798EIGEN_STRONG_INLINE Packet2i plset<Packet2i>(const int32_t& a) {
799 const int32_t c[] = {0, 1};
800 return vadd_s32(pset1<Packet2i>(a), vld1_s32(c));
801}
802template <>
803EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int32_t& a) {
804 const int32_t c[] = {0, 1, 2, 3};
805 return vaddq_s32(pset1<Packet4i>(a), vld1q_s32(c));
806}
807template <>
808EIGEN_STRONG_INLINE Packet2ui plset<Packet2ui>(const uint32_t& a) {
809 const uint32_t c[] = {0, 1};
810 return vadd_u32(pset1<Packet2ui>(a), vld1_u32(c));
811}
812template <>
813EIGEN_STRONG_INLINE Packet4ui plset<Packet4ui>(const uint32_t& a) {
814 const uint32_t c[] = {0, 1, 2, 3};
815 return vaddq_u32(pset1<Packet4ui>(a), vld1q_u32(c));
816}
817template <>
818EIGEN_STRONG_INLINE Packet2l plset<Packet2l>(const int64_t& a) {
819 const int64_t c[] = {0, 1};
820 return vaddq_s64(pset1<Packet2l>(a), vld1q_s64(c));
821}
822template <>
823EIGEN_STRONG_INLINE Packet2ul plset<Packet2ul>(const uint64_t& a) {
824 const uint64_t c[] = {0, 1};
825 return vaddq_u64(pset1<Packet2ul>(a), vld1q_u64(c));
826}
827
828template <>
829EIGEN_STRONG_INLINE Packet2f padd<Packet2f>(const Packet2f& a, const Packet2f& b) {
830 return vadd_f32(a, b);
831}
832template <>
833EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) {
834 return vaddq_f32(a, b);
835}
836template <>
837EIGEN_STRONG_INLINE Packet4c padd<Packet4c>(const Packet4c& a, const Packet4c& b) {
838 return vget_lane_s32(
839 vreinterpret_s32_s8(vadd_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
840}
841template <>
842EIGEN_STRONG_INLINE Packet8c padd<Packet8c>(const Packet8c& a, const Packet8c& b) {
843 return vadd_s8(a, b);
844}
845template <>
846EIGEN_STRONG_INLINE Packet16c padd<Packet16c>(const Packet16c& a, const Packet16c& b) {
847 return vaddq_s8(a, b);
848}
849template <>
850EIGEN_STRONG_INLINE Packet4uc padd<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
851 return vget_lane_u32(
852 vreinterpret_u32_u8(vadd_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
853}
854template <>
855EIGEN_STRONG_INLINE Packet8uc padd<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
856 return vadd_u8(a, b);
857}
858template <>
859EIGEN_STRONG_INLINE Packet16uc padd<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
860 return vaddq_u8(a, b);
861}
862template <>
863EIGEN_STRONG_INLINE Packet4s padd<Packet4s>(const Packet4s& a, const Packet4s& b) {
864 return vadd_s16(a, b);
865}
866template <>
867EIGEN_STRONG_INLINE Packet8s padd<Packet8s>(const Packet8s& a, const Packet8s& b) {
868 return vaddq_s16(a, b);
869}
870template <>
871EIGEN_STRONG_INLINE Packet4us padd<Packet4us>(const Packet4us& a, const Packet4us& b) {
872 return vadd_u16(a, b);
873}
874template <>
875EIGEN_STRONG_INLINE Packet8us padd<Packet8us>(const Packet8us& a, const Packet8us& b) {
876 return vaddq_u16(a, b);
877}
878template <>
879EIGEN_STRONG_INLINE Packet2i padd<Packet2i>(const Packet2i& a, const Packet2i& b) {
880 return vadd_s32(a, b);
881}
882template <>
883EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) {
884 return vaddq_s32(a, b);
885}
886template <>
887EIGEN_STRONG_INLINE Packet2ui padd<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
888 return vadd_u32(a, b);
889}
890template <>
891EIGEN_STRONG_INLINE Packet4ui padd<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
892 return vaddq_u32(a, b);
893}
894template <>
895EIGEN_STRONG_INLINE Packet2l padd<Packet2l>(const Packet2l& a, const Packet2l& b) {
896 return vaddq_s64(a, b);
897}
898template <>
899EIGEN_STRONG_INLINE Packet2ul padd<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
900 return vaddq_u64(a, b);
901}
902
903template <>
904EIGEN_STRONG_INLINE Packet2f psub<Packet2f>(const Packet2f& a, const Packet2f& b) {
905 return vsub_f32(a, b);
906}
907template <>
908EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) {
909 return vsubq_f32(a, b);
910}
911template <>
912EIGEN_STRONG_INLINE Packet4c psub<Packet4c>(const Packet4c& a, const Packet4c& b) {
913 return vget_lane_s32(
914 vreinterpret_s32_s8(vsub_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
915}
916template <>
917EIGEN_STRONG_INLINE Packet8c psub<Packet8c>(const Packet8c& a, const Packet8c& b) {
918 return vsub_s8(a, b);
919}
920template <>
921EIGEN_STRONG_INLINE Packet16c psub<Packet16c>(const Packet16c& a, const Packet16c& b) {
922 return vsubq_s8(a, b);
923}
924template <>
925EIGEN_STRONG_INLINE Packet4uc psub<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
926 return vget_lane_u32(
927 vreinterpret_u32_u8(vsub_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
928}
929template <>
930EIGEN_STRONG_INLINE Packet8uc psub<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
931 return vsub_u8(a, b);
932}
933template <>
934EIGEN_STRONG_INLINE Packet16uc psub<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
935 return vsubq_u8(a, b);
936}
937template <>
938EIGEN_STRONG_INLINE Packet4s psub<Packet4s>(const Packet4s& a, const Packet4s& b) {
939 return vsub_s16(a, b);
940}
941template <>
942EIGEN_STRONG_INLINE Packet8s psub<Packet8s>(const Packet8s& a, const Packet8s& b) {
943 return vsubq_s16(a, b);
944}
945template <>
946EIGEN_STRONG_INLINE Packet4us psub<Packet4us>(const Packet4us& a, const Packet4us& b) {
947 return vsub_u16(a, b);
948}
949template <>
950EIGEN_STRONG_INLINE Packet8us psub<Packet8us>(const Packet8us& a, const Packet8us& b) {
951 return vsubq_u16(a, b);
952}
953template <>
954EIGEN_STRONG_INLINE Packet2i psub<Packet2i>(const Packet2i& a, const Packet2i& b) {
955 return vsub_s32(a, b);
956}
957template <>
958EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) {
959 return vsubq_s32(a, b);
960}
961template <>
962EIGEN_STRONG_INLINE Packet2ui psub<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
963 return vsub_u32(a, b);
964}
965template <>
966EIGEN_STRONG_INLINE Packet4ui psub<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
967 return vsubq_u32(a, b);
968}
969template <>
970EIGEN_STRONG_INLINE Packet2l psub<Packet2l>(const Packet2l& a, const Packet2l& b) {
971 return vsubq_s64(a, b);
972}
973template <>
974EIGEN_STRONG_INLINE Packet2ul psub<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
975 return vsubq_u64(a, b);
976}
977
978template <>
979EIGEN_STRONG_INLINE Packet2f pxor<Packet2f>(const Packet2f& a, const Packet2f& b);
980template <>
981EIGEN_STRONG_INLINE Packet2f paddsub<Packet2f>(const Packet2f& a, const Packet2f& b) {
982 Packet2f mask = make_packet2f(numext::bit_cast<float>(0x80000000u), 0.0f);
983 return padd(a, pxor(mask, b));
984}
985template <>
986EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b);
987template <>
988EIGEN_STRONG_INLINE Packet4f paddsub<Packet4f>(const Packet4f& a, const Packet4f& b) {
989 Packet4f mask = make_packet4f(numext::bit_cast<float>(0x80000000u), 0.0f, numext::bit_cast<float>(0x80000000u), 0.0f);
990 return padd(a, pxor(mask, b));
991}
992
993template <>
994EIGEN_STRONG_INLINE Packet2f pnegate(const Packet2f& a) {
995 return vneg_f32(a);
996}
997template <>
998EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) {
999 return vnegq_f32(a);
1000}
1001template <>
1002EIGEN_STRONG_INLINE Packet4c pnegate(const Packet4c& a) {
1003 return vget_lane_s32(vreinterpret_s32_s8(vneg_s8(vreinterpret_s8_s32(vdup_n_s32(a)))), 0);
1004}
1005template <>
1006EIGEN_STRONG_INLINE Packet8c pnegate(const Packet8c& a) {
1007 return vneg_s8(a);
1008}
1009template <>
1010EIGEN_STRONG_INLINE Packet16c pnegate(const Packet16c& a) {
1011 return vnegq_s8(a);
1012}
1013template <>
1014EIGEN_STRONG_INLINE Packet4s pnegate(const Packet4s& a) {
1015 return vneg_s16(a);
1016}
1017template <>
1018EIGEN_STRONG_INLINE Packet8s pnegate(const Packet8s& a) {
1019 return vnegq_s16(a);
1020}
1021template <>
1022EIGEN_STRONG_INLINE Packet2i pnegate(const Packet2i& a) {
1023 return vneg_s32(a);
1024}
1025template <>
1026EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) {
1027 return vnegq_s32(a);
1028}
1029template <>
1030EIGEN_STRONG_INLINE Packet2l pnegate(const Packet2l& a) {
1031#if EIGEN_ARCH_ARM64
1032 return vnegq_s64(a);
1033#else
1034 return vcombine_s64(vdup_n_s64(-vgetq_lane_s64(a, 0)), vdup_n_s64(-vgetq_lane_s64(a, 1)));
1035#endif
1036}
1037
1038template <>
1039EIGEN_STRONG_INLINE Packet2f pconj(const Packet2f& a) {
1040 return a;
1041}
1042template <>
1043EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) {
1044 return a;
1045}
1046template <>
1047EIGEN_STRONG_INLINE Packet4c pconj(const Packet4c& a) {
1048 return a;
1049}
1050template <>
1051EIGEN_STRONG_INLINE Packet8c pconj(const Packet8c& a) {
1052 return a;
1053}
1054template <>
1055EIGEN_STRONG_INLINE Packet16c pconj(const Packet16c& a) {
1056 return a;
1057}
1058template <>
1059EIGEN_STRONG_INLINE Packet4uc pconj(const Packet4uc& a) {
1060 return a;
1061}
1062template <>
1063EIGEN_STRONG_INLINE Packet8uc pconj(const Packet8uc& a) {
1064 return a;
1065}
1066template <>
1067EIGEN_STRONG_INLINE Packet16uc pconj(const Packet16uc& a) {
1068 return a;
1069}
1070template <>
1071EIGEN_STRONG_INLINE Packet4s pconj(const Packet4s& a) {
1072 return a;
1073}
1074template <>
1075EIGEN_STRONG_INLINE Packet8s pconj(const Packet8s& a) {
1076 return a;
1077}
1078template <>
1079EIGEN_STRONG_INLINE Packet4us pconj(const Packet4us& a) {
1080 return a;
1081}
1082template <>
1083EIGEN_STRONG_INLINE Packet8us pconj(const Packet8us& a) {
1084 return a;
1085}
1086template <>
1087EIGEN_STRONG_INLINE Packet2i pconj(const Packet2i& a) {
1088 return a;
1089}
1090template <>
1091EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) {
1092 return a;
1093}
1094template <>
1095EIGEN_STRONG_INLINE Packet2ui pconj(const Packet2ui& a) {
1096 return a;
1097}
1098template <>
1099EIGEN_STRONG_INLINE Packet4ui pconj(const Packet4ui& a) {
1100 return a;
1101}
1102template <>
1103EIGEN_STRONG_INLINE Packet2l pconj(const Packet2l& a) {
1104 return a;
1105}
1106template <>
1107EIGEN_STRONG_INLINE Packet2ul pconj(const Packet2ul& a) {
1108 return a;
1109}
1110
1111template <>
1112EIGEN_STRONG_INLINE Packet2f pmul<Packet2f>(const Packet2f& a, const Packet2f& b) {
1113 return vmul_f32(a, b);
1114}
1115template <>
1116EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) {
1117 return vmulq_f32(a, b);
1118}
1119template <>
1120EIGEN_STRONG_INLINE Packet4c pmul<Packet4c>(const Packet4c& a, const Packet4c& b) {
1121 return vget_lane_s32(
1122 vreinterpret_s32_s8(vmul_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1123}
1124template <>
1125EIGEN_STRONG_INLINE Packet8c pmul<Packet8c>(const Packet8c& a, const Packet8c& b) {
1126 return vmul_s8(a, b);
1127}
1128template <>
1129EIGEN_STRONG_INLINE Packet16c pmul<Packet16c>(const Packet16c& a, const Packet16c& b) {
1130 return vmulq_s8(a, b);
1131}
1132template <>
1133EIGEN_STRONG_INLINE Packet4uc pmul<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1134 return vget_lane_u32(
1135 vreinterpret_u32_u8(vmul_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1136}
1137template <>
1138EIGEN_STRONG_INLINE Packet8uc pmul<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1139 return vmul_u8(a, b);
1140}
1141template <>
1142EIGEN_STRONG_INLINE Packet16uc pmul<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1143 return vmulq_u8(a, b);
1144}
1145template <>
1146EIGEN_STRONG_INLINE Packet4s pmul<Packet4s>(const Packet4s& a, const Packet4s& b) {
1147 return vmul_s16(a, b);
1148}
1149template <>
1150EIGEN_STRONG_INLINE Packet8s pmul<Packet8s>(const Packet8s& a, const Packet8s& b) {
1151 return vmulq_s16(a, b);
1152}
1153template <>
1154EIGEN_STRONG_INLINE Packet4us pmul<Packet4us>(const Packet4us& a, const Packet4us& b) {
1155 return vmul_u16(a, b);
1156}
1157template <>
1158EIGEN_STRONG_INLINE Packet8us pmul<Packet8us>(const Packet8us& a, const Packet8us& b) {
1159 return vmulq_u16(a, b);
1160}
1161template <>
1162EIGEN_STRONG_INLINE Packet2i pmul<Packet2i>(const Packet2i& a, const Packet2i& b) {
1163 return vmul_s32(a, b);
1164}
1165template <>
1166EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) {
1167 return vmulq_s32(a, b);
1168}
1169template <>
1170EIGEN_STRONG_INLINE Packet2ui pmul<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1171 return vmul_u32(a, b);
1172}
1173template <>
1174EIGEN_STRONG_INLINE Packet4ui pmul<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1175 return vmulq_u32(a, b);
1176}
1177template <>
1178EIGEN_STRONG_INLINE Packet2l pmul<Packet2l>(const Packet2l& a, const Packet2l& b) {
1179 return vcombine_s64(vdup_n_s64(vgetq_lane_s64(a, 0) * vgetq_lane_s64(b, 0)),
1180 vdup_n_s64(vgetq_lane_s64(a, 1) * vgetq_lane_s64(b, 1)));
1181}
1182template <>
1183EIGEN_STRONG_INLINE Packet2ul pmul<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1184 return vcombine_u64(vdup_n_u64(vgetq_lane_u64(a, 0) * vgetq_lane_u64(b, 0)),
1185 vdup_n_u64(vgetq_lane_u64(a, 1) * vgetq_lane_u64(b, 1)));
1186}
1187
1188template <>
1189EIGEN_STRONG_INLINE Packet4c pdiv<Packet4c>(const Packet4c& /*a*/, const Packet4c& /*b*/) {
1190 eigen_assert(false && "packet integer division are not supported by NEON");
1191 return pset1<Packet4c>(0);
1192}
1193template <>
1194EIGEN_STRONG_INLINE Packet8c pdiv<Packet8c>(const Packet8c& /*a*/, const Packet8c& /*b*/) {
1195 eigen_assert(false && "packet integer division are not supported by NEON");
1196 return pset1<Packet8c>(0);
1197}
1198template <>
1199EIGEN_STRONG_INLINE Packet16c pdiv<Packet16c>(const Packet16c& /*a*/, const Packet16c& /*b*/) {
1200 eigen_assert(false && "packet integer division are not supported by NEON");
1201 return pset1<Packet16c>(0);
1202}
1203template <>
1204EIGEN_STRONG_INLINE Packet4uc pdiv<Packet4uc>(const Packet4uc& /*a*/, const Packet4uc& /*b*/) {
1205 eigen_assert(false && "packet integer division are not supported by NEON");
1206 return pset1<Packet4uc>(0);
1207}
1208template <>
1209EIGEN_STRONG_INLINE Packet8uc pdiv<Packet8uc>(const Packet8uc& /*a*/, const Packet8uc& /*b*/) {
1210 eigen_assert(false && "packet integer division are not supported by NEON");
1211 return pset1<Packet8uc>(0);
1212}
1213template <>
1214EIGEN_STRONG_INLINE Packet16uc pdiv<Packet16uc>(const Packet16uc& /*a*/, const Packet16uc& /*b*/) {
1215 eigen_assert(false && "packet integer division are not supported by NEON");
1216 return pset1<Packet16uc>(0);
1217}
1218template <>
1219EIGEN_STRONG_INLINE Packet4s pdiv<Packet4s>(const Packet4s& /*a*/, const Packet4s& /*b*/) {
1220 eigen_assert(false && "packet integer division are not supported by NEON");
1221 return pset1<Packet4s>(0);
1222}
1223template <>
1224EIGEN_STRONG_INLINE Packet8s pdiv<Packet8s>(const Packet8s& /*a*/, const Packet8s& /*b*/) {
1225 eigen_assert(false && "packet integer division are not supported by NEON");
1226 return pset1<Packet8s>(0);
1227}
1228template <>
1229EIGEN_STRONG_INLINE Packet4us pdiv<Packet4us>(const Packet4us& /*a*/, const Packet4us& /*b*/) {
1230 eigen_assert(false && "packet integer division are not supported by NEON");
1231 return pset1<Packet4us>(0);
1232}
1233template <>
1234EIGEN_STRONG_INLINE Packet8us pdiv<Packet8us>(const Packet8us& /*a*/, const Packet8us& /*b*/) {
1235 eigen_assert(false && "packet integer division are not supported by NEON");
1236 return pset1<Packet8us>(0);
1237}
1238template <>
1239EIGEN_STRONG_INLINE Packet2i pdiv<Packet2i>(const Packet2i& /*a*/, const Packet2i& /*b*/) {
1240 eigen_assert(false && "packet integer division are not supported by NEON");
1241 return pset1<Packet2i>(0);
1242}
1243template <>
1244EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/) {
1245 eigen_assert(false && "packet integer division are not supported by NEON");
1246 return pset1<Packet4i>(0);
1247}
1248template <>
1249EIGEN_STRONG_INLINE Packet2ui pdiv<Packet2ui>(const Packet2ui& /*a*/, const Packet2ui& /*b*/) {
1250 eigen_assert(false && "packet integer division are not supported by NEON");
1251 return pset1<Packet2ui>(0);
1252}
1253template <>
1254EIGEN_STRONG_INLINE Packet4ui pdiv<Packet4ui>(const Packet4ui& /*a*/, const Packet4ui& /*b*/) {
1255 eigen_assert(false && "packet integer division are not supported by NEON");
1256 return pset1<Packet4ui>(0);
1257}
1258template <>
1259EIGEN_STRONG_INLINE Packet2l pdiv<Packet2l>(const Packet2l& /*a*/, const Packet2l& /*b*/) {
1260 eigen_assert(false && "packet integer division are not supported by NEON");
1261 return pset1<Packet2l>(0LL);
1262}
1263template <>
1264EIGEN_STRONG_INLINE Packet2ul pdiv<Packet2ul>(const Packet2ul& /*a*/, const Packet2ul& /*b*/) {
1265 eigen_assert(false && "packet integer division are not supported by NEON");
1266 return pset1<Packet2ul>(0ULL);
1267}
1268
1269#ifdef EIGEN_VECTORIZE_FMA
1270template <>
1271EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) {
1272 return vfmaq_f32(c, a, b);
1273}
1274template <>
1275EIGEN_STRONG_INLINE Packet2f pmadd(const Packet2f& a, const Packet2f& b, const Packet2f& c) {
1276 return vfma_f32(c, a, b);
1277}
1278#else
1279template <>
1280EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) {
1281 return vmlaq_f32(c, a, b);
1282}
1283template <>
1284EIGEN_STRONG_INLINE Packet2f pmadd(const Packet2f& a, const Packet2f& b, const Packet2f& c) {
1285 return vmla_f32(c, a, b);
1286}
1287#endif
1288
1289// No FMA instruction for int, so use MLA unconditionally.
1290template <>
1291EIGEN_STRONG_INLINE Packet4c pmadd(const Packet4c& a, const Packet4c& b, const Packet4c& c) {
1292 return vget_lane_s32(
1293 vreinterpret_s32_s8(vmla_s8(vreinterpret_s8_s32(vdup_n_s32(c)), vreinterpret_s8_s32(vdup_n_s32(a)),
1294 vreinterpret_s8_s32(vdup_n_s32(b)))),
1295 0);
1296}
1297template <>
1298EIGEN_STRONG_INLINE Packet8c pmadd(const Packet8c& a, const Packet8c& b, const Packet8c& c) {
1299 return vmla_s8(c, a, b);
1300}
1301template <>
1302EIGEN_STRONG_INLINE Packet16c pmadd(const Packet16c& a, const Packet16c& b, const Packet16c& c) {
1303 return vmlaq_s8(c, a, b);
1304}
1305template <>
1306EIGEN_STRONG_INLINE Packet4uc pmadd(const Packet4uc& a, const Packet4uc& b, const Packet4uc& c) {
1307 return vget_lane_u32(
1308 vreinterpret_u32_u8(vmla_u8(vreinterpret_u8_u32(vdup_n_u32(c)), vreinterpret_u8_u32(vdup_n_u32(a)),
1309 vreinterpret_u8_u32(vdup_n_u32(b)))),
1310 0);
1311}
1312template <>
1313EIGEN_STRONG_INLINE Packet8uc pmadd(const Packet8uc& a, const Packet8uc& b, const Packet8uc& c) {
1314 return vmla_u8(c, a, b);
1315}
1316template <>
1317EIGEN_STRONG_INLINE Packet16uc pmadd(const Packet16uc& a, const Packet16uc& b, const Packet16uc& c) {
1318 return vmlaq_u8(c, a, b);
1319}
1320template <>
1321EIGEN_STRONG_INLINE Packet4s pmadd(const Packet4s& a, const Packet4s& b, const Packet4s& c) {
1322 return vmla_s16(c, a, b);
1323}
1324template <>
1325EIGEN_STRONG_INLINE Packet8s pmadd(const Packet8s& a, const Packet8s& b, const Packet8s& c) {
1326 return vmlaq_s16(c, a, b);
1327}
1328template <>
1329EIGEN_STRONG_INLINE Packet4us pmadd(const Packet4us& a, const Packet4us& b, const Packet4us& c) {
1330 return vmla_u16(c, a, b);
1331}
1332template <>
1333EIGEN_STRONG_INLINE Packet8us pmadd(const Packet8us& a, const Packet8us& b, const Packet8us& c) {
1334 return vmlaq_u16(c, a, b);
1335}
1336template <>
1337EIGEN_STRONG_INLINE Packet2i pmadd(const Packet2i& a, const Packet2i& b, const Packet2i& c) {
1338 return vmla_s32(c, a, b);
1339}
1340template <>
1341EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) {
1342 return vmlaq_s32(c, a, b);
1343}
1344template <>
1345EIGEN_STRONG_INLINE Packet2ui pmadd(const Packet2ui& a, const Packet2ui& b, const Packet2ui& c) {
1346 return vmla_u32(c, a, b);
1347}
1348template <>
1349EIGEN_STRONG_INLINE Packet4ui pmadd(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c) {
1350 return vmlaq_u32(c, a, b);
1351}
1352
1353template <>
1354EIGEN_STRONG_INLINE Packet2f pabsdiff<Packet2f>(const Packet2f& a, const Packet2f& b) {
1355 return vabd_f32(a, b);
1356}
1357template <>
1358EIGEN_STRONG_INLINE Packet4f pabsdiff<Packet4f>(const Packet4f& a, const Packet4f& b) {
1359 return vabdq_f32(a, b);
1360}
1361template <>
1362EIGEN_STRONG_INLINE Packet4c pabsdiff<Packet4c>(const Packet4c& a, const Packet4c& b) {
1363 return vget_lane_s32(
1364 vreinterpret_s32_s8(vabd_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1365}
1366template <>
1367EIGEN_STRONG_INLINE Packet8c pabsdiff<Packet8c>(const Packet8c& a, const Packet8c& b) {
1368 return vabd_s8(a, b);
1369}
1370template <>
1371EIGEN_STRONG_INLINE Packet16c pabsdiff<Packet16c>(const Packet16c& a, const Packet16c& b) {
1372 return vabdq_s8(a, b);
1373}
1374template <>
1375EIGEN_STRONG_INLINE Packet4uc pabsdiff<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1376 return vget_lane_u32(
1377 vreinterpret_u32_u8(vabd_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1378}
1379template <>
1380EIGEN_STRONG_INLINE Packet8uc pabsdiff<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1381 return vabd_u8(a, b);
1382}
1383template <>
1384EIGEN_STRONG_INLINE Packet16uc pabsdiff<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1385 return vabdq_u8(a, b);
1386}
1387template <>
1388EIGEN_STRONG_INLINE Packet4s pabsdiff<Packet4s>(const Packet4s& a, const Packet4s& b) {
1389 return vabd_s16(a, b);
1390}
1391template <>
1392EIGEN_STRONG_INLINE Packet8s pabsdiff<Packet8s>(const Packet8s& a, const Packet8s& b) {
1393 return vabdq_s16(a, b);
1394}
1395template <>
1396EIGEN_STRONG_INLINE Packet4us pabsdiff<Packet4us>(const Packet4us& a, const Packet4us& b) {
1397 return vabd_u16(a, b);
1398}
1399template <>
1400EIGEN_STRONG_INLINE Packet8us pabsdiff<Packet8us>(const Packet8us& a, const Packet8us& b) {
1401 return vabdq_u16(a, b);
1402}
1403template <>
1404EIGEN_STRONG_INLINE Packet2i pabsdiff<Packet2i>(const Packet2i& a, const Packet2i& b) {
1405 return vabd_s32(a, b);
1406}
1407template <>
1408EIGEN_STRONG_INLINE Packet4i pabsdiff<Packet4i>(const Packet4i& a, const Packet4i& b) {
1409 return vabdq_s32(a, b);
1410}
1411template <>
1412EIGEN_STRONG_INLINE Packet2ui pabsdiff<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1413 return vabd_u32(a, b);
1414}
1415template <>
1416EIGEN_STRONG_INLINE Packet4ui pabsdiff<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1417 return vabdq_u32(a, b);
1418}
1419
1420template <>
1421EIGEN_STRONG_INLINE Packet2f pmin<Packet2f>(const Packet2f& a, const Packet2f& b) {
1422 return vmin_f32(a, b);
1423}
1424template <>
1425EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) {
1426 return vminq_f32(a, b);
1427}
1428
1429#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
1430// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8
1431// systems).
1432template <>
1433EIGEN_STRONG_INLINE Packet4f pmin<PropagateNumbers, Packet4f>(const Packet4f& a, const Packet4f& b) {
1434 return vminnmq_f32(a, b);
1435}
1436template <>
1437EIGEN_STRONG_INLINE Packet2f pmin<PropagateNumbers, Packet2f>(const Packet2f& a, const Packet2f& b) {
1438 return vminnm_f32(a, b);
1439}
1440#endif
1441
1442template <>
1443EIGEN_STRONG_INLINE Packet4f pmin<PropagateNaN, Packet4f>(const Packet4f& a, const Packet4f& b) {
1444 return pmin<Packet4f>(a, b);
1445}
1446
1447template <>
1448EIGEN_STRONG_INLINE Packet2f pmin<PropagateNaN, Packet2f>(const Packet2f& a, const Packet2f& b) {
1449 return pmin<Packet2f>(a, b);
1450}
1451
1452template <>
1453EIGEN_STRONG_INLINE Packet4c pmin<Packet4c>(const Packet4c& a, const Packet4c& b) {
1454 return vget_lane_s32(
1455 vreinterpret_s32_s8(vmin_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1456}
1457template <>
1458EIGEN_STRONG_INLINE Packet8c pmin<Packet8c>(const Packet8c& a, const Packet8c& b) {
1459 return vmin_s8(a, b);
1460}
1461template <>
1462EIGEN_STRONG_INLINE Packet16c pmin<Packet16c>(const Packet16c& a, const Packet16c& b) {
1463 return vminq_s8(a, b);
1464}
1465template <>
1466EIGEN_STRONG_INLINE Packet4uc pmin<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1467 return vget_lane_u32(
1468 vreinterpret_u32_u8(vmin_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1469}
1470template <>
1471EIGEN_STRONG_INLINE Packet8uc pmin<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1472 return vmin_u8(a, b);
1473}
1474template <>
1475EIGEN_STRONG_INLINE Packet16uc pmin<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1476 return vminq_u8(a, b);
1477}
1478template <>
1479EIGEN_STRONG_INLINE Packet4s pmin<Packet4s>(const Packet4s& a, const Packet4s& b) {
1480 return vmin_s16(a, b);
1481}
1482template <>
1483EIGEN_STRONG_INLINE Packet8s pmin<Packet8s>(const Packet8s& a, const Packet8s& b) {
1484 return vminq_s16(a, b);
1485}
1486template <>
1487EIGEN_STRONG_INLINE Packet4us pmin<Packet4us>(const Packet4us& a, const Packet4us& b) {
1488 return vmin_u16(a, b);
1489}
1490template <>
1491EIGEN_STRONG_INLINE Packet8us pmin<Packet8us>(const Packet8us& a, const Packet8us& b) {
1492 return vminq_u16(a, b);
1493}
1494template <>
1495EIGEN_STRONG_INLINE Packet2i pmin<Packet2i>(const Packet2i& a, const Packet2i& b) {
1496 return vmin_s32(a, b);
1497}
1498template <>
1499EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) {
1500 return vminq_s32(a, b);
1501}
1502template <>
1503EIGEN_STRONG_INLINE Packet2ui pmin<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1504 return vmin_u32(a, b);
1505}
1506template <>
1507EIGEN_STRONG_INLINE Packet4ui pmin<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1508 return vminq_u32(a, b);
1509}
1510template <>
1511EIGEN_STRONG_INLINE Packet2l pmin<Packet2l>(const Packet2l& a, const Packet2l& b) {
1512 return vcombine_s64(vdup_n_s64((std::min)(vgetq_lane_s64(a, 0), vgetq_lane_s64(b, 0))),
1513 vdup_n_s64((std::min)(vgetq_lane_s64(a, 1), vgetq_lane_s64(b, 1))));
1514}
1515template <>
1516EIGEN_STRONG_INLINE Packet2ul pmin<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1517 return vcombine_u64(vdup_n_u64((std::min)(vgetq_lane_u64(a, 0), vgetq_lane_u64(b, 0))),
1518 vdup_n_u64((std::min)(vgetq_lane_u64(a, 1), vgetq_lane_u64(b, 1))));
1519}
1520
1521template <>
1522EIGEN_STRONG_INLINE Packet2f pmax<Packet2f>(const Packet2f& a, const Packet2f& b) {
1523 return vmax_f32(a, b);
1524}
1525template <>
1526EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) {
1527 return vmaxq_f32(a, b);
1528}
1529
1530#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
1531// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8
1532// systems).
1533template <>
1534EIGEN_STRONG_INLINE Packet4f pmax<PropagateNumbers, Packet4f>(const Packet4f& a, const Packet4f& b) {
1535 return vmaxnmq_f32(a, b);
1536}
1537template <>
1538EIGEN_STRONG_INLINE Packet2f pmax<PropagateNumbers, Packet2f>(const Packet2f& a, const Packet2f& b) {
1539 return vmaxnm_f32(a, b);
1540}
1541#endif
1542
1543template <>
1544EIGEN_STRONG_INLINE Packet4f pmax<PropagateNaN, Packet4f>(const Packet4f& a, const Packet4f& b) {
1545 return pmax<Packet4f>(a, b);
1546}
1547
1548template <>
1549EIGEN_STRONG_INLINE Packet2f pmax<PropagateNaN, Packet2f>(const Packet2f& a, const Packet2f& b) {
1550 return pmax<Packet2f>(a, b);
1551}
1552
1553template <>
1554EIGEN_STRONG_INLINE Packet4c pmax<Packet4c>(const Packet4c& a, const Packet4c& b) {
1555 return vget_lane_s32(
1556 vreinterpret_s32_s8(vmax_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1557}
1558template <>
1559EIGEN_STRONG_INLINE Packet8c pmax<Packet8c>(const Packet8c& a, const Packet8c& b) {
1560 return vmax_s8(a, b);
1561}
1562template <>
1563EIGEN_STRONG_INLINE Packet16c pmax<Packet16c>(const Packet16c& a, const Packet16c& b) {
1564 return vmaxq_s8(a, b);
1565}
1566template <>
1567EIGEN_STRONG_INLINE Packet4uc pmax<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1568 return vget_lane_u32(
1569 vreinterpret_u32_u8(vmax_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1570}
1571template <>
1572EIGEN_STRONG_INLINE Packet8uc pmax<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1573 return vmax_u8(a, b);
1574}
1575template <>
1576EIGEN_STRONG_INLINE Packet16uc pmax<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1577 return vmaxq_u8(a, b);
1578}
1579template <>
1580EIGEN_STRONG_INLINE Packet4s pmax<Packet4s>(const Packet4s& a, const Packet4s& b) {
1581 return vmax_s16(a, b);
1582}
1583template <>
1584EIGEN_STRONG_INLINE Packet8s pmax<Packet8s>(const Packet8s& a, const Packet8s& b) {
1585 return vmaxq_s16(a, b);
1586}
1587template <>
1588EIGEN_STRONG_INLINE Packet4us pmax<Packet4us>(const Packet4us& a, const Packet4us& b) {
1589 return vmax_u16(a, b);
1590}
1591template <>
1592EIGEN_STRONG_INLINE Packet8us pmax<Packet8us>(const Packet8us& a, const Packet8us& b) {
1593 return vmaxq_u16(a, b);
1594}
1595template <>
1596EIGEN_STRONG_INLINE Packet2i pmax<Packet2i>(const Packet2i& a, const Packet2i& b) {
1597 return vmax_s32(a, b);
1598}
1599template <>
1600EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) {
1601 return vmaxq_s32(a, b);
1602}
1603template <>
1604EIGEN_STRONG_INLINE Packet2ui pmax<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1605 return vmax_u32(a, b);
1606}
1607template <>
1608EIGEN_STRONG_INLINE Packet4ui pmax<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1609 return vmaxq_u32(a, b);
1610}
1611template <>
1612EIGEN_STRONG_INLINE Packet2l pmax<Packet2l>(const Packet2l& a, const Packet2l& b) {
1613 return vcombine_s64(vdup_n_s64((std::max)(vgetq_lane_s64(a, 0), vgetq_lane_s64(b, 0))),
1614 vdup_n_s64((std::max)(vgetq_lane_s64(a, 1), vgetq_lane_s64(b, 1))));
1615}
1616template <>
1617EIGEN_STRONG_INLINE Packet2ul pmax<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1618 return vcombine_u64(vdup_n_u64((std::max)(vgetq_lane_u64(a, 0), vgetq_lane_u64(b, 0))),
1619 vdup_n_u64((std::max)(vgetq_lane_u64(a, 1), vgetq_lane_u64(b, 1))));
1620}
1621
1622template <>
1623EIGEN_STRONG_INLINE Packet2f pcmp_le<Packet2f>(const Packet2f& a, const Packet2f& b) {
1624 return vreinterpret_f32_u32(vcle_f32(a, b));
1625}
1626template <>
1627EIGEN_STRONG_INLINE Packet4f pcmp_le<Packet4f>(const Packet4f& a, const Packet4f& b) {
1628 return vreinterpretq_f32_u32(vcleq_f32(a, b));
1629}
1630template <>
1631EIGEN_STRONG_INLINE Packet4c pcmp_le<Packet4c>(const Packet4c& a, const Packet4c& b) {
1632 return vget_lane_s32(
1633 vreinterpret_s32_u8(vcle_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1634}
1635template <>
1636EIGEN_STRONG_INLINE Packet8c pcmp_le<Packet8c>(const Packet8c& a, const Packet8c& b) {
1637 return vreinterpret_s8_u8(vcle_s8(a, b));
1638}
1639template <>
1640EIGEN_STRONG_INLINE Packet16c pcmp_le<Packet16c>(const Packet16c& a, const Packet16c& b) {
1641 return vreinterpretq_s8_u8(vcleq_s8(a, b));
1642}
1643template <>
1644EIGEN_STRONG_INLINE Packet4uc pcmp_le<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1645 return vget_lane_u32(
1646 vreinterpret_u32_u8(vcle_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1647}
1648template <>
1649EIGEN_STRONG_INLINE Packet8uc pcmp_le<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1650 return vcle_u8(a, b);
1651}
1652template <>
1653EIGEN_STRONG_INLINE Packet16uc pcmp_le<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1654 return vcleq_u8(a, b);
1655}
1656template <>
1657EIGEN_STRONG_INLINE Packet4s pcmp_le<Packet4s>(const Packet4s& a, const Packet4s& b) {
1658 return vreinterpret_s16_u16(vcle_s16(a, b));
1659}
1660template <>
1661EIGEN_STRONG_INLINE Packet8s pcmp_le<Packet8s>(const Packet8s& a, const Packet8s& b) {
1662 return vreinterpretq_s16_u16(vcleq_s16(a, b));
1663}
1664template <>
1665EIGEN_STRONG_INLINE Packet4us pcmp_le<Packet4us>(const Packet4us& a, const Packet4us& b) {
1666 return vcle_u16(a, b);
1667}
1668template <>
1669EIGEN_STRONG_INLINE Packet8us pcmp_le<Packet8us>(const Packet8us& a, const Packet8us& b) {
1670 return vcleq_u16(a, b);
1671}
1672template <>
1673EIGEN_STRONG_INLINE Packet2i pcmp_le<Packet2i>(const Packet2i& a, const Packet2i& b) {
1674 return vreinterpret_s32_u32(vcle_s32(a, b));
1675}
1676template <>
1677EIGEN_STRONG_INLINE Packet4i pcmp_le<Packet4i>(const Packet4i& a, const Packet4i& b) {
1678 return vreinterpretq_s32_u32(vcleq_s32(a, b));
1679}
1680template <>
1681EIGEN_STRONG_INLINE Packet2ui pcmp_le<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1682 return vcle_u32(a, b);
1683}
1684template <>
1685EIGEN_STRONG_INLINE Packet4ui pcmp_le<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1686 return vcleq_u32(a, b);
1687}
1688template <>
1689EIGEN_STRONG_INLINE Packet2l pcmp_le<Packet2l>(const Packet2l& a, const Packet2l& b) {
1690#if EIGEN_ARCH_ARM64
1691 return vreinterpretq_s64_u64(vcleq_s64(a, b));
1692#else
1693 return vcombine_s64(vdup_n_s64(vgetq_lane_s64(a, 0) <= vgetq_lane_s64(b, 0) ? numext::int64_t(-1) : 0),
1694 vdup_n_s64(vgetq_lane_s64(a, 1) <= vgetq_lane_s64(b, 1) ? numext::int64_t(-1) : 0));
1695#endif
1696}
1697template <>
1698EIGEN_STRONG_INLINE Packet2ul pcmp_le<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1699#if EIGEN_ARCH_ARM64
1700 return vcleq_u64(a, b);
1701#else
1702 return vcombine_u64(vdup_n_u64(vgetq_lane_u64(a, 0) <= vgetq_lane_u64(b, 0) ? numext::uint64_t(-1) : 0),
1703 vdup_n_u64(vgetq_lane_u64(a, 1) <= vgetq_lane_u64(b, 1) ? numext::uint64_t(-1) : 0));
1704#endif
1705}
1706
1707template <>
1708EIGEN_STRONG_INLINE Packet2f pcmp_lt<Packet2f>(const Packet2f& a, const Packet2f& b) {
1709 return vreinterpret_f32_u32(vclt_f32(a, b));
1710}
1711template <>
1712EIGEN_STRONG_INLINE Packet4f pcmp_lt<Packet4f>(const Packet4f& a, const Packet4f& b) {
1713 return vreinterpretq_f32_u32(vcltq_f32(a, b));
1714}
1715template <>
1716EIGEN_STRONG_INLINE Packet4c pcmp_lt<Packet4c>(const Packet4c& a, const Packet4c& b) {
1717 return vget_lane_s32(
1718 vreinterpret_s32_u8(vclt_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1719}
1720template <>
1721EIGEN_STRONG_INLINE Packet8c pcmp_lt<Packet8c>(const Packet8c& a, const Packet8c& b) {
1722 return vreinterpret_s8_u8(vclt_s8(a, b));
1723}
1724template <>
1725EIGEN_STRONG_INLINE Packet16c pcmp_lt<Packet16c>(const Packet16c& a, const Packet16c& b) {
1726 return vreinterpretq_s8_u8(vcltq_s8(a, b));
1727}
1728template <>
1729EIGEN_STRONG_INLINE Packet4uc pcmp_lt<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1730 return vget_lane_u32(
1731 vreinterpret_u32_u8(vclt_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1732}
1733template <>
1734EIGEN_STRONG_INLINE Packet8uc pcmp_lt<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1735 return vclt_u8(a, b);
1736}
1737template <>
1738EIGEN_STRONG_INLINE Packet16uc pcmp_lt<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1739 return vcltq_u8(a, b);
1740}
1741template <>
1742EIGEN_STRONG_INLINE Packet4s pcmp_lt<Packet4s>(const Packet4s& a, const Packet4s& b) {
1743 return vreinterpret_s16_u16(vclt_s16(a, b));
1744}
1745template <>
1746EIGEN_STRONG_INLINE Packet8s pcmp_lt<Packet8s>(const Packet8s& a, const Packet8s& b) {
1747 return vreinterpretq_s16_u16(vcltq_s16(a, b));
1748}
1749template <>
1750EIGEN_STRONG_INLINE Packet4us pcmp_lt<Packet4us>(const Packet4us& a, const Packet4us& b) {
1751 return vclt_u16(a, b);
1752}
1753template <>
1754EIGEN_STRONG_INLINE Packet8us pcmp_lt<Packet8us>(const Packet8us& a, const Packet8us& b) {
1755 return vcltq_u16(a, b);
1756}
1757template <>
1758EIGEN_STRONG_INLINE Packet2i pcmp_lt<Packet2i>(const Packet2i& a, const Packet2i& b) {
1759 return vreinterpret_s32_u32(vclt_s32(a, b));
1760}
1761template <>
1762EIGEN_STRONG_INLINE Packet4i pcmp_lt<Packet4i>(const Packet4i& a, const Packet4i& b) {
1763 return vreinterpretq_s32_u32(vcltq_s32(a, b));
1764}
1765template <>
1766EIGEN_STRONG_INLINE Packet2ui pcmp_lt<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1767 return vclt_u32(a, b);
1768}
1769template <>
1770EIGEN_STRONG_INLINE Packet4ui pcmp_lt<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1771 return vcltq_u32(a, b);
1772}
1773template <>
1774EIGEN_STRONG_INLINE Packet2l pcmp_lt<Packet2l>(const Packet2l& a, const Packet2l& b) {
1775#if EIGEN_ARCH_ARM64
1776 return vreinterpretq_s64_u64(vcltq_s64(a, b));
1777#else
1778 return vcombine_s64(vdup_n_s64(vgetq_lane_s64(a, 0) < vgetq_lane_s64(b, 0) ? numext::int64_t(-1) : 0),
1779 vdup_n_s64(vgetq_lane_s64(a, 1) < vgetq_lane_s64(b, 1) ? numext::int64_t(-1) : 0));
1780#endif
1781}
1782template <>
1783EIGEN_STRONG_INLINE Packet2ul pcmp_lt<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1784#if EIGEN_ARCH_ARM64
1785 return vcltq_u64(a, b);
1786#else
1787 return vcombine_u64(vdup_n_u64(vgetq_lane_u64(a, 0) < vgetq_lane_u64(b, 0) ? numext::uint64_t(-1) : 0),
1788 vdup_n_u64(vgetq_lane_u64(a, 1) < vgetq_lane_u64(b, 1) ? numext::uint64_t(-1) : 0));
1789#endif
1790}
1791
1792template <>
1793EIGEN_STRONG_INLINE Packet2f pcmp_eq<Packet2f>(const Packet2f& a, const Packet2f& b) {
1794 return vreinterpret_f32_u32(vceq_f32(a, b));
1795}
1796template <>
1797EIGEN_STRONG_INLINE Packet4f pcmp_eq<Packet4f>(const Packet4f& a, const Packet4f& b) {
1798 return vreinterpretq_f32_u32(vceqq_f32(a, b));
1799}
1800template <>
1801EIGEN_STRONG_INLINE Packet4c pcmp_eq<Packet4c>(const Packet4c& a, const Packet4c& b) {
1802 return vget_lane_s32(
1803 vreinterpret_s32_u8(vceq_s8(vreinterpret_s8_s32(vdup_n_s32(a)), vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
1804}
1805template <>
1806EIGEN_STRONG_INLINE Packet8c pcmp_eq<Packet8c>(const Packet8c& a, const Packet8c& b) {
1807 return vreinterpret_s8_u8(vceq_s8(a, b));
1808}
1809template <>
1810EIGEN_STRONG_INLINE Packet16c pcmp_eq<Packet16c>(const Packet16c& a, const Packet16c& b) {
1811 return vreinterpretq_s8_u8(vceqq_s8(a, b));
1812}
1813template <>
1814EIGEN_STRONG_INLINE Packet4uc pcmp_eq<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1815 return vget_lane_u32(
1816 vreinterpret_u32_u8(vceq_u8(vreinterpret_u8_u32(vdup_n_u32(a)), vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
1817}
1818template <>
1819EIGEN_STRONG_INLINE Packet8uc pcmp_eq<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1820 return vceq_u8(a, b);
1821}
1822template <>
1823EIGEN_STRONG_INLINE Packet16uc pcmp_eq<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1824 return vceqq_u8(a, b);
1825}
1826template <>
1827EIGEN_STRONG_INLINE Packet4s pcmp_eq<Packet4s>(const Packet4s& a, const Packet4s& b) {
1828 return vreinterpret_s16_u16(vceq_s16(a, b));
1829}
1830template <>
1831EIGEN_STRONG_INLINE Packet8s pcmp_eq<Packet8s>(const Packet8s& a, const Packet8s& b) {
1832 return vreinterpretq_s16_u16(vceqq_s16(a, b));
1833}
1834template <>
1835EIGEN_STRONG_INLINE Packet4us pcmp_eq<Packet4us>(const Packet4us& a, const Packet4us& b) {
1836 return vceq_u16(a, b);
1837}
1838template <>
1839EIGEN_STRONG_INLINE Packet8us pcmp_eq<Packet8us>(const Packet8us& a, const Packet8us& b) {
1840 return vceqq_u16(a, b);
1841}
1842template <>
1843EIGEN_STRONG_INLINE Packet2i pcmp_eq<Packet2i>(const Packet2i& a, const Packet2i& b) {
1844 return vreinterpret_s32_u32(vceq_s32(a, b));
1845}
1846template <>
1847EIGEN_STRONG_INLINE Packet4i pcmp_eq<Packet4i>(const Packet4i& a, const Packet4i& b) {
1848 return vreinterpretq_s32_u32(vceqq_s32(a, b));
1849}
1850template <>
1851EIGEN_STRONG_INLINE Packet2ui pcmp_eq<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1852 return vceq_u32(a, b);
1853}
1854template <>
1855EIGEN_STRONG_INLINE Packet4ui pcmp_eq<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1856 return vceqq_u32(a, b);
1857}
1858template <>
1859EIGEN_STRONG_INLINE Packet2l pcmp_eq<Packet2l>(const Packet2l& a, const Packet2l& b) {
1860#if EIGEN_ARCH_ARM64
1861 return vreinterpretq_s64_u64(vceqq_s64(a, b));
1862#else
1863 return vcombine_s64(vdup_n_s64(vgetq_lane_s64(a, 0) == vgetq_lane_s64(b, 0) ? numext::int64_t(-1) : 0),
1864 vdup_n_s64(vgetq_lane_s64(a, 1) == vgetq_lane_s64(b, 1) ? numext::int64_t(-1) : 0));
1865#endif
1866}
1867template <>
1868EIGEN_STRONG_INLINE Packet2ul pcmp_eq<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1869#if EIGEN_ARCH_ARM64
1870 return vceqq_u64(a, b);
1871#else
1872 return vcombine_u64(vdup_n_u64(vgetq_lane_u64(a, 0) == vgetq_lane_u64(b, 0) ? numext::uint64_t(-1) : 0),
1873 vdup_n_u64(vgetq_lane_u64(a, 1) == vgetq_lane_u64(b, 1) ? numext::uint64_t(-1) : 0));
1874#endif
1875}
1876
1877template <>
1878EIGEN_STRONG_INLINE Packet2f pcmp_lt_or_nan<Packet2f>(const Packet2f& a, const Packet2f& b) {
1879 return vreinterpret_f32_u32(vmvn_u32(vcge_f32(a, b)));
1880}
1881template <>
1882EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan<Packet4f>(const Packet4f& a, const Packet4f& b) {
1883 return vreinterpretq_f32_u32(vmvnq_u32(vcgeq_f32(a, b)));
1884}
1885
1886// Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics
1887template <>
1888EIGEN_STRONG_INLINE Packet2f pand<Packet2f>(const Packet2f& a, const Packet2f& b) {
1889 return vreinterpret_f32_u32(vand_u32(vreinterpret_u32_f32(a), vreinterpret_u32_f32(b)));
1890}
1891template <>
1892EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) {
1893 return vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(a), vreinterpretq_u32_f32(b)));
1894}
1895template <>
1896EIGEN_STRONG_INLINE Packet4c pand<Packet4c>(const Packet4c& a, const Packet4c& b) {
1897 return a & b;
1898}
1899template <>
1900EIGEN_STRONG_INLINE Packet8c pand<Packet8c>(const Packet8c& a, const Packet8c& b) {
1901 return vand_s8(a, b);
1902}
1903template <>
1904EIGEN_STRONG_INLINE Packet16c pand<Packet16c>(const Packet16c& a, const Packet16c& b) {
1905 return vandq_s8(a, b);
1906}
1907template <>
1908EIGEN_STRONG_INLINE Packet4uc pand<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1909 return a & b;
1910}
1911template <>
1912EIGEN_STRONG_INLINE Packet8uc pand<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1913 return vand_u8(a, b);
1914}
1915template <>
1916EIGEN_STRONG_INLINE Packet16uc pand<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1917 return vandq_u8(a, b);
1918}
1919template <>
1920EIGEN_STRONG_INLINE Packet4s pand<Packet4s>(const Packet4s& a, const Packet4s& b) {
1921 return vand_s16(a, b);
1922}
1923template <>
1924EIGEN_STRONG_INLINE Packet8s pand<Packet8s>(const Packet8s& a, const Packet8s& b) {
1925 return vandq_s16(a, b);
1926}
1927template <>
1928EIGEN_STRONG_INLINE Packet4us pand<Packet4us>(const Packet4us& a, const Packet4us& b) {
1929 return vand_u16(a, b);
1930}
1931template <>
1932EIGEN_STRONG_INLINE Packet8us pand<Packet8us>(const Packet8us& a, const Packet8us& b) {
1933 return vandq_u16(a, b);
1934}
1935template <>
1936EIGEN_STRONG_INLINE Packet2i pand<Packet2i>(const Packet2i& a, const Packet2i& b) {
1937 return vand_s32(a, b);
1938}
1939template <>
1940EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) {
1941 return vandq_s32(a, b);
1942}
1943template <>
1944EIGEN_STRONG_INLINE Packet2ui pand<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
1945 return vand_u32(a, b);
1946}
1947template <>
1948EIGEN_STRONG_INLINE Packet4ui pand<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
1949 return vandq_u32(a, b);
1950}
1951template <>
1952EIGEN_STRONG_INLINE Packet2l pand<Packet2l>(const Packet2l& a, const Packet2l& b) {
1953 return vandq_s64(a, b);
1954}
1955template <>
1956EIGEN_STRONG_INLINE Packet2ul pand<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
1957 return vandq_u64(a, b);
1958}
1959
1960template <>
1961EIGEN_STRONG_INLINE Packet2f por<Packet2f>(const Packet2f& a, const Packet2f& b) {
1962 return vreinterpret_f32_u32(vorr_u32(vreinterpret_u32_f32(a), vreinterpret_u32_f32(b)));
1963}
1964template <>
1965EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) {
1966 return vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a), vreinterpretq_u32_f32(b)));
1967}
1968template <>
1969EIGEN_STRONG_INLINE Packet4c por<Packet4c>(const Packet4c& a, const Packet4c& b) {
1970 return a | b;
1971}
1972template <>
1973EIGEN_STRONG_INLINE Packet8c por<Packet8c>(const Packet8c& a, const Packet8c& b) {
1974 return vorr_s8(a, b);
1975}
1976template <>
1977EIGEN_STRONG_INLINE Packet16c por<Packet16c>(const Packet16c& a, const Packet16c& b) {
1978 return vorrq_s8(a, b);
1979}
1980template <>
1981EIGEN_STRONG_INLINE Packet4uc por<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
1982 return a | b;
1983}
1984template <>
1985EIGEN_STRONG_INLINE Packet8uc por<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
1986 return vorr_u8(a, b);
1987}
1988template <>
1989EIGEN_STRONG_INLINE Packet16uc por<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
1990 return vorrq_u8(a, b);
1991}
1992template <>
1993EIGEN_STRONG_INLINE Packet4s por<Packet4s>(const Packet4s& a, const Packet4s& b) {
1994 return vorr_s16(a, b);
1995}
1996template <>
1997EIGEN_STRONG_INLINE Packet8s por<Packet8s>(const Packet8s& a, const Packet8s& b) {
1998 return vorrq_s16(a, b);
1999}
2000template <>
2001EIGEN_STRONG_INLINE Packet4us por<Packet4us>(const Packet4us& a, const Packet4us& b) {
2002 return vorr_u16(a, b);
2003}
2004template <>
2005EIGEN_STRONG_INLINE Packet8us por<Packet8us>(const Packet8us& a, const Packet8us& b) {
2006 return vorrq_u16(a, b);
2007}
2008template <>
2009EIGEN_STRONG_INLINE Packet2i por<Packet2i>(const Packet2i& a, const Packet2i& b) {
2010 return vorr_s32(a, b);
2011}
2012template <>
2013EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) {
2014 return vorrq_s32(a, b);
2015}
2016template <>
2017EIGEN_STRONG_INLINE Packet2ui por<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
2018 return vorr_u32(a, b);
2019}
2020template <>
2021EIGEN_STRONG_INLINE Packet4ui por<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
2022 return vorrq_u32(a, b);
2023}
2024template <>
2025EIGEN_STRONG_INLINE Packet2l por<Packet2l>(const Packet2l& a, const Packet2l& b) {
2026 return vorrq_s64(a, b);
2027}
2028template <>
2029EIGEN_STRONG_INLINE Packet2ul por<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
2030 return vorrq_u64(a, b);
2031}
2032
2033template <>
2034EIGEN_STRONG_INLINE Packet2f pxor<Packet2f>(const Packet2f& a, const Packet2f& b) {
2035 return vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(a), vreinterpret_u32_f32(b)));
2036}
2037template <>
2038EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) {
2039 return vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a), vreinterpretq_u32_f32(b)));
2040}
2041template <>
2042EIGEN_STRONG_INLINE Packet4c pxor<Packet4c>(const Packet4c& a, const Packet4c& b) {
2043 return a ^ b;
2044}
2045template <>
2046EIGEN_STRONG_INLINE Packet8c pxor<Packet8c>(const Packet8c& a, const Packet8c& b) {
2047 return veor_s8(a, b);
2048}
2049template <>
2050EIGEN_STRONG_INLINE Packet16c pxor<Packet16c>(const Packet16c& a, const Packet16c& b) {
2051 return veorq_s8(a, b);
2052}
2053template <>
2054EIGEN_STRONG_INLINE Packet4uc pxor<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
2055 return a ^ b;
2056}
2057template <>
2058EIGEN_STRONG_INLINE Packet8uc pxor<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
2059 return veor_u8(a, b);
2060}
2061template <>
2062EIGEN_STRONG_INLINE Packet16uc pxor<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
2063 return veorq_u8(a, b);
2064}
2065template <>
2066EIGEN_STRONG_INLINE Packet4s pxor<Packet4s>(const Packet4s& a, const Packet4s& b) {
2067 return veor_s16(a, b);
2068}
2069template <>
2070EIGEN_STRONG_INLINE Packet8s pxor<Packet8s>(const Packet8s& a, const Packet8s& b) {
2071 return veorq_s16(a, b);
2072}
2073template <>
2074EIGEN_STRONG_INLINE Packet4us pxor<Packet4us>(const Packet4us& a, const Packet4us& b) {
2075 return veor_u16(a, b);
2076}
2077template <>
2078EIGEN_STRONG_INLINE Packet8us pxor<Packet8us>(const Packet8us& a, const Packet8us& b) {
2079 return veorq_u16(a, b);
2080}
2081template <>
2082EIGEN_STRONG_INLINE Packet2i pxor<Packet2i>(const Packet2i& a, const Packet2i& b) {
2083 return veor_s32(a, b);
2084}
2085template <>
2086EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) {
2087 return veorq_s32(a, b);
2088}
2089template <>
2090EIGEN_STRONG_INLINE Packet2ui pxor<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
2091 return veor_u32(a, b);
2092}
2093template <>
2094EIGEN_STRONG_INLINE Packet4ui pxor<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
2095 return veorq_u32(a, b);
2096}
2097template <>
2098EIGEN_STRONG_INLINE Packet2l pxor<Packet2l>(const Packet2l& a, const Packet2l& b) {
2099 return veorq_s64(a, b);
2100}
2101template <>
2102EIGEN_STRONG_INLINE Packet2ul pxor<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
2103 return veorq_u64(a, b);
2104}
2105
2106template <>
2107EIGEN_STRONG_INLINE Packet2f pandnot<Packet2f>(const Packet2f& a, const Packet2f& b) {
2108 return vreinterpret_f32_u32(vbic_u32(vreinterpret_u32_f32(a), vreinterpret_u32_f32(b)));
2109}
2110template <>
2111EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) {
2112 return vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a), vreinterpretq_u32_f32(b)));
2113}
2114template <>
2115EIGEN_STRONG_INLINE Packet4c pandnot<Packet4c>(const Packet4c& a, const Packet4c& b) {
2116 return a & ~b;
2117}
2118template <>
2119EIGEN_STRONG_INLINE Packet8c pandnot<Packet8c>(const Packet8c& a, const Packet8c& b) {
2120 return vbic_s8(a, b);
2121}
2122template <>
2123EIGEN_STRONG_INLINE Packet16c pandnot<Packet16c>(const Packet16c& a, const Packet16c& b) {
2124 return vbicq_s8(a, b);
2125}
2126template <>
2127EIGEN_STRONG_INLINE Packet4uc pandnot<Packet4uc>(const Packet4uc& a, const Packet4uc& b) {
2128 return a & ~b;
2129}
2130template <>
2131EIGEN_STRONG_INLINE Packet8uc pandnot<Packet8uc>(const Packet8uc& a, const Packet8uc& b) {
2132 return vbic_u8(a, b);
2133}
2134template <>
2135EIGEN_STRONG_INLINE Packet16uc pandnot<Packet16uc>(const Packet16uc& a, const Packet16uc& b) {
2136 return vbicq_u8(a, b);
2137}
2138template <>
2139EIGEN_STRONG_INLINE Packet4s pandnot<Packet4s>(const Packet4s& a, const Packet4s& b) {
2140 return vbic_s16(a, b);
2141}
2142template <>
2143EIGEN_STRONG_INLINE Packet8s pandnot<Packet8s>(const Packet8s& a, const Packet8s& b) {
2144 return vbicq_s16(a, b);
2145}
2146template <>
2147EIGEN_STRONG_INLINE Packet4us pandnot<Packet4us>(const Packet4us& a, const Packet4us& b) {
2148 return vbic_u16(a, b);
2149}
2150template <>
2151EIGEN_STRONG_INLINE Packet8us pandnot<Packet8us>(const Packet8us& a, const Packet8us& b) {
2152 return vbicq_u16(a, b);
2153}
2154template <>
2155EIGEN_STRONG_INLINE Packet2i pandnot<Packet2i>(const Packet2i& a, const Packet2i& b) {
2156 return vbic_s32(a, b);
2157}
2158template <>
2159EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) {
2160 return vbicq_s32(a, b);
2161}
2162template <>
2163EIGEN_STRONG_INLINE Packet2ui pandnot<Packet2ui>(const Packet2ui& a, const Packet2ui& b) {
2164 return vbic_u32(a, b);
2165}
2166template <>
2167EIGEN_STRONG_INLINE Packet4ui pandnot<Packet4ui>(const Packet4ui& a, const Packet4ui& b) {
2168 return vbicq_u32(a, b);
2169}
2170template <>
2171EIGEN_STRONG_INLINE Packet2l pandnot<Packet2l>(const Packet2l& a, const Packet2l& b) {
2172 return vbicq_s64(a, b);
2173}
2174template <>
2175EIGEN_STRONG_INLINE Packet2ul pandnot<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
2176 return vbicq_u64(a, b);
2177}
2178
2179template <int N>
2180EIGEN_STRONG_INLINE Packet4c parithmetic_shift_right(Packet4c& a) {
2181 return vget_lane_s32(vreinterpret_s32_s8(vshr_n_s8(vreinterpret_s8_s32(vdup_n_s32(a)), N)), 0);
2182}
2183template <int N>
2184EIGEN_STRONG_INLINE Packet8c parithmetic_shift_right(Packet8c a) {
2185 return vshr_n_s8(a, N);
2186}
2187template <int N>
2188EIGEN_STRONG_INLINE Packet16c parithmetic_shift_right(Packet16c a) {
2189 return vshrq_n_s8(a, N);
2190}
2191template <int N>
2192EIGEN_STRONG_INLINE Packet4uc parithmetic_shift_right(Packet4uc& a) {
2193 return vget_lane_u32(vreinterpret_u32_u8(vshr_n_u8(vreinterpret_u8_u32(vdup_n_u32(a)), N)), 0);
2194}
2195template <int N>
2196EIGEN_STRONG_INLINE Packet8uc parithmetic_shift_right(Packet8uc a) {
2197 return vshr_n_u8(a, N);
2198}
2199template <int N>
2200EIGEN_STRONG_INLINE Packet16uc parithmetic_shift_right(Packet16uc a) {
2201 return vshrq_n_u8(a, N);
2202}
2203template <int N>
2204EIGEN_STRONG_INLINE Packet4s parithmetic_shift_right(Packet4s a) {
2205 return vshr_n_s16(a, N);
2206}
2207template <int N>
2208EIGEN_STRONG_INLINE Packet8s parithmetic_shift_right(Packet8s a) {
2209 return vshrq_n_s16(a, N);
2210}
2211template <int N>
2212EIGEN_STRONG_INLINE Packet4us parithmetic_shift_right(Packet4us a) {
2213 return vshr_n_u16(a, N);
2214}
2215template <int N>
2216EIGEN_STRONG_INLINE Packet8us parithmetic_shift_right(Packet8us a) {
2217 return vshrq_n_u16(a, N);
2218}
2219template <int N>
2220EIGEN_STRONG_INLINE Packet2i parithmetic_shift_right(Packet2i a) {
2221 return vshr_n_s32(a, N);
2222}
2223template <int N>
2224EIGEN_STRONG_INLINE Packet4i parithmetic_shift_right(Packet4i a) {
2225 return vshrq_n_s32(a, N);
2226}
2227template <int N>
2228EIGEN_STRONG_INLINE Packet2ui parithmetic_shift_right(Packet2ui a) {
2229 return vshr_n_u32(a, N);
2230}
2231template <int N>
2232EIGEN_STRONG_INLINE Packet4ui parithmetic_shift_right(Packet4ui a) {
2233 return vshrq_n_u32(a, N);
2234}
2235template <int N>
2236EIGEN_STRONG_INLINE Packet2l parithmetic_shift_right(Packet2l a) {
2237 return vshrq_n_s64(a, N);
2238}
2239template <int N>
2240EIGEN_STRONG_INLINE Packet2ul parithmetic_shift_right(Packet2ul a) {
2241 return vshrq_n_u64(a, N);
2242}
2243
2244template <int N>
2245EIGEN_STRONG_INLINE Packet4c plogical_shift_right(Packet4c& a) {
2246 return vget_lane_s32(vreinterpret_s32_u8(vshr_n_u8(vreinterpret_u8_s32(vdup_n_s32(a)), N)), 0);
2247}
2248template <int N>
2249EIGEN_STRONG_INLINE Packet8c plogical_shift_right(Packet8c a) {
2250 return vreinterpret_s8_u8(vshr_n_u8(vreinterpret_u8_s8(a), N));
2251}
2252template <int N>
2253EIGEN_STRONG_INLINE Packet16c plogical_shift_right(Packet16c a) {
2254 return vreinterpretq_s8_u8(vshrq_n_u8(vreinterpretq_u8_s8(a), N));
2255}
2256template <int N>
2257EIGEN_STRONG_INLINE Packet4uc plogical_shift_right(Packet4uc& a) {
2258 return vget_lane_u32(vreinterpret_u32_s8(vshr_n_s8(vreinterpret_s8_u32(vdup_n_u32(a)), N)), 0);
2259}
2260template <int N>
2261EIGEN_STRONG_INLINE Packet8uc plogical_shift_right(Packet8uc a) {
2262 return vshr_n_u8(a, N);
2263}
2264template <int N>
2265EIGEN_STRONG_INLINE Packet16uc plogical_shift_right(Packet16uc a) {
2266 return vshrq_n_u8(a, N);
2267}
2268template <int N>
2269EIGEN_STRONG_INLINE Packet4s plogical_shift_right(Packet4s a) {
2270 return vreinterpret_s16_u16(vshr_n_u16(vreinterpret_u16_s16(a), N));
2271}
2272template <int N>
2273EIGEN_STRONG_INLINE Packet8s plogical_shift_right(Packet8s a) {
2274 return vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(a), N));
2275}
2276template <int N>
2277EIGEN_STRONG_INLINE Packet4us plogical_shift_right(Packet4us a) {
2278 return vshr_n_u16(a, N);
2279}
2280template <int N>
2281EIGEN_STRONG_INLINE Packet8us plogical_shift_right(Packet8us a) {
2282 return vshrq_n_u16(a, N);
2283}
2284template <int N>
2285EIGEN_STRONG_INLINE Packet2i plogical_shift_right(Packet2i a) {
2286 return vreinterpret_s32_u32(vshr_n_u32(vreinterpret_u32_s32(a), N));
2287}
2288template <int N>
2289EIGEN_STRONG_INLINE Packet4i plogical_shift_right(Packet4i a) {
2290 return vreinterpretq_s32_u32(vshrq_n_u32(vreinterpretq_u32_s32(a), N));
2291}
2292template <int N>
2293EIGEN_STRONG_INLINE Packet2ui plogical_shift_right(Packet2ui a) {
2294 return vshr_n_u32(a, N);
2295}
2296template <int N>
2297EIGEN_STRONG_INLINE Packet4ui plogical_shift_right(Packet4ui a) {
2298 return vshrq_n_u32(a, N);
2299}
2300template <int N>
2301EIGEN_STRONG_INLINE Packet2l plogical_shift_right(Packet2l a) {
2302 return vreinterpretq_s64_u64(vshrq_n_u64(vreinterpretq_u64_s64(a), N));
2303}
2304template <int N>
2305EIGEN_STRONG_INLINE Packet2ul plogical_shift_right(Packet2ul a) {
2306 return vshrq_n_u64(a, N);
2307}
2308
2309template <int N>
2310EIGEN_STRONG_INLINE Packet4c plogical_shift_left(Packet4c& a) {
2311 return vget_lane_s32(vreinterpret_s32_s8(vshl_n_s8(vreinterpret_s8_s32(vdup_n_s32(a)), N)), 0);
2312}
2313template <int N>
2314EIGEN_STRONG_INLINE Packet8c plogical_shift_left(Packet8c a) {
2315 return vshl_n_s8(a, N);
2316}
2317template <int N>
2318EIGEN_STRONG_INLINE Packet16c plogical_shift_left(Packet16c a) {
2319 return vshlq_n_s8(a, N);
2320}
2321template <int N>
2322EIGEN_STRONG_INLINE Packet4uc plogical_shift_left(Packet4uc& a) {
2323 return vget_lane_u32(vreinterpret_u32_u8(vshl_n_u8(vreinterpret_u8_u32(vdup_n_u32(a)), N)), 0);
2324}
2325template <int N>
2326EIGEN_STRONG_INLINE Packet8uc plogical_shift_left(Packet8uc a) {
2327 return vshl_n_u8(a, N);
2328}
2329template <int N>
2330EIGEN_STRONG_INLINE Packet16uc plogical_shift_left(Packet16uc a) {
2331 return vshlq_n_u8(a, N);
2332}
2333template <int N>
2334EIGEN_STRONG_INLINE Packet4s plogical_shift_left(Packet4s a) {
2335 return vshl_n_s16(a, N);
2336}
2337template <int N>
2338EIGEN_STRONG_INLINE Packet8s plogical_shift_left(Packet8s a) {
2339 return vshlq_n_s16(a, N);
2340}
2341template <int N>
2342EIGEN_STRONG_INLINE Packet4us plogical_shift_left(Packet4us a) {
2343 return vshl_n_u16(a, N);
2344}
2345template <int N>
2346EIGEN_STRONG_INLINE Packet8us plogical_shift_left(Packet8us a) {
2347 return vshlq_n_u16(a, N);
2348}
2349template <int N>
2350EIGEN_STRONG_INLINE Packet2i plogical_shift_left(Packet2i a) {
2351 return vshl_n_s32(a, N);
2352}
2353template <int N>
2354EIGEN_STRONG_INLINE Packet4i plogical_shift_left(Packet4i a) {
2355 return vshlq_n_s32(a, N);
2356}
2357template <int N>
2358EIGEN_STRONG_INLINE Packet2ui plogical_shift_left(Packet2ui a) {
2359 return vshl_n_u32(a, N);
2360}
2361template <int N>
2362EIGEN_STRONG_INLINE Packet4ui plogical_shift_left(Packet4ui a) {
2363 return vshlq_n_u32(a, N);
2364}
2365template <int N>
2366EIGEN_STRONG_INLINE Packet2l plogical_shift_left(Packet2l a) {
2367 return vshlq_n_s64(a, N);
2368}
2369template <int N>
2370EIGEN_STRONG_INLINE Packet2ul plogical_shift_left(Packet2ul a) {
2371 return vshlq_n_u64(a, N);
2372}
2373
2374template <>
2375EIGEN_STRONG_INLINE Packet2f pload<Packet2f>(const float* from) {
2376 EIGEN_DEBUG_ALIGNED_LOAD return vld1_f32(from);
2377}
2378template <>
2379EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) {
2380 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f32(from);
2381}
2382template <>
2383EIGEN_STRONG_INLINE Packet4c pload<Packet4c>(const int8_t* from) {
2384 Packet4c res;
2385 memcpy(&res, from, sizeof(Packet4c));
2386 return res;
2387}
2388template <>
2389EIGEN_STRONG_INLINE Packet8c pload<Packet8c>(const int8_t* from) {
2390 EIGEN_DEBUG_ALIGNED_LOAD return vld1_s8(from);
2391}
2392template <>
2393EIGEN_STRONG_INLINE Packet16c pload<Packet16c>(const int8_t* from) {
2394 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s8(from);
2395}
2396template <>
2397EIGEN_STRONG_INLINE Packet4uc pload<Packet4uc>(const uint8_t* from) {
2398 Packet4uc res;
2399 memcpy(&res, from, sizeof(Packet4uc));
2400 return res;
2401}
2402template <>
2403EIGEN_STRONG_INLINE Packet8uc pload<Packet8uc>(const uint8_t* from) {
2404 EIGEN_DEBUG_ALIGNED_LOAD return vld1_u8(from);
2405}
2406template <>
2407EIGEN_STRONG_INLINE Packet16uc pload<Packet16uc>(const uint8_t* from) {
2408 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u8(from);
2409}
2410template <>
2411EIGEN_STRONG_INLINE Packet4s pload<Packet4s>(const int16_t* from) {
2412 EIGEN_DEBUG_ALIGNED_LOAD return vld1_s16(from);
2413}
2414template <>
2415EIGEN_STRONG_INLINE Packet8s pload<Packet8s>(const int16_t* from) {
2416 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s16(from);
2417}
2418template <>
2419EIGEN_STRONG_INLINE Packet4us pload<Packet4us>(const uint16_t* from) {
2420 EIGEN_DEBUG_ALIGNED_LOAD return vld1_u16(from);
2421}
2422template <>
2423EIGEN_STRONG_INLINE Packet8us pload<Packet8us>(const uint16_t* from) {
2424 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u16(from);
2425}
2426template <>
2427EIGEN_STRONG_INLINE Packet2i pload<Packet2i>(const int32_t* from) {
2428 EIGEN_DEBUG_ALIGNED_LOAD return vld1_s32(from);
2429}
2430template <>
2431EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int32_t* from) {
2432 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s32(from);
2433}
2434template <>
2435EIGEN_STRONG_INLINE Packet2ui pload<Packet2ui>(const uint32_t* from) {
2436 EIGEN_DEBUG_ALIGNED_LOAD return vld1_u32(from);
2437}
2438template <>
2439EIGEN_STRONG_INLINE Packet4ui pload<Packet4ui>(const uint32_t* from) {
2440 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u32(from);
2441}
2442template <>
2443EIGEN_STRONG_INLINE Packet2l pload<Packet2l>(const int64_t* from) {
2444 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s64(from);
2445}
2446template <>
2447EIGEN_STRONG_INLINE Packet2ul pload<Packet2ul>(const uint64_t* from) {
2448 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u64(from);
2449}
2450
2451template <>
2452EIGEN_STRONG_INLINE Packet2f ploadu<Packet2f>(const float* from) {
2453 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_f32(from);
2454}
2455template <>
2456EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) {
2457 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f32(from);
2458}
2459template <>
2460EIGEN_STRONG_INLINE Packet4c ploadu<Packet4c>(const int8_t* from) {
2461 Packet4c res;
2462 memcpy(&res, from, sizeof(Packet4c));
2463 return res;
2464}
2465template <>
2466EIGEN_STRONG_INLINE Packet8c ploadu<Packet8c>(const int8_t* from) {
2467 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_s8(from);
2468}
2469template <>
2470EIGEN_STRONG_INLINE Packet16c ploadu<Packet16c>(const int8_t* from) {
2471 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s8(from);
2472}
2473template <>
2474EIGEN_STRONG_INLINE Packet4uc ploadu<Packet4uc>(const uint8_t* from) {
2475 Packet4uc res;
2476 memcpy(&res, from, sizeof(Packet4uc));
2477 return res;
2478}
2479template <>
2480EIGEN_STRONG_INLINE Packet8uc ploadu<Packet8uc>(const uint8_t* from) {
2481 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_u8(from);
2482}
2483template <>
2484EIGEN_STRONG_INLINE Packet16uc ploadu<Packet16uc>(const uint8_t* from) {
2485 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u8(from);
2486}
2487template <>
2488EIGEN_STRONG_INLINE Packet4s ploadu<Packet4s>(const int16_t* from) {
2489 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_s16(from);
2490}
2491template <>
2492EIGEN_STRONG_INLINE Packet8s ploadu<Packet8s>(const int16_t* from) {
2493 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s16(from);
2494}
2495template <>
2496EIGEN_STRONG_INLINE Packet4us ploadu<Packet4us>(const uint16_t* from) {
2497 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_u16(from);
2498}
2499template <>
2500EIGEN_STRONG_INLINE Packet8us ploadu<Packet8us>(const uint16_t* from) {
2501 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u16(from);
2502}
2503template <>
2504EIGEN_STRONG_INLINE Packet2i ploadu<Packet2i>(const int32_t* from) {
2505 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_s32(from);
2506}
2507template <>
2508EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int32_t* from) {
2509 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s32(from);
2510}
2511template <>
2512EIGEN_STRONG_INLINE Packet2ui ploadu<Packet2ui>(const uint32_t* from) {
2513 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_u32(from);
2514}
2515template <>
2516EIGEN_STRONG_INLINE Packet4ui ploadu<Packet4ui>(const uint32_t* from) {
2517 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u32(from);
2518}
2519template <>
2520EIGEN_STRONG_INLINE Packet2l ploadu<Packet2l>(const int64_t* from) {
2521 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s64(from);
2522}
2523template <>
2524EIGEN_STRONG_INLINE Packet2ul ploadu<Packet2ul>(const uint64_t* from) {
2525 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u64(from);
2526}
2527
2528template <>
2529EIGEN_STRONG_INLINE Packet2f ploaddup<Packet2f>(const float* from) {
2530 return vld1_dup_f32(from);
2531}
2532template <>
2533EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) {
2534 return vcombine_f32(vld1_dup_f32(from), vld1_dup_f32(from + 1));
2535}
2536template <>
2537EIGEN_STRONG_INLINE Packet4c ploaddup<Packet4c>(const int8_t* from) {
2538 const int8x8_t a = vreinterpret_s8_s32(vdup_n_s32(pload<Packet4c>(from)));
2539 return vget_lane_s32(vreinterpret_s32_s8(vzip_s8(a, a).val[0]), 0);
2540}
2541template <>
2542EIGEN_STRONG_INLINE Packet8c ploaddup<Packet8c>(const int8_t* from) {
2543 const int8x8_t a = vld1_s8(from);
2544 return vzip_s8(a, a).val[0];
2545}
2546template <>
2547EIGEN_STRONG_INLINE Packet16c ploaddup<Packet16c>(const int8_t* from) {
2548 const int8x8_t a = vld1_s8(from);
2549 const int8x8x2_t b = vzip_s8(a, a);
2550 return vcombine_s8(b.val[0], b.val[1]);
2551}
2552template <>
2553EIGEN_STRONG_INLINE Packet4uc ploaddup<Packet4uc>(const uint8_t* from) {
2554 const uint8x8_t a = vreinterpret_u8_u32(vdup_n_u32(pload<Packet4uc>(from)));
2555 return vget_lane_u32(vreinterpret_u32_u8(vzip_u8(a, a).val[0]), 0);
2556}
2557template <>
2558EIGEN_STRONG_INLINE Packet8uc ploaddup<Packet8uc>(const uint8_t* from) {
2559 const uint8x8_t a = vld1_u8(from);
2560 return vzip_u8(a, a).val[0];
2561}
2562template <>
2563EIGEN_STRONG_INLINE Packet16uc ploaddup<Packet16uc>(const uint8_t* from) {
2564 const uint8x8_t a = vld1_u8(from);
2565 const uint8x8x2_t b = vzip_u8(a, a);
2566 return vcombine_u8(b.val[0], b.val[1]);
2567}
2568template <>
2569EIGEN_STRONG_INLINE Packet4s ploaddup<Packet4s>(const int16_t* from) {
2570 return vreinterpret_s16_u32(
2571 vzip_u32(vreinterpret_u32_s16(vld1_dup_s16(from)), vreinterpret_u32_s16(vld1_dup_s16(from + 1))).val[0]);
2572}
2573template <>
2574EIGEN_STRONG_INLINE Packet8s ploaddup<Packet8s>(const int16_t* from) {
2575 const int16x4_t a = vld1_s16(from);
2576 const int16x4x2_t b = vzip_s16(a, a);
2577 return vcombine_s16(b.val[0], b.val[1]);
2578}
2579template <>
2580EIGEN_STRONG_INLINE Packet4us ploaddup<Packet4us>(const uint16_t* from) {
2581 return vreinterpret_u16_u32(
2582 vzip_u32(vreinterpret_u32_u16(vld1_dup_u16(from)), vreinterpret_u32_u16(vld1_dup_u16(from + 1))).val[0]);
2583}
2584template <>
2585EIGEN_STRONG_INLINE Packet8us ploaddup<Packet8us>(const uint16_t* from) {
2586 const uint16x4_t a = vld1_u16(from);
2587 const uint16x4x2_t b = vzip_u16(a, a);
2588 return vcombine_u16(b.val[0], b.val[1]);
2589}
2590template <>
2591EIGEN_STRONG_INLINE Packet2i ploaddup<Packet2i>(const int32_t* from) {
2592 return vld1_dup_s32(from);
2593}
2594template <>
2595EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int32_t* from) {
2596 return vcombine_s32(vld1_dup_s32(from), vld1_dup_s32(from + 1));
2597}
2598template <>
2599EIGEN_STRONG_INLINE Packet2ui ploaddup<Packet2ui>(const uint32_t* from) {
2600 return vld1_dup_u32(from);
2601}
2602template <>
2603EIGEN_STRONG_INLINE Packet4ui ploaddup<Packet4ui>(const uint32_t* from) {
2604 return vcombine_u32(vld1_dup_u32(from), vld1_dup_u32(from + 1));
2605}
2606template <>
2607EIGEN_STRONG_INLINE Packet2l ploaddup<Packet2l>(const int64_t* from) {
2608 return vld1q_dup_s64(from);
2609}
2610template <>
2611EIGEN_STRONG_INLINE Packet2ul ploaddup<Packet2ul>(const uint64_t* from) {
2612 return vld1q_dup_u64(from);
2613}
2614
2615template <>
2616EIGEN_STRONG_INLINE Packet4f ploadquad<Packet4f>(const float* from) {
2617 return vld1q_dup_f32(from);
2618}
2619template <>
2620EIGEN_STRONG_INLINE Packet4c ploadquad<Packet4c>(const int8_t* from) {
2621 return vget_lane_s32(vreinterpret_s32_s8(vld1_dup_s8(from)), 0);
2622}
2623template <>
2624EIGEN_STRONG_INLINE Packet8c ploadquad<Packet8c>(const int8_t* from) {
2625 return vreinterpret_s8_u32(
2626 vzip_u32(vreinterpret_u32_s8(vld1_dup_s8(from)), vreinterpret_u32_s8(vld1_dup_s8(from + 1))).val[0]);
2627}
2628template <>
2629EIGEN_STRONG_INLINE Packet16c ploadquad<Packet16c>(const int8_t* from) {
2630 const int8x8_t a = vreinterpret_s8_u32(
2631 vzip_u32(vreinterpret_u32_s8(vld1_dup_s8(from)), vreinterpret_u32_s8(vld1_dup_s8(from + 1))).val[0]);
2632 const int8x8_t b = vreinterpret_s8_u32(
2633 vzip_u32(vreinterpret_u32_s8(vld1_dup_s8(from + 2)), vreinterpret_u32_s8(vld1_dup_s8(from + 3))).val[0]);
2634 return vcombine_s8(a, b);
2635}
2636template <>
2637EIGEN_STRONG_INLINE Packet4uc ploadquad<Packet4uc>(const uint8_t* from) {
2638 return vget_lane_u32(vreinterpret_u32_u8(vld1_dup_u8(from)), 0);
2639}
2640template <>
2641EIGEN_STRONG_INLINE Packet8uc ploadquad<Packet8uc>(const uint8_t* from) {
2642 return vreinterpret_u8_u32(
2643 vzip_u32(vreinterpret_u32_u8(vld1_dup_u8(from)), vreinterpret_u32_u8(vld1_dup_u8(from + 1))).val[0]);
2644}
2645template <>
2646EIGEN_STRONG_INLINE Packet16uc ploadquad<Packet16uc>(const uint8_t* from) {
2647 const uint8x8_t a = vreinterpret_u8_u32(
2648 vzip_u32(vreinterpret_u32_u8(vld1_dup_u8(from)), vreinterpret_u32_u8(vld1_dup_u8(from + 1))).val[0]);
2649 const uint8x8_t b = vreinterpret_u8_u32(
2650 vzip_u32(vreinterpret_u32_u8(vld1_dup_u8(from + 2)), vreinterpret_u32_u8(vld1_dup_u8(from + 3))).val[0]);
2651 return vcombine_u8(a, b);
2652}
2653template <>
2654EIGEN_STRONG_INLINE Packet8s ploadquad<Packet8s>(const int16_t* from) {
2655 return vcombine_s16(vld1_dup_s16(from), vld1_dup_s16(from + 1));
2656}
2657template <>
2658EIGEN_STRONG_INLINE Packet8us ploadquad<Packet8us>(const uint16_t* from) {
2659 return vcombine_u16(vld1_dup_u16(from), vld1_dup_u16(from + 1));
2660}
2661template <>
2662EIGEN_STRONG_INLINE Packet4i ploadquad<Packet4i>(const int32_t* from) {
2663 return vld1q_dup_s32(from);
2664}
2665template <>
2666EIGEN_STRONG_INLINE Packet4ui ploadquad<Packet4ui>(const uint32_t* from) {
2667 return vld1q_dup_u32(from);
2668}
2669
2670template <>
2671EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet2f& from) {
2672 EIGEN_DEBUG_ALIGNED_STORE vst1_f32(to, from);
2673}
2674template <>
2675EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) {
2676 EIGEN_DEBUG_ALIGNED_STORE vst1q_f32(to, from);
2677}
2678template <>
2679EIGEN_STRONG_INLINE void pstore<int8_t>(int8_t* to, const Packet4c& from) {
2680 memcpy(to, &from, sizeof(from));
2681}
2682template <>
2683EIGEN_STRONG_INLINE void pstore<int8_t>(int8_t* to, const Packet8c& from) {
2684 EIGEN_DEBUG_ALIGNED_STORE vst1_s8(to, from);
2685}
2686template <>
2687EIGEN_STRONG_INLINE void pstore<int8_t>(int8_t* to, const Packet16c& from) {
2688 EIGEN_DEBUG_ALIGNED_STORE vst1q_s8(to, from);
2689}
2690template <>
2691EIGEN_STRONG_INLINE void pstore<uint8_t>(uint8_t* to, const Packet4uc& from) {
2692 memcpy(to, &from, sizeof(from));
2693}
2694template <>
2695EIGEN_STRONG_INLINE void pstore<uint8_t>(uint8_t* to, const Packet8uc& from) {
2696 EIGEN_DEBUG_ALIGNED_STORE vst1_u8(to, from);
2697}
2698template <>
2699EIGEN_STRONG_INLINE void pstore<uint8_t>(uint8_t* to, const Packet16uc& from) {
2700 EIGEN_DEBUG_ALIGNED_STORE vst1q_u8(to, from);
2701}
2702template <>
2703EIGEN_STRONG_INLINE void pstore<int16_t>(int16_t* to, const Packet4s& from) {
2704 EIGEN_DEBUG_ALIGNED_STORE vst1_s16(to, from);
2705}
2706template <>
2707EIGEN_STRONG_INLINE void pstore<int16_t>(int16_t* to, const Packet8s& from) {
2708 EIGEN_DEBUG_ALIGNED_STORE vst1q_s16(to, from);
2709}
2710template <>
2711EIGEN_STRONG_INLINE void pstore<uint16_t>(uint16_t* to, const Packet4us& from) {
2712 EIGEN_DEBUG_ALIGNED_STORE vst1_u16(to, from);
2713}
2714template <>
2715EIGEN_STRONG_INLINE void pstore<uint16_t>(uint16_t* to, const Packet8us& from) {
2716 EIGEN_DEBUG_ALIGNED_STORE vst1q_u16(to, from);
2717}
2718template <>
2719EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet2i& from) {
2720 EIGEN_DEBUG_ALIGNED_STORE vst1_s32(to, from);
2721}
2722template <>
2723EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet4i& from) {
2724 EIGEN_DEBUG_ALIGNED_STORE vst1q_s32(to, from);
2725}
2726template <>
2727EIGEN_STRONG_INLINE void pstore<uint32_t>(uint32_t* to, const Packet2ui& from) {
2728 EIGEN_DEBUG_ALIGNED_STORE vst1_u32(to, from);
2729}
2730template <>
2731EIGEN_STRONG_INLINE void pstore<uint32_t>(uint32_t* to, const Packet4ui& from) {
2732 EIGEN_DEBUG_ALIGNED_STORE vst1q_u32(to, from);
2733}
2734template <>
2735EIGEN_STRONG_INLINE void pstore<int64_t>(int64_t* to, const Packet2l& from) {
2736 EIGEN_DEBUG_ALIGNED_STORE vst1q_s64(to, from);
2737}
2738template <>
2739EIGEN_STRONG_INLINE void pstore<uint64_t>(uint64_t* to, const Packet2ul& from) {
2740 EIGEN_DEBUG_ALIGNED_STORE vst1q_u64(to, from);
2741}
2742
2743template <>
2744EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet2f& from) {
2745 EIGEN_DEBUG_UNALIGNED_STORE vst1_f32(to, from);
2746}
2747template <>
2748EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) {
2749 EIGEN_DEBUG_UNALIGNED_STORE vst1q_f32(to, from);
2750}
2751template <>
2752EIGEN_STRONG_INLINE void pstoreu<int8_t>(int8_t* to, const Packet4c& from) {
2753 memcpy(to, &from, sizeof(from));
2754}
2755template <>
2756EIGEN_STRONG_INLINE void pstoreu<int8_t>(int8_t* to, const Packet8c& from) {
2757 EIGEN_DEBUG_UNALIGNED_STORE vst1_s8(to, from);
2758}
2759template <>
2760EIGEN_STRONG_INLINE void pstoreu<int8_t>(int8_t* to, const Packet16c& from) {
2761 EIGEN_DEBUG_UNALIGNED_STORE vst1q_s8(to, from);
2762}
2763template <>
2764EIGEN_STRONG_INLINE void pstoreu<uint8_t>(uint8_t* to, const Packet4uc& from) {
2765 memcpy(to, &from, sizeof(from));
2766}
2767template <>
2768EIGEN_STRONG_INLINE void pstoreu<uint8_t>(uint8_t* to, const Packet8uc& from) {
2769 EIGEN_DEBUG_UNALIGNED_STORE vst1_u8(to, from);
2770}
2771template <>
2772EIGEN_STRONG_INLINE void pstoreu<uint8_t>(uint8_t* to, const Packet16uc& from) {
2773 EIGEN_DEBUG_UNALIGNED_STORE vst1q_u8(to, from);
2774}
2775template <>
2776EIGEN_STRONG_INLINE void pstoreu<int16_t>(int16_t* to, const Packet4s& from) {
2777 EIGEN_DEBUG_UNALIGNED_STORE vst1_s16(to, from);
2778}
2779template <>
2780EIGEN_STRONG_INLINE void pstoreu<int16_t>(int16_t* to, const Packet8s& from) {
2781 EIGEN_DEBUG_UNALIGNED_STORE vst1q_s16(to, from);
2782}
2783template <>
2784EIGEN_STRONG_INLINE void pstoreu<uint16_t>(uint16_t* to, const Packet4us& from) {
2785 EIGEN_DEBUG_UNALIGNED_STORE vst1_u16(to, from);
2786}
2787template <>
2788EIGEN_STRONG_INLINE void pstoreu<uint16_t>(uint16_t* to, const Packet8us& from) {
2789 EIGEN_DEBUG_UNALIGNED_STORE vst1q_u16(to, from);
2790}
2791template <>
2792EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet2i& from) {
2793 EIGEN_DEBUG_UNALIGNED_STORE vst1_s32(to, from);
2794}
2795template <>
2796EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet4i& from) {
2797 EIGEN_DEBUG_UNALIGNED_STORE vst1q_s32(to, from);
2798}
2799template <>
2800EIGEN_STRONG_INLINE void pstoreu<uint32_t>(uint32_t* to, const Packet2ui& from) {
2801 EIGEN_DEBUG_UNALIGNED_STORE vst1_u32(to, from);
2802}
2803template <>
2804EIGEN_STRONG_INLINE void pstoreu<uint32_t>(uint32_t* to, const Packet4ui& from) {
2805 EIGEN_DEBUG_UNALIGNED_STORE vst1q_u32(to, from);
2806}
2807template <>
2808EIGEN_STRONG_INLINE void pstoreu<int64_t>(int64_t* to, const Packet2l& from) {
2809 EIGEN_DEBUG_UNALIGNED_STORE vst1q_s64(to, from);
2810}
2811template <>
2812EIGEN_STRONG_INLINE void pstoreu<uint64_t>(uint64_t* to, const Packet2ul& from) {
2813 EIGEN_DEBUG_UNALIGNED_STORE vst1q_u64(to, from);
2814}
2815
2816template <>
2817EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2f pgather<float, Packet2f>(const float* from, Index stride) {
2818 Packet2f res = vld1_dup_f32(from);
2819 res = vld1_lane_f32(from + 1 * stride, res, 1);
2820 return res;
2821}
2822template <>
2823EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4f pgather<float, Packet4f>(const float* from, Index stride) {
2824 Packet4f res = vld1q_dup_f32(from);
2825 res = vld1q_lane_f32(from + 1 * stride, res, 1);
2826 res = vld1q_lane_f32(from + 2 * stride, res, 2);
2827 res = vld1q_lane_f32(from + 3 * stride, res, 3);
2828 return res;
2829}
2830template <>
2831EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4c pgather<int8_t, Packet4c>(const int8_t* from, Index stride) {
2832 Packet4c res;
2833 for (int i = 0; i != 4; i++) reinterpret_cast<int8_t*>(&res)[i] = *(from + i * stride);
2834 return res;
2835}
2836template <>
2837EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8c pgather<int8_t, Packet8c>(const int8_t* from, Index stride) {
2838 Packet8c res = vld1_dup_s8(from);
2839 res = vld1_lane_s8(from + 1 * stride, res, 1);
2840 res = vld1_lane_s8(from + 2 * stride, res, 2);
2841 res = vld1_lane_s8(from + 3 * stride, res, 3);
2842 res = vld1_lane_s8(from + 4 * stride, res, 4);
2843 res = vld1_lane_s8(from + 5 * stride, res, 5);
2844 res = vld1_lane_s8(from + 6 * stride, res, 6);
2845 res = vld1_lane_s8(from + 7 * stride, res, 7);
2846 return res;
2847}
2848template <>
2849EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16c pgather<int8_t, Packet16c>(const int8_t* from, Index stride) {
2850 Packet16c res = vld1q_dup_s8(from);
2851 res = vld1q_lane_s8(from + 1 * stride, res, 1);
2852 res = vld1q_lane_s8(from + 2 * stride, res, 2);
2853 res = vld1q_lane_s8(from + 3 * stride, res, 3);
2854 res = vld1q_lane_s8(from + 4 * stride, res, 4);
2855 res = vld1q_lane_s8(from + 5 * stride, res, 5);
2856 res = vld1q_lane_s8(from + 6 * stride, res, 6);
2857 res = vld1q_lane_s8(from + 7 * stride, res, 7);
2858 res = vld1q_lane_s8(from + 8 * stride, res, 8);
2859 res = vld1q_lane_s8(from + 9 * stride, res, 9);
2860 res = vld1q_lane_s8(from + 10 * stride, res, 10);
2861 res = vld1q_lane_s8(from + 11 * stride, res, 11);
2862 res = vld1q_lane_s8(from + 12 * stride, res, 12);
2863 res = vld1q_lane_s8(from + 13 * stride, res, 13);
2864 res = vld1q_lane_s8(from + 14 * stride, res, 14);
2865 res = vld1q_lane_s8(from + 15 * stride, res, 15);
2866 return res;
2867}
2868template <>
2869EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4uc pgather<uint8_t, Packet4uc>(const uint8_t* from, Index stride) {
2870 Packet4uc res;
2871 for (int i = 0; i != 4; i++) reinterpret_cast<uint8_t*>(&res)[i] = *(from + i * stride);
2872 return res;
2873}
2874template <>
2875EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8uc pgather<uint8_t, Packet8uc>(const uint8_t* from, Index stride) {
2876 Packet8uc res = vld1_dup_u8(from);
2877 res = vld1_lane_u8(from + 1 * stride, res, 1);
2878 res = vld1_lane_u8(from + 2 * stride, res, 2);
2879 res = vld1_lane_u8(from + 3 * stride, res, 3);
2880 res = vld1_lane_u8(from + 4 * stride, res, 4);
2881 res = vld1_lane_u8(from + 5 * stride, res, 5);
2882 res = vld1_lane_u8(from + 6 * stride, res, 6);
2883 res = vld1_lane_u8(from + 7 * stride, res, 7);
2884 return res;
2885}
2886template <>
2887EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16uc pgather<uint8_t, Packet16uc>(const uint8_t* from, Index stride) {
2888 Packet16uc res = vld1q_dup_u8(from);
2889 res = vld1q_lane_u8(from + 1 * stride, res, 1);
2890 res = vld1q_lane_u8(from + 2 * stride, res, 2);
2891 res = vld1q_lane_u8(from + 3 * stride, res, 3);
2892 res = vld1q_lane_u8(from + 4 * stride, res, 4);
2893 res = vld1q_lane_u8(from + 5 * stride, res, 5);
2894 res = vld1q_lane_u8(from + 6 * stride, res, 6);
2895 res = vld1q_lane_u8(from + 7 * stride, res, 7);
2896 res = vld1q_lane_u8(from + 8 * stride, res, 8);
2897 res = vld1q_lane_u8(from + 9 * stride, res, 9);
2898 res = vld1q_lane_u8(from + 10 * stride, res, 10);
2899 res = vld1q_lane_u8(from + 11 * stride, res, 11);
2900 res = vld1q_lane_u8(from + 12 * stride, res, 12);
2901 res = vld1q_lane_u8(from + 13 * stride, res, 13);
2902 res = vld1q_lane_u8(from + 14 * stride, res, 14);
2903 res = vld1q_lane_u8(from + 15 * stride, res, 15);
2904 return res;
2905}
2906template <>
2907EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4s pgather<int16_t, Packet4s>(const int16_t* from, Index stride) {
2908 Packet4s res = vld1_dup_s16(from);
2909 res = vld1_lane_s16(from + 1 * stride, res, 1);
2910 res = vld1_lane_s16(from + 2 * stride, res, 2);
2911 res = vld1_lane_s16(from + 3 * stride, res, 3);
2912 return res;
2913}
2914template <>
2915EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8s pgather<int16_t, Packet8s>(const int16_t* from, Index stride) {
2916 Packet8s res = vld1q_dup_s16(from);
2917 res = vld1q_lane_s16(from + 1 * stride, res, 1);
2918 res = vld1q_lane_s16(from + 2 * stride, res, 2);
2919 res = vld1q_lane_s16(from + 3 * stride, res, 3);
2920 res = vld1q_lane_s16(from + 4 * stride, res, 4);
2921 res = vld1q_lane_s16(from + 5 * stride, res, 5);
2922 res = vld1q_lane_s16(from + 6 * stride, res, 6);
2923 res = vld1q_lane_s16(from + 7 * stride, res, 7);
2924 return res;
2925}
2926template <>
2927EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4us pgather<uint16_t, Packet4us>(const uint16_t* from, Index stride) {
2928 Packet4us res = vld1_dup_u16(from);
2929 res = vld1_lane_u16(from + 1 * stride, res, 1);
2930 res = vld1_lane_u16(from + 2 * stride, res, 2);
2931 res = vld1_lane_u16(from + 3 * stride, res, 3);
2932 return res;
2933}
2934template <>
2935EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8us pgather<uint16_t, Packet8us>(const uint16_t* from, Index stride) {
2936 Packet8us res = vld1q_dup_u16(from);
2937 res = vld1q_lane_u16(from + 1 * stride, res, 1);
2938 res = vld1q_lane_u16(from + 2 * stride, res, 2);
2939 res = vld1q_lane_u16(from + 3 * stride, res, 3);
2940 res = vld1q_lane_u16(from + 4 * stride, res, 4);
2941 res = vld1q_lane_u16(from + 5 * stride, res, 5);
2942 res = vld1q_lane_u16(from + 6 * stride, res, 6);
2943 res = vld1q_lane_u16(from + 7 * stride, res, 7);
2944 return res;
2945}
2946template <>
2947EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2i pgather<int32_t, Packet2i>(const int32_t* from, Index stride) {
2948 Packet2i res = vld1_dup_s32(from);
2949 res = vld1_lane_s32(from + 1 * stride, res, 1);
2950 return res;
2951}
2952template <>
2953EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4i pgather<int32_t, Packet4i>(const int32_t* from, Index stride) {
2954 Packet4i res = vld1q_dup_s32(from);
2955 res = vld1q_lane_s32(from + 1 * stride, res, 1);
2956 res = vld1q_lane_s32(from + 2 * stride, res, 2);
2957 res = vld1q_lane_s32(from + 3 * stride, res, 3);
2958 return res;
2959}
2960template <>
2961EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ui pgather<uint32_t, Packet2ui>(const uint32_t* from, Index stride) {
2962 Packet2ui res = vld1_dup_u32(from);
2963 res = vld1_lane_u32(from + 1 * stride, res, 1);
2964 return res;
2965}
2966template <>
2967EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4ui pgather<uint32_t, Packet4ui>(const uint32_t* from, Index stride) {
2968 Packet4ui res = vld1q_dup_u32(from);
2969 res = vld1q_lane_u32(from + 1 * stride, res, 1);
2970 res = vld1q_lane_u32(from + 2 * stride, res, 2);
2971 res = vld1q_lane_u32(from + 3 * stride, res, 3);
2972 return res;
2973}
2974template <>
2975EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2l pgather<int64_t, Packet2l>(const int64_t* from, Index stride) {
2976 Packet2l res = vld1q_dup_s64(from);
2977 res = vld1q_lane_s64(from + 1 * stride, res, 1);
2978 return res;
2979}
2980template <>
2981EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ul pgather<uint64_t, Packet2ul>(const uint64_t* from, Index stride) {
2982 Packet2ul res = vld1q_dup_u64(from);
2983 res = vld1q_lane_u64(from + 1 * stride, res, 1);
2984 return res;
2985}
2986
2987template <>
2988EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<float, Packet2f>(float* to, const Packet2f& from, Index stride) {
2989 vst1_lane_f32(to + stride * 0, from, 0);
2990 vst1_lane_f32(to + stride * 1, from, 1);
2991}
2992template <>
2993EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) {
2994 vst1q_lane_f32(to + stride * 0, from, 0);
2995 vst1q_lane_f32(to + stride * 1, from, 1);
2996 vst1q_lane_f32(to + stride * 2, from, 2);
2997 vst1q_lane_f32(to + stride * 3, from, 3);
2998}
2999template <>
3000EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int8_t, Packet4c>(int8_t* to, const Packet4c& from, Index stride) {
3001 for (int i = 0; i != 4; i++) *(to + i * stride) = reinterpret_cast<const int8_t*>(&from)[i];
3002}
3003template <>
3004EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int8_t, Packet8c>(int8_t* to, const Packet8c& from, Index stride) {
3005 vst1_lane_s8(to + stride * 0, from, 0);
3006 vst1_lane_s8(to + stride * 1, from, 1);
3007 vst1_lane_s8(to + stride * 2, from, 2);
3008 vst1_lane_s8(to + stride * 3, from, 3);
3009 vst1_lane_s8(to + stride * 4, from, 4);
3010 vst1_lane_s8(to + stride * 5, from, 5);
3011 vst1_lane_s8(to + stride * 6, from, 6);
3012 vst1_lane_s8(to + stride * 7, from, 7);
3013}
3014template <>
3015EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int8_t, Packet16c>(int8_t* to, const Packet16c& from,
3016 Index stride) {
3017 vst1q_lane_s8(to + stride * 0, from, 0);
3018 vst1q_lane_s8(to + stride * 1, from, 1);
3019 vst1q_lane_s8(to + stride * 2, from, 2);
3020 vst1q_lane_s8(to + stride * 3, from, 3);
3021 vst1q_lane_s8(to + stride * 4, from, 4);
3022 vst1q_lane_s8(to + stride * 5, from, 5);
3023 vst1q_lane_s8(to + stride * 6, from, 6);
3024 vst1q_lane_s8(to + stride * 7, from, 7);
3025 vst1q_lane_s8(to + stride * 8, from, 8);
3026 vst1q_lane_s8(to + stride * 9, from, 9);
3027 vst1q_lane_s8(to + stride * 10, from, 10);
3028 vst1q_lane_s8(to + stride * 11, from, 11);
3029 vst1q_lane_s8(to + stride * 12, from, 12);
3030 vst1q_lane_s8(to + stride * 13, from, 13);
3031 vst1q_lane_s8(to + stride * 14, from, 14);
3032 vst1q_lane_s8(to + stride * 15, from, 15);
3033}
3034template <>
3035EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint8_t, Packet4uc>(uint8_t* to, const Packet4uc& from,
3036 Index stride) {
3037 for (int i = 0; i != 4; i++) *(to + i * stride) = reinterpret_cast<const uint8_t*>(&from)[i];
3038}
3039template <>
3040EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint8_t, Packet8uc>(uint8_t* to, const Packet8uc& from,
3041 Index stride) {
3042 vst1_lane_u8(to + stride * 0, from, 0);
3043 vst1_lane_u8(to + stride * 1, from, 1);
3044 vst1_lane_u8(to + stride * 2, from, 2);
3045 vst1_lane_u8(to + stride * 3, from, 3);
3046 vst1_lane_u8(to + stride * 4, from, 4);
3047 vst1_lane_u8(to + stride * 5, from, 5);
3048 vst1_lane_u8(to + stride * 6, from, 6);
3049 vst1_lane_u8(to + stride * 7, from, 7);
3050}
3051template <>
3052EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint8_t, Packet16uc>(uint8_t* to, const Packet16uc& from,
3053 Index stride) {
3054 vst1q_lane_u8(to + stride * 0, from, 0);
3055 vst1q_lane_u8(to + stride * 1, from, 1);
3056 vst1q_lane_u8(to + stride * 2, from, 2);
3057 vst1q_lane_u8(to + stride * 3, from, 3);
3058 vst1q_lane_u8(to + stride * 4, from, 4);
3059 vst1q_lane_u8(to + stride * 5, from, 5);
3060 vst1q_lane_u8(to + stride * 6, from, 6);
3061 vst1q_lane_u8(to + stride * 7, from, 7);
3062 vst1q_lane_u8(to + stride * 8, from, 8);
3063 vst1q_lane_u8(to + stride * 9, from, 9);
3064 vst1q_lane_u8(to + stride * 10, from, 10);
3065 vst1q_lane_u8(to + stride * 11, from, 11);
3066 vst1q_lane_u8(to + stride * 12, from, 12);
3067 vst1q_lane_u8(to + stride * 13, from, 13);
3068 vst1q_lane_u8(to + stride * 14, from, 14);
3069 vst1q_lane_u8(to + stride * 15, from, 15);
3070}
3071template <>
3072EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int16_t, Packet4s>(int16_t* to, const Packet4s& from,
3073 Index stride) {
3074 vst1_lane_s16(to + stride * 0, from, 0);
3075 vst1_lane_s16(to + stride * 1, from, 1);
3076 vst1_lane_s16(to + stride * 2, from, 2);
3077 vst1_lane_s16(to + stride * 3, from, 3);
3078}
3079template <>
3080EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int16_t, Packet8s>(int16_t* to, const Packet8s& from,
3081 Index stride) {
3082 vst1q_lane_s16(to + stride * 0, from, 0);
3083 vst1q_lane_s16(to + stride * 1, from, 1);
3084 vst1q_lane_s16(to + stride * 2, from, 2);
3085 vst1q_lane_s16(to + stride * 3, from, 3);
3086 vst1q_lane_s16(to + stride * 4, from, 4);
3087 vst1q_lane_s16(to + stride * 5, from, 5);
3088 vst1q_lane_s16(to + stride * 6, from, 6);
3089 vst1q_lane_s16(to + stride * 7, from, 7);
3090}
3091template <>
3092EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint16_t, Packet4us>(uint16_t* to, const Packet4us& from,
3093 Index stride) {
3094 vst1_lane_u16(to + stride * 0, from, 0);
3095 vst1_lane_u16(to + stride * 1, from, 1);
3096 vst1_lane_u16(to + stride * 2, from, 2);
3097 vst1_lane_u16(to + stride * 3, from, 3);
3098}
3099template <>
3100EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint16_t, Packet8us>(uint16_t* to, const Packet8us& from,
3101 Index stride) {
3102 vst1q_lane_u16(to + stride * 0, from, 0);
3103 vst1q_lane_u16(to + stride * 1, from, 1);
3104 vst1q_lane_u16(to + stride * 2, from, 2);
3105 vst1q_lane_u16(to + stride * 3, from, 3);
3106 vst1q_lane_u16(to + stride * 4, from, 4);
3107 vst1q_lane_u16(to + stride * 5, from, 5);
3108 vst1q_lane_u16(to + stride * 6, from, 6);
3109 vst1q_lane_u16(to + stride * 7, from, 7);
3110}
3111template <>
3112EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int32_t, Packet2i>(int32_t* to, const Packet2i& from,
3113 Index stride) {
3114 vst1_lane_s32(to + stride * 0, from, 0);
3115 vst1_lane_s32(to + stride * 1, from, 1);
3116}
3117template <>
3118EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int32_t, Packet4i>(int32_t* to, const Packet4i& from,
3119 Index stride) {
3120 vst1q_lane_s32(to + stride * 0, from, 0);
3121 vst1q_lane_s32(to + stride * 1, from, 1);
3122 vst1q_lane_s32(to + stride * 2, from, 2);
3123 vst1q_lane_s32(to + stride * 3, from, 3);
3124}
3125template <>
3126EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint32_t, Packet2ui>(uint32_t* to, const Packet2ui& from,
3127 Index stride) {
3128 vst1_lane_u32(to + stride * 0, from, 0);
3129 vst1_lane_u32(to + stride * 1, from, 1);
3130}
3131template <>
3132EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint32_t, Packet4ui>(uint32_t* to, const Packet4ui& from,
3133 Index stride) {
3134 vst1q_lane_u32(to + stride * 0, from, 0);
3135 vst1q_lane_u32(to + stride * 1, from, 1);
3136 vst1q_lane_u32(to + stride * 2, from, 2);
3137 vst1q_lane_u32(to + stride * 3, from, 3);
3138}
3139template <>
3140EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int64_t, Packet2l>(int64_t* to, const Packet2l& from,
3141 Index stride) {
3142 vst1q_lane_s64(to + stride * 0, from, 0);
3143 vst1q_lane_s64(to + stride * 1, from, 1);
3144}
3145template <>
3146EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint64_t, Packet2ul>(uint64_t* to, const Packet2ul& from,
3147 Index stride) {
3148 vst1q_lane_u64(to + stride * 0, from, 0);
3149 vst1q_lane_u64(to + stride * 1, from, 1);
3150}
3151
3152template <>
3153EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) {
3154 EIGEN_ARM_PREFETCH(addr);
3155}
3156template <>
3157EIGEN_STRONG_INLINE void prefetch<int8_t>(const int8_t* addr) {
3158 EIGEN_ARM_PREFETCH(addr);
3159}
3160template <>
3161EIGEN_STRONG_INLINE void prefetch<uint8_t>(const uint8_t* addr) {
3162 EIGEN_ARM_PREFETCH(addr);
3163}
3164template <>
3165EIGEN_STRONG_INLINE void prefetch<int16_t>(const int16_t* addr) {
3166 EIGEN_ARM_PREFETCH(addr);
3167}
3168template <>
3169EIGEN_STRONG_INLINE void prefetch<uint16_t>(const uint16_t* addr) {
3170 EIGEN_ARM_PREFETCH(addr);
3171}
3172template <>
3173EIGEN_STRONG_INLINE void prefetch<int32_t>(const int32_t* addr) {
3174 EIGEN_ARM_PREFETCH(addr);
3175}
3176template <>
3177EIGEN_STRONG_INLINE void prefetch<uint32_t>(const uint32_t* addr) {
3178 EIGEN_ARM_PREFETCH(addr);
3179}
3180template <>
3181EIGEN_STRONG_INLINE void prefetch<int64_t>(const int64_t* addr) {
3182 EIGEN_ARM_PREFETCH(addr);
3183}
3184template <>
3185EIGEN_STRONG_INLINE void prefetch<uint64_t>(const uint64_t* addr) {
3186 EIGEN_ARM_PREFETCH(addr);
3187}
3188
3189template <>
3190EIGEN_STRONG_INLINE float pfirst<Packet2f>(const Packet2f& a) {
3191 return vget_lane_f32(a, 0);
3192}
3193template <>
3194EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) {
3195 return vgetq_lane_f32(a, 0);
3196}
3197template <>
3198EIGEN_STRONG_INLINE int8_t pfirst<Packet4c>(const Packet4c& a) {
3199 return static_cast<int8_t>(a & 0xff);
3200}
3201template <>
3202EIGEN_STRONG_INLINE int8_t pfirst<Packet8c>(const Packet8c& a) {
3203 return vget_lane_s8(a, 0);
3204}
3205template <>
3206EIGEN_STRONG_INLINE int8_t pfirst<Packet16c>(const Packet16c& a) {
3207 return vgetq_lane_s8(a, 0);
3208}
3209template <>
3210EIGEN_STRONG_INLINE uint8_t pfirst<Packet4uc>(const Packet4uc& a) {
3211 return static_cast<uint8_t>(a & 0xff);
3212}
3213template <>
3214EIGEN_STRONG_INLINE uint8_t pfirst<Packet8uc>(const Packet8uc& a) {
3215 return vget_lane_u8(a, 0);
3216}
3217template <>
3218EIGEN_STRONG_INLINE uint8_t pfirst<Packet16uc>(const Packet16uc& a) {
3219 return vgetq_lane_u8(a, 0);
3220}
3221template <>
3222EIGEN_STRONG_INLINE int16_t pfirst<Packet4s>(const Packet4s& a) {
3223 return vget_lane_s16(a, 0);
3224}
3225template <>
3226EIGEN_STRONG_INLINE int16_t pfirst<Packet8s>(const Packet8s& a) {
3227 return vgetq_lane_s16(a, 0);
3228}
3229template <>
3230EIGEN_STRONG_INLINE uint16_t pfirst<Packet4us>(const Packet4us& a) {
3231 return vget_lane_u16(a, 0);
3232}
3233template <>
3234EIGEN_STRONG_INLINE uint16_t pfirst<Packet8us>(const Packet8us& a) {
3235 return vgetq_lane_u16(a, 0);
3236}
3237template <>
3238EIGEN_STRONG_INLINE int32_t pfirst<Packet2i>(const Packet2i& a) {
3239 return vget_lane_s32(a, 0);
3240}
3241template <>
3242EIGEN_STRONG_INLINE int32_t pfirst<Packet4i>(const Packet4i& a) {
3243 return vgetq_lane_s32(a, 0);
3244}
3245template <>
3246EIGEN_STRONG_INLINE uint32_t pfirst<Packet2ui>(const Packet2ui& a) {
3247 return vget_lane_u32(a, 0);
3248}
3249template <>
3250EIGEN_STRONG_INLINE uint32_t pfirst<Packet4ui>(const Packet4ui& a) {
3251 return vgetq_lane_u32(a, 0);
3252}
3253template <>
3254EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(const Packet2l& a) {
3255 return vgetq_lane_s64(a, 0);
3256}
3257template <>
3258EIGEN_STRONG_INLINE uint64_t pfirst<Packet2ul>(const Packet2ul& a) {
3259 return vgetq_lane_u64(a, 0);
3260}
3261
3262template <>
3263EIGEN_STRONG_INLINE Packet2f preverse(const Packet2f& a) {
3264 return vrev64_f32(a);
3265}
3266template <>
3267EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) {
3268 const float32x4_t a_r64 = vrev64q_f32(a);
3269 return vcombine_f32(vget_high_f32(a_r64), vget_low_f32(a_r64));
3270}
3271template <>
3272EIGEN_STRONG_INLINE Packet4c preverse(const Packet4c& a) {
3273 return vget_lane_s32(vreinterpret_s32_s8(vrev64_s8(vreinterpret_s8_s32(vdup_n_s32(a)))), 0);
3274}
3275template <>
3276EIGEN_STRONG_INLINE Packet8c preverse(const Packet8c& a) {
3277 return vrev64_s8(a);
3278}
3279template <>
3280EIGEN_STRONG_INLINE Packet16c preverse(const Packet16c& a) {
3281 const int8x16_t a_r64 = vrev64q_s8(a);
3282 return vcombine_s8(vget_high_s8(a_r64), vget_low_s8(a_r64));
3283}
3284template <>
3285EIGEN_STRONG_INLINE Packet4uc preverse(const Packet4uc& a) {
3286 return vget_lane_u32(vreinterpret_u32_u8(vrev64_u8(vreinterpret_u8_u32(vdup_n_u32(a)))), 0);
3287}
3288template <>
3289EIGEN_STRONG_INLINE Packet8uc preverse(const Packet8uc& a) {
3290 return vrev64_u8(a);
3291}
3292template <>
3293EIGEN_STRONG_INLINE Packet16uc preverse(const Packet16uc& a) {
3294 const uint8x16_t a_r64 = vrev64q_u8(a);
3295 return vcombine_u8(vget_high_u8(a_r64), vget_low_u8(a_r64));
3296}
3297template <>
3298EIGEN_STRONG_INLINE Packet4s preverse(const Packet4s& a) {
3299 return vrev64_s16(a);
3300}
3301template <>
3302EIGEN_STRONG_INLINE Packet8s preverse(const Packet8s& a) {
3303 const int16x8_t a_r64 = vrev64q_s16(a);
3304 return vcombine_s16(vget_high_s16(a_r64), vget_low_s16(a_r64));
3305}
3306template <>
3307EIGEN_STRONG_INLINE Packet4us preverse(const Packet4us& a) {
3308 return vrev64_u16(a);
3309}
3310template <>
3311EIGEN_STRONG_INLINE Packet8us preverse(const Packet8us& a) {
3312 const uint16x8_t a_r64 = vrev64q_u16(a);
3313 return vcombine_u16(vget_high_u16(a_r64), vget_low_u16(a_r64));
3314}
3315template <>
3316EIGEN_STRONG_INLINE Packet2i preverse(const Packet2i& a) {
3317 return vrev64_s32(a);
3318}
3319template <>
3320EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) {
3321 const int32x4_t a_r64 = vrev64q_s32(a);
3322 return vcombine_s32(vget_high_s32(a_r64), vget_low_s32(a_r64));
3323}
3324template <>
3325EIGEN_STRONG_INLINE Packet2ui preverse(const Packet2ui& a) {
3326 return vrev64_u32(a);
3327}
3328template <>
3329EIGEN_STRONG_INLINE Packet4ui preverse(const Packet4ui& a) {
3330 const uint32x4_t a_r64 = vrev64q_u32(a);
3331 return vcombine_u32(vget_high_u32(a_r64), vget_low_u32(a_r64));
3332}
3333template <>
3334EIGEN_STRONG_INLINE Packet2l preverse(const Packet2l& a) {
3335 return vcombine_s64(vget_high_s64(a), vget_low_s64(a));
3336}
3337template <>
3338EIGEN_STRONG_INLINE Packet2ul preverse(const Packet2ul& a) {
3339 return vcombine_u64(vget_high_u64(a), vget_low_u64(a));
3340}
3341
3342template <>
3343EIGEN_STRONG_INLINE Packet2f pabs(const Packet2f& a) {
3344 return vabs_f32(a);
3345}
3346template <>
3347EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) {
3348 return vabsq_f32(a);
3349}
3350template <>
3351EIGEN_STRONG_INLINE Packet4c pabs<Packet4c>(const Packet4c& a) {
3352 return vget_lane_s32(vreinterpret_s32_s8(vabs_s8(vreinterpret_s8_s32(vdup_n_s32(a)))), 0);
3353}
3354template <>
3355EIGEN_STRONG_INLINE Packet8c pabs(const Packet8c& a) {
3356 return vabs_s8(a);
3357}
3358template <>
3359EIGEN_STRONG_INLINE Packet16c pabs(const Packet16c& a) {
3360 return vabsq_s8(a);
3361}
3362template <>
3363EIGEN_STRONG_INLINE Packet4uc pabs(const Packet4uc& a) {
3364 return a;
3365}
3366template <>
3367EIGEN_STRONG_INLINE Packet8uc pabs(const Packet8uc& a) {
3368 return a;
3369}
3370template <>
3371EIGEN_STRONG_INLINE Packet16uc pabs(const Packet16uc& a) {
3372 return a;
3373}
3374template <>
3375EIGEN_STRONG_INLINE Packet4s pabs(const Packet4s& a) {
3376 return vabs_s16(a);
3377}
3378template <>
3379EIGEN_STRONG_INLINE Packet8s pabs(const Packet8s& a) {
3380 return vabsq_s16(a);
3381}
3382template <>
3383EIGEN_STRONG_INLINE Packet4us pabs(const Packet4us& a) {
3384 return a;
3385}
3386template <>
3387EIGEN_STRONG_INLINE Packet8us pabs(const Packet8us& a) {
3388 return a;
3389}
3390template <>
3391EIGEN_STRONG_INLINE Packet2i pabs(const Packet2i& a) {
3392 return vabs_s32(a);
3393}
3394template <>
3395EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) {
3396 return vabsq_s32(a);
3397}
3398template <>
3399EIGEN_STRONG_INLINE Packet2ui pabs(const Packet2ui& a) {
3400 return a;
3401}
3402template <>
3403EIGEN_STRONG_INLINE Packet4ui pabs(const Packet4ui& a) {
3404 return a;
3405}
3406template <>
3407EIGEN_STRONG_INLINE Packet2l pabs(const Packet2l& a) {
3408#if EIGEN_ARCH_ARM64
3409 return vabsq_s64(a);
3410#else
3411 return vcombine_s64(vdup_n_s64((std::abs)(vgetq_lane_s64(a, 0))), vdup_n_s64((std::abs)(vgetq_lane_s64(a, 1))));
3412#endif
3413}
3414template <>
3415EIGEN_STRONG_INLINE Packet2ul pabs(const Packet2ul& a) {
3416 return a;
3417}
3418
3419template <>
3420EIGEN_STRONG_INLINE Packet2f psignbit(const Packet2f& a) {
3421 return vreinterpret_f32_s32(vshr_n_s32(vreinterpret_s32_f32(a), 31));
3422}
3423template <>
3424EIGEN_STRONG_INLINE Packet4f psignbit(const Packet4f& a) {
3425 return vreinterpretq_f32_s32(vshrq_n_s32(vreinterpretq_s32_f32(a), 31));
3426}
3427
3428template <>
3429EIGEN_STRONG_INLINE Packet2f pfrexp<Packet2f>(const Packet2f& a, Packet2f& exponent) {
3430 return pfrexp_generic(a, exponent);
3431}
3432template <>
3433EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) {
3434 return pfrexp_generic(a, exponent);
3435}
3436
3437template <>
3438EIGEN_STRONG_INLINE Packet2f pldexp<Packet2f>(const Packet2f& a, const Packet2f& exponent) {
3439 return pldexp_generic(a, exponent);
3440}
3441template <>
3442EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) {
3443 return pldexp_generic(a, exponent);
3444}
3445
3446#if EIGEN_ARCH_ARM64
3447template <>
3448EIGEN_STRONG_INLINE float predux<Packet2f>(const Packet2f& a) {
3449 return vaddv_f32(a);
3450}
3451template <>
3452EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) {
3453 return vaddvq_f32(a);
3454}
3455#else
3456template <>
3457EIGEN_STRONG_INLINE float predux<Packet2f>(const Packet2f& a) {
3458 return vget_lane_f32(vpadd_f32(a, a), 0);
3459}
3460template <>
3461EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) {
3462 const float32x2_t sum = vadd_f32(vget_low_f32(a), vget_high_f32(a));
3463 return vget_lane_f32(vpadd_f32(sum, sum), 0);
3464}
3465#endif
3466template <>
3467EIGEN_STRONG_INLINE int8_t predux<Packet4c>(const Packet4c& a) {
3468 const int8x8_t a_dup = vreinterpret_s8_s32(vdup_n_s32(a));
3469 int8x8_t sum = vpadd_s8(a_dup, a_dup);
3470 sum = vpadd_s8(sum, sum);
3471 return vget_lane_s8(sum, 0);
3472}
3473#if EIGEN_ARCH_ARM64
3474template <>
3475EIGEN_STRONG_INLINE int8_t predux<Packet8c>(const Packet8c& a) {
3476 return vaddv_s8(a);
3477}
3478template <>
3479EIGEN_STRONG_INLINE int8_t predux<Packet16c>(const Packet16c& a) {
3480 return vaddvq_s8(a);
3481}
3482#else
3483template <>
3484EIGEN_STRONG_INLINE int8_t predux<Packet8c>(const Packet8c& a) {
3485 int8x8_t sum = vpadd_s8(a, a);
3486 sum = vpadd_s8(sum, sum);
3487 sum = vpadd_s8(sum, sum);
3488 return vget_lane_s8(sum, 0);
3489}
3490template <>
3491EIGEN_STRONG_INLINE int8_t predux<Packet16c>(const Packet16c& a) {
3492 int8x8_t sum = vadd_s8(vget_low_s8(a), vget_high_s8(a));
3493 sum = vpadd_s8(sum, sum);
3494 sum = vpadd_s8(sum, sum);
3495 sum = vpadd_s8(sum, sum);
3496 return vget_lane_s8(sum, 0);
3497}
3498#endif
3499template <>
3500EIGEN_STRONG_INLINE uint8_t predux<Packet4uc>(const Packet4uc& a) {
3501 const uint8x8_t a_dup = vreinterpret_u8_u32(vdup_n_u32(a));
3502 uint8x8_t sum = vpadd_u8(a_dup, a_dup);
3503 sum = vpadd_u8(sum, sum);
3504 return vget_lane_u8(sum, 0);
3505}
3506#if EIGEN_ARCH_ARM64
3507template <>
3508EIGEN_STRONG_INLINE uint8_t predux<Packet8uc>(const Packet8uc& a) {
3509 return vaddv_u8(a);
3510}
3511template <>
3512EIGEN_STRONG_INLINE uint8_t predux<Packet16uc>(const Packet16uc& a) {
3513 return vaddvq_u8(a);
3514}
3515template <>
3516EIGEN_STRONG_INLINE int16_t predux<Packet4s>(const Packet4s& a) {
3517 return vaddv_s16(a);
3518}
3519template <>
3520EIGEN_STRONG_INLINE int16_t predux<Packet8s>(const Packet8s& a) {
3521 return vaddvq_s16(a);
3522}
3523template <>
3524EIGEN_STRONG_INLINE uint16_t predux<Packet4us>(const Packet4us& a) {
3525 return vaddv_u16(a);
3526}
3527template <>
3528EIGEN_STRONG_INLINE uint16_t predux<Packet8us>(const Packet8us& a) {
3529 return vaddvq_u16(a);
3530}
3531template <>
3532EIGEN_STRONG_INLINE int32_t predux<Packet2i>(const Packet2i& a) {
3533 return vaddv_s32(a);
3534}
3535template <>
3536EIGEN_STRONG_INLINE int32_t predux<Packet4i>(const Packet4i& a) {
3537 return vaddvq_s32(a);
3538}
3539template <>
3540EIGEN_STRONG_INLINE uint32_t predux<Packet2ui>(const Packet2ui& a) {
3541 return vaddv_u32(a);
3542}
3543template <>
3544EIGEN_STRONG_INLINE uint32_t predux<Packet4ui>(const Packet4ui& a) {
3545 return vaddvq_u32(a);
3546}
3547template <>
3548EIGEN_STRONG_INLINE int64_t predux<Packet2l>(const Packet2l& a) {
3549 return vaddvq_s64(a);
3550}
3551template <>
3552EIGEN_STRONG_INLINE uint64_t predux<Packet2ul>(const Packet2ul& a) {
3553 return vaddvq_u64(a);
3554}
3555#else
3556template <>
3557EIGEN_STRONG_INLINE uint8_t predux<Packet8uc>(const Packet8uc& a) {
3558 uint8x8_t sum = vpadd_u8(a, a);
3559 sum = vpadd_u8(sum, sum);
3560 sum = vpadd_u8(sum, sum);
3561 return vget_lane_u8(sum, 0);
3562}
3563template <>
3564EIGEN_STRONG_INLINE uint8_t predux<Packet16uc>(const Packet16uc& a) {
3565 uint8x8_t sum = vadd_u8(vget_low_u8(a), vget_high_u8(a));
3566 sum = vpadd_u8(sum, sum);
3567 sum = vpadd_u8(sum, sum);
3568 sum = vpadd_u8(sum, sum);
3569 return vget_lane_u8(sum, 0);
3570}
3571template <>
3572EIGEN_STRONG_INLINE int16_t predux<Packet4s>(const Packet4s& a) {
3573 const int16x4_t sum = vpadd_s16(a, a);
3574 return vget_lane_s16(vpadd_s16(sum, sum), 0);
3575}
3576template <>
3577EIGEN_STRONG_INLINE int16_t predux<Packet8s>(const Packet8s& a) {
3578 int16x4_t sum = vadd_s16(vget_low_s16(a), vget_high_s16(a));
3579 sum = vpadd_s16(sum, sum);
3580 sum = vpadd_s16(sum, sum);
3581 return vget_lane_s16(sum, 0);
3582}
3583template <>
3584EIGEN_STRONG_INLINE uint16_t predux<Packet4us>(const Packet4us& a) {
3585 const uint16x4_t sum = vpadd_u16(a, a);
3586 return vget_lane_u16(vpadd_u16(sum, sum), 0);
3587}
3588template <>
3589EIGEN_STRONG_INLINE uint16_t predux<Packet8us>(const Packet8us& a) {
3590 uint16x4_t sum = vadd_u16(vget_low_u16(a), vget_high_u16(a));
3591 sum = vpadd_u16(sum, sum);
3592 sum = vpadd_u16(sum, sum);
3593 return vget_lane_u16(sum, 0);
3594}
3595template <>
3596EIGEN_STRONG_INLINE int32_t predux<Packet2i>(const Packet2i& a) {
3597 return vget_lane_s32(vpadd_s32(a, a), 0);
3598}
3599template <>
3600EIGEN_STRONG_INLINE int32_t predux<Packet4i>(const Packet4i& a) {
3601 const int32x2_t sum = vadd_s32(vget_low_s32(a), vget_high_s32(a));
3602 return vget_lane_s32(vpadd_s32(sum, sum), 0);
3603}
3604template <>
3605EIGEN_STRONG_INLINE uint32_t predux<Packet2ui>(const Packet2ui& a) {
3606 return vget_lane_u32(vpadd_u32(a, a), 0);
3607}
3608template <>
3609EIGEN_STRONG_INLINE uint32_t predux<Packet4ui>(const Packet4ui& a) {
3610 const uint32x2_t sum = vadd_u32(vget_low_u32(a), vget_high_u32(a));
3611 return vget_lane_u32(vpadd_u32(sum, sum), 0);
3612}
3613template <>
3614EIGEN_STRONG_INLINE int64_t predux<Packet2l>(const Packet2l& a) {
3615 return vgetq_lane_s64(a, 0) + vgetq_lane_s64(a, 1);
3616}
3617template <>
3618EIGEN_STRONG_INLINE uint64_t predux<Packet2ul>(const Packet2ul& a) {
3619 return vgetq_lane_u64(a, 0) + vgetq_lane_u64(a, 1);
3620}
3621#endif
3622
3623template <>
3624EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4c predux_half_dowto4(const Packet8c& a) {
3625 return vget_lane_s32(vreinterpret_s32_s8(vadd_s8(a, vreinterpret_s8_s32(vrev64_s32(vreinterpret_s32_s8(a))))), 0);
3626}
3627template <>
3628EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8c predux_half_dowto4(const Packet16c& a) {
3629 return vadd_s8(vget_high_s8(a), vget_low_s8(a));
3630}
3631template <>
3632EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4uc predux_half_dowto4(const Packet8uc& a) {
3633 return vget_lane_u32(vreinterpret_u32_u8(vadd_u8(a, vreinterpret_u8_u32(vrev64_u32(vreinterpret_u32_u8(a))))), 0);
3634}
3635template <>
3636EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8uc predux_half_dowto4(const Packet16uc& a) {
3637 return vadd_u8(vget_high_u8(a), vget_low_u8(a));
3638}
3639template <>
3640EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4s predux_half_dowto4(const Packet8s& a) {
3641 return vadd_s16(vget_high_s16(a), vget_low_s16(a));
3642}
3643template <>
3644EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4us predux_half_dowto4(const Packet8us& a) {
3645 return vadd_u16(vget_high_u16(a), vget_low_u16(a));
3646}
3647
3648// Other reduction functions:
3649// mul
3650template <>
3651EIGEN_STRONG_INLINE float predux_mul<Packet2f>(const Packet2f& a) {
3652 return vget_lane_f32(a, 0) * vget_lane_f32(a, 1);
3653}
3654template <>
3655EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) {
3656 return predux_mul<Packet2f>(vmul_f32(vget_low_f32(a), vget_high_f32(a)));
3657}
3658template <>
3659EIGEN_STRONG_INLINE int8_t predux_mul<Packet4c>(const Packet4c& a) {
3660 int8x8_t prod = vreinterpret_s8_s32(vdup_n_s32(a));
3661 prod = vmul_s8(prod, vrev16_s8(prod));
3662 return vget_lane_s8(prod, 0) * vget_lane_s8(prod, 2);
3663}
3664template <>
3665EIGEN_STRONG_INLINE int8_t predux_mul<Packet8c>(const Packet8c& a) {
3666 int8x8_t prod = vmul_s8(a, vrev16_s8(a));
3667 prod = vmul_s8(prod, vrev32_s8(prod));
3668 return vget_lane_s8(prod, 0) * vget_lane_s8(prod, 4);
3669}
3670template <>
3671EIGEN_STRONG_INLINE int8_t predux_mul<Packet16c>(const Packet16c& a) {
3672 return predux_mul<Packet8c>(vmul_s8(vget_low_s8(a), vget_high_s8(a)));
3673}
3674template <>
3675EIGEN_STRONG_INLINE uint8_t predux_mul<Packet4uc>(const Packet4uc& a) {
3676 uint8x8_t prod = vreinterpret_u8_u32(vdup_n_u32(a));
3677 prod = vmul_u8(prod, vrev16_u8(prod));
3678 return vget_lane_u8(prod, 0) * vget_lane_u8(prod, 2);
3679}
3680template <>
3681EIGEN_STRONG_INLINE uint8_t predux_mul<Packet8uc>(const Packet8uc& a) {
3682 uint8x8_t prod = vmul_u8(a, vrev16_u8(a));
3683 prod = vmul_u8(prod, vrev32_u8(prod));
3684 return vget_lane_u8(prod, 0) * vget_lane_u8(prod, 4);
3685}
3686template <>
3687EIGEN_STRONG_INLINE uint8_t predux_mul<Packet16uc>(const Packet16uc& a) {
3688 return predux_mul<Packet8uc>(vmul_u8(vget_low_u8(a), vget_high_u8(a)));
3689}
3690template <>
3691EIGEN_STRONG_INLINE int16_t predux_mul<Packet4s>(const Packet4s& a) {
3692 const int16x4_t prod = vmul_s16(a, vrev32_s16(a));
3693 return vget_lane_s16(prod, 0) * vget_lane_s16(prod, 2);
3694}
3695template <>
3696EIGEN_STRONG_INLINE int16_t predux_mul<Packet8s>(const Packet8s& a) {
3697 int16x4_t prod;
3698
3699 // Get the product of a_lo * a_hi -> |a1*a5|a2*a6|a3*a7|a4*a8|
3700 prod = vmul_s16(vget_low_s16(a), vget_high_s16(a));
3701 // Swap and multiply |a1*a5*a2*a6|a3*a7*a4*a8|
3702 prod = vmul_s16(prod, vrev32_s16(prod));
3703 // Multiply |a1*a5*a2*a6*a3*a7*a4*a8|
3704 return vget_lane_s16(prod, 0) * vget_lane_s16(prod, 2);
3705}
3706template <>
3707EIGEN_STRONG_INLINE uint16_t predux_mul<Packet4us>(const Packet4us& a) {
3708 const uint16x4_t prod = vmul_u16(a, vrev32_u16(a));
3709 return vget_lane_u16(prod, 0) * vget_lane_u16(prod, 2);
3710}
3711template <>
3712EIGEN_STRONG_INLINE uint16_t predux_mul<Packet8us>(const Packet8us& a) {
3713 uint16x4_t prod;
3714
3715 // Get the product of a_lo * a_hi -> |a1*a5|a2*a6|a3*a7|a4*a8|
3716 prod = vmul_u16(vget_low_u16(a), vget_high_u16(a));
3717 // Swap and multiply |a1*a5*a2*a6|a3*a7*a4*a8|
3718 prod = vmul_u16(prod, vrev32_u16(prod));
3719 // Multiply |a1*a5*a2*a6*a3*a7*a4*a8|
3720 return vget_lane_u16(prod, 0) * vget_lane_u16(prod, 2);
3721}
3722template <>
3723EIGEN_STRONG_INLINE int32_t predux_mul<Packet2i>(const Packet2i& a) {
3724 return vget_lane_s32(a, 0) * vget_lane_s32(a, 1);
3725}
3726template <>
3727EIGEN_STRONG_INLINE int32_t predux_mul<Packet4i>(const Packet4i& a) {
3728 return predux_mul<Packet2i>(vmul_s32(vget_low_s32(a), vget_high_s32(a)));
3729}
3730template <>
3731EIGEN_STRONG_INLINE uint32_t predux_mul<Packet2ui>(const Packet2ui& a) {
3732 return vget_lane_u32(a, 0) * vget_lane_u32(a, 1);
3733}
3734template <>
3735EIGEN_STRONG_INLINE uint32_t predux_mul<Packet4ui>(const Packet4ui& a) {
3736 return predux_mul<Packet2ui>(vmul_u32(vget_low_u32(a), vget_high_u32(a)));
3737}
3738template <>
3739EIGEN_STRONG_INLINE int64_t predux_mul<Packet2l>(const Packet2l& a) {
3740 return vgetq_lane_s64(a, 0) * vgetq_lane_s64(a, 1);
3741}
3742template <>
3743EIGEN_STRONG_INLINE uint64_t predux_mul<Packet2ul>(const Packet2ul& a) {
3744 return vgetq_lane_u64(a, 0) * vgetq_lane_u64(a, 1);
3745}
3746
3747// min
3748#if EIGEN_ARCH_ARM64
3749template <>
3750EIGEN_STRONG_INLINE float predux_min<Packet2f>(const Packet2f& a) {
3751 return vminv_f32(a);
3752}
3753template <>
3754EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) {
3755 return vminvq_f32(a);
3756}
3757#else
3758template <>
3759EIGEN_STRONG_INLINE float predux_min<Packet2f>(const Packet2f& a) {
3760 return vget_lane_f32(vpmin_f32(a, a), 0);
3761}
3762template <>
3763EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) {
3764 const float32x2_t min = vmin_f32(vget_low_f32(a), vget_high_f32(a));
3765 return vget_lane_f32(vpmin_f32(min, min), 0);
3766}
3767#endif
3768template <>
3769EIGEN_STRONG_INLINE int8_t predux_min<Packet4c>(const Packet4c& a) {
3770 const int8x8_t a_dup = vreinterpret_s8_s32(vdup_n_s32(a));
3771 int8x8_t min = vpmin_s8(a_dup, a_dup);
3772 min = vpmin_s8(min, min);
3773 return vget_lane_s8(min, 0);
3774}
3775#if EIGEN_ARCH_ARM64
3776template <>
3777EIGEN_STRONG_INLINE int8_t predux_min<Packet8c>(const Packet8c& a) {
3778 return vminv_s8(a);
3779}
3780template <>
3781EIGEN_STRONG_INLINE int8_t predux_min<Packet16c>(const Packet16c& a) {
3782 return vminvq_s8(a);
3783}
3784#else
3785template <>
3786EIGEN_STRONG_INLINE int8_t predux_min<Packet8c>(const Packet8c& a) {
3787 int8x8_t min = vpmin_s8(a, a);
3788 min = vpmin_s8(min, min);
3789 min = vpmin_s8(min, min);
3790 return vget_lane_s8(min, 0);
3791}
3792template <>
3793EIGEN_STRONG_INLINE int8_t predux_min<Packet16c>(const Packet16c& a) {
3794 int8x8_t min = vmin_s8(vget_low_s8(a), vget_high_s8(a));
3795 min = vpmin_s8(min, min);
3796 min = vpmin_s8(min, min);
3797 min = vpmin_s8(min, min);
3798 return vget_lane_s8(min, 0);
3799}
3800#endif
3801template <>
3802EIGEN_STRONG_INLINE uint8_t predux_min<Packet4uc>(const Packet4uc& a) {
3803 const uint8x8_t a_dup = vreinterpret_u8_u32(vdup_n_u32(a));
3804 uint8x8_t min = vpmin_u8(a_dup, a_dup);
3805 min = vpmin_u8(min, min);
3806 return vget_lane_u8(min, 0);
3807}
3808#if EIGEN_ARCH_ARM64
3809template <>
3810EIGEN_STRONG_INLINE uint8_t predux_min<Packet8uc>(const Packet8uc& a) {
3811 return vminv_u8(a);
3812}
3813template <>
3814EIGEN_STRONG_INLINE uint8_t predux_min<Packet16uc>(const Packet16uc& a) {
3815 return vminvq_u8(a);
3816}
3817template <>
3818EIGEN_STRONG_INLINE int16_t predux_min<Packet4s>(const Packet4s& a) {
3819 return vminv_s16(a);
3820}
3821template <>
3822EIGEN_STRONG_INLINE int16_t predux_min<Packet8s>(const Packet8s& a) {
3823 return vminvq_s16(a);
3824}
3825template <>
3826EIGEN_STRONG_INLINE uint16_t predux_min<Packet4us>(const Packet4us& a) {
3827 return vminv_u16(a);
3828}
3829template <>
3830EIGEN_STRONG_INLINE uint16_t predux_min<Packet8us>(const Packet8us& a) {
3831 return vminvq_u16(a);
3832}
3833template <>
3834EIGEN_STRONG_INLINE int32_t predux_min<Packet2i>(const Packet2i& a) {
3835 return vminv_s32(a);
3836}
3837template <>
3838EIGEN_STRONG_INLINE int32_t predux_min<Packet4i>(const Packet4i& a) {
3839 return vminvq_s32(a);
3840}
3841template <>
3842EIGEN_STRONG_INLINE uint32_t predux_min<Packet2ui>(const Packet2ui& a) {
3843 return vminv_u32(a);
3844}
3845template <>
3846EIGEN_STRONG_INLINE uint32_t predux_min<Packet4ui>(const Packet4ui& a) {
3847 return vminvq_u32(a);
3848}
3849#else
3850template <>
3851EIGEN_STRONG_INLINE uint8_t predux_min<Packet8uc>(const Packet8uc& a) {
3852 uint8x8_t min = vpmin_u8(a, a);
3853 min = vpmin_u8(min, min);
3854 min = vpmin_u8(min, min);
3855 return vget_lane_u8(min, 0);
3856}
3857template <>
3858EIGEN_STRONG_INLINE uint8_t predux_min<Packet16uc>(const Packet16uc& a) {
3859 uint8x8_t min = vmin_u8(vget_low_u8(a), vget_high_u8(a));
3860 min = vpmin_u8(min, min);
3861 min = vpmin_u8(min, min);
3862 min = vpmin_u8(min, min);
3863 return vget_lane_u8(min, 0);
3864}
3865template <>
3866EIGEN_STRONG_INLINE int16_t predux_min<Packet4s>(const Packet4s& a) {
3867 const int16x4_t min = vpmin_s16(a, a);
3868 return vget_lane_s16(vpmin_s16(min, min), 0);
3869}
3870template <>
3871EIGEN_STRONG_INLINE int16_t predux_min<Packet8s>(const Packet8s& a) {
3872 int16x4_t min = vmin_s16(vget_low_s16(a), vget_high_s16(a));
3873 min = vpmin_s16(min, min);
3874 min = vpmin_s16(min, min);
3875 return vget_lane_s16(min, 0);
3876}
3877template <>
3878EIGEN_STRONG_INLINE uint16_t predux_min<Packet4us>(const Packet4us& a) {
3879 const uint16x4_t min = vpmin_u16(a, a);
3880 return vget_lane_u16(vpmin_u16(min, min), 0);
3881}
3882template <>
3883EIGEN_STRONG_INLINE uint16_t predux_min<Packet8us>(const Packet8us& a) {
3884 uint16x4_t min = vmin_u16(vget_low_u16(a), vget_high_u16(a));
3885 min = vpmin_u16(min, min);
3886 min = vpmin_u16(min, min);
3887 return vget_lane_u16(min, 0);
3888}
3889template <>
3890EIGEN_STRONG_INLINE int32_t predux_min<Packet2i>(const Packet2i& a) {
3891 return vget_lane_s32(vpmin_s32(a, a), 0);
3892}
3893template <>
3894EIGEN_STRONG_INLINE int32_t predux_min<Packet4i>(const Packet4i& a) {
3895 const int32x2_t min = vmin_s32(vget_low_s32(a), vget_high_s32(a));
3896 return vget_lane_s32(vpmin_s32(min, min), 0);
3897}
3898template <>
3899EIGEN_STRONG_INLINE uint32_t predux_min<Packet2ui>(const Packet2ui& a) {
3900 return vget_lane_u32(vpmin_u32(a, a), 0);
3901}
3902template <>
3903EIGEN_STRONG_INLINE uint32_t predux_min<Packet4ui>(const Packet4ui& a) {
3904 const uint32x2_t min = vmin_u32(vget_low_u32(a), vget_high_u32(a));
3905 return vget_lane_u32(vpmin_u32(min, min), 0);
3906}
3907#endif
3908template <>
3909EIGEN_STRONG_INLINE int64_t predux_min<Packet2l>(const Packet2l& a) {
3910 return (std::min)(vgetq_lane_s64(a, 0), vgetq_lane_s64(a, 1));
3911}
3912template <>
3913EIGEN_STRONG_INLINE uint64_t predux_min<Packet2ul>(const Packet2ul& a) {
3914 return (std::min)(vgetq_lane_u64(a, 0), vgetq_lane_u64(a, 1));
3915}
3916
3917// max
3918#if EIGEN_ARCH_ARM64
3919template <>
3920EIGEN_STRONG_INLINE float predux_max<Packet2f>(const Packet2f& a) {
3921 return vmaxv_f32(a);
3922}
3923template <>
3924EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) {
3925 return vmaxvq_f32(a);
3926}
3927#else
3928template <>
3929EIGEN_STRONG_INLINE float predux_max<Packet2f>(const Packet2f& a) {
3930 return vget_lane_f32(vpmax_f32(a, a), 0);
3931}
3932template <>
3933EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) {
3934 const float32x2_t max = vmax_f32(vget_low_f32(a), vget_high_f32(a));
3935 return vget_lane_f32(vpmax_f32(max, max), 0);
3936}
3937#endif
3938template <>
3939EIGEN_STRONG_INLINE int8_t predux_max<Packet4c>(const Packet4c& a) {
3940 const int8x8_t a_dup = vreinterpret_s8_s32(vdup_n_s32(a));
3941 int8x8_t max = vpmax_s8(a_dup, a_dup);
3942 max = vpmax_s8(max, max);
3943 return vget_lane_s8(max, 0);
3944}
3945#if EIGEN_ARCH_ARM64
3946template <>
3947EIGEN_STRONG_INLINE int8_t predux_max<Packet8c>(const Packet8c& a) {
3948 return vmaxv_s8(a);
3949}
3950template <>
3951EIGEN_STRONG_INLINE int8_t predux_max<Packet16c>(const Packet16c& a) {
3952 return vmaxvq_s8(a);
3953}
3954#else
3955template <>
3956EIGEN_STRONG_INLINE int8_t predux_max<Packet8c>(const Packet8c& a) {
3957 int8x8_t max = vpmax_s8(a, a);
3958 max = vpmax_s8(max, max);
3959 max = vpmax_s8(max, max);
3960 return vget_lane_s8(max, 0);
3961}
3962template <>
3963EIGEN_STRONG_INLINE int8_t predux_max<Packet16c>(const Packet16c& a) {
3964 int8x8_t max = vmax_s8(vget_low_s8(a), vget_high_s8(a));
3965 max = vpmax_s8(max, max);
3966 max = vpmax_s8(max, max);
3967 max = vpmax_s8(max, max);
3968 return vget_lane_s8(max, 0);
3969}
3970#endif
3971template <>
3972EIGEN_STRONG_INLINE uint8_t predux_max<Packet4uc>(const Packet4uc& a) {
3973 const uint8x8_t a_dup = vreinterpret_u8_u32(vdup_n_u32(a));
3974 uint8x8_t max = vpmax_u8(a_dup, a_dup);
3975 max = vpmax_u8(max, max);
3976 return vget_lane_u8(max, 0);
3977}
3978#if EIGEN_ARCH_ARM64
3979template <>
3980EIGEN_STRONG_INLINE uint8_t predux_max<Packet8uc>(const Packet8uc& a) {
3981 return vmaxv_u8(a);
3982}
3983template <>
3984EIGEN_STRONG_INLINE uint8_t predux_max<Packet16uc>(const Packet16uc& a) {
3985 return vmaxvq_u8(a);
3986}
3987template <>
3988EIGEN_STRONG_INLINE int16_t predux_max<Packet4s>(const Packet4s& a) {
3989 return vmaxv_s16(a);
3990}
3991template <>
3992EIGEN_STRONG_INLINE int16_t predux_max<Packet8s>(const Packet8s& a) {
3993 return vmaxvq_s16(a);
3994}
3995template <>
3996EIGEN_STRONG_INLINE uint16_t predux_max<Packet4us>(const Packet4us& a) {
3997 return vmaxv_u16(a);
3998}
3999template <>
4000EIGEN_STRONG_INLINE uint16_t predux_max<Packet8us>(const Packet8us& a) {
4001 return vmaxvq_u16(a);
4002}
4003template <>
4004EIGEN_STRONG_INLINE int32_t predux_max<Packet2i>(const Packet2i& a) {
4005 return vmaxv_s32(a);
4006}
4007template <>
4008EIGEN_STRONG_INLINE int32_t predux_max<Packet4i>(const Packet4i& a) {
4009 return vmaxvq_s32(a);
4010}
4011template <>
4012EIGEN_STRONG_INLINE uint32_t predux_max<Packet2ui>(const Packet2ui& a) {
4013 return vmaxv_u32(a);
4014}
4015template <>
4016EIGEN_STRONG_INLINE uint32_t predux_max<Packet4ui>(const Packet4ui& a) {
4017 return vmaxvq_u32(a);
4018}
4019#else
4020template <>
4021EIGEN_STRONG_INLINE uint8_t predux_max<Packet8uc>(const Packet8uc& a) {
4022 uint8x8_t max = vpmax_u8(a, a);
4023 max = vpmax_u8(max, max);
4024 max = vpmax_u8(max, max);
4025 return vget_lane_u8(max, 0);
4026}
4027template <>
4028EIGEN_STRONG_INLINE uint8_t predux_max<Packet16uc>(const Packet16uc& a) {
4029 uint8x8_t max = vmax_u8(vget_low_u8(a), vget_high_u8(a));
4030 max = vpmax_u8(max, max);
4031 max = vpmax_u8(max, max);
4032 max = vpmax_u8(max, max);
4033 return vget_lane_u8(max, 0);
4034}
4035template <>
4036EIGEN_STRONG_INLINE int16_t predux_max<Packet4s>(const Packet4s& a) {
4037 const int16x4_t max = vpmax_s16(a, a);
4038 return vget_lane_s16(vpmax_s16(max, max), 0);
4039}
4040template <>
4041EIGEN_STRONG_INLINE int16_t predux_max<Packet8s>(const Packet8s& a) {
4042 int16x4_t max = vmax_s16(vget_low_s16(a), vget_high_s16(a));
4043 max = vpmax_s16(max, max);
4044 max = vpmax_s16(max, max);
4045 return vget_lane_s16(max, 0);
4046}
4047template <>
4048EIGEN_STRONG_INLINE uint16_t predux_max<Packet4us>(const Packet4us& a) {
4049 const uint16x4_t max = vpmax_u16(a, a);
4050 return vget_lane_u16(vpmax_u16(max, max), 0);
4051}
4052template <>
4053EIGEN_STRONG_INLINE uint16_t predux_max<Packet8us>(const Packet8us& a) {
4054 uint16x4_t max = vmax_u16(vget_low_u16(a), vget_high_u16(a));
4055 max = vpmax_u16(max, max);
4056 max = vpmax_u16(max, max);
4057 return vget_lane_u16(max, 0);
4058}
4059template <>
4060EIGEN_STRONG_INLINE int32_t predux_max<Packet2i>(const Packet2i& a) {
4061 return vget_lane_s32(vpmax_s32(a, a), 0);
4062}
4063template <>
4064EIGEN_STRONG_INLINE int32_t predux_max<Packet4i>(const Packet4i& a) {
4065 const int32x2_t max = vmax_s32(vget_low_s32(a), vget_high_s32(a));
4066 return vget_lane_s32(vpmax_s32(max, max), 0);
4067}
4068template <>
4069EIGEN_STRONG_INLINE uint32_t predux_max<Packet2ui>(const Packet2ui& a) {
4070 return vget_lane_u32(vpmax_u32(a, a), 0);
4071}
4072template <>
4073EIGEN_STRONG_INLINE uint32_t predux_max<Packet4ui>(const Packet4ui& a) {
4074 const uint32x2_t max = vmax_u32(vget_low_u32(a), vget_high_u32(a));
4075 return vget_lane_u32(vpmax_u32(max, max), 0);
4076}
4077#endif
4078template <>
4079EIGEN_STRONG_INLINE int64_t predux_max<Packet2l>(const Packet2l& a) {
4080 return (std::max)(vgetq_lane_s64(a, 0), vgetq_lane_s64(a, 1));
4081}
4082template <>
4083EIGEN_STRONG_INLINE uint64_t predux_max<Packet2ul>(const Packet2ul& a) {
4084 return (std::max)(vgetq_lane_u64(a, 0), vgetq_lane_u64(a, 1));
4085}
4086
4087template <>
4088EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x) {
4089 uint32x2_t tmp = vorr_u32(vget_low_u32(vreinterpretq_u32_f32(x)), vget_high_u32(vreinterpretq_u32_f32(x)));
4090 return vget_lane_u32(vpmax_u32(tmp, tmp), 0);
4091}
4092
4093// Helpers for ptranspose.
4094namespace detail {
4095
4096template <typename Packet>
4097void zip_in_place(Packet& p1, Packet& p2);
4098
4099template <>
4100EIGEN_ALWAYS_INLINE void zip_in_place<Packet2f>(Packet2f& p1, Packet2f& p2) {
4101 const float32x2x2_t tmp = vzip_f32(p1, p2);
4102 p1 = tmp.val[0];
4103 p2 = tmp.val[1];
4104}
4105
4106template <>
4107EIGEN_ALWAYS_INLINE void zip_in_place<Packet4f>(Packet4f& p1, Packet4f& p2) {
4108 const float32x4x2_t tmp = vzipq_f32(p1, p2);
4109 p1 = tmp.val[0];
4110 p2 = tmp.val[1];
4111}
4112
4113template <>
4114EIGEN_ALWAYS_INLINE void zip_in_place<Packet8c>(Packet8c& p1, Packet8c& p2) {
4115 const int8x8x2_t tmp = vzip_s8(p1, p2);
4116 p1 = tmp.val[0];
4117 p2 = tmp.val[1];
4118}
4119
4120template <>
4121EIGEN_ALWAYS_INLINE void zip_in_place<Packet16c>(Packet16c& p1, Packet16c& p2) {
4122 const int8x16x2_t tmp = vzipq_s8(p1, p2);
4123 p1 = tmp.val[0];
4124 p2 = tmp.val[1];
4125}
4126
4127template <>
4128EIGEN_ALWAYS_INLINE void zip_in_place<Packet8uc>(Packet8uc& p1, Packet8uc& p2) {
4129 const uint8x8x2_t tmp = vzip_u8(p1, p2);
4130 p1 = tmp.val[0];
4131 p2 = tmp.val[1];
4132}
4133
4134template <>
4135EIGEN_ALWAYS_INLINE void zip_in_place<Packet16uc>(Packet16uc& p1, Packet16uc& p2) {
4136 const uint8x16x2_t tmp = vzipq_u8(p1, p2);
4137 p1 = tmp.val[0];
4138 p2 = tmp.val[1];
4139}
4140
4141template <>
4142EIGEN_ALWAYS_INLINE void zip_in_place<Packet2i>(Packet2i& p1, Packet2i& p2) {
4143 const int32x2x2_t tmp = vzip_s32(p1, p2);
4144 p1 = tmp.val[0];
4145 p2 = tmp.val[1];
4146}
4147
4148template <>
4149EIGEN_ALWAYS_INLINE void zip_in_place<Packet4i>(Packet4i& p1, Packet4i& p2) {
4150 const int32x4x2_t tmp = vzipq_s32(p1, p2);
4151 p1 = tmp.val[0];
4152 p2 = tmp.val[1];
4153}
4154
4155template <>
4156EIGEN_ALWAYS_INLINE void zip_in_place<Packet2ui>(Packet2ui& p1, Packet2ui& p2) {
4157 const uint32x2x2_t tmp = vzip_u32(p1, p2);
4158 p1 = tmp.val[0];
4159 p2 = tmp.val[1];
4160}
4161
4162template <>
4163EIGEN_ALWAYS_INLINE void zip_in_place<Packet4ui>(Packet4ui& p1, Packet4ui& p2) {
4164 const uint32x4x2_t tmp = vzipq_u32(p1, p2);
4165 p1 = tmp.val[0];
4166 p2 = tmp.val[1];
4167}
4168
4169template <>
4170EIGEN_ALWAYS_INLINE void zip_in_place<Packet4s>(Packet4s& p1, Packet4s& p2) {
4171 const int16x4x2_t tmp = vzip_s16(p1, p2);
4172 p1 = tmp.val[0];
4173 p2 = tmp.val[1];
4174}
4175
4176template <>
4177EIGEN_ALWAYS_INLINE void zip_in_place<Packet8s>(Packet8s& p1, Packet8s& p2) {
4178 const int16x8x2_t tmp = vzipq_s16(p1, p2);
4179 p1 = tmp.val[0];
4180 p2 = tmp.val[1];
4181}
4182
4183template <>
4184EIGEN_ALWAYS_INLINE void zip_in_place<Packet4us>(Packet4us& p1, Packet4us& p2) {
4185 const uint16x4x2_t tmp = vzip_u16(p1, p2);
4186 p1 = tmp.val[0];
4187 p2 = tmp.val[1];
4188}
4189
4190template <>
4191EIGEN_ALWAYS_INLINE void zip_in_place<Packet8us>(Packet8us& p1, Packet8us& p2) {
4192 const uint16x8x2_t tmp = vzipq_u16(p1, p2);
4193 p1 = tmp.val[0];
4194 p2 = tmp.val[1];
4195}
4196
4197template <typename Packet>
4198EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 2>& kernel) {
4199 zip_in_place(kernel.packet[0], kernel.packet[1]);
4200}
4201
4202template <typename Packet>
4203EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 4>& kernel) {
4204 zip_in_place(kernel.packet[0], kernel.packet[2]);
4205 zip_in_place(kernel.packet[1], kernel.packet[3]);
4206 zip_in_place(kernel.packet[0], kernel.packet[1]);
4207 zip_in_place(kernel.packet[2], kernel.packet[3]);
4208}
4209
4210template <typename Packet>
4211EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 8>& kernel) {
4212 zip_in_place(kernel.packet[0], kernel.packet[4]);
4213 zip_in_place(kernel.packet[1], kernel.packet[5]);
4214 zip_in_place(kernel.packet[2], kernel.packet[6]);
4215 zip_in_place(kernel.packet[3], kernel.packet[7]);
4216
4217 zip_in_place(kernel.packet[0], kernel.packet[2]);
4218 zip_in_place(kernel.packet[1], kernel.packet[3]);
4219 zip_in_place(kernel.packet[4], kernel.packet[6]);
4220 zip_in_place(kernel.packet[5], kernel.packet[7]);
4221
4222 zip_in_place(kernel.packet[0], kernel.packet[1]);
4223 zip_in_place(kernel.packet[2], kernel.packet[3]);
4224 zip_in_place(kernel.packet[4], kernel.packet[5]);
4225 zip_in_place(kernel.packet[6], kernel.packet[7]);
4226}
4227
4228template <typename Packet>
4229EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 16>& kernel) {
4230 EIGEN_UNROLL_LOOP
4231 for (int i = 0; i < 4; ++i) {
4232 const int m = (1 << i);
4233 EIGEN_UNROLL_LOOP
4234 for (int j = 0; j < m; ++j) {
4235 const int n = (1 << (3 - i));
4236 EIGEN_UNROLL_LOOP
4237 for (int k = 0; k < n; ++k) {
4238 const int idx = 2 * j * n + k;
4239 zip_in_place(kernel.packet[idx], kernel.packet[idx + n]);
4240 }
4241 }
4242 }
4243}
4244
4245} // namespace detail
4246
4247EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2f, 2>& kernel) {
4248 detail::ptranspose_impl(kernel);
4249}
4250EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4f, 4>& kernel) {
4251 detail::ptranspose_impl(kernel);
4252}
4253
4254EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4c, 4>& kernel) {
4255 const int8x8_t a = vreinterpret_s8_s32(vset_lane_s32(kernel.packet[2], vdup_n_s32(kernel.packet[0]), 1));
4256 const int8x8_t b = vreinterpret_s8_s32(vset_lane_s32(kernel.packet[3], vdup_n_s32(kernel.packet[1]), 1));
4257
4258 const int8x8x2_t zip8 = vzip_s8(a, b);
4259 const int16x4x2_t zip16 = vzip_s16(vreinterpret_s16_s8(zip8.val[0]), vreinterpret_s16_s8(zip8.val[1]));
4260
4261 kernel.packet[0] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[0]), 0);
4262 kernel.packet[1] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[0]), 1);
4263 kernel.packet[2] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[1]), 0);
4264 kernel.packet[3] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[1]), 1);
4265}
4266EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8c, 8>& kernel) {
4267 detail::ptranspose_impl(kernel);
4268}
4269EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8c, 4>& kernel) {
4270 detail::ptranspose_impl(kernel);
4271}
4272EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16c, 16>& kernel) {
4273 detail::ptranspose_impl(kernel);
4274}
4275EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16c, 8>& kernel) {
4276 detail::ptranspose_impl(kernel);
4277}
4278EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16c, 4>& kernel) {
4279 detail::ptranspose_impl(kernel);
4280}
4281
4282EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4uc, 4>& kernel) {
4283 const uint8x8_t a = vreinterpret_u8_u32(vset_lane_u32(kernel.packet[2], vdup_n_u32(kernel.packet[0]), 1));
4284 const uint8x8_t b = vreinterpret_u8_u32(vset_lane_u32(kernel.packet[3], vdup_n_u32(kernel.packet[1]), 1));
4285
4286 const uint8x8x2_t zip8 = vzip_u8(a, b);
4287 const uint16x4x2_t zip16 = vzip_u16(vreinterpret_u16_u8(zip8.val[0]), vreinterpret_u16_u8(zip8.val[1]));
4288
4289 kernel.packet[0] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[0]), 0);
4290 kernel.packet[1] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[0]), 1);
4291 kernel.packet[2] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[1]), 0);
4292 kernel.packet[3] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[1]), 1);
4293}
4294EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8uc, 8>& kernel) {
4295 detail::ptranspose_impl(kernel);
4296}
4297EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8uc, 4>& kernel) {
4298 detail::ptranspose_impl(kernel);
4299}
4300EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16uc, 16>& kernel) {
4301 detail::ptranspose_impl(kernel);
4302}
4303EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16uc, 8>& kernel) {
4304 detail::ptranspose_impl(kernel);
4305}
4306EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16uc, 4>& kernel) {
4307 detail::ptranspose_impl(kernel);
4308}
4309
4310EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4s, 4>& kernel) {
4311 detail::ptranspose_impl(kernel);
4312}
4313EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8s, 8>& kernel) {
4314 detail::ptranspose_impl(kernel);
4315}
4316EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8s, 4>& kernel) {
4317 detail::ptranspose_impl(kernel);
4318}
4319
4320EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4us, 4>& kernel) {
4321 detail::ptranspose_impl(kernel);
4322}
4323EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8us, 8>& kernel) {
4324 detail::ptranspose_impl(kernel);
4325}
4326EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8us, 4>& kernel) {
4327 detail::ptranspose_impl(kernel);
4328}
4329
4330EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2i, 2>& kernel) {
4331 detail::ptranspose_impl(kernel);
4332}
4333EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4i, 4>& kernel) {
4334 detail::ptranspose_impl(kernel);
4335}
4336EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2ui, 2>& kernel) {
4337 detail::zip_in_place(kernel.packet[0], kernel.packet[1]);
4338}
4339EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4ui, 4>& kernel) {
4340 detail::ptranspose_impl(kernel);
4341}
4342
4343EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2l, 2>& kernel) {
4344#if EIGEN_ARCH_ARM64
4345 const int64x2_t tmp1 = vzip1q_s64(kernel.packet[0], kernel.packet[1]);
4346 kernel.packet[1] = vzip2q_s64(kernel.packet[0], kernel.packet[1]);
4347 kernel.packet[0] = tmp1;
4348#else
4349 const int64x1_t tmp[2][2] = {{vget_low_s64(kernel.packet[0]), vget_high_s64(kernel.packet[0])},
4350 {vget_low_s64(kernel.packet[1]), vget_high_s64(kernel.packet[1])}};
4351
4352 kernel.packet[0] = vcombine_s64(tmp[0][0], tmp[1][0]);
4353 kernel.packet[1] = vcombine_s64(tmp[0][1], tmp[1][1]);
4354#endif
4355}
4356EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2ul, 2>& kernel) {
4357#if EIGEN_ARCH_ARM64
4358 const uint64x2_t tmp1 = vzip1q_u64(kernel.packet[0], kernel.packet[1]);
4359 kernel.packet[1] = vzip2q_u64(kernel.packet[0], kernel.packet[1]);
4360 kernel.packet[0] = tmp1;
4361#else
4362 const uint64x1_t tmp[2][2] = {{vget_low_u64(kernel.packet[0]), vget_high_u64(kernel.packet[0])},
4363 {vget_low_u64(kernel.packet[1]), vget_high_u64(kernel.packet[1])}};
4364
4365 kernel.packet[0] = vcombine_u64(tmp[0][0], tmp[1][0]);
4366 kernel.packet[1] = vcombine_u64(tmp[0][1], tmp[1][1]);
4367#endif
4368}
4369
4370template <>
4371EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2f pselect(const Packet2f& mask, const Packet2f& a, const Packet2f& b) {
4372 return vbsl_f32(vreinterpret_u32_f32(mask), a, b);
4373}
4374template <>
4375EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b) {
4376 return vbslq_f32(vreinterpretq_u32_f32(mask), a, b);
4377}
4378template <>
4379EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8c pselect(const Packet8c& mask, const Packet8c& a, const Packet8c& b) {
4380 return vbsl_s8(vreinterpret_u8_s8(mask), a, b);
4381}
4382template <>
4383EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16c pselect(const Packet16c& mask, const Packet16c& a, const Packet16c& b) {
4384 return vbslq_s8(vreinterpretq_u8_s8(mask), a, b);
4385}
4386template <>
4387EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8uc pselect(const Packet8uc& mask, const Packet8uc& a, const Packet8uc& b) {
4388 return vbsl_u8(mask, a, b);
4389}
4390template <>
4391EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16uc pselect(const Packet16uc& mask, const Packet16uc& a,
4392 const Packet16uc& b) {
4393 return vbslq_u8(mask, a, b);
4394}
4395template <>
4396EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4s pselect(const Packet4s& mask, const Packet4s& a, const Packet4s& b) {
4397 return vbsl_s16(vreinterpret_u16_s16(mask), a, b);
4398}
4399template <>
4400EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8s pselect(const Packet8s& mask, const Packet8s& a, const Packet8s& b) {
4401 return vbslq_s16(vreinterpretq_u16_s16(mask), a, b);
4402}
4403template <>
4404EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4us pselect(const Packet4us& mask, const Packet4us& a, const Packet4us& b) {
4405 return vbsl_u16(mask, a, b);
4406}
4407template <>
4408EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8us pselect(const Packet8us& mask, const Packet8us& a, const Packet8us& b) {
4409 return vbslq_u16(mask, a, b);
4410}
4411template <>
4412EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2i pselect(const Packet2i& mask, const Packet2i& a, const Packet2i& b) {
4413 return vbsl_s32(vreinterpret_u32_s32(mask), a, b);
4414}
4415template <>
4416EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4i pselect(const Packet4i& mask, const Packet4i& a, const Packet4i& b) {
4417 return vbslq_s32(vreinterpretq_u32_s32(mask), a, b);
4418}
4419template <>
4420EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ui pselect(const Packet2ui& mask, const Packet2ui& a, const Packet2ui& b) {
4421 return vbsl_u32(mask, a, b);
4422}
4423template <>
4424EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4ui pselect(const Packet4ui& mask, const Packet4ui& a, const Packet4ui& b) {
4425 return vbslq_u32(mask, a, b);
4426}
4427template <>
4428EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2l pselect(const Packet2l& mask, const Packet2l& a, const Packet2l& b) {
4429 return vbslq_s64(vreinterpretq_u64_s64(mask), a, b);
4430}
4431template <>
4432EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ul pselect(const Packet2ul& mask, const Packet2ul& a, const Packet2ul& b) {
4433 return vbslq_u64(mask, a, b);
4434}
4435
4436// Use armv8 rounding intinsics if available.
4437#if EIGEN_ARCH_ARMV8
4438template <>
4439EIGEN_STRONG_INLINE Packet2f print<Packet2f>(const Packet2f& a) {
4440 return vrndn_f32(a);
4441}
4442
4443template <>
4444EIGEN_STRONG_INLINE Packet4f print<Packet4f>(const Packet4f& a) {
4445 return vrndnq_f32(a);
4446}
4447
4448template <>
4449EIGEN_STRONG_INLINE Packet2f pfloor<Packet2f>(const Packet2f& a) {
4450 return vrndm_f32(a);
4451}
4452
4453template <>
4454EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) {
4455 return vrndmq_f32(a);
4456}
4457
4458template <>
4459EIGEN_STRONG_INLINE Packet2f pceil<Packet2f>(const Packet2f& a) {
4460 return vrndp_f32(a);
4461}
4462
4463template <>
4464EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) {
4465 return vrndpq_f32(a);
4466}
4467
4468template <>
4469EIGEN_STRONG_INLINE Packet2f pround<Packet2f>(const Packet2f& a) {
4470 return vrnda_f32(a);
4471}
4472
4473template <>
4474EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) {
4475 return vrndaq_f32(a);
4476}
4477
4478template <>
4479EIGEN_STRONG_INLINE Packet2f ptrunc<Packet2f>(const Packet2f& a) {
4480 return vrnd_f32(a);
4481}
4482
4483template <>
4484EIGEN_STRONG_INLINE Packet4f ptrunc<Packet4f>(const Packet4f& a) {
4485 return vrndq_f32(a);
4486}
4487#endif
4488
4495template <>
4496EIGEN_STRONG_INLINE Packet4uc psqrt(const Packet4uc& a) {
4497 uint8x8_t x = vreinterpret_u8_u32(vdup_n_u32(a));
4498 uint8x8_t res = vdup_n_u8(0);
4499 uint8x8_t add = vdup_n_u8(0x8);
4500 for (int i = 0; i < 4; i++) {
4501 const uint8x8_t temp = vorr_u8(res, add);
4502 res = vbsl_u8(vcge_u8(x, vmul_u8(temp, temp)), temp, res);
4503 add = vshr_n_u8(add, 1);
4504 }
4505 return vget_lane_u32(vreinterpret_u32_u8(res), 0);
4506}
4508template <>
4509EIGEN_STRONG_INLINE Packet8uc psqrt(const Packet8uc& a) {
4510 uint8x8_t res = vdup_n_u8(0);
4511 uint8x8_t add = vdup_n_u8(0x8);
4512 for (int i = 0; i < 4; i++) {
4513 const uint8x8_t temp = vorr_u8(res, add);
4514 res = vbsl_u8(vcge_u8(a, vmul_u8(temp, temp)), temp, res);
4515 add = vshr_n_u8(add, 1);
4516 }
4517 return res;
4518}
4520template <>
4521EIGEN_STRONG_INLINE Packet16uc psqrt(const Packet16uc& a) {
4522 uint8x16_t res = vdupq_n_u8(0);
4523 uint8x16_t add = vdupq_n_u8(0x8);
4524 for (int i = 0; i < 4; i++) {
4525 const uint8x16_t temp = vorrq_u8(res, add);
4526 res = vbslq_u8(vcgeq_u8(a, vmulq_u8(temp, temp)), temp, res);
4527 add = vshrq_n_u8(add, 1);
4528 }
4529 return res;
4530}
4532template <>
4533EIGEN_STRONG_INLINE Packet4us psqrt(const Packet4us& a) {
4534 uint16x4_t res = vdup_n_u16(0);
4535 uint16x4_t add = vdup_n_u16(0x80);
4536 for (int i = 0; i < 8; i++) {
4537 const uint16x4_t temp = vorr_u16(res, add);
4538 res = vbsl_u16(vcge_u16(a, vmul_u16(temp, temp)), temp, res);
4539 add = vshr_n_u16(add, 1);
4540 }
4541 return res;
4542}
4544template <>
4545EIGEN_STRONG_INLINE Packet8us psqrt(const Packet8us& a) {
4546 uint16x8_t res = vdupq_n_u16(0);
4547 uint16x8_t add = vdupq_n_u16(0x80);
4548 for (int i = 0; i < 8; i++) {
4549 const uint16x8_t temp = vorrq_u16(res, add);
4550 res = vbslq_u16(vcgeq_u16(a, vmulq_u16(temp, temp)), temp, res);
4551 add = vshrq_n_u16(add, 1);
4552 }
4553 return res;
4554}
4556template <>
4557EIGEN_STRONG_INLINE Packet2ui psqrt(const Packet2ui& a) {
4558 uint32x2_t res = vdup_n_u32(0);
4559 uint32x2_t add = vdup_n_u32(0x8000);
4560 for (int i = 0; i < 16; i++) {
4561 const uint32x2_t temp = vorr_u32(res, add);
4562 res = vbsl_u32(vcge_u32(a, vmul_u32(temp, temp)), temp, res);
4563 add = vshr_n_u32(add, 1);
4564 }
4565 return res;
4566}
4568template <>
4569EIGEN_STRONG_INLINE Packet4ui psqrt(const Packet4ui& a) {
4570 uint32x4_t res = vdupq_n_u32(0);
4571 uint32x4_t add = vdupq_n_u32(0x8000);
4572 for (int i = 0; i < 16; i++) {
4573 const uint32x4_t temp = vorrq_u32(res, add);
4574 res = vbslq_u32(vcgeq_u32(a, vmulq_u32(temp, temp)), temp, res);
4575 add = vshrq_n_u32(add, 1);
4576 }
4577 return res;
4578}
4579
4580EIGEN_STRONG_INLINE Packet4f prsqrt_float_unsafe(const Packet4f& a) {
4581 // Compute approximate reciprocal sqrt.
4582 // Does not correctly handle +/- 0 or +inf
4583 float32x4_t result = vrsqrteq_f32(a);
4584 result = vmulq_f32(vrsqrtsq_f32(vmulq_f32(a, result), result), result);
4585 result = vmulq_f32(vrsqrtsq_f32(vmulq_f32(a, result), result), result);
4586 return result;
4587}
4588
4589EIGEN_STRONG_INLINE Packet2f prsqrt_float_unsafe(const Packet2f& a) {
4590 // Compute approximate reciprocal sqrt.
4591 // Does not correctly handle +/- 0 or +inf
4592 float32x2_t result = vrsqrte_f32(a);
4593 result = vmul_f32(vrsqrts_f32(vmul_f32(a, result), result), result);
4594 result = vmul_f32(vrsqrts_f32(vmul_f32(a, result), result), result);
4595 return result;
4596}
4597
4598template <typename Packet>
4599Packet prsqrt_float_common(const Packet& a) {
4600 const Packet cst_zero = pzero(a);
4601 const Packet cst_inf = pset1<Packet>(NumTraits<float>::infinity());
4602 Packet return_zero = pcmp_eq(a, cst_inf);
4603 Packet return_inf = pcmp_eq(a, cst_zero);
4604 Packet result = prsqrt_float_unsafe(a);
4605 result = pselect(return_inf, por(cst_inf, a), result);
4606 result = pandnot(result, return_zero);
4607 return result;
4608}
4609
4610template <>
4611EIGEN_STRONG_INLINE Packet4f prsqrt(const Packet4f& a) {
4612 return prsqrt_float_common(a);
4613}
4614
4615template <>
4616EIGEN_STRONG_INLINE Packet2f prsqrt(const Packet2f& a) {
4617 return prsqrt_float_common(a);
4618}
4619
4620template <>
4621EIGEN_STRONG_INLINE Packet4f preciprocal<Packet4f>(const Packet4f& a) {
4622 // Compute approximate reciprocal.
4623 float32x4_t result = vrecpeq_f32(a);
4624 result = vmulq_f32(vrecpsq_f32(a, result), result);
4625 result = vmulq_f32(vrecpsq_f32(a, result), result);
4626 return result;
4627}
4628
4629template <>
4630EIGEN_STRONG_INLINE Packet2f preciprocal<Packet2f>(const Packet2f& a) {
4631 // Compute approximate reciprocal.
4632 float32x2_t result = vrecpe_f32(a);
4633 result = vmul_f32(vrecps_f32(a, result), result);
4634 result = vmul_f32(vrecps_f32(a, result), result);
4635 return result;
4636}
4637
4638// Unfortunately vsqrt_f32 is only available for A64.
4639#if EIGEN_ARCH_ARM64
4640template <>
4641EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& a) {
4642 return vsqrtq_f32(a);
4643}
4644
4645template <>
4646EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& a) {
4647 return vsqrt_f32(a);
4648}
4649
4650template <>
4651EIGEN_STRONG_INLINE Packet4f pdiv(const Packet4f& a, const Packet4f& b) {
4652 return vdivq_f32(a, b);
4653}
4654
4655template <>
4656EIGEN_STRONG_INLINE Packet2f pdiv(const Packet2f& a, const Packet2f& b) {
4657 return vdiv_f32(a, b);
4658}
4659#else
4660template <typename Packet>
4661EIGEN_STRONG_INLINE Packet psqrt_float_common(const Packet& a) {
4662 const Packet cst_zero = pzero(a);
4663 const Packet cst_inf = pset1<Packet>(NumTraits<float>::infinity());
4664
4665 Packet result = pmul(a, prsqrt_float_unsafe(a));
4666 Packet a_is_zero = pcmp_eq(a, cst_zero);
4667 Packet a_is_inf = pcmp_eq(a, cst_inf);
4668 Packet return_a = por(a_is_zero, a_is_inf);
4669
4670 result = pselect(return_a, a, result);
4671 return result;
4672}
4673
4674template <>
4675EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& a) {
4676 return psqrt_float_common(a);
4677}
4678
4679template <>
4680EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& a) {
4681 return psqrt_float_common(a);
4682}
4683
4684template <typename Packet>
4685EIGEN_STRONG_INLINE Packet pdiv_float_common(const Packet& a, const Packet& b) {
4686 // if b is large, NEON intrinsics will flush preciprocal(b) to zero
4687 // avoid underflow with the following manipulation:
4688 // a / b = f * (a * reciprocal(f * b))
4689
4690 const Packet cst_one = pset1<Packet>(1.0f);
4691 const Packet cst_quarter = pset1<Packet>(0.25f);
4692 const Packet cst_thresh = pset1<Packet>(NumTraits<float>::highest() / 4.0f);
4693
4694 Packet b_will_underflow = pcmp_le(cst_thresh, pabs(b));
4695 Packet f = pselect(b_will_underflow, cst_quarter, cst_one);
4696 Packet result = pmul(f, pmul(a, preciprocal(pmul(b, f))));
4697 return result;
4698}
4699
4700template <>
4701EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) {
4702 return pdiv_float_common(a, b);
4703}
4704
4705template <>
4706EIGEN_STRONG_INLINE Packet2f pdiv<Packet2f>(const Packet2f& a, const Packet2f& b) {
4707 return pdiv_float_common(a, b);
4708}
4709#endif
4710
4711//---------- bfloat16 ----------
4712// TODO: Add support for native armv8.6-a bfloat16_t
4713
4714// TODO: Guard if we have native bfloat16 support
4715typedef eigen_packet_wrapper<uint16x4_t, 19> Packet4bf;
4716
4717template <>
4718struct is_arithmetic<Packet4bf> {
4719 enum { value = true };
4720};
4721
4722template <>
4723struct packet_traits<bfloat16> : default_packet_traits {
4724 typedef Packet4bf type;
4725 typedef Packet4bf half;
4726 enum {
4727 Vectorizable = 1,
4728 AlignedOnScalar = 1,
4729 size = 4,
4730
4731 HasCmp = 1,
4732 HasAdd = 1,
4733 HasSub = 1,
4734 HasShift = 1,
4735 HasMul = 1,
4736 HasNegate = 1,
4737 HasAbs = 1,
4738 HasArg = 0,
4739 HasAbs2 = 1,
4740 HasAbsDiff = 1,
4741 HasMin = 1,
4742 HasMax = 1,
4743 HasConj = 1,
4744 HasSetLinear = 1,
4745 HasBlend = 0,
4746 HasDiv = 1,
4747 HasSin = EIGEN_FAST_MATH,
4748 HasCos = EIGEN_FAST_MATH,
4749 HasLog = 1,
4750 HasExp = 1,
4751 HasSqrt = 0,
4752 HasTanh = EIGEN_FAST_MATH,
4753 HasErf = EIGEN_FAST_MATH,
4754 HasBessel = 0, // Issues with accuracy.
4755 HasNdtri = 0
4756 };
4757};
4758
4759template <>
4760struct unpacket_traits<Packet4bf> {
4761 typedef bfloat16 type;
4762 typedef Packet4bf half;
4763 enum {
4764 size = 4,
4765 alignment = Aligned16,
4766 vectorizable = true,
4767 masked_load_available = false,
4768 masked_store_available = false
4769 };
4770};
4771
4772namespace detail {
4773template <>
4774EIGEN_ALWAYS_INLINE void zip_in_place<Packet4bf>(Packet4bf& p1, Packet4bf& p2) {
4775 const uint16x4x2_t tmp = vzip_u16(p1, p2);
4776 p1 = tmp.val[0];
4777 p2 = tmp.val[1];
4778}
4779} // namespace detail
4780
4781EIGEN_STRONG_INLINE Packet4bf F32ToBf16(const Packet4f& p) {
4782 // See the scalar implementation in BFloat16.h for a comprehensible explanation
4783 // of this fast rounding algorithm
4784 Packet4ui input = Packet4ui(vreinterpretq_u32_f32(p));
4785
4786 // lsb = (input >> 16) & 1
4787 Packet4ui lsb = vandq_u32(vshrq_n_u32(input, 16), vdupq_n_u32(1));
4788
4789 // rounding_bias = 0x7fff + lsb
4790 Packet4ui rounding_bias = vaddq_u32(lsb, vdupq_n_u32(0x7fff));
4791
4792 // input += rounding_bias
4793 input = vaddq_u32(input, rounding_bias);
4794
4795 // input = input >> 16
4796 input = vshrq_n_u32(input, 16);
4797
4798 // Replace float-nans by bfloat16-nans, that is 0x7fc0
4799 const Packet4ui bf16_nan = vdupq_n_u32(0x7fc0);
4800 const Packet4ui mask = vceqq_f32(p, p);
4801 input = vbslq_u32(mask, input, bf16_nan);
4802
4803 // output = static_cast<uint16_t>(input)
4804 return vmovn_u32(input);
4805}
4806
4807EIGEN_STRONG_INLINE Packet4f Bf16ToF32(const Packet4bf& p) {
4808 return Packet4f(vreinterpretq_f32_u32(vshlq_n_u32(vmovl_u16(p), 16)));
4809}
4810
4811EIGEN_STRONG_INLINE Packet4bf F32MaskToBf16Mask(const Packet4f& p) { return vmovn_u32(vreinterpretq_u32_f32(p)); }
4812
4813template <>
4814EIGEN_STRONG_INLINE Packet4bf pset1<Packet4bf>(const bfloat16& from) {
4815 return Packet4bf(pset1<Packet4us>(from.value));
4816}
4817
4818template <>
4819EIGEN_STRONG_INLINE bfloat16 pfirst<Packet4bf>(const Packet4bf& from) {
4820 return bfloat16_impl::raw_uint16_to_bfloat16(static_cast<uint16_t>(pfirst<Packet4us>(Packet4us(from))));
4821}
4822
4823template <>
4824EIGEN_STRONG_INLINE Packet4bf pload<Packet4bf>(const bfloat16* from) {
4825 return Packet4bf(pload<Packet4us>(reinterpret_cast<const uint16_t*>(from)));
4826}
4827
4828template <>
4829EIGEN_STRONG_INLINE Packet4bf ploadu<Packet4bf>(const bfloat16* from) {
4830 return Packet4bf(ploadu<Packet4us>(reinterpret_cast<const uint16_t*>(from)));
4831}
4832
4833template <>
4834EIGEN_STRONG_INLINE void pstore<bfloat16>(bfloat16* to, const Packet4bf& from) {
4835 EIGEN_DEBUG_ALIGNED_STORE vst1_u16(reinterpret_cast<uint16_t*>(to), from);
4836}
4837
4838template <>
4839EIGEN_STRONG_INLINE void pstoreu<bfloat16>(bfloat16* to, const Packet4bf& from) {
4840 EIGEN_DEBUG_UNALIGNED_STORE vst1_u16(reinterpret_cast<uint16_t*>(to), from);
4841}
4842
4843template <>
4844EIGEN_STRONG_INLINE Packet4bf ploaddup<Packet4bf>(const bfloat16* from) {
4845 return Packet4bf(ploaddup<Packet4us>(reinterpret_cast<const uint16_t*>(from)));
4846}
4847
4848template <>
4849EIGEN_STRONG_INLINE Packet4bf pabs(const Packet4bf& a) {
4850 return F32ToBf16(pabs<Packet4f>(Bf16ToF32(a)));
4851}
4852
4853template <>
4854EIGEN_STRONG_INLINE Packet4bf pmin<PropagateNumbers, Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4855 return F32ToBf16(pmin<PropagateNumbers, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4856}
4857template <>
4858EIGEN_STRONG_INLINE Packet4bf pmin<PropagateNaN, Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4859 return F32ToBf16(pmin<PropagateNaN, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4860}
4861
4862template <>
4863EIGEN_STRONG_INLINE Packet4bf pmin<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4864 return F32ToBf16(pmin<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4865}
4866
4867template <>
4868EIGEN_STRONG_INLINE Packet4bf pmax<PropagateNumbers, Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4869 return F32ToBf16(pmax<PropagateNumbers, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4870}
4871template <>
4872EIGEN_STRONG_INLINE Packet4bf pmax<PropagateNaN, Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4873 return F32ToBf16(pmax<PropagateNaN, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4874}
4875
4876template <>
4877EIGEN_STRONG_INLINE Packet4bf pmax<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4878 return F32ToBf16(pmax<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4879}
4880
4881template <>
4882EIGEN_STRONG_INLINE Packet4bf plset<Packet4bf>(const bfloat16& a) {
4883 return F32ToBf16(plset<Packet4f>(static_cast<float>(a)));
4884}
4885
4886template <>
4887EIGEN_STRONG_INLINE Packet4bf por(const Packet4bf& a, const Packet4bf& b) {
4888 return Packet4bf(por<Packet4us>(Packet4us(a), Packet4us(b)));
4889}
4890
4891template <>
4892EIGEN_STRONG_INLINE Packet4bf pxor(const Packet4bf& a, const Packet4bf& b) {
4893 return Packet4bf(pxor<Packet4us>(Packet4us(a), Packet4us(b)));
4894}
4895
4896template <>
4897EIGEN_STRONG_INLINE Packet4bf pand(const Packet4bf& a, const Packet4bf& b) {
4898 return Packet4bf(pand<Packet4us>(Packet4us(a), Packet4us(b)));
4899}
4900
4901template <>
4902EIGEN_STRONG_INLINE Packet4bf pandnot(const Packet4bf& a, const Packet4bf& b) {
4903 return Packet4bf(pandnot<Packet4us>(Packet4us(a), Packet4us(b)));
4904}
4905
4906template <>
4907EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4bf pselect(const Packet4bf& mask, const Packet4bf& a, const Packet4bf& b) {
4908 return Packet4bf(pselect<Packet4us>(Packet4us(mask), Packet4us(a), Packet4us(b)));
4909}
4910
4911template <>
4912EIGEN_STRONG_INLINE Packet4bf print<Packet4bf>(const Packet4bf& a) {
4913 return F32ToBf16(print<Packet4f>(Bf16ToF32(a)));
4914}
4915
4916template <>
4917EIGEN_STRONG_INLINE Packet4bf pfloor<Packet4bf>(const Packet4bf& a) {
4918 return F32ToBf16(pfloor<Packet4f>(Bf16ToF32(a)));
4919}
4920
4921template <>
4922EIGEN_STRONG_INLINE Packet4bf pceil<Packet4bf>(const Packet4bf& a) {
4923 return F32ToBf16(pceil<Packet4f>(Bf16ToF32(a)));
4924}
4925
4926template <>
4927EIGEN_STRONG_INLINE Packet4bf pround<Packet4bf>(const Packet4bf& a) {
4928 return F32ToBf16(pround<Packet4f>(Bf16ToF32(a)));
4929}
4930
4931template <>
4932EIGEN_STRONG_INLINE Packet4bf ptrunc<Packet4bf>(const Packet4bf& a) {
4933 return F32ToBf16(ptrunc<Packet4f>(Bf16ToF32(a)));
4934}
4935
4936template <>
4937EIGEN_STRONG_INLINE Packet4bf pconj(const Packet4bf& a) {
4938 return a;
4939}
4940
4941template <>
4942EIGEN_STRONG_INLINE Packet4bf padd<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4943 return F32ToBf16(padd<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4944}
4945
4946template <>
4947EIGEN_STRONG_INLINE Packet4bf psub<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4948 return F32ToBf16(psub<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4949}
4950
4951template <>
4952EIGEN_STRONG_INLINE Packet4bf pmul<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4953 return F32ToBf16(pmul<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4954}
4955
4956template <>
4957EIGEN_STRONG_INLINE Packet4bf pdiv<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
4958 return F32ToBf16(pdiv<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
4959}
4960
4961template <>
4962EIGEN_STRONG_INLINE Packet4bf pgather<bfloat16, Packet4bf>(const bfloat16* from, Index stride) {
4963 return Packet4bf(pgather<uint16_t, Packet4us>(reinterpret_cast<const uint16_t*>(from), stride));
4964}
4965
4966template <>
4967EIGEN_STRONG_INLINE void pscatter<bfloat16, Packet4bf>(bfloat16* to, const Packet4bf& from, Index stride) {
4968 pscatter<uint16_t, Packet4us>(reinterpret_cast<uint16_t*>(to), Packet4us(from), stride);
4969}
4970
4971template <>
4972EIGEN_STRONG_INLINE bfloat16 predux<Packet4bf>(const Packet4bf& a) {
4973 return static_cast<bfloat16>(predux<Packet4f>(Bf16ToF32(a)));
4974}
4975
4976template <>
4977EIGEN_STRONG_INLINE bfloat16 predux_max<Packet4bf>(const Packet4bf& a) {
4978 return static_cast<bfloat16>(predux_max<Packet4f>(Bf16ToF32(a)));
4979}
4980
4981template <>
4982EIGEN_STRONG_INLINE bfloat16 predux_min<Packet4bf>(const Packet4bf& a) {
4983 return static_cast<bfloat16>(predux_min<Packet4f>(Bf16ToF32(a)));
4984}
4985
4986template <>
4987EIGEN_STRONG_INLINE bfloat16 predux_mul<Packet4bf>(const Packet4bf& a) {
4988 return static_cast<bfloat16>(predux_mul<Packet4f>(Bf16ToF32(a)));
4989}
4990
4991template <>
4992EIGEN_STRONG_INLINE Packet4bf preverse<Packet4bf>(const Packet4bf& a) {
4993 return Packet4bf(preverse<Packet4us>(Packet4us(a)));
4994}
4995
4996EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4bf, 4>& kernel) {
4997 detail::ptranspose_impl(kernel);
4998}
4999
5000template <>
5001EIGEN_STRONG_INLINE Packet4bf pabsdiff<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
5002 return F32ToBf16(pabsdiff<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
5003}
5004
5005template <>
5006EIGEN_STRONG_INLINE Packet4bf pcmp_eq<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
5007 return F32MaskToBf16Mask(pcmp_eq<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
5008}
5009
5010template <>
5011EIGEN_STRONG_INLINE Packet4bf pcmp_lt<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
5012 return F32MaskToBf16Mask(pcmp_lt<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
5013}
5014
5015template <>
5016EIGEN_STRONG_INLINE Packet4bf pcmp_lt_or_nan<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
5017 return F32MaskToBf16Mask(pcmp_lt_or_nan<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
5018}
5019
5020template <>
5021EIGEN_STRONG_INLINE Packet4bf pcmp_le<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
5022 return F32MaskToBf16Mask(pcmp_le<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
5023}
5024
5025template <>
5026EIGEN_STRONG_INLINE Packet4bf pnegate<Packet4bf>(const Packet4bf& a) {
5027 return Packet4bf(pxor<Packet4us>(Packet4us(a), pset1<Packet4us>(static_cast<uint16_t>(0x8000))));
5028}
5029
5030//---------- double ----------
5031
5032// Clang 3.5 in the iOS toolchain has an ICE triggered by NEON intrisics for double.
5033// Confirmed at least with __apple_build_version__ = 6000054.
5034#if EIGEN_COMP_CLANGAPPLE
5035// Let's hope that by the time __apple_build_version__ hits the 601* range, the bug will be fixed.
5036// https://gist.github.com/yamaya/2924292 suggests that the 3 first digits are only updated with
5037// major toolchain updates.
5038#define EIGEN_APPLE_DOUBLE_NEON_BUG (EIGEN_COMP_CLANGAPPLE < 6010000)
5039#else
5040#define EIGEN_APPLE_DOUBLE_NEON_BUG 0
5041#endif
5042
5043#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
5044
5045#if EIGEN_COMP_GNUC
5046// Bug 907: workaround missing declarations of the following two functions in the ADK
5047// Defining these functions as templates ensures that if these intrinsics are
5048// already defined in arm_neon.h, then our workaround doesn't cause a conflict
5049// and has lower priority in overload resolution.
5050// This doesn't work with MSVC though, since the function names are macros.
5051template <typename T>
5052uint64x2_t vreinterpretq_u64_f64(T a) {
5053 return (uint64x2_t)a;
5054}
5055
5056template <typename T>
5057float64x2_t vreinterpretq_f64_u64(T a) {
5058 return (float64x2_t)a;
5059}
5060#endif
5061
5062#if EIGEN_COMP_MSVC_STRICT
5063typedef eigen_packet_wrapper<float64x2_t, 18> Packet2d;
5064typedef eigen_packet_wrapper<float64x1_t, 19> Packet1d;
5065
5066EIGEN_ALWAYS_INLINE Packet2d make_packet2d(double a, double b) {
5067 double from[2] = {a, b};
5068 return vld1q_f64(from);
5069}
5070
5071#else
5072typedef float64x2_t Packet2d;
5073typedef float64x1_t Packet1d;
5074
5075EIGEN_ALWAYS_INLINE Packet2d make_packet2d(double a, double b) { return Packet2d{a, b}; }
5076#endif
5077
5078// fuctionally equivalent to _mm_shuffle_pd in SSE (i.e. shuffle(m, n, mask) equals _mm_shuffle_pd(m,n,mask))
5079// Currently used in LU/arch/InverseSize4.h to enable a shared implementation
5080// for fast inversion of matrices of size 4.
5081EIGEN_STRONG_INLINE Packet2d shuffle(const Packet2d& m, const Packet2d& n, int mask) {
5082 const double* a = reinterpret_cast<const double*>(&m);
5083 const double* b = reinterpret_cast<const double*>(&n);
5084 Packet2d res = make_packet2d(*(a + (mask & 1)), *(b + ((mask >> 1) & 1)));
5085 return res;
5086}
5087
5088EIGEN_STRONG_INLINE Packet2d vec2d_swizzle2(const Packet2d& a, const Packet2d& b, int mask) {
5089 return shuffle(a, b, mask);
5090}
5091EIGEN_STRONG_INLINE Packet2d vec2d_unpacklo(const Packet2d& a, const Packet2d& b) { return shuffle(a, b, 0); }
5092EIGEN_STRONG_INLINE Packet2d vec2d_unpackhi(const Packet2d& a, const Packet2d& b) { return shuffle(a, b, 3); }
5093#define vec2d_duplane(a, p) Packet2d(vdupq_laneq_f64(a, p))
5094
5095template <>
5096struct packet_traits<double> : default_packet_traits {
5097 typedef Packet2d type;
5098 typedef Packet2d half;
5099 enum {
5100 Vectorizable = 1,
5101 AlignedOnScalar = 1,
5102 size = 2,
5103
5104 HasCmp = 1,
5105 HasAdd = 1,
5106 HasSub = 1,
5107 HasShift = 1,
5108 HasMul = 1,
5109 HasNegate = 1,
5110 HasAbs = 1,
5111 HasArg = 0,
5112 HasAbs2 = 1,
5113 HasAbsDiff = 1,
5114 HasMin = 1,
5115 HasMax = 1,
5116 HasConj = 1,
5117 HasSetLinear = 1,
5118 HasBlend = 0,
5119
5120 HasDiv = 1,
5121
5122#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
5123 HasExp = 1,
5124 HasLog = 1,
5125 HasATan = 1,
5126#endif
5127 HasSin = EIGEN_FAST_MATH,
5128 HasCos = EIGEN_FAST_MATH,
5129 HasSqrt = 1,
5130 HasRsqrt = 1,
5131 HasTanh = 0,
5132 HasErf = 0
5133 };
5134};
5135
5136template <>
5137struct unpacket_traits<Packet2d> {
5138 typedef double type;
5139 typedef Packet2d half;
5140 typedef Packet2l integer_packet;
5141 enum {
5142 size = 2,
5143 alignment = Aligned16,
5144 vectorizable = true,
5145 masked_load_available = false,
5146 masked_store_available = false
5147 };
5148};
5149
5150template <>
5151EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) {
5152 return vdupq_n_f64(from);
5153}
5154
5155template <>
5156EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) {
5157 const double c[] = {0.0, 1.0};
5158 return vaddq_f64(pset1<Packet2d>(a), vld1q_f64(c));
5159}
5160
5161template <>
5162EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) {
5163 return vaddq_f64(a, b);
5164}
5165
5166template <>
5167EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) {
5168 return vsubq_f64(a, b);
5169}
5170
5171template <>
5172EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d&, const Packet2d&);
5173template <>
5174EIGEN_STRONG_INLINE Packet2d paddsub<Packet2d>(const Packet2d& a, const Packet2d& b) {
5175 const Packet2d mask = make_packet2d(numext::bit_cast<double>(0x8000000000000000ull), 0.0);
5176 return padd(a, pxor(mask, b));
5177}
5178
5179template <>
5180EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) {
5181 return vnegq_f64(a);
5182}
5183
5184template <>
5185EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) {
5186 return a;
5187}
5188
5189template <>
5190EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) {
5191 return vmulq_f64(a, b);
5192}
5193
5194template <>
5195EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) {
5196 return vdivq_f64(a, b);
5197}
5198
5199#ifdef EIGEN_VECTORIZE_FMA
5200// See bug 936. See above comment about FMA for float.
5201template <>
5202EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) {
5203 return vfmaq_f64(c, a, b);
5204}
5205#else
5206template <>
5207EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) {
5208 return vmlaq_f64(c, a, b);
5209}
5210#endif
5211
5212template <>
5213EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) {
5214 return vminq_f64(a, b);
5215}
5216
5217#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
5218// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8
5219// systems).
5220template <>
5221EIGEN_STRONG_INLINE Packet2d pmin<PropagateNumbers, Packet2d>(const Packet2d& a, const Packet2d& b) {
5222 return vminnmq_f64(a, b);
5223}
5224template <>
5225EIGEN_STRONG_INLINE Packet2d pmax<PropagateNumbers, Packet2d>(const Packet2d& a, const Packet2d& b) {
5226 return vmaxnmq_f64(a, b);
5227}
5228
5229#endif
5230
5231template <>
5232EIGEN_STRONG_INLINE Packet2d pmin<PropagateNaN, Packet2d>(const Packet2d& a, const Packet2d& b) {
5233 return pmin<Packet2d>(a, b);
5234}
5235
5236template <>
5237EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) {
5238 return vmaxq_f64(a, b);
5239}
5240
5241template <>
5242EIGEN_STRONG_INLINE Packet2d pmax<PropagateNaN, Packet2d>(const Packet2d& a, const Packet2d& b) {
5243 return pmax<Packet2d>(a, b);
5244}
5245
5246// Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics
5247template <>
5248EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) {
5249 return vreinterpretq_f64_u64(vandq_u64(vreinterpretq_u64_f64(a), vreinterpretq_u64_f64(b)));
5250}
5251
5252template <>
5253EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) {
5254 return vreinterpretq_f64_u64(vorrq_u64(vreinterpretq_u64_f64(a), vreinterpretq_u64_f64(b)));
5255}
5256
5257template <>
5258EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) {
5259 return vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a), vreinterpretq_u64_f64(b)));
5260}
5261
5262template <>
5263EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) {
5264 return vreinterpretq_f64_u64(vbicq_u64(vreinterpretq_u64_f64(a), vreinterpretq_u64_f64(b)));
5265}
5266
5267template <>
5268EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b) {
5269 return vreinterpretq_f64_u64(vcleq_f64(a, b));
5270}
5271
5272template <>
5273EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b) {
5274 return vreinterpretq_f64_u64(vcltq_f64(a, b));
5275}
5276
5277template <>
5278EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(const Packet2d& a, const Packet2d& b) {
5279 return vreinterpretq_f64_u32(vmvnq_u32(vreinterpretq_u32_u64(vcgeq_f64(a, b))));
5280}
5281
5282template <>
5283EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b) {
5284 return vreinterpretq_f64_u64(vceqq_f64(a, b));
5285}
5286
5287template <>
5288EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) {
5289 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f64(from);
5290}
5291
5292template <>
5293EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) {
5294 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f64(from);
5295}
5296
5297template <>
5298EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) {
5299 return vld1q_dup_f64(from);
5300}
5301template <>
5302EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) {
5303 EIGEN_DEBUG_ALIGNED_STORE vst1q_f64(to, from);
5304}
5305
5306template <>
5307EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) {
5308 EIGEN_DEBUG_UNALIGNED_STORE vst1q_f64(to, from);
5309}
5310
5311template <>
5312EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2d pgather<double, Packet2d>(const double* from, Index stride) {
5313 Packet2d res = pset1<Packet2d>(0.0);
5314 res = vld1q_lane_f64(from + 0 * stride, res, 0);
5315 res = vld1q_lane_f64(from + 1 * stride, res, 1);
5316 return res;
5317}
5318
5319template <>
5320EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) {
5321 vst1q_lane_f64(to + stride * 0, from, 0);
5322 vst1q_lane_f64(to + stride * 1, from, 1);
5323}
5324
5325template <>
5326EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) {
5327 EIGEN_ARM_PREFETCH(addr);
5328}
5329
5330// FIXME only store the 2 first elements ?
5331template <>
5332EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) {
5333 return vgetq_lane_f64(a, 0);
5334}
5335
5336template <>
5337EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) {
5338 return vcombine_f64(vget_high_f64(a), vget_low_f64(a));
5339}
5340
5341template <>
5342EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) {
5343 return vabsq_f64(a);
5344}
5345
5346template <>
5347EIGEN_STRONG_INLINE Packet2d psignbit(const Packet2d& a) {
5348 return vreinterpretq_f64_s64(vshrq_n_s64(vreinterpretq_s64_f64(a), 63));
5349}
5350
5351template <>
5352EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) {
5353 return vaddvq_f64(a);
5354}
5355
5356// Other reduction functions:
5357// mul
5358#if EIGEN_COMP_CLANGAPPLE
5359template <>
5360EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) {
5361 return (vget_low_f64(a) * vget_high_f64(a))[0];
5362}
5363#else
5364template <>
5365EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) {
5366 return vget_lane_f64(vmul_f64(vget_low_f64(a), vget_high_f64(a)), 0);
5367}
5368#endif
5369
5370// min
5371template <>
5372EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) {
5373 return vminvq_f64(a);
5374}
5375
5376// max
5377template <>
5378EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) {
5379 return vmaxvq_f64(a);
5380}
5381
5382EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2d, 2>& kernel) {
5383 const float64x2_t tmp1 = vzip1q_f64(kernel.packet[0], kernel.packet[1]);
5384 const float64x2_t tmp2 = vzip2q_f64(kernel.packet[0], kernel.packet[1]);
5385
5386 kernel.packet[0] = tmp1;
5387 kernel.packet[1] = tmp2;
5388}
5389
5390template <>
5391EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2d pselect(const Packet2d& mask, const Packet2d& a, const Packet2d& b) {
5392 return vbslq_f64(vreinterpretq_u64_f64(mask), a, b);
5393}
5394
5395template <>
5396EIGEN_STRONG_INLINE Packet2d print<Packet2d>(const Packet2d& a) {
5397 return vrndnq_f64(a);
5398}
5399
5400template <>
5401EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) {
5402 return vrndmq_f64(a);
5403}
5404
5405template <>
5406EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) {
5407 return vrndpq_f64(a);
5408}
5409
5410template <>
5411EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) {
5412 return vrndaq_f64(a);
5413}
5414
5415template <>
5416EIGEN_STRONG_INLINE Packet2d ptrunc<Packet2d>(const Packet2d& a) {
5417 return vrndq_f64(a);
5418}
5419
5420template <>
5421EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) {
5422 return pldexp_generic(a, exponent);
5423}
5424
5425template <>
5426EIGEN_STRONG_INLINE Packet2d pfrexp<Packet2d>(const Packet2d& a, Packet2d& exponent) {
5427 return pfrexp_generic(a, exponent);
5428}
5429
5430template <>
5431EIGEN_STRONG_INLINE Packet2d pset1frombits<Packet2d>(uint64_t from) {
5432 return vreinterpretq_f64_u64(vdupq_n_u64(from));
5433}
5434
5435template <>
5436EIGEN_STRONG_INLINE Packet2d prsqrt(const Packet2d& a) {
5437 // Do Newton iterations for 1/sqrt(x).
5438 return generic_rsqrt_newton_step<Packet2d, /*Steps=*/3>::run(a, vrsqrteq_f64(a));
5439}
5440
5441template <>
5442EIGEN_STRONG_INLINE Packet2d psqrt(const Packet2d& _x) {
5443 return vsqrtq_f64(_x);
5444}
5445
5446#endif // EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
5447
5448// Do we have an fp16 types and supporting Neon intrinsics?
5449#if EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
5450typedef float16x4_t Packet4hf;
5451typedef float16x8_t Packet8hf;
5452
5453template <>
5454struct packet_traits<Eigen::half> : default_packet_traits {
5455 typedef Packet8hf type;
5456 typedef Packet4hf half;
5457 enum {
5458 Vectorizable = 1,
5459 AlignedOnScalar = 1,
5460 size = 8,
5461
5462 HasCmp = 1,
5463 HasCast = 1,
5464 HasAdd = 1,
5465 HasSub = 1,
5466 HasShift = 1,
5467 HasMul = 1,
5468 HasNegate = 1,
5469 HasAbs = 1,
5470 HasArg = 0,
5471 HasAbs2 = 1,
5472 HasAbsDiff = 0,
5473 HasMin = 1,
5474 HasMax = 1,
5475 HasConj = 1,
5476 HasSetLinear = 1,
5477 HasBlend = 0,
5478 HasInsert = 1,
5479 HasReduxp = 1,
5480 HasDiv = 1,
5481 HasSin = 0,
5482 HasCos = 0,
5483 HasLog = 0,
5484 HasExp = 0,
5485 HasTanh = packet_traits<float>::HasTanh, // tanh<half> calls tanh<float>
5486 HasSqrt = 1,
5487 HasRsqrt = 1,
5488 HasErf = EIGEN_FAST_MATH,
5489 HasBessel = 0, // Issues with accuracy.
5490 HasNdtri = 0
5491 };
5492};
5493
5494template <>
5495struct unpacket_traits<Packet4hf> {
5496 typedef Eigen::half type;
5497 typedef Packet4hf half;
5498 enum {
5499 size = 4,
5500 alignment = Aligned16,
5501 vectorizable = true,
5502 masked_load_available = false,
5503 masked_store_available = false
5504 };
5505};
5506
5507template <>
5508struct unpacket_traits<Packet8hf> {
5509 typedef Eigen::half type;
5510 typedef Packet4hf half;
5511 enum {
5512 size = 8,
5513 alignment = Aligned16,
5514 vectorizable = true,
5515 masked_load_available = false,
5516 masked_store_available = false
5517 };
5518};
5519
5520template <>
5521EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf predux_half_dowto4<Packet8hf>(const Packet8hf& a) {
5522 return vadd_f16(vget_low_f16(a), vget_high_f16(a));
5523}
5524
5525template <>
5526EIGEN_STRONG_INLINE Packet8hf pset1<Packet8hf>(const Eigen::half& from) {
5527 return vdupq_n_f16(from.x);
5528}
5529
5530template <>
5531EIGEN_STRONG_INLINE Packet4hf pset1<Packet4hf>(const Eigen::half& from) {
5532 return vdup_n_f16(from.x);
5533}
5534
5535template <>
5536EIGEN_STRONG_INLINE Packet8hf plset<Packet8hf>(const Eigen::half& a) {
5537 const float16_t f[] = {0, 1, 2, 3, 4, 5, 6, 7};
5538 Packet8hf countdown = vld1q_f16(f);
5539 return vaddq_f16(pset1<Packet8hf>(a), countdown);
5540}
5541
5542template <>
5543EIGEN_STRONG_INLINE Packet4hf plset<Packet4hf>(const Eigen::half& a) {
5544 const float16_t f[] = {0, 1, 2, 3};
5545 Packet4hf countdown = vld1_f16(f);
5546 return vadd_f16(pset1<Packet4hf>(a), countdown);
5547}
5548
5549template <>
5550EIGEN_STRONG_INLINE Packet8hf padd<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5551 return vaddq_f16(a, b);
5552}
5553
5554template <>
5555EIGEN_STRONG_INLINE Packet4hf padd<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5556 return vadd_f16(a, b);
5557}
5558
5559template <>
5560EIGEN_STRONG_INLINE Packet8hf psub<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5561 return vsubq_f16(a, b);
5562}
5563
5564template <>
5565EIGEN_STRONG_INLINE Packet4hf psub<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5566 return vsub_f16(a, b);
5567}
5568
5569template <>
5570EIGEN_STRONG_INLINE Packet8hf pnegate(const Packet8hf& a) {
5571 return vnegq_f16(a);
5572}
5573
5574template <>
5575EIGEN_STRONG_INLINE Packet4hf pnegate(const Packet4hf& a) {
5576 return vneg_f16(a);
5577}
5578
5579template <>
5580EIGEN_STRONG_INLINE Packet8hf pconj(const Packet8hf& a) {
5581 return a;
5582}
5583
5584template <>
5585EIGEN_STRONG_INLINE Packet4hf pconj(const Packet4hf& a) {
5586 return a;
5587}
5588
5589template <>
5590EIGEN_STRONG_INLINE Packet8hf pmul<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5591 return vmulq_f16(a, b);
5592}
5593
5594template <>
5595EIGEN_STRONG_INLINE Packet4hf pmul<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5596 return vmul_f16(a, b);
5597}
5598
5599template <>
5600EIGEN_STRONG_INLINE Packet8hf pdiv<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5601 return vdivq_f16(a, b);
5602}
5603
5604template <>
5605EIGEN_STRONG_INLINE Packet4hf pdiv<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5606 return vdiv_f16(a, b);
5607}
5608
5609template <>
5610EIGEN_STRONG_INLINE Packet8hf pmadd(const Packet8hf& a, const Packet8hf& b, const Packet8hf& c) {
5611 return vfmaq_f16(c, a, b);
5612}
5613
5614template <>
5615EIGEN_STRONG_INLINE Packet4hf pmadd(const Packet4hf& a, const Packet4hf& b, const Packet4hf& c) {
5616 return vfma_f16(c, a, b);
5617}
5618
5619template <>
5620EIGEN_STRONG_INLINE Packet8hf pmin<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5621 return vminq_f16(a, b);
5622}
5623
5624template <>
5625EIGEN_STRONG_INLINE Packet4hf pmin<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5626 return vmin_f16(a, b);
5627}
5628
5629#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
5630// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8
5631// systems).
5632template <>
5633EIGEN_STRONG_INLINE Packet4hf pmin<PropagateNumbers, Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5634 return vminnm_f16(a, b);
5635}
5636template <>
5637EIGEN_STRONG_INLINE Packet8hf pmin<PropagateNumbers, Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5638 return vminnmq_f16(a, b);
5639}
5640#endif
5641
5642template <>
5643EIGEN_STRONG_INLINE Packet4hf pmin<PropagateNaN, Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5644 return pmin<Packet4hf>(a, b);
5645}
5646
5647template <>
5648EIGEN_STRONG_INLINE Packet8hf pmin<PropagateNaN, Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5649 return pmin<Packet8hf>(a, b);
5650}
5651
5652template <>
5653EIGEN_STRONG_INLINE Packet8hf pmax<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5654 return vmaxq_f16(a, b);
5655}
5656
5657template <>
5658EIGEN_STRONG_INLINE Packet4hf pmax<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5659 return vmax_f16(a, b);
5660}
5661
5662#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
5663// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8
5664// systems).
5665template <>
5666EIGEN_STRONG_INLINE Packet4hf pmax<PropagateNumbers, Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5667 return vmaxnm_f16(a, b);
5668}
5669template <>
5670EIGEN_STRONG_INLINE Packet8hf pmax<PropagateNumbers, Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5671 return vmaxnmq_f16(a, b);
5672}
5673#endif
5674
5675template <>
5676EIGEN_STRONG_INLINE Packet4hf pmax<PropagateNaN, Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5677 return pmax<Packet4hf>(a, b);
5678}
5679
5680template <>
5681EIGEN_STRONG_INLINE Packet8hf pmax<PropagateNaN, Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5682 return pmax<Packet8hf>(a, b);
5683}
5684
5685#define EIGEN_MAKE_ARM_FP16_CMP_8(name) \
5686 template <> \
5687 EIGEN_STRONG_INLINE Packet8hf pcmp_##name(const Packet8hf& a, const Packet8hf& b) { \
5688 return vreinterpretq_f16_u16(vc##name##q_f16(a, b)); \
5689 }
5690
5691#define EIGEN_MAKE_ARM_FP16_CMP_4(name) \
5692 template <> \
5693 EIGEN_STRONG_INLINE Packet4hf pcmp_##name(const Packet4hf& a, const Packet4hf& b) { \
5694 return vreinterpret_f16_u16(vc##name##_f16(a, b)); \
5695 }
5696
5697EIGEN_MAKE_ARM_FP16_CMP_8(eq)
5698EIGEN_MAKE_ARM_FP16_CMP_8(lt)
5699EIGEN_MAKE_ARM_FP16_CMP_8(le)
5700
5701EIGEN_MAKE_ARM_FP16_CMP_4(eq)
5702EIGEN_MAKE_ARM_FP16_CMP_4(lt)
5703EIGEN_MAKE_ARM_FP16_CMP_4(le)
5704
5705#undef EIGEN_MAKE_ARM_FP16_CMP_8
5706#undef EIGEN_MAKE_ARM_FP16_CMP_4
5707
5708template <>
5709EIGEN_STRONG_INLINE Packet8hf pcmp_lt_or_nan<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5710 return vreinterpretq_f16_u16(vmvnq_u16(vcgeq_f16(a, b)));
5711}
5712
5713template <>
5714EIGEN_STRONG_INLINE Packet4hf pcmp_lt_or_nan<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5715 return vreinterpret_f16_u16(vmvn_u16(vcge_f16(a, b)));
5716}
5717
5718template <>
5719EIGEN_STRONG_INLINE Packet8hf print<Packet8hf>(const Packet8hf& a) {
5720 return vrndnq_f16(a);
5721}
5722
5723template <>
5724EIGEN_STRONG_INLINE Packet4hf print<Packet4hf>(const Packet4hf& a) {
5725 return vrndn_f16(a);
5726}
5727
5728template <>
5729EIGEN_STRONG_INLINE Packet8hf pfloor<Packet8hf>(const Packet8hf& a) {
5730 return vrndmq_f16(a);
5731}
5732
5733template <>
5734EIGEN_STRONG_INLINE Packet4hf pfloor<Packet4hf>(const Packet4hf& a) {
5735 return vrndm_f16(a);
5736}
5737
5738template <>
5739EIGEN_STRONG_INLINE Packet8hf pceil<Packet8hf>(const Packet8hf& a) {
5740 return vrndpq_f16(a);
5741}
5742
5743template <>
5744EIGEN_STRONG_INLINE Packet4hf pceil<Packet4hf>(const Packet4hf& a) {
5745 return vrndp_f16(a);
5746}
5747
5748template <>
5749EIGEN_STRONG_INLINE Packet8hf pround<Packet8hf>(const Packet8hf& a) {
5750 return vrndaq_f16(a);
5751}
5752
5753template <>
5754EIGEN_STRONG_INLINE Packet4hf pround<Packet4hf>(const Packet4hf& a) {
5755 return vrnda_f16(a);
5756}
5757
5758template <>
5759EIGEN_STRONG_INLINE Packet8hf ptrunc<Packet8hf>(const Packet8hf& a) {
5760 return vrndq_f16(a);
5761}
5762
5763template <>
5764EIGEN_STRONG_INLINE Packet4hf ptrunc<Packet4hf>(const Packet4hf& a) {
5765 return vrnd_f16(a);
5766}
5767
5768template <>
5769EIGEN_STRONG_INLINE Packet8hf psqrt<Packet8hf>(const Packet8hf& a) {
5770 return vsqrtq_f16(a);
5771}
5772
5773template <>
5774EIGEN_STRONG_INLINE Packet4hf psqrt<Packet4hf>(const Packet4hf& a) {
5775 return vsqrt_f16(a);
5776}
5777
5778template <>
5779EIGEN_STRONG_INLINE Packet8hf pand<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5780 return vreinterpretq_f16_u16(vandq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
5781}
5782
5783template <>
5784EIGEN_STRONG_INLINE Packet4hf pand<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5785 return vreinterpret_f16_u16(vand_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
5786}
5787
5788template <>
5789EIGEN_STRONG_INLINE Packet8hf por<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5790 return vreinterpretq_f16_u16(vorrq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
5791}
5792
5793template <>
5794EIGEN_STRONG_INLINE Packet4hf por<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5795 return vreinterpret_f16_u16(vorr_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
5796}
5797
5798template <>
5799EIGEN_STRONG_INLINE Packet8hf pxor<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5800 return vreinterpretq_f16_u16(veorq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
5801}
5802
5803template <>
5804EIGEN_STRONG_INLINE Packet4hf pxor<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5805 return vreinterpret_f16_u16(veor_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
5806}
5807
5808template <>
5809EIGEN_STRONG_INLINE Packet8hf pandnot<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
5810 return vreinterpretq_f16_u16(vbicq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
5811}
5812
5813template <>
5814EIGEN_STRONG_INLINE Packet4hf pandnot<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
5815 return vreinterpret_f16_u16(vbic_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
5816}
5817
5818template <>
5819EIGEN_STRONG_INLINE Packet8hf pload<Packet8hf>(const Eigen::half* from) {
5820 EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f16(reinterpret_cast<const float16_t*>(from));
5821}
5822
5823template <>
5824EIGEN_STRONG_INLINE Packet4hf pload<Packet4hf>(const Eigen::half* from) {
5825 EIGEN_DEBUG_ALIGNED_LOAD return vld1_f16(reinterpret_cast<const float16_t*>(from));
5826}
5827
5828template <>
5829EIGEN_STRONG_INLINE Packet8hf ploadu<Packet8hf>(const Eigen::half* from) {
5830 EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f16(reinterpret_cast<const float16_t*>(from));
5831}
5832
5833template <>
5834EIGEN_STRONG_INLINE Packet4hf ploadu<Packet4hf>(const Eigen::half* from) {
5835 EIGEN_DEBUG_UNALIGNED_LOAD return vld1_f16(reinterpret_cast<const float16_t*>(from));
5836}
5837
5838template <>
5839EIGEN_STRONG_INLINE Packet8hf ploaddup<Packet8hf>(const Eigen::half* from) {
5840 Packet8hf packet;
5841 packet[0] = from[0].x;
5842 packet[1] = from[0].x;
5843 packet[2] = from[1].x;
5844 packet[3] = from[1].x;
5845 packet[4] = from[2].x;
5846 packet[5] = from[2].x;
5847 packet[6] = from[3].x;
5848 packet[7] = from[3].x;
5849 return packet;
5850}
5851
5852template <>
5853EIGEN_STRONG_INLINE Packet4hf ploaddup<Packet4hf>(const Eigen::half* from) {
5854 float16x4_t packet;
5855 float16_t* tmp;
5856 tmp = (float16_t*)&packet;
5857 tmp[0] = from[0].x;
5858 tmp[1] = from[0].x;
5859 tmp[2] = from[1].x;
5860 tmp[3] = from[1].x;
5861 return packet;
5862}
5863
5864template <>
5865EIGEN_STRONG_INLINE Packet8hf ploadquad<Packet8hf>(const Eigen::half* from) {
5866 Packet4hf lo, hi;
5867 lo = vld1_dup_f16(reinterpret_cast<const float16_t*>(from));
5868 hi = vld1_dup_f16(reinterpret_cast<const float16_t*>(from + 1));
5869 return vcombine_f16(lo, hi);
5870}
5871
5872EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pinsertfirst(const Packet8hf& a, Eigen::half b) {
5873 return vsetq_lane_f16(b.x, a, 0);
5874}
5875
5876EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pinsertfirst(const Packet4hf& a, Eigen::half b) {
5877 return vset_lane_f16(b.x, a, 0);
5878}
5879
5880template <>
5881EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pselect(const Packet8hf& mask, const Packet8hf& a, const Packet8hf& b) {
5882 return vbslq_f16(vreinterpretq_u16_f16(mask), a, b);
5883}
5884
5885template <>
5886EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pselect(const Packet4hf& mask, const Packet4hf& a, const Packet4hf& b) {
5887 return vbsl_f16(vreinterpret_u16_f16(mask), a, b);
5888}
5889
5890EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pinsertlast(const Packet8hf& a, Eigen::half b) {
5891 return vsetq_lane_f16(b.x, a, 7);
5892}
5893
5894EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pinsertlast(const Packet4hf& a, Eigen::half b) {
5895 return vset_lane_f16(b.x, a, 3);
5896}
5897
5898template <>
5899EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet8hf& from) {
5900 EIGEN_DEBUG_ALIGNED_STORE vst1q_f16(reinterpret_cast<float16_t*>(to), from);
5901}
5902
5903template <>
5904EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet4hf& from) {
5905 EIGEN_DEBUG_ALIGNED_STORE vst1_f16(reinterpret_cast<float16_t*>(to), from);
5906}
5907
5908template <>
5909EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet8hf& from) {
5910 EIGEN_DEBUG_UNALIGNED_STORE vst1q_f16(reinterpret_cast<float16_t*>(to), from);
5911}
5912
5913template <>
5914EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet4hf& from) {
5915 EIGEN_DEBUG_UNALIGNED_STORE vst1_f16(reinterpret_cast<float16_t*>(to), from);
5916}
5917
5918template <>
5919EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pgather<Eigen::half, Packet8hf>(const Eigen::half* from, Index stride) {
5920 Packet8hf res = pset1<Packet8hf>(Eigen::half(0.f));
5921 res = vsetq_lane_f16(from[0 * stride].x, res, 0);
5922 res = vsetq_lane_f16(from[1 * stride].x, res, 1);
5923 res = vsetq_lane_f16(from[2 * stride].x, res, 2);
5924 res = vsetq_lane_f16(from[3 * stride].x, res, 3);
5925 res = vsetq_lane_f16(from[4 * stride].x, res, 4);
5926 res = vsetq_lane_f16(from[5 * stride].x, res, 5);
5927 res = vsetq_lane_f16(from[6 * stride].x, res, 6);
5928 res = vsetq_lane_f16(from[7 * stride].x, res, 7);
5929 return res;
5930}
5931
5932template <>
5933EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pgather<Eigen::half, Packet4hf>(const Eigen::half* from, Index stride) {
5934 Packet4hf res = pset1<Packet4hf>(Eigen::half(0.f));
5935 res = vset_lane_f16(from[0 * stride].x, res, 0);
5936 res = vset_lane_f16(from[1 * stride].x, res, 1);
5937 res = vset_lane_f16(from[2 * stride].x, res, 2);
5938 res = vset_lane_f16(from[3 * stride].x, res, 3);
5939 return res;
5940}
5941
5942template <>
5943EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet8hf>(Eigen::half* to, const Packet8hf& from,
5944 Index stride) {
5945 to[stride * 0].x = vgetq_lane_f16(from, 0);
5946 to[stride * 1].x = vgetq_lane_f16(from, 1);
5947 to[stride * 2].x = vgetq_lane_f16(from, 2);
5948 to[stride * 3].x = vgetq_lane_f16(from, 3);
5949 to[stride * 4].x = vgetq_lane_f16(from, 4);
5950 to[stride * 5].x = vgetq_lane_f16(from, 5);
5951 to[stride * 6].x = vgetq_lane_f16(from, 6);
5952 to[stride * 7].x = vgetq_lane_f16(from, 7);
5953}
5954
5955template <>
5956EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet4hf>(Eigen::half* to, const Packet4hf& from,
5957 Index stride) {
5958 to[stride * 0].x = vget_lane_f16(from, 0);
5959 to[stride * 1].x = vget_lane_f16(from, 1);
5960 to[stride * 2].x = vget_lane_f16(from, 2);
5961 to[stride * 3].x = vget_lane_f16(from, 3);
5962}
5963
5964template <>
5965EIGEN_STRONG_INLINE void prefetch<Eigen::half>(const Eigen::half* addr) {
5966 EIGEN_ARM_PREFETCH(addr);
5967}
5968
5969template <>
5970EIGEN_STRONG_INLINE Eigen::half pfirst<Packet8hf>(const Packet8hf& a) {
5971 float16_t x[8];
5972 vst1q_f16(x, a);
5973 Eigen::half h;
5974 h.x = x[0];
5975 return h;
5976}
5977
5978template <>
5979EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4hf>(const Packet4hf& a) {
5980 float16_t x[4];
5981 vst1_f16(x, a);
5982 Eigen::half h;
5983 h.x = x[0];
5984 return h;
5985}
5986
5987template <>
5988EIGEN_STRONG_INLINE Packet8hf preverse(const Packet8hf& a) {
5989 float16x4_t a_lo, a_hi;
5990 Packet8hf a_r64;
5991
5992 a_r64 = vrev64q_f16(a);
5993 a_lo = vget_low_f16(a_r64);
5994 a_hi = vget_high_f16(a_r64);
5995 return vcombine_f16(a_hi, a_lo);
5996}
5997
5998template <>
5999EIGEN_STRONG_INLINE Packet4hf preverse<Packet4hf>(const Packet4hf& a) {
6000 return vrev64_f16(a);
6001}
6002
6003template <>
6004EIGEN_STRONG_INLINE Packet8hf pabs<Packet8hf>(const Packet8hf& a) {
6005 return vabsq_f16(a);
6006}
6007
6008template <>
6009EIGEN_STRONG_INLINE Packet8hf psignbit(const Packet8hf& a) {
6010 return vreinterpretq_f16_s16(vshrq_n_s16(vreinterpretq_s16_f16(a), 15));
6011}
6012
6013template <>
6014EIGEN_STRONG_INLINE Packet4hf pabs<Packet4hf>(const Packet4hf& a) {
6015 return vabs_f16(a);
6016}
6017
6018template <>
6019EIGEN_STRONG_INLINE Packet4hf psignbit(const Packet4hf& a) {
6020 return vreinterpret_f16_s16(vshr_n_s16(vreinterpret_s16_f16(a), 15));
6021}
6022
6023template <>
6024EIGEN_STRONG_INLINE Eigen::half predux<Packet8hf>(const Packet8hf& a) {
6025 float16x4_t a_lo, a_hi, sum;
6026
6027 a_lo = vget_low_f16(a);
6028 a_hi = vget_high_f16(a);
6029 sum = vpadd_f16(a_lo, a_hi);
6030 sum = vpadd_f16(sum, sum);
6031 sum = vpadd_f16(sum, sum);
6032
6033 Eigen::half h;
6034 h.x = vget_lane_f16(sum, 0);
6035 return h;
6036}
6037
6038template <>
6039EIGEN_STRONG_INLINE Eigen::half predux<Packet4hf>(const Packet4hf& a) {
6040 float16x4_t sum;
6041
6042 sum = vpadd_f16(a, a);
6043 sum = vpadd_f16(sum, sum);
6044 Eigen::half h;
6045 h.x = vget_lane_f16(sum, 0);
6046 return h;
6047}
6048
6049template <>
6050EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet8hf>(const Packet8hf& a) {
6051 float16x4_t a_lo, a_hi, prod;
6052
6053 a_lo = vget_low_f16(a);
6054 a_hi = vget_high_f16(a);
6055 prod = vmul_f16(a_lo, a_hi);
6056 prod = vmul_f16(prod, vrev64_f16(prod));
6057
6058 Eigen::half h;
6059 h.x = vmulh_f16(vget_lane_f16(prod, 0), vget_lane_f16(prod, 1));
6060 return h;
6061}
6062
6063template <>
6064EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet4hf>(const Packet4hf& a) {
6065 float16x4_t prod;
6066 prod = vmul_f16(a, vrev64_f16(a));
6067 Eigen::half h;
6068 h.x = vmulh_f16(vget_lane_f16(prod, 0), vget_lane_f16(prod, 1));
6069 return h;
6070}
6071
6072template <>
6073EIGEN_STRONG_INLINE Eigen::half predux_min<Packet8hf>(const Packet8hf& a) {
6074 Eigen::half h;
6075 h.x = vminvq_f16(a);
6076 return h;
6077}
6078
6079template <>
6080EIGEN_STRONG_INLINE Eigen::half predux_min<Packet4hf>(const Packet4hf& a) {
6081 Eigen::half h;
6082 h.x = vminv_f16(a);
6083 return h;
6084}
6085
6086template <>
6087EIGEN_STRONG_INLINE Eigen::half predux_max<Packet8hf>(const Packet8hf& a) {
6088 Eigen::half h;
6089 h.x = vmaxvq_f16(a);
6090 return h;
6091}
6092
6093template <>
6094EIGEN_STRONG_INLINE Eigen::half predux_max<Packet4hf>(const Packet4hf& a) {
6095 Eigen::half h;
6096 h.x = vmaxv_f16(a);
6097 return h;
6098}
6099
6100EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8hf, 4>& kernel) {
6101 const float16x8x2_t zip16_1 = vzipq_f16(kernel.packet[0], kernel.packet[1]);
6102 const float16x8x2_t zip16_2 = vzipq_f16(kernel.packet[2], kernel.packet[3]);
6103
6104 const float32x4x2_t zip32_1 = vzipq_f32(vreinterpretq_f32_f16(zip16_1.val[0]), vreinterpretq_f32_f16(zip16_2.val[0]));
6105 const float32x4x2_t zip32_2 = vzipq_f32(vreinterpretq_f32_f16(zip16_1.val[1]), vreinterpretq_f32_f16(zip16_2.val[1]));
6106
6107 kernel.packet[0] = vreinterpretq_f16_f32(zip32_1.val[0]);
6108 kernel.packet[1] = vreinterpretq_f16_f32(zip32_1.val[1]);
6109 kernel.packet[2] = vreinterpretq_f16_f32(zip32_2.val[0]);
6110 kernel.packet[3] = vreinterpretq_f16_f32(zip32_2.val[1]);
6111}
6112
6113EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4hf, 4>& kernel) {
6114 EIGEN_ALIGN16 float16x4x4_t tmp_x4;
6115 float16_t* tmp = (float16_t*)&kernel;
6116 tmp_x4 = vld4_f16(tmp);
6117
6118 kernel.packet[0] = tmp_x4.val[0];
6119 kernel.packet[1] = tmp_x4.val[1];
6120 kernel.packet[2] = tmp_x4.val[2];
6121 kernel.packet[3] = tmp_x4.val[3];
6122}
6123
6124EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8hf, 8>& kernel) {
6125 float16x8x2_t T_1[4];
6126
6127 T_1[0] = vuzpq_f16(kernel.packet[0], kernel.packet[1]);
6128 T_1[1] = vuzpq_f16(kernel.packet[2], kernel.packet[3]);
6129 T_1[2] = vuzpq_f16(kernel.packet[4], kernel.packet[5]);
6130 T_1[3] = vuzpq_f16(kernel.packet[6], kernel.packet[7]);
6131
6132 float16x8x2_t T_2[4];
6133 T_2[0] = vuzpq_f16(T_1[0].val[0], T_1[1].val[0]);
6134 T_2[1] = vuzpq_f16(T_1[0].val[1], T_1[1].val[1]);
6135 T_2[2] = vuzpq_f16(T_1[2].val[0], T_1[3].val[0]);
6136 T_2[3] = vuzpq_f16(T_1[2].val[1], T_1[3].val[1]);
6137
6138 float16x8x2_t T_3[4];
6139 T_3[0] = vuzpq_f16(T_2[0].val[0], T_2[2].val[0]);
6140 T_3[1] = vuzpq_f16(T_2[0].val[1], T_2[2].val[1]);
6141 T_3[2] = vuzpq_f16(T_2[1].val[0], T_2[3].val[0]);
6142 T_3[3] = vuzpq_f16(T_2[1].val[1], T_2[3].val[1]);
6143
6144 kernel.packet[0] = T_3[0].val[0];
6145 kernel.packet[1] = T_3[2].val[0];
6146 kernel.packet[2] = T_3[1].val[0];
6147 kernel.packet[3] = T_3[3].val[0];
6148 kernel.packet[4] = T_3[0].val[1];
6149 kernel.packet[5] = T_3[2].val[1];
6150 kernel.packet[6] = T_3[1].val[1];
6151 kernel.packet[7] = T_3[3].val[1];
6152}
6153#endif // end EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
6154
6155} // end namespace internal
6156
6157} // end namespace Eigen
6158
6159#endif // EIGEN_PACKET_MATH_NEON_H
@ Unaligned
Definition Constants.h:235
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition Core:137