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

ShDataType.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
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,  //< computation data type on the host
00044   SH_MEM,  //< data type stored in memory on the host
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 // define special cases here
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; /* additive identity and also a true value */ \
00085     static const type One; /* multiplicative identity also a false value */ \
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

Generated on Thu Apr 21 17:32:46 2005 for Sh by  doxygen 1.4.2