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