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

ShTypeInfoCasts.cpp

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 #include <fstream>
00028 #include "ShTypeInfo.hpp"
00029 #include "ShCastManager.hpp"
00030 #include "ShVariantCast.hpp"
00031 
00032 namespace {
00033 using namespace SH;
00034 
00035 template<typename Dest, ShDataType DestDT, typename Src, ShDataType SrcDT>
00036 void addCast(bool automatic)
00037 {
00038   ShCastManager::instance()->addCast(ShDataVariantCast<Dest, DestDT, Src, SrcDT>::instance(), automatic);
00039 }
00040 // adds automatic promotion from src to dest
00041 // and a type conversion edge in the opposite direction 
00042 template<typename Dest, typename Src>
00043 void addPromotion()
00044 {
00045   addCast<Dest, SH_HOST, Src, SH_HOST>(true);
00046   addCast<Src, SH_HOST, Dest, SH_HOST>(false);
00047 }
00048 
00049 // adds automatic promotion from src to dest
00050 // and a type conversion edge in the opposite direction
00051 template<typename T>
00052 void addMemoryCast()
00053 {
00054   addCast<T, SH_HOST, T, SH_MEM>(false);
00055   addCast<T, SH_MEM, T, SH_HOST>(false);
00056 }
00057 
00058 }
00059 
00060 namespace SH {
00061 
00062 // This adds the available automatic and explicit casts 
00063 void ShTypeInfo::addCasts()
00064 {
00065   
00066   // automatic promotion DAG edges 
00067   // the inverse edges are added as automatic conversions, but not promotions
00068   // i_d <- i_f, d 
00069   // i_f <- f
00070   // d <- f
00071   // f <- h, i, ui, fi, fs, fb, fui, fus, fub
00072   // i <- s, b, us, ub
00073   //
00074   // This should give a connected graph with maximum diameter (longest shortest
00075   // path between all pairs) of 3 (i.e. convering fi to b goes fi -> f -> i ->
00076   // b)
00077   //
00078   // We can add in a few more automatic conversions to turn this down to 2
00079   // (by making f the direct "supertype" of everything fractional or int)
00080   
00081   addPromotion<ShInterval<double>, ShInterval<float> >();
00082   addCast<ShInterval<double>, SH_HOST, double, SH_HOST>(true);
00083 
00084   addCast<ShInterval<float>, SH_HOST, float, SH_HOST>(true);
00085 
00086   addPromotion<double, float>();
00087 
00088   addPromotion<float, ShHalf>();
00089   addPromotion<float, int>();
00090   addPromotion<float, unsigned int>();
00091   addPromotion<float, ShFracInt> ();
00092   addPromotion<float, ShFracShort> ();
00093   addPromotion<float, ShFracByte> ();
00094   addPromotion<float, ShFracUInt> ();
00095   addPromotion<float, ShFracUShort> ();
00096   addPromotion<float, ShFracUByte> ();
00097 
00098   addPromotion<int, short>();
00099   addPromotion<int, char>();
00100   addPromotion<int, unsigned short>();
00101   addPromotion<int, unsigned char>();
00102 
00103   // these are the extra conversions to make the diameter = 2
00104   addCast<float, SH_HOST, short, SH_HOST>(false);
00105   addCast<float, SH_HOST, char, SH_HOST>(false);
00106   addCast<float, SH_HOST, unsigned short, SH_HOST>(false);
00107   addCast<float, SH_HOST, unsigned char, SH_HOST>(false);
00108 
00109   // these are the memory->SH_HOST, SH_HOST->memory casts
00110   addMemoryCast<ShInterval<double> >();
00111   addMemoryCast<ShInterval<float> >();
00112 
00113   addMemoryCast<double>();
00114   addMemoryCast<float>();
00115   addMemoryCast<ShHalf>();
00116 
00117   addMemoryCast<int>();
00118   addMemoryCast<short>();
00119   addMemoryCast<char>();
00120   addMemoryCast<unsigned int>();
00121   addMemoryCast<unsigned short>();
00122   addMemoryCast<unsigned char>();
00123 
00124   addMemoryCast<ShFraction<int> >();
00125   addMemoryCast<ShFraction<short> >();
00126   addMemoryCast<ShFraction<char> >();
00127   addMemoryCast<ShFraction<unsigned int> >();
00128   addMemoryCast<ShFraction<unsigned short> >();
00129   addMemoryCast<ShFraction<unsigned char> >();
00130 
00131   ShCastManager::instance()->init();
00132 
00133 #if 0
00134   std::ofstream fout("castgraph.dot");
00135   ShCastManager::instance()->graphvizDump(fout);
00136   system("dot -Tps < castgraph.dot > castgraph.ps");
00137 #endif
00138 }
00139 
00140 }

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