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__)
313 return ((
uint64_t)ptr) & 0xFFFFFFFF;
318 return (((
uint64_t)ptr) >> 32) & 0xFFFFFFFF;
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;
556 if (
fmodf(-
y, 2.0f) == 0.0f)
578 return (
b != 0.0f) ? a /
b : 0.0f;
592 return (
b != 0.0f) ?
fmodf(a,
b) : 0.0f;
597 return (
b != 0.0f) ? a -
floorf(a /
b) *
b : 0.0f;
618 return s_sq > 0.0004f ? 1.0f -
safe_sqrtf(1.0f - s_sq) : 0.5f * s_sq;
637#ifdef __KERNEL_METAL__
642 const float _1_180 = 1.0f / 180.0f;
643 const float log2pi = 1.83787706641f;
644 const float logx =
log(
x);
645 return (log2pi - logx +
646 x * (logx * 2.0f +
log(
x *
sinh(1.0f /
x) + (_1_180 /
pow(
x, 6.0f))) - 2.0f)) *
663 return bits * (1.0f / (float)0xFFFFFFFF);
666#if !defined(__KERNEL_GPU__)
667# if defined(__GNUC__)
670 return __builtin_popcount(
x);
677 i =
i - ((
i >> 1) & 0x55555555);
678 i = (
i & 0x33333333) + ((
i >> 2) & 0x33333333);
679 i = (((
i + (
i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
683#elif defined(__KERNEL_ONEAPI__)
684# define popcount(x) sycl::popcount(x)
685#elif defined(__KERNEL_HIP__)
687# define popcount(x) __popcll(x)
688#elif !defined(__KERNEL_METAL__)
689# define popcount(x) __popc(x)
694#if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
696#elif defined(__KERNEL_METAL__)
698#elif defined(__KERNEL_ONEAPI__)
703 unsigned long leading_zero = 0;
704 _BitScanReverse(&leading_zero,
x);
705 return (31 - leading_zero);
707 return __builtin_clz(
x);
714#if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
715 return (__ffs(
x) - 1);
716#elif defined(__KERNEL_METAL__)
718#elif defined(__KERNEL_ONEAPI__)
723 unsigned long ctz = 0;
724 _BitScanForward(&ctz,
x);
727 return __builtin_ctz(
x);
734#if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
736#elif defined(__KERNEL_METAL__)
737 return (
x != 0) ? ctz(
x) + 1 : 0;
742 return __builtin_ffs(
x);
759 if (
fabsf(a -
b) < abs_diff) {
763 if ((a < 0.0f) != (
b < 0.0f)) {
783# define __has_builtin(v) 0
790#if defined(__KERNEL_CUDA__)
792#elif defined(__KERNEL_METAL__)
793 return reverse_bits(
x);
794#elif defined(__aarch64__) || (defined(_M_ARM64) && !defined(_MSC_VER))
796 __asm__(
"rbit %w0, %w1" :
"=r"(
x) :
"r"(
x));
798#elif defined(__arm__) && ((__ARM_ARCH > 7) || __ARM_ARCH == 6 && __ARM_ARCH_ISA_THUMB >= 2)
801 __asm__(
"rbit %0, %1" :
"=r"(
x) :
"r"(
x));
803#elif __has_builtin(__builtin_bitreverse32)
804 return __builtin_bitreverse32(
x);
807 x = ((
x & 0x55555555) << 1) | ((
x & 0xAAAAAAAA) >> 1);
809 x = ((
x & 0x33333333) << 2) | ((
x & 0xCCCCCCCC) >> 2);
811 x = ((
x & 0x0F0F0F0F) << 4) | ((
x & 0xF0F0F0F0) >> 4);
814 return _byteswap_ulong(
x);
815# elif defined(__INTEL_COMPILER)
816 return (uint32_t)_bswap((
int)
x);
819 return __builtin_bswap32(
x);
831 const bool valid_linear = (a == 0.0f) && (
b != 0.0f);
834 const float discriminant =
sqr(
b) - 4.0f * a * c;
836 const bool valid_quadratic = (a != 0.0f) && (discriminant > -1e-5f);
838 if (valid_quadratic) {
844 const float r1 = temp / a;
845 const float r2 = c / temp;
851 return (valid_linear || valid_quadratic);
867 return value >=
min && value <=
max;
876template<
typename T1,
typename T2>
889 return {
max(first.min, second.min),
min(first.max, second.max)};
MINLINE float signf(float f)
MINLINE float safe_sqrtf(float a)
MINLINE float safe_logf(float a, float base)
MINLINE float safe_acosf(float a)
MINLINE float safe_powf(float base, float exponent)
MINLINE float safe_divide(float a, float b)
MINLINE float safe_asinf(float a)
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned long long int uint64_t
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
#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
constexpr T clamp(T, U, U) 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_inline float sqr(const float a)
ccl_device_inline uint as_uint(const int i)
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_inline uint uint16_unpack_from_uint_1(const uint i)
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_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 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 float sin_sqr_to_one_minus_cos(const float s_sq)
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 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 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 uint popcount(const uint x)
ccl_device_inline float xor_signmask(const float x, const int y)
ccl_device_inline bool compare_floats(const float a, const float b, float abs_diff, const int ulp_diff)
ccl_device_inline T make_zero()
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 uint count_trailing_zeros(const uint x)
MINLINE float fractf(float a)
MINLINE float smoothminf(float a, float b, float c)
MINLINE float pingpongf(float value, float scale)
MINLINE float smoothstep(float edge0, float edge1, float x)
MINLINE float compatible_signf(float f)
MINLINE float wrapf(float value, float max, float min)
float safe_floored_modulo(float a, float b)
float safe_modulo(float a, float b)
ccl_device_inline_method T length() const
ccl_device_inline_method bool contains(T value) const
ccl_device_inline_method bool is_empty() const