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

ShStatement.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 <iostream> 00028 #include "ShStatement.hpp" 00029 00030 namespace SH { 00031 00035 const ShOperationInfo opInfo[] = { 00036 {"ASN", 1, ShOperationInfo::LINEAR, false}, 00037 00038 {"NEG", 1, ShOperationInfo::LINEAR, false}, 00039 {"ADD", 2, ShOperationInfo::LINEAR, true}, 00040 {"MUL", 2, ShOperationInfo::LINEAR, true}, 00041 {"DIV", 2, ShOperationInfo::LINEAR, false}, 00042 00043 {"SLT", 2, ShOperationInfo::LINEAR, false}, 00044 {"SLE", 2, ShOperationInfo::LINEAR, false}, 00045 {"SGT", 2, ShOperationInfo::LINEAR, false}, 00046 {"SGE", 2, ShOperationInfo::LINEAR, false}, 00047 {"SEQ", 2, ShOperationInfo::LINEAR, false}, 00048 {"SNE", 2, ShOperationInfo::LINEAR, false}, 00049 00050 {"ABS", 1, ShOperationInfo::LINEAR, false}, 00051 {"ACOS", 1, ShOperationInfo::LINEAR, false}, 00052 {"ASIN", 1, ShOperationInfo::LINEAR, false}, 00053 {"ATAN", 1, ShOperationInfo::LINEAR, false}, 00054 {"ATAN2", 2, ShOperationInfo::LINEAR, false}, 00055 {"CBRT", 1, ShOperationInfo::LINEAR, false}, 00056 {"CEIL", 1, ShOperationInfo::LINEAR, false}, 00057 {"COS", 1, ShOperationInfo::LINEAR, false}, 00058 {"CMUL", 1, ShOperationInfo::ALL, false}, 00059 {"CSUM", 1, ShOperationInfo::ALL, false}, 00060 {"DOT", 2, ShOperationInfo::ALL, true}, 00061 {"DX", 1, ShOperationInfo::EXTERNAL, false}, 00062 {"DY", 1, ShOperationInfo::EXTERNAL, false}, 00063 {"EXP", 1, ShOperationInfo::LINEAR, false}, 00064 {"EXP2", 1, ShOperationInfo::LINEAR, false}, 00065 {"EXP10", 1, ShOperationInfo::LINEAR, false}, 00066 {"FLR", 1, ShOperationInfo::LINEAR, false}, 00067 {"FRAC", 1, ShOperationInfo::LINEAR, false}, 00068 {"LRP", 3, ShOperationInfo::LINEAR, false}, 00069 {"MAD", 3, ShOperationInfo::LINEAR, false}, 00070 {"MAX", 2, ShOperationInfo::LINEAR, false}, 00071 {"MIN", 2, ShOperationInfo::LINEAR, true}, 00072 {"MOD", 2, ShOperationInfo::LINEAR, true}, 00073 {"LOG", 1, ShOperationInfo::LINEAR, false}, 00074 {"LOG2", 1, ShOperationInfo::LINEAR, false}, 00075 {"LOG10", 1, ShOperationInfo::LINEAR, false}, 00076 {"POW", 2, ShOperationInfo::LINEAR, false}, 00077 {"RND", 1, ShOperationInfo::LINEAR, false}, 00078 {"RCP", 1, ShOperationInfo::LINEAR, false}, 00079 {"RSQ", 1, ShOperationInfo::LINEAR, false}, 00080 {"SIN", 1, ShOperationInfo::LINEAR, false}, 00081 {"SGN", 1, ShOperationInfo::LINEAR, false}, 00082 {"SQRT", 1, ShOperationInfo::LINEAR, false}, 00083 {"TAN", 1, ShOperationInfo::LINEAR, false}, 00084 00085 {"NORM", 1, ShOperationInfo::ALL, false}, 00086 {"XPD", 2, ShOperationInfo::ALL, false}, // Not quite true, but probably good enough 00087 00088 {"TEX", 2, ShOperationInfo::EXTERNAL, false}, 00089 {"TEXI", 2, ShOperationInfo::EXTERNAL, false}, 00090 {"TEXD", 3, ShOperationInfo::EXTERNAL, false}, 00091 00092 {"COND", 3, ShOperationInfo::LINEAR, false}, 00093 00094 {"KIL", 1, ShOperationInfo::IGNORE, false}, 00095 00096 {"OPTBRA", 1, ShOperationInfo::IGNORE, false}, 00097 00098 {"FETCH", 1, ShOperationInfo::EXTERNAL, false}, 00099 00100 {0, 0, ShOperationInfo::IGNORE, false} 00101 }; 00102 00103 ShStatementInfo::ShStatementInfo() 00104 { 00105 } 00106 00107 ShStatementInfo::~ShStatementInfo() 00108 { 00109 } 00110 00111 ShStatement::ShStatement(ShVariable dest, ShOperation op) 00112 : dest(dest), op(op) 00113 { 00114 } 00115 00116 ShStatement::ShStatement(ShVariable dest, ShOperation op, ShVariable src1) 00117 : dest(dest), op(op) 00118 { 00119 src[0] = src1; 00120 } 00121 00122 ShStatement::ShStatement(ShVariable dest, ShVariable src0, ShOperation op, ShVariable src1) 00123 : dest(dest), op(op) 00124 { 00125 src[0] = src0; 00126 src[1] = src1; 00127 } 00128 00129 ShStatement::ShStatement(ShVariable dest, ShOperation op, ShVariable src0, ShVariable src1, ShVariable src2) 00130 : dest(dest), op(op) 00131 { 00132 src[0] = src0; 00133 src[1] = src1; 00134 src[2] = src2; 00135 } 00136 00137 ShStatement::ShStatement(const ShStatement& other) 00138 : dest(other.dest), 00139 op(other.op), 00140 marked(other.marked) 00141 { 00142 for (int i = 0; i < 3; i++) src[i] = other.src[i]; 00143 for (std::list<ShStatementInfo*>::const_iterator I = other.info.begin(); I != other.info.end(); ++I) { 00144 info.push_back((*I)->clone()); 00145 } 00146 } 00147 00148 00149 ShStatement& ShStatement::operator=(const ShStatement& other) 00150 { 00151 if (&other == this) return *this; 00152 00153 dest = other.dest; 00154 op = other.op; 00155 marked = other.marked; 00156 for (int i = 0; i < 3; i++) src[i] = other.src[i]; 00157 00158 for (std::list<ShStatementInfo*>::const_iterator I = info.begin(); 00159 I != info.end(); ++I) { 00160 delete *I; 00161 } 00162 info.clear(); 00163 00164 for (std::list<ShStatementInfo*>::const_iterator I = other.info.begin(); 00165 I != other.info.end(); ++I) { 00166 info.push_back((*I)->clone()); 00167 } 00168 00169 return *this; 00170 } 00171 00172 ShStatement::~ShStatement() 00173 { 00174 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end(); ++I) { 00175 delete *I; 00176 } 00177 } 00178 00179 std::ostream& operator<<(std::ostream& out, const ShStatement& stmt) 00180 { 00181 if (stmt.op == SH::SH_OP_ASN) { 00182 // Special case for assignment 00183 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << stmt.src[0].name() << stmt.src[0].swizzle(); 00184 return out; 00185 } 00186 00187 switch (SH::opInfo[stmt.op].arity) { 00188 case 0: 00189 out << SH::opInfo[stmt.op].name << " " << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle(); 00190 break; 00191 case 1: 00192 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << SH::opInfo[stmt.op].name 00193 << " " << (stmt.src[0].neg() ? "-" : "") << stmt.src[0].name() << stmt.src[0].swizzle(); 00194 break; 00195 case 2: 00196 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << (stmt.src[0].neg() ? "-" : "") << stmt.src[0].name() << stmt.src[0].swizzle() 00197 << " " << SH::opInfo[stmt.op].name << " " <<(stmt.src[1].neg() ? "-" : "") << stmt.src[1].name() << stmt.src[1].swizzle(); 00198 break; 00199 case 3: 00200 out << (stmt.dest.neg() ? "-" : "") << stmt.dest.name() << stmt.dest.swizzle() << " := " << SH::opInfo[stmt.op].name << " " 00201 << (stmt.src[0].neg() ? "-" : "") << stmt.src[0].name() << stmt.src[0].swizzle() << ", " 00202 << (stmt.src[1].neg() ? "-" : "") << stmt.src[1].name() << stmt.src[1].swizzle() << ", " 00203 << (stmt.src[2].neg() ? "-" : "") << stmt.src[2].name() << stmt.src[2].swizzle(); 00204 break; 00205 default: 00206 out << "<<<Unknown arity>>>"; 00207 break; 00208 } 00209 return out; 00210 } 00211 00212 void ShStatement::add_info(ShStatementInfo* new_info) 00213 { 00214 info.push_back(new_info); 00215 } 00216 00217 void ShStatement::remove_info(ShStatementInfo* old_info) 00218 { 00219 info.remove(old_info); 00220 } 00221 00222 } // namespace SH 00223

Generated on Mon Oct 18 14:17:40 2004 for Sh by doxygen 1.3.7