Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_math.h
| Show All 28 Lines | |||||
| #endif | #endif | ||||
| #include <float.h> | #include <float.h> | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #endif | #endif | ||||
| #include "util_algorithm.h" | |||||
sergey: That's not best idea in the world to include algorithm for non-CPU kernels. | |||||
| #include "util_types.h" | #include "util_types.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* Float Pi variations */ | /* Float Pi variations */ | ||||
| /* Division */ | /* Division */ | ||||
| #ifndef M_PI_F | #ifndef M_PI_F | ||||
| ▲ Show 20 Lines • Show All 889 Lines • ▼ Show 20 Lines | |||||
| ccl_device_inline void print_float4(const char *label, const float4& a) | ccl_device_inline void print_float4(const char *label, const float4& a) | ||||
| { | { | ||||
| printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w); | printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Int2 */ | |||||
| #ifndef __KERNEL_OPENCL__ | |||||
| ccl_device_inline int2 operator+(const int2 &a, const int2 &b) | |||||
| { | |||||
| return make_int2(a.x + b.x, a.y + b.y); | |||||
| } | |||||
| ccl_device_inline int2 operator+=(int2 &a, const int2 &b) | |||||
| { | |||||
| return a = a + b; | |||||
| } | |||||
| ccl_device_inline int2 operator-(const int2 &a, const int2 &b) | |||||
| { | |||||
| return make_int2(a.x - b.x, a.y - b.y); | |||||
| } | |||||
| ccl_device_inline int2 operator*(const int2 &a, const int2 &b) | |||||
| { | |||||
| return make_int2(a.x * b.x, a.y * b.y); | |||||
| } | |||||
| ccl_device_inline int2 operator/(const int2 &a, const int2 &b) | |||||
| { | |||||
| return make_int2(a.x / b.x, a.y / b.y); | |||||
| } | |||||
| #endif | |||||
| /* Int3 */ | /* Int3 */ | ||||
| #ifndef __KERNEL_OPENCL__ | #ifndef __KERNEL_OPENCL__ | ||||
| ccl_device_inline int3 min(int3 a, int3 b) | ccl_device_inline int3 min(int3 a, int3 b) | ||||
| { | { | ||||
| #if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE41__) | #if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE41__) | ||||
| return _mm_min_epi32(a.m128, b.m128); | return _mm_min_epi32(a.m128, b.m128); | ||||
| ▲ Show 20 Lines • Show All 559 Lines • ▼ Show 20 Lines | ccl_device_inline int util_max_axis(float3 vec) | ||||
| else { | else { | ||||
| if(vec.y > vec.z) | if(vec.y > vec.z) | ||||
| return 1; | return 1; | ||||
| else | else | ||||
| return 2; | return 2; | ||||
| } | } | ||||
| } | } | ||||
| ccl_device_inline int2 hilbert_to_pos(int n, int d) | |||||
sergeyUnsubmitted Not Done Inline ActionsAvoid having rather meaningless names. sergey: Avoid having rather meaningless names. | |||||
| { | |||||
| int2 r, xy = make_int2(0, 0); | |||||
| for(int s = 1; s < n; s *= 2) { | |||||
| r.x = (d / 2) & 1; | |||||
| r.y = (d ^ r.x) & 1; | |||||
| if(!r.y) { | |||||
| if(r.x) | |||||
| xy = make_int2(s-1, s-1) - xy; | |||||
| swap(xy.x, xy.y); | |||||
| } | |||||
| xy += r*make_int2(s, s); | |||||
| d /= 4; | |||||
| } | |||||
| return xy; | |||||
| } | |||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif /* __UTIL_MATH_H__ */ | #endif /* __UTIL_MATH_H__ */ | ||||
That's not best idea in the world to include algorithm for non-CPU kernels.