Home | History | Annotate | Download | only in AltiVec
      1 // This file is part of Eigen, a lightweight C++ template library
      2 // for linear algebra.
      3 //
      4 // Copyright (C) 2008 Konstantinos Margaritis <markos (at) codex.gr>
      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_ALTIVEC_H
     11 #define EIGEN_PACKET_MATH_ALTIVEC_H
     12 
     13 namespace Eigen {
     14 
     15 namespace internal {
     16 
     17 #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
     18 #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 4
     19 #endif
     20 
     21 #ifndef EIGEN_HAS_FUSE_CJMADD
     22 #define EIGEN_HAS_FUSE_CJMADD 1
     23 #endif
     24 
     25 // NOTE Altivec has 32 registers, but Eigen only accepts a value of 8 or 16
     26 #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
     27 #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 16
     28 #endif
     29 
     30 typedef __vector float          Packet4f;
     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 
     37 // We don't want to write the same code all the time, but we need to reuse the constants
     38 // and it doesn't really work to declare them global, so we define macros instead
     39 
     40 #define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \
     41   Packet4f p4f_##NAME = (Packet4f) vec_splat_s32(X)
     42 
     43 #define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \
     44   Packet4i p4i_##NAME = vec_splat_s32(X)
     45 
     46 #define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
     47   Packet4f p4f_##NAME = pset1<Packet4f>(X)
     48 
     49 #define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
     50   Packet4f p4f_##NAME = vreinterpretq_f32_u32(pset1<int>(X))
     51 
     52 #define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
     53   Packet4i p4i_##NAME = pset1<Packet4i>(X)
     54 
     55 #define DST_CHAN 1
     56 #define DST_CTRL(size, count, stride) (((size) << 24) | ((count) << 16) | (stride))
     57 
     58 // Define global static constants:
     59 static Packet4f p4f_COUNTDOWN = { 3.0, 2.0, 1.0, 0.0 };
     60 static Packet4i p4i_COUNTDOWN = { 3, 2, 1, 0 };
     61 static Packet16uc p16uc_REVERSE = {12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3};
     62 static Packet16uc p16uc_FORWARD = vec_lvsl(0, (float*)0);
     63 static Packet16uc p16uc_DUPLICATE = {0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7};
     64 
     65 static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0);
     66 static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0);
     67 static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE,1);
     68 static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS16,-16);
     69 static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1);
     70 static Packet4f p4f_ONE = vec_ctf(p4i_ONE, 0);
     71 static Packet4f p4f_ZERO_ = (Packet4f) vec_sl((Packet4ui)p4i_MINUS1, (Packet4ui)p4i_MINUS1);
     72 
     73 template<> struct packet_traits<float>  : default_packet_traits
     74 {
     75   typedef Packet4f type;
     76   enum {
     77     Vectorizable = 1,
     78     AlignedOnScalar = 1,
     79     size=4,
     80 
     81     // FIXME check the Has*
     82     HasSin  = 0,
     83     HasCos  = 0,
     84     HasLog  = 0,
     85     HasExp  = 0,
     86     HasSqrt = 0
     87   };
     88 };
     89 template<> struct packet_traits<int>    : default_packet_traits
     90 {
     91   typedef Packet4i type;
     92   enum {
     93     // FIXME check the Has*
     94     Vectorizable = 1,
     95     AlignedOnScalar = 1,
     96     size=4
     97   };
     98 };
     99 
    100 template<> struct unpacket_traits<Packet4f> { typedef float  type; enum {size=4}; };
    101 template<> struct unpacket_traits<Packet4i> { typedef int    type; enum {size=4}; };
    102 /*
    103 inline std::ostream & operator <<(std::ostream & s, const Packet4f & v)
    104 {
    105   union {
    106     Packet4f   v;
    107     float n[4];
    108   } vt;
    109   vt.v = v;
    110   s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
    111   return s;
    112 }
    113 
    114 inline std::ostream & operator <<(std::ostream & s, const Packet4i & v)
    115 {
    116   union {
    117     Packet4i   v;
    118     int n[4];
    119   } vt;
    120   vt.v = v;
    121   s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
    122   return s;
    123 }
    124 
    125 inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v)
    126 {
    127   union {
    128     Packet4ui   v;
    129     unsigned int n[4];
    130   } vt;
    131   vt.v = v;
    132   s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
    133   return s;
    134 }
    135 
    136 inline std::ostream & operator <<(std::ostream & s, const Packetbi & v)
    137 {
    138   union {
    139     Packet4bi v;
    140     unsigned int n[4];
    141   } vt;
    142   vt.v = v;
    143   s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
    144   return s;
    145 }
    146 */
    147 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float&  from) {
    148   // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html
    149   float EIGEN_ALIGN16 af[4];
    150   af[0] = from;
    151   Packet4f vc = vec_ld(0, af);
    152   vc = vec_splat(vc, 0);
    153   return vc;
    154 }
    155 
    156 template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int&    from)   {
    157   int EIGEN_ALIGN16 ai[4];
    158   ai[0] = from;
    159   Packet4i vc = vec_ld(0, ai);
    160   vc = vec_splat(vc, 0);
    161   return vc;
    162 }
    163 
    164 template<> EIGEN_STRONG_INLINE Packet4f plset<float>(const float& a) { return vec_add(pset1<Packet4f>(a), p4f_COUNTDOWN); }
    165 template<> EIGEN_STRONG_INLINE Packet4i plset<int>(const int& a)     { return vec_add(pset1<Packet4i>(a), p4i_COUNTDOWN); }
    166 
    167 template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_add(a,b); }
    168 template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_add(a,b); }
    169 
    170 template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_sub(a,b); }
    171 template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_sub(a,b); }
    172 
    173 template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return psub<Packet4f>(p4f_ZERO, a); }
    174 template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return psub<Packet4i>(p4i_ZERO, a); }
    175 
    176 template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_madd(a,b,p4f_ZERO); }
    177 /* Commented out: it's actually slower than processing it scalar
    178  *
    179 template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b)
    180 {
    181   // Detailed in: http://freevec.org/content/32bit_signed_integer_multiplication_altivec
    182   //Set up constants, variables
    183   Packet4i a1, b1, bswap, low_prod, high_prod, prod, prod_, v1sel;
    184 
    185   // Get the absolute values
    186   a1  = vec_abs(a);
    187   b1  = vec_abs(b);
    188 
    189   // Get the signs using xor
    190   Packet4bi sgn = (Packet4bi) vec_cmplt(vec_xor(a, b), p4i_ZERO);
    191 
    192   // Do the multiplication for the asbolute values.
    193   bswap = (Packet4i) vec_rl((Packet4ui) b1, (Packet4ui) p4i_MINUS16 );
    194   low_prod = vec_mulo((Packet8i) a1, (Packet8i)b1);
    195   high_prod = vec_msum((Packet8i) a1, (Packet8i) bswap, p4i_ZERO);
    196   high_prod = (Packet4i) vec_sl((Packet4ui) high_prod, (Packet4ui) p4i_MINUS16);
    197   prod = vec_add( low_prod, high_prod );
    198 
    199   // NOR the product and select only the negative elements according to the sign mask
    200   prod_ = vec_nor(prod, prod);
    201   prod_ = vec_sel(p4i_ZERO, prod_, sgn);
    202 
    203   // Add 1 to the result to get the negative numbers
    204   v1sel = vec_sel(p4i_ZERO, p4i_ONE, sgn);
    205   prod_ = vec_add(prod_, v1sel);
    206 
    207   // Merge the results back to the final vector.
    208   prod = vec_sel(prod, prod_, sgn);
    209 
    210   return prod;
    211 }
    212 */
    213 template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b)
    214 {
    215   Packet4f t, y_0, y_1, res;
    216 
    217   // Altivec does not offer a divide instruction, we have to do a reciprocal approximation
    218   y_0 = vec_re(b);
    219 
    220   // Do one Newton-Raphson iteration to get the needed accuracy
    221   t   = vec_nmsub(y_0, b, p4f_ONE);
    222   y_1 = vec_madd(y_0, t, y_0);
    223 
    224   res = vec_madd(a, y_1, p4f_ZERO);
    225   return res;
    226 }
    227 
    228 template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/)
    229 { eigen_assert(false && "packet integer division are not supported by AltiVec");
    230   return pset1<Packet4i>(0);
    231 }
    232 
    233 // for some weird raisons, it has to be overloaded for packet of integers
    234 template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a, b, c); }
    235 template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd(pmul(a,b), c); }
    236 
    237 template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_min(a, b); }
    238 template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); }
    239 
    240 template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_max(a, b); }
    241 template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); }
    242 
    243 // Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics
    244 template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, b); }
    245 template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); }
    246 
    247 template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_or(a, b); }
    248 template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); }
    249 
    250 template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); }
    251 template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); }
    252 
    253 template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, vec_nor(b, b)); }
    254 template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, vec_nor(b, b)); }
    255 
    256 template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) { EIGEN_DEBUG_ALIGNED_LOAD return vec_ld(0, from); }
    257 template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int*     from) { EIGEN_DEBUG_ALIGNED_LOAD return vec_ld(0, from); }
    258 
    259 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from)
    260 {
    261   EIGEN_DEBUG_ALIGNED_LOAD
    262   // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html
    263   Packet16uc MSQ, LSQ;
    264   Packet16uc mask;
    265   MSQ = vec_ld(0, (unsigned char *)from);          // most significant quadword
    266   LSQ = vec_ld(15, (unsigned char *)from);         // least significant quadword
    267   mask = vec_lvsl(0, from);                        // create the permute mask
    268   return (Packet4f) vec_perm(MSQ, LSQ, mask);           // align the data
    269 
    270 }
    271 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from)
    272 {
    273   EIGEN_DEBUG_ALIGNED_LOAD
    274   // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html
    275   Packet16uc MSQ, LSQ;
    276   Packet16uc mask;
    277   MSQ = vec_ld(0, (unsigned char *)from);          // most significant quadword
    278   LSQ = vec_ld(15, (unsigned char *)from);         // least significant quadword
    279   mask = vec_lvsl(0, from);                        // create the permute mask
    280   return (Packet4i) vec_perm(MSQ, LSQ, mask);    // align the data
    281 }
    282 
    283 template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float*   from)
    284 {
    285   Packet4f p;
    286   if((ptrdiff_t(&from) % 16) == 0)  p = pload<Packet4f>(from);
    287   else                              p = ploadu<Packet4f>(from);
    288   return vec_perm(p, p, p16uc_DUPLICATE);
    289 }
    290 template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int*     from)
    291 {
    292   Packet4i p;
    293   if((ptrdiff_t(&from) % 16) == 0)  p = pload<Packet4i>(from);
    294   else                              p = ploadu<Packet4i>(from);
    295   return vec_perm(p, p, p16uc_DUPLICATE);
    296 }
    297 
    298 template<> EIGEN_STRONG_INLINE void pstore<float>(float*   to, const Packet4f& from) { EIGEN_DEBUG_ALIGNED_STORE vec_st(from, 0, to); }
    299 template<> EIGEN_STRONG_INLINE void pstore<int>(int*       to, const Packet4i& from) { EIGEN_DEBUG_ALIGNED_STORE vec_st(from, 0, to); }
    300 
    301 template<> EIGEN_STRONG_INLINE void pstoreu<float>(float*  to, const Packet4f& from)
    302 {
    303   EIGEN_DEBUG_UNALIGNED_STORE
    304   // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html
    305   // Warning: not thread safe!
    306   Packet16uc MSQ, LSQ, edges;
    307   Packet16uc edgeAlign, align;
    308 
    309   MSQ = vec_ld(0, (unsigned char *)to);                     // most significant quadword
    310   LSQ = vec_ld(15, (unsigned char *)to);                    // least significant quadword
    311   edgeAlign = vec_lvsl(0, to);                              // permute map to extract edges
    312   edges=vec_perm(LSQ,MSQ,edgeAlign);                        // extract the edges
    313   align = vec_lvsr( 0, to );                                // permute map to misalign data
    314   MSQ = vec_perm(edges,(Packet16uc)from,align);             // misalign the data (MSQ)
    315   LSQ = vec_perm((Packet16uc)from,edges,align);             // misalign the data (LSQ)
    316   vec_st( LSQ, 15, (unsigned char *)to );                   // Store the LSQ part first
    317   vec_st( MSQ, 0, (unsigned char *)to );                    // Store the MSQ part
    318 }
    319 template<> EIGEN_STRONG_INLINE void pstoreu<int>(int*      to, const Packet4i& from)
    320 {
    321   EIGEN_DEBUG_UNALIGNED_STORE
    322   // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html
    323   // Warning: not thread safe!
    324   Packet16uc MSQ, LSQ, edges;
    325   Packet16uc edgeAlign, align;
    326 
    327   MSQ = vec_ld(0, (unsigned char *)to);                     // most significant quadword
    328   LSQ = vec_ld(15, (unsigned char *)to);                    // least significant quadword
    329   edgeAlign = vec_lvsl(0, to);                              // permute map to extract edges
    330   edges=vec_perm(LSQ, MSQ, edgeAlign);                      // extract the edges
    331   align = vec_lvsr( 0, to );                                // permute map to misalign data
    332   MSQ = vec_perm(edges, (Packet16uc) from, align);          // misalign the data (MSQ)
    333   LSQ = vec_perm((Packet16uc) from, edges, align);          // misalign the data (LSQ)
    334   vec_st( LSQ, 15, (unsigned char *)to );                   // Store the LSQ part first
    335   vec_st( MSQ, 0, (unsigned char *)to );                    // Store the MSQ part
    336 }
    337 
    338 template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { vec_dstt(addr, DST_CTRL(2,2,32), DST_CHAN); }
    339 template<> EIGEN_STRONG_INLINE void prefetch<int>(const int*     addr) { vec_dstt(addr, DST_CTRL(2,2,32), DST_CHAN); }
    340 
    341 template<> EIGEN_STRONG_INLINE float  pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x[4]; vec_st(a, 0, x); return x[0]; }
    342 template<> EIGEN_STRONG_INLINE int    pfirst<Packet4i>(const Packet4i& a) { int   EIGEN_ALIGN16 x[4]; vec_st(a, 0, x); return x[0]; }
    343 
    344 template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) { return (Packet4f)vec_perm((Packet16uc)a,(Packet16uc)a, p16uc_REVERSE); }
    345 template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) { return (Packet4i)vec_perm((Packet16uc)a,(Packet16uc)a, p16uc_REVERSE); }
    346 
    347 template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return vec_abs(a); }
    348 template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vec_abs(a); }
    349 
    350 template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
    351 {
    352   Packet4f b, sum;
    353   b   = (Packet4f) vec_sld(a, a, 8);
    354   sum = vec_add(a, b);
    355   b   = (Packet4f) vec_sld(sum, sum, 4);
    356   sum = vec_add(sum, b);
    357   return pfirst(sum);
    358 }
    359 
    360 template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs)
    361 {
    362   Packet4f v[4], sum[4];
    363 
    364   // It's easier and faster to transpose then add as columns
    365   // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation
    366   // Do the transpose, first set of moves
    367   v[0] = vec_mergeh(vecs[0], vecs[2]);
    368   v[1] = vec_mergel(vecs[0], vecs[2]);
    369   v[2] = vec_mergeh(vecs[1], vecs[3]);
    370   v[3] = vec_mergel(vecs[1], vecs[3]);
    371   // Get the resulting vectors
    372   sum[0] = vec_mergeh(v[0], v[2]);
    373   sum[1] = vec_mergel(v[0], v[2]);
    374   sum[2] = vec_mergeh(v[1], v[3]);
    375   sum[3] = vec_mergel(v[1], v[3]);
    376 
    377   // Now do the summation:
    378   // Lines 0+1
    379   sum[0] = vec_add(sum[0], sum[1]);
    380   // Lines 2+3
    381   sum[1] = vec_add(sum[2], sum[3]);
    382   // Add the results
    383   sum[0] = vec_add(sum[0], sum[1]);
    384 
    385   return sum[0];
    386 }
    387 
    388 template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
    389 {
    390   Packet4i sum;
    391   sum = vec_sums(a, p4i_ZERO);
    392   sum = vec_sld(sum, p4i_ZERO, 12);
    393   return pfirst(sum);
    394 }
    395 
    396 template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs)
    397 {
    398   Packet4i v[4], sum[4];
    399 
    400   // It's easier and faster to transpose then add as columns
    401   // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation
    402   // Do the transpose, first set of moves
    403   v[0] = vec_mergeh(vecs[0], vecs[2]);
    404   v[1] = vec_mergel(vecs[0], vecs[2]);
    405   v[2] = vec_mergeh(vecs[1], vecs[3]);
    406   v[3] = vec_mergel(vecs[1], vecs[3]);
    407   // Get the resulting vectors
    408   sum[0] = vec_mergeh(v[0], v[2]);
    409   sum[1] = vec_mergel(v[0], v[2]);
    410   sum[2] = vec_mergeh(v[1], v[3]);
    411   sum[3] = vec_mergel(v[1], v[3]);
    412 
    413   // Now do the summation:
    414   // Lines 0+1
    415   sum[0] = vec_add(sum[0], sum[1]);
    416   // Lines 2+3
    417   sum[1] = vec_add(sum[2], sum[3]);
    418   // Add the results
    419   sum[0] = vec_add(sum[0], sum[1]);
    420 
    421   return sum[0];
    422 }
    423 
    424 // Other reduction functions:
    425 // mul
    426 template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
    427 {
    428   Packet4f prod;
    429   prod = pmul(a, (Packet4f)vec_sld(a, a, 8));
    430   return pfirst(pmul(prod, (Packet4f)vec_sld(prod, prod, 4)));
    431 }
    432 
    433 template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a)
    434 {
    435   EIGEN_ALIGN16 int aux[4];
    436   pstore(aux, a);
    437   return aux[0] * aux[1] * aux[2] * aux[3];
    438 }
    439 
    440 // min
    441 template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
    442 {
    443   Packet4f b, res;
    444   b = vec_min(a, vec_sld(a, a, 8));
    445   res = vec_min(b, vec_sld(b, b, 4));
    446   return pfirst(res);
    447 }
    448 
    449 template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a)
    450 {
    451   Packet4i b, res;
    452   b = vec_min(a, vec_sld(a, a, 8));
    453   res = vec_min(b, vec_sld(b, b, 4));
    454   return pfirst(res);
    455 }
    456 
    457 // max
    458 template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
    459 {
    460   Packet4f b, res;
    461   b = vec_max(a, vec_sld(a, a, 8));
    462   res = vec_max(b, vec_sld(b, b, 4));
    463   return pfirst(res);
    464 }
    465 
    466 template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a)
    467 {
    468   Packet4i b, res;
    469   b = vec_max(a, vec_sld(a, a, 8));
    470   res = vec_max(b, vec_sld(b, b, 4));
    471   return pfirst(res);
    472 }
    473 
    474 template<int Offset>
    475 struct palign_impl<Offset,Packet4f>
    476 {
    477   static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second)
    478   {
    479     if (Offset!=0)
    480       first = vec_sld(first, second, Offset*4);
    481   }
    482 };
    483 
    484 template<int Offset>
    485 struct palign_impl<Offset,Packet4i>
    486 {
    487   static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second)
    488   {
    489     if (Offset!=0)
    490       first = vec_sld(first, second, Offset*4);
    491   }
    492 };
    493 
    494 } // end namespace internal
    495 
    496 } // end namespace Eigen
    497 
    498 #endif // EIGEN_PACKET_MATH_ALTIVEC_H
    499