diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-12-16 18:27:44 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-12-25 00:50:49 +0300 |
commit | ab8d9c4b8853755faa62307750d961dc2ec43708 (patch) | |
tree | 707d52530016e210d46375e2c1c0db432ae230b1 /intern/cycles/util/util_math.h | |
parent | f770bc4757a2b471d5aaee048359096c1c79a6b2 (diff) |
Cycles: Add some utility functions and structures
Most of them are not currently used but are essential for the further work.
- CPU kernels with SSE2 support will now have sse3b, sse3f and sse3i
- Added templatedversions of min4, max4 which are handy to use with register
variables.
- Added util_swap function which gets arguments by pointers.
So hopefully it'll be a portable version of std::swap.
Diffstat (limited to 'intern/cycles/util/util_math.h')
-rw-r--r-- | intern/cycles/util/util_math.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index 6898dc974c6..3d605e0ecfd 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -124,6 +124,24 @@ ccl_device_inline double min(double a, double b) return (a < b)? a: b; } +/* These 2 guys are templated for usage with registers data. + * + * NOTE: Since this is CPU-only functions it is ok to use references here. + * But for other devices we'll need to be careful about this. + */ + +template<typename T> +ccl_device_inline T min4(const T& a, const T& b, const T& c, const T& d) +{ + return min(min(a,b),min(c,d)); +} + +template<typename T> +ccl_device_inline T max4(const T& a, const T& b, const T& c, const T& d) +{ + return max(max(a,b),max(c,d)); +} + #endif ccl_device_inline float min4(float a, float b, float c, float d) @@ -1468,6 +1486,25 @@ ccl_device_inline int util_max_axis(float3 vec) } } +/* NOTE: We don't use std::swap here because of number of reasons: + * + * - We don't want current context to be polluted with all the templated + * functions from stl which might cause some interference about which + * function is used. + * + * - Different devices in theory might want to use intrinsics to optimize + * this function for specific type. + * + * - We don't want ot use references because of OpenCL state at this moment. + */ +template <typename T> +ccl_device_inline void util_swap(T *__restrict a, T *__restrict b) +{ + T c = *a; + *a = *b; + *b = c; +} + CCL_NAMESPACE_END #endif /* __UTIL_MATH_H__ */ |