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