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