Eigen  5.0.1-dev+7c7d8473
 
Loading...
Searching...
No Matches
PacketMath.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_PACKET_MATH_ZVECTOR_H
11#define EIGEN_PACKET_MATH_ZVECTOR_H
12
13// IWYU pragma: private
14#include "../../InternalHeaderCheck.h"
15
16namespace Eigen {
17
18namespace internal {
19
20#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
21#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 16
22#endif
23
24#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
25#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
26#endif
27
28#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
29#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
30#endif
31
32typedef __vector int Packet4i;
33typedef __vector unsigned int Packet4ui;
34typedef __vector __bool int Packet4bi;
35typedef __vector short int Packet8i;
36typedef __vector unsigned char Packet16uc;
37typedef __vector double Packet2d;
38typedef __vector unsigned long long Packet2ul;
39typedef __vector long long Packet2l;
40
41// Z14 has builtin support for float vectors
42#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
43typedef __vector float Packet4f;
44#else
45typedef struct {
46 Packet2d v4f[2];
47} Packet4f;
48#endif
49
50typedef union {
51 numext::int32_t i[4];
52 numext::uint32_t ui[4];
53 numext::int64_t l[2];
54 numext::uint64_t ul[2];
55 double d[2];
56 float f[4];
57 Packet4i v4i;
58 Packet4ui v4ui;
59 Packet2l v2l;
60 Packet2ul v2ul;
61 Packet2d v2d;
62#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
63 Packet4f v4f;
64#endif
65} Packet;
66
67// We don't want to write the same code all the time, but we need to reuse the constants
68// and it doesn't really work to declare them global, so we define macros instead
69
70#define EIGEN_DECLARE_CONST_FAST_Packet4i(NAME, X) Packet4i p4i_##NAME = reinterpret_cast<Packet4i>(vec_splat_s32(X))
71
72#define EIGEN_DECLARE_CONST_FAST_Packet2d(NAME, X) Packet2d p2d_##NAME = reinterpret_cast<Packet2d>(vec_splat_s64(X))
73
74#define EIGEN_DECLARE_CONST_FAST_Packet2l(NAME, X) Packet2l p2l_##NAME = reinterpret_cast<Packet2l>(vec_splat_s64(X))
75
76#define EIGEN_DECLARE_CONST_Packet4i(NAME, X) Packet4i p4i_##NAME = pset1<Packet4i>(X)
77
78#define EIGEN_DECLARE_CONST_Packet2d(NAME, X) Packet2d p2d_##NAME = pset1<Packet2d>(X)
79
80#define EIGEN_DECLARE_CONST_Packet2l(NAME, X) Packet2l p2l_##NAME = pset1<Packet2l>(X)
81
82// These constants are endian-agnostic
83static EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,}
84static EIGEN_DECLARE_CONST_FAST_Packet4i(ONE, 1); //{ 1, 1, 1, 1}
85
86static EIGEN_DECLARE_CONST_FAST_Packet2d(ZERO, 0);
87static EIGEN_DECLARE_CONST_FAST_Packet2l(ZERO, 0);
88static EIGEN_DECLARE_CONST_FAST_Packet2l(ONE, 1);
89
90static Packet2d p2d_ONE = {1.0, 1.0};
91static Packet2d p2d_ZERO_ = {numext::bit_cast<double>(0x8000000000000000ull),
92 numext::bit_cast<double>(0x8000000000000000ull)};
93
94#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
95#define EIGEN_DECLARE_CONST_FAST_Packet4f(NAME, X) Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X))
96
97#define EIGEN_DECLARE_CONST_Packet4f(NAME, X) Packet4f p4f_##NAME = pset1<Packet4f>(X)
98
99#define EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME, X) \
100 const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X))
101
102static EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0}
103static EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1, -1); //{ -1, -1, -1, -1}
104static Packet4f p4f_MZERO = {0x80000000, 0x80000000, 0x80000000, 0x80000000};
105#endif
106
107static Packet4i p4i_COUNTDOWN = {0, 1, 2, 3};
108static Packet4f p4f_COUNTDOWN = {0.0, 1.0, 2.0, 3.0};
109static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(
110 vec_sld(reinterpret_cast<Packet16uc>(p2d_ZERO), reinterpret_cast<Packet16uc>(p2d_ONE), 8));
111
112static Packet16uc p16uc_PSET64_HI = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7};
113static Packet16uc p16uc_DUPLICATE32_HI = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7};
114
115// Mask alignment
116#define EIGEN_MASK_ALIGNMENT 0xfffffffffffffff0
117
118#define EIGEN_ALIGNED_PTR(x) ((std::ptrdiff_t)(x) & EIGEN_MASK_ALIGNMENT)
119
120// Handle endianness properly while loading constants
121// Define global static constants:
122
123static Packet16uc p16uc_FORWARD = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
124static Packet16uc p16uc_REVERSE32 = {12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3};
125static Packet16uc p16uc_REVERSE64 = {8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7};
126
127static Packet16uc p16uc_PSET32_WODD =
128 vec_sld((Packet16uc)vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc)vec_splat((Packet4ui)p16uc_FORWARD, 2),
129 8); //{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 };
130static Packet16uc p16uc_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (Packet16uc)vec_splat((Packet4ui)p16uc_FORWARD, 3),
131 8); //{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 };
132/*static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3),
1338); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16};
134
135static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD,
136(Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };*/
137static Packet16uc p16uc_PSET64_LO = (Packet16uc)vec_mergel(
138 (Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 };
139/*static Packet16uc p16uc_TRANSPOSE64_HI = vec_add(p16uc_PSET64_HI, p16uc_HALF64_0_16); //{ 0,1,2,3, 4,5,6,7,
14016,17,18,19, 20,21,22,23}; static Packet16uc p16uc_TRANSPOSE64_LO = vec_add(p16uc_PSET64_LO, p16uc_HALF64_0_16); //{
1418,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};*/
142static Packet16uc p16uc_TRANSPOSE64_HI = {0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};
143static Packet16uc p16uc_TRANSPOSE64_LO = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31};
144
145static Packet16uc p16uc_COMPLEX32_REV =
146 vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 };
147
148static Packet16uc p16uc_COMPLEX32_REV2 =
149 vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
150
151#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
152#define EIGEN_ZVECTOR_PREFETCH(ADDR) __builtin_prefetch(ADDR);
153#else
154#define EIGEN_ZVECTOR_PREFETCH(ADDR) asm(" pfd [%[addr]]\n" ::[addr] "r"(ADDR) : "cc");
155#endif
156
157template <>
158struct packet_traits<int> : default_packet_traits {
159 typedef Packet4i type;
160 typedef Packet4i half;
161 enum {
162 Vectorizable = 1,
163 AlignedOnScalar = 1,
164 size = 4,
165
166 HasAdd = 1,
167 HasSub = 1,
168 HasMul = 1,
169 HasDiv = 1,
170 };
171};
172
173template <>
174struct packet_traits<float> : default_packet_traits {
175 typedef Packet4f type;
176 typedef Packet4f half;
177 enum {
178 Vectorizable = 1,
179 AlignedOnScalar = 1,
180 size = 4,
181
182 HasCmp = 1,
183 HasAdd = 1,
184 HasSub = 1,
185 HasMul = 1,
186 HasDiv = 1,
187 HasMin = 1,
188 HasMax = 1,
189 HasAbs = 1,
190 HasSin = 0,
191 HasCos = 0,
192 HasLog = 0,
193 HasExp = 1,
194 HasSqrt = 1,
195 HasRsqrt = 1,
196 HasTanh = 1,
197 HasErf = 1,
198 HasNegate = 1,
199 };
200};
201
202template <>
203struct packet_traits<double> : default_packet_traits {
204 typedef Packet2d type;
205 typedef Packet2d half;
206 enum {
207 Vectorizable = 1,
208 AlignedOnScalar = 1,
209 size = 2,
210
211 HasAdd = 1,
212 HasSub = 1,
213 HasMul = 1,
214 HasDiv = 1,
215 HasMin = 1,
216 HasMax = 1,
217 HasAbs = 1,
218 HasSin = 0,
219 HasCos = 0,
220 HasLog = 0,
221 HasExp = 1,
222 HasSqrt = 1,
223 HasRsqrt = 1,
224 HasNegate = 1,
225 };
226};
227
228template <>
229struct unpacket_traits<Packet4i> {
230 typedef int type;
231 enum {
232 size = 4,
233 alignment = Aligned16,
234 vectorizable = true,
235 masked_load_available = false,
236 masked_store_available = false
237 };
238 typedef Packet4i half;
239};
240template <>
241struct unpacket_traits<Packet4f> {
242 typedef float type;
243 enum {
244 size = 4,
245 alignment = Aligned16,
246 vectorizable = true,
247 masked_load_available = false,
248 masked_store_available = false
249 };
250 typedef Packet4f half;
251 typedef Packet4i integer_packet;
252};
253template <>
254struct unpacket_traits<Packet2d> {
255 typedef double type;
256 enum {
257 size = 2,
258 alignment = Aligned16,
259 vectorizable = true,
260 masked_load_available = false,
261 masked_store_available = false
262 };
263 typedef Packet2d half;
264 typedef Packet2l integer_packet;
265};
266
267/* Forward declaration */
268EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f, 4>& kernel);
269
270inline std::ostream& operator<<(std::ostream& s, const Packet4i& v) {
271 Packet vt;
272 vt.v4i = v;
273 s << vt.i[0] << ", " << vt.i[1] << ", " << vt.i[2] << ", " << vt.i[3];
274 return s;
275}
276
277inline std::ostream& operator<<(std::ostream& s, const Packet4ui& v) {
278 Packet vt;
279 vt.v4ui = v;
280 s << vt.ui[0] << ", " << vt.ui[1] << ", " << vt.ui[2] << ", " << vt.ui[3];
281 return s;
282}
283
284inline std::ostream& operator<<(std::ostream& s, const Packet2l& v) {
285 Packet vt;
286 vt.v2l = v;
287 s << vt.l[0] << ", " << vt.l[1];
288 return s;
289}
290
291inline std::ostream& operator<<(std::ostream& s, const Packet2ul& v) {
292 Packet vt;
293 vt.v2ul = v;
294 s << vt.ul[0] << ", " << vt.ul[1];
295 return s;
296}
297
298inline std::ostream& operator<<(std::ostream& s, const Packet2d& v) {
299 Packet vt;
300 vt.v2d = v;
301 s << vt.d[0] << ", " << vt.d[1];
302 return s;
303}
304
305#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
306inline std::ostream& operator<<(std::ostream& s, const Packet4f& v) {
307 Packet vt;
308 vt.v4f = v;
309 s << vt.f[0] << ", " << vt.f[1] << ", " << vt.f[2] << ", " << vt.f[3];
310 return s;
311}
312#endif
313
314template <>
315EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) {
316 EIGEN_DEBUG_ALIGNED_LOAD
317 return vec_xl(0, from);
318}
319
320template <>
321EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) {
322 EIGEN_DEBUG_ALIGNED_LOAD
323 return vec_xl(0, from);
324}
325
326template <>
327EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) {
328 EIGEN_DEBUG_ALIGNED_STORE
329 vec_xst(from, 0, to);
330}
331
332template <>
333EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) {
334 EIGEN_DEBUG_ALIGNED_STORE
335 vec_xst(from, 0, to);
336}
337
338template <>
339EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) {
340 return pfrexp_generic(a, exponent);
341}
342
343template <>
344EIGEN_STRONG_INLINE Packet2d pfrexp<Packet2d>(const Packet2d& a, Packet2d& exponent) {
345 return pfrexp_generic(a, exponent);
346}
347
348template <>
349EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) {
350 return vec_splats(from);
351}
352template <>
353EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) {
354 return vec_splats(from);
355}
356
357template <>
358EIGEN_STRONG_INLINE void pbroadcast4<Packet4i>(const int* a, Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3) {
359 a3 = pload<Packet4i>(a);
360 a0 = vec_splat(a3, 0);
361 a1 = vec_splat(a3, 1);
362 a2 = vec_splat(a3, 2);
363 a3 = vec_splat(a3, 3);
364}
365
366template <>
367EIGEN_STRONG_INLINE void pbroadcast4<Packet2d>(const double* a, Packet2d& a0, Packet2d& a1, Packet2d& a2,
368 Packet2d& a3) {
369 a1 = pload<Packet2d>(a);
370 a0 = vec_splat(a1, 0);
371 a1 = vec_splat(a1, 1);
372 a3 = pload<Packet2d>(a + 2);
373 a2 = vec_splat(a3, 0);
374 a3 = vec_splat(a3, 1);
375}
376
377template <>
378EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride) {
379 EIGEN_ALIGN16 int ai[4];
380 ai[0] = from[0 * stride];
381 ai[1] = from[1 * stride];
382 ai[2] = from[2 * stride];
383 ai[3] = from[3 * stride];
384 return pload<Packet4i>(ai);
385}
386
387template <>
388EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) {
389 EIGEN_ALIGN16 double af[2];
390 af[0] = from[0 * stride];
391 af[1] = from[1 * stride];
392 return pload<Packet2d>(af);
393}
394
395template <>
396EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride) {
397 EIGEN_ALIGN16 int ai[4];
398 pstore<int>((int*)ai, from);
399 to[0 * stride] = ai[0];
400 to[1 * stride] = ai[1];
401 to[2 * stride] = ai[2];
402 to[3 * stride] = ai[3];
403}
404
405template <>
406EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) {
407 EIGEN_ALIGN16 double af[2];
408 pstore<double>(af, from);
409 to[0 * stride] = af[0];
410 to[1 * stride] = af[1];
411}
412
413template <>
414EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) {
415 return (a + b);
416}
417template <>
418EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) {
419 return (a + b);
420}
421
422template <>
423EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) {
424 return (a - b);
425}
426template <>
427EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) {
428 return (a - b);
429}
430
431template <>
432EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) {
433 return (a * b);
434}
435template <>
436EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) {
437 return (a * b);
438}
439
440template <>
441EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) {
442 return (a / b);
443}
444template <>
445EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) {
446 return (a / b);
447}
448
449template <>
450EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) {
451 return (-a);
452}
453template <>
454EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) {
455 return (-a);
456}
457
458template <>
459EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) {
460 return a;
461}
462template <>
463EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) {
464 return a;
465}
466
467template <>
468EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) {
469 return padd<Packet4i>(pmul<Packet4i>(a, b), c);
470}
471template <>
472EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) {
473 return vec_madd(a, b, c);
474}
475
476template <>
477EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) {
478 return padd<Packet4i>(pset1<Packet4i>(a), p4i_COUNTDOWN);
479}
480template <>
481EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) {
482 return padd<Packet2d>(pset1<Packet2d>(a), p2d_COUNTDOWN);
483}
484
485template <>
486EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) {
487 return vec_min(a, b);
488}
489template <>
490EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) {
491 return vec_min(a, b);
492}
493
494template <>
495EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) {
496 return vec_max(a, b);
497}
498template <>
499EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) {
500 return vec_max(a, b);
501}
502
503template <>
504EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) {
505 return vec_and(a, b);
506}
507template <>
508EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) {
509 return vec_and(a, b);
510}
511
512template <>
513EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) {
514 return vec_or(a, b);
515}
516template <>
517EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) {
518 return vec_or(a, b);
519}
520
521template <>
522EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) {
523 return vec_xor(a, b);
524}
525template <>
526EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) {
527 return vec_xor(a, b);
528}
529
530template <>
531EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) {
532 return pand<Packet4i>(a, vec_nor(b, b));
533}
534template <>
535EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) {
536 return vec_and(a, vec_nor(b, b));
537}
538
539template <>
540EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) {
541 /* Uses non-default rounding for vec_round */
542 return __builtin_s390_vfidb(a, 0, 1);
543}
544template <>
545EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) {
546 return vec_ceil(a);
547}
548template <>
549EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) {
550 return vec_floor(a);
551}
552
553template <>
554EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) {
555 return pload<Packet4i>(from);
556}
557template <>
558EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) {
559 return pload<Packet2d>(from);
560}
561
562template <>
563EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from) {
564 Packet4i p = pload<Packet4i>(from);
565 return vec_perm(p, p, p16uc_DUPLICATE32_HI);
566}
567
568template <>
569EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) {
570 Packet2d p = pload<Packet2d>(from);
571 return vec_perm(p, p, p16uc_PSET64_HI);
572}
573
574template <>
575EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) {
576 pstore<int>(to, from);
577}
578template <>
579EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) {
580 pstore<double>(to, from);
581}
582
583template <>
584EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) {
585 EIGEN_ZVECTOR_PREFETCH(addr);
586}
587template <>
588EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) {
589 EIGEN_ZVECTOR_PREFETCH(addr);
590}
591
592template <int N>
593EIGEN_STRONG_INLINE Packet2l parithmetic_shift_right(const Packet2l& a) {
594 return Packet2l{parithmetic_shift_right<N>(a[0]), parithmetic_shift_right<N>(a[1])};
595}
596template <int N>
597EIGEN_STRONG_INLINE Packet4i parithmetic_shift_right(const Packet4i& a) {
598 return Packet4i{parithmetic_shift_right<N>(a[0]), parithmetic_shift_right<N>(a[1]), parithmetic_shift_right<N>(a[2]),
599 parithmetic_shift_right<N>(a[3])};
600}
601
602template <int N>
603EIGEN_STRONG_INLINE Packet2l plogical_shift_right(const Packet2l& a) {
604 return Packet2l{plogical_shift_right<N>(a[0]), plogical_shift_right<N>(a[1])};
605}
606template <int N>
607EIGEN_STRONG_INLINE Packet4i plogical_shift_right(const Packet4i& a) {
608 return Packet4i{plogical_shift_right<N>(a[0]), plogical_shift_right<N>(a[1]), plogical_shift_right<N>(a[2]),
609 plogical_shift_right<N>(a[3])};
610}
611
612template <int N>
613EIGEN_STRONG_INLINE Packet2l plogical_shift_left(const Packet2l& a) {
614 return Packet2l{plogical_shift_left<N>(a[0]), plogical_shift_left<N>(a[1])};
615}
616template <int N>
617EIGEN_STRONG_INLINE Packet4i plogical_shift_left(const Packet4i& a) {
618 return Packet4i{plogical_shift_left<N>(a[0]), plogical_shift_left<N>(a[1]), plogical_shift_left<N>(a[2]),
619 plogical_shift_left<N>(a[3])};
620}
621
622template <>
623EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) {
624 EIGEN_ALIGN16 int x[4];
625 pstore(x, a);
626 return x[0];
627}
628template <>
629EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) {
630 EIGEN_ALIGN16 double x[2];
631 pstore(x, a);
632 return x[0];
633}
634
635template <>
636EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) {
637 return reinterpret_cast<Packet4i>(
638 vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
639}
640
641template <>
642EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) {
643 return reinterpret_cast<Packet2d>(
644 vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64));
645}
646
647template <>
648EIGEN_STRONG_INLINE Packet4i pabs<Packet4i>(const Packet4i& a) {
649 return vec_abs(a);
650}
651template <>
652EIGEN_STRONG_INLINE Packet2d pabs<Packet2d>(const Packet2d& a) {
653 return vec_abs(a);
654}
655
656template <>
657EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) {
658 Packet4i b, sum;
659 b = vec_sld(a, a, 8);
660 sum = padd<Packet4i>(a, b);
661 b = vec_sld(sum, sum, 4);
662 sum = padd<Packet4i>(sum, b);
663 return pfirst(sum);
664}
665
666template <>
667EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) {
668 Packet2d b, sum;
669 b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8));
670 sum = padd<Packet2d>(a, b);
671 return pfirst(sum);
672}
673
674// Other reduction functions:
675// mul
676template <>
677EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a) {
678 EIGEN_ALIGN16 int aux[4];
679 pstore(aux, a);
680 return aux[0] * aux[1] * aux[2] * aux[3];
681}
682
683template <>
684EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) {
685 return pfirst(
686 pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
687}
688
689// min
690template <>
691EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a) {
692 Packet4i b, res;
693 b = pmin<Packet4i>(a, vec_sld(a, a, 8));
694 res = pmin<Packet4i>(b, vec_sld(b, b, 4));
695 return pfirst(res);
696}
697
698template <>
699EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) {
700 return pfirst(pmin<Packet2d>(
701 a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
702}
703
704// max
705template <>
706EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a) {
707 Packet4i b, res;
708 b = pmax<Packet4i>(a, vec_sld(a, a, 8));
709 res = pmax<Packet4i>(b, vec_sld(b, b, 4));
710 return pfirst(res);
711}
712
713// max
714template <>
715EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) {
716 return pfirst(pmax<Packet2d>(
717 a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
718}
719
720EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4i, 4>& kernel) {
721 Packet4i t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
722 Packet4i t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
723 Packet4i t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
724 Packet4i t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
725 kernel.packet[0] = vec_mergeh(t0, t2);
726 kernel.packet[1] = vec_mergel(t0, t2);
727 kernel.packet[2] = vec_mergeh(t1, t3);
728 kernel.packet[3] = vec_mergel(t1, t3);
729}
730
731EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2d, 2>& kernel) {
732 Packet2d t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI);
733 Packet2d t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO);
734 kernel.packet[0] = t0;
735 kernel.packet[1] = t1;
736}
737
738/* z13 has no vector float support so we emulate that with double
739 z14 has proper vector float support.
740*/
741#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
742/* Helper function to simulate a vec_splat_packet4f
743 */
744template <int element>
745EIGEN_STRONG_INLINE Packet4f vec_splat_packet4f(const Packet4f& from) {
746 Packet4f splat;
747 switch (element) {
748 case 0:
749 splat.v4f[0] = vec_splat(from.v4f[0], 0);
750 splat.v4f[1] = splat.v4f[0];
751 break;
752 case 1:
753 splat.v4f[0] = vec_splat(from.v4f[0], 1);
754 splat.v4f[1] = splat.v4f[0];
755 break;
756 case 2:
757 splat.v4f[0] = vec_splat(from.v4f[1], 0);
758 splat.v4f[1] = splat.v4f[0];
759 break;
760 case 3:
761 splat.v4f[0] = vec_splat(from.v4f[1], 1);
762 splat.v4f[1] = splat.v4f[0];
763 break;
764 }
765 return splat;
766}
767
768template <>
769EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) {
770 // FIXME: No intrinsic yet
771 EIGEN_DEBUG_ALIGNED_LOAD
772 Packet4f vfrom;
773 vfrom.v4f[0] = vec_ld2f(&from[0]);
774 vfrom.v4f[1] = vec_ld2f(&from[2]);
775 return vfrom;
776}
777
778template <>
779EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) {
780 // FIXME: No intrinsic yet
781 EIGEN_DEBUG_ALIGNED_STORE
782 vec_st2f(from.v4f[0], &to[0]);
783 vec_st2f(from.v4f[1], &to[2]);
784}
785
786template <>
787EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) {
788 Packet4f to;
789 to.v4f[0] = pset1<Packet2d>(static_cast<const double&>(from));
790 to.v4f[1] = to.v4f[0];
791 return to;
792}
793
794template <>
795EIGEN_STRONG_INLINE void pbroadcast4<Packet4f>(const float* a, Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) {
796 a3 = pload<Packet4f>(a);
797 a0 = vec_splat_packet4f<0>(a3);
798 a1 = vec_splat_packet4f<1>(a3);
799 a2 = vec_splat_packet4f<2>(a3);
800 a3 = vec_splat_packet4f<3>(a3);
801}
802
803template <>
804EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) {
805 EIGEN_ALIGN16 float ai[4];
806 ai[0] = from[0 * stride];
807 ai[1] = from[1 * stride];
808 ai[2] = from[2 * stride];
809 ai[3] = from[3 * stride];
810 return pload<Packet4f>(ai);
811}
812
813template <>
814EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) {
815 EIGEN_ALIGN16 float ai[4];
816 pstore<float>((float*)ai, from);
817 to[0 * stride] = ai[0];
818 to[1 * stride] = ai[1];
819 to[2 * stride] = ai[2];
820 to[3 * stride] = ai[3];
821}
822
823template <>
824EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) {
825 Packet4f c;
826 c.v4f[0] = a.v4f[0] + b.v4f[0];
827 c.v4f[1] = a.v4f[1] + b.v4f[1];
828 return c;
829}
830
831template <>
832EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) {
833 Packet4f c;
834 c.v4f[0] = a.v4f[0] - b.v4f[0];
835 c.v4f[1] = a.v4f[1] - b.v4f[1];
836 return c;
837}
838
839template <>
840EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) {
841 Packet4f c;
842 c.v4f[0] = a.v4f[0] * b.v4f[0];
843 c.v4f[1] = a.v4f[1] * b.v4f[1];
844 return c;
845}
846
847template <>
848EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) {
849 Packet4f c;
850 c.v4f[0] = a.v4f[0] / b.v4f[0];
851 c.v4f[1] = a.v4f[1] / b.v4f[1];
852 return c;
853}
854
855template <>
856EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) {
857 Packet4f c;
858 c.v4f[0] = -a.v4f[0];
859 c.v4f[1] = -a.v4f[1];
860 return c;
861}
862
863template <>
864EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) {
865 Packet4f res;
866 res.v4f[0] = vec_madd(a.v4f[0], b.v4f[0], c.v4f[0]);
867 res.v4f[1] = vec_madd(a.v4f[1], b.v4f[1], c.v4f[1]);
868 return res;
869}
870
871template <>
872EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) {
873 Packet4f res;
874 res.v4f[0] = pmin(a.v4f[0], b.v4f[0]);
875 res.v4f[1] = pmin(a.v4f[1], b.v4f[1]);
876 return res;
877}
878
879template <>
880EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) {
881 Packet4f res;
882 res.v4f[0] = pmax(a.v4f[0], b.v4f[0]);
883 res.v4f[1] = pmax(a.v4f[1], b.v4f[1]);
884 return res;
885}
886
887template <>
888EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) {
889 Packet4f res;
890 res.v4f[0] = pand(a.v4f[0], b.v4f[0]);
891 res.v4f[1] = pand(a.v4f[1], b.v4f[1]);
892 return res;
893}
894
895template <>
896EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) {
897 Packet4f res;
898 res.v4f[0] = por(a.v4f[0], b.v4f[0]);
899 res.v4f[1] = por(a.v4f[1], b.v4f[1]);
900 return res;
901}
902
903template <>
904EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) {
905 Packet4f res;
906 res.v4f[0] = pxor(a.v4f[0], b.v4f[0]);
907 res.v4f[1] = pxor(a.v4f[1], b.v4f[1]);
908 return res;
909}
910
911template <>
912EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) {
913 Packet4f res;
914 res.v4f[0] = pandnot(a.v4f[0], b.v4f[0]);
915 res.v4f[1] = pandnot(a.v4f[1], b.v4f[1]);
916 return res;
917}
918
919template <>
920EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) {
921 Packet4f res;
922 res.v4f[0] = generic_round(a.v4f[0]);
923 res.v4f[1] = generic_round(a.v4f[1]);
924 return res;
925}
926
927template <>
928EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) {
929 Packet4f res;
930 res.v4f[0] = vec_ceil(a.v4f[0]);
931 res.v4f[1] = vec_ceil(a.v4f[1]);
932 return res;
933}
934
935template <>
936EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) {
937 Packet4f res;
938 res.v4f[0] = vec_floor(a.v4f[0]);
939 res.v4f[1] = vec_floor(a.v4f[1]);
940 return res;
941}
942
943template <>
944EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) {
945 Packet4f p = pload<Packet4f>(from);
946 p.v4f[1] = vec_splat(p.v4f[0], 1);
947 p.v4f[0] = vec_splat(p.v4f[0], 0);
948 return p;
949}
950
951template <>
952EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) {
953 EIGEN_ALIGN16 float x[2];
954 vec_st2f(a.v4f[0], &x[0]);
955 return x[0];
956}
957
958template <>
959EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) {
960 Packet4f rev;
961 rev.v4f[0] = preverse<Packet2d>(a.v4f[1]);
962 rev.v4f[1] = preverse<Packet2d>(a.v4f[0]);
963 return rev;
964}
965
966template <>
967EIGEN_STRONG_INLINE Packet4f pabs<Packet4f>(const Packet4f& a) {
968 Packet4f res;
969 res.v4f[0] = pabs(a.v4f[0]);
970 res.v4f[1] = pabs(a.v4f[1]);
971 return res;
972}
973
974template <>
975EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) {
976 Packet2d sum;
977 sum = padd<Packet2d>(a.v4f[0], a.v4f[1]);
978 double first = predux<Packet2d>(sum);
979 return static_cast<float>(first);
980}
981
982template <>
983EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) {
984 // Return predux_mul<Packet2d> of the subvectors product
985 return static_cast<float>(pfirst(predux_mul(pmul(a.v4f[0], a.v4f[1]))));
986}
987
988template <>
989EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) {
990 Packet2d b, res;
991 b = pmin<Packet2d>(a.v4f[0], a.v4f[1]);
992 res = pmin<Packet2d>(
993 b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8)));
994 return static_cast<float>(pfirst(res));
995}
996
997template <>
998EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) {
999 Packet2d b, res;
1000 b = pmax<Packet2d>(a.v4f[0], a.v4f[1]);
1001 res = pmax<Packet2d>(
1002 b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8)));
1003 return static_cast<float>(pfirst(res));
1004}
1005
1006/* Split the Packet4f PacketBlock into 4 Packet2d PacketBlocks and transpose each one
1007 */
1008EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f, 4>& kernel) {
1009 PacketBlock<Packet2d, 2> t0, t1, t2, t3;
1010 // copy top-left 2x2 Packet2d block
1011 t0.packet[0] = kernel.packet[0].v4f[0];
1012 t0.packet[1] = kernel.packet[1].v4f[0];
1013
1014 // copy top-right 2x2 Packet2d block
1015 t1.packet[0] = kernel.packet[0].v4f[1];
1016 t1.packet[1] = kernel.packet[1].v4f[1];
1017
1018 // copy bottom-left 2x2 Packet2d block
1019 t2.packet[0] = kernel.packet[2].v4f[0];
1020 t2.packet[1] = kernel.packet[3].v4f[0];
1021
1022 // copy bottom-right 2x2 Packet2d block
1023 t3.packet[0] = kernel.packet[2].v4f[1];
1024 t3.packet[1] = kernel.packet[3].v4f[1];
1025
1026 // Transpose all 2x2 blocks
1027 ptranspose(t0);
1028 ptranspose(t1);
1029 ptranspose(t2);
1030 ptranspose(t3);
1031
1032 // Copy back transposed blocks, but exchange t1 and t2 due to transposition
1033 kernel.packet[0].v4f[0] = t0.packet[0];
1034 kernel.packet[0].v4f[1] = t2.packet[0];
1035 kernel.packet[1].v4f[0] = t0.packet[1];
1036 kernel.packet[1].v4f[1] = t2.packet[1];
1037 kernel.packet[2].v4f[0] = t1.packet[0];
1038 kernel.packet[2].v4f[1] = t3.packet[0];
1039 kernel.packet[3].v4f[0] = t1.packet[1];
1040 kernel.packet[3].v4f[1] = t3.packet[1];
1041}
1042
1043template <>
1044Packet4f EIGEN_STRONG_INLINE pcmp_le<Packet4f>(const Packet4f& a, const Packet4f& b) {
1045 Packet4f res;
1046 res.v4f[0] = pcmp_le(a.v4f[0], b.v4f[0]);
1047 res.v4f[1] = pcmp_le(a.v4f[1], b.v4f[1]);
1048 return res;
1049}
1050
1051template <>
1052Packet4f EIGEN_STRONG_INLINE pcmp_lt<Packet4f>(const Packet4f& a, const Packet4f& b) {
1053 Packet4f res;
1054 res.v4f[0] = pcmp_lt(a.v4f[0], b.v4f[0]);
1055 res.v4f[1] = pcmp_lt(a.v4f[1], b.v4f[1]);
1056 return res;
1057}
1058
1059template <>
1060Packet4f EIGEN_STRONG_INLINE pcmp_eq<Packet4f>(const Packet4f& a, const Packet4f& b) {
1061 Packet4f res;
1062 res.v4f[0] = pcmp_eq(a.v4f[0], b.v4f[0]);
1063 res.v4f[1] = pcmp_eq(a.v4f[1], b.v4f[1]);
1064 return res;
1065}
1066
1067#else
1068template <>
1069EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) {
1070 EIGEN_DEBUG_ALIGNED_LOAD
1071 return vec_xl(0, from);
1072}
1073
1074template <>
1075EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) {
1076 EIGEN_DEBUG_ALIGNED_STORE
1077 vec_xst(from, 0, to);
1078}
1079
1080template <>
1081EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) {
1082 return vec_splats(from);
1083}
1084
1085template <>
1086EIGEN_STRONG_INLINE void pbroadcast4<Packet4f>(const float* a, Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) {
1087 a3 = pload<Packet4f>(a);
1088 a0 = vec_splat(a3, 0);
1089 a1 = vec_splat(a3, 1);
1090 a2 = vec_splat(a3, 2);
1091 a3 = vec_splat(a3, 3);
1092}
1093
1094template <>
1095EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) {
1096 EIGEN_ALIGN16 float af[4];
1097 af[0] = from[0 * stride];
1098 af[1] = from[1 * stride];
1099 af[2] = from[2 * stride];
1100 af[3] = from[3 * stride];
1101 return pload<Packet4f>(af);
1102}
1103
1104template <>
1105EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) {
1106 EIGEN_ALIGN16 float af[4];
1107 pstore<float>((float*)af, from);
1108 to[0 * stride] = af[0];
1109 to[1 * stride] = af[1];
1110 to[2 * stride] = af[2];
1111 to[3 * stride] = af[3];
1112}
1113
1114template <>
1115EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) {
1116 return (a + b);
1117}
1118template <>
1119EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) {
1120 return (a - b);
1121}
1122template <>
1123EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) {
1124 return (a * b);
1125}
1126template <>
1127EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) {
1128 return (a / b);
1129}
1130template <>
1131EIGEN_STRONG_INLINE Packet4f pnegate<Packet4f>(const Packet4f& a) {
1132 return (-a);
1133}
1134template <>
1135EIGEN_STRONG_INLINE Packet4f pconj<Packet4f>(const Packet4f& a) {
1136 return a;
1137}
1138template <>
1139EIGEN_STRONG_INLINE Packet4f pmadd<Packet4f>(const Packet4f& a, const Packet4f& b, const Packet4f& c) {
1140 return vec_madd(a, b, c);
1141}
1142template <>
1143EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) {
1144 return vec_min(a, b);
1145}
1146template <>
1147EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) {
1148 return vec_max(a, b);
1149}
1150template <>
1151EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) {
1152 return vec_and(a, b);
1153}
1154template <>
1155EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) {
1156 return vec_or(a, b);
1157}
1158template <>
1159EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) {
1160 return vec_xor(a, b);
1161}
1162template <>
1163EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) {
1164 return vec_and(a, vec_nor(b, b));
1165}
1166template <>
1167EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) {
1168 /* Uses non-default rounding for vec_round */
1169 return __builtin_s390_vfisb(a, 0, 1);
1170}
1171template <>
1172EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) {
1173 return vec_ceil(a);
1174}
1175template <>
1176EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) {
1177 return vec_floor(a);
1178}
1179template <>
1180EIGEN_STRONG_INLINE Packet4f pabs<Packet4f>(const Packet4f& a) {
1181 return vec_abs(a);
1182}
1183template <>
1184EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) {
1185 EIGEN_ALIGN16 float x[4];
1186 pstore(x, a);
1187 return x[0];
1188}
1189
1190template <>
1191EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) {
1192 Packet4f p = pload<Packet4f>(from);
1193 return vec_perm(p, p, p16uc_DUPLICATE32_HI);
1194}
1195
1196template <>
1197EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) {
1198 return reinterpret_cast<Packet4f>(
1199 vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
1200}
1201
1202template <>
1203EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) {
1204 Packet4f b, sum;
1205 b = vec_sld(a, a, 8);
1206 sum = padd<Packet4f>(a, b);
1207 b = vec_sld(sum, sum, 4);
1208 sum = padd<Packet4f>(sum, b);
1209 return pfirst(sum);
1210}
1211
1212// Other reduction functions:
1213// mul
1214template <>
1215EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) {
1216 Packet4f prod;
1217 prod = pmul(a, vec_sld(a, a, 8));
1218 return pfirst(pmul(prod, vec_sld(prod, prod, 4)));
1219}
1220
1221// min
1222template <>
1223EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) {
1224 Packet4f b, res;
1225 b = pmin<Packet4f>(a, vec_sld(a, a, 8));
1226 res = pmin<Packet4f>(b, vec_sld(b, b, 4));
1227 return pfirst(res);
1228}
1229
1230// max
1231template <>
1232EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) {
1233 Packet4f b, res;
1234 b = pmax<Packet4f>(a, vec_sld(a, a, 8));
1235 res = pmax<Packet4f>(b, vec_sld(b, b, 4));
1236 return pfirst(res);
1237}
1238
1239EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f, 4>& kernel) {
1240 Packet4f t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
1241 Packet4f t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
1242 Packet4f t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
1243 Packet4f t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
1244 kernel.packet[0] = vec_mergeh(t0, t2);
1245 kernel.packet[1] = vec_mergel(t0, t2);
1246 kernel.packet[2] = vec_mergeh(t1, t3);
1247 kernel.packet[3] = vec_mergel(t1, t3);
1248}
1249
1250#endif
1251
1252template <>
1253EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) {
1254 return pldexp_generic(a, exponent);
1255}
1256
1257template <>
1258EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) {
1259 // Clamp exponent to [-2099, 2099]
1260 const Packet2d max_exponent = pset1<Packet2d>(2099.0);
1261 const Packet2l e = pcast<Packet2d, Packet2l>(pmin(pmax(exponent, pnegate(max_exponent)), max_exponent));
1262
1263 // Split 2^e into four factors and multiply:
1264 const Packet2l bias = {1023, 1023};
1265 Packet2l b = plogical_shift_right<2>(e); // floor(e/4)
1266 Packet2d c = reinterpret_cast<Packet2d>(plogical_shift_left<52>(b + bias));
1267 Packet2d out = pmul(pmul(pmul(a, c), c), c); // a * 2^(3b)
1268 b = psub(psub(psub(e, b), b), b); // e - 3b
1269 c = reinterpret_cast<Packet2d>(plogical_shift_left<52>(b + bias)); // 2^(e - 3b)
1270 out = pmul(out, c); // a * 2^e
1271 return out;
1272}
1273
1274template <>
1275EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) {
1276 EIGEN_ZVECTOR_PREFETCH(addr);
1277}
1278template <>
1279EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) {
1280 return pload<Packet4f>(from);
1281}
1282template <>
1283EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) {
1284 pstore<float>(to, from);
1285}
1286template <>
1287EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) {
1288 return padd<Packet4f>(pset1<Packet4f>(a), p4f_COUNTDOWN);
1289}
1290
1291#if !defined(vec_float) || !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 13)
1292#pragma GCC warning "float->int and int->float conversion is simulated. compile for z15 for improved performance"
1293template <>
1294struct cast_impl<Packet4i, Packet4f> {
1295 EIGEN_DEVICE_FUNC static inline Packet4f run(const Packet4i& a) {
1296 return Packet4f{float(a[0]), float(a[1]), float(a[2]), float(a[3])};
1297 }
1298};
1299
1300template <>
1301struct cast_impl<Packet4f, Packet4i> {
1302 EIGEN_DEVICE_FUNC static inline Packet4i run(const Packet4f& a) {
1303 return Packet4i{int(a[0]), int(a[1]), int(a[2]), int(a[3])};
1304 }
1305};
1306
1307template <>
1308struct cast_impl<Packet2l, Packet2d> {
1309 EIGEN_DEVICE_FUNC static inline Packet2d run(const Packet2l& a) { return Packet2d{double(a[0]), double(a[1])}; }
1310};
1311
1312template <>
1313struct cast_impl<Packet2d, Packet2l> {
1314 EIGEN_DEVICE_FUNC static inline Packet2l run(const Packet2d& a) {
1315 return Packet2l{(long long)(a[0]), (long long)(a[1])};
1316 }
1317};
1318#else
1319template <>
1320struct cast_impl<Packet4i, Packet4f> {
1321 EIGEN_DEVICE_FUNC static inline Packet4f run(const Packet4i& a) { return vec_float(a); }
1322};
1323
1324template <>
1325struct cast_impl<Packet4f, Packet4i> {
1326 EIGEN_DEVICE_FUNC static inline Packet4i run(const Packet4f& a) { return vec_signed(a); }
1327};
1328
1329template <>
1330struct cast_impl<Packet2l, Packet2d> {
1331 EIGEN_DEVICE_FUNC static inline Packet2d run(const Packet2l& a) { return vec_double(a); }
1332};
1333
1334template <>
1335struct cast_impl<Packet2d, Packet2l> {
1336 EIGEN_DEVICE_FUNC static inline Packet2l run(const Packet2d& a) { return vec_signed(a); }
1337};
1338#endif
1339
1340template <>
1341EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(uint32_t from) {
1342 return pset1<Packet4f>(Eigen::numext::bit_cast<float>(from));
1343}
1344template <>
1345EIGEN_STRONG_INLINE Packet2d pset1frombits<Packet2d>(uint64_t from) {
1346 return pset1<Packet2d>(Eigen::numext::bit_cast<double>(from));
1347}
1348
1349} // end namespace internal
1350
1351} // end namespace Eigen
1352
1353#endif // EIGEN_PACKET_MATH_ZVECTOR_H
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82