Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
UVec4.inl
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
6
8{
9#if defined(JPH_USE_SSE)
10 mValue = _mm_set_epi32(int(inW), int(inZ), int(inY), int(inX));
11#elif defined(JPH_USE_NEON)
12 uint32x2_t xy = vcreate_u32(static_cast<uint64>(inX) | (static_cast<uint64>(inY) << 32));
13 uint32x2_t zw = vcreate_u32(static_cast<uint64>(inZ) | (static_cast<uint64>(inW) << 32));
14 mValue = vcombine_u32(xy, zw);
15#elif defined(JPH_USE_RVV)
16 vuint32m1_t v = __riscv_vmv_v_x_u32m1(inW, 4);
17 v = __riscv_vslide1up_vx_u32m1(v, inZ, 4);
18 v = __riscv_vslide1up_vx_u32m1(v, inY, 4);
19 v = __riscv_vslide1up_vx_u32m1(v, inX, 4);
20 __riscv_vse32_v_u32m1(mU32, v, 4);
21#elif defined(JPH_USE_VSX)
22 mValue = Type { inX, inY, inZ, inW };
23#else
24 mU32[0] = inX;
25 mU32[1] = inY;
26 mU32[2] = inZ;
27 mU32[3] = inW;
28#endif
29}
30
32{
33 return sEquals(*this, inV2).TestAllTrue();
34}
35
36template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW>
38{
39 static_assert(SwizzleX <= 3, "SwizzleX template parameter out of range");
40 static_assert(SwizzleY <= 3, "SwizzleY template parameter out of range");
41 static_assert(SwizzleZ <= 3, "SwizzleZ template parameter out of range");
42 static_assert(SwizzleW <= 3, "SwizzleW template parameter out of range");
43
44#if defined(JPH_USE_SSE)
45 return _mm_shuffle_epi32(mValue, _MM_SHUFFLE(SwizzleW, SwizzleZ, SwizzleY, SwizzleX));
46#elif defined(JPH_USE_NEON)
47 return JPH_NEON_SHUFFLE_U32x4(mValue, mValue, SwizzleX, SwizzleY, SwizzleZ, SwizzleW);
48#elif defined(JPH_USE_RVV)
49 UVec4 v;
50 const vuint32m1_t data = __riscv_vle32_v_u32m1(mU32, 4);
51 const uint32 stored_indices[4] = { SwizzleX, SwizzleY, SwizzleZ, SwizzleW };
52 const vuint32m1_t index = __riscv_vle32_v_u32m1(stored_indices, 4);
53 const vuint32m1_t swizzled = __riscv_vrgather_vv_u32m1(data, index, 4);
54 __riscv_vse32_v_u32m1(v.mU32, swizzled, 4);
55 return v;
56#elif defined(JPH_USE_VSX)
57 return __builtin_shufflevector(mValue, mValue, SwizzleX, SwizzleY, SwizzleZ, SwizzleW);
58#else
59 return UVec4(mU32[SwizzleX], mU32[SwizzleY], mU32[SwizzleZ], mU32[SwizzleW]);
60#endif
61}
62
64{
65#if defined(JPH_USE_SSE)
66 return _mm_setzero_si128();
67#elif defined(JPH_USE_NEON)
68 return vdupq_n_u32(0);
69#elif defined(JPH_USE_RVV)
70 UVec4 v;
71 const vuint32m1_t zero_vec = __riscv_vmv_v_x_u32m1(0, 4);
72 __riscv_vse32_v_u32m1(v.mU32, zero_vec, 4);
73 return v;
74#elif defined(JPH_USE_VSX)
75 return vec_splats(uint32(0));
76#else
77 return UVec4(0, 0, 0, 0);
78#endif
79}
80
82{
83#if defined(JPH_USE_SSE)
84 return _mm_set1_epi32(int(inV));
85#elif defined(JPH_USE_NEON)
86 return vdupq_n_u32(inV);
87#elif defined(JPH_USE_RVV)
88 UVec4 vec;
89 const vuint32m1_t v = __riscv_vmv_v_x_u32m1(inV, 4);
90 __riscv_vse32_v_u32m1(vec.mU32, v, 4);
91 return vec;
92#elif defined(JPH_USE_VSX)
93 return vec_splats(inV);
94#else
95 return UVec4(inV, inV, inV, inV);
96#endif
97}
98
100{
101#if defined(JPH_USE_SSE)
102 return _mm_castps_si128(_mm_load_ss(reinterpret_cast<const float*>(inV)));
103#elif defined(JPH_USE_NEON)
104 return vsetq_lane_u32(*inV, vdupq_n_u32(0), 0);
105#elif defined(JPH_USE_VSX)
106 return Type { *inV, 0, 0, 0 };
107#else
108 return UVec4(*inV, 0, 0, 0);
109#endif
110}
111
113{
114#if defined(JPH_USE_SSE)
115 return _mm_loadu_si128(reinterpret_cast<const __m128i *>(inV));
116#elif defined(JPH_USE_NEON)
117 return vld1q_u32(inV);
118#elif defined(JPH_USE_RVV)
119 UVec4 vector;
120 const vuint32m1_t v = __riscv_vle32_v_u32m1(inV, 4);
121 __riscv_vse32_v_u32m1(vector.mU32, v, 4);
122 return vector;
123#elif defined(JPH_USE_VSX)
124 return vec_xl(0, inV);
125#else
126 return UVec4(inV[0], inV[1], inV[2], inV[3]);
127#endif
128}
129
131{
132#if defined(JPH_USE_SSE)
133 return _mm_load_si128(reinterpret_cast<const __m128i *>(inV));
134#elif defined(JPH_USE_NEON)
135 return vld1q_u32(inV); // ARM doesn't make distinction between aligned or not
136#elif defined(JPH_USE_RVV)
137 UVec4 vector;
138 const vuint32m1_t v = __riscv_vle32_v_u32m1(inV, 4);
139 __riscv_vse32_v_u32m1(vector.mU32, v, 4);
140 return vector;
141#elif defined(JPH_USE_VSX)
142 return vec_ld(0, inV);
143#else
144 return UVec4(inV[0], inV[1], inV[2], inV[3]);
145#endif
146}
147
148template <const int Scale>
149UVec4 UVec4::sGatherInt4(const uint32 *inBase, UVec4Arg inOffsets)
150{
151#ifdef JPH_USE_AVX2
152 return _mm_i32gather_epi32(reinterpret_cast<const int *>(inBase), inOffsets.mValue, Scale);
153#elif defined(JPH_USE_RVV)
154 UVec4 v;
155 const vuint32m1_t offsets = __riscv_vle32_v_u32m1(inOffsets.mU32, 4);
156 const vuint32m1_t scaled_offsets = __riscv_vmul_vx_u32m1(offsets, Scale, 4);
157 const vuint32m1_t gathered = __riscv_vluxei32_v_u32m1(inBase, scaled_offsets, 4);
158 __riscv_vse32_v_u32m1(v.mU32, gathered, 4);
159 return v;
160#else
161 const uint8 *base = reinterpret_cast<const uint8 *>(inBase);
162 uint32 x = *reinterpret_cast<const uint32 *>(base + inOffsets.GetX() * Scale);
163 uint32 y = *reinterpret_cast<const uint32 *>(base + inOffsets.GetY() * Scale);
164 uint32 z = *reinterpret_cast<const uint32 *>(base + inOffsets.GetZ() * Scale);
165 uint32 w = *reinterpret_cast<const uint32 *>(base + inOffsets.GetW() * Scale);
166 return UVec4(x, y, z, w);
167#endif
168}
169
171{
172#if defined(JPH_USE_SSE4_1)
173 return _mm_min_epu32(inV1.mValue, inV2.mValue);
174#elif defined(JPH_USE_NEON)
175 return vminq_u32(inV1.mValue, inV2.mValue);
176#elif defined(JPH_USE_RVV)
177 UVec4 res;
178 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(inV1.mU32, 4);
179 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
180 const vuint32m1_t min = __riscv_vminu_vv_u32m1(v1, v2, 4);
181 __riscv_vse32_v_u32m1(res.mU32, min, 4);
182 return res;
183#elif defined(JPH_USE_VSX)
184 return vec_min(inV1.mValue, inV2.mValue);
185#else
186 UVec4 result;
187 for (int i = 0; i < 4; i++)
188 result.mU32[i] = min(inV1.mU32[i], inV2.mU32[i]);
189 return result;
190#endif
191}
192
194{
195#if defined(JPH_USE_SSE4_1)
196 return _mm_max_epu32(inV1.mValue, inV2.mValue);
197#elif defined(JPH_USE_NEON)
198 return vmaxq_u32(inV1.mValue, inV2.mValue);
199#elif defined(JPH_USE_RVV)
200 UVec4 res;
201 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(inV1.mU32, 4);
202 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
203 const vuint32m1_t max = __riscv_vmaxu_vv_u32m1(v1, v2, 4);
204 __riscv_vse32_v_u32m1(res.mU32, max, 4);
205 return res;
206#elif defined(JPH_USE_VSX)
207 return vec_max(inV1.mValue, inV2.mValue);
208#else
209 UVec4 result;
210 for (int i = 0; i < 4; i++)
211 result.mU32[i] = max(inV1.mU32[i], inV2.mU32[i]);
212 return result;
213#endif
214}
215
217{
218#if defined(JPH_USE_SSE)
219 return _mm_cmpeq_epi32(inV1.mValue, inV2.mValue);
220#elif defined(JPH_USE_NEON)
221 return vceqq_u32(inV1.mValue, inV2.mValue);
222#elif defined(JPH_USE_RVV)
223 UVec4 res;
224 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(inV1.mU32, 4);
225 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
226 const vbool32_t mask = __riscv_vmseq_vv_u32m1_b32(v1, v2, 4);
227 const vuint32m1_t zeros = __riscv_vmv_v_x_u32m1(0x0, 4);
228 const vuint32m1_t merged = __riscv_vmerge_vxm_u32m1(zeros, 0xFFFFFFFF, mask, 4);
229 __riscv_vse32_v_u32m1(res.mU32, merged, 4);
230 return res;
231#elif defined(JPH_USE_VSX)
232 return (Type)vec_cmpeq(inV1.mValue, inV2.mValue);
233#else
234 return UVec4(inV1.mU32[0] == inV2.mU32[0]? 0xffffffffu : 0,
235 inV1.mU32[1] == inV2.mU32[1]? 0xffffffffu : 0,
236 inV1.mU32[2] == inV2.mU32[2]? 0xffffffffu : 0,
237 inV1.mU32[3] == inV2.mU32[3]? 0xffffffffu : 0);
238#endif
239}
240
241UVec4 UVec4::sSelect(UVec4Arg inNotSet, UVec4Arg inSet, UVec4Arg inControl)
242{
243#if defined(JPH_USE_SSE4_1) && !defined(JPH_PLATFORM_WASM) // _mm_blendv_ps has problems on FireFox
244 return _mm_castps_si128(_mm_blendv_ps(_mm_castsi128_ps(inNotSet.mValue), _mm_castsi128_ps(inSet.mValue), _mm_castsi128_ps(inControl.mValue)));
245#elif defined(JPH_USE_SSE)
246 __m128 is_set = _mm_castsi128_ps(_mm_srai_epi32(inControl.mValue, 31));
247 return _mm_castps_si128(_mm_or_ps(_mm_and_ps(is_set, _mm_castsi128_ps(inSet.mValue)), _mm_andnot_ps(is_set, _mm_castsi128_ps(inNotSet.mValue))));
248#elif defined(JPH_USE_NEON)
249 return vbslq_u32(vreinterpretq_u32_s32(vshrq_n_s32(vreinterpretq_s32_u32(inControl.mValue), 31)), inSet.mValue, inNotSet.mValue);
250#elif defined(JPH_USE_RVV)
251 UVec4 masked;
252 const vuint32m1_t control = __riscv_vle32_v_u32m1(inControl.mU32, 4);
253 const vuint32m1_t not_set = __riscv_vle32_v_u32m1(inNotSet.mU32, 4);
254 const vuint32m1_t set = __riscv_vle32_v_u32m1(inSet.mU32, 4);
255
256 // Generate RVV bool mask from UVec4
257 const vuint32m1_t r = __riscv_vand_vx_u32m1(control, 0x80000000u, 4);
258 const vbool32_t rvv_mask = __riscv_vmsne_vx_u32m1_b32(r, 0x0, 4);
259 const vuint32m1_t merged = __riscv_vmerge_vvm_u32m1(not_set, set, rvv_mask, 4);
260 __riscv_vse32_v_u32m1(masked.mU32, merged, 4);
261 return masked;
262#elif defined(JPH_USE_VSX)
263 return vec_sel(inNotSet.mValue, inSet.mValue, (Type)vec_sra((__vector signed int)inControl.mValue, vec_splats(uint32(31))));
264#else
265 UVec4 result;
266 for (int i = 0; i < 4; i++)
267 result.mU32[i] = (inControl.mU32[i] & 0x80000000u) ? inSet.mU32[i] : inNotSet.mU32[i];
268 return result;
269#endif
270}
271
273{
274#if defined(JPH_USE_SSE)
275 return _mm_or_si128(inV1.mValue, inV2.mValue);
276#elif defined(JPH_USE_NEON)
277 return vorrq_u32(inV1.mValue, inV2.mValue);
278#elif defined(JPH_USE_RVV)
279 UVec4 or_result;
280 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(inV1.mU32, 4);
281 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
282 const vuint32m1_t res = __riscv_vor_vv_u32m1(v1, v2, 4);
283 __riscv_vse32_v_u32m1(or_result.mU32, res, 4);
284 return or_result;
285#elif defined(JPH_USE_VSX)
286 return vec_or(inV1.mValue, inV2.mValue);
287#else
288 return UVec4(inV1.mU32[0] | inV2.mU32[0],
289 inV1.mU32[1] | inV2.mU32[1],
290 inV1.mU32[2] | inV2.mU32[2],
291 inV1.mU32[3] | inV2.mU32[3]);
292#endif
293}
294
296{
297#if defined(JPH_USE_SSE)
298 return _mm_xor_si128(inV1.mValue, inV2.mValue);
299#elif defined(JPH_USE_NEON)
300 return veorq_u32(inV1.mValue, inV2.mValue);
301#elif defined(JPH_USE_RVV)
302 UVec4 xor_result;
303 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(inV1.mU32, 4);
304 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
305 const vuint32m1_t res = __riscv_vxor_vv_u32m1(v1, v2, 4);
306 __riscv_vse32_v_u32m1(xor_result.mU32, res, 4);
307 return xor_result;
308#elif defined(JPH_USE_VSX)
309 return vec_xor(inV1.mValue, inV2.mValue);
310#else
311 return UVec4(inV1.mU32[0] ^ inV2.mU32[0],
312 inV1.mU32[1] ^ inV2.mU32[1],
313 inV1.mU32[2] ^ inV2.mU32[2],
314 inV1.mU32[3] ^ inV2.mU32[3]);
315#endif
316}
317
319{
320#if defined(JPH_USE_SSE)
321 return _mm_and_si128(inV1.mValue, inV2.mValue);
322#elif defined(JPH_USE_NEON)
323 return vandq_u32(inV1.mValue, inV2.mValue);
324#elif defined(JPH_USE_RVV)
325 UVec4 and_result;
326 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(inV1.mU32, 4);
327 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
328 const vuint32m1_t res = __riscv_vand_vv_u32m1(v1, v2, 4);
329 __riscv_vse32_v_u32m1(and_result.mU32, res, 4);
330 return and_result;
331#elif defined(JPH_USE_VSX)
332 return vec_and(inV1.mValue, inV2.mValue);
333#else
334 return UVec4(inV1.mU32[0] & inV2.mU32[0],
335 inV1.mU32[1] & inV2.mU32[1],
336 inV1.mU32[2] & inV2.mU32[2],
337 inV1.mU32[3] & inV2.mU32[3]);
338#endif
339}
340
341
343{
344#if defined(JPH_USE_AVX512)
345 return _mm_ternarylogic_epi32(inV1.mValue, inV1.mValue, inV1.mValue, 0b01010101);
346#elif defined(JPH_USE_SSE)
347 return sXor(inV1, sReplicate(0xffffffff));
348#elif defined(JPH_USE_NEON)
349 return vmvnq_u32(inV1.mValue);
350#elif defined(JPH_USE_RVV)
351 UVec4 v;
352 const vuint32m1_t src = __riscv_vle32_v_u32m1(inV1.mU32, 4);
353 const vuint32m1_t rvv_not = __riscv_vxor_vx_u32m1(src, -1, 4);
354 __riscv_vse32_v_u32m1(v.mU32, rvv_not, 4);
355 return v;
356#elif defined(JPH_USE_VSX)
357 return vec_nor(inV1.mValue, inV1.mValue);
358#else
359 return UVec4(~inV1.mU32[0], ~inV1.mU32[1], ~inV1.mU32[2], ~inV1.mU32[3]);
360#endif
361}
362
364{
365 // If inValue.z is false then shift W to Z
366 UVec4 v = UVec4::sSelect(inIndex.Swizzle<SWIZZLE_X, SWIZZLE_Y, SWIZZLE_W, SWIZZLE_W>(), inIndex, inValue.SplatZ());
367
368 // If inValue.y is false then shift Z and further to Y and further
370
371 // If inValue.x is false then shift X and further to Y and further
373
374 return v;
375}
376
378{
379#if defined(JPH_USE_SSE4_1)
380 return _mm_mullo_epi32(mValue, inV2.mValue);
381#elif defined(JPH_USE_NEON)
382 return vmulq_u32(mValue, inV2.mValue);
383#elif defined(JPH_USE_RVV)
384 UVec4 res;
385 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
386 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
387 const vuint32m1_t mul = __riscv_vmul_vv_u32m1(v1, v2, 4);
388 __riscv_vse32_v_u32m1(res.mU32, mul, 4);
389 return res;
390#elif defined(JPH_USE_VSX)
391 return vec_mul(mValue, inV2.mValue);
392#else
393 UVec4 result;
394 for (int i = 0; i < 4; i++)
395 result.mU32[i] = mU32[i] * inV2.mU32[i];
396 return result;
397#endif
398}
399
401{
402#if defined(JPH_USE_SSE)
403 return _mm_add_epi32(mValue, inV2.mValue);
404#elif defined(JPH_USE_NEON)
405 return vaddq_u32(mValue, inV2.mValue);
406#elif defined(JPH_USE_RVV)
407 UVec4 res;
408 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
409 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
410 const vuint32m1_t rvv_add = __riscv_vadd_vv_u32m1(v1, v2, 4);
411 __riscv_vse32_v_u32m1(res.mU32, rvv_add, 4);
412 return res;
413#elif defined(JPH_USE_VSX)
414 return vec_add(mValue, inV2.mValue);
415#else
416 return UVec4(mU32[0] + inV2.mU32[0],
417 mU32[1] + inV2.mU32[1],
418 mU32[2] + inV2.mU32[2],
419 mU32[3] + inV2.mU32[3]);
420#endif
421}
422
424{
425#if defined(JPH_USE_SSE)
426 mValue = _mm_add_epi32(mValue, inV2.mValue);
427#elif defined(JPH_USE_NEON)
428 mValue = vaddq_u32(mValue, inV2.mValue);
429#elif defined(JPH_USE_RVV)
430 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
431 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
432 const vuint32m1_t rvv_add = __riscv_vadd_vv_u32m1(v1, v2, 4);
433 __riscv_vse32_v_u32m1(mU32, rvv_add, 4);
434#elif defined(JPH_USE_VSX)
435 mValue = vec_add(mValue, inV2.mValue);
436#else
437 for (int i = 0; i < 4; ++i)
438 mU32[i] += inV2.mU32[i];
439#endif
440 return *this;
441}
442
444{
445#if defined(JPH_USE_SSE)
446 return _mm_sub_epi32(mValue, inV2.mValue);
447#elif defined(JPH_USE_NEON)
448 return vsubq_u32(mValue, inV2.mValue);
449#elif defined(JPH_USE_RVV)
450 UVec4 res;
451 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
452 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
453 const vuint32m1_t rvv_add = __riscv_vsub_vv_u32m1(v1, v2, 4);
454 __riscv_vse32_v_u32m1(res.mU32, rvv_add, 4);
455 return res;
456#elif defined(JPH_USE_VSX)
457 return vec_sub(mValue, inV2.mValue);
458#else
459 return UVec4(mU32[0] - inV2.mU32[0],
460 mU32[1] - inV2.mU32[1],
461 mU32[2] - inV2.mU32[2],
462 mU32[3] - inV2.mU32[3]);
463#endif
464}
465
467{
468#if defined(JPH_USE_SSE)
469 mValue = _mm_sub_epi32(mValue, inV2.mValue);
470#elif defined(JPH_USE_NEON)
471 mValue = vsubq_u32(mValue, inV2.mValue);
472#elif defined(JPH_USE_RVV)
473 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
474 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
475 const vuint32m1_t rvv_sub = __riscv_vsub_vv_u32m1(v1, v2, 4);
476 __riscv_vse32_v_u32m1(mU32, rvv_sub, 4);
477#elif defined(JPH_USE_VSX)
478 mValue = vec_sub(mValue, inV2.mValue);
479#else
480 for (int i = 0; i < 4; ++i)
481 mU32[i] -= inV2.mU32[i];
482#endif
483 return *this;
484}
485
487{
488#if defined(JPH_USE_SSE)
489 return _mm_shuffle_epi32(mValue, _MM_SHUFFLE(0, 0, 0, 0));
490#elif defined(JPH_USE_NEON)
491 return vdupq_laneq_u32(mValue, 0);
492#elif defined(JPH_USE_RVV)
493 UVec4 vec;
494 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(mU32[0], 4);
495 __riscv_vse32_v_u32m1(vec.mU32, splat, 4);
496 return vec;
497#elif defined(JPH_USE_VSX)
498 return vec_splat(mValue, 0);
499#else
500 return UVec4(mU32[0], mU32[0], mU32[0], mU32[0]);
501#endif
502}
503
505{
506#if defined(JPH_USE_SSE)
507 return _mm_shuffle_epi32(mValue, _MM_SHUFFLE(1, 1, 1, 1));
508#elif defined(JPH_USE_NEON)
509 return vdupq_laneq_u32(mValue, 1);
510#elif defined(JPH_USE_RVV)
511 UVec4 vec;
512 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(mU32[1], 4);
513 __riscv_vse32_v_u32m1(vec.mU32, splat, 4);
514 return vec;
515#elif defined(JPH_USE_VSX)
516 return vec_splat(mValue, 1);
517#else
518 return UVec4(mU32[1], mU32[1], mU32[1], mU32[1]);
519#endif
520}
521
523{
524#if defined(JPH_USE_SSE)
525 return _mm_shuffle_epi32(mValue, _MM_SHUFFLE(2, 2, 2, 2));
526#elif defined(JPH_USE_NEON)
527 return vdupq_laneq_u32(mValue, 2);
528#elif defined(JPH_USE_RVV)
529 UVec4 vec;
530 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(mU32[2], 4);
531 __riscv_vse32_v_u32m1(vec.mU32, splat, 4);
532 return vec;
533#elif defined(JPH_USE_VSX)
534 return vec_splat(mValue, 2);
535#else
536 return UVec4(mU32[2], mU32[2], mU32[2], mU32[2]);
537#endif
538}
539
541{
542#if defined(JPH_USE_SSE)
543 return _mm_shuffle_epi32(mValue, _MM_SHUFFLE(3, 3, 3, 3));
544#elif defined(JPH_USE_NEON)
545 return vdupq_laneq_u32(mValue, 3);
546#elif defined(JPH_USE_RVV)
547 UVec4 vec;
548 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(mU32[3], 4);
549 __riscv_vse32_v_u32m1(vec.mU32, splat, 4);
550 return vec;
551#elif defined(JPH_USE_VSX)
552 return vec_splat(mValue, 3);
553#else
554 return UVec4(mU32[3], mU32[3], mU32[3], mU32[3]);
555#endif
556}
557
559{
560#if defined(JPH_USE_SSE)
561 return _mm_cvtepi32_ps(mValue);
562#elif defined(JPH_USE_NEON)
563 return vcvtq_f32_u32(mValue);
564#elif defined(JPH_USE_RVV)
565 Vec4 res;
566 const vuint32m1_t v = __riscv_vle32_v_u32m1(mU32, 4);
567 const vfloat32m1_t v_float = __riscv_vfcvt_f_xu_v_f32m1(v, 4);
568 __riscv_vse32_v_f32m1(res.mF32, v_float, 4);
569 return res;
570#elif defined(JPH_USE_VSX)
571 return vec_ctf(mValue, 0);
572#else
573 return Vec4((float)mU32[0], (float)mU32[1], (float)mU32[2], (float)mU32[3]);
574#endif
575}
576
578{
579#if defined(JPH_USE_SSE)
580 return Vec4(_mm_castsi128_ps(mValue));
581#elif defined(JPH_USE_NEON)
582 return vreinterpretq_f32_u32(mValue);
583#elif defined(JPH_USE_VSX)
584 return (Vec4::Type)mValue;
585#else
586 return BitCast<Vec4>(*this);
587#endif
588}
589
591{
592#if defined(JPH_USE_SSE4_1)
593 __m128i mul = _mm_mullo_epi32(mValue, inV2.mValue);
594 __m128i sum = _mm_add_epi32(mul, _mm_shuffle_epi32(mul, _MM_SHUFFLE(2, 3, 0, 1)));
595 return _mm_add_epi32(sum, _mm_shuffle_epi32(sum, _MM_SHUFFLE(1, 0, 3, 2)));
596#elif defined(JPH_USE_NEON)
597 uint32x4_t mul = vmulq_u32(mValue, inV2.mValue);
598 return vdupq_n_u32(vaddvq_u32(mul));
599#elif defined(JPH_USE_RVV)
600 UVec4 res;
601 const vuint32m1_t zeros = __riscv_vmv_v_x_u32m1(0, 4);
602 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
603 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
604 const vuint32m1_t mul = __riscv_vmul_vv_u32m1(v1, v2, 4);
605 const vuint32m1_t sum = __riscv_vredsum_vs_u32m1_u32m1(mul, zeros, 4);
606 const vuint32m1_t splat = __riscv_vrgather_vx_u32m1(sum, 0, 4);
607 __riscv_vse32_v_u32m1(res.mU32, splat, 4);
608 return res;
609
610#elif defined(JPH_USE_VSX)
611 Type mul = vec_mul(mValue, inV2.mValue);
612 Type sum = vec_add(mul, __builtin_shufflevector(mul, mul, 1, 0, 3, 2));
613 return vec_add(sum, __builtin_shufflevector(sum, sum, 2, 3, 0, 1));
614#else
615 return UVec4::sReplicate(mU32[0] * inV2.mU32[0] + mU32[1] * inV2.mU32[1] + mU32[2] * inV2.mU32[2] + mU32[3] * inV2.mU32[3]);
616#endif
617}
618
620{
621#if defined(JPH_USE_SSE4_1)
622 __m128i mul = _mm_mullo_epi32(mValue, inV2.mValue);
623 __m128i sum = _mm_add_epi32(mul, _mm_shuffle_epi32(mul, _MM_SHUFFLE(2, 3, 0, 1)));
624 return _mm_cvtsi128_si32(_mm_add_epi32(sum, _mm_shuffle_epi32(sum, _MM_SHUFFLE(1, 0, 3, 2))));
625#elif defined(JPH_USE_NEON)
626 uint32x4_t mul = vmulq_u32(mValue, inV2.mValue);
627 return vaddvq_u32(mul);
628#elif defined(JPH_USE_RVV)
629 const vuint32m1_t zeros = __riscv_vmv_v_x_u32m1(0, 4);
630 const vuint32m1_t v1 = __riscv_vle32_v_u32m1(mU32, 4);
631 const vuint32m1_t v2 = __riscv_vle32_v_u32m1(inV2.mU32, 4);
632 const vuint32m1_t mul = __riscv_vmul_vv_u32m1(v1, v2, 4);
633 const vuint32m1_t sum = __riscv_vredsum_vs_u32m1_u32m1(mul, zeros, 4);
634 return __riscv_vmv_x_s_u32m1_u32(sum);
635#elif defined(JPH_USE_VSX)
636 Type mul = vec_mul(mValue, inV2.mValue);
637 Type sum = vec_add(mul, __builtin_shufflevector(mul, mul, 1, 0, 3, 2));
638 return vec_extract(vec_add(sum, __builtin_shufflevector(sum, sum, 2, 3, 0, 1)), 0);
639#else
640 return mU32[0] * inV2.mU32[0] + mU32[1] * inV2.mU32[1] + mU32[2] * inV2.mU32[2] + mU32[3] * inV2.mU32[3];
641#endif
642}
643
644void UVec4::StoreInt4(uint32 *outV) const
645{
646#if defined(JPH_USE_SSE)
647 _mm_storeu_si128(reinterpret_cast<__m128i *>(outV), mValue);
648#elif defined(JPH_USE_NEON)
649 vst1q_u32(outV, mValue);
650#elif defined(JPH_USE_RVV)
651 const vuint32m1_t v = __riscv_vle32_v_u32m1(mU32, 4);
652 __riscv_vse32_v_u32m1(outV, v, 4);
653#elif defined(JPH_USE_VSX)
654 vec_xst(mValue, 0, outV);
655#else
656 for (int i = 0; i < 4; ++i)
657 outV[i] = mU32[i];
658#endif
659}
660
662{
663#if defined(JPH_USE_SSE)
664 _mm_store_si128(reinterpret_cast<__m128i *>(outV), mValue);
665#elif defined(JPH_USE_NEON)
666 vst1q_u32(outV, mValue); // ARM doesn't make distinction between aligned or not
667#elif defined(JPH_USE_RVV)
668 const vuint32m1_t v = __riscv_vle32_v_u32m1(mU32, 4);
669 __riscv_vse32_v_u32m1(outV, v, 4);
670#elif defined(JPH_USE_VSX)
671 vec_st(mValue, 0, outV);
672#else
673 for (int i = 0; i < 4; ++i)
674 outV[i] = mU32[i];
675#endif
676}
677
679{
680#if defined(JPH_USE_SSE)
681 return CountBits(_mm_movemask_ps(_mm_castsi128_ps(mValue)));
682#elif defined(JPH_USE_NEON)
683 return vaddvq_u32(vshrq_n_u32(mValue, 31));
684#elif defined(JPH_USE_RVV)
685 const vuint32m1_t src = __riscv_vle32_v_u32m1(mU32, 4);
686 const vuint32m1_t filter = __riscv_vand_vx_u32m1(src, 0x80000000, 4);
687 const vbool32_t mask = __riscv_vmsne_vx_u32m1_b32(filter, 0, 4);
688 return __riscv_vcpop_m_b32(mask, 4);
689#elif defined(JPH_USE_VSX)
690 return CountBits(uint32(GetTrues()));
691#else
692 return (mU32[0] >> 31) + (mU32[1] >> 31) + (mU32[2] >> 31) + (mU32[3] >> 31);
693#endif
694}
695
697{
698#if defined(JPH_USE_SSE)
699 return _mm_movemask_ps(_mm_castsi128_ps(mValue));
700#elif defined(JPH_USE_NEON)
701 int32x4_t shift = JPH_NEON_INT32x4(0, 1, 2, 3);
702 return vaddvq_u32(vshlq_u32(vshrq_n_u32(mValue, 31), shift));
703#elif defined(JPH_USE_RVV)
704 const vuint32m1_t src = __riscv_vle32_v_u32m1(mU32, 4);
705 const vbool32_t mask = __riscv_vmsgeu_vx_u32m1_b32(src, 0x80000000, 4);
706 const vuint32m1_t as_int = __riscv_vreinterpret_v_b32_u32m1(mask);
707 const uint32 result = __riscv_vmv_x_s_u32m1_u32(as_int) & 0xF;
708 return result;
709#elif defined(JPH_USE_VSX)
710 // Gather the sign bit of every component, the bits of a vector are numbered starting at the most significant bit of W
711 const __vector unsigned char perm = { 96, 64, 32, 0, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 };
712 return int(vec_extract((__vector unsigned long long)vec_vbpermq((__vector unsigned char)mValue, perm), 1));
713#else
714 return (mU32[0] >> 31) | ((mU32[1] >> 31) << 1) | ((mU32[2] >> 31) << 2) | ((mU32[3] >> 31) << 3);
715#endif
716}
717
719{
720#if defined(JPH_USE_VSX)
721 return vec_any_lt((__vector signed int)mValue, vec_splats(0));
722#else
723 return GetTrues() != 0;
724#endif
725}
726
728{
729#if defined(JPH_USE_VSX)
730 return vec_any_lt((__vector signed int)__builtin_shufflevector(mValue, mValue, 0, 1, 2, 2), vec_splats(0));
731#else
732 return (GetTrues() & 0b111) != 0;
733#endif
734}
735
737{
738#if defined(JPH_USE_VSX)
739 return vec_all_lt((__vector signed int)mValue, vec_splats(0));
740#else
741 return GetTrues() == 0b1111;
742#endif
743}
744
746{
747#if defined(JPH_USE_VSX)
748 return vec_all_lt((__vector signed int)__builtin_shufflevector(mValue, mValue, 0, 1, 2, 2), vec_splats(0));
749#else
750 return (GetTrues() & 0b111) == 0b111;
751#endif
752}
753
754template <const uint Count>
756{
757 static_assert(Count <= 31, "Invalid shift");
758
759#if defined(JPH_USE_SSE)
760 return _mm_slli_epi32(mValue, Count);
761#elif defined(JPH_USE_NEON)
762 return vshlq_n_u32(mValue, Count);
763#elif defined(JPH_USE_RVV)
764 const vuint32m1_t v = __riscv_vle32_v_u32m1(mU32, 4);
765 const vuint32m1_t shifted = __riscv_vsll_vx_u32m1(v, Count, 4);
766
767 UVec4 vec;
768 __riscv_vse32_v_u32m1(vec.mU32, shifted, 4);
769 return vec;
770#elif defined(JPH_USE_VSX)
771 return vec_sl(mValue, vec_splats(uint32(Count)));
772#else
773 return UVec4(mU32[0] << Count, mU32[1] << Count, mU32[2] << Count, mU32[3] << Count);
774#endif
775}
776
777template <const uint Count>
779{
780 static_assert(Count <= 31, "Invalid shift");
781
782#if defined(JPH_USE_SSE)
783 return _mm_srli_epi32(mValue, Count);
784#elif defined(JPH_USE_NEON)
785 return vshrq_n_u32(mValue, Count);
786#elif defined(JPH_USE_RVV)
787 const vuint32m1_t v = __riscv_vle32_v_u32m1(mU32, 4);
788 const vuint32m1_t shifted = __riscv_vsrl_vx_u32m1(v, Count, 4);
789
790 UVec4 vec;
791 __riscv_vse32_v_u32m1(vec.mU32, shifted, 4);
792 return vec;
793#elif defined(JPH_USE_VSX)
794 return vec_sr(mValue, vec_splats(uint32(Count)));
795#else
796 return UVec4(mU32[0] >> Count, mU32[1] >> Count, mU32[2] >> Count, mU32[3] >> Count);
797#endif
798}
799
800template <const uint Count>
802{
803 static_assert(Count <= 31, "Invalid shift");
804
805#if defined(JPH_USE_SSE)
806 return _mm_srai_epi32(mValue, Count);
807#elif defined(JPH_USE_NEON)
808 return vreinterpretq_u32_s32(vshrq_n_s32(vreinterpretq_s32_u32(mValue), Count));
809#elif defined(JPH_USE_RVV)
810 const vint32m1_t v = __riscv_vle32_v_i32m1(reinterpret_cast<const int32 *>(mU32), 4);
811 const vint32m1_t shifted = __riscv_vsra_vx_i32m1(v, Count, 4);
812
813 UVec4 vec;
814 __riscv_vse32_v_i32m1(reinterpret_cast<int32 *>(vec.mU32), shifted, 4);
815 return vec;
816#elif defined(JPH_USE_VSX)
817 return (Type)vec_sra((__vector signed int)mValue, vec_splats(uint32(Count)));
818#else
819 return UVec4(uint32(int32(mU32[0]) >> Count),
820 uint32(int32(mU32[1]) >> Count),
821 uint32(int32(mU32[2]) >> Count),
822 uint32(int32(mU32[3]) >> Count));
823#endif
824}
825
827{
828#if defined(JPH_USE_SSE)
829 return _mm_unpacklo_epi16(mValue, _mm_castps_si128(_mm_setzero_ps()));
830#elif defined(JPH_USE_NEON)
831 uint16x4_t value = vget_low_u16(vreinterpretq_u16_u32(mValue));
832 uint16x4_t zero = vdup_n_u16(0);
833 return vreinterpretq_u32_u16(vcombine_u16(vzip1_u16(value, zero), vzip2_u16(value, zero)));
834#elif defined(JPH_USE_RVV)
835 const vuint16mf2_t v = __riscv_vle16_v_u16mf2(reinterpret_cast<const uint16 *>(mU32), 4);
836 const vuint32m1_t zext = __riscv_vzext_vf2_u32m1(v, 4);
837
838 UVec4 res;
839 __riscv_vse32_v_u32m1(res.mU32, zext, 4);
840 return res;
841#elif defined(JPH_USE_VSX)
842 const __vector unsigned short zero = vec_splats((unsigned short)0);
843 return (Type)__builtin_shufflevector((__vector unsigned short)mValue, zero, 0, 8, 1, 8, 2, 8, 3, 8);
844#else
845 return UVec4(mU32[0] & 0xffff,
846 (mU32[0] >> 16) & 0xffff,
847 mU32[1] & 0xffff,
848 (mU32[1] >> 16) & 0xffff);
849#endif
850}
851
853{
854#if defined(JPH_USE_SSE)
855 return _mm_unpackhi_epi16(mValue, _mm_castps_si128(_mm_setzero_ps()));
856#elif defined(JPH_USE_NEON)
857 uint16x4_t value = vget_high_u16(vreinterpretq_u16_u32(mValue));
858 uint16x4_t zero = vdup_n_u16(0);
859 return vreinterpretq_u32_u16(vcombine_u16(vzip1_u16(value, zero), vzip2_u16(value, zero)));
860#elif defined(JPH_USE_RVV)
861 const vuint16mf2_t v = __riscv_vle16_v_u16mf2(reinterpret_cast<const uint16 *>(&mU32[2]), 4);
862 const vuint32m1_t zext = __riscv_vzext_vf2_u32m1(v, 4);
863
864 UVec4 res;
865 __riscv_vse32_v_u32m1(res.mU32, zext, 4);
866 return res;
867#elif defined(JPH_USE_VSX)
868 const __vector unsigned short zero = vec_splats((unsigned short)0);
869 return (Type)__builtin_shufflevector((__vector unsigned short)mValue, zero, 4, 8, 5, 8, 6, 8, 7, 8);
870#else
871 return UVec4(mU32[2] & 0xffff,
872 (mU32[2] >> 16) & 0xffff,
873 mU32[3] & 0xffff,
874 (mU32[3] >> 16) & 0xffff);
875#endif
876}
877
879{
880#if defined(JPH_USE_SSE4_1)
881 return _mm_shuffle_epi8(mValue, _mm_set_epi32(int(0xffffff03), int(0xffffff02), int(0xffffff01), int(0xffffff00)));
882#elif defined(JPH_USE_NEON)
883 uint8x16_t idx = JPH_NEON_UINT8x16(0x00, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, 0x7f, 0x7f, 0x02, 0x7f, 0x7f, 0x7f, 0x03, 0x7f, 0x7f, 0x7f);
884 return vreinterpretq_u32_s8(vqtbl1q_s8(vreinterpretq_s8_u32(mValue), idx));
885#elif defined(JPH_USE_RVV)
886 const vuint8mf4_t v = __riscv_vle8_v_u8mf4(reinterpret_cast<const uint8 *>(mU32), 4);
887 const vuint32m1_t zext = __riscv_vzext_vf4_u32m1(v, 4);
888
889 UVec4 res;
890 __riscv_vse32_v_u32m1(res.mU32, zext, 4);
891 return res;
892#elif defined(JPH_USE_VSX)
893 const __vector unsigned char zero = vec_splats((unsigned char)0);
894 return (Type)__builtin_shufflevector((__vector unsigned char)mValue, zero, 0, 16, 16, 16, 1, 16, 16, 16, 2, 16, 16, 16, 3, 16, 16, 16);
895#else
896 UVec4 result;
897 for (int i = 0; i < 4; i++)
898 result.mU32[i] = (mU32[0] >> (i * 8)) & 0xff;
899 return result;
900#endif
901}
902
904{
905#if defined(JPH_USE_SSE4_1)
906 return _mm_shuffle_epi8(mValue, _mm_set_epi32(int(0xffffff07), int(0xffffff06), int(0xffffff05), int(0xffffff04)));
907#elif defined(JPH_USE_NEON)
908 uint8x16_t idx = JPH_NEON_UINT8x16(0x04, 0x7f, 0x7f, 0x7f, 0x05, 0x7f, 0x7f, 0x7f, 0x06, 0x7f, 0x7f, 0x7f, 0x07, 0x7f, 0x7f, 0x7f);
909 return vreinterpretq_u32_s8(vqtbl1q_s8(vreinterpretq_s8_u32(mValue), idx));
910#elif defined(JPH_USE_RVV)
911 const vuint8mf4_t v = __riscv_vle8_v_u8mf4(reinterpret_cast<const uint8 *>(&mU32[1]), 4);
912 const vuint32m1_t zext = __riscv_vzext_vf4_u32m1(v, 4);
913
914 UVec4 res;
915 __riscv_vse32_v_u32m1(res.mU32, zext, 4);
916 return res;
917#elif defined(JPH_USE_VSX)
918 const __vector unsigned char zero = vec_splats((unsigned char)0);
919 return (Type)__builtin_shufflevector((__vector unsigned char)mValue, zero, 4, 16, 16, 16, 5, 16, 16, 16, 6, 16, 16, 16, 7, 16, 16, 16);
920#else
921 UVec4 result;
922 for (int i = 0; i < 4; i++)
923 result.mU32[i] = (mU32[1] >> (i * 8)) & 0xff;
924 return result;
925#endif
926}
927
929{
930#if defined(JPH_USE_SSE4_1)
931 return _mm_shuffle_epi8(mValue, _mm_set_epi32(int(0xffffff0b), int(0xffffff0a), int(0xffffff09), int(0xffffff08)));
932#elif defined(JPH_USE_NEON)
933 uint8x16_t idx = JPH_NEON_UINT8x16(0x08, 0x7f, 0x7f, 0x7f, 0x09, 0x7f, 0x7f, 0x7f, 0x0a, 0x7f, 0x7f, 0x7f, 0x0b, 0x7f, 0x7f, 0x7f);
934 return vreinterpretq_u32_s8(vqtbl1q_s8(vreinterpretq_s8_u32(mValue), idx));
935#elif defined(JPH_USE_RVV)
936 const vuint8mf4_t v = __riscv_vle8_v_u8mf4(reinterpret_cast<const uint8 *>(&mU32[2]), 4);
937 const vuint32m1_t zext = __riscv_vzext_vf4_u32m1(v, 4);
938
939 UVec4 res;
940 __riscv_vse32_v_u32m1(res.mU32, zext, 4);
941 return res;
942#elif defined(JPH_USE_VSX)
943 const __vector unsigned char zero = vec_splats((unsigned char)0);
944 return (Type)__builtin_shufflevector((__vector unsigned char)mValue, zero, 8, 16, 16, 16, 9, 16, 16, 16, 10, 16, 16, 16, 11, 16, 16, 16);
945#else
946 UVec4 result;
947 for (int i = 0; i < 4; i++)
948 result.mU32[i] = (mU32[2] >> (i * 8)) & 0xff;
949 return result;
950#endif
951}
952
954{
955#if defined(JPH_USE_SSE4_1)
956 return _mm_shuffle_epi8(mValue, _mm_set_epi32(int(0xffffff0f), int(0xffffff0e), int(0xffffff0d), int(0xffffff0c)));
957#elif defined(JPH_USE_NEON)
958 uint8x16_t idx = JPH_NEON_UINT8x16(0x0c, 0x7f, 0x7f, 0x7f, 0x0d, 0x7f, 0x7f, 0x7f, 0x0e, 0x7f, 0x7f, 0x7f, 0x0f, 0x7f, 0x7f, 0x7f);
959 return vreinterpretq_u32_s8(vqtbl1q_s8(vreinterpretq_s8_u32(mValue), idx));
960#elif defined(JPH_USE_RVV)
961 const vuint8mf4_t v = __riscv_vle8_v_u8mf4(reinterpret_cast<const uint8 *>(&mU32[3]), 4);
962 const vuint32m1_t zext = __riscv_vzext_vf4_u32m1(v, 4);
963
964 UVec4 res;
965 __riscv_vse32_v_u32m1(res.mU32, zext, 4);
966 return res;
967#elif defined(JPH_USE_VSX)
968 const __vector unsigned char zero = vec_splats((unsigned char)0);
969 return (Type)__builtin_shufflevector((__vector unsigned char)mValue, zero, 12, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16);
970#else
971 UVec4 result;
972 for (int i = 0; i < 4; i++)
973 result.mU32[i] = (mU32[3] >> (i * 8)) & 0xff;
974 return result;
975#endif
976}
977
979{
980#if defined(JPH_USE_SSE4_1) || defined(JPH_USE_NEON) || defined(JPH_USE_VSX)
981 alignas(UVec4) static constexpr uint32 sFourMinusXShuffle[5][4] =
982 {
983 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff },
984 { 0x0f0e0d0c, 0xffffffff, 0xffffffff, 0xffffffff },
985 { 0x0b0a0908, 0x0f0e0d0c, 0xffffffff, 0xffffffff },
986 { 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0xffffffff },
987 { 0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c }
988 };
989#endif
990
991#if defined(JPH_USE_SSE4_1)
992 return _mm_shuffle_epi8(mValue, *reinterpret_cast<const UVec4::Type *>(sFourMinusXShuffle[inCount]));
993#elif defined(JPH_USE_NEON)
994 uint8x16_t idx = vreinterpretq_u8_u32(*reinterpret_cast<const UVec4::Type *>(sFourMinusXShuffle[inCount]));
995 return vreinterpretq_u32_s8(vqtbl1q_s8(vreinterpretq_s8_u32(mValue), idx));
996#elif defined(JPH_USE_RVV)
997 const uint32 *start_ptr = mU32 + (4 - inCount);
998 const vuint32m1_t v = __riscv_vle32_v_u32m1(start_ptr, inCount);
999
1000 UVec4 res = sZero();
1001 __riscv_vse32_v_u32m1(res.mU32, v, inCount);
1002 return res;
1003#elif defined(JPH_USE_VSX)
1004 // vec_perm only looks at the lowest 5 bits of an index so 0xff selects the last byte of the 2nd (zero) vector
1005 __vector unsigned char idx = (__vector unsigned char)vec_ld(0, sFourMinusXShuffle[inCount]);
1006 return (Type)vec_perm((__vector unsigned char)mValue, vec_splats((unsigned char)0), idx);
1007#else
1008 UVec4 result = UVec4::sZero();
1009 for (int i = 0; i < inCount; i++)
1010 result.mU32[i] = mU32[i + 4 - inCount];
1011 return result;
1012#endif
1013}
1014
std::uint8_t uint8
Definition Core.h:578
std::int32_t int32
Definition Core.h:581
std::uint64_t uint64
Definition Core.h:582
#define JPH_NAMESPACE_END
Definition Core.h:494
std::uint32_t uint32
Definition Core.h:580
#define JPH_NAMESPACE_BEGIN
Definition Core.h:488
std::uint16_t uint16
Definition Core.h:579
#define xy
Definition HLSLToCPP.h:511
uint CountBits(uint32 inValue)
Count the number of 1 bits in a value.
Definition Math.h:243
JPH_INLINE constexpr To BitCast(const From &inValue)
Simple implementation of C++20 std::bit_cast.
Definition Math.h:271
@ SWIZZLE_Z
Use the Z component.
Definition Swizzle.h:14
@ SWIZZLE_W
Use the W component.
Definition Swizzle.h:15
@ SWIZZLE_X
Use the X component.
Definition Swizzle.h:12
@ SWIZZLE_Y
Use the Y component.
Definition Swizzle.h:13
Definition UVec4.h:12
JPH_INLINE UVec4 operator-(UVec4Arg inV2) const
Subtract two integer vectors (component wise)
Definition UVec4.inl:443
JPH_INLINE UVec4 Swizzle() const
Swizzle the elements in inV.
static JPH_INLINE UVec4 sNot(UVec4Arg inV1)
Logical not (component wise)
Definition UVec4.inl:342
JPH_INLINE uint32 GetZ() const
Definition UVec4.h:111
static JPH_INLINE UVec4 sMin(UVec4Arg inV1, UVec4Arg inV2)
Return the minimum value of each of the components.
Definition UVec4.inl:170
JPH_INLINE UVec4 LogicalShiftLeft() const
Shift all components by Count bits to the left (filling with zeros from the left)
JPH_INLINE int CountTrues() const
Count the number of components that are true (true is when highest bit of component is set)
Definition UVec4.inl:678
JPH_INLINE UVec4 & operator-=(UVec4Arg inV2)
Subtract two integer vectors (component wise)
Definition UVec4.inl:466
JPH_INLINE UVec4 SplatY() const
Replicate the Y component to all components.
Definition UVec4.inl:504
static JPH_INLINE UVec4 sSelect(UVec4Arg inNotSet, UVec4Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition UVec4.inl:241
static JPH_INLINE UVec4 sLoadInt(const uint32 *inV)
Load 1 int from memory and place it in the X component, zeros Y, Z and W.
Definition UVec4.inl:99
JPH_INLINE UVec4 Expand4Uint16Lo() const
Takes the lower 4 16 bits and expands them to X, Y, Z and W.
Definition UVec4.inl:826
static JPH_INLINE UVec4 sSort4True(UVec4Arg inValue, UVec4Arg inIndex)
Definition UVec4.inl:363
JPH_INLINE UVec4 operator+(UVec4Arg inV2) const
Add two integer vectors (component wise)
Definition UVec4.inl:400
JPH_INLINE uint32 GetY() const
Definition UVec4.h:110
JPH_INLINE UVec4 LogicalShiftRight() const
Shift all components by Count bits to the right (filling with zeros from the right)
static JPH_INLINE UVec4 sReplicate(uint32 inV)
Replicate int inV across all components.
Definition UVec4.inl:81
JPH_INLINE UVec4 SplatX() const
Replicate the X component to all components.
Definition UVec4.inl:486
JPH_INLINE UVec4 Expand4Byte4() const
Takes byte 4 .. 7 and expands them to X, Y, Z and W.
Definition UVec4.inl:903
JPH_INLINE bool TestAllTrue() const
Test if all components are true (true is when highest bit of component is set)
Definition UVec4.inl:736
JPH_INLINE UVec4 Expand4Byte0() const
Takes byte 0 .. 3 and expands them to X, Y, Z and W.
Definition UVec4.inl:878
JPH_INLINE int GetTrues() const
Store if X is true in bit 0, Y in bit 1, Z in bit 2 and W in bit 3 (true is when highest bit of compo...
Definition UVec4.inl:696
JPH_INLINE bool TestAnyXYZTrue() const
Test if any of X, Y or Z components are true (true is when highest bit of component is set)
Definition UVec4.inl:727
JPH_INLINE UVec4 & operator+=(UVec4Arg inV2)
Add two integer vectors (component wise)
Definition UVec4.inl:423
static JPH_INLINE UVec4 sGatherInt4(const uint32 *inBase, UVec4Arg inOffsets)
Gather 4 ints from memory at inBase + inOffsets[i] * Scale.
static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2)
Logical and (component wise)
Definition UVec4.inl:318
static JPH_INLINE UVec4 sEquals(UVec4Arg inV1, UVec4Arg inV2)
Equals (component wise)
Definition UVec4.inl:216
static JPH_INLINE UVec4 sOr(UVec4Arg inV1, UVec4Arg inV2)
Logical or (component wise)
Definition UVec4.inl:272
struct { uint32 mData[4];} Type
Definition UVec4.h:24
JPH_INLINE uint32 GetW() const
Definition UVec4.h:112
JPH_INLINE bool TestAllXYZTrue() const
Test if X, Y and Z components are true (true is when highest bit of component is set)
Definition UVec4.inl:745
JPH_INLINE UVec4 ShiftComponents4Minus(int inCount) const
Shift vector components by 4 - Count floats to the left, so if Count = 1 the resulting vector is (W,...
Definition UVec4.inl:978
JPH_INLINE bool operator==(UVec4Arg inV2) const
Comparison.
Definition UVec4.inl:31
static JPH_INLINE UVec4 sMax(UVec4Arg inV1, UVec4Arg inV2)
Return the maximum of each of the components.
Definition UVec4.inl:193
JPH_INLINE UVec4 SplatZ() const
Replicate the Z component to all components.
Definition UVec4.inl:522
Type mValue
Definition UVec4.h:230
JPH_INLINE UVec4 SplatW() const
Replicate the W component to all components.
Definition UVec4.inl:540
JPH_INLINE void StoreInt4(uint32 *outV) const
Store 4 ints to memory.
Definition UVec4.inl:644
JPH_INLINE uint32 GetX() const
Get individual components.
Definition UVec4.h:109
JPH_INLINE UVec4 Expand4Byte8() const
Takes byte 8 .. 11 and expands them to X, Y, Z and W.
Definition UVec4.inl:928
static JPH_INLINE UVec4 sLoadInt4Aligned(const uint32 *inV)
Load 4 ints from memory, aligned to 16 bytes.
Definition UVec4.inl:130
static JPH_INLINE UVec4 sLoadInt4(const uint32 *inV)
Load 4 ints from memory.
Definition UVec4.inl:112
JPH_INLINE UVec4 Expand4Byte12() const
Takes byte 12 .. 15 and expands them to X, Y, Z and W.
Definition UVec4.inl:953
static JPH_INLINE UVec4 sXor(UVec4Arg inV1, UVec4Arg inV2)
Logical xor (component wise)
Definition UVec4.inl:295
JPH_INLINE UVec4 Expand4Uint16Hi() const
Takes the upper 4 16 bits and expands them to X, Y, Z and W.
Definition UVec4.inl:852
static JPH_INLINE UVec4 sZero()
Vector with all zeros.
Definition UVec4.inl:63
JPH_INLINE uint32 Dot(UVec4Arg inV2) const
Dot product.
Definition UVec4.inl:619
JPH_INLINE UVec4 DotV(UVec4Arg inV2) const
Dot product, returns the dot product in X, Y, Z and W components.
Definition UVec4.inl:590
JPH_INLINE UVec4 ArithmeticShiftRight() const
Shift all components by Count bits to the right (shifting in the value of the highest bit)
UVec4()=default
Constructor.
JPH_INLINE UVec4 operator*(UVec4Arg inV2) const
Component wise multiplication of two integer vectors (stores low 32 bits of result only)
Definition UVec4.inl:377
JPH_INLINE Vec4 ToFloat() const
Convert each component from an int to a float.
Definition UVec4.inl:558
JPH_INLINE Vec4 ReinterpretAsFloat() const
Reinterpret UVec4 as a Vec4 (doesn't change the bits)
Definition UVec4.inl:577
JPH_INLINE void StoreInt4Aligned(uint32 *outV) const
Store 4 ints to memory, aligned to 16 bytes.
Definition UVec4.inl:661
JPH_INLINE bool TestAnyTrue() const
Test if any of the components are true (true is when highest bit of component is set)
Definition UVec4.inl:718
uint32 mU32[4]
Definition UVec4.h:231
Definition Vec4.h:14
float mF32[4]
Definition Vec4.h:325
struct { float mData[4];} Type
Definition Vec4.h:26