00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #ifndef SHDATATYPE_HPP
00021 #define SHDATATYPE_HPP
00022
00023 #include "ShUtility.hpp"
00024 #include "ShVariableType.hpp"
00025 #include "ShHalf.hpp"
00026 #include "ShFraction.hpp"
00027 #include "ShStorageType.hpp"
00028
00035 namespace SH {
00038 enum ShDataType {
00039 SH_HOST,
00040 SH_MEM,
00041 SH_DATATYPE_END
00042 };
00043
00044 SH_DLLEXPORT
00045 extern const char* dataTypeName[];
00046
00056 template<typename T, ShDataType DT> struct ShDataTypeCppType;
00057
00058 template<typename T> struct ShDataTypeCppType<T, SH_HOST> { typedef T type; };
00059 template<typename T> struct ShDataTypeCppType<T, SH_MEM> { typedef T type; };
00060
00061
00062 #define SH_VALUETYPE_DATATYPE(T, hostType, memType)\
00063 template<> struct ShDataTypeCppType<T, SH_HOST> { typedef hostType type; }; \
00064 template<> struct ShDataTypeCppType<T, SH_MEM> { typedef memType type; };
00065
00066 SH_VALUETYPE_DATATYPE(ShHalf, float, ShHalf);
00067
00068 template<typename T> struct ShHostType { typedef typename ShDataTypeCppType<T, SH_HOST>::type type; };
00069 template<typename T> struct ShMemType { typedef typename ShDataTypeCppType<T, SH_MEM>::type type; };
00070
00071
00077 template<typename T, ShDataType DT>
00078 struct ShDataTypeConstant {
00079 typedef typename ShDataTypeCppType<T, DT>::type type;
00080 static const type Zero; \
00081 static const type One; \
00082 };
00083
00084 template<typename T, ShDataType DT>
00085 const typename ShDataTypeCppType<T, DT>::type ShDataTypeConstant<T, DT>::Zero =
00086 (typename ShDataTypeCppType<T, DT>::type)(0.0);
00087
00088 template<typename T, ShDataType DT>
00089 const typename ShDataTypeCppType<T, DT>::type ShDataTypeConstant<T, DT>::One =
00090 (typename ShDataTypeCppType<T, DT>::type)(1.0);
00091
00092
00094 template<typename T, ShDataType DT>
00095 inline
00096 typename ShDataTypeCppType<T, DT>::type shDataTypeCond(bool cond);
00097
00101 template<typename T>
00102 inline
00103 bool shDataTypeEqual(const T &a, const T &b);
00104
00105
00108 template<typename T>
00109 inline
00110 bool shDataTypeIsPositive(const T &a);
00111
00112
00115 template<typename T1, ShDataType DT1, typename T2, ShDataType DT2>
00116 void shDataTypeCast(typename ShDataTypeCppType<T1, DT1>::type &dest,
00117 const typename ShDataTypeCppType<T2, DT2>::type &src);
00118
00119 }
00120
00121 #include "ShDataTypeImpl.hpp"
00122
00123 #endif