blitz  Version 1.0.2
tvevaluate.h
Go to the documentation of this file.
1 /***************************************************************************
2  * blitz/tinyvec.cc Declaration of TinyVector methods
3  *
4  * $Id$
5  *
6  * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
7  *
8  * This file is a part of Blitz.
9  *
10  * Blitz is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation, either version 3
13  * of the License, or (at your option) any later version.
14  *
15  * Blitz is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * Suggestions: blitz-devel@lists.sourceforge.net
24  * Bugs: blitz-support@lists.sourceforge.net
25  *
26  * For more information, please see the Blitz++ Home Page:
27  * https://sourceforge.net/projects/blitz/
28  *
29  ***************************************************************************/
30 
31 #ifndef BZ_TVEVALUATE_H
32 #define BZ_TVEVALUATE_H
33 
34 #include <blitz/tinyvec2.h>
35 #include <blitz/update.h>
36 #include <blitz/blitz.h>
37 #include <blitz/meta/vecassign.h>
38 
39 namespace blitz {
40 
41 
44 template<bool unroll, int N_length>
45 struct _tv_evaluator {
46 
55  template<typename T, typename T_expr, typename T_update>
56  static _bz_forceinline void
58  const T_expr& expr, T_update) {
59 
60  // since we can't resize tinyvectors, there are two options: all
61  // vectors have our size or the expression is malformed.
62  // Check that all operands have the same shape
63 #ifdef BZ_DEBUG
64  if (!expr.shapeCheck(dest.shape()))
65  {
66  if (assertFailMode == false)
67  {
68  cerr << "[Blitz++] Shape check failed: Module " << __FILE__
69  << " line " << __LINE__ << endl
70  << " Expression: ";
71  prettyPrintFormat format(true); // Use terse formatting
72  std::string str;
73  expr.prettyPrint(str, format);
74  cerr << str << endl ;
75  }
76  }
77 #endif
78 
79  BZPRECHECK(expr.shapeCheck(dest.shape()),
80  "Shape check failed." << endl << "Expression:");
81 
82  BZPRECONDITION(expr.isUnitStride(0));
83  BZPRECONDITION(T_expr::rank_<=1);
84  BZPRECONDITION(T_expr::numIndexPlaceholders==0);
85 
86  // now call the aligned (unrolled or not) evaluation function
87  const bool do_unroll = N_length < BZ_TV_EVALUATE_UNROLL_LENGTH;
89  }
90 
97  template<typename T_numtype, typename T_expr, typename T_update>
98  static _bz_forceinline void
99  evaluate_aligned(T_numtype* data, const T_expr& expr, T_update) {
100 #ifdef BZ_USE_ALIGNMENT_PRAGMAS
101 #pragma ivdep
102 #pragma vector aligned
103 #endif
104  for (int i=0; i < N_length; ++i)
105  T_update::update(data[i], expr.fastRead(i));
106  }
107 
112  template<typename T_numtype, typename T_expr, typename T_update>
113  static _bz_forceinline void
114  evaluate_unaligned(T_numtype* data, const T_expr& expr, T_update) {
115 #ifdef BZ_USE_ALIGNMENT_PRAGMAS
116 #pragma ivdep
117 #pragma vector unaligned
118 #endif
119  for (int i=0; i < N_length; ++i)
120  T_update::update(data[i], expr.fastRead(i));
121  }
122 };
123 
125 template<int N_length>
126 struct _tv_evaluator<true, N_length> {
127 
131  template<typename T, typename T_expr, typename T_update>
132  static _bz_forceinline void
134  const T_expr& expr, T_update) {
135  _bz_evaluate(dest, expr, T_update());
136  }
137 
142  template<typename T_numtype, typename T_expr, typename T_update>
143  static _bz_forceinline void
144  evaluate_aligned(T_numtype* data, const T_expr& expr, T_update) {
145 #ifdef BZ_USE_ALIGNMENT_PRAGMAS
146  //#pragma ivdep
147  //#pragma vector aligned
148 #endif
149  _bz_meta_vecAssign<N_length, 0>::fastAssign(data, expr, T_update());
150  }
151 
156  template<typename T_numtype, typename T_expr, typename T_update>
157  static _bz_forceinline void
158  evaluate_unaligned(T_numtype* data, const T_expr& expr, T_update) {
159  //#pragma ivdep
160  //#pragma vector unaligned
161  _bz_meta_vecAssign<N_length, 0>::fastAssign(data, expr, T_update());
162  }
163 };
164 
165 
169 template<typename P_numtype, int N_length>
170 template<typename T_expr, typename T_update>
172 void
173 TinyVector<P_numtype,N_length>::_tv_evaluate(const T_expr& expr, T_update)
174 {
175  const bool mixed_expr =
176  (T_expr::numArrayOperands>0) ||
177  (T_expr::numTMOperands>0) ||
178  (T_expr::numIndexPlaceholders>0);
180 }
181 
182 
183 }
184 
185 #endif // BZ_TVEVALUATE_H
_bz_global blitz::IndexPlaceholder< 0 > i
Definition: indexexpr.h:256
static _bz_forceinline void select_evaluation(TinyVector< T, N_length > &dest, const T_expr &expr, T_update)
The false version of select_evaluation is picked for expressions that contain operands other than Tin...
Definition: tvevaluate.h:133
The _tv_evaluator class has a bool template argument that is used to select code paths at compile tim...
Definition: tvevaluate.h:45
static _bz_forceinline void select_evaluation(TinyVector< T, N_length > &dest, const T_expr &expr, T_update)
The select_evaluation function redirects expressions that do not contains solely TinyVector operands ...
Definition: tvevaluate.h:57
Definition: array-impl.h:66
static _bz_forceinline void evaluate_aligned(T_numtype *data, const T_expr &expr, T_update)
This version of the evaluation function assumes that the TinyVectors have appropriate alignment (as w...
Definition: tvevaluate.h:99
static _bz_forceinline void evaluate_aligned(T_numtype *data, const T_expr &expr, T_update)
This version of the evaluation function assumes that the TinyVectors have appropriate alignment (as w...
Definition: tvevaluate.h:144
void _tv_evaluate(const T_expr &expr, T_update)
#define BZ_TV_EVALUATE_UNROLL_LENGTH
Definition: tuning.h:64
const TinyVector< int, rank_ > shape() const
Definition: tinyvec2.h:270
#define _bz_forceinline
Definition: tuning.h:79
The TinyVector class is a one-dimensional, fixed length vector that implements the blitz expression t...
Definition: et-forward.h:14
static _bz_forceinline void evaluate_unaligned(T_numtype *data, const T_expr &expr, T_update)
This version of the evaluation function is used when vectorizing expressions that we know can't be al...
Definition: tvevaluate.h:158
T_numtype *restrict data()
Definition: tinyvec2.h:258
Definition: prettyprint.h:40
static _bz_forceinline void evaluate_unaligned(T_numtype *data, const T_expr &expr, T_update)
This version of the evaluation function is used when vectorizing expressions that we know can't be al...
Definition: tvevaluate.h:114
#define true
Definition: compiler.h:101