Blender V5.3
math_int4.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2013 Intel Corporation
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0 */
5
6#pragma once
7
8#include "util/types_float4.h"
9#include "util/types_int4.h"
10
12
13#if !defined(__KERNEL_METAL__)
15{
16# ifdef __KERNEL_SSE__
17 return int4(_mm_add_epi32(a.m128, b.m128));
18# else
19 return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
20# endif
21}
22
24{
25 return a = a + b;
26}
27
29{
30# ifdef __KERNEL_SSE__
31 return int4(_mm_sub_epi32(a.m128, b.m128));
32# else
33 return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
34# endif
35}
36
38{
39 return a = a - b;
40}
41
43{
44 return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
45}
46
48{
49# ifdef __KERNEL_SSE__
50 return int4(_mm_srai_epi32(a.m128, i));
51# else
52 return make_int4(a.x >> i, a.y >> i, a.z >> i, a.w >> i);
53# endif
54}
55
57{
58# ifdef __KERNEL_SSE__
59 return int4(_mm_slli_epi32(a.m128, i));
60# else
61 return make_int4(a.x << i, a.y << i, a.z << i, a.w << i);
62# endif
63}
64
66{
67# ifdef __KERNEL_SSE__
68 return int4(_mm_cmplt_epi32(a.m128, b.m128));
69# else
70 return make_int4(a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w);
71# endif
72}
73
75{
76 return a < make_int4(b);
77}
78
80{
81 return b < a;
82}
83
85{
86# ifdef __KERNEL_SSE__
87 return int4(_mm_cmpeq_epi32(a.m128, b.m128));
88# else
89 return make_int4(a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w);
90# endif
91}
92
94{
95 return a == make_int4(b);
96}
97
99{
100# ifdef __KERNEL_SSE__
101 return int4(_mm_xor_si128(_mm_set1_epi32(0xffffffff), _mm_cmplt_epi32(a.m128, b.m128)));
102# else
103 return make_int4(a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w);
104# endif
105}
106
108{
109 return a >= make_int4(b);
110}
111
113{
114# ifdef __KERNEL_SSE__
115 return int4(_mm_and_si128(a.m128, b.m128));
116# else
117 return make_int4(a.x & b.x, a.y & b.y, a.z & b.z, a.w & b.w);
118# endif
119}
120
122{
123# ifdef __KERNEL_SSE__
124 return int4(_mm_or_si128(a.m128, b.m128));
125# else
126 return make_int4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w);
127# endif
128}
129
131{
132# ifdef __KERNEL_SSE__
133 return int4(_mm_xor_si128(a.m128, b.m128));
134# else
135 return make_int4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
136# endif
137}
138
140{
141 return make_int4(a) & b;
142}
143
145{
146 return a & make_int4(b);
147}
148
150{
151 return make_int4(a) | b;
152}
153
155{
156 return a | make_int4(b);
157}
158
160{
161 return make_int4(a) ^ b;
162}
163
165{
166 return a ^ make_int4(b);
167}
168
170{
171 return a = a & b;
172}
174{
175 return a = a & b;
176}
177
179{
180 return a = a | b;
181}
183{
184 return a = a | b;
185}
186
188{
189 return a = a ^ b;
190}
192{
193 return a = a ^ b;
194}
195
197{
198 return a = a << b;
199}
201{
202 return a = a >> b;
203}
204
205ccl_device_inline int4 srl(const int4 a, const int i)
206{
207# ifdef __KERNEL_SSE__
208 return int4(_mm_srli_epi32(a.m128, i));
209# else
210 return make_int4(uint32_t(a.x) >> i, uint32_t(a.y) >> i, uint32_t(a.z) >> i, uint32_t(a.w) >> i);
211# endif
212}
213
215{
216# if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE42__)
217 return int4(_mm_min_epi32(a.m128, b.m128));
218# else
219 return make_int4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
220# endif
221}
222
224{
225# if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE42__)
226 return int4(_mm_max_epi32(a.m128, b.m128));
227# else
228 return make_int4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), max(a.w, b.w));
229# endif
230}
231
232ccl_device_inline int4 clamp(const int4 a, const int4 mn, const int4 mx)
233{
234 return min(max(a, mn), mx);
235}
236
238{
239# ifdef __KERNEL_SSE__
240 return int4(_mm_or_si128(_mm_and_si128(mask, a), _mm_andnot_si128(mask, b)));
241# else
242 return make_int4(
243 (mask.x) ? a.x : b.x, (mask.y) ? a.y : b.y, (mask.z) ? a.z : b.z, (mask.w) ? a.w : b.w);
244# endif
245}
246
248{
249# ifdef __KERNEL_SSE__
250 return int4(_mm_loadu_si128((__m128i *)v));
251# else
252 return make_int4(v[0], v[1], v[2], v[3]);
253# endif
254}
255#endif /* __KERNEL_METAL__ */
256
258{
259#ifdef __KERNEL_SSE__
260 return float4(_mm_castsi128_ps(a));
261#else
262 return make_float4(
264#endif
265}
266
267#ifdef __KERNEL_SSE__
268ccl_device_forceinline int4 andnot(const int4 a, const int4 b)
269{
270 return int4(_mm_andnot_si128(a.m128, b.m128));
271}
272
273template<size_t i0, const size_t i1, const size_t i2, const size_t i3>
274ccl_device_forceinline int4 shuffle(const int4 a)
275{
276# ifdef __KERNEL_NEON__
277 int32x4_t result = shuffle_neon<int32x4_t, i0, i1, i2, i3>(vreinterpretq_s32_m128i(a));
278 return int4(vreinterpretq_m128i_s32(result));
279# else
280 return int4(_mm_shuffle_epi32(a, _MM_SHUFFLE(i3, i2, i1, i0)));
281# endif
282}
283
284template<size_t i0, const size_t i1, const size_t i2, const size_t i3>
285ccl_device_forceinline int4 shuffle(const int4 a, const int4 b)
286{
287# ifdef __KERNEL_NEON__
288 int32x4_t result = shuffle_neon<int32x4_t, i0, i1, i2, i3>(vreinterpretq_s32_m128i(a),
289 vreinterpretq_s32_m128i(b));
290 return int4(vreinterpretq_m128i_s32(result));
291# else
292 return int4(_mm_castps_si128(
293 _mm_shuffle_ps(_mm_castsi128_ps(a), _mm_castsi128_ps(b), _MM_SHUFFLE(i3, i2, i1, i0))));
294# endif
295}
296
297template<size_t i0> ccl_device_forceinline int4 shuffle(const int4 b)
298{
299 return shuffle<i0, i0, i0, i0>(b);
300}
301#endif
302
btScalar max
#define ccl_device_forceinline
#define ccl_device_inline
#define CCL_NAMESPACE_END
std::ostream & operator<<(std::ostream &os, DeviceKernel kernel)
#define __int_as_float(x)
ccl_device_forceinline int4 make_int4(const int x, const int y, const int z, const int w)
#define select(A, B, C)
constexpr T clamp(T, U, U) RET
__forceinline LightTreeMeasure operator+(const LightTreeMeasure &a, const LightTreeMeasure &b)
ccl_device_inline Extrema< T > operator*(const Extrema< T > a, const T b)
Definition math_base.h:967
ccl_device_inline Extrema< T > operator+=(ccl_private Extrema< T > &a, const ccl_private Extrema< T > &b)
Definition math_base.h:980
ccl_device_inline dual< T1 > operator-(const dual< T1 > a, T2 b)
Definition math_dual.h:113
ccl_device_inline bool operator<(const ccl_private dual1 &a, const float b)
Definition math_dual.h:45
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 int3 operator>(const float3 a, const float3 b)
ccl_device_inline float3 operator-=(float3 &a, const float3 b)
ccl_device_inline int4 cast(const float4 a)
Definition math_float4.h:32
ccl_device_inline float4 operator^(const float4 a, const float4 b)
ccl_device_inline int2 operator&(const int2 a, const int2 b)
Definition math_int2.h:48
ccl_device_inline int2 operator>>(const int2 a, const int i)
Definition math_int2.h:43
ccl_device_inline int4 load_int4(const int *v)
Definition math_int4.h:247
ccl_device_inline int4 & operator|=(int4 &a, const int4 b)
Definition math_int4.h:178
ccl_device_inline int4 & operator&=(int4 &a, const int4 b)
Definition math_int4.h:169
ccl_device_inline int4 operator|(const int4 a, const int4 b)
Definition math_int4.h:121
ccl_device_inline int4 & operator>>=(int4 &a, const int32_t b)
Definition math_int4.h:200
ccl_device_inline int4 & operator<<=(int4 &a, const int32_t b)
Definition math_int4.h:196
ccl_device_inline int4 srl(const int4 a, const int i)
Definition math_int4.h:205
ccl_device_inline int4 & operator^=(int4 &a, const int4 b)
Definition math_int4.h:187
#define make_float4
#define min(a, b)
Definition sort.cc:38