00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHEVAL_HPP
00025 #define SHEVAL_HPP
00026
00027 #include <vector>
00028 #include <map>
00029 #include "ShHashMap.hpp"
00030 #include "ShInfo.hpp"
00031 #include "ShStatement.hpp"
00032 #include "ShVariant.hpp"
00033 #include "ShOperation.hpp"
00034 #include "ShRefCount.hpp"
00035 #include "ShHalf.hpp"
00036
00037 namespace SH {
00038
00062
00063
00064 class ShEvalOp;
00065
00066
00067
00068 struct
00069 SH_DLLEXPORT
00070 ShEvalOpInfo: public ShInfo {
00071 ShOperation m_op;
00072
00073 const ShEvalOp* m_evalOp;
00074
00075
00076
00077
00078 ShValueType m_dest;
00079 ShValueType m_src[3];
00080
00081 ShEvalOpInfo(ShOperation op, const ShEvalOp* evalOp, ShValueType dest,
00082 ShValueType src0, ShValueType src1, ShValueType src2);
00083
00084 ShInfo* clone() const;
00085
00086 std::string encode() const;
00087 };
00088
00089 class
00090 SH_DLLEXPORT
00091 ShEval {
00092 public:
00101 void operator()(ShOperation op, ShVariant* dest,
00102 const ShVariant* a, const ShVariant* b, const ShVariant* c) const;
00103
00104 void operator()(ShOperation op, ShVariantPtr dest,
00105 ShVariantCPtr a, ShVariantCPtr b, ShVariantCPtr c) const;
00106
00107
00109 void addOp(ShOperation op, const ShEvalOp* evalOp, ShValueType dest,
00110 ShValueType src0, ShValueType src1 = SH_VALUETYPE_END,
00111 ShValueType src2 = SH_VALUETYPE_END);
00112
00119 const ShEvalOpInfo* getEvalOpInfo(ShOperation op, ShValueType dest,
00120 ShValueType src0, ShValueType src1 = SH_VALUETYPE_END,
00121 ShValueType src2 = SH_VALUETYPE_END) const;
00122 const ShEvalOpInfo* getEvalOpInfo(const ShStatement &stmt) const;
00124
00126 std::string availableOps() const;
00127
00128 static ShEval* instance();
00129
00130 private:
00131 ShEval();
00132
00133
00134 typedef std::list<ShEvalOpInfo> OpInfoList;
00135 typedef OpInfoList OpInfoMap[SH_OPERATION_END];
00136 OpInfoMap m_evalOpMap;
00137
00138 typedef ShPairPairHashMap<ShOperation, ShValueType, ShValueType, ShValueType, const ShEvalOpInfo*> EvalOpCache;
00139 mutable EvalOpCache m_evalOpCache;
00140
00141 static ShEval* m_instance;
00142 };
00143
00144 class
00145 SH_DLLEXPORT
00146 ShEvalOp {
00147 public:
00148 virtual ~ShEvalOp();
00149
00150
00151 virtual void operator()(ShVariant* dest, const ShVariant* a,
00152 const ShVariant* b, const ShVariant* c) const = 0;
00153 };
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00179 template<ShOperation S, typename T>
00180 struct ShRegularOp: public ShEvalOp {
00181 void operator()(ShVariant* dest, const ShVariant* a,
00182 const ShVariant* b, const ShVariant* c) const;
00183 };
00184
00185
00186
00187
00188
00189
00190
00191
00192 template<ShOperation S, typename T>
00193 struct ShConcreteRegularOp {
00194 typedef ShDataVariant<T, SH_HOST> Variant;
00195 typedef Variant* DataPtr;
00196 typedef const Variant* DataCPtr;
00197
00198 static void doop(DataPtr dest, DataCPtr a, DataCPtr b = 0, DataCPtr c = 0);
00199 };
00200
00202
00203
00204
00205
00206
00207 template<ShOperation S, typename T>
00208 struct ShConcreteCTypeOp {
00209 typedef ShDataVariant<T, SH_HOST> Variant;
00210 typedef Variant* DataPtr;
00211 typedef const Variant* DataCPtr;
00212
00213 static void doop(DataPtr dest, DataCPtr a, DataCPtr b = 0, DataCPtr c = 0);
00214 };
00215
00216 template<ShOperation S, typename T>
00217 struct ShRegularOpChooser {
00218 typedef ShConcreteRegularOp<S, T> Op;
00219 };
00220
00221 #define SHOPC_CTYPE_OP(T)\
00222 template<ShOperation S>\
00223 struct ShRegularOpChooser<S, T> {\
00224 typedef ShConcreteCTypeOp<S, T> Op;\
00225 };
00226
00227 SHOPC_CTYPE_OP(double);
00228 SHOPC_CTYPE_OP(float);
00229 SHOPC_CTYPE_OP(ShHalf);
00230 SHOPC_CTYPE_OP(int);
00231
00232
00233
00234 template<typename T>
00235 void _shInitFloatOps();
00236
00237
00238
00239 template<typename T>
00240 void _shInitIntOps();
00241
00242 }
00243
00244 #include "ShEvalImpl.hpp"
00245 #include "ShConcreteRegularOpImpl.hpp"
00246 #include "ShConcreteCTypeOpImpl.hpp"
00247
00248 #endif