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

ShLibArithImpl.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHLIBARITHIMPL_HPP
00025 #define SHLIBARITHIMPL_HPP
00026 
00027 #include "ShLibArith.hpp"
00028 #include "ShInstructions.hpp"
00029 
00030 namespace SH {
00031 
00032 template<int N, typename T1, typename T2>
00033 ShGeneric<N, CT1T2>
00034 operator+(const ShGeneric<N, T1>& left, const ShGeneric<N, T2>& right)
00035 {
00036   ShAttrib<N, SH_TEMP, CT1T2> t;
00037   shADD(t, left, right);
00038   return t;
00039 }
00040 template<int N, typename T1, typename T2>
00041 ShGeneric<N, CT1T2>
00042 operator+(const ShGeneric<N, T1>& left, const ShGeneric<1, T2>& right)
00043 {
00044   ShAttrib<N, SH_TEMP, CT1T2> t;
00045   shADD(t, left, right);
00046   return t;
00047 }
00048 template<int N, typename T1, typename T2>
00049 ShGeneric<N, CT1T2>
00050 operator+(const ShGeneric<1, T1>& left, const ShGeneric<N, T2>& right)
00051 {
00052   ShAttrib<N, SH_TEMP, CT1T2> t;
00053   shADD(t, left, right);
00054   return t;
00055 }
00056 template<typename T1, typename T2>
00057 ShGeneric<1, CT1T2>
00058 operator+(const ShGeneric<1, T1>& left, const ShGeneric<1, T2>& right)
00059 {
00060   ShAttrib<1, SH_TEMP, CT1T2> t;
00061   shADD(t, left, right);
00062   return t;
00063 }
00064 SH_SHLIB_CONST_SCALAR_OP(operator+);
00065 SH_SHLIB_CONST_N_OP_BOTH(operator+);
00066 
00067 template<int N, typename T1, typename T2>
00068 ShGeneric<N, CT1T2>
00069 operator-(const ShGeneric<N, T1>& left, const ShGeneric<N, T2>& right)
00070 {
00071   ShAttrib<N, SH_TEMP, CT1T2> t;
00072   shADD(t, left, -right);
00073   return t;
00074 }
00075 template<int N, typename T1, typename T2>
00076 ShGeneric<N, CT1T2>
00077 operator-(const ShGeneric<N, T1>& left, const ShGeneric<1, T2>& right)
00078 {
00079   ShAttrib<N, SH_TEMP, CT1T2> t;
00080   shADD(t, left, -right);
00081   return t;
00082 }
00083 template<int N, typename T1, typename T2>
00084 ShGeneric<N, CT1T2>
00085 operator-(const ShGeneric<1, T1>& left, const ShGeneric<N, T2>& right)
00086 {
00087   ShAttrib<N, SH_TEMP, CT1T2> t;
00088   shADD(t, left, -right);
00089   return t;
00090 }
00091 template<typename T1, typename T2>
00092 ShGeneric<1, CT1T2>
00093 operator-(const ShGeneric<1, T1>& left, const ShGeneric<1, T2>& right)
00094 {
00095   ShAttrib<1, SH_TEMP, CT1T2> t;
00096   shADD(t, left, -right);
00097   return t;
00098 }
00099 SH_SHLIB_CONST_SCALAR_OP(operator-);
00100 SH_SHLIB_CONST_N_OP_BOTH(operator-);
00101 
00102 template<int N, typename T1, typename T2>
00103 ShGeneric<N, CT1T2>
00104 operator*(const ShGeneric<N, T1>& left, const ShGeneric<N, T2>& right)
00105 {
00106   ShAttrib<N, SH_TEMP, CT1T2> t;
00107   shMUL(t, left, right);
00108   return t;
00109 }
00110 template<int N, typename T1, typename T2>
00111 ShGeneric<N, CT1T2>
00112 operator*(const ShGeneric<1, T1>& left, const ShGeneric<N, T2>& right)
00113 {
00114   ShAttrib<N, SH_TEMP, CT1T2> t;
00115   shMUL(t, left, right);
00116   return t;
00117 }
00118 template<int N, typename T1, typename T2>
00119 ShGeneric<N, CT1T2>
00120 operator*(const ShGeneric<N, T1>& left, const ShGeneric<1, T2>& right)
00121 {
00122   ShAttrib<N, SH_TEMP, CT1T2> t;
00123   shMUL(t, left, right);
00124   return t;
00125 }
00126 template<typename T1, typename T2>
00127 ShGeneric<1, CT1T2>
00128 operator*(const ShGeneric<1, T1>& left, const ShGeneric<1, T2>& right)
00129 {
00130   ShAttrib<1, SH_TEMP, CT1T2> t;
00131   shMUL(t, left, right);
00132   return t;
00133 }
00134 SH_SHLIB_CONST_SCALAR_OP(operator*);
00135 SH_SHLIB_CONST_N_OP_BOTH(operator*);
00136 
00137 template<int N, typename T1, typename T2>
00138 ShGeneric<N, CT1T2>
00139 operator/(const ShGeneric<N, T1>& left, const ShGeneric<N, T2>& right)
00140 {
00141   ShAttrib<N, SH_TEMP, CT1T2> t;
00142   shDIV(t, left, right);
00143   return t;
00144 }
00145 template<int N, typename T1, typename T2>
00146 ShGeneric<N, CT1T2>
00147 operator/(const ShGeneric<N, T1>& left, const ShGeneric<1, T2>& right)
00148 {
00149   ShAttrib<N, SH_TEMP, CT1T2> t;
00150   shDIV(t, left, right);
00151   return t;
00152 }
00153 template<int N, typename T1, typename T2>
00154 ShGeneric<N, CT1T2>
00155 operator/(const ShGeneric<1, T1>& left, const ShGeneric<N, T2>& right)
00156 {
00157   ShAttrib<N, SH_TEMP, CT1T2> t;
00158   shDIV(t, left, right);
00159   return t;
00160 }
00161 template<typename T1, typename T2>
00162 ShGeneric<1, CT1T2>
00163 operator/(const ShGeneric<1, T1>& left, const ShGeneric<1, T2>& right)
00164 {
00165   ShAttrib<1, SH_TEMP, CT1T2> t;
00166   shDIV(t, left, right);
00167   return t;
00168 }
00169 SH_SHLIB_CONST_SCALAR_OP(operator/);
00170 SH_SHLIB_CONST_N_OP_LEFT(operator/);
00171 
00172 template<int N, typename T>
00173 ShGeneric<N, T> exp(const ShGeneric<N, T>& var)
00174 {
00175   ShAttrib<N, SH_TEMP, T> t;
00176   shEXP(t, var);
00177   return t;
00178 }
00179 
00180 template<int N, typename T>
00181 ShGeneric<N, T> exp2(const ShGeneric<N, T>& var)
00182 {
00183   ShAttrib<N, SH_TEMP, T> t;
00184   shEXP2(t, var);
00185   return t;
00186 }
00187 
00188 template<int N, typename T>
00189 ShGeneric<N, T> exp10(const ShGeneric<N, T>& var)
00190 {
00191   ShAttrib<N, SH_TEMP, T> t;
00192   shEXP10(t, var);
00193   return t;
00194 }
00195 
00196 template<int N, typename T>
00197 ShGeneric<N, T> expm1(const ShGeneric<N, T>& var)
00198 {
00199   return exp(var - 1.0);
00200 }
00201 
00202 template<int N, typename T>
00203 ShGeneric<N, T> log(const ShGeneric<N, T>& var)
00204 {
00205   ShAttrib<N, SH_TEMP, T> t;
00206   shLOG(t, var);
00207   return t;
00208 }
00209 
00210 template<int N, typename T>
00211 ShGeneric<N, T> log2(const ShGeneric<N, T>& var)
00212 {
00213   ShAttrib<N, SH_TEMP, T> t;
00214   shLOG2(t, var);
00215   return t;
00216 }
00217 
00218 template<int N, typename T>
00219 ShGeneric<N, T> log10(const ShGeneric<N, T>& var)
00220 {
00221   ShAttrib<N, SH_TEMP, T> t;
00222   shLOG10(t, var);
00223   return t;
00224 }
00225 
00226 template<int N, typename T>
00227 ShGeneric<N, T> logp1(const ShGeneric<N, T>& var)
00228 {
00229   return log(var + 1.0);
00230 }
00231 
00232 template<int N, typename T1, typename T2>
00233 ShGeneric<N, CT1T2> pow(const ShGeneric<N, T1>& left, const ShGeneric<N, T2>& right)
00234 {
00235   ShAttrib<N, SH_TEMP, CT1T2> t;
00236   shPOW(t, left, right);
00237   return t;
00238 }
00239 template<int N, typename T1, typename T2>
00240 ShGeneric<N, CT1T2> pow(const ShGeneric<N, T1>& left, const ShGeneric<1, T2>& right)
00241 {
00242   ShAttrib<N, SH_TEMP, CT1T2> t;
00243   shPOW(t, left, right);
00244   return t;
00245 }
00246 template<int N, typename T1, typename T2>
00247 ShGeneric<N, CT1T2> pow(const ShGeneric<1, T1>& left, const ShGeneric<N, T2>& right)
00248 {
00249   ShAttrib<N, SH_TEMP, CT1T2> t;
00250   shPOW(t, left, right);
00251   return t;
00252 }
00253 template<typename T1, typename T2>
00254 ShGeneric<1, CT1T2> pow(const ShGeneric<1, T1>& left, const ShGeneric<1, T2>& right)
00255 {
00256   ShAttrib<1, SH_TEMP, CT1T2> t;
00257   shPOW(t, left, right);
00258   return t;
00259 }
00260 SH_SHLIB_CONST_SCALAR_OP(pow);
00261 SH_SHLIB_CONST_N_OP_RIGHT(pow);
00262 
00263 template<int N, typename T1, typename T2, typename T3>
00264 ShGeneric<N, CT1T2T3> mad(const ShGeneric<N, T1>& m1, const ShGeneric<N, T2>& m2, 
00265                     const ShGeneric<N, T3>& a)
00266 {
00267   ShAttrib<N, SH_TEMP, CT1T2T3> t;
00268   shMAD(t, m1, m2, a);
00269   return t;
00270 }
00271 template<int N, typename T1, typename T2, typename T3>
00272 ShGeneric<N, CT1T2T3> mad(const ShGeneric<N, T1>& m1, const ShGeneric<1, T2>& m2, 
00273                     const ShGeneric<N, T3>& a)
00274 {
00275   ShAttrib<N, SH_TEMP, CT1T2T3> t;
00276   shMAD(t, m1, m2, a);
00277   return t;
00278 }
00279 template<int N, typename T1, typename T2, typename T3>
00280 ShGeneric<N, CT1T2T3> mad(const ShGeneric<1, T1>& m1, const ShGeneric<N, T2>& m2, 
00281                     const ShGeneric<N, T3>& a)
00282 {
00283   ShAttrib<N, SH_TEMP, CT1T2T3> t;
00284   shMAD(t, m1, m2, a);
00285   return t;
00286 }
00287 template<typename T1, typename T2, typename T3>
00288 ShGeneric<1, CT1T2T3> mad(const ShGeneric<1, T1>& m1, const ShGeneric<1, T2>& m2, 
00289                     const ShGeneric<1, T3>& a)
00290 {
00291   ShAttrib<1, SH_TEMP, CT1T2T3> t;
00292   shMAD(t, m1, m2, a);
00293   return t;
00294 }
00295 
00296 template<int N, typename T1, typename T2> 
00297 ShGeneric<N, CT1T2> mad(double m1, const ShGeneric<N, T1>& m2, const ShGeneric<N, T2>& a)
00298 {
00299   ShAttrib<N, SH_TEMP, CT1T2> t;
00300   shMAD(t, ShAttrib<1, SH_CONST, CT1T2>(m1), m2, a);
00301   return t;
00302 }
00303 template<int N, typename T1, typename T2>
00304 ShGeneric<N, CT1T2> mad(const ShGeneric<N, T1>& m1, double m2, const ShGeneric<N, T2>& a)
00305 {
00306   ShAttrib<N, SH_TEMP, CT1T2> t;
00307   shMAD(t, m1, ShAttrib<1, SH_CONST, CT1T2>(m2), a);
00308   return t;
00309 }
00310 
00311 template<int N, typename T>
00312 ShGeneric<N, T> rcp(const ShGeneric<N, T>& var)
00313 {
00314   ShAttrib<N, SH_TEMP, T> t;
00315   shRCP(t, var);
00316   return t;
00317 }
00318 
00319 template<int N, typename T>
00320 ShGeneric<N, T> sqrt(const ShGeneric<N, T>& var)
00321 {
00322   ShAttrib<N, SH_TEMP, T> t;
00323   shSQRT(t, var);
00324   return t;
00325 }
00326 
00327 template<int N, typename T>
00328 ShGeneric<N, T> rsqrt(const ShGeneric<N, T>& var)
00329 {
00330   ShAttrib<N, SH_TEMP, T> t;
00331   shRSQ(t, var);
00332   return t;
00333 }
00334 
00335 template<int N, typename T>
00336 ShGeneric<N, T> cbrt(const ShGeneric<N, T>& var)
00337 {
00338   ShAttrib<N, SH_TEMP, T> t;
00339   shCBRT(t, var);
00340   return t;
00341 }
00342 
00343 template<int N, typename T1, typename T2, typename T3>
00344 ShGeneric<N, CT1T2T3> lerp(const ShGeneric<N, T1>& f, const ShGeneric<N, T2>& a, 
00345                      const ShGeneric<N, T3>& b)
00346 {
00347   ShAttrib<N, SH_TEMP, CT1T2T3> t;
00348   shLRP(t, f, a, b);
00349   return t;
00350 }
00351 
00352 template<int N, typename T1, typename T2, typename T3>
00353 ShGeneric<N, CT1T2T3> lerp(const ShGeneric<1, T1>& f, const ShGeneric<N, T2>& a, 
00354                      const ShGeneric<N, T3>& b)
00355 {
00356   ShAttrib<N, SH_TEMP, CT1T2T3> t;
00357   shLRP(t, f, a, b);
00358   return t;
00359 }
00360 
00361 template<typename T1, typename T2, typename T3>
00362 ShGeneric<1, CT1T2T3> lerp(const ShGeneric<1, T1>& f, const ShGeneric<1, T2>& a, 
00363                      const ShGeneric<1, T3>& b)
00364 {
00365   ShAttrib<1, SH_TEMP, CT1T2T3> t;
00366   shLRP(t, f, a, b);
00367   return t;
00368 }
00369 //@todo type see explanation in LibArith.hpp file
00370 template<int N, typename T1, typename T2>
00371 ShGeneric<N, CT1T2> lerp(double f, const ShGeneric<N, T1>& a, const ShGeneric<N, T2>& b)
00372 {
00373   ShAttrib<N, SH_TEMP, CT1T2> t;
00374   shLRP(t, f, a, b);
00375   return t;
00376 }
00377 
00378 template<int N, typename T>
00379 ShGeneric<1, T> sum(const ShGeneric<N, T>& var)
00380 {
00381   ShAttrib<1, SH_TEMP, T> t;
00382   shCSUM(t, var);
00383   return t;
00384 }
00385 
00386 template<int N, typename T>
00387 ShGeneric<1, T> prod(const ShGeneric<N, T>& var)
00388 {
00389   ShAttrib<1, SH_TEMP, T> t;
00390   shCMUL(t, var);
00391   return t;
00392 }
00393 
00394 
00395 }
00396 
00397 #endif

Generated on Wed Jun 15 18:12:40 2005 for Sh by  doxygen 1.4.3-20050530