Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShEvalImpl.hpp

00001 #ifndef SHEVALIMPL_HPP 
00002 #define SHEVALIMPL_HPP
00003 
00004 #include <numeric>
00005 #include "ShEval.hpp"
00006 #include "ShVariant.hpp"
00007 #include "ShDebug.hpp"
00008 #include "ShError.hpp"
00009 
00010 namespace SH {
00011 
00012 template<ShOperation OP, typename T>
00013 void ShRegularOp<OP, T>::operator()( 
00014     ShVariant* dest, const ShVariant* a, const ShVariant* b, const ShVariant* c) const
00015 {
00016   ShDataVariant<T, SH_HOST>* destVec;
00017   const ShDataVariant<T, SH_HOST>  *aVec, *bVec, *cVec;
00018 
00019   SH_DEBUG_ASSERT(dest && a);
00020   destVec = variant_cast<T, SH_HOST>(dest);
00021   aVec = variant_cast<T, SH_HOST>(a);
00022 
00023   if(b) bVec = variant_cast<T, SH_HOST>(b);
00024   else bVec = 0;
00025 
00026   if(c) cVec = variant_cast<T, SH_HOST>(c);
00027   else cVec = 0;
00028 
00029   ShRegularOpChooser<OP, T>::Op::doop(destVec, aVec, bVec, cVec);
00030 }
00031 
00032 template<ShOperation OP, typename T1, typename T2>
00033 void ShIntervalOp<OP, T1, T2>::operator()( 
00034     ShVariant* dest, const ShVariant* a, const ShVariant* b, const ShVariant* c) const
00035 {
00036 
00037   SH_DEBUG_ASSERT(dest && a);
00038 
00039   ShDataVariant<T1, SH_HOST>* destVec = variant_cast<T1, SH_HOST>(dest);
00040 
00041   const ShDataVariant<T2, SH_HOST>* aVec = variant_cast<T2, SH_HOST>(a);
00042 
00043   ShConcreteIntervalOp<OP, T1, T2>::doop(*destVec, *aVec);
00044 }
00045 
00046 template<typename T>
00047 void _shInitFloatOps() {
00048   ShEval* eval = ShEval::instance();
00049   const ShValueType V = ShStorageTypeInfo<T>::value_type;
00050 
00051   eval->addOp(SH_OP_ABS, new ShRegularOp<SH_OP_ABS, T>(), V, V);
00052   eval->addOp(SH_OP_ACOS, new ShRegularOp<SH_OP_ACOS, T>(), V, V);
00053   eval->addOp(SH_OP_ASIN, new ShRegularOp<SH_OP_ASIN, T>(), V, V);
00054   eval->addOp(SH_OP_ASN, new ShRegularOp<SH_OP_ASN, T>(), V, V);
00055   eval->addOp(SH_OP_ATAN, new ShRegularOp<SH_OP_ATAN, T>(), V, V);
00056   eval->addOp(SH_OP_CBRT, new ShRegularOp<SH_OP_CBRT, T>(), V, V);
00057   eval->addOp(SH_OP_CEIL, new ShRegularOp<SH_OP_CEIL, T>(), V, V);
00058   eval->addOp(SH_OP_COS, new ShRegularOp<SH_OP_COS, T>(), V, V);
00059   eval->addOp(SH_OP_CSUM, new ShRegularOp<SH_OP_CSUM, T>(), V, V);
00060   eval->addOp(SH_OP_CMUL, new ShRegularOp<SH_OP_CMUL, T>(), V, V);
00061   eval->addOp(SH_OP_EXP, new ShRegularOp<SH_OP_EXP, T>(), V, V);
00062   eval->addOp(SH_OP_EXP2, new ShRegularOp<SH_OP_EXP2, T>(), V, V);
00063   eval->addOp(SH_OP_EXP10, new ShRegularOp<SH_OP_EXP10, T>(), V, V);
00064   eval->addOp(SH_OP_FLR, new ShRegularOp<SH_OP_FLR, T>(), V, V);
00065   eval->addOp(SH_OP_FRAC, new ShRegularOp<SH_OP_FRAC, T>(), V, V);
00066   eval->addOp(SH_OP_LOG, new ShRegularOp<SH_OP_LOG, T>(), V, V);
00067   eval->addOp(SH_OP_LOG2, new ShRegularOp<SH_OP_LOG2, T>(), V, V);
00068   eval->addOp(SH_OP_LOG10, new ShRegularOp<SH_OP_LOG10, T>(), V, V);
00069   //eval->addOp(SH_OP_NEG, new ShRegularOp<SH_OP_NEG, T>());
00070   eval->addOp(SH_OP_NORM, new ShRegularOp<SH_OP_NORM, T>(), V, V);
00071   eval->addOp(SH_OP_RCP, new ShRegularOp<SH_OP_RCP, T>(), V, V);
00072   eval->addOp(SH_OP_RND, new ShRegularOp<SH_OP_RND, T>(), V, V);
00073   eval->addOp(SH_OP_RSQ, new ShRegularOp<SH_OP_RSQ, T>(), V, V);
00074   eval->addOp(SH_OP_SIN, new ShRegularOp<SH_OP_SIN, T>(), V, V);
00075   eval->addOp(SH_OP_SGN, new ShRegularOp<SH_OP_SGN, T>(), V, V);
00076   eval->addOp(SH_OP_SQRT, new ShRegularOp<SH_OP_SQRT, T>(), V, V);
00077   eval->addOp(SH_OP_TAN, new ShRegularOp<SH_OP_TAN, T>(), V, V);
00078 
00079   eval->addOp(SH_OP_ADD, new ShRegularOp<SH_OP_ADD, T>(), V, V, V);
00080   eval->addOp(SH_OP_ATAN2, new ShRegularOp<SH_OP_ATAN2, T>(), V, V, V);
00081   eval->addOp(SH_OP_DIV, new ShRegularOp<SH_OP_DIV, T>(), V, V, V);
00082   eval->addOp(SH_OP_DOT, new ShRegularOp<SH_OP_DOT, T>(), V, V, V);
00083   eval->addOp(SH_OP_MAX, new ShRegularOp<SH_OP_MAX, T>(), V, V, V);
00084   eval->addOp(SH_OP_MIN, new ShRegularOp<SH_OP_MIN, T>(), V, V, V);
00085   eval->addOp(SH_OP_MOD, new ShRegularOp<SH_OP_MOD, T>(), V, V, V);
00086   eval->addOp(SH_OP_MUL, new ShRegularOp<SH_OP_MUL, T>(), V, V, V);
00087   eval->addOp(SH_OP_POW, new ShRegularOp<SH_OP_POW, T>(), V, V, V);
00088   eval->addOp(SH_OP_SEQ, new ShRegularOp<SH_OP_SEQ, T>(), V, V, V);
00089   eval->addOp(SH_OP_SGE, new ShRegularOp<SH_OP_SGE, T>(), V, V, V);
00090   eval->addOp(SH_OP_SGT, new ShRegularOp<SH_OP_SGT, T>(), V, V, V);
00091   eval->addOp(SH_OP_SLE, new ShRegularOp<SH_OP_SLE, T>(), V, V, V);
00092   eval->addOp(SH_OP_SLT, new ShRegularOp<SH_OP_SLT, T>(), V, V, V);
00093   eval->addOp(SH_OP_SNE, new ShRegularOp<SH_OP_SNE, T>(), V, V, V);
00094   eval->addOp(SH_OP_XPD, new ShRegularOp<SH_OP_XPD, T>(), V, V, V);
00095 
00096   eval->addOp(SH_OP_LRP, new ShRegularOp<SH_OP_LRP, T>(), V, V, V, V);
00097   eval->addOp(SH_OP_MAD, new ShRegularOp<SH_OP_MAD, T>(), V, V, V, V);
00098   eval->addOp(SH_OP_COND, new ShRegularOp<SH_OP_COND, T>(), V, V, V, V);
00099 }
00100 
00101 template<typename T>
00102 void _shInitIntOps() {
00103   ShEval* eval = ShEval::instance();
00104   const ShValueType V = ShStorageTypeInfo<T>::value_type;
00105 
00106   // guaranteed int result ops (ignore overflow)
00107   eval->addOp(SH_OP_ABS, new ShRegularOp<SH_OP_ABS, T>(), V, V);
00108   eval->addOp(SH_OP_ASN, new ShRegularOp<SH_OP_ASN, T>(), V, V);
00109   //eval->addOp(SH_OP_NEG, new ShRegularOp<SH_OP_NEG, T>());
00110   eval->addOp(SH_OP_CSUM, new ShRegularOp<SH_OP_CSUM, T>(), V, V);
00111   eval->addOp(SH_OP_CMUL, new ShRegularOp<SH_OP_CMUL, T>(), V, V);
00112   eval->addOp(SH_OP_SGN, new ShRegularOp<SH_OP_SGN, T>(), V, V);
00113 
00114   eval->addOp(SH_OP_ADD, new ShRegularOp<SH_OP_ADD, T>(), V, V, V);
00115   eval->addOp(SH_OP_DIV, new ShRegularOp<SH_OP_DIV, T>(), V, V, V);
00116   eval->addOp(SH_OP_DOT, new ShRegularOp<SH_OP_DOT, T>(), V, V, V);
00117   eval->addOp(SH_OP_MAX, new ShRegularOp<SH_OP_MAX, T>(), V, V, V);
00118   eval->addOp(SH_OP_MIN, new ShRegularOp<SH_OP_MIN, T>(), V, V, V);
00119   eval->addOp(SH_OP_MOD, new ShRegularOp<SH_OP_MOD, T>(), V, V, V);
00120   eval->addOp(SH_OP_MUL, new ShRegularOp<SH_OP_MUL, T>(), V, V, V);
00121   eval->addOp(SH_OP_POW, new ShRegularOp<SH_OP_POW, T>(), V, V, V);
00122   eval->addOp(SH_OP_SEQ, new ShRegularOp<SH_OP_SEQ, T>(), V, V, V);
00123   eval->addOp(SH_OP_SGE, new ShRegularOp<SH_OP_SGE, T>(), V, V, V);
00124   eval->addOp(SH_OP_SGT, new ShRegularOp<SH_OP_SGT, T>(), V, V, V);
00125   eval->addOp(SH_OP_SLE, new ShRegularOp<SH_OP_SLE, T>(), V, V, V);
00126   eval->addOp(SH_OP_SLT, new ShRegularOp<SH_OP_SLT, T>(), V, V, V);
00127   eval->addOp(SH_OP_SNE, new ShRegularOp<SH_OP_SNE, T>(), V, V, V);
00128   eval->addOp(SH_OP_XPD, new ShRegularOp<SH_OP_XPD, T>(), V, V, V);
00129 
00130   eval->addOp(SH_OP_LRP, new ShRegularOp<SH_OP_LRP, T>(), V, V, V, V);
00131   eval->addOp(SH_OP_MAD, new ShRegularOp<SH_OP_MAD, T>(), V, V, V, V);
00132   eval->addOp(SH_OP_COND, new ShRegularOp<SH_OP_COND, T>(), V, V, V, V);
00133 
00134   // unary ASN equivalents for ints 
00135   eval->addOp(SH_OP_CEIL, new ShRegularOp<SH_OP_ASN, T>(), V, V);
00136   eval->addOp(SH_OP_FLR, new ShRegularOp<SH_OP_ASN, T>(), V, V);
00137   eval->addOp(SH_OP_FRAC, new ShRegularOp<SH_OP_ASN, T>(), V, V);
00138   eval->addOp(SH_OP_RND, new ShRegularOp<SH_OP_ASN, T>(), V, V);
00139 
00140   // all other ops must use float (since they can potentially give float
00141   // results)
00142 }
00143 
00144 template<typename T, typename IntervalT>
00145 void _shInitIntervalOps() {
00146   ShEval* eval = ShEval::instance();
00147   const ShValueType V = ShStorageTypeInfo<T>::value_type;
00148   const ShValueType IntervalV = ShStorageTypeInfo<IntervalT>::value_type; 
00149 
00150   eval->addOp(SH_OP_LO, new ShIntervalOp<SH_OP_LO, T, IntervalT>(), 
00151       V, IntervalV);
00152   eval->addOp(SH_OP_HI, new ShIntervalOp<SH_OP_HI, T, IntervalT>(), 
00153       V, IntervalV);
00154 
00155   eval->addOp(SH_OP_SETLO, new ShIntervalOp<SH_OP_SETLO, IntervalT, T>(), 
00156       IntervalV, V);
00157   eval->addOp(SH_OP_SETHI, new ShIntervalOp<SH_OP_SETHI, IntervalT, T>(), 
00158       IntervalV, V);
00159 }
00160 
00161 }
00162 
00163 #endif

Generated on Mon Jan 24 18:36:31 2005 for Sh by  doxygen 1.4.1