TDVecDVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TDVECDVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TDVECDVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/math/Intrinsics.h>
47 #include <blaze/util/Assert.h>
48 #include <blaze/util/DisableIf.h>
49 #include <blaze/util/EnableIf.h>
50 #include <blaze/util/Exception.h>
52 #include <blaze/util/Types.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // CLASS DEFINITION
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
70 template< typename T1 // Type of the left-hand side dense vector
71  , typename T2 > // Type of the right-hand side dense vector
72 struct TDVecDVecMultExprHelper
73 {
74  //**Type definitions****************************************************************************
76  typedef typename RemoveReference< typename T1::CompositeType >::Type CT1;
77 
79  typedef typename RemoveReference< typename T2::CompositeType >::Type CT2;
80  //**********************************************************************************************
81 
82  //**********************************************************************************************
83  enum { value = useOptimizedKernels &&
84  CT1::vectorizable &&
85  CT2::vectorizable &&
86  IsSame< typename CT1::ElementType, typename CT2::ElementType>::value &&
87  IntrinsicTrait< typename CT1::ElementType >::addition &&
88  IntrinsicTrait< typename CT2::ElementType >::multiplication };
89  //**********************************************************************************************
90 };
92 //*************************************************************************************************
93 
94 
95 
96 
97 //=================================================================================================
98 //
99 // GLOBAL BINARY ARITHMETIC OPERATORS
100 //
101 //=================================================================================================
102 
103 //*************************************************************************************************
129 template< typename T1 // Type of the left-hand side dense vector
130  , typename T2 > // Type of the right-hand side dense vector
131 inline typename DisableIf< TDVecDVecMultExprHelper<T1,T2>,
132  const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type >::Type
134 {
136 
137  if( (~lhs).size() != (~rhs).size() ) {
138  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
139  }
140 
141  typedef typename T1::CompositeType Lhs;
142  typedef typename T2::CompositeType Rhs;
143  typedef typename T1::ElementType ET1;
144  typedef typename T2::ElementType ET2;
145  typedef typename MultTrait<ET1,ET2>::Type MultType;
146 
147  if( (~lhs).size() == 0UL ) return MultType();
148 
149  Lhs left ( ~lhs );
150  Rhs right( ~rhs );
151 
152  MultType sp( left[0UL] * right[0UL] );
153 
154  for( size_t i=1UL; i<left.size(); ++i )
155  sp += left[i] * right[i];
156 
157  return sp;
158 }
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
190 template< typename T1 // Type of the left-hand side dense vector
191  , typename T2 > // Type of the right-hand side dense vector
192 inline typename EnableIf< TDVecDVecMultExprHelper<T1,T2>,
193  const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type >::Type
195 {
197 
198  if( (~lhs).size() != (~rhs).size() ) {
199  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
200  }
201 
202  typedef typename T1::CompositeType Lhs;
203  typedef typename T2::CompositeType Rhs;
204  typedef typename T1::ElementType ET1;
205  typedef typename T2::ElementType ET2;
206  typedef typename MultTrait<ET1,ET2>::Type MultType;
207  typedef IntrinsicTrait<MultType> IT;
208 
209  if( (~lhs).size() == 0UL ) return MultType();
210 
211  Lhs left ( ~lhs );
212  Rhs right( ~rhs );
213 
214  typename IT::Type xmm1, xmm2, xmm3, xmm4;
215 
216  const size_t N ( left.size() );
217  const size_t iend( N - N % (IT::size*4UL) );
218  BLAZE_INTERNAL_ASSERT( iend % (IT::size*4UL) == 0, "Invalid end calculation" );
219 
220  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
221  xmm1 = xmm1 + ( left.load(i ) * right.load(i ) );
222  xmm2 = xmm2 + ( left.load(i+IT::size ) * right.load(i+IT::size ) );
223  xmm3 = xmm3 + ( left.load(i+IT::size*2UL) * right.load(i+IT::size*2UL) );
224  xmm4 = xmm4 + ( left.load(i+IT::size*3UL) * right.load(i+IT::size*3UL) );
225  }
226 
227  MultType sp( sum( xmm1 + xmm2 + xmm3 + xmm4 ) );
228 
229  for( size_t i=iend; i<N; ++i )
230  sp += left[i] * right[i];
231 
232  return sp;
233 }
234 //*************************************************************************************************
235 
236 } // namespace blaze
237 
238 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7820
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
Header file for the IsSame and IsStrictlySame type traits.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
Header file for the DenseVector base class.
System settings for performance optimizations.
Header file for the DisableIf class template.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Header file for the EnableIf class template.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:1232
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:138
const bool useOptimizedKernels
Configuration switch for optimized kernels.This configuration switch enables/disables all optimized c...
Definition: Optimizations.h:84
Header file for the RemoveReference type trait.
BLAZE_ALWAYS_INLINE int16_t sum(const simd_int16_t &a)
Returns the sum of all elements in the 16-bit integral intrinsic vector.
Definition: Reduction.h:63
Header file for all intrinsic functionality.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
Header file for exception macros.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the FunctionTrace class.