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 library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
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,  //< computation data type on the host
00040   SH_MEM,  //< data type stored in memory on the host
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 // define special cases here
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; /* additive identity and also a true value */ \
00081     static const type One; /* multiplicative identity also a false value */ \
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

Generated on Thu Jul 28 17:33:02 2005 for Sh by  doxygen 1.4.3-20050530