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

ShLibArithImpl.hpp

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 SHLIBARITHIMPL_HPP 00028 #define SHLIBARITHIMPL_HPP 00029 00030 #include "ShLibArith.hpp" 00031 #include "ShInstructions.hpp" 00032 00033 namespace SH { 00034 00035 template<int N, typename T> 00036 inline 00037 ShGeneric<N, T> operator+(const ShGeneric<N, T>& left, const ShGeneric<N, T>& right) 00038 { 00039 ShAttrib<N, SH_TEMP, T> t; 00040 shADD(t, left, right); 00041 return t; 00042 } 00043 template<int N, typename T> 00044 inline 00045 ShGeneric<N, T> operator+(const ShGeneric<N, T>& left, const ShGeneric<1, T>& right) 00046 { 00047 ShAttrib<N, SH_TEMP, T> t; 00048 shADD(t, left, right); 00049 return t; 00050 } 00051 template<int N, typename T> 00052 inline 00053 ShGeneric<N, T> operator+(const ShGeneric<1, T>& left, const ShGeneric<N, T>& right) 00054 { 00055 ShAttrib<N, SH_TEMP, T> t; 00056 shADD(t, left, right); 00057 return t; 00058 } 00059 template<typename T> 00060 inline 00061 ShGeneric<1, T> operator+(const ShGeneric<1, T>& left, const ShGeneric<1, T>& right) 00062 { 00063 ShAttrib<1, SH_TEMP, T> t; 00064 shADD(t, left, right); 00065 return t; 00066 } 00067 00068 template<int N, typename T> 00069 inline 00070 ShGeneric<N, T> operator-(const ShGeneric<N, T>& left, const ShGeneric<N, T>& right) 00071 { 00072 ShAttrib<N, SH_TEMP, T> t; 00073 shADD(t, left, -right); 00074 return t; 00075 } 00076 template<int N, typename T> 00077 inline 00078 ShGeneric<N, T> operator-(const ShGeneric<N, T>& left, const ShGeneric<1, T>& right) 00079 { 00080 ShAttrib<N, SH_TEMP, T> t; 00081 shADD(t, left, -right); 00082 return t; 00083 } 00084 template<int N, typename T> 00085 inline 00086 ShGeneric<N, T> operator-(const ShGeneric<1, T>& left, const ShGeneric<N, T>& right) 00087 { 00088 ShAttrib<N, SH_TEMP, T> t; 00089 shADD(t, left, -right); 00090 return t; 00091 } 00092 template<typename T> 00093 inline 00094 ShGeneric<1, T> operator-(const ShGeneric<1, T>& left, const ShGeneric<1, T>& right) 00095 { 00096 ShAttrib<1, SH_TEMP, T> t; 00097 shADD(t, left, -right); 00098 return t; 00099 } 00100 00101 template<int N, typename T> 00102 inline 00103 ShGeneric<N, T> operator*(const ShGeneric<N, T>& left, const ShGeneric<N, T>& right) 00104 { 00105 ShAttrib<N, SH_TEMP, T> t; 00106 shMUL(t, left, right); 00107 return t; 00108 } 00109 template<int N, typename T> 00110 inline 00111 ShGeneric<N, T> operator*(const ShGeneric<1, T>& left, const ShGeneric<N, T>& right) 00112 { 00113 ShAttrib<N, SH_TEMP, T> t; 00114 shMUL(t, left, right); 00115 return t; 00116 } 00117 template<int N, typename T> 00118 inline 00119 ShGeneric<N, T> operator*(const ShGeneric<N, T>& left, const ShGeneric<1, T>& right) 00120 { 00121 ShAttrib<N, SH_TEMP, T> t; 00122 shMUL(t, left, right); 00123 return t; 00124 } 00125 template<typename T> 00126 inline 00127 ShGeneric<1, T> operator*(const ShGeneric<1, T>& left, const ShGeneric<1, T>& right) 00128 { 00129 ShAttrib<1, SH_TEMP, T> t; 00130 shMUL(t, left, right); 00131 return t; 00132 } 00133 00134 template<int N, typename T> 00135 inline 00136 ShGeneric<N, T> operator/(const ShGeneric<N, T>& left, const ShGeneric<N, T>& right) 00137 { 00138 ShAttrib<N, SH_TEMP, T> t; 00139 shDIV(t, left, right); 00140 return t; 00141 } 00142 template<int N, typename T> 00143 inline 00144 ShGeneric<N, T> operator/(const ShGeneric<N, T>& left, const ShGeneric<1, T>& right) 00145 { 00146 ShAttrib<N, SH_TEMP, T> t; 00147 shDIV(t, left, right); 00148 return t; 00149 } 00150 template<int N, typename T> 00151 inline 00152 ShGeneric<N, T> operator/(const ShGeneric<1, T>& left, const ShGeneric<N, T>& right) 00153 { 00154 ShAttrib<N, SH_TEMP, T> t; 00155 shDIV(t, left, right); 00156 return t; 00157 } 00158 template<typename T> 00159 inline 00160 ShGeneric<1, T> operator/(const ShGeneric<1, T>& left, const ShGeneric<1, T>& right) 00161 { 00162 ShAttrib<1, SH_TEMP, T> t; 00163 shDIV(t, left, right); 00164 return t; 00165 } 00166 00167 template<int N, typename T> 00168 ShGeneric<N, T> exp(const ShGeneric<N, T>& var) 00169 { 00170 ShAttrib<N, SH_TEMP, T> t; 00171 shEXP(t, var); 00172 return t; 00173 } 00174 00175 template<int N, typename T> 00176 ShGeneric<N, T> exp2(const ShGeneric<N, T>& var) 00177 { 00178 ShAttrib<N, SH_TEMP, T> t; 00179 shEXP2(t, var); 00180 return t; 00181 } 00182 00183 template<int N, typename T> 00184 ShGeneric<N, T> exp10(const ShGeneric<N, T>& var) 00185 { 00186 ShAttrib<N, SH_TEMP, T> t; 00187 shEXP10(t, var); 00188 return t; 00189 } 00190 00191 template<int N, typename T> 00192 ShGeneric<N, T> expm1(const ShGeneric<N, T>& var) 00193 { 00194 return exp(var - 1.0); 00195 } 00196 00197 template<int N, typename T> 00198 ShGeneric<N, T> log(const ShGeneric<N, T>& var) 00199 { 00200 ShAttrib<N, SH_TEMP, T> t; 00201 shLOG(t, var); 00202 return t; 00203 } 00204 00205 template<int N, typename T> 00206 ShGeneric<N, T> log2(const ShGeneric<N, T>& var) 00207 { 00208 ShAttrib<N, SH_TEMP, T> t; 00209 shLOG2(t, var); 00210 return t; 00211 } 00212 00213 template<int N, typename T> 00214 ShGeneric<N, T> log10(const ShGeneric<N, T>& var) 00215 { 00216 ShAttrib<N, SH_TEMP, T> t; 00217 shLOG10(t, var); 00218 return t; 00219 } 00220 00221 template<int N, typename T> 00222 ShGeneric<N, T> logp1(const ShGeneric<N, T>& var) 00223 { 00224 return log(var + 1.0); 00225 } 00226 00227 template<int N, typename T> 00228 inline 00229 ShGeneric<N, T> pow(const ShGeneric<N, T>& left, const ShGeneric<N, T>& right) 00230 { 00231 ShAttrib<N, SH_TEMP, T> t; 00232 shPOW(t, left, right); 00233 return t; 00234 } 00235 template<int N, typename T> 00236 inline 00237 ShGeneric<N, T> pow(const ShGeneric<N, T>& left, const ShGeneric<1, T>& right) 00238 { 00239 ShAttrib<N, SH_TEMP, T> t; 00240 shPOW(t, left, right); 00241 return t; 00242 } 00243 template<typename T> 00244 inline 00245 ShGeneric<1, T> pow(const ShGeneric<1, T>& left, const ShGeneric<1, T>& right) 00246 { 00247 ShAttrib<1, SH_TEMP, T> t; 00248 shPOW(t, left, right); 00249 return t; 00250 } 00251 00252 template<int N, typename T> 00253 inline 00254 ShGeneric<N, T> mad(const ShGeneric<N, T>& m1, const ShGeneric<N, T>& m2, 00255 const ShGeneric<N, T>& a) 00256 { 00257 ShAttrib<N, SH_TEMP, T> t; 00258 shMAD(t, m1, m2, a); 00259 return t; 00260 } 00261 template<int N, typename T> 00262 inline 00263 ShGeneric<N, T> mad(const ShGeneric<N, T>& m1, const ShGeneric<1, T>& m2, 00264 const ShGeneric<N, T>& a) 00265 { 00266 ShAttrib<N, SH_TEMP, T> t; 00267 shMAD(t, m1, m2, a); 00268 return t; 00269 } 00270 template<int N, typename T> 00271 inline 00272 ShGeneric<N, T> mad(const ShGeneric<1, T>& m1, const ShGeneric<N, T>& m2, 00273 const ShGeneric<N, T>& a) 00274 { 00275 ShAttrib<N, SH_TEMP, T> t; 00276 shMAD(t, m1, m2, a); 00277 return t; 00278 } 00279 template<typename T> 00280 inline 00281 ShGeneric<1, T> mad(const ShGeneric<1, T>& m1, const ShGeneric<1, T>& m2, 00282 const ShGeneric<1, T>& a) 00283 { 00284 ShAttrib<1, SH_TEMP, T> t; 00285 shMAD(t, m1, m2, a); 00286 return t; 00287 } 00288 00289 template<int N, typename T> 00290 inline 00291 ShGeneric<N, T> mad(T m1, const ShGeneric<N, T>& m2, const ShGeneric<N, T>& a) 00292 { 00293 ShAttrib<N, SH_TEMP, T> t; 00294 shMAD(t, ShAttrib<1, SH_CONST, T>(m1), m2, a); 00295 return t; 00296 } 00297 template<int N, typename T> 00298 inline 00299 ShGeneric<N, T> mad(double m1, const ShGeneric<N, T>& m2, const ShGeneric<N, T>& a) 00300 { 00301 ShAttrib<N, SH_TEMP, T> t; 00302 shMAD(t, ShAttrib<1, SH_CONST, T>(m1), m2, a); 00303 return t; 00304 } 00305 template<int N, typename T> 00306 inline 00307 ShGeneric<N, T> mad(const ShGeneric<N, T>& m1, T m2, const ShGeneric<N, T>& a) 00308 { 00309 ShAttrib<N, SH_TEMP, T> t; 00310 shMAD(t, m1, ShAttrib<1, SH_CONST, T>(m2), a); 00311 return t; 00312 } 00313 template<int N, typename T> 00314 inline 00315 ShGeneric<N, T> mad(const ShGeneric<N, T>& m1, double m2, const ShGeneric<N, T>& a) 00316 { 00317 ShAttrib<N, SH_TEMP, T> t; 00318 shMAD(t, m1, ShAttrib<1, SH_CONST, T>(m2), a); 00319 return t; 00320 } 00321 00322 template<int N, typename T> 00323 inline 00324 ShGeneric<N, T> rcp(const ShGeneric<N, T>& var) 00325 { 00326 ShAttrib<N, SH_TEMP, T> t; 00327 shRCP(t, var); 00328 return t; 00329 } 00330 00331 template<int N, typename T> 00332 inline 00333 ShGeneric<N, T> sqrt(const ShGeneric<N, T>& var) 00334 { 00335 ShAttrib<N, SH_TEMP, T> t; 00336 shSQRT(t, var); 00337 return t; 00338 } 00339 00340 template<int N, typename T> 00341 inline 00342 ShGeneric<N, T> rsqrt(const ShGeneric<N, T>& var) 00343 { 00344 ShAttrib<N, SH_TEMP, T> t; 00345 shRSQ(t, var); 00346 return t; 00347 } 00348 00349 template<int N, typename T> 00350 inline 00351 ShGeneric<N, T> cbrt(const ShGeneric<N, T>& var) 00352 { 00353 ShAttrib<N, SH_TEMP, T> t; 00354 shCBRT(t, var); 00355 return t; 00356 } 00357 00358 template<int N, typename T> 00359 ShGeneric<N, T> lerp(const ShGeneric<N, T>& f, const ShGeneric<N, T>& a, 00360 const ShGeneric<N, T>& b) 00361 { 00362 ShAttrib<N, SH_TEMP, T> t; 00363 shLRP(t, f, a, b); 00364 return t; 00365 } 00366 template<int N, typename T> 00367 ShGeneric<N, T> lerp(const ShGeneric<1, T>& f, const ShGeneric<N, T>& a, 00368 const ShGeneric<N, T>& b) 00369 { 00370 ShAttrib<N, SH_TEMP, T> t; 00371 shLRP(t, f, a, b); 00372 return t; 00373 } 00374 template<typename T> 00375 ShGeneric<1, T> lerp(const ShGeneric<1, T>& f, const ShGeneric<1, T>& a, 00376 const ShGeneric<1, T>& b) 00377 { 00378 ShAttrib<1, SH_TEMP, T> t; 00379 shLRP(t, f, a, b); 00380 return t; 00381 } 00382 template<int N, typename T> 00383 ShGeneric<N, T> lerp(T f, const ShGeneric<N, T>& a, 00384 const ShGeneric<N, T>& b) 00385 { 00386 ShAttrib<N, SH_TEMP, T> t; 00387 shLRP(t, f, a, b); 00388 return t; 00389 } 00390 00391 template<int N, typename T> 00392 ShGeneric<1, T> sum(const ShGeneric<N, T>& var) 00393 { 00394 ShAttrib<1, SH_TEMP, T> t; 00395 shCSUM(t, var); 00396 return t; 00397 } 00398 00399 template<int N, typename T> 00400 ShGeneric<1, T> prod(const ShGeneric<N, T>& var) 00401 { 00402 ShAttrib<1, SH_TEMP, T> t; 00403 shCMUL(t, var); 00404 return t; 00405 } 00406 00407 00408 } 00409 00410 #endif

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