16# include <hip/hip_vector_types.h>
19#if !defined(__KERNEL_METAL__)
30# define M_PI_F (3.1415926535897932f)
33# define M_PI_2_F (1.5707963267948966f)
36# define M_PI_4_F (0.7853981633974830f)
39# define M_1_PI_F (0.3183098861837067f)
42# define M_2_PI_F (0.6366197723675813f)
45# define M_1_2PI_F (0.1591549430918953f)
48# define M_1_4PI_F (0.0795774715459476f)
51# define M_SQRT_PI_8_F (0.6266570686577501f)
54# define M_LN_2PI_F (1.8378770664093454f)
59# define M_2PI_F (6.2831853071795864f)
62# define M_4PI_F (12.566370614359172f)
65# define M_PI_4F 0.78539816339744830962f
70# define M_SQRT2_F (1.4142135623730950f)
73# define M_CBRT2_F 1.2599210498948732f
76# define M_SQRT1_2F 0.70710678118654752440f
79# define M_SQRT3_F (1.7320508075688772f)
82# define M_LN2_F (0.6931471805599453f)
85# define M_LN10_F (2.3025850929940457f)
90#if !defined(__HIP__) && !defined(__KERNEL_ONEAPI__)
94 return (a >
b) ? a :
b;
99 return (a <
b) ? a :
b;
105#if !defined(__KERNEL_GPU__) || defined(__KERNEL_ONEAPI__)
106# ifndef __KERNEL_ONEAPI__
111# define isfinite(x) sycl::isfinite((x))
112# define isnan(x) sycl::isnan((x))
117 return (
x > 0) ?
x : -
x;
122 return (a >
b) ? a :
b;
127 return (a <
b) ? a :
b;
132 return (a >
b) ? a :
b;
137 return (a <
b) ? a :
b;
142 return (a >
b) ? a :
b;
147 return (a <
b) ? a :
b;
160 return (a >
b) ? a :
b;
166 return (a <
b) ? a :
b;
171 return (a >
b) ? a :
b;
176 return (a <
b) ? a :
b;
181 return (a >
b) ? a :
b;
186 return (a <
b) ? a :
b;
223#if !defined(__KERNEL_METAL__) && !defined(__KERNEL_ONEAPI__)
300#if defined(__KERNEL_METAL__)
328 return (a << 16) |
b;
345 return (
x << 1) > 0xff000000u;
352 return (f == f) && (
x == 0 ||
x == (1u << 31) || (f != 2.0f * f)) && !((
x << 1) > 0xff000000u);
361#if !defined(__KERNEL_METAL__)
364 return min(
max(a, mn), mx);
369 return min(
max(a, mn), mx);
374 return a + t * (
b - a);
383 else if (
x >= edge1) {
387 const float t = (
x - edge0) / (edge1 - edge0);
388 result = (3.0f - 2.0f * t) * (t * t);
395#if defined(__KERNEL_CUDA__)
398 return __saturatef(a);
400#elif !defined(__KERNEL_METAL__)
403 return clamp(a, 0.0f, 1.0f);
437 const float range =
max -
min;
438 return (range != 0.0f) ? value - (range *
floorf((value -
min) / range)) :
min;
443 return (
b != 0.0f) ?
fabsf(
fractf((a -
b) / (
b * 2.0f)) *
b * 2.0f -
b) : 0.0f;
450 return fminf(a,
b) - h * h * h * k * (1.0f / 6.0f);
457 return (f < 0.0f) ? -1.0f : 1.0f;
473 return (
x == 0.0f &&
y == 0.0f) ? 0.0f :
atan2f(
y,
x);
493 const float ff = f * f;
494 return (3.0f * ff - 2.0f * ff * f);
499 return (
x % m + m) % m;
504 return a + t * (
b - a);
509 return (
x - a) / (
b - a);
516 (((d + 3.0f * (
b - c) - a) *
x + (2.0f * a - 5.0f *
b + 4.0f * c - d)) *
x +
531#if defined(__KERNEL_METAL__)
532 return (f > 0.0f) ? rsqrt(f) : 0.0f;
534 return (f > 0.0f) ? 1.0f /
sqrtf(f) : 0.0f;
560 if (
fmodf(-
y, 2.0f) == 0.0f) {
582 return (
b != 0.0f) ? a /
b : 0.0f;
596 return (
b != 0.0f) ?
fmodf(a,
b) : 0.0f;
601 return (
b != 0.0f) ? a -
floorf(a /
b) *
b : 0.0f;
622 return s_sq > 0.0004f ? 1.0f -
safe_sqrtf(1.0f - s_sq) : 0.5f * s_sq;
647#ifdef __KERNEL_METAL__
652 const float _1_180 = 1.0f / 180.0f;
653 const float log2pi = 1.83787706641f;
654 const float logx =
log(
x);
655 return (log2pi - logx +
656 x * (logx * 2.0f +
log(
x *
sinh(1.0f /
x) + (_1_180 /
pow(
x, 6.0f))) - 2.0f)) *
678 return bits * (1.0f / (
float)0xFFFFFFFF);
681#if !defined(__KERNEL_GPU__)
682# if defined(__GNUC__)
685 return __builtin_popcount(
x);
692 i =
i - ((
i >> 1) & 0x55555555);
693 i = (
i & 0x33333333) + ((
i >> 2) & 0x33333333);
694 i = (((
i + (
i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
698#elif defined(__KERNEL_ONEAPI__)
699# define popcount(x) sycl::popcount(x)
700#elif defined(__KERNEL_HIP__)
702# define popcount(x) __popcll(x)
703#elif !defined(__KERNEL_METAL__)
704# define popcount(x) __popc(x)
709#if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
711#elif defined(__KERNEL_METAL__)
713#elif defined(__KERNEL_ONEAPI__)
718 unsigned long leading_zero = 0;
719 _BitScanReverse(&leading_zero,
x);
720 return (31 - leading_zero);
722 return __builtin_clz(
x);
729#if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
730 return (__ffs(
x) - 1);
731#elif defined(__KERNEL_METAL__)
733#elif defined(__KERNEL_ONEAPI__)
738 unsigned long ctz = 0;
739 _BitScanForward(&ctz,
x);
742 return __builtin_ctz(
x);
749#if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
751#elif defined(__KERNEL_METAL__)
752 return (
x != 0) ? ctz(
x) + 1 : 0;
757 return __builtin_ffs(
x);
774 if (
fabsf(a -
b) < abs_diff) {
778 if ((a < 0.0f) != (
b < 0.0f)) {
798# define __has_builtin(v) 0
805#if defined(__KERNEL_CUDA__)
807#elif defined(__KERNEL_METAL__)
808 return reverse_bits(
x);
809#elif defined(__aarch64__) || (defined(_M_ARM64) && !defined(_MSC_VER))
811 __asm__(
"rbit %w0, %w1" :
"=r"(
x) :
"r"(
x));
813#elif defined(__arm__) && ((__ARM_ARCH > 7) || __ARM_ARCH == 6 && __ARM_ARCH_ISA_THUMB >= 2)
816 __asm__(
"rbit %0, %1" :
"=r"(
x) :
"r"(
x));
818#elif __has_builtin(__builtin_bitreverse32)
819 return __builtin_bitreverse32(
x);
822 x = ((
x & 0x55555555) << 1) | ((
x & 0xAAAAAAAA) >> 1);
824 x = ((
x & 0x33333333) << 2) | ((
x & 0xCCCCCCCC) >> 2);
826 x = ((
x & 0x0F0F0F0F) << 4) | ((
x & 0xF0F0F0F0) >> 4);
829 return _byteswap_ulong(
x);
830# elif defined(__INTEL_COMPILER)
831 return (uint32_t)_bswap((
int)
x);
834 return __builtin_bswap32(
x);
846 const bool valid_linear = (a == 0.0f) && (
b != 0.0f);
849 const float discriminant =
sqr(
b) - 4.0f * a * c;
851 const bool valid_quadratic = (a != 0.0f) && (discriminant > -1e-5f);
853 if (valid_quadratic) {
859 const float r1 = temp / a;
860 const float r2 = c / temp;
866 return (valid_linear || valid_quadratic);
882 return value >=
min && value <=
max;
891template<
typename T1,
typename T2>
904 return {
max(first.min, second.min),
min(first.max, second.max)};
930 return {a.min +
b.min, a.max +
b.max};
944 return {
min(a.min,
b.min),
max(a.max,
b.max)};
950 return {
min(a.min,
v),
max(a.max,
v)};
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned long long int uint64_t
#define ccl_device_forceinline
#define ccl_device_inline
#define ccl_device_template_spec
#define ccl_device_inline_method
#define CCL_NAMESPACE_END
#define assert(assertion)
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline float floorfrac(const float x, ccl_private int *i)
ccl_device_inline bool isnan_safe(const float f)
ccl_device_inline float smoothstepf(const float f)
ccl_device float safe_floored_modulo(const float a, const float b)
ccl_device_inline int clamp(const int a, const int mn, const int mx)
ccl_device_inline uint as_uint(const int i)
ccl_device_inline Extrema< T > merge(const ccl_private Extrema< T > &a, const ccl_private Extrema< T > &b)
ccl_device_inline Interval< T1 > operator/=(ccl_private Interval< T1 > &interval, const T2 f)
ccl_device_inline uint prev_power_of_two(const uint x)
ccl_device_inline int ceil_to_int(const float f)
ccl_device float safe_asinf(const float a)
ccl_device_inline uint uint16_unpack_from_uint_1(const uint i)
ccl_device_inline float or_mask(const float x, const uint y)
ccl_device_inline float signf(const float f)
ccl_device float safe_powf(const float a, const float b)
ccl_device_inline T min4(const T &a, const T &b, const T &c, const T &d)
ccl_device_inline float pow22(const float a)
ccl_device_inline uint count_leading_zeros(const uint x)
ccl_device float bits_to_01(const uint bits)
ccl_device float safe_modulo(const float a, const float b)
ccl_device_inline float inversesqrtf(const float f)
ccl_device_inline float compatible_atan2(const float y, const float x)
ccl_device float compatible_powf(const float x, const float y)
ccl_device_inline Extrema< T > operator*(const Extrema< T > a, const T b)
ccl_device_inline float safe_sqrtf(const float f)
ccl_device_inline uint pointer_pack_to_uint_1(T *ptr)
ccl_device_inline float cubic_interp(const float a, const float b, float c, const float d, float x)
ccl_device_inline int floor_to_int(const float f)
ccl_device_inline float sin_from_cos(const float c)
ccl_device_inline uint32_t reverse_integer_bits(uint32_t x)
ccl_device_inline int power_of_2(const int a)
ccl_device_inline Extrema< T > operator+=(ccl_private Extrema< T > &a, const ccl_private Extrema< T > &b)
ccl_device_inline float sin_sqr_to_one_minus_cos(const float s_sq)
ccl_device float safe_acosf(const float a)
ccl_device_inline float compatible_signf(const float f)
ccl_device_inline float xor_mask(const float x, const uint y)
ccl_device_inline uint uint16_pack_to_uint(const uint a, const uint b)
ccl_device_inline int as_int(const uint i)
ccl_device_inline float nonzerof(const float f, const float eps)
ccl_device_inline bool solve_quadratic(const float a, const float b, const float c, ccl_private float &x1, ccl_private float &x2)
ccl_device_inline float smoothminf(const float a, const float b, float k)
ccl_device_inline uint pointer_pack_to_uint_0(T *ptr)
ccl_device_inline T * pointer_unpack_from_uint(const uint a, const uint b)
ccl_device_inline uint next_power_of_two(const uint x)
ccl_device_inline float inverse_lerp(const float a, const float b, const float x)
ccl_device_inline T max4(const T &a, const T &b, const T &c, const T &d)
ccl_device_inline float pow20(const float a)
ccl_device_inline int float_to_int(const float f)
ccl_device_inline uint find_first_set(const uint x)
ccl_device_inline Extrema< T > operator+(const ccl_private Extrema< T > &a, const ccl_private Extrema< T > &b)
ccl_device_inline T make_zero()
ccl_device float safe_divide(const float a, const float b)
ccl_device_inline Interval< T > intervals_intersection(const ccl_private Interval< T > &first, const ccl_private Interval< T > &second)
ccl_device_inline float ensure_finite(const float v)
ccl_device_inline float interp(const float a, const float b, const float t)
ccl_device_inline uint uint16_unpack_from_uint_0(const uint i)
ccl_device_inline float smoothstep(const float edge0, const float edge1, const float x)
ccl_device_inline uint popcount(const uint x)
ccl_device_inline float wrapf(const float value, const float max, const float min)
ccl_device_inline bool compare_floats(const float a, const float b, float abs_diff, const int ulp_diff)
ccl_device float safe_logf(const float a, const float b)
ccl_device_inline bool isfinite_safe(const float f)
ccl_device_inline float one_minus_cos(const float angle)
ccl_device_inline float beta(const float x, const float y)
ccl_device_inline float cos_from_sin(const float s)
ccl_device_inline float pingpongf(const float a, const float b)
ccl_device_inline uint count_trailing_zeros(const uint x)
ccl_device_inline_method Extrema(T value)
ccl_device_inline_method Extrema(T min_, T max_)
ccl_device_inline_method T range() const
ccl_device_inline_method T length() const
ccl_device_inline_method bool contains(T value) const
ccl_device_inline_method bool is_empty() const