00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHDATATYPE_HPP
00025 #define SHDATATYPE_HPP
00026
00027 #include "ShUtility.hpp"
00028 #include "ShVariableType.hpp"
00029 #include "ShHalf.hpp"
00030 #include "ShFraction.hpp"
00031 #include "ShStorageType.hpp"
00032
00039 namespace SH {
00042 enum ShDataType {
00043 SH_HOST,
00044 SH_MEM,
00045 SH_DATATYPE_END
00046 };
00047
00048 SH_DLLEXPORT
00049 extern const char* dataTypeName[];
00050
00060 template<typename T, ShDataType DT> struct ShDataTypeCppType;
00061
00062 template<typename T> struct ShDataTypeCppType<T, SH_HOST> { typedef T type; };
00063 template<typename T> struct ShDataTypeCppType<T, SH_MEM> { typedef T type; };
00064
00065
00066 #define SH_VALUETYPE_DATATYPE(T, hostType, memType)\
00067 template<> struct ShDataTypeCppType<T, SH_HOST> { typedef hostType type; }; \
00068 template<> struct ShDataTypeCppType<T, SH_MEM> { typedef memType type; };
00069
00070 SH_VALUETYPE_DATATYPE(ShHalf, float, ShHalf);
00071
00072 template<typename T> struct ShHostType { typedef typename ShDataTypeCppType<T, SH_HOST>::type type; };
00073 template<typename T> struct ShMemType { typedef typename ShDataTypeCppType<T, SH_MEM>::type type; };
00074
00075
00081 template<typename T, ShDataType DT>
00082 struct ShDataTypeConstant {
00083 typedef typename ShDataTypeCppType<T, DT>::type type;
00084 static const type Zero; \
00085 static const type One; \
00086 };
00087
00088 template<typename T, ShDataType DT>
00089 const typename ShDataTypeCppType<T, DT>::type ShDataTypeConstant<T, DT>::Zero =
00090 (typename ShDataTypeCppType<T, DT>::type)(0.0);
00091
00092 template<typename T, ShDataType DT>
00093 const typename ShDataTypeCppType<T, DT>::type ShDataTypeConstant<T, DT>::One =
00094 (typename ShDataTypeCppType<T, DT>::type)(1.0);
00095
00096
00098 template<typename T, ShDataType DT>
00099 inline
00100 typename ShDataTypeCppType<T, DT>::type shDataTypeCond(bool cond);
00101
00105 template<typename T>
00106 inline
00107 bool shDataTypeEqual(const T &a, const T &b);
00108
00109
00112 template<typename T>
00113 inline
00114 bool shDataTypeIsPositive(const T &a);
00115
00116
00119 template<typename T1, ShDataType DT1, typename T2, ShDataType DT2>
00120 void shDataTypeCast(typename ShDataTypeCppType<T1, DT1>::type &dest,
00121 const typename ShDataTypeCppType<T2, DT2>::type &src);
00122
00123 }
00124
00125 #include "ShDataTypeImpl.hpp"
00126
00127 #endif