16 return float4(_mm_setzero_ps());
35 return int4(_mm_castps_si128(a));
42#if !defined(__KERNEL_METAL__)
46 const __m128
mask = _mm_castsi128_ps(_mm_set1_epi32(0x80000000));
56 return float4(_mm_mul_ps(a.m128,
b.m128));
64# if defined(__KERNEL_SSE__)
79 return float4(_mm_div_ps(_mm_set1_ps(f), a.m128));
87 return a * (1.0f / f);
93 return float4(_mm_div_ps(a.m128,
b.m128));
101# ifdef __KERNEL_SSE__
102 return float4(_mm_add_ps(a.m128,
b.m128));
115# ifdef __KERNEL_SSE__
116 return float4(_mm_sub_ps(a.m128,
b.m128));
159# ifdef __KERNEL_SSE__
160 return int4(_mm_castps_si128(_mm_cmplt_ps(a.m128,
b.m128)));
168# ifdef __KERNEL_SSE__
169 return int4(_mm_castps_si128(_mm_cmpge_ps(a.m128,
b.m128)));
177# ifdef __KERNEL_SSE__
178 return int4(_mm_castps_si128(_mm_cmpgt_ps(a.m128,
b.m128)));
186# ifdef __KERNEL_SSE__
187 return int4(_mm_castps_si128(_mm_cmple_ps(a.m128,
b.m128)));
195# ifdef __KERNEL_SSE__
196 return (_mm_movemask_ps(_mm_cmpeq_ps(a.m128,
b.m128)) & 15) == 15;
198 return (a.
x ==
b.x && a.
y ==
b.y && a.
z ==
b.z && a.
w ==
b.w);
204# ifdef __KERNEL_SSE__
205 return float4(_mm_xor_ps(a.m128,
b.m128));
216# ifdef __KERNEL_SSE__
217 return float4(_mm_min_ps(a.m128,
b.m128));
225# ifdef __KERNEL_SSE__
226 return float4(_mm_max_ps(a.m128,
b.m128));
234 return min(
max(a, mn), mx);
241# ifdef __KERNEL_NEON__
242 return float4(vfmaq_f32(c, a,
b));
243# elif defined(__KERNEL_AVX2__)
244 return float4(_mm_fmadd_ps(a,
b, c));
256# ifdef __KERNEL_NEON__
257 return float4(vfmaq_f32(vnegq_f32(c), a,
b));
258# elif defined(__KERNEL_AVX2__)
259 return float4(_mm_fmsub_ps(a,
b, c));
269template<
size_t i0, const
size_t i1, const
size_t i2, const
size_t i3>
272# ifdef __KERNEL_NEON__
273 return float4(shuffle_neon<float32x4_t, i0, i1, i2, i3>(a.m128));
276 _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(a), _MM_SHUFFLE(i3, i2, i1, i0))));
282 return float4(_mm_movelh_ps(a, a));
287 return float4(_mm_movehl_ps(a, a));
290# ifdef __KERNEL_SSE3__
293 return float4(_mm_moveldup_ps(a));
298 return float4(_mm_movehdup_ps(a));
302template<
size_t i0, const
size_t i1, const
size_t i2, const
size_t i3>
305# ifdef __KERNEL_NEON__
306 return float4(shuffle_neon<float32x4_t, i0, i1, i2, i3>(a,
b));
308 return float4(_mm_shuffle_ps(a,
b, _MM_SHUFFLE(i3, i2, i1, i0)));
314 return shuffle<i0, i0, i0, i0>(a);
318# ifdef __KERNEL_NEON__
319 return float4(shuffle_neon<float32x4_t, i0, i0, i0, i0>(a,
b));
321 return float4(_mm_shuffle_ps(a,
b, _MM_SHUFFLE(i0, i0, i0, i0)));
327 return float4(_mm_movelh_ps(a,
b));
332 return float4(_mm_movehl_ps(
b, a));
337 return _mm_cvtss_f32(shuffle<i, i, i, i>(a));
341 return _mm_cvtss_f32(a);
347#if defined(__KERNEL_SSE__)
348# if defined(__KERNEL_NEON__)
349 return vaddvq_f32(a);
350# elif defined(__KERNEL_SSE3__)
351 float4 h(_mm_hadd_ps(a.m128, a.m128));
352 return _mm_cvtss_f32(_mm_hadd_ps(h.m128, h.m128));
354 float4 h(shuffle<1, 0, 3, 2>(a) + a);
355 return _mm_cvtss_f32(shuffle<2, 3, 0, 1>(h) + h);
358 return a.
x + a.
y + a.
z + a.
w;
364#if defined(__KERNEL_SSE__)
365# if defined(__KERNEL_NEON__)
366 return vminvq_f32(a);
368 float4 h =
min(shuffle<1, 0, 3, 2>(a), a);
369 return _mm_cvtss_f32(
min(shuffle<2, 3, 0, 1>(h), h));
378#if defined(__KERNEL_SSE__)
379# if defined(__KERNEL_NEON__)
380 return vmaxvq_f32(a);
382 float4 h =
max(shuffle<1, 0, 3, 2>(a), a);
383 return _mm_cvtss_f32(
max(shuffle<2, 3, 0, 1>(h), h));
390#if !defined(__KERNEL_METAL__)
393# if defined(__KERNEL_SSE42__) && defined(__KERNEL_SSE__)
394# if defined(__KERNEL_NEON__)
395 const __m128 t = vmulq_f32(a,
b);
396 return vaddvq_f32(t);
398 return _mm_cvtss_f32(_mm_dp_ps(a,
b, 0xFF));
401 return (a.
x *
b.x + a.
y *
b.y) + (a.
z *
b.z + a.
w *
b.w);
421#if !defined(__KERNEL_METAL__)
429# ifdef __KERNEL_SSE__
430 return float4(_mm_sqrt_ps(a.m128));
438# ifdef __KERNEL_SSE__
439 return (shuffle<1, 2, 0, 0>(a) * shuffle<2, 0, 1, 0>(
b)) -
440 (shuffle<2, 0, 1, 0>(a) * shuffle<1, 2, 0, 0>(
b));
448# ifdef __KERNEL_SSE__
451 return (a.
x == 0.0f && a.
y == 0.0f && a.
z == 0.0f && a.
w == 0.0f);
467 const float t =
len(a);
468 return (t != 0.0f) ? a / t : a;
473# if defined(__KERNEL_SSE__)
474# if defined(__KERNEL_NEON__)
475 return float4(vabsq_f32(a));
477 return float4(_mm_and_ps(a.m128, _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff))));
490# if defined(__KERNEL_NEON__)
494 const float32x4_t iquot = vrndq_f32(a /
b);
495 return float4(vsubq_f32(a, vmulq_f32(iquot, vdupq_n_f32(
b))));
496# elif defined(__KERNEL_SSE42__) && defined(__KERNEL_SSE__)
497 const __m128 iquot = _mm_round_ps(a /
b, _MM_FROUND_TRUNC);
498 return float4(_mm_sub_ps(a, _mm_mul_ps(iquot, _mm_set1_ps(
b))));
506# ifdef __KERNEL_SSE__
507# if defined(__KERNEL_NEON__)
508 return float4(vrndmq_f32(a));
510 return float4(_mm_floor_ps(a));
519# ifdef __KERNEL_SSE__
521 *i =
int4(_mm_cvttps_epi32(f.m128));
552#if defined(__KERNEL_METAL__)
559template<
class MaskType>
562#if defined(__KERNEL_METAL__)
564#elif defined(__KERNEL_SSE__)
565# ifdef __KERNEL_SSE42__
566 return float4(_mm_blendv_ps(
b.m128, a.m128, _mm_castsi128_ps(
mask.m128)));
569 _mm_or_ps(_mm_and_ps(_mm_castsi128_ps(
mask), a), _mm_andnot_ps(_mm_castsi128_ps(
mask),
b)));
583#ifndef __KERNEL_GPU__
587# ifdef __KERNEL_SSE__
588 return float4(_mm_loadu_ps(v));
604 (
b.y != 0.0f) ? a.
y /
b.y : 0.0f,
605 (
b.z != 0.0f) ? a.
z /
b.z : 0.0f,
606 (
b.w != 0.0f) ? a.
w /
b.w : 0.0f);
640 return a + t * (
b - a);
643#if !defined(__KERNEL_METAL__) && !defined(__KERNEL_ONEAPI__)
647# ifdef __KERNEL_SSE__
648 return int4(_mm_castps_si128(f.m128));
657# ifdef __KERNEL_SSE__
658 return float4(_mm_castsi128_ps(i.m128));
__forceinline float extract(const int4 &b)
#define ccl_device_inline
#define ccl_device_template_spec
#define CCL_NAMESPACE_END
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
float distance(float, float) RET
bool all(VecOp< bool, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
constexpr T clamp(T, U, U) RET
float safe_divide(float a, float b)
float reduce_add(float2 a)
float reduce_min(float2 a)
float reduce_max(float2 a)
VecT safe_normalize(VecT vector)
__forceinline LightTreeMeasure operator+(const LightTreeMeasure &a, const LightTreeMeasure &b)
ccl_device_inline float floorfrac(const float x, ccl_private int *i)
ccl_device_inline Interval< T1 > operator/=(ccl_private Interval< T1 > &interval, const T2 f)
ccl_device_inline Extrema< T > operator*(const Extrema< T > a, const T b)
ccl_device_inline Extrema< T > operator+=(ccl_private Extrema< T > &a, const ccl_private Extrema< T > &b)
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 bool isfinite_safe(const float f)
ccl_device_inline T make_zero()
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline dual1 len_squared(const ccl_private dual< T > &a)
ccl_device_inline dual< T > operator/(const dual< T > a, T b)
ccl_device_inline dual< T1 > operator-(const dual< T1 > a, T2 b)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
ccl_device_inline bool operator<(const ccl_private dual1 &a, const float b)
CCL_NAMESPACE_BEGIN ccl_device_inline float madd(const float a, const float b, const float c)
ccl_device_inline float2 power(const float2 v, const float e)
ccl_device_inline float2 fmod(const float2 a, const float b)
ccl_device_inline bool isequal(const float2 a, const float2 b)
ccl_device_inline bool operator==(const float2 a, const float2 b)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
ccl_device_inline int2 operator>=(const float2 a, const float2 b)
ccl_device_inline float2 operator*=(float2 &a, const float2 b)
ccl_device_inline int3 operator>(const float3 a, const float3 b)
ccl_device_inline float3 operator-=(float3 &a, const float3 b)
ccl_device_inline float4 msub(const float4 a, const float4 b, const float4 c)
ccl_device_inline int4 __float4_as_int4(const float4 f)
ccl_device_inline float4 one_float4()
ccl_device_inline int4 operator<=(const float4 a, const float4 b)
ccl_device_inline int4 cast(const float4 a)
ccl_device_inline float4 operator^(const float4 a, const float4 b)
ccl_device_inline float4 __int4_as_float4(const int4 i)
ccl_device_inline float4 load_float4(const ccl_private float *v)
ccl_device_inline void copy_v4_v4(ccl_private float *r, const float4 val)
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()