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 (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SHDATATYPE_HPP
00028 #define SHDATATYPE_HPP
00029 
00030 #include "ShUtility.hpp"
00031 #include "ShVariableType.hpp"
00032 #include "ShInterval.hpp"
00033 #include "ShHalf.hpp"
00034 #include "ShFraction.hpp"
00035 #include "ShStorageType.hpp"
00036 
00043 namespace SH {
00046 enum ShDataType {
00047   SH_HOST,  //< computation data type on the host
00048   SH_MEM,  //< data type stored in memory on the host
00049   SH_DATATYPE_END
00050 };
00051 
00052 SH_DLLEXPORT
00053 extern const char* dataTypeName[];
00054 
00064 template<typename T, ShDataType DT> struct ShDataTypeCppType; 
00065 
00066 template<typename T> struct ShDataTypeCppType<T, SH_HOST> { typedef T type; }; 
00067 template<typename T> struct ShDataTypeCppType<T, SH_MEM> { typedef T type; }; 
00068 
00069 // define special cases here
00070 #define SH_VALUETYPE_DATATYPE(T, hostType, memType)\
00071   template<> struct ShDataTypeCppType<T, SH_HOST> { typedef hostType type; }; \
00072   template<> struct ShDataTypeCppType<T, SH_MEM> { typedef memType type; }; 
00073 
00074 SH_VALUETYPE_DATATYPE(ShHalf, float, ShHalf); 
00075 
00076 template<typename T> struct ShHostType { typedef typename ShDataTypeCppType<T, SH_HOST>::type type; };
00077 template<typename T> struct ShMemType { typedef typename ShDataTypeCppType<T, SH_MEM>::type type; };
00078 // @}
00079 
00085 template<typename T, ShDataType DT> 
00086 struct ShDataTypeConstant {
00087     typedef typename ShDataTypeCppType<T, DT>::type type;
00088     static const type Zero; /* additive identity and also a true value */ \
00089     static const type One; /* multiplicative identity also a false value */ \
00090 };
00091 
00092 template<typename T, ShDataType DT>
00093 const typename ShDataTypeCppType<T, DT>::type ShDataTypeConstant<T, DT>::Zero = 
00094   (typename ShDataTypeCppType<T, DT>::type)(0.0); 
00095 
00096 template<typename T, ShDataType DT>
00097 const typename ShDataTypeCppType<T, DT>::type ShDataTypeConstant<T, DT>::One = 
00098   (typename ShDataTypeCppType<T, DT>::type)(1.0); 
00099 // @}
00100 
00102 template<typename T, ShDataType DT>
00103 inline
00104 typename ShDataTypeCppType<T, DT>::type shDataTypeCond(bool cond);
00105 
00109 template<typename T>
00110 inline
00111 bool shDataTypeEqual(const T &a, const T &b);
00112 // @}
00113 
00116 template<typename T>
00117 inline
00118 bool shDataTypeIsPositive(const T &a);
00119 
00120 
00123 template<typename T1, ShDataType DT1, typename T2, ShDataType DT2>
00124 void shDataTypeCast(typename ShDataTypeCppType<T1, DT1>::type &dest,
00125                     const typename ShDataTypeCppType<T2, DT2>::type &src);
00126 
00127 }
00128 
00129 #include "ShDataTypeImpl.hpp"
00130 
00131 #endif

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