00001 #ifndef SHEVAL_HPP
00002 #define SHEVAL_HPP
00003
00004 #include <vector>
00005 #include <map>
00006 #include "ShHashMap.hpp"
00007 #include "ShStatement.hpp"
00008 #include "ShVariant.hpp"
00009 #include "ShOperation.hpp"
00010 #include "ShRefCount.hpp"
00011 #include "ShInterval.hpp"
00012 #include "ShHalf.hpp"
00013
00014 namespace SH {
00015
00039
00040
00041 class ShEvalOp;
00042
00043
00044
00045 struct
00046 SH_DLLEXPORT
00047 ShEvalOpInfo: public ShStatementInfo {
00048 ShOperation m_op;
00049
00050 const ShEvalOp* m_evalOp;
00051
00052
00053
00054
00055 ShValueType m_dest;
00056 ShValueType m_src[3];
00057
00058 ShEvalOpInfo(ShOperation op, const ShEvalOp* evalOp, ShValueType dest,
00059 ShValueType src0, ShValueType src1, ShValueType src2);
00060
00061 ShStatementInfo* clone() const;
00062
00063 std::string encode() const;
00064 };
00065
00066 class
00067 SH_DLLEXPORT
00068 ShEval {
00069 public:
00078 void operator()(ShOperation op, ShVariant* dest,
00079 const ShVariant* a, const ShVariant* b, const ShVariant* c) const;
00080
00082 void addOp(ShOperation op, const ShEvalOp* evalOp, ShValueType dest,
00083 ShValueType src0, ShValueType src1 = SH_VALUETYPE_END,
00084 ShValueType src2 = SH_VALUETYPE_END);
00085
00090 const ShEvalOpInfo* getEvalOpInfo(ShOperation op, ShValueType dest,
00091 ShValueType src0, ShValueType src1 = SH_VALUETYPE_END,
00092 ShValueType src2 = SH_VALUETYPE_END) const;
00093
00095 std::string availableOps() const;
00096
00097 static ShEval* instance();
00098
00099 private:
00100 ShEval();
00101
00102
00103 typedef std::list<ShEvalOpInfo> OpInfoList;
00104 typedef OpInfoList OpInfoMap[SH_OPERATION_END];
00105 OpInfoMap m_evalOpMap;
00106
00107 typedef ShPairPairHashMap<ShOperation, ShValueType, ShValueType, ShValueType, const ShEvalOpInfo*> EvalOpCache;
00108 mutable EvalOpCache m_evalOpCache;
00109
00110 static ShEval* m_instance;
00111 };
00112
00113 class
00114 SH_DLLEXPORT
00115 ShEvalOp {
00116 public:
00117 virtual ~ShEvalOp();
00118
00119
00120 virtual void operator()(ShVariant* dest, const ShVariant* a,
00121 const ShVariant* b, const ShVariant* c) const = 0;
00122 };
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00148 template<ShOperation S, typename T>
00149 struct ShRegularOp: public ShEvalOp {
00150 void operator()(ShVariant* dest, const ShVariant* a,
00151 const ShVariant* b, const ShVariant* c) const;
00152 };
00153
00154
00155
00156
00157
00158
00159
00160
00161 template<ShOperation S, typename T>
00162 struct ShConcreteRegularOp {
00163 typedef ShDataVariant<T, SH_HOST> Variant;
00164 typedef Variant* DataPtr;
00165 typedef const Variant* DataCPtr;
00166
00167 static void doop(DataPtr dest, DataCPtr a, DataCPtr b = 0, DataCPtr c = 0);
00168 };
00169
00171
00172
00173
00174
00175
00176 template<ShOperation S, typename T>
00177 struct ShConcreteCTypeOp {
00178 typedef ShDataVariant<T, SH_HOST> Variant;
00179 typedef Variant* DataPtr;
00180 typedef const Variant* DataCPtr;
00181
00182 static void doop(DataPtr dest, DataCPtr a, DataCPtr b = 0, DataCPtr c = 0);
00183 };
00184
00185 template<ShOperation S, typename T>
00186 struct ShRegularOpChooser {
00187 typedef ShConcreteRegularOp<S, T> Op;
00188 };
00189
00190 #define SHOPC_CTYPE_OP(T)\
00191 template<ShOperation S>\
00192 struct ShRegularOpChooser<S, T> {\
00193 typedef ShConcreteCTypeOp<S, T> Op;\
00194 };
00195
00196 SHOPC_CTYPE_OP(double);
00197 SHOPC_CTYPE_OP(float);
00198 SHOPC_CTYPE_OP(ShHalf);
00199 SHOPC_CTYPE_OP(int);
00200
00204 template<ShOperation S, typename T1, typename T2>
00205 struct ShIntervalOp: public ShEvalOp {
00206 void operator()(ShVariant* dest, const ShVariant* a,
00207 const ShVariant* b, const ShVariant* c) const;
00208 };
00209
00210 template<ShOperation S, typename T1, typename T2>
00211 struct ShConcreteIntervalOp{
00212 static void doop(ShDataVariant<T1, SH_HOST> &dest,
00213 const ShDataVariant<T2, SH_HOST> &a);
00214
00215 };
00216
00217
00218
00219
00220 template<typename T>
00221 void _shInitFloatOps();
00222
00223
00224
00225 template<typename T>
00226 void _shInitIntOps();
00227
00228
00229 template<typename T, typename IntervalT>
00230 void _shInitIntervalOps();
00231
00232
00233 }
00234
00235 #include "ShEvalImpl.hpp"
00236 #include "ShConcreteRegularOpImpl.hpp"
00237 #include "ShConcreteCTypeOpImpl.hpp"
00238 #include "ShConcreteIntervalOpImpl.hpp"
00239
00240
00241 #endif