From c2ee454df447f3fc3be505c4c89ecf94140345c3 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 19 Jul 2010 16:49:09 +0200 Subject: [PATCH] * fix compilation of mixed scalar product * optimize mixed scalar products --- Eigen/src/Core/Functors.h | 24 ++++++++++++++--------- Eigen/src/Core/arch/SSE/PacketMath.h | 2 -- Eigen/src/Core/util/ForwardDeclarations.h | 6 +++--- Eigen/src/Core/util/Macros.h | 2 -- Eigen/src/Core/util/Meta.h | 8 ++++---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 3f059d233..cde91ff97 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2008-2010 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -55,21 +55,25 @@ struct ei_functor_traits > { * * \sa class CwiseBinaryOp, Cwise::operator*(), class VectorwiseOp, MatrixBase::redux() */ -template struct ei_scalar_product_op { +template struct ei_scalar_product_op { + enum { + Vectorizable = ei_is_same_type::ret && ei_packet_traits::HasMul && ei_packet_traits::HasMul + }; + typedef typename ei_scalar_product_traits::ReturnType result_type; EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_product_op) - EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return a * b; } + EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; } template EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const { return ei_pmul(a,b); } template - EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const + EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const { return ei_predux_mul(a); } }; -template -struct ei_functor_traits > { +template +struct ei_functor_traits > { enum { - Cost = NumTraits::MulCost, - PacketAccess = ei_packet_traits::HasMul + Cost = (NumTraits::MulCost + NumTraits::MulCost)/2, // rough estimate! + PacketAccess = ei_scalar_product_op::Vectorizable }; }; @@ -581,13 +585,15 @@ template struct ei_linspaced_op // all functors allow linear access, except ei_scalar_identity_op. So we fix here a quick meta // to indicate whether a functor allows linear access, just always answering 'yes' except for // ei_scalar_identity_op. +// FIXME move this to ei_functor_traits adding a ei_functor_default template struct ei_functor_has_linear_access { enum { ret = 1 }; }; template struct ei_functor_has_linear_access > { enum { ret = 0 }; }; // in CwiseBinaryOp, we require the Lhs and Rhs to have the same scalar type, except for multiplication // where we only require them to have the same _real_ scalar type so one may multiply, say, float by complex. +// FIXME move this to ei_functor_traits adding a ei_functor_default template struct ei_functor_allows_mixing_real_and_complex { enum { ret = 0 }; }; -template struct ei_functor_allows_mixing_real_and_complex > { enum { ret = 1 }; }; +template struct ei_functor_allows_mixing_real_and_complex > { enum { ret = 1 }; }; /** \internal diff --git a/Eigen/src/Core/arch/SSE/PacketMath.h b/Eigen/src/Core/arch/SSE/PacketMath.h index c2459e99f..8c441810c 100644 --- a/Eigen/src/Core/arch/SSE/PacketMath.h +++ b/Eigen/src/Core/arch/SSE/PacketMath.h @@ -45,8 +45,6 @@ template<> struct ei_is_arithmetic<__m128d> { enum { ret = true }; }; #define ei_vec2d_swizzle1(v,p,q) \ (_mm_castsi128_pd(_mm_shuffle_epi32( _mm_castpd_si128(v), ((q*2+1)<<6|(q*2)<<4|(p*2+1)<<2|(p*2))))) -// #define ei_vec2d_swizzle1(v,p,q) \ - (_mm_shuffle_pd(v,v, (q)<<1|(p) )) #define ei_vec4f_swizzle2(a,b,p,q,r,s) \ (_mm_shuffle_ps( (a), (b), ((s)<<6|(r)<<4|(q)<<2|(p)))) diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 310ffa4b3..72223c9e0 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -108,11 +108,10 @@ struct ProductReturnType; // Provides scalar/packet-wise product and product with accumulation // with optional conjugation of the arguments. -template struct ei_conj_helper; +template struct ei_conj_helper; template struct ei_scalar_sum_op; template struct ei_scalar_difference_op; -template struct ei_scalar_product_op; template struct ei_scalar_conj_product_op; template struct ei_scalar_quotient_op; template struct ei_scalar_opposite_op; @@ -140,7 +139,8 @@ template struct ei_scalar_add_op; template struct ei_scalar_constant_op; template struct ei_scalar_identity_op; -template struct ei_scalar_multiple2_op; +template struct ei_scalar_product_op; +template struct ei_scalar_multiple2_op; struct IOFormat; diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 987020e52..7600cc3e7 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -359,10 +359,8 @@ #define EIGEN_CWISE_PRODUCT_RETURN_TYPE(LHS,RHS) \ CwiseBinaryOp< \ ei_scalar_product_op< \ - typename ei_scalar_product_traits< \ typename ei_traits::Scalar, \ typename ei_traits::Scalar \ - >::ReturnType \ >, \ LHS, \ RHS \ diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index b01ceafb2..3d28680b6 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -205,10 +205,10 @@ template struct ei_scalar_product_traits, T> }; // FIXME quick workaround around current limitation of ei_result_of -template -struct ei_result_of(ArgType0,ArgType1)> { -typedef typename ei_scalar_product_traits::type, typename ei_cleantype::type>::ReturnType type; -}; +// template +// struct ei_result_of(ArgType0,ArgType1)> { +// typedef typename ei_scalar_product_traits::type, typename ei_cleantype::type>::ReturnType type; +// }; template struct ei_is_diagonal { enum { ret = false }; };