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));
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)
36template<u
int32 SwizzleX, u
int32 SwizzleY, u
int32 SwizzleZ, u
int32 SwizzleW>
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");
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)
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);
56#elif defined(JPH_USE_VSX)
57 return __builtin_shufflevector(
mValue,
mValue, SwizzleX, SwizzleY, SwizzleZ, SwizzleW);
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)
71 const vuint32m1_t zero_vec = __riscv_vmv_v_x_u32m1(0, 4);
72 __riscv_vse32_v_u32m1(v.
mU32, zero_vec, 4);
74#elif defined(JPH_USE_VSX)
75 return vec_splats(
uint32(0));
77 return UVec4(0, 0, 0, 0);
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)
89 const vuint32m1_t v = __riscv_vmv_v_x_u32m1(inV, 4);
90 __riscv_vse32_v_u32m1(vec.
mU32, v, 4);
92#elif defined(JPH_USE_VSX)
93 return vec_splats(inV);
95 return UVec4(inV, inV, inV, inV);
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 };
108 return UVec4(*inV, 0, 0, 0);
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)
120 const vuint32m1_t v = __riscv_vle32_v_u32m1(inV, 4);
121 __riscv_vse32_v_u32m1(vector.
mU32, v, 4);
123#elif defined(JPH_USE_VSX)
124 return vec_xl(0, inV);
126 return UVec4(inV[0], inV[1], inV[2], inV[3]);
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);
136#elif defined(JPH_USE_RVV)
138 const vuint32m1_t v = __riscv_vle32_v_u32m1(inV, 4);
139 __riscv_vse32_v_u32m1(vector.
mU32, v, 4);
141#elif defined(JPH_USE_VSX)
142 return vec_ld(0, inV);
144 return UVec4(inV[0], inV[1], inV[2], inV[3]);
148template <const
int Scale>
152 return _mm_i32gather_epi32(
reinterpret_cast<const int *
>(inBase), inOffsets.
mValue, Scale);
153#elif defined(JPH_USE_RVV)
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);
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);
172#if defined(JPH_USE_SSE4_1)
174#elif defined(JPH_USE_NEON)
176#elif defined(JPH_USE_RVV)
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);
183#elif defined(JPH_USE_VSX)
187 for (
int i = 0; i < 4; i++)
195#if defined(JPH_USE_SSE4_1)
197#elif defined(JPH_USE_NEON)
199#elif defined(JPH_USE_RVV)
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);
206#elif defined(JPH_USE_VSX)
210 for (
int i = 0; i < 4; i++)
218#if defined(JPH_USE_SSE)
220#elif defined(JPH_USE_NEON)
222#elif defined(JPH_USE_RVV)
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);
231#elif defined(JPH_USE_VSX)
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);
243#if defined(JPH_USE_SSE4_1) && !defined(JPH_PLATFORM_WASM)
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)
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);
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);
262#elif defined(JPH_USE_VSX)
266 for (
int i = 0; i < 4; i++)
267 result.
mU32[i] = (inControl.
mU32[i] & 0x80000000u) ? inSet.
mU32[i] : inNotSet.
mU32[i];
274#if defined(JPH_USE_SSE)
276#elif defined(JPH_USE_NEON)
278#elif defined(JPH_USE_RVV)
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);
285#elif defined(JPH_USE_VSX)
297#if defined(JPH_USE_SSE)
299#elif defined(JPH_USE_NEON)
301#elif defined(JPH_USE_RVV)
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);
308#elif defined(JPH_USE_VSX)
320#if defined(JPH_USE_SSE)
322#elif defined(JPH_USE_NEON)
324#elif defined(JPH_USE_RVV)
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);
331#elif defined(JPH_USE_VSX)
344#if defined(JPH_USE_AVX512)
346#elif defined(JPH_USE_SSE)
348#elif defined(JPH_USE_NEON)
349 return vmvnq_u32(inV1.
mValue);
350#elif defined(JPH_USE_RVV)
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);
356#elif defined(JPH_USE_VSX)
379#if defined(JPH_USE_SSE4_1)
381#elif defined(JPH_USE_NEON)
383#elif defined(JPH_USE_RVV)
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);
390#elif defined(JPH_USE_VSX)
394 for (
int i = 0; i < 4; i++)
402#if defined(JPH_USE_SSE)
404#elif defined(JPH_USE_NEON)
406#elif defined(JPH_USE_RVV)
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);
413#elif defined(JPH_USE_VSX)
425#if defined(JPH_USE_SSE)
427#elif defined(JPH_USE_NEON)
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)
437 for (
int i = 0; i < 4; ++i)
445#if defined(JPH_USE_SSE)
447#elif defined(JPH_USE_NEON)
449#elif defined(JPH_USE_RVV)
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);
456#elif defined(JPH_USE_VSX)
468#if defined(JPH_USE_SSE)
470#elif defined(JPH_USE_NEON)
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)
480 for (
int i = 0; i < 4; ++i)
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)
494 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(
mU32[0], 4);
495 __riscv_vse32_v_u32m1(vec.
mU32, splat, 4);
497#elif defined(JPH_USE_VSX)
498 return vec_splat(
mValue, 0);
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)
512 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(
mU32[1], 4);
513 __riscv_vse32_v_u32m1(vec.
mU32, splat, 4);
515#elif defined(JPH_USE_VSX)
516 return vec_splat(
mValue, 1);
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)
530 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(
mU32[2], 4);
531 __riscv_vse32_v_u32m1(vec.
mU32, splat, 4);
533#elif defined(JPH_USE_VSX)
534 return vec_splat(
mValue, 2);
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)
548 const vuint32m1_t splat = __riscv_vmv_v_x_u32m1(
mU32[3], 4);
549 __riscv_vse32_v_u32m1(vec.
mU32, splat, 4);
551#elif defined(JPH_USE_VSX)
552 return vec_splat(
mValue, 3);
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)
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);
570#elif defined(JPH_USE_VSX)
571 return vec_ctf(
mValue, 0);
579#if defined(JPH_USE_SSE)
581#elif defined(JPH_USE_NEON)
582 return vreinterpretq_f32_u32(
mValue);
583#elif defined(JPH_USE_VSX)
592#if defined(JPH_USE_SSE4_1)
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)
598 return vdupq_n_u32(vaddvq_u32(mul));
599#elif defined(JPH_USE_RVV)
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);
610#elif defined(JPH_USE_VSX)
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));
621#if defined(JPH_USE_SSE4_1)
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)
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)
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);
646#if defined(JPH_USE_SSE)
647 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(outV),
mValue);
648#elif defined(JPH_USE_NEON)
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)
656 for (
int i = 0; i < 4; ++i)
663#if defined(JPH_USE_SSE)
664 _mm_store_si128(
reinterpret_cast<__m128i *
>(outV),
mValue);
665#elif defined(JPH_USE_NEON)
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)
673 for (
int i = 0; i < 4; ++i)
680#if defined(JPH_USE_SSE)
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)
692 return (
mU32[0] >> 31) + (
mU32[1] >> 31) + (
mU32[2] >> 31) + (
mU32[3] >> 31);
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;
709#elif defined(JPH_USE_VSX)
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));
714 return (
mU32[0] >> 31) | ((
mU32[1] >> 31) << 1) | ((
mU32[2] >> 31) << 2) | ((
mU32[3] >> 31) << 3);
720#if defined(JPH_USE_VSX)
721 return vec_any_lt((__vector
signed int)
mValue, vec_splats(0));
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));
738#if defined(JPH_USE_VSX)
739 return vec_all_lt((__vector
signed int)
mValue, vec_splats(0));
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));
750 return (
GetTrues() & 0b111) == 0b111;
754template <const u
int Count>
757 static_assert(Count <= 31,
"Invalid shift");
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);
768 __riscv_vse32_v_u32m1(vec.
mU32, shifted, 4);
770#elif defined(JPH_USE_VSX)
777template <const u
int Count>
780 static_assert(Count <= 31,
"Invalid shift");
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);
791 __riscv_vse32_v_u32m1(vec.
mU32, shifted, 4);
793#elif defined(JPH_USE_VSX)
800template <const u
int Count>
803 static_assert(Count <= 31,
"Invalid shift");
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);
814 __riscv_vse32_v_i32m1(
reinterpret_cast<int32 *
>(vec.
mU32), shifted, 4);
816#elif defined(JPH_USE_VSX)
817 return (
Type)vec_sra((__vector
signed int)
mValue, vec_splats(
uint32(Count)));
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);
839 __riscv_vse32_v_u32m1(res.
mU32, zext, 4);
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);
846 (
mU32[0] >> 16) & 0xffff,
848 (
mU32[1] >> 16) & 0xffff);
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);
865 __riscv_vse32_v_u32m1(res.
mU32, zext, 4);
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);
872 (
mU32[2] >> 16) & 0xffff,
874 (
mU32[3] >> 16) & 0xffff);
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);
890 __riscv_vse32_v_u32m1(res.
mU32, zext, 4);
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);
897 for (
int i = 0; i < 4; i++)
898 result.
mU32[i] = (
mU32[0] >> (i * 8)) & 0xff;
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);
915 __riscv_vse32_v_u32m1(res.
mU32, zext, 4);
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);
922 for (
int i = 0; i < 4; i++)
923 result.
mU32[i] = (
mU32[1] >> (i * 8)) & 0xff;
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);
940 __riscv_vse32_v_u32m1(res.
mU32, zext, 4);
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);
947 for (
int i = 0; i < 4; i++)
948 result.
mU32[i] = (
mU32[2] >> (i * 8)) & 0xff;
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);
965 __riscv_vse32_v_u32m1(res.
mU32, zext, 4);
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);
972 for (
int i = 0; i < 4; i++)
973 result.
mU32[i] = (
mU32[3] >> (i * 8)) & 0xff;
980#if defined(JPH_USE_SSE4_1) || defined(JPH_USE_NEON) || defined(JPH_USE_VSX)
981 alignas(
UVec4)
static constexpr uint32 sFourMinusXShuffle[5][4] =
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 }
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);
1001 __riscv_vse32_v_u32m1(res.
mU32, v, inCount);
1003#elif defined(JPH_USE_VSX)
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);
1009 for (
int i = 0; i < inCount; i++)
1010 result.
mU32[i] =
mU32[i + 4 - inCount];
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
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
float mF32[4]
Definition Vec4.h:325
struct { float mData[4];} Type
Definition Vec4.h:26