ZVector/PacketMath.h
Go to the documentation of this file.
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 #include "../../InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
19 #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
20 #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 16
21 #endif
22 
23 #ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
24 #define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
25 #endif
26 
27 #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
28 #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
29 #endif
30 
31 typedef __vector int Packet4i;
32 typedef __vector unsigned int Packet4ui;
33 typedef __vector __bool int Packet4bi;
34 typedef __vector short int Packet8i;
35 typedef __vector unsigned char Packet16uc;
36 typedef __vector double Packet2d;
37 typedef __vector unsigned long long Packet2ul;
38 typedef __vector long long Packet2l;
39 
40 // Z14 has builtin support for float vectors
41 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
42 typedef __vector float Packet4f;
43 #else
44 typedef struct {
45  Packet2d v4f[2];
46 } Packet4f;
47 #endif
48 
49 typedef union {
50  numext::int32_t i[4];
51  numext::uint32_t ui[4];
52  numext::int64_t l[2];
53  numext::uint64_t ul[2];
54  double d[2];
55  float f[4];
56  Packet4i v4i;
57  Packet4ui v4ui;
58  Packet2l v2l;
59  Packet2ul v2ul;
60  Packet2d v2d;
61 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
62  Packet4f v4f;
63 #endif
64 } Packet;
65 
66 // We don't want to write the same code all the time, but we need to reuse the constants
67 // and it doesn't really work to declare them global, so we define macros instead
68 
69 #define EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \
70  Packet4i p4i_##NAME = reinterpret_cast<Packet4i>(vec_splat_s32(X))
71 
72 #define EIGEN_DECLARE_CONST_FAST_Packet2d(NAME,X) \
73  Packet2d p2d_##NAME = reinterpret_cast<Packet2d>(vec_splat_s64(X))
74 
75 #define EIGEN_DECLARE_CONST_FAST_Packet2l(NAME,X) \
76  Packet2l p2l_##NAME = reinterpret_cast<Packet2l>(vec_splat_s64(X))
77 
78 #define EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
79  Packet4i p4i_##NAME = pset1<Packet4i>(X)
80 
81 #define EIGEN_DECLARE_CONST_Packet2d(NAME,X) \
82  Packet2d p2d_##NAME = pset1<Packet2d>(X)
83 
84 #define EIGEN_DECLARE_CONST_Packet2l(NAME,X) \
85  Packet2l p2l_##NAME = pset1<Packet2l>(X)
86 
87 // These constants are endian-agnostic
88 static EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,}
89 static EIGEN_DECLARE_CONST_FAST_Packet4i(ONE, 1); //{ 1, 1, 1, 1}
90 
94 
95 static Packet2d p2d_ONE = { 1.0, 1.0 };
96 static Packet2d p2d_ZERO_ = { numext::bit_cast<double>(0x8000000000000000ull),
97  numext::bit_cast<double>(0x8000000000000000ull) };
98 
99 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
100 #define EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \
101  Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X))
102 
103 #define EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
104  Packet4f p4f_##NAME = pset1<Packet4f>(X)
105 
106 #define EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
107  const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X))
108 
109 static EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0}
110 static EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1}
111 static Packet4f p4f_MZERO = { 0x80000000, 0x80000000, 0x80000000, 0x80000000};
112 #endif
113 
114 static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 };
115 static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 };
116 static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet16uc>(p2d_ZERO), reinterpret_cast<Packet16uc>(p2d_ONE), 8));
117 
118 static Packet16uc p16uc_PSET64_HI = { 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };
119 static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 };
120 
121 // Mask alignment
122 #define EIGEN_MASK_ALIGNMENT 0xfffffffffffffff0
123 
124 #define EIGEN_ALIGNED_PTR(x) ((std::ptrdiff_t)(x) & EIGEN_MASK_ALIGNMENT)
125 
126 // Handle endianness properly while loading constants
127 // Define global static constants:
128 
129 static Packet16uc p16uc_FORWARD = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15 };
130 static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 };
131 static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
132 
133 static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 };
134 static Packet16uc p16uc_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 };
135 /*static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16};
136 
137 static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };*/
138 static Packet16uc p16uc_PSET64_LO = (Packet16uc) vec_mergel((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, 16,17,18,19, 20,21,22,23};
140 static Packet16uc p16uc_TRANSPOSE64_LO = vec_add(p16uc_PSET64_LO, p16uc_HALF64_0_16); //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};*/
141 static Packet16uc p16uc_TRANSPOSE64_HI = { 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23};
142 static Packet16uc p16uc_TRANSPOSE64_LO = { 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};
143 
144 static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 };
145 
146 static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
147 
148 
149 #if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
150  #define EIGEN_ZVECTOR_PREFETCH(ADDR) __builtin_prefetch(ADDR);
151 #else
152  #define EIGEN_ZVECTOR_PREFETCH(ADDR) asm( " pfd [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" );
153 #endif
154 
155 template<> struct packet_traits<int> : default_packet_traits
156 {
157  typedef Packet4i type;
158  typedef Packet4i half;
159  enum {
160  Vectorizable = 1,
161  AlignedOnScalar = 1,
162  size = 4,
163 
164  HasAdd = 1,
165  HasSub = 1,
166  HasMul = 1,
167  HasDiv = 1,
168  HasBlend = 1
169  };
170 };
171 
172 template <>
173 struct packet_traits<float> : default_packet_traits {
174  typedef Packet4f type;
175  typedef Packet4f half;
176  enum {
177  Vectorizable = 1,
178  AlignedOnScalar = 1,
179  size = 4,
180 
181  HasAdd = 1,
182  HasSub = 1,
183  HasMul = 1,
184  HasDiv = 1,
185  HasMin = 1,
186  HasMax = 1,
187  HasAbs = 1,
188  HasSin = 0,
189  HasCos = 0,
190  HasLog = 0,
191  HasExp = 1,
192  HasSqrt = 1,
193  HasRsqrt = 1,
194  HasTanh = 1,
195  HasErf = 1,
196  HasRound = 1,
197  HasFloor = 1,
198  HasCeil = 1,
199  HasNegate = 1,
200  HasBlend = 1
201  };
202 };
203 
204 template<> struct packet_traits<double> : default_packet_traits
205 {
206  typedef Packet2d type;
207  typedef Packet2d half;
208  enum {
209  Vectorizable = 1,
210  AlignedOnScalar = 1,
211  size=2,
212 
213  HasAdd = 1,
214  HasSub = 1,
215  HasMul = 1,
216  HasDiv = 1,
217  HasMin = 1,
218  HasMax = 1,
219  HasAbs = 1,
220  HasSin = 0,
221  HasCos = 0,
222  HasLog = 0,
223  HasExp = 1,
224  HasSqrt = 1,
225  HasRsqrt = 1,
226  HasRound = 1,
227  HasFloor = 1,
228  HasCeil = 1,
229  HasNegate = 1,
230  HasBlend = 1
231  };
232 };
233 
234 template<> struct unpacket_traits<Packet4i> { typedef int type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4i half; };
235 template<> struct unpacket_traits<Packet4f> { typedef float type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4f half; };
236 template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2d half; };
237 
238 /* Forward declaration */
239 EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f,4>& kernel);
240 
241 inline std::ostream & operator <<(std::ostream & s, const Packet4i & v)
242 {
243  Packet vt;
244  vt.v4i = v;
245  s << vt.i[0] << ", " << vt.i[1] << ", " << vt.i[2] << ", " << vt.i[3];
246  return s;
247 }
248 
249 inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v)
250 {
251  Packet vt;
252  vt.v4ui = v;
253  s << vt.ui[0] << ", " << vt.ui[1] << ", " << vt.ui[2] << ", " << vt.ui[3];
254  return s;
255 }
256 
257 inline std::ostream & operator <<(std::ostream & s, const Packet2l & v)
258 {
259  Packet vt;
260  vt.v2l = v;
261  s << vt.l[0] << ", " << vt.l[1];
262  return s;
263 }
264 
265 inline std::ostream & operator <<(std::ostream & s, const Packet2ul & v)
266 {
267  Packet vt;
268  vt.v2ul = v;
269  s << vt.ul[0] << ", " << vt.ul[1] ;
270  return s;
271 }
272 
273 inline std::ostream & operator <<(std::ostream & s, const Packet2d & v)
274 {
275  Packet vt;
276  vt.v2d = v;
277  s << vt.d[0] << ", " << vt.d[1];
278  return s;
279 }
280 
281 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
282 inline std::ostream & operator <<(std::ostream & s, const Packet4f & v)
283 {
284  Packet vt;
285  vt.v4f = v;
286  s << vt.f[0] << ", " << vt.f[1] << ", " << vt.f[2] << ", " << vt.f[3];
287  return s;
288 }
289 #endif
290 
291 template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from)
292 {
293  // FIXME: No intrinsic yet
295  Packet *vfrom;
296  vfrom = (Packet *) from;
297  return vfrom->v4i;
298 }
299 
300 template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from)
301 {
302  // FIXME: No intrinsic yet
304  Packet *vfrom;
305  vfrom = (Packet *) from;
306  return vfrom->v2d;
307 }
308 
309 template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from)
310 {
311  // FIXME: No intrinsic yet
313  Packet *vto;
314  vto = (Packet *) to;
315  vto->v4i = from;
316 }
317 
318 template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from)
319 {
320  // FIXME: No intrinsic yet
322  Packet *vto;
323  vto = (Packet *) to;
324  vto->v2d = from;
325 }
326 
327 template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from)
328 {
329  return vec_splats(from);
330 }
331 template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) {
332  return vec_splats(from);
333 }
334 
335 template<> EIGEN_STRONG_INLINE void
336 pbroadcast4<Packet4i>(const int *a,
337  Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3)
338 {
339  a3 = pload<Packet4i>(a);
340  a0 = vec_splat(a3, 0);
341  a1 = vec_splat(a3, 1);
342  a2 = vec_splat(a3, 2);
343  a3 = vec_splat(a3, 3);
344 }
345 
346 template<> EIGEN_STRONG_INLINE void
347 pbroadcast4<Packet2d>(const double *a,
348  Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3)
349 {
350  a1 = pload<Packet2d>(a);
351  a0 = vec_splat(a1, 0);
352  a1 = vec_splat(a1, 1);
353  a3 = pload<Packet2d>(a+2);
354  a2 = vec_splat(a3, 0);
355  a3 = vec_splat(a3, 1);
356 }
357 
358 template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride)
359 {
360  EIGEN_ALIGN16 int ai[4];
361  ai[0] = from[0*stride];
362  ai[1] = from[1*stride];
363  ai[2] = from[2*stride];
364  ai[3] = from[3*stride];
365  return pload<Packet4i>(ai);
366 }
367 
368 template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride)
369 {
370  EIGEN_ALIGN16 double af[2];
371  af[0] = from[0*stride];
372  af[1] = from[1*stride];
373  return pload<Packet2d>(af);
374 }
375 
376 template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride)
377 {
378  EIGEN_ALIGN16 int ai[4];
379  pstore<int>((int *)ai, from);
380  to[0*stride] = ai[0];
381  to[1*stride] = ai[1];
382  to[2*stride] = ai[2];
383  to[3*stride] = ai[3];
384 }
385 
386 template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride)
387 {
388  EIGEN_ALIGN16 double af[2];
389  pstore<double>(af, from);
390  to[0*stride] = af[0];
391  to[1*stride] = af[1];
392 }
393 
394 template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a + b); }
395 template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a + b); }
396 
397 template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a - b); }
398 template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a - b); }
399 
400 template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a * b); }
401 template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a * b); }
402 
403 template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a / b); }
404 template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a / b); }
405 
406 template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return (-a); }
407 template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return (-a); }
408 
409 template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; }
410 template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; }
411 
412 template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd<Packet4i>(pmul<Packet4i>(a, b), c); }
413 template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); }
414 
415 template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return padd<Packet4i>(pset1<Packet4i>(a), p4i_COUNTDOWN); }
416 template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return padd<Packet2d>(pset1<Packet2d>(a), p2d_COUNTDOWN); }
417 
418 template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); }
419 template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_min(a, b); }
420 
421 template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); }
422 template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_max(a, b); }
423 
424 template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); }
425 template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); }
426 
427 template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); }
428 template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); }
429 
430 template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); }
431 template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); }
432 
433 template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return pand<Packet4i>(a, vec_nor(b, b)); }
434 template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); }
435 
436 template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { return vec_round(a); }
437 template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); }
438 template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); }
439 
440 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) { return pload<Packet4i>(from); }
441 template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) { return pload<Packet2d>(from); }
442 
443 
444 template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from)
445 {
446  Packet4i p = pload<Packet4i>(from);
447  return vec_perm(p, p, p16uc_DUPLICATE32_HI);
448 }
449 
450 template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from)
451 {
452  Packet2d p = pload<Packet2d>(from);
453  return vec_perm(p, p, p16uc_PSET64_HI);
454 }
455 
456 template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { pstore<int>(to, from); }
457 template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) { pstore<double>(to, from); }
458 
459 template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
460 template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
461 
462 template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { EIGEN_ALIGN16 int x[4]; pstore(x, a); return x[0]; }
463 template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { EIGEN_ALIGN16 double x[2]; pstore(x, a); return x[0]; }
464 
465 template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a)
466 {
467  return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
468 }
469 
470 template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a)
471 {
472  return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64));
473 }
474 
475 template<> EIGEN_STRONG_INLINE Packet4i pabs<Packet4i>(const Packet4i& a) { return vec_abs(a); }
476 template<> EIGEN_STRONG_INLINE Packet2d pabs<Packet2d>(const Packet2d& a) { return vec_abs(a); }
477 
478 template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
479 {
480  Packet4i b, sum;
481  b = vec_sld(a, a, 8);
482  sum = padd<Packet4i>(a, b);
483  b = vec_sld(sum, sum, 4);
484  sum = padd<Packet4i>(sum, b);
485  return pfirst(sum);
486 }
487 
488 template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
489 {
490  Packet2d b, sum;
491  b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8));
492  sum = padd<Packet2d>(a, b);
493  return pfirst(sum);
494 }
495 
496 // Other reduction functions:
497 // mul
498 template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a)
499 {
500  EIGEN_ALIGN16 int aux[4];
501  pstore(aux, a);
502  return aux[0] * aux[1] * aux[2] * aux[3];
503 }
504 
505 template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
506 {
507  return pfirst(pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
508 }
509 
510 // min
511 template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a)
512 {
513  Packet4i b, res;
514  b = pmin<Packet4i>(a, vec_sld(a, a, 8));
515  res = pmin<Packet4i>(b, vec_sld(b, b, 4));
516  return pfirst(res);
517 }
518 
519 template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a)
520 {
521  return pfirst(pmin<Packet2d>(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
522 }
523 
524 // max
525 template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a)
526 {
527  Packet4i b, res;
528  b = pmax<Packet4i>(a, vec_sld(a, a, 8));
529  res = pmax<Packet4i>(b, vec_sld(b, b, 4));
530  return pfirst(res);
531 }
532 
533 // max
534 template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a)
535 {
536  return pfirst(pmax<Packet2d>(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
537 }
538 
539 EIGEN_DEVICE_FUNC inline void
540 ptranspose(PacketBlock<Packet4i,4>& kernel) {
541  Packet4i t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
542  Packet4i t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
543  Packet4i t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
544  Packet4i t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
545  kernel.packet[0] = vec_mergeh(t0, t2);
546  kernel.packet[1] = vec_mergel(t0, t2);
547  kernel.packet[2] = vec_mergeh(t1, t3);
548  kernel.packet[3] = vec_mergel(t1, t3);
549 }
550 
551 EIGEN_DEVICE_FUNC inline void
552 ptranspose(PacketBlock<Packet2d,2>& kernel) {
553  Packet2d t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI);
554  Packet2d t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO);
555  kernel.packet[0] = t0;
556  kernel.packet[1] = t1;
557 }
558 
559 template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) {
560  Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] };
561  Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE));
562  return vec_sel(elsePacket, thenPacket, mask);
563 }
564 
565 
566 template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) {
567  Packet2ul select = { ifPacket.select[0], ifPacket.select[1] };
568  Packet2ul mask = vec_cmpeq(select, reinterpret_cast<Packet2ul>(p2l_ONE));
569  return vec_sel(elsePacket, thenPacket, mask);
570 }
571 
572 /* z13 has no vector float support so we emulate that with double
573  z14 has proper vector float support.
574 */
575 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
576 /* Helper function to simulate a vec_splat_packet4f
577  */
578 template<int element> EIGEN_STRONG_INLINE Packet4f vec_splat_packet4f(const Packet4f& from)
579 {
580  Packet4f splat;
581  switch (element) {
582  case 0:
583  splat.v4f[0] = vec_splat(from.v4f[0], 0);
584  splat.v4f[1] = splat.v4f[0];
585  break;
586  case 1:
587  splat.v4f[0] = vec_splat(from.v4f[0], 1);
588  splat.v4f[1] = splat.v4f[0];
589  break;
590  case 2:
591  splat.v4f[0] = vec_splat(from.v4f[1], 0);
592  splat.v4f[1] = splat.v4f[0];
593  break;
594  case 3:
595  splat.v4f[0] = vec_splat(from.v4f[1], 1);
596  splat.v4f[1] = splat.v4f[0];
597  break;
598  }
599  return splat;
600 }
601 
602 template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
603 {
604  // FIXME: No intrinsic yet
606  Packet4f vfrom;
607  vfrom.v4f[0] = vec_ld2f(&from[0]);
608  vfrom.v4f[1] = vec_ld2f(&from[2]);
609  return vfrom;
610 }
611 
612 template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from)
613 {
614  // FIXME: No intrinsic yet
616  vec_st2f(from.v4f[0], &to[0]);
617  vec_st2f(from.v4f[1], &to[2]);
618 }
619 
620 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from)
621 {
622  Packet4f to;
623  to.v4f[0] = pset1<Packet2d>(static_cast<const double&>(from));
624  to.v4f[1] = to.v4f[0];
625  return to;
626 }
627 
628 template<> EIGEN_STRONG_INLINE void
629 pbroadcast4<Packet4f>(const float *a,
630  Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3)
631 {
632  a3 = pload<Packet4f>(a);
633  a0 = vec_splat_packet4f<0>(a3);
634  a1 = vec_splat_packet4f<1>(a3);
635  a2 = vec_splat_packet4f<2>(a3);
636  a3 = vec_splat_packet4f<3>(a3);
637 }
638 
639 template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride)
640 {
641  EIGEN_ALIGN16 float ai[4];
642  ai[0] = from[0*stride];
643  ai[1] = from[1*stride];
644  ai[2] = from[2*stride];
645  ai[3] = from[3*stride];
646  return pload<Packet4f>(ai);
647 }
648 
649 template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
650 {
651  EIGEN_ALIGN16 float ai[4];
652  pstore<float>((float *)ai, from);
653  to[0*stride] = ai[0];
654  to[1*stride] = ai[1];
655  to[2*stride] = ai[2];
656  to[3*stride] = ai[3];
657 }
658 
659 template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b)
660 {
661  Packet4f c;
662  c.v4f[0] = a.v4f[0] + b.v4f[0];
663  c.v4f[1] = a.v4f[1] + b.v4f[1];
664  return c;
665 }
666 
667 template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b)
668 {
669  Packet4f c;
670  c.v4f[0] = a.v4f[0] - b.v4f[0];
671  c.v4f[1] = a.v4f[1] - b.v4f[1];
672  return c;
673 }
674 
675 template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b)
676 {
677  Packet4f c;
678  c.v4f[0] = a.v4f[0] * b.v4f[0];
679  c.v4f[1] = a.v4f[1] * b.v4f[1];
680  return c;
681 }
682 
683 template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b)
684 {
685  Packet4f c;
686  c.v4f[0] = a.v4f[0] / b.v4f[0];
687  c.v4f[1] = a.v4f[1] / b.v4f[1];
688  return c;
689 }
690 
691 template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a)
692 {
693  Packet4f c;
694  c.v4f[0] = -a.v4f[0];
695  c.v4f[1] = -a.v4f[1];
696  return c;
697 }
698 
699 template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c)
700 {
701  Packet4f res;
702  res.v4f[0] = vec_madd(a.v4f[0], b.v4f[0], c.v4f[0]);
703  res.v4f[1] = vec_madd(a.v4f[1], b.v4f[1], c.v4f[1]);
704  return res;
705 }
706 
707 template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b)
708 {
709  Packet4f res;
710  res.v4f[0] = pmin(a.v4f[0], b.v4f[0]);
711  res.v4f[1] = pmin(a.v4f[1], b.v4f[1]);
712  return res;
713 }
714 
715 template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b)
716 {
717  Packet4f res;
718  res.v4f[0] = pmax(a.v4f[0], b.v4f[0]);
719  res.v4f[1] = pmax(a.v4f[1], b.v4f[1]);
720  return res;
721 }
722 
723 template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b)
724 {
725  Packet4f res;
726  res.v4f[0] = pand(a.v4f[0], b.v4f[0]);
727  res.v4f[1] = pand(a.v4f[1], b.v4f[1]);
728  return res;
729 }
730 
731 template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b)
732 {
733  Packet4f res;
734  res.v4f[0] = por(a.v4f[0], b.v4f[0]);
735  res.v4f[1] = por(a.v4f[1], b.v4f[1]);
736  return res;
737 }
738 
739 template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b)
740 {
741  Packet4f res;
742  res.v4f[0] = pxor(a.v4f[0], b.v4f[0]);
743  res.v4f[1] = pxor(a.v4f[1], b.v4f[1]);
744  return res;
745 }
746 
747 template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b)
748 {
749  Packet4f res;
750  res.v4f[0] = pandnot(a.v4f[0], b.v4f[0]);
751  res.v4f[1] = pandnot(a.v4f[1], b.v4f[1]);
752  return res;
753 }
754 
755 template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a)
756 {
757  Packet4f res;
758  res.v4f[0] = vec_round(a.v4f[0]);
759  res.v4f[1] = vec_round(a.v4f[1]);
760  return res;
761 }
762 
763 template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a)
764 {
765  Packet4f res;
766  res.v4f[0] = vec_ceil(a.v4f[0]);
767  res.v4f[1] = vec_ceil(a.v4f[1]);
768  return res;
769 }
770 
771 template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a)
772 {
773  Packet4f res;
774  res.v4f[0] = vec_floor(a.v4f[0]);
775  res.v4f[1] = vec_floor(a.v4f[1]);
776  return res;
777 }
778 
779 template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
780 {
781  Packet4f p = pload<Packet4f>(from);
782  p.v4f[1] = vec_splat(p.v4f[0], 1);
783  p.v4f[0] = vec_splat(p.v4f[0], 0);
784  return p;
785 }
786 
787 template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { EIGEN_ALIGN16 float x[2]; vec_st2f(a.v4f[0], &x[0]); return x[0]; }
788 
789 template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
790 {
791  Packet4f rev;
792  rev.v4f[0] = preverse<Packet2d>(a.v4f[1]);
793  rev.v4f[1] = preverse<Packet2d>(a.v4f[0]);
794  return rev;
795 }
796 
797 template<> EIGEN_STRONG_INLINE Packet4f pabs<Packet4f>(const Packet4f& a)
798 {
799  Packet4f res;
800  res.v4f[0] = pabs(a.v4f[0]);
801  res.v4f[1] = pabs(a.v4f[1]);
802  return res;
803 }
804 
805 template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
806 {
807  Packet2d sum;
808  sum = padd<Packet2d>(a.v4f[0], a.v4f[1]);
809  double first = predux<Packet2d>(sum);
810  return static_cast<float>(first);
811 }
812 
813 template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
814 {
815  // Return predux_mul<Packet2d> of the subvectors product
816  return static_cast<float>(pfirst(predux_mul(pmul(a.v4f[0], a.v4f[1]))));
817 }
818 
819 template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
820 {
821  Packet2d b, res;
822  b = pmin<Packet2d>(a.v4f[0], a.v4f[1]);
823  res = pmin<Packet2d>(b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8)));
824  return static_cast<float>(pfirst(res));
825 }
826 
827 template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
828 {
829  Packet2d b, res;
830  b = pmax<Packet2d>(a.v4f[0], a.v4f[1]);
831  res = pmax<Packet2d>(b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8)));
832  return static_cast<float>(pfirst(res));
833 }
834 
835 /* Split the Packet4f PacketBlock into 4 Packet2d PacketBlocks and transpose each one
836  */
837 EIGEN_DEVICE_FUNC inline void
838 ptranspose(PacketBlock<Packet4f,4>& kernel) {
839  PacketBlock<Packet2d,2> t0,t1,t2,t3;
840  // copy top-left 2x2 Packet2d block
841  t0.packet[0] = kernel.packet[0].v4f[0];
842  t0.packet[1] = kernel.packet[1].v4f[0];
843 
844  // copy top-right 2x2 Packet2d block
845  t1.packet[0] = kernel.packet[0].v4f[1];
846  t1.packet[1] = kernel.packet[1].v4f[1];
847 
848  // copy bottom-left 2x2 Packet2d block
849  t2.packet[0] = kernel.packet[2].v4f[0];
850  t2.packet[1] = kernel.packet[3].v4f[0];
851 
852  // copy bottom-right 2x2 Packet2d block
853  t3.packet[0] = kernel.packet[2].v4f[1];
854  t3.packet[1] = kernel.packet[3].v4f[1];
855 
856  // Transpose all 2x2 blocks
857  ptranspose(t0);
858  ptranspose(t1);
859  ptranspose(t2);
860  ptranspose(t3);
861 
862  // Copy back transposed blocks, but exchange t1 and t2 due to transposition
863  kernel.packet[0].v4f[0] = t0.packet[0];
864  kernel.packet[0].v4f[1] = t2.packet[0];
865  kernel.packet[1].v4f[0] = t0.packet[1];
866  kernel.packet[1].v4f[1] = t2.packet[1];
867  kernel.packet[2].v4f[0] = t1.packet[0];
868  kernel.packet[2].v4f[1] = t3.packet[0];
869  kernel.packet[3].v4f[0] = t1.packet[1];
870  kernel.packet[3].v4f[1] = t3.packet[1];
871 }
872 
873 template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) {
874  Packet2ul select_hi = { ifPacket.select[0], ifPacket.select[1] };
875  Packet2ul select_lo = { ifPacket.select[2], ifPacket.select[3] };
876  Packet2ul mask_hi = vec_cmpeq(select_hi, reinterpret_cast<Packet2ul>(p2l_ONE));
877  Packet2ul mask_lo = vec_cmpeq(select_lo, reinterpret_cast<Packet2ul>(p2l_ONE));
878  Packet4f result;
879  result.v4f[0] = vec_sel(elsePacket.v4f[0], thenPacket.v4f[0], mask_hi);
880  result.v4f[1] = vec_sel(elsePacket.v4f[1], thenPacket.v4f[1], mask_lo);
881  return result;
882 }
883 
884 template<> Packet4f EIGEN_STRONG_INLINE pcmp_le<Packet4f>(const Packet4f& a, const Packet4f& b)
885 {
886  Packet4f res;
887  res.v4f[0] = pcmp_le(a.v4f[0], b.v4f[0]);
888  res.v4f[1] = pcmp_le(a.v4f[1], b.v4f[1]);
889  return res;
890 }
891 
892 template<> Packet4f EIGEN_STRONG_INLINE pcmp_lt<Packet4f>(const Packet4f& a, const Packet4f& b)
893 {
894  Packet4f res;
895  res.v4f[0] = pcmp_lt(a.v4f[0], b.v4f[0]);
896  res.v4f[1] = pcmp_lt(a.v4f[1], b.v4f[1]);
897  return res;
898 }
899 
900 template<> Packet4f EIGEN_STRONG_INLINE pcmp_eq<Packet4f>(const Packet4f& a, const Packet4f& b)
901 {
902  Packet4f res;
903  res.v4f[0] = pcmp_eq(a.v4f[0], b.v4f[0]);
904  res.v4f[1] = pcmp_eq(a.v4f[1], b.v4f[1]);
905  return res;
906 }
907 
908 #else
909 template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
910 {
911  // FIXME: No intrinsic yet
913  Packet *vfrom;
914  vfrom = (Packet *) from;
915  return vfrom->v4f;
916 }
917 
918 template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from)
919 {
920  // FIXME: No intrinsic yet
922  Packet *vto;
923  vto = (Packet *) to;
924  vto->v4f = from;
925 }
926 
927 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from)
928 {
929  return vec_splats(from);
930 }
931 
932 template<> EIGEN_STRONG_INLINE void
933 pbroadcast4<Packet4f>(const float *a,
934  Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3)
935 {
936  a3 = pload<Packet4f>(a);
937  a0 = vec_splat(a3, 0);
938  a1 = vec_splat(a3, 1);
939  a2 = vec_splat(a3, 2);
940  a3 = vec_splat(a3, 3);
941 }
942 
943 template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride)
944 {
945  EIGEN_ALIGN16 float af[4];
946  af[0] = from[0*stride];
947  af[1] = from[1*stride];
948  af[2] = from[2*stride];
949  af[3] = from[3*stride];
950  return pload<Packet4f>(af);
951 }
952 
953 template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
954 {
955  EIGEN_ALIGN16 float af[4];
956  pstore<float>((float*)af, from);
957  to[0*stride] = af[0];
958  to[1*stride] = af[1];
959  to[2*stride] = af[2];
960  to[3*stride] = af[3];
961 }
962 
963 template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a + b); }
964 template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a - b); }
965 template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a * b); }
966 template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a / b); }
967 template<> EIGEN_STRONG_INLINE Packet4f pnegate<Packet4f>(const Packet4f& a) { return (-a); }
968 template<> EIGEN_STRONG_INLINE Packet4f pconj<Packet4f> (const Packet4f& a) { return a; }
969 template<> EIGEN_STRONG_INLINE Packet4f pmadd<Packet4f> (const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a, b, c); }
970 template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_min(a, b); }
971 template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_max(a, b); }
972 template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_and(a, b); }
973 template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_or(a, b); }
974 template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); }
975 template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, vec_nor(b, b)); }
976 template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f> (const Packet4f& a) { return vec_round(a); }
977 template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f> (const Packet4f& a) { return vec_ceil(a); }
978 template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f> (const Packet4f& a) { return vec_floor(a); }
979 template<> EIGEN_STRONG_INLINE Packet4f pabs<Packet4f> (const Packet4f& a) { return vec_abs(a); }
980 template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { EIGEN_ALIGN16 float x[4]; pstore(x, a); return x[0]; }
981 
982 template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
983 {
984  Packet4f p = pload<Packet4f>(from);
985  return vec_perm(p, p, p16uc_DUPLICATE32_HI);
986 }
987 
988 template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
989 {
990  return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
991 }
992 
993 template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
994 {
995  Packet4f b, sum;
996  b = vec_sld(a, a, 8);
997  sum = padd<Packet4f>(a, b);
998  b = vec_sld(sum, sum, 4);
999  sum = padd<Packet4f>(sum, b);
1000  return pfirst(sum);
1001 }
1002 
1003 // Other reduction functions:
1004 // mul
1005 template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
1006 {
1007  Packet4f prod;
1008  prod = pmul(a, vec_sld(a, a, 8));
1009  return pfirst(pmul(prod, vec_sld(prod, prod, 4)));
1010 }
1011 
1012 // min
1013 template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
1014 {
1015  Packet4f b, res;
1016  b = pmin<Packet4f>(a, vec_sld(a, a, 8));
1017  res = pmin<Packet4f>(b, vec_sld(b, b, 4));
1018  return pfirst(res);
1019 }
1020 
1021 // max
1022 template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
1023 {
1024  Packet4f b, res;
1025  b = pmax<Packet4f>(a, vec_sld(a, a, 8));
1026  res = pmax<Packet4f>(b, vec_sld(b, b, 4));
1027  return pfirst(res);
1028 }
1029 
1030 EIGEN_DEVICE_FUNC inline void
1031 ptranspose(PacketBlock<Packet4f,4>& kernel) {
1032  Packet4f t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
1033  Packet4f t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
1034  Packet4f t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
1035  Packet4f t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
1036  kernel.packet[0] = vec_mergeh(t0, t2);
1037  kernel.packet[1] = vec_mergel(t0, t2);
1038  kernel.packet[2] = vec_mergeh(t1, t3);
1039  kernel.packet[3] = vec_mergel(t1, t3);
1040 }
1041 
1042 template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) {
1043  Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] };
1044  Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE));
1045  return vec_sel(elsePacket, thenPacket, mask);
1046 }
1047 
1048 #endif
1049 
1050 template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
1051 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f> (const float* from) { return pload<Packet4f>(from); }
1052 template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { pstore<float>(to, from); }
1053 template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f> (const float& a) { return padd<Packet4f>(pset1<Packet4f>(a), p4f_COUNTDOWN); }
1054 
1055 } // end namespace internal
1056 
1057 } // end namespace Eigen
1058 
1059 #endif // EIGEN_PACKET_MATH_ZVECTOR_H
Array< int, Dynamic, 1 > v
Array< int, 3, 1 > b
#define EIGEN_ALIGN16
Array33i c
#define EIGEN_DEBUG_ALIGNED_STORE
#define EIGEN_DEBUG_ALIGNED_LOAD
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
float * p
#define EIGEN_ZVECTOR_PREFETCH(ADDR)
@ Aligned16
Definition: Constants.h:237
static Packet16uc p16uc_REVERSE64
Packet4f pcmp_lt< Packet4f >(const Packet4f &a, const Packet4f &b)
std::ostream & operator<<(std::ostream &s, const Packet16c &v)
Packet pmin(const Packet &a, const Packet &b)
Packet2d pdiv< Packet2d >(const Packet2d &a, const Packet2d &b)
double predux_max< Packet2d >(const Packet2d &a)
void pstore(Scalar *to, const Packet &from)
void pstore< float >(float *to, const Packet4f &from)
float predux_max< Packet4f >(const Packet4f &a)
double predux_min< Packet2d >(const Packet2d &a)
static Packet4i p4i_COUNTDOWN
Packet2d plset< Packet2d >(const double &a)
Packet4f vec_splat_packet4f(const Packet4f &from)
__vector int Packet4i
Packet2d pmin< Packet2d >(const Packet2d &a, const Packet2d &b)
Packet2d pmul< Packet2d >(const Packet2d &a, const Packet2d &b)
void pstore< int >(int *to, const Packet4i &from)
static EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0)
static EIGEN_DECLARE_CONST_FAST_Packet2d(ZERO, 0)
Packet4f pxor< Packet4f >(const Packet4f &a, const Packet4f &b)
__vector unsigned char Packet16uc
int predux< Packet4i >(const Packet4i &a)
Packet4f pmin< Packet4f >(const Packet4f &a, const Packet4f &b)
float predux_min< Packet4f >(const Packet4f &a)
Packet2d pceil< Packet2d >(const Packet2d &a)
Packet4f por< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_ALWAYS_INLINE Packet4i pgather< int, Packet4i >(const int *from, Index stride)
static Packet16uc p16uc_TRANSPOSE64_LO
Packet4f pandnot< Packet4f >(const Packet4f &a, const Packet4f &b)
Packet8h pandnot(const Packet8h &a, const Packet8h &b)
Packet4f pabs(const Packet4f &a)
static Packet16uc p16uc_REVERSE32
Packet pmax(const Packet &a, const Packet &b)
float predux< Packet4f >(const Packet4f &a)
Packet4f plset< Packet4f >(const float &a)
Packet2cf pnegate(const Packet2cf &a)
double predux< Packet2d >(const Packet2d &a)
Packet2d pround< Packet2d >(const Packet2d &a)
Packet4f pand< Packet4f >(const Packet4f &a, const Packet4f &b)
int predux_max< Packet4i >(const Packet4i &a)
Packet4f pcmp_eq< Packet4f >(const Packet4f &a, const Packet4f &b)
Packet4f pcmp_le< Packet4f >(const Packet4f &a, const Packet4f &b)
Packet2d pand< Packet2d >(const Packet2d &a, const Packet2d &b)
double predux_mul< Packet2d >(const Packet2d &a)
Packet4f pdiv< Packet4f >(const Packet4f &a, const Packet4f &b)
static Packet16uc p16uc_PSET32_WEVEN
Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Packet2d ploaddup< Packet2d >(const double *from)
Packet4i pmul< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet2cf pcmp_eq(const Packet2cf &a, const Packet2cf &b)
bfloat16 pfirst(const Packet8bf &a)
Packet2d pgather< double, Packet2d >(const double *from, Index stride)
void pstoreu< double >(double *to, const Packet4d &from)
EIGEN_ALWAYS_INLINE void pscatter< int, Packet4i >(int *to, const Packet4i &from, Index stride)
static EIGEN_DECLARE_CONST_FAST_Packet2l(ZERO, 0)
__vector unsigned int Packet4ui
Packet pmul(const Packet &a, const Packet &b)
__vector __bool int Packet4bi
void ptranspose(PacketBlock< Packet2cf, 2 > &kernel)
Packet4i ploadu< Packet4i >(const int *from)
float pfirst< Packet4f >(const Packet4f &a)
double pfirst< Packet2d >(const Packet2d &a)
Packet4i pxor< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet4i pandnot< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet4i pset1< Packet4i >(const int &from)
Packet4f padd< Packet4f >(const Packet4f &a, const Packet4f &b)
Packet4i pload< Packet4i >(const int *from)
Packet4f ploadu< Packet4f >(const float *from)
float predux_mul< Packet4f >(const Packet4f &a)
Packet2d padd< Packet2d >(const Packet2d &a, const Packet2d &b)
Packet2d pandnot< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_ALWAYS_INLINE void pscatter< float, Packet4f >(float *to, const Packet4f &from, Index stride)
void pbroadcast4< Packet4i >(const int *a, Packet4i &a0, Packet4i &a1, Packet4i &a2, Packet4i &a3)
static Packet4f p4f_MZERO
Packet4i ploaddup< Packet4i >(const int *from)
void prefetch< float >(const float *addr)
void prefetch< double >(const double *addr)
Packet4f pmul< Packet4f >(const Packet4f &a, const Packet4f &b)
Packet2d pset1< Packet2d >(const double &from)
static Packet2d p2d_ZERO_
Packet4i pdiv< Packet4i >(const Packet4i &a, const Packet4i &b)
unpacket_traits< Packet >::type predux_mul(const Packet &a)
Packet8h pand(const Packet8h &a, const Packet8h &b)
Packet2d ploadu< Packet2d >(const double *from)
Packet2d pabs< Packet2d >(const Packet2d &a)
Packet4i plset< Packet4i >(const int &a)
void pstoreu< float >(float *to, const Packet4f &from)
static EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0)
static Packet2d p2d_ONE
eigen_packet_wrapper< __m256i, 0 > Packet8i
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Packet4i pabs< Packet4i >(const Packet4i &a)
Packet2d psub< Packet2d >(const Packet2d &a, const Packet2d &b)
Packet2d pfloor< Packet2d >(const Packet2d &a)
static Packet16uc p16uc_PSET64_HI
EIGEN_ALWAYS_INLINE Packet4f pgather< float, Packet4f >(const float *from, Index stride)
Packet8h pxor(const Packet8h &a, const Packet8h &b)
int predux_min< Packet4i >(const Packet4i &a)
Packet4i padd< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet4f pabs< Packet4f >(const Packet4f &a)
Packet4i psub< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet2d pxor< Packet2d >(const Packet2d &a, const Packet2d &b)
int predux_mul< Packet4i >(const Packet4i &a)
Packet4i pblend(const Selector< 4 > &ifPacket, const Packet4i &thenPacket, const Packet4i &elsePacket)
static Packet16uc p16uc_FORWARD
int pfirst< Packet4i >(const Packet4i &a)
Packet4i pmax< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet4i por< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet2cf pconj(const Packet2cf &a)
Packet2d por< Packet2d >(const Packet2d &a, const Packet2d &b)
void pstoreu< int >(int *to, const Packet4i &from)
Packet4f pmax< Packet4f >(const Packet4f &a, const Packet4f &b)
Packet4i pmin< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet4i pand< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet2d pload< Packet2d >(const double *from)
Packet4f psub< Packet4f >(const Packet4f &a, const Packet4f &b)
static Packet2d p2d_COUNTDOWN
static Packet16uc p16uc_PSET32_WODD
Packet2cf preverse(const Packet2cf &a)
static Packet16uc p16uc_PSET64_LO
Packet4f pload< Packet4f >(const float *from)
static Packet16uc p16uc_COMPLEX32_REV
Packet8h por(const Packet8h &a, const Packet8h &b)
Packet4f pset1< Packet4f >(const float &from)
Packet4i pcmp_lt(const Packet4i &a, const Packet4i &b)
Packet4f ploaddup< Packet4f >(const float *from)
__vector float Packet4f
static Packet4f p4f_COUNTDOWN
Packet4f pround< Packet4f >(const Packet4f &a)
Packet4f pfloor< Packet4f >(const Packet4f &a)
void prefetch< int >(const int *addr)
void pbroadcast4< Packet4f >(const float *a, Packet4f &a0, Packet4f &a1, Packet4f &a2, Packet4f &a3)
static Packet16uc p16uc_COMPLEX32_REV2
void pscatter< double, Packet2d >(double *to, const Packet2d &from, Index stride)
void pbroadcast4< Packet2d >(const double *a, Packet2d &a0, Packet2d &a1, Packet2d &a2, Packet2d &a3)
void pstore< double >(double *to, const Packet4d &from)
Packet4f pcmp_le(const Packet4f &a, const Packet4f &b)
Packet4f pceil< Packet4f >(const Packet4f &a)
static Packet16uc p16uc_DUPLICATE32_HI
Packet2d pmax< Packet2d >(const Packet2d &a, const Packet2d &b)
static Packet16uc p16uc_TRANSPOSE64_HI
std::int32_t int32_t
Definition: Meta.h:40
std::int64_t int64_t
Definition: Meta.h:42
std::uint32_t uint32_t
Definition: Meta.h:39
std::uint64_t uint64_t
Definition: Meta.h:41
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82