29#ifndef PXFOUNDATION_PXUNIXNEONINLINEAOS_H
30#define PXFOUNDATION_PXUNIXNEONINLINEAOS_H
32#if !COMPILE_VECTOR_INTRINSICS
33#error Vector intrinsics should not be included when using scalar implementation.
42#define VRECIPEQ recipq_newton<1>
43#define VRECIPE recip_newton<1>
44#define VRECIPSQRTEQ rsqrtq_newton<1>
45#define VRECIPSQRTE rsqrt_newton<1>
48#define VRECIPQ recipq_newton<4>
51#define VRECIP recip_newton<5>
53#define VRECIP recip_newton<4>
55#define VRECIPSQRTQ rsqrtq_newton<4>
56#define VRECIPSQRT rsqrt_newton<4>
58#define VECMATH_AOS_EPSILON (1e-3f)
64#define FLOAT_COMPONENTS_EQUAL_THRESHOLD 0.01f
75 vst1_f32(
reinterpret_cast<float32_t*
>(data), a);
104 return(0 == (
size_t(a) & 0x0f));
108#define ASSERT_ISVALIDVEC3V(a) PX_ASSERT(isValidVec3V(a))
109#define ASSERT_ISVALIDFLOATV(a) PX_ASSERT(isValidFloatV(a))
110#define ASSERT_ISALIGNED16(a) PX_ASSERT(isAligned16(static_cast<const void*>(a)))
112#define ASSERT_ISVALIDVEC3V(a)
113#define ASSERT_ISVALIDFLOATV(a)
114#define ASSERT_ISALIGNED16(a)
117namespace internalUnitNeonSimd
121 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
122 const uint16x4_t dLow = vmovn_u32(a);
123 const uint16x8_t combined = vcombine_u16(dLow, dHigh);
124 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
125 return PxU32(vget_lane_u32(finalReduce, 0) == 0xffffFFFF);
130 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
131 const uint16x4_t dLow = vmovn_u32(a);
132 const uint16x8_t combined = vcombine_u16(dLow, dHigh);
133 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
134 return PxU32((vget_lane_u32(finalReduce, 0) & 0xffFFff) == 0xffFFff);
139 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
140 const uint16x4_t dLow = vmovn_u32(a);
141 const uint16x8_t combined = vcombine_u16(dLow, dHigh);
142 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
143 return PxU32(vget_lane_u32(finalReduce, 0) != 0x0);
148 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
149 const uint16x4_t dLow = vmovn_u32(a);
150 const uint16x8_t combined = vcombine_u16(dLow, dHigh);
151 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
152 return PxU32((vget_lane_u32(finalReduce, 0) & 0xffFFff) != 0);
156namespace vecMathTests
161 PX_ALIGN(16, PxF32) data[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
162 return V4LoadA(data);
165PX_FORCE_INLINE bool allElementsEqualFloatV(
const FloatV a,
const FloatV b)
167 ASSERT_ISVALIDFLOATV(a);
168 ASSERT_ISVALIDFLOATV(b);
169 return vget_lane_u32(vceq_f32(a, b), 0) != 0;
172PX_FORCE_INLINE bool allElementsEqualVec3V(
const Vec3V a,
const Vec3V b)
174 ASSERT_ISVALIDVEC3V(a);
175 ASSERT_ISVALIDVEC3V(b);
176 return V3AllEq(a, b) != 0;
179PX_FORCE_INLINE bool allElementsEqualVec4V(
const Vec4V a,
const Vec4V b)
181 return V4AllEq(a, b) != 0;
184PX_FORCE_INLINE bool allElementsEqualBoolV(
const BoolV a,
const BoolV b)
186 return internalUnitNeonSimd::BAllTrue4_R(vceqq_u32(a, b)) != 0;
191 return internalUnitNeonSimd::BAllTrue4_R(V4IsEqU32(a, b));
194PX_FORCE_INLINE bool allElementsEqualVecU32V(
const VecU32V a,
const VecU32V b)
196 return V4U32AllEq(a, b) != 0;
201 return vceqq_s32(a, b);
206 return internalUnitNeonSimd::BAllTrue4_R(V4IsEqI32(a, b));
209PX_FORCE_INLINE bool allElementsEqualVecI32V(
const VecI32V a,
const VecI32V b)
211 return V4I32AllEq(a, b) != 0;
214PX_FORCE_INLINE bool allElementsNearEqualFloatV(
const FloatV a,
const FloatV b)
216 ASSERT_ISVALIDFLOATV(a);
217 ASSERT_ISVALIDFLOATV(b);
219 const float32x2_t c = vsub_f32(a, b);
220 const float32x2_t error = vdup_n_f32(VECMATH_AOS_EPSILON);
222 const uint32x2_t greater = vcagt_f32(error, c);
223 const uint32x2_t min = vpmin_u32(greater, greater);
224 return vget_lane_u32(min, 0) != 0x0;
227PX_FORCE_INLINE bool allElementsNearEqualVec3V(
const Vec3V a,
const Vec3V b)
229 ASSERT_ISVALIDVEC3V(a);
230 ASSERT_ISVALIDVEC3V(b);
231 const float32x4_t c = vsubq_f32(a, b);
232 const float32x4_t error = vdupq_n_f32(VECMATH_AOS_EPSILON);
234 const uint32x4_t greater = vcagtq_f32(error, c);
235 return internalUnitNeonSimd::BAllTrue3_R(greater) != 0;
238PX_FORCE_INLINE bool allElementsNearEqualVec4V(
const Vec4V a,
const Vec4V b)
240 const float32x4_t c = vsubq_f32(a, b);
241 const float32x4_t error = vdupq_n_f32(VECMATH_AOS_EPSILON);
243 const uint32x4_t greater = vcagtq_f32(error, c);
244 return internalUnitNeonSimd::BAllTrue4_R(greater) != 0x0;
254 printf(
"%s: (%f, %f, %f, %f)\n", name, data[0], data[1], data[2], data[3]);
261 printf(
"%s: (%f, %f)\n", name, data[0], data[1]);
268 printf(
"%s: (0x%x, 0x%x, 0x%x, 0x%x)\n", name, data[0], data[1], data[2], data[3]);
275 printf(
"%s: (0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", name, data[0], data[1], data[2], data[3],
276 data[4], data[5], data[6], data[7]);
283 printf(
"%s: (0x%x, 0x%x, 0x%x, 0x%x)\n", name, data[0], data[1], data[2], data[3]);
290 printf(
"%s: (0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", name, data[0], data[1], data[2], data[3],
291 data[4], data[5], data[6], data[7]);
298 printf(
"%s: (0x%x, 0x%x, 0x%x, 0x%x)\n", name, data[0], data[1], data[2], data[3]);
305 printf(
"%s: (0x%x, 0x%x)\n", name, data[0], data[1]);
310 printf(
"%s: 0x%x\n", name, v);
315 printf(
"%s: %f\n", name, v);
318#define PRINT_VAR(X) printVar((X), #X)
319#define PRINT_VEC(X) printVec((X), #X)
320#define PRINT_VEC_TITLE(TITLE, X) printVec((X), TITLE #X)
330 vst1_f32(
reinterpret_cast<float32_t*
>(data), a);
337 vst1q_f32(
reinterpret_cast<float32_t*
>(data), a);
344 vst1q_f32(
reinterpret_cast<float32_t*
>(data), a);
350 ASSERT_ISVALIDFLOATV(a);
351 return vget_lane_u32(vreinterpret_u32_f32(a), 0) == 0;
356 const uint32x2_t dLow = vget_low_u32(vreinterpretq_u32_f32(a));
357 const uint32x2_t dMin = vpmin_u32(dLow, dLow);
359 return vget_lane_u32(dMin, 0) == 0 || vgetq_lane_u32(vreinterpretq_u32_f32(a), 2) == 0;
364 const uint32x2_t dHigh = vget_high_u32(vreinterpretq_u32_f32(a));
365 const uint32x2_t dLow = vget_low_u32(vreinterpretq_u32_f32(a));
367 const uint32x2_t dMin = vmin_u32(dHigh, dLow);
368 const uint32x2_t pairMin = vpmin_u32(dMin, dMin);
369 return vget_lane_u32(pairMin, 0) == 0;
378 return vdup_n_f32(
reinterpret_cast<const float32_t&
>(f));
383 ASSERT_ISALIGNED16(f);
384 return vld1_f32(
reinterpret_cast<const float32_t*
>(f));
389 PX_ALIGN(16, PxF32) data[4] = { f, f, f, 0.0f };
390 return V4LoadA(data);
395 return vdupq_n_f32(
reinterpret_cast<const float32_t&
>(f));
400 const PxU32 i =
static_cast<PxU32
>(-(
static_cast<PxI32
>(f)));
401 return vdupq_n_u32(i);
406 ASSERT_ISALIGNED16(&f);
407 PX_ALIGN(16, PxF32) data[4] = { f.x, f.y, f.z, 0.0f };
408 return V4LoadA(data);
413 PX_ALIGN(16, PxF32) data[4] = { f.x, f.y, f.z, 0.0f };
414 return V4LoadA(data);
419 ASSERT_ISALIGNED16(&f);
420 PX_ALIGN(16, PxF32) data[4] = { f.x, f.y, f.z, 0.0f };
421 return V4LoadA(data);
426 ASSERT_ISALIGNED16(f);
427 PX_ALIGN(16, PxF32) data[4] = { f[0], f[1], f[2], 0.0f };
428 return V4LoadA(data);
433 PX_ALIGN(16, PxF32) data[4] = { f[0], f[1], f[2], 0.0f };
434 return V4LoadA(data);
439 return vsetq_lane_f32(0.0f, v, 3);
454 return vcombine_f32(f, f);
459 return Vec3V_From_Vec4V(Vec4V_From_FloatV(f));
464 return Vec3V_From_Vec4V_WUndefined(Vec4V_From_FloatV(f));
469 PX_ALIGN(16, PxF32) data[4] = { f.x, f.y, f.z, 0.0f };
470 return V4LoadA(data);
475 return Mat33V(V3LoadU(m.column0), V3LoadU(m.column1), V3LoadU(m.column2));
480 V3StoreU(m.col0, out.column0);
481 V3StoreU(m.col1, out.column1);
482 V3StoreU(m.col2, out.column2);
487 ASSERT_ISALIGNED16(f);
488 return vld1q_f32(
reinterpret_cast<const float32_t*
>(f));
493 ASSERT_ISALIGNED16(f);
494 vst1q_f32(
reinterpret_cast<float32_t*
>(f), a);
500 vst1q_f32(
reinterpret_cast<float32_t*
>(f2), a);
509 ASSERT_ISALIGNED16(u);
510 vst1q_u32(
reinterpret_cast<uint32_t*
>(u), a);
515 ASSERT_ISALIGNED16(u);
516 vst1q_u32(
reinterpret_cast<uint32_t*
>(u), uv);
521 ASSERT_ISALIGNED16(i);
522 vst1q_s32(
reinterpret_cast<int32_t*
>(i), iv);
527 return vld1q_f32(
reinterpret_cast<const float32_t*
>(f));
532 const PX_ALIGN(16, PxU32) b[4] = {
static_cast<PxU32
>(-
static_cast<PxI32
>(f[0])),
533 static_cast<PxU32
>(-
static_cast<PxI32
>(f[1])),
534 static_cast<PxU32
>(-
static_cast<PxI32
>(f[2])),
535 static_cast<PxU32
>(-
static_cast<PxI32
>(f[3])) };
541 ASSERT_ISVALIDFLOATV(a);
543 *f = vget_lane_f32(a, 0);
548 *f = vget_lane_u32(vget_low_u32(a), 0);
553 ASSERT_ISALIGNED16(&f);
555 vst1q_f32(
reinterpret_cast<float32_t*
>(f2), a);
556 f = PxVec3(f2[0], f2[1], f2[2]);
562 vst1q_f32(
reinterpret_cast<float32_t*
>(f2), a);
563 f = PxVec3(f2[0], f2[1], f2[2]);
587 return FLoad(PX_EPS_REAL);
597 return FLoad(PX_MAX_REAL);
602 return FLoad(-PX_MAX_REAL);
607 return vreinterpret_f32_u32(vdup_n_u32(0));
612 return vreinterpret_f32_u32(vdup_n_u32(1));
617 return vreinterpret_f32_u32(vdup_n_u32(2));
622 return vreinterpret_f32_u32(vdup_n_u32(3));
627 return vreinterpret_f32_u32(vdup_n_u32(4));
632 ASSERT_ISVALIDFLOATV(f);
638 ASSERT_ISVALIDFLOATV(a);
639 ASSERT_ISVALIDFLOATV(b);
640 return vadd_f32(a, b);
645 ASSERT_ISVALIDFLOATV(a);
646 ASSERT_ISVALIDFLOATV(b);
647 return vsub_f32(a, b);
652 ASSERT_ISVALIDFLOATV(a);
653 ASSERT_ISVALIDFLOATV(b);
654 return vmul_f32(a, b);
660 float32x2_t recip = vrecpe_f32(in);
661 for(
int i = 0; i < n; ++i)
662 recip = vmul_f32(recip, vrecps_f32(in, recip));
669 float32x4_t recip = vrecpeq_f32(in);
670 for(
int i = 0; i < n; ++i)
671 recip = vmulq_f32(recip, vrecpsq_f32(recip, in));
678 float32x2_t rsqrt = vrsqrte_f32(in);
679 for(
int i = 0; i < n; ++i)
680 rsqrt = vmul_f32(rsqrt, vrsqrts_f32(vmul_f32(rsqrt, rsqrt), in));
687 float32x4_t rsqrt = vrsqrteq_f32(in);
688 for(
int i = 0; i < n; ++i)
689 rsqrt = vmulq_f32(rsqrt, vrsqrtsq_f32(vmulq_f32(rsqrt, rsqrt), in));
695 ASSERT_ISVALIDFLOATV(a);
696 ASSERT_ISVALIDFLOATV(b);
697 return vmul_f32(a, VRECIP(b));
702 ASSERT_ISVALIDFLOATV(a);
703 ASSERT_ISVALIDFLOATV(b);
704 return vmul_f32(a, VRECIPE(b));
709 ASSERT_ISVALIDFLOATV(a);
715 ASSERT_ISVALIDFLOATV(a);
721 ASSERT_ISVALIDFLOATV(a);
722 return VRECIPSQRT(a);
727 ASSERT_ISVALIDFLOATV(a);
728 return FSel(FIsEq(a, FZero()), a, vmul_f32(a, VRECIPSQRT(a)));
733 ASSERT_ISVALIDFLOATV(a);
734 return VRECIPSQRTE(a);
737PX_FORCE_INLINE FloatV FScaleAdd(
const FloatV a,
const FloatV b,
const FloatV c)
739 ASSERT_ISVALIDFLOATV(a);
740 ASSERT_ISVALIDFLOATV(b);
741 ASSERT_ISVALIDFLOATV(c);
742 return vmla_f32(c, a, b);
745PX_FORCE_INLINE FloatV FNegScaleSub(
const FloatV a,
const FloatV b,
const FloatV c)
747 ASSERT_ISVALIDFLOATV(a);
748 ASSERT_ISVALIDFLOATV(b);
749 ASSERT_ISVALIDFLOATV(c);
750 return vmls_f32(c, a, b);
755 ASSERT_ISVALIDFLOATV(a);
759PX_FORCE_INLINE FloatV FSel(
const BoolV c,
const FloatV a,
const FloatV b)
761 PX_ASSERT( vecMathTests::allElementsEqualBoolV(c, BTTTT()) ||
762 vecMathTests::allElementsEqualBoolV(c, BFFFF()));
763 ASSERT_ISVALIDFLOATV(vbsl_f32(vget_low_u32(c), a, b));
764 return vbsl_f32(vget_low_u32(c), a, b);
769 ASSERT_ISVALIDFLOATV(a);
770 ASSERT_ISVALIDFLOATV(b);
771 return vdupq_lane_u32(vcgt_f32(a, b), 0);
776 ASSERT_ISVALIDFLOATV(a);
777 ASSERT_ISVALIDFLOATV(b);
778 return vdupq_lane_u32(vcge_f32(a, b), 0);
783 ASSERT_ISVALIDFLOATV(a);
784 ASSERT_ISVALIDFLOATV(b);
785 return vdupq_lane_u32(vceq_f32(a, b), 0);
792 return vmax_f32(a, b);
799 return vmin_f32(a, b);
802PX_FORCE_INLINE FloatV FClamp(
const FloatV a,
const FloatV minV,
const FloatV maxV)
804 ASSERT_ISVALIDFLOATV(minV);
805 ASSERT_ISVALIDFLOATV(maxV);
806 return vmax_f32(vmin_f32(a, maxV), minV);
811 ASSERT_ISVALIDFLOATV(a);
812 ASSERT_ISVALIDFLOATV(b);
813 return vget_lane_u32(vcgt_f32(a, b), 0);
818 ASSERT_ISVALIDFLOATV(a);
819 ASSERT_ISVALIDFLOATV(b);
820 return vget_lane_u32(vcge_f32(a, b), 0);
825 ASSERT_ISVALIDFLOATV(a);
826 ASSERT_ISVALIDFLOATV(b);
827 return vget_lane_u32(vceq_f32(a, b), 0);
832 ASSERT_ISVALIDFLOATV(a);
835 const float32x2_t half = vdup_n_f32(0.5f);
836 const float32x2_t sign = vcvt_f32_u32((vshr_n_u32(vreinterpret_u32_f32(a), 31)));
837 const float32x2_t aPlusHalf = vadd_f32(a, half);
838 const float32x2_t aRound = vsub_f32(aPlusHalf, sign);
839 int32x2_t tmp = vcvt_s32_f32(aRound);
840 return vcvt_f32_s32(tmp);
845 ASSERT_ISVALIDFLOATV(a);
848 const FloatV recipTwoPi = FLoadA(g_PXReciprocalTwoPi.f);
849 const FloatV twoPi = FLoadA(g_PXTwoPi.f);
850 const FloatV tmp = FMul(a, recipTwoPi);
851 const FloatV b = FRound(tmp);
852 const FloatV V1 = FNegScaleSub(twoPi, b, a);
856 const FloatV V2 = FMul(V1, V1);
857 const FloatV V3 = FMul(V2, V1);
858 const FloatV V5 = FMul(V3, V2);
859 const FloatV V7 = FMul(V5, V2);
860 const FloatV V9 = FMul(V7, V2);
861 const FloatV V11 = FMul(V9, V2);
862 const FloatV V13 = FMul(V11, V2);
863 const FloatV V15 = FMul(V13, V2);
864 const FloatV V17 = FMul(V15, V2);
865 const FloatV V19 = FMul(V17, V2);
866 const FloatV V21 = FMul(V19, V2);
867 const FloatV V23 = FMul(V21, V2);
869 const Vec4V sinCoefficients0 = V4LoadA(g_PXSinCoefficients0.f);
870 const Vec4V sinCoefficients1 = V4LoadA(g_PXSinCoefficients1.f);
871 const Vec4V sinCoefficients2 = V4LoadA(g_PXSinCoefficients2.f);
873 const FloatV S1 = V4GetY(sinCoefficients0);
874 const FloatV S2 = V4GetZ(sinCoefficients0);
875 const FloatV S3 = V4GetW(sinCoefficients0);
876 const FloatV S4 = V4GetX(sinCoefficients1);
877 const FloatV S5 = V4GetY(sinCoefficients1);
878 const FloatV S6 = V4GetZ(sinCoefficients1);
879 const FloatV S7 = V4GetW(sinCoefficients1);
880 const FloatV S8 = V4GetX(sinCoefficients2);
881 const FloatV S9 = V4GetY(sinCoefficients2);
882 const FloatV S10 = V4GetZ(sinCoefficients2);
883 const FloatV S11 = V4GetW(sinCoefficients2);
886 Result = FScaleAdd(S1, V3, V1);
887 Result = FScaleAdd(S2, V5, Result);
888 Result = FScaleAdd(S3, V7, Result);
889 Result = FScaleAdd(S4, V9, Result);
890 Result = FScaleAdd(S5, V11, Result);
891 Result = FScaleAdd(S6, V13, Result);
892 Result = FScaleAdd(S7, V15, Result);
893 Result = FScaleAdd(S8, V17, Result);
894 Result = FScaleAdd(S9, V19, Result);
895 Result = FScaleAdd(S10, V21, Result);
896 Result = FScaleAdd(S11, V23, Result);
903 ASSERT_ISVALIDFLOATV(a);
906 const FloatV recipTwoPi = FLoadA(g_PXReciprocalTwoPi.f);
907 const FloatV twoPi = FLoadA(g_PXTwoPi.f);
908 const FloatV tmp = FMul(a, recipTwoPi);
909 const FloatV b = FRound(tmp);
910 const FloatV V1 = FNegScaleSub(twoPi, b, a);
914 const FloatV V2 = FMul(V1, V1);
915 const FloatV V4 = FMul(V2, V2);
916 const FloatV V6 = FMul(V4, V2);
917 const FloatV V8 = FMul(V4, V4);
918 const FloatV V10 = FMul(V6, V4);
919 const FloatV V12 = FMul(V6, V6);
920 const FloatV V14 = FMul(V8, V6);
921 const FloatV V16 = FMul(V8, V8);
922 const FloatV V18 = FMul(V10, V8);
923 const FloatV V20 = FMul(V10, V10);
924 const FloatV V22 = FMul(V12, V10);
926 const Vec4V cosCoefficients0 = V4LoadA(g_PXCosCoefficients0.f);
927 const Vec4V cosCoefficients1 = V4LoadA(g_PXCosCoefficients1.f);
928 const Vec4V cosCoefficients2 = V4LoadA(g_PXCosCoefficients2.f);
930 const FloatV C1 = V4GetY(cosCoefficients0);
931 const FloatV C2 = V4GetZ(cosCoefficients0);
932 const FloatV C3 = V4GetW(cosCoefficients0);
933 const FloatV C4 = V4GetX(cosCoefficients1);
934 const FloatV C5 = V4GetY(cosCoefficients1);
935 const FloatV C6 = V4GetZ(cosCoefficients1);
936 const FloatV C7 = V4GetW(cosCoefficients1);
937 const FloatV C8 = V4GetX(cosCoefficients2);
938 const FloatV C9 = V4GetY(cosCoefficients2);
939 const FloatV C10 = V4GetZ(cosCoefficients2);
940 const FloatV C11 = V4GetW(cosCoefficients2);
943 Result = FScaleAdd(C1, V2, FOne());
944 Result = FScaleAdd(C2, V4, Result);
945 Result = FScaleAdd(C3, V6, Result);
946 Result = FScaleAdd(C4, V8, Result);
947 Result = FScaleAdd(C5, V10, Result);
948 Result = FScaleAdd(C6, V12, Result);
949 Result = FScaleAdd(C7, V14, Result);
950 Result = FScaleAdd(C8, V16, Result);
951 Result = FScaleAdd(C9, V18, Result);
952 Result = FScaleAdd(C10, V20, Result);
953 Result = FScaleAdd(C11, V22, Result);
958PX_FORCE_INLINE PxU32 FOutOfBounds(
const FloatV a,
const FloatV min,
const FloatV max)
960 ASSERT_ISVALIDFLOATV(a);
961 ASSERT_ISVALIDFLOATV(min);
962 ASSERT_ISVALIDFLOATV(max);
964 const BoolV c = BOr(FIsGrtr(a, max), FIsGrtr(min, a));
965 return PxU32(!BAllEqFFFF(c));
968PX_FORCE_INLINE PxU32 FInBounds(
const FloatV a,
const FloatV min,
const FloatV max)
970 ASSERT_ISVALIDFLOATV(a);
971 ASSERT_ISVALIDFLOATV(min);
972 ASSERT_ISVALIDFLOATV(max);
974 const BoolV c = BAnd(FIsGrtrOrEq(a, min), FIsGrtrOrEq(max, a));
975 return PxU32(BAllEqTTTT(c));
980 ASSERT_ISVALIDFLOATV(a);
981 ASSERT_ISVALIDFLOATV(bounds);
982 const uint32x2_t greater = vcagt_f32(a, bounds);
983 return vget_lane_u32(greater, 0);
988 ASSERT_ISVALIDFLOATV(a);
989 ASSERT_ISVALIDFLOATV(bounds);
990 const uint32x2_t geq = vcage_f32(bounds, a);
991 return vget_lane_u32(geq, 0);
1000 ASSERT_ISVALIDFLOATV(f);
1002 const uint32x2_t mask = { 0xffffFFFF, 0x0 };
1003 const uint32x2_t uHigh = vreinterpret_u32_f32(f);
1004 const float32x2_t dHigh = vreinterpret_f32_u32(vand_u32(uHigh, mask));
1006 return vcombine_f32(f, dHigh);
1009PX_FORCE_INLINE Vec3V V3Merge(
const FloatVArg x,
const FloatVArg y,
const FloatVArg z)
1011 ASSERT_ISVALIDFLOATV(x);
1012 ASSERT_ISVALIDFLOATV(y);
1013 ASSERT_ISVALIDFLOATV(z);
1015 const uint32x2_t mask = { 0xffffFFFF, 0x0 };
1016 const uint32x2_t dHigh = vand_u32(vreinterpret_u32_f32(z), mask);
1017 const uint32x2_t dLow = vext_u32(vreinterpret_u32_f32(x), vreinterpret_u32_f32(y), 1);
1018 return vreinterpretq_f32_u32(vcombine_u32(dLow, dHigh));
1023 const float32x4_t x = { 1.0f, 0.0f, 0.0f, 0.0f };
1029 const float32x4_t y = { 0, 1.0f, 0, 0 };
1035 const float32x4_t z = { 0, 0, 1.0f, 0 };
1041 ASSERT_ISVALIDVEC3V(f);
1042 const float32x2_t fLow = vget_low_f32(f);
1043 return vdup_lane_f32(fLow, 0);
1048 ASSERT_ISVALIDVEC3V(f);
1049 const float32x2_t fLow = vget_low_f32(f);
1050 return vdup_lane_f32(fLow, 1);
1055 ASSERT_ISVALIDVEC3V(f);
1056 const float32x2_t fhigh = vget_high_f32(f);
1057 return vdup_lane_f32(fhigh, 0);
1062 ASSERT_ISVALIDVEC3V(v);
1063 ASSERT_ISVALIDFLOATV(f);
1064 return V4Sel(BFTTT(), v, vcombine_f32(f, f));
1069 ASSERT_ISVALIDVEC3V(v);
1070 ASSERT_ISVALIDFLOATV(f);
1071 return V4Sel(BTFTT(), v, vcombine_f32(f, f));
1076 ASSERT_ISVALIDVEC3V(v);
1077 ASSERT_ISVALIDFLOATV(f);
1078 return V4Sel(BTTFT(), v, vcombine_f32(f, f));
1081PX_FORCE_INLINE Vec3V V3ColX(
const Vec3V a,
const Vec3V b,
const Vec3V c)
1083 ASSERT_ISVALIDVEC3V(a);
1084 ASSERT_ISVALIDVEC3V(b);
1085 ASSERT_ISVALIDVEC3V(c);
1087 const float32x2_t aLow = vget_low_f32(a);
1088 const float32x2_t bLow = vget_low_f32(b);
1089 const float32x2_t cLow = vget_low_f32(c);
1090 const float32x2_t
zero = vdup_n_f32(0.0f);
1092 const float32x2x2_t zipL = vzip_f32(aLow, bLow);
1093 const float32x2x2_t zipH = vzip_f32(cLow, zero);
1095 return vcombine_f32(zipL.val[0], zipH.val[0]);
1098PX_FORCE_INLINE Vec3V V3ColY(
const Vec3V a,
const Vec3V b,
const Vec3V c)
1100 ASSERT_ISVALIDVEC3V(a);
1101 ASSERT_ISVALIDVEC3V(b);
1102 ASSERT_ISVALIDVEC3V(c);
1104 const float32x2_t aLow = vget_low_f32(a);
1105 const float32x2_t bLow = vget_low_f32(b);
1106 const float32x2_t cLow = vget_low_f32(c);
1107 const float32x2_t
zero = vdup_n_f32(0.0f);
1109 const float32x2x2_t zipL = vzip_f32(aLow, bLow);
1110 const float32x2x2_t zipH = vzip_f32(cLow, zero);
1112 return vcombine_f32(zipL.val[1], zipH.val[1]);
1115PX_FORCE_INLINE Vec3V V3ColZ(
const Vec3V a,
const Vec3V b,
const Vec3V c)
1117 ASSERT_ISVALIDVEC3V(a);
1118 ASSERT_ISVALIDVEC3V(b);
1119 ASSERT_ISVALIDVEC3V(c);
1121 const float32x2_t aHi = vget_high_f32(a);
1122 const float32x2_t bHi = vget_high_f32(b);
1123 const float32x2_t cHi = vget_high_f32(c);
1125 const float32x2x2_t zipL = vzip_f32(aHi, bHi);
1127 return vcombine_f32(zipL.val[0], cHi);
1132 return vdupq_n_f32(0.0f);
1137 return V3Load(PX_EPS_REAL);
1142 return V3Load(1.0f);
1147 ASSERT_ISVALIDVEC3V(f);
1148 const float32x4_t tmp = vnegq_f32(f);
1149 return vsetq_lane_f32(0.0f, tmp, 3);
1154 ASSERT_ISVALIDVEC3V(a);
1155 ASSERT_ISVALIDVEC3V(b);
1156 return vaddq_f32(a, b);
1161 ASSERT_ISVALIDVEC3V(a);
1162 ASSERT_ISVALIDFLOATV(b);
1163 return vaddq_f32(a, Vec3V_From_FloatV(b));
1168 ASSERT_ISVALIDVEC3V(a);
1169 ASSERT_ISVALIDVEC3V(b);
1170 return vsubq_f32(a, b);
1175 ASSERT_ISVALIDVEC3V(a);
1176 ASSERT_ISVALIDFLOATV(b);
1177 return vsubq_f32(a, Vec3V_From_FloatV(b));
1182 ASSERT_ISVALIDVEC3V(a);
1183 ASSERT_ISVALIDFLOATV(b);
1184 const float32x4_t tmp = vmulq_lane_f32(a, b, 0);
1185 return vsetq_lane_f32(0.0f, tmp, 3);
1190 ASSERT_ISVALIDVEC3V(a);
1191 ASSERT_ISVALIDVEC3V(b);
1192 return vmulq_f32(a, b);
1197 ASSERT_ISVALIDVEC3V(a);
1198 ASSERT_ISVALIDFLOATV(b);
1199 const float32x2_t invB = VRECIP(b);
1200 const float32x4_t tmp = vmulq_lane_f32(a, invB, 0);
1201 return vsetq_lane_f32(0.0f, tmp, 3);
1206 ASSERT_ISVALIDVEC3V(a);
1207 ASSERT_ISVALIDVEC3V(b);
1208 float32x4_t invB = VRECIPQ(b);
1209 invB = vsetq_lane_f32(0.0f, invB, 3);
1210 return vmulq_f32(a, invB);
1215 ASSERT_ISVALIDVEC3V(a);
1216 ASSERT_ISVALIDFLOATV(b);
1217 const float32x2_t invB = VRECIPE(b);
1218 const float32x4_t tmp = vmulq_lane_f32(a, invB, 0);
1219 return vsetq_lane_f32(0.0f, tmp, 3);
1224 ASSERT_ISVALIDVEC3V(a);
1225 ASSERT_ISVALIDVEC3V(b);
1226 float32x4_t invB = VRECIPEQ(b);
1227 invB = vsetq_lane_f32(0.0f, invB, 3);
1228 return vmulq_f32(a, invB);
1233 ASSERT_ISVALIDVEC3V(a);
1234 const float32x4_t recipA = VRECIPQ(a);
1235 return vsetq_lane_f32(0.0f, recipA, 3);
1240 ASSERT_ISVALIDVEC3V(a);
1241 const float32x4_t recipA = VRECIPEQ(a);
1242 return vsetq_lane_f32(0.0f, recipA, 3);
1247 ASSERT_ISVALIDVEC3V(a);
1248 const float32x4_t rSqrA = VRECIPSQRTQ(a);
1249 return vsetq_lane_f32(0.0f, rSqrA, 3);
1254 ASSERT_ISVALIDVEC3V(a);
1255 const float32x4_t rSqrA = VRECIPSQRTEQ(a);
1256 return vsetq_lane_f32(0.0f, rSqrA, 3);
1259PX_FORCE_INLINE Vec3V V3ScaleAdd(
const Vec3V a,
const FloatV b,
const Vec3V c)
1261 ASSERT_ISVALIDVEC3V(a);
1262 ASSERT_ISVALIDFLOATV(b);
1263 ASSERT_ISVALIDVEC3V(c);
1265 float32x4_t tmp = vmlaq_lane_f32(c, a, b, 0);
1274 float32x2_t w_z = vget_high_f32(tmp);
1275 float32x2_t y_x = vget_low_f32(tmp);
1276 w_z = vset_lane_f32(0.0f, w_z, 1);
1277 return vcombine_f32(y_x, w_z);
1280PX_FORCE_INLINE Vec3V V3NegScaleSub(
const Vec3V a,
const FloatV b,
const Vec3V c)
1282 ASSERT_ISVALIDVEC3V(a);
1283 ASSERT_ISVALIDFLOATV(b);
1284 ASSERT_ISVALIDVEC3V(c);
1286 float32x4_t tmp = vmlsq_lane_f32(c, a, b, 0);
1295 float32x2_t w_z = vget_high_f32(tmp);
1296 float32x2_t y_x = vget_low_f32(tmp);
1297 w_z = vset_lane_f32(0.0f, w_z, 1);
1298 return vcombine_f32(y_x, w_z);
1301PX_FORCE_INLINE Vec3V V3MulAdd(
const Vec3V a,
const Vec3V b,
const Vec3V c)
1303 ASSERT_ISVALIDVEC3V(a);
1304 ASSERT_ISVALIDVEC3V(b);
1305 ASSERT_ISVALIDVEC3V(c);
1306 return vmlaq_f32(c, a, b);
1309PX_FORCE_INLINE Vec3V V3NegMulSub(
const Vec3V a,
const Vec3V b,
const Vec3V c)
1311 ASSERT_ISVALIDVEC3V(a);
1312 ASSERT_ISVALIDVEC3V(b);
1313 ASSERT_ISVALIDVEC3V(c);
1314 return vmlsq_f32(c, a, b);
1319 ASSERT_ISVALIDVEC3V(a);
1320 return vabsq_f32(a);
1325 ASSERT_ISVALIDVEC3V(a);
1326 ASSERT_ISVALIDVEC3V(b);
1329 const float32x4_t tmp = vmulq_f32(a, b);
1331 const float32x2_t low = vget_low_f32(tmp);
1332 const float32x2_t high = vget_high_f32(tmp);
1335 const float32x2_t sumTmp = vpadd_f32(low, high);
1336 const float32x2_t sum0ZYX = vpadd_f32(sumTmp, sumTmp);
1343 ASSERT_ISVALIDVEC3V(a);
1344 ASSERT_ISVALIDVEC3V(b);
1346 const uint32x2_t TF = { 0xffffFFFF, 0x0 };
1347 const float32x2_t ay_ax = vget_low_f32(a);
1348 const float32x2_t aw_az = vget_high_f32(a);
1349 const float32x2_t by_bx = vget_low_f32(b);
1350 const float32x2_t bw_bz = vget_high_f32(b);
1352 const float32x2_t bz_by = vext_f32(by_bx, bw_bz, 1);
1353 const float32x2_t az_ay = vext_f32(ay_ax, aw_az, 1);
1355 const float32x2_t azbx = vmul_f32(aw_az, by_bx);
1356 const float32x2_t aybz_axby = vmul_f32(ay_ax, bz_by);
1358 const float32x2_t azbxSUBaxbz = vmls_f32(azbx, bw_bz, ay_ax);
1359 const float32x2_t aybzSUBazby_axbySUBaybx = vmls_f32(aybz_axby, by_bx, az_ay);
1361 const float32x2_t retLow = vext_f32(aybzSUBazby_axbySUBaybx, azbxSUBaxbz, 1);
1362 const uint32x2_t retHigh = vand_u32(TF, vreinterpret_u32_f32(aybzSUBazby_axbySUBaybx));
1364 return vcombine_f32(retLow, vreinterpret_f32_u32(retHigh));
1369 ASSERT_ISVALIDVEC3V(a);
1375 ASSERT_ISVALIDVEC3V(a);
1379 const float32x4_t tmp = vmulq_f32(a, a);
1380 const float32x2_t low = vget_low_f32(tmp);
1381 const float32x2_t high = vget_high_f32(tmp);
1384 const float32x2_t sumTmp = vpadd_f32(low, high);
1385 const float32x2_t sum0ZYX = vpadd_f32(sumTmp, sumTmp);
1387 return FSqrt(sum0ZYX);
1392 ASSERT_ISVALIDVEC3V(a);
1398 ASSERT_ISVALIDVEC3V(a);
1400 return V3ScaleInv(a, V3Length(a));
1405 ASSERT_ISVALIDVEC3V(a);
1407 return V3Scale(a, VRECIPSQRTE(V3Dot(a, a)));
1410PX_FORCE_INLINE Vec3V V3NormalizeSafe(
const Vec3V a,
const Vec3V unsafeReturnValue)
1412 ASSERT_ISVALIDVEC3V(a);
1413 const FloatV
zero = vdup_n_f32(0.0f);
1414 const FloatV length = V3Length(a);
1415 const uint32x4_t isGreaterThanZero = FIsGrtr(length, zero);
1416 return V3Sel(isGreaterThanZero, V3ScaleInv(a, length), unsafeReturnValue);
1419PX_FORCE_INLINE Vec3V V3Sel(
const BoolV c,
const Vec3V a,
const Vec3V b)
1421 ASSERT_ISVALIDVEC3V( vbslq_f32(c, a, b));
1422 return vbslq_f32(c, a, b);
1427 ASSERT_ISVALIDVEC3V(a);
1428 ASSERT_ISVALIDVEC3V(b);
1429 return vcgtq_f32(a, b);
1434 ASSERT_ISVALIDVEC3V(a);
1435 ASSERT_ISVALIDVEC3V(b);
1436 return vcgeq_f32(a, b);
1441 ASSERT_ISVALIDVEC3V(a);
1442 ASSERT_ISVALIDVEC3V(b);
1443 return vceqq_f32(a, b);
1448 ASSERT_ISVALIDVEC3V(a);
1449 ASSERT_ISVALIDVEC3V(b);
1450 return vmaxq_f32(a, b);
1455 ASSERT_ISVALIDVEC3V(a);
1456 ASSERT_ISVALIDVEC3V(b);
1457 return vminq_f32(a, b);
1462 ASSERT_ISVALIDVEC3V(a);
1464 const float32x2_t low = vget_low_f32(a);
1465 const float32x2_t high = vget_high_f32(a);
1467 const float32x2_t zz = vdup_lane_f32(high, 0);
1468 const float32x2_t max0 = vpmax_f32(zz, low);
1469 const float32x2_t max1 = vpmax_f32(max0, max0);
1476 ASSERT_ISVALIDVEC3V(a);
1478 const float32x2_t low = vget_low_f32(a);
1479 const float32x2_t high = vget_high_f32(a);
1481 const float32x2_t zz = vdup_lane_f32(high, 0);
1482 const float32x2_t min0 = vpmin_f32(zz, low);
1483 const float32x2_t min1 = vpmin_f32(min0, min0);
1491 ASSERT_ISVALIDVEC3V(a);
1492 const Vec3V
zero = V3Zero();
1493 const Vec3V one = V3One();
1494 const Vec3V none = V3Neg(one);
1495 return V3Sel(V3IsGrtrOrEq(a, zero), one, none);
1498PX_FORCE_INLINE Vec3V V3Clamp(
const Vec3V a,
const Vec3V minV,
const Vec3V maxV)
1500 ASSERT_ISVALIDVEC3V(minV);
1501 ASSERT_ISVALIDVEC3V(maxV);
1502 return V3Max(V3Min(a, maxV), minV);
1507 ASSERT_ISVALIDVEC3V(a);
1508 ASSERT_ISVALIDVEC3V(b);
1509 return internalUnitNeonSimd::BAllTrue3_R(V4IsGrtr(a, b));
1514 ASSERT_ISVALIDVEC3V(a);
1515 ASSERT_ISVALIDVEC3V(b);
1516 return internalUnitNeonSimd::BAllTrue3_R(V4IsGrtrOrEq(a, b));
1521 ASSERT_ISVALIDVEC3V(a);
1522 ASSERT_ISVALIDVEC3V(b);
1523 return internalUnitNeonSimd::BAllTrue3_R(V4IsEq(a, b));
1528 ASSERT_ISVALIDVEC3V(a);
1530 const Vec3V half = V3Load(0.5f);
1531 const float32x4_t sign = vcvtq_f32_u32((vshrq_n_u32(vreinterpretq_u32_f32(a), 31)));
1532 const Vec3V aPlusHalf = V3Add(a, half);
1533 const Vec3V aRound = V3Sub(aPlusHalf, sign);
1534 return vcvtq_f32_s32(vcvtq_s32_f32(aRound));
1539 ASSERT_ISVALIDVEC3V(a);
1542 const Vec4V recipTwoPi = V4LoadA(g_PXReciprocalTwoPi.f);
1543 const Vec4V twoPi = V4LoadA(g_PXTwoPi.f);
1544 const Vec3V tmp = V4Mul(a, recipTwoPi);
1545 const Vec3V b = V3Round(tmp);
1546 const Vec3V V1 = V4NegMulSub(twoPi, b, a);
1550 const Vec3V V2 = V3Mul(V1, V1);
1551 const Vec3V V3 = V3Mul(V2, V1);
1552 const Vec3V V5 = V3Mul(V3, V2);
1553 const Vec3V V7 = V3Mul(V5, V2);
1554 const Vec3V V9 = V3Mul(V7, V2);
1555 const Vec3V V11 = V3Mul(V9, V2);
1556 const Vec3V V13 = V3Mul(V11, V2);
1557 const Vec3V V15 = V3Mul(V13, V2);
1558 const Vec3V V17 = V3Mul(V15, V2);
1559 const Vec3V V19 = V3Mul(V17, V2);
1560 const Vec3V V21 = V3Mul(V19, V2);
1561 const Vec3V V23 = V3Mul(V21, V2);
1563 const Vec4V sinCoefficients0 = V4LoadA(g_PXSinCoefficients0.f);
1564 const Vec4V sinCoefficients1 = V4LoadA(g_PXSinCoefficients1.f);
1565 const Vec4V sinCoefficients2 = V4LoadA(g_PXSinCoefficients2.f);
1567 const FloatV S1 = V4GetY(sinCoefficients0);
1568 const FloatV S2 = V4GetZ(sinCoefficients0);
1569 const FloatV S3 = V4GetW(sinCoefficients0);
1570 const FloatV S4 = V4GetX(sinCoefficients1);
1571 const FloatV S5 = V4GetY(sinCoefficients1);
1572 const FloatV S6 = V4GetZ(sinCoefficients1);
1573 const FloatV S7 = V4GetW(sinCoefficients1);
1574 const FloatV S8 = V4GetX(sinCoefficients2);
1575 const FloatV S9 = V4GetY(sinCoefficients2);
1576 const FloatV S10 = V4GetZ(sinCoefficients2);
1577 const FloatV S11 = V4GetW(sinCoefficients2);
1580 Result = V4ScaleAdd(V3, S1, V1);
1581 Result = V4ScaleAdd(V5, S2, Result);
1582 Result = V4ScaleAdd(V7, S3, Result);
1583 Result = V4ScaleAdd(V9, S4, Result);
1584 Result = V4ScaleAdd(V11, S5, Result);
1585 Result = V4ScaleAdd(V13, S6, Result);
1586 Result = V4ScaleAdd(V15, S7, Result);
1587 Result = V4ScaleAdd(V17, S8, Result);
1588 Result = V4ScaleAdd(V19, S9, Result);
1589 Result = V4ScaleAdd(V21, S10, Result);
1590 Result = V4ScaleAdd(V23, S11, Result);
1597 ASSERT_ISVALIDVEC3V(a);
1600 const Vec4V recipTwoPi = V4LoadA(g_PXReciprocalTwoPi.f);
1601 const Vec4V twoPi = V4LoadA(g_PXTwoPi.f);
1602 const Vec3V tmp = V4Mul(a, recipTwoPi);
1603 const Vec3V b = V3Round(tmp);
1604 const Vec3V V1 = V4NegMulSub(twoPi, b, a);
1608 const Vec3V V2 = V3Mul(V1, V1);
1609 const Vec3V V4 = V3Mul(V2, V2);
1610 const Vec3V V6 = V3Mul(V4, V2);
1611 const Vec3V V8 = V3Mul(V4, V4);
1612 const Vec3V V10 = V3Mul(V6, V4);
1613 const Vec3V V12 = V3Mul(V6, V6);
1614 const Vec3V V14 = V3Mul(V8, V6);
1615 const Vec3V V16 = V3Mul(V8, V8);
1616 const Vec3V V18 = V3Mul(V10, V8);
1617 const Vec3V V20 = V3Mul(V10, V10);
1618 const Vec3V V22 = V3Mul(V12, V10);
1620 const Vec4V cosCoefficients0 = V4LoadA(g_PXCosCoefficients0.f);
1621 const Vec4V cosCoefficients1 = V4LoadA(g_PXCosCoefficients1.f);
1622 const Vec4V cosCoefficients2 = V4LoadA(g_PXCosCoefficients2.f);
1624 const FloatV C1 = V4GetY(cosCoefficients0);
1625 const FloatV C2 = V4GetZ(cosCoefficients0);
1626 const FloatV C3 = V4GetW(cosCoefficients0);
1627 const FloatV C4 = V4GetX(cosCoefficients1);
1628 const FloatV C5 = V4GetY(cosCoefficients1);
1629 const FloatV C6 = V4GetZ(cosCoefficients1);
1630 const FloatV C7 = V4GetW(cosCoefficients1);
1631 const FloatV C8 = V4GetX(cosCoefficients2);
1632 const FloatV C9 = V4GetY(cosCoefficients2);
1633 const FloatV C10 = V4GetZ(cosCoefficients2);
1634 const FloatV C11 = V4GetW(cosCoefficients2);
1637 Result = V4ScaleAdd(V2, C1, V4One());
1638 Result = V4ScaleAdd(V4, C2, Result);
1639 Result = V4ScaleAdd(V6, C3, Result);
1640 Result = V4ScaleAdd(V8, C4, Result);
1641 Result = V4ScaleAdd(V10, C5, Result);
1642 Result = V4ScaleAdd(V12, C6, Result);
1643 Result = V4ScaleAdd(V14, C7, Result);
1644 Result = V4ScaleAdd(V16, C8, Result);
1645 Result = V4ScaleAdd(V18, C9, Result);
1646 Result = V4ScaleAdd(V20, C10, Result);
1647 Result = V4ScaleAdd(V22, C11, Result);
1649 return V4ClearW(Result);
1654 ASSERT_ISVALIDVEC3V(a);
1655 const float32x2_t xy = vget_low_f32(a);
1656 const float32x2_t zw = vget_high_f32(a);
1657 const float32x2_t yz = vext_f32(xy, zw, 1);
1658 return vcombine_f32(yz, zw);
1663 ASSERT_ISVALIDVEC3V(a);
1665 const uint32x2_t mask = { 0xffffFFFF, 0x0 };
1666 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(a));
1667 const uint32x2_t xw = vand_u32(xy, mask);
1668 return vreinterpretq_f32_u32(vcombine_u32(xy, xw));
1673 ASSERT_ISVALIDVEC3V(a);
1675 const uint32x2_t mask = { 0xffffFFFF, 0x0 };
1676 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(a));
1677 const uint32x2_t zw = vget_high_u32(vreinterpretq_u32_f32(a));
1678 const uint32x2_t yz = vext_u32(xy, zw, 1);
1679 const uint32x2_t xw = vand_u32(xy, mask);
1680 return vreinterpretq_f32_u32(vcombine_u32(yz, xw));
1685 ASSERT_ISVALIDVEC3V(a);
1687 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(a));
1688 const uint32x2_t zw = vget_high_u32(vreinterpretq_u32_f32(a));
1689 const uint32x2_t wz = vrev64_u32(zw);
1691 const uint32x2_t zx = vext_u32(wz, xy, 1);
1692 const uint32x2_t yw = vext_u32(xy, wz, 1);
1694 return vreinterpretq_f32_u32(vcombine_u32(zx, yw));
1699 ASSERT_ISVALIDVEC3V(a);
1701 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(a));
1702 const uint32x2_t zw = vget_high_u32(vreinterpretq_u32_f32(a));
1704 const uint32x2_t wz = vrev64_u32(zw);
1705 const uint32x2_t yw = vext_u32(xy, wz, 1);
1706 const uint32x2_t zz = vdup_lane_u32(wz, 1);
1708 return vreinterpretq_f32_u32(vcombine_u32(zz, yw));
1713 ASSERT_ISVALIDVEC3V(a);
1715 const uint32x2_t mask = { 0xffffFFFF, 0x0 };
1716 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(a));
1717 const uint32x2_t yx = vrev64_u32(xy);
1718 const uint32x2_t xw = vand_u32(xy, mask);
1719 return vreinterpretq_f32_u32(vcombine_u32(yx, xw));
1722PX_FORCE_INLINE Vec3V V3Perm_Zero_1Z_0Y(
const Vec3V v0,
const Vec3V v1)
1724 ASSERT_ISVALIDVEC3V(v0);
1725 ASSERT_ISVALIDVEC3V(v1);
1727 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(v0));
1728 const uint32x2_t zw = vget_high_u32(vreinterpretq_u32_f32(v1));
1729 const uint32x2_t wz = vrev64_u32(zw);
1730 const uint32x2_t yw = vext_u32(xy, wz, 1);
1732 return vreinterpretq_f32_u32(vcombine_u32(wz, yw));
1735PX_FORCE_INLINE Vec3V V3Perm_0Z_Zero_1X(
const Vec3V v0,
const Vec3V v1)
1737 ASSERT_ISVALIDVEC3V(v0);
1738 ASSERT_ISVALIDVEC3V(v1);
1740 const uint32x2_t mask = { 0xffffFFFF, 0x0 };
1741 const uint32x2_t zw = vget_high_u32(vreinterpretq_u32_f32(v0));
1742 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(v1));
1743 const uint32x2_t xw = vand_u32(xy, mask);
1745 return vreinterpretq_f32_u32(vcombine_u32(zw, xw));
1748PX_FORCE_INLINE Vec3V V3Perm_1Y_0X_Zero(
const Vec3V v0,
const Vec3V v1)
1750 ASSERT_ISVALIDVEC3V(v0);
1751 ASSERT_ISVALIDVEC3V(v1);
1753 const uint32x2_t axy = vget_low_u32(vreinterpretq_u32_f32(v0));
1754 const uint32x2_t bxy = vget_low_u32(vreinterpretq_u32_f32(v1));
1755 const uint32x2_t byax = vext_u32(bxy, axy, 1);
1756 const uint32x2_t ww = vdup_n_u32(0);
1758 return vreinterpretq_f32_u32(vcombine_u32(byax, ww));
1763 ASSERT_ISVALIDVEC3V(a);
1767 const float32x2_t low = vget_low_f32(a);
1768 const float32x2_t high = vget_high_f32(a);
1771 const float32x2_t sumTmp = vpadd_f32(low, high);
1772 const float32x2_t sum0ZYX = vpadd_f32(sumTmp, sumTmp);
1777PX_FORCE_INLINE PxU32 V3OutOfBounds(
const Vec3V a,
const Vec3V min,
const Vec3V max)
1779 ASSERT_ISVALIDVEC3V(a);
1780 ASSERT_ISVALIDVEC3V(min);
1781 ASSERT_ISVALIDVEC3V(max);
1783 const BoolV c = BOr(V3IsGrtr(a, max), V3IsGrtr(min, a));
1784 return internalUnitNeonSimd::BAnyTrue3_R(c);
1787PX_FORCE_INLINE PxU32 V3InBounds(
const Vec3V a,
const Vec3V min,
const Vec3V max)
1789 ASSERT_ISVALIDVEC3V(a);
1790 ASSERT_ISVALIDVEC3V(min);
1791 ASSERT_ISVALIDVEC3V(max);
1793 const BoolV c = BAnd(V3IsGrtrOrEq(a, min), V3IsGrtrOrEq(max, a));
1794 return internalUnitNeonSimd::BAllTrue4_R(c);
1799 ASSERT_ISVALIDVEC3V(a);
1800 ASSERT_ISVALIDVEC3V(bounds);
1802 const BoolV greater = V3IsGrtr(V3Abs(a), bounds);
1803 return internalUnitNeonSimd::BAnyTrue3_R(greater);
1808 ASSERT_ISVALIDVEC3V(a);
1809 ASSERT_ISVALIDVEC3V(bounds);
1811 const BoolV greaterOrEq = V3IsGrtrOrEq(bounds, V3Abs(a));
1812 return internalUnitNeonSimd::BAllTrue4_R(greaterOrEq);
1815PX_FORCE_INLINE void V3Transpose(Vec3V& col0, Vec3V& col1, Vec3V& col2)
1817 ASSERT_ISVALIDVEC3V(col0);
1818 ASSERT_ISVALIDVEC3V(col1);
1819 ASSERT_ISVALIDVEC3V(col2);
1821 Vec3V col3 = V3Zero();
1822 const float32x4x2_t v0v1 = vzipq_f32(col0, col2);
1823 const float32x4x2_t v2v3 = vzipq_f32(col1, col3);
1824 const float32x4x2_t zip0 = vzipq_f32(v0v1.val[0], v2v3.val[0]);
1825 const float32x4x2_t zip1 = vzipq_f32(v0v1.val[1], v2v3.val[1]);
1838 ASSERT_ISVALIDFLOATV(f);
1839 return vcombine_f32(f, f);
1844 ASSERT_ISVALIDFLOATV(floatVArray[0]);
1845 ASSERT_ISVALIDFLOATV(floatVArray[1]);
1846 ASSERT_ISVALIDFLOATV(floatVArray[2]);
1847 ASSERT_ISVALIDFLOATV(floatVArray[3]);
1849 const uint32x2_t xLow = vreinterpret_u32_f32(floatVArray[0]);
1850 const uint32x2_t yLow = vreinterpret_u32_f32(floatVArray[1]);
1851 const uint32x2_t zLow = vreinterpret_u32_f32(floatVArray[2]);
1852 const uint32x2_t wLow = vreinterpret_u32_f32(floatVArray[3]);
1854 const uint32x2_t dLow = vext_u32(xLow, yLow, 1);
1855 const uint32x2_t dHigh = vext_u32(zLow, wLow, 1);
1857 return vreinterpretq_f32_u32(vcombine_u32(dLow, dHigh));
1860PX_FORCE_INLINE Vec4V V4Merge(
const FloatVArg x,
const FloatVArg y,
const FloatVArg z,
const FloatVArg w)
1862 ASSERT_ISVALIDFLOATV(x);
1863 ASSERT_ISVALIDFLOATV(y);
1864 ASSERT_ISVALIDFLOATV(z);
1865 ASSERT_ISVALIDFLOATV(w);
1867 const uint32x2_t xLow = vreinterpret_u32_f32(x);
1868 const uint32x2_t yLow = vreinterpret_u32_f32(y);
1869 const uint32x2_t zLow = vreinterpret_u32_f32(z);
1870 const uint32x2_t wLow = vreinterpret_u32_f32(w);
1872 const uint32x2_t dLow = vext_u32(xLow, yLow, 1);
1873 const uint32x2_t dHigh = vext_u32(zLow, wLow, 1);
1875 return vreinterpretq_f32_u32(vcombine_u32(dLow, dHigh));
1878PX_FORCE_INLINE Vec4V V4MergeW(
const Vec4VArg x,
const Vec4VArg y,
const Vec4VArg z,
const Vec4VArg w)
1880 const float32x2_t xx = vget_high_f32(x);
1881 const float32x2_t yy = vget_high_f32(y);
1882 const float32x2_t zz = vget_high_f32(z);
1883 const float32x2_t ww = vget_high_f32(w);
1885 const float32x2x2_t zipL = vzip_f32(xx, yy);
1886 const float32x2x2_t zipH = vzip_f32(zz, ww);
1888 return vcombine_f32(zipL.val[1], zipH.val[1]);
1891PX_FORCE_INLINE Vec4V V4MergeZ(
const Vec4VArg x,
const Vec4VArg y,
const Vec4VArg z,
const Vec4VArg w)
1893 const float32x2_t xx = vget_high_f32(x);
1894 const float32x2_t yy = vget_high_f32(y);
1895 const float32x2_t zz = vget_high_f32(z);
1896 const float32x2_t ww = vget_high_f32(w);
1898 const float32x2x2_t zipL = vzip_f32(xx, yy);
1899 const float32x2x2_t zipH = vzip_f32(zz, ww);
1901 return vcombine_f32(zipL.val[0], zipH.val[0]);
1904PX_FORCE_INLINE Vec4V V4MergeY(
const Vec4VArg x,
const Vec4VArg y,
const Vec4VArg z,
const Vec4VArg w)
1906 const float32x2_t xx = vget_low_f32(x);
1907 const float32x2_t yy = vget_low_f32(y);
1908 const float32x2_t zz = vget_low_f32(z);
1909 const float32x2_t ww = vget_low_f32(w);
1911 const float32x2x2_t zipL = vzip_f32(xx, yy);
1912 const float32x2x2_t zipH = vzip_f32(zz, ww);
1914 return vcombine_f32(zipL.val[1], zipH.val[1]);
1917PX_FORCE_INLINE Vec4V V4MergeX(
const Vec4VArg x,
const Vec4VArg y,
const Vec4VArg z,
const Vec4VArg w)
1919 const float32x2_t xx = vget_low_f32(x);
1920 const float32x2_t yy = vget_low_f32(y);
1921 const float32x2_t zz = vget_low_f32(z);
1922 const float32x2_t ww = vget_low_f32(w);
1924 const float32x2x2_t zipL = vzip_f32(xx, yy);
1925 const float32x2x2_t zipH = vzip_f32(zz, ww);
1927 return vcombine_f32(zipL.val[0], zipH.val[0]);
1932 return vzipq_f32(a, b).val[0];
1937 return vzipq_f32(a, b).val[1];
1942 const float32x2_t zeros = vreinterpret_f32_u32(vmov_n_u32(0));
1943 const float32x2_t ones = vmov_n_f32(1.0f);
1944 const float32x2_t zo = vext_f32(zeros, ones, 1);
1945 return vcombine_f32(zeros, zo);
1950 const float32x2_t zeros = vreinterpret_f32_u32(vmov_n_u32(0));
1951 const float32x2_t ones = vmov_n_f32(1.0f);
1952 const float32x2_t oz = vext_f32(ones, zeros, 1);
1953 return vcombine_f32(oz, zeros);
1958 const float32x2_t zeros = vreinterpret_f32_u32(vmov_n_u32(0));
1959 const float32x2_t ones = vmov_n_f32(1.0f);
1960 const float32x2_t zo = vext_f32(zeros, ones, 1);
1961 return vcombine_f32(zo, zeros);
1966 const float32x2_t zeros = vreinterpret_f32_u32(vmov_n_u32(0));
1967 const float32x2_t ones = vmov_n_f32(1.0f);
1968 const float32x2_t oz = vext_f32(ones, zeros, 1);
1969 return vcombine_f32(zeros, oz);
1974 const float32x2_t fhigh = vget_high_f32(f);
1975 return vdup_lane_f32(fhigh, 1);
1980 const float32x2_t fLow = vget_low_f32(f);
1981 return vdup_lane_f32(fLow, 0);
1986 const float32x2_t fLow = vget_low_f32(f);
1987 return vdup_lane_f32(fLow, 1);
1992 const float32x2_t fhigh = vget_high_f32(f);
1993 return vdup_lane_f32(fhigh, 0);
1998 ASSERT_ISVALIDFLOATV(f);
1999 return V4Sel(BTTTF(), v, vcombine_f32(f, f));
2004 ASSERT_ISVALIDFLOATV(f);
2005 return V4Sel(BFTTT(), v, vcombine_f32(f, f));
2010 ASSERT_ISVALIDFLOATV(f);
2011 return V4Sel(BTFTT(), v, vcombine_f32(f, f));
2016 ASSERT_ISVALIDFLOATV(f);
2017 return V4Sel(BTTFT(), v, vcombine_f32(f, f));
2022 return V4Sel(BTTTF(), v, V4Zero());
2027 const float32x2_t xy = vget_low_f32(a);
2028 const float32x2_t zw = vget_high_f32(a);
2029 const float32x2_t yx = vext_f32(xy, xy, 1);
2030 const float32x2_t wz = vext_f32(zw, zw, 1);
2031 return vcombine_f32(yx, wz);
2036 const float32x2_t xy = vget_low_f32(a);
2037 const float32x2_t zw = vget_high_f32(a);
2038 const float32x2x2_t xzyw = vzip_f32(xy, zw);
2039 return vcombine_f32(xzyw.val[0], xzyw.val[0]);
2044 const float32x2_t xy = vget_low_f32(a);
2045 const float32x2_t zw = vget_high_f32(a);
2046 const float32x2x2_t xzyw = vzip_f32(xy, zw);
2047 return vcombine_f32(xzyw.val[1], xzyw.val[1]);
2052 const uint32x2_t xy = vget_low_u32(vreinterpretq_u32_f32(a));
2053 const uint32x2_t zw = vget_high_u32(vreinterpretq_u32_f32(a));
2054 const uint32x2_t yz = vext_u32(xy, zw, 1);
2055 const uint32x2_t xw = vrev64_u32(vext_u32(zw, xy, 1));
2056 return vreinterpretq_f32_u32(vcombine_u32(yz, xw));
2061 const float32x2_t low = vget_low_f32(a);
2062 const float32x2_t high = vget_high_f32(a);
2063 return vcombine_f32(high, low);
2066template <PxU8 E0, PxU8 E1, PxU8 E2, PxU8 E3>
2069 static const uint32_t ControlElement[4] =
2085 tbl.val[0] = vreinterpret_u8_f32(vget_low_f32(V));
2086 tbl.val[1] = vreinterpret_u8_f32(vget_high_f32(V));
2089 vcreate_u8(
static_cast<uint64_t>(ControlElement[E0]) | (
static_cast<uint64_t>(ControlElement[E1]) << 32));
2090 const uint8x8_t rL = vtbl2_u8(tbl, idx);
2091 idx = vcreate_u8(
static_cast<uint64_t>(ControlElement[E2]) | (
static_cast<uint64_t>(ControlElement[E3]) << 32));
2092 const uint8x8_t rH = vtbl2_u8(tbl, idx);
2093 return vreinterpretq_f32_u8(vcombine_u8(rL, rH));
2104 return vreinterpretq_f32_u32(vmovq_n_u32(0));
2110 return vmovq_n_f32(1.0f);
2116 return V4Load(PX_EPS_REAL);
2121 return vnegq_f32(f);
2126 return vaddq_f32(a, b);
2131 return vsubq_f32(a, b);
2136 return vmulq_lane_f32(a, b, 0);
2141 return vmulq_f32(a, b);
2146 ASSERT_ISVALIDFLOATV(b);
2147 const float32x2_t invB = VRECIP(b);
2148 return vmulq_lane_f32(a, invB, 0);
2153 const float32x4_t invB = VRECIPQ(b);
2154 return vmulq_f32(a, invB);
2159 ASSERT_ISVALIDFLOATV(b);
2160 const float32x2_t invB = VRECIPE(b);
2161 return vmulq_lane_f32(a, invB, 0);
2166 const float32x4_t invB = VRECIPEQ(b);
2167 return vmulq_f32(a, invB);
2182 return VRECIPSQRTQ(a);
2187 return VRECIPSQRTEQ(a);
2192 return V4Sel(V4IsEq(a, V4Zero()), a, V4Mul(a, VRECIPSQRTQ(a)));
2195PX_FORCE_INLINE Vec4V V4ScaleAdd(
const Vec4V a,
const FloatV b,
const Vec4V c)
2197 ASSERT_ISVALIDFLOATV(b);
2198 return vmlaq_lane_f32(c, a, b, 0);
2201PX_FORCE_INLINE Vec4V V4NegScaleSub(
const Vec4V a,
const FloatV b,
const Vec4V c)
2203 ASSERT_ISVALIDFLOATV(b);
2204 return vmlsq_lane_f32(c, a, b, 0);
2207PX_FORCE_INLINE Vec4V V4MulAdd(
const Vec4V a,
const Vec4V b,
const Vec4V c)
2209 return vmlaq_f32(c, a, b);
2212PX_FORCE_INLINE Vec4V V4NegMulSub(
const Vec4V a,
const Vec4V b,
const Vec4V c)
2214 return vmlsq_f32(c, a, b);
2219 return vabsq_f32(a);
2224 const Vec4V xy = V4UnpackXY(a, a);
2225 const Vec4V zw = V4UnpackZW(a, a);
2226 const Vec4V xz_yw = V4Add(xy, zw);
2227 const FloatV xz = V4GetX(xz_yw);
2228 const FloatV yw = V4GetZ(xz_yw);
2229 return FAdd(xz, yw);
2234 const float32x4_t tmp = vmulq_f32(a, b);
2235 const float32x2_t low = vget_low_f32(tmp);
2236 const float32x2_t high = vget_high_f32(tmp);
2238 const float32x2_t sumTmp = vpadd_f32(low, high);
2239 const float32x2_t sumWZYX = vpadd_f32(sumTmp, sumTmp);
2247 const Vec4V a = V4ClearW(aa);
2248 const Vec4V b = V4ClearW(bb);
2250 const float32x4_t tmp = vmulq_f32(a, b);
2251 const float32x2_t low = vget_low_f32(tmp);
2252 const float32x2_t high = vget_high_f32(tmp);
2254 const float32x2_t sumTmp = vpadd_f32(low, high);
2255 const float32x2_t sum0ZYX = vpadd_f32(sumTmp, sumTmp);
2261 const uint32x2_t TF = { 0xffffFFFF, 0x0 };
2262 const float32x2_t ay_ax = vget_low_f32(a);
2263 const float32x2_t aw_az = vget_high_f32(a);
2264 const float32x2_t by_bx = vget_low_f32(b);
2265 const float32x2_t bw_bz = vget_high_f32(b);
2267 const float32x2_t bz_by = vext_f32(by_bx, bw_bz, 1);
2268 const float32x2_t az_ay = vext_f32(ay_ax, aw_az, 1);
2270 const float32x2_t azbx = vmul_f32(aw_az, by_bx);
2271 const float32x2_t aybz_axby = vmul_f32(ay_ax, bz_by);
2273 const float32x2_t azbxSUBaxbz = vmls_f32(azbx, bw_bz, ay_ax);
2274 const float32x2_t aybzSUBazby_axbySUBaybx = vmls_f32(aybz_axby, by_bx, az_ay);
2276 const float32x2_t retLow = vext_f32(aybzSUBazby_axbySUBaybx, azbxSUBaxbz, 1);
2277 const uint32x2_t retHigh = vand_u32(TF, vreinterpret_u32_f32(aybzSUBazby_axbySUBaybx));
2279 return vcombine_f32(retLow, vreinterpret_f32_u32(retHigh));
2284 const float32x4_t tmp = vmulq_f32(a, a);
2285 const float32x2_t low = vget_low_f32(tmp);
2286 const float32x2_t high = vget_high_f32(tmp);
2288 const float32x2_t sumTmp = vpadd_f32(low, high);
2289 const float32x2_t sumWZYX = vpadd_f32(sumTmp, sumTmp);
2290 return FSqrt(sumWZYX);
2301 return V4ScaleInv(a, V4Length(a));
2307 return V4Scale(a, FRsqrtFast(V4Dot(a, a)));
2310PX_FORCE_INLINE Vec4V V4NormalizeSafe(
const Vec4V a,
const Vec4V unsafeReturnValue)
2312 const FloatV
zero = FZero();
2313 const FloatV length = V4Length(a);
2314 const uint32x4_t isGreaterThanZero = FIsGrtr(length, zero);
2315 return V4Sel(isGreaterThanZero, V4ScaleInv(a, length), unsafeReturnValue);
2320 return vceqq_u32(a, b);
2323PX_FORCE_INLINE Vec4V V4Sel(
const BoolV c,
const Vec4V a,
const Vec4V b)
2325 return vbslq_f32(c, a, b);
2330 return vcgtq_f32(a, b);
2335 return vcgeq_f32(a, b);
2340 return vceqq_f32(a, b);
2345 return vmaxq_f32(a, b);
2350 return vminq_f32(a, b);
2355 const float32x2_t low = vget_low_f32(a);
2356 const float32x2_t high = vget_high_f32(a);
2358 const float32x2_t max0 = vpmax_f32(high, low);
2359 const float32x2_t max1 = vpmax_f32(max0, max0);
2366 const float32x2_t low = vget_low_f32(a);
2367 const float32x2_t high = vget_high_f32(a);
2369 const float32x2_t min0 = vpmin_f32(high, low);
2370 const float32x2_t min1 = vpmin_f32(min0, min0);
2375PX_FORCE_INLINE Vec4V V4Clamp(
const Vec4V a,
const Vec4V minV,
const Vec4V maxV)
2377 return V4Max(V4Min(a, maxV), minV);
2382 return internalUnitNeonSimd::BAllTrue4_R(V4IsGrtr(a, b));
2387 return internalUnitNeonSimd::BAllTrue4_R(V4IsGrtrOrEq(a, b));
2392 return internalUnitNeonSimd::BAllTrue3_R(V4IsGrtrOrEq(a, b));
2397 return internalUnitNeonSimd::BAllTrue4_R(V4IsEq(a, b));
2402 return internalUnitNeonSimd::BAnyTrue3_R(V4IsGrtr(a, b));
2408 const Vec4V half = V4Load(0.5f);
2409 const float32x4_t sign = vcvtq_f32_u32((vshrq_n_u32(vreinterpretq_u32_f32(a), 31)));
2410 const Vec4V aPlusHalf = V4Add(a, half);
2411 const Vec4V aRound = V4Sub(aPlusHalf, sign);
2412 return vcvtq_f32_s32(vcvtq_s32_f32(aRound));
2417 const Vec4V recipTwoPi = V4LoadA(g_PXReciprocalTwoPi.f);
2418 const Vec4V twoPi = V4LoadA(g_PXTwoPi.f);
2419 const Vec4V tmp = V4Mul(a, recipTwoPi);
2420 const Vec4V b = V4Round(tmp);
2421 const Vec4V V1 = V4NegMulSub(twoPi, b, a);
2425 const Vec4V V2 = V4Mul(V1, V1);
2426 const Vec4V V3 = V4Mul(V2, V1);
2427 const Vec4V V5 = V4Mul(V3, V2);
2428 const Vec4V V7 = V4Mul(V5, V2);
2429 const Vec4V V9 = V4Mul(V7, V2);
2430 const Vec4V V11 = V4Mul(V9, V2);
2431 const Vec4V V13 = V4Mul(V11, V2);
2432 const Vec4V V15 = V4Mul(V13, V2);
2433 const Vec4V V17 = V4Mul(V15, V2);
2434 const Vec4V V19 = V4Mul(V17, V2);
2435 const Vec4V V21 = V4Mul(V19, V2);
2436 const Vec4V V23 = V4Mul(V21, V2);
2438 const Vec4V sinCoefficients0 = V4LoadA(g_PXSinCoefficients0.f);
2439 const Vec4V sinCoefficients1 = V4LoadA(g_PXSinCoefficients1.f);
2440 const Vec4V sinCoefficients2 = V4LoadA(g_PXSinCoefficients2.f);
2442 const FloatV S1 = V4GetY(sinCoefficients0);
2443 const FloatV S2 = V4GetZ(sinCoefficients0);
2444 const FloatV S3 = V4GetW(sinCoefficients0);
2445 const FloatV S4 = V4GetX(sinCoefficients1);
2446 const FloatV S5 = V4GetY(sinCoefficients1);
2447 const FloatV S6 = V4GetZ(sinCoefficients1);
2448 const FloatV S7 = V4GetW(sinCoefficients1);
2449 const FloatV S8 = V4GetX(sinCoefficients2);
2450 const FloatV S9 = V4GetY(sinCoefficients2);
2451 const FloatV S10 = V4GetZ(sinCoefficients2);
2452 const FloatV S11 = V4GetW(sinCoefficients2);
2455 Result = V4ScaleAdd(V3, S1, V1);
2456 Result = V4ScaleAdd(V5, S2, Result);
2457 Result = V4ScaleAdd(V7, S3, Result);
2458 Result = V4ScaleAdd(V9, S4, Result);
2459 Result = V4ScaleAdd(V11, S5, Result);
2460 Result = V4ScaleAdd(V13, S6, Result);
2461 Result = V4ScaleAdd(V15, S7, Result);
2462 Result = V4ScaleAdd(V17, S8, Result);
2463 Result = V4ScaleAdd(V19, S9, Result);
2464 Result = V4ScaleAdd(V21, S10, Result);
2465 Result = V4ScaleAdd(V23, S11, Result);
2472 const Vec4V recipTwoPi = V4LoadA(g_PXReciprocalTwoPi.f);
2473 const Vec4V twoPi = V4LoadA(g_PXTwoPi.f);
2474 const Vec4V tmp = V4Mul(a, recipTwoPi);
2475 const Vec4V b = V4Round(tmp);
2476 const Vec4V V1 = V4NegMulSub(twoPi, b, a);
2480 const Vec4V V2 = V4Mul(V1, V1);
2481 const Vec4V V4 = V4Mul(V2, V2);
2482 const Vec4V V6 = V4Mul(V4, V2);
2483 const Vec4V V8 = V4Mul(V4, V4);
2484 const Vec4V V10 = V4Mul(V6, V4);
2485 const Vec4V V12 = V4Mul(V6, V6);
2486 const Vec4V V14 = V4Mul(V8, V6);
2487 const Vec4V V16 = V4Mul(V8, V8);
2488 const Vec4V V18 = V4Mul(V10, V8);
2489 const Vec4V V20 = V4Mul(V10, V10);
2490 const Vec4V V22 = V4Mul(V12, V10);
2492 const Vec4V cosCoefficients0 = V4LoadA(g_PXCosCoefficients0.f);
2493 const Vec4V cosCoefficients1 = V4LoadA(g_PXCosCoefficients1.f);
2494 const Vec4V cosCoefficients2 = V4LoadA(g_PXCosCoefficients2.f);
2496 const FloatV C1 = V4GetY(cosCoefficients0);
2497 const FloatV C2 = V4GetZ(cosCoefficients0);
2498 const FloatV C3 = V4GetW(cosCoefficients0);
2499 const FloatV C4 = V4GetX(cosCoefficients1);
2500 const FloatV C5 = V4GetY(cosCoefficients1);
2501 const FloatV C6 = V4GetZ(cosCoefficients1);
2502 const FloatV C7 = V4GetW(cosCoefficients1);
2503 const FloatV C8 = V4GetX(cosCoefficients2);
2504 const FloatV C9 = V4GetY(cosCoefficients2);
2505 const FloatV C10 = V4GetZ(cosCoefficients2);
2506 const FloatV C11 = V4GetW(cosCoefficients2);
2509 Result = V4ScaleAdd(V2, C1, V4One());
2510 Result = V4ScaleAdd(V4, C2, Result);
2511 Result = V4ScaleAdd(V6, C3, Result);
2512 Result = V4ScaleAdd(V8, C4, Result);
2513 Result = V4ScaleAdd(V10, C5, Result);
2514 Result = V4ScaleAdd(V12, C6, Result);
2515 Result = V4ScaleAdd(V14, C7, Result);
2516 Result = V4ScaleAdd(V16, C8, Result);
2517 Result = V4ScaleAdd(V18, C9, Result);
2518 Result = V4ScaleAdd(V20, C10, Result);
2519 Result = V4ScaleAdd(V22, C11, Result);
2524PX_FORCE_INLINE void V4Transpose(Vec4V& col0, Vec4V& col1, Vec4V& col2, Vec4V& col3)
2526 const float32x4x2_t v0v1 = vzipq_f32(col0, col2);
2527 const float32x4x2_t v2v3 = vzipq_f32(col1, col3);
2528 const float32x4x2_t zip0 = vzipq_f32(v0v1.val[0], v2v3.val[0]);
2529 const float32x4x2_t zip1 = vzipq_f32(v0v1.val[1], v2v3.val[1]);
2542 return vmovq_n_u32(0);
2547 const uint32x2_t zeros = vmov_n_u32(0);
2548 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2549 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2550 return vcombine_u32(zeros, zo);
2555 const uint32x2_t zeros = vmov_n_u32(0);
2556 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2557 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2558 return vcombine_u32(zeros, oz);
2563 const uint32x2_t zeros = vmov_n_u32(0);
2564 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2565 return vcombine_u32(zeros, ones);
2570 const uint32x2_t zeros = vmov_n_u32(0);
2571 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2572 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2573 return vcombine_u32(zo, zeros);
2578 const uint32x2_t zeros = vmov_n_u32(0);
2579 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2580 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2581 return vcombine_u32(zo, zo);
2586 const uint32x2_t zeros = vmov_n_u32(0);
2587 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2588 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2589 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2590 return vcombine_u32(zo, oz);
2595 const uint32x2_t zeros = vmov_n_u32(0);
2596 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2597 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2598 return vcombine_u32(zo, ones);
2603 const uint32x2_t zeros = vmov_n_u32(0);
2604 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2606 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2607 return vcombine_u32(oz, zeros);
2612 const uint32x2_t zeros = vmov_n_u32(0);
2613 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2614 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2615 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2616 return vcombine_u32(oz, zo);
2621 const uint32x2_t zeros = vmov_n_u32(0);
2622 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2623 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2624 return vcombine_u32(oz, oz);
2629 const uint32x2_t zeros = vmov_n_u32(0);
2630 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2631 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2632 return vcombine_u32(oz, ones);
2637 const uint32x2_t zeros = vmov_n_u32(0);
2638 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2639 return vcombine_u32(ones, zeros);
2644 const uint32x2_t zeros = vmov_n_u32(0);
2645 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2646 const uint32x2_t zo = vext_u32(zeros, ones, 1);
2647 return vcombine_u32(ones, zo);
2652 const uint32x2_t zeros = vmov_n_u32(0);
2653 const uint32x2_t ones = vmov_n_u32(0xffffFFFF);
2654 const uint32x2_t oz = vext_u32(ones, zeros, 1);
2655 return vcombine_u32(ones, oz);
2660 return vmovq_n_u32(0xffffFFFF);
2685 const uint32x2_t fLow = vget_low_u32(f);
2686 return vdupq_lane_u32(fLow, 0);
2691 const uint32x2_t fLow = vget_low_u32(f);
2692 return vdupq_lane_u32(fLow, 1);
2697 const uint32x2_t fHigh = vget_high_u32(f);
2698 return vdupq_lane_u32(fHigh, 0);
2703 const uint32x2_t fHigh = vget_high_u32(f);
2704 return vdupq_lane_u32(fHigh, 1);
2709 return vbslq_u32(BFTTT(), v, f);
2714 return vbslq_u32(BTFTT(), v, f);
2719 return vbslq_u32(BTTFT(), v, f);
2724 return vbslq_u32(BTTTF(), v, f);
2729 return vandq_u32(a, b);
2734 return vmvnq_u32(a);
2740 return vandq_u32(a, vmvnq_u32(b));
2745 return vorrq_u32(a, b);
2750 const uint32x2_t allTrue = vmov_n_u32(0xffffFFFF);
2751 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
2752 const uint16x4_t dLow = vmovn_u32(a);
2753 uint16x8_t combined = vcombine_u16(dLow, dHigh);
2754 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
2755 const uint32x2_t result = vceq_u32(finalReduce, allTrue);
2756 return vdupq_lane_u32(result, 0);
2761 const uint32x2_t allTrue = vmov_n_u32(0xffffFFFF);
2762 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
2763 const uint16x4_t dLow = vmovn_u32(a);
2764 uint16x8_t combined = vcombine_u16(dLow, dHigh);
2765 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
2766 const uint32x2_t result = vtst_u32(finalReduce, allTrue);
2767 return vdupq_lane_u32(result, 0);
2772 const uint32x2_t allTrue3 = vmov_n_u32(0x00ffFFFF);
2773 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
2774 const uint16x4_t dLow = vmovn_u32(a);
2775 uint16x8_t combined = vcombine_u16(dLow, dHigh);
2776 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
2777 const uint32x2_t result = vceq_u32(vand_u32(finalReduce, allTrue3), allTrue3);
2778 return vdupq_lane_u32(result, 0);
2783 const uint32x2_t allTrue3 = vmov_n_u32(0x00ffFFFF);
2784 const uint16x4_t dHigh = vget_high_u16(vreinterpretq_u16_u32(a));
2785 const uint16x4_t dLow = vmovn_u32(a);
2786 uint16x8_t combined = vcombine_u16(dLow, dHigh);
2787 const uint32x2_t finalReduce = vreinterpret_u32_u8(vmovn_u16(combined));
2788 const uint32x2_t result = vtst_u32(vand_u32(finalReduce, allTrue3), allTrue3);
2789 return vdupq_lane_u32(result, 0);
2794 const BoolV bTest = vceqq_u32(a, b);
2795 return internalUnitNeonSimd::BAllTrue4_R(bTest);
2800 return BAllEq(a, BTTTT());
2805 return BAllEq(a, BFFFF());
2810 static PX_ALIGN(16,
const PxU32) bitMaskData[4] = { 1, 2, 4, 8 };
2811 const uint32x4_t bitMask = *(
reinterpret_cast<const uint32x4_t*
>(bitMaskData));
2812 const uint32x4_t t0 = vandq_u32(a, bitMask);
2813 const uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0));
2814 return PxU32(vget_lane_u32(vpadd_u32(t1, t1), 0));
2823 const FloatV x = V3GetX(b);
2824 const FloatV y = V3GetY(b);
2825 const FloatV z = V3GetZ(b);
2826 const Vec3V v0 = V3Scale(a.col0, x);
2827 const Vec3V v1 = V3Scale(a.col1, y);
2828 const Vec3V v2 = V3Scale(a.col2, z);
2829 const Vec3V v0PlusV1 = V3Add(v0, v1);
2830 return V3Add(v0PlusV1, v2);
2835 const FloatV x = V3Dot(a.col0, b);
2836 const FloatV y = V3Dot(a.col1, b);
2837 const FloatV z = V3Dot(a.col2, b);
2838 return V3Merge(x, y, z);
2841PX_FORCE_INLINE Vec3V M33MulV3AddV3(
const Mat33V& A,
const Vec3V b,
const Vec3V c)
2843 const FloatV x = V3GetX(b);
2844 const FloatV y = V3GetY(b);
2845 const FloatV z = V3GetZ(b);
2846 Vec3V result = V3ScaleAdd(A.col0, x, c);
2847 result = V3ScaleAdd(A.col1, y, result);
2848 return V3ScaleAdd(A.col2, z, result);
2853 return Mat33V(M33MulV3(a, b.col0), M33MulV3(a, b.col1), M33MulV3(a, b.col2));
2858 return Mat33V(V3Add(a.col0, b.col0), V3Add(a.col1, b.col1), V3Add(a.col2, b.col2));
2863 return Mat33V(V3Scale(a.col0, b), V3Scale(a.col1, b), V3Scale(a.col2, b));
2868 const float32x2_t zeros = vreinterpret_f32_u32(vmov_n_u32(0));
2869 const BoolV btttf = BTTTF();
2871 const Vec3V cross01 = V3Cross(a.col0, a.col1);
2872 const Vec3V cross12 = V3Cross(a.col1, a.col2);
2873 const Vec3V cross20 = V3Cross(a.col2, a.col0);
2874 const FloatV dot = V3Dot(cross01, a.col2);
2875 const FloatV invDet = FRecipFast(dot);
2877 const float32x4x2_t merge = vzipq_f32(cross12, cross01);
2878 const float32x4_t mergeh = merge.val[0];
2879 const float32x4_t mergel = merge.val[1];
2882 const float32x4_t colInv0_xxyy = vzipq_f32(mergeh, cross20).val[0];
2883 const float32x4_t colInv0 = vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(colInv0_xxyy), btttf));
2886 const float32x2_t zw0 = vget_high_f32(mergeh);
2887 const float32x2_t xy1 = vget_low_f32(cross20);
2888 const float32x2_t yzero1 = vext_f32(xy1, zeros, 1);
2889 const float32x2x2_t merge1 = vzip_f32(zw0, yzero1);
2890 const float32x4_t colInv1 = vcombine_f32(merge1.val[0], merge1.val[1]);
2893 const float32x2_t x0y0 = vget_low_f32(mergel);
2894 const float32x2_t z1w1 = vget_high_f32(cross20);
2895 const float32x2x2_t merge2 = vzip_f32(x0y0, z1w1);
2896 const float32x4_t colInv2 = vcombine_f32(merge2.val[0], merge2.val[1]);
2898 return Mat33V(vmulq_lane_f32(colInv0, invDet, 0), vmulq_lane_f32(colInv1, invDet, 0),
2899 vmulq_lane_f32(colInv2, invDet, 0));
2904 return Mat33V(V3Merge(V3GetX(a.col0), V3GetX(a.col1), V3GetX(a.col2)),
2905 V3Merge(V3GetY(a.col0), V3GetY(a.col1), V3GetY(a.col2)),
2906 V3Merge(V3GetZ(a.col0), V3GetZ(a.col1), V3GetZ(a.col2)));
2911 return Mat33V(V3UnitX(), V3UnitY(), V3UnitZ());
2916 return Mat33V(V3Sub(a.col0, b.col0), V3Sub(a.col1, b.col1), V3Sub(a.col2, b.col2));
2921 return Mat33V(V3Neg(a.col0), V3Neg(a.col1), V3Neg(a.col2));
2926 return Mat33V(V3Abs(a.col0), V3Abs(a.col1), V3Abs(a.col2));
2931 const BoolV bTFFF = BTFFF();
2932 const BoolV bFTFF = BFTFF();
2933 const BoolV bFFTF = BTFTF();
2935 const Vec3V
zero = V3Zero();
2937 return Mat33V(V3Sel(bTFFF, v, zero), V3Sel(bFTFF, v, zero), V3Sel(bFFTF, v, zero));
2942 const Vec3V x = V3Mul(V3UnitX(), d);
2943 const Vec3V y = V3Mul(V3UnitY(), d);
2944 const Vec3V z = V3Mul(V3UnitZ(), d);
2945 return Mat33V(x, y, z);
2954 const FloatV x = V3GetX(b);
2955 const FloatV y = V3GetY(b);
2956 const FloatV z = V3GetZ(b);
2957 const Vec3V v0 = V3Scale(a.col0, x);
2958 const Vec3V v1 = V3Scale(a.col1, y);
2959 const Vec3V v2 = V3Scale(a.col2, z);
2960 const Vec3V v0PlusV1 = V3Add(v0, v1);
2961 const Vec3V v0PlusV1Plusv2 = V3Add(v0PlusV1, v2);
2962 return V3Add(v0PlusV1Plusv2, a.col3);
2967 const FloatV x = V3GetX(b);
2968 const FloatV y = V3GetY(b);
2969 const FloatV z = V3GetZ(b);
2970 const Vec3V v0 = V3Scale(a.col0, x);
2971 const Vec3V v1 = V3Scale(a.col1, y);
2972 const Vec3V v2 = V3Scale(a.col2, z);
2973 const Vec3V v0PlusV1 = V3Add(v0, v1);
2974 return V3Add(v0PlusV1, v2);
2979 const FloatV x = V3Dot(a.col0, b);
2980 const FloatV y = V3Dot(a.col1, b);
2981 const FloatV z = V3Dot(a.col2, b);
2982 return V3Merge(x, y, z);
2987 return Mat34V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2), M34MulV3(a, b.col3));
2992 return Mat33V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2));
2997 return Mat33V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2));
3002 return Mat34V(V3Add(a.col0, b.col0), V3Add(a.col1, b.col1), V3Add(a.col2, b.col2), V3Add(a.col3, b.col3));
3007 return Mat33V(V3Merge(V3GetX(a.col0), V3GetX(a.col1), V3GetX(a.col2)),
3008 V3Merge(V3GetY(a.col0), V3GetY(a.col1), V3GetY(a.col2)),
3009 V3Merge(V3GetZ(a.col0), V3GetZ(a.col1), V3GetZ(a.col2)));
3018 const FloatV x = V4GetX(b);
3019 const FloatV y = V4GetY(b);
3020 const FloatV z = V4GetZ(b);
3021 const FloatV w = V4GetW(b);
3023 const Vec4V v0 = V4Scale(a.col0, x);
3024 const Vec4V v1 = V4Scale(a.col1, y);
3025 const Vec4V v2 = V4Scale(a.col2, z);
3026 const Vec4V v3 = V4Scale(a.col3, w);
3027 const Vec4V v0PlusV1 = V4Add(v0, v1);
3028 const Vec4V v0PlusV1Plusv2 = V4Add(v0PlusV1, v2);
3029 return V4Add(v0PlusV1Plusv2, v3);
3034 return V4Merge(V4Dot(a.col0, b), V4Dot(a.col1, b), V4Dot(a.col2, b), V4Dot(a.col3, b));
3039 return Mat44V(M44MulV4(a, b.col0), M44MulV4(a, b.col1), M44MulV4(a, b.col2), M44MulV4(a, b.col3));
3044 return Mat44V(V4Add(a.col0, b.col0), V4Add(a.col1, b.col1), V4Add(a.col2, b.col2), V4Add(a.col3, b.col3));
3056 const float32x4x2_t v0v1 = vzipq_f32(a.col0, a.col2);
3057 const float32x4x2_t v2v3 = vzipq_f32(a.col1, a.col3);
3058 const float32x4x2_t zip0 = vzipq_f32(v0v1.val[0], v2v3.val[0]);
3059 const float32x4x2_t zip1 = vzipq_f32(v0v1.val[1], v2v3.val[1]);
3061 return Mat44V(zip0.val[0], zip0.val[1], zip1.val[0], zip1.val[1]);
3066 float32x4_t minor0, minor1, minor2, minor3;
3067 float32x4_t row0, row1, row2, row3;
3068 float32x4_t det, tmp1;
3070 tmp1 = vmovq_n_f32(0.0f);
3071 row1 = vmovq_n_f32(0.0f);
3072 row3 = vmovq_n_f32(0.0f);
3075 row1 = vextq_f32(a.col1, a.col1, 2);
3077 row3 = vextq_f32(a.col3, a.col3, 2);
3079 tmp1 = vmulq_f32(row2, row3);
3080 tmp1 = vrev64q_f32(tmp1);
3081 minor0 = vmulq_f32(row1, tmp1);
3082 minor1 = vmulq_f32(row0, tmp1);
3083 tmp1 = vextq_f32(tmp1, tmp1, 2);
3084 minor0 = vsubq_f32(vmulq_f32(row1, tmp1), minor0);
3085 minor1 = vsubq_f32(vmulq_f32(row0, tmp1), minor1);
3086 minor1 = vextq_f32(minor1, minor1, 2);
3088 tmp1 = vmulq_f32(row1, row2);
3089 tmp1 = vrev64q_f32(tmp1);
3090 minor0 = vaddq_f32(vmulq_f32(row3, tmp1), minor0);
3091 minor3 = vmulq_f32(row0, tmp1);
3092 tmp1 = vextq_f32(tmp1, tmp1, 2);
3093 minor0 = vsubq_f32(minor0, vmulq_f32(row3, tmp1));
3094 minor3 = vsubq_f32(vmulq_f32(row0, tmp1), minor3);
3095 minor3 = vextq_f32(minor3, minor3, 2);
3097 tmp1 = vmulq_f32(vextq_f32(row1, row1, 2), row3);
3098 tmp1 = vrev64q_f32(tmp1);
3099 row2 = vextq_f32(row2, row2, 2);
3100 minor0 = vaddq_f32(vmulq_f32(row2, tmp1), minor0);
3101 minor2 = vmulq_f32(row0, tmp1);
3102 tmp1 = vextq_f32(tmp1, tmp1, 2);
3103 minor0 = vsubq_f32(minor0, vmulq_f32(row2, tmp1));
3104 minor2 = vsubq_f32(vmulq_f32(row0, tmp1), minor2);
3105 minor2 = vextq_f32(minor2, minor2, 2);
3107 tmp1 = vmulq_f32(row0, row1);
3108 tmp1 = vrev64q_f32(tmp1);
3109 minor2 = vaddq_f32(vmulq_f32(row3, tmp1), minor2);
3110 minor3 = vsubq_f32(vmulq_f32(row2, tmp1), minor3);
3111 tmp1 = vextq_f32(tmp1, tmp1, 2);
3112 minor2 = vsubq_f32(vmulq_f32(row3, tmp1), minor2);
3113 minor3 = vsubq_f32(minor3, vmulq_f32(row2, tmp1));
3115 tmp1 = vmulq_f32(row0, row3);
3116 tmp1 = vrev64q_f32(tmp1);
3117 minor1 = vsubq_f32(minor1, vmulq_f32(row2, tmp1));
3118 minor2 = vaddq_f32(vmulq_f32(row1, tmp1), minor2);
3119 tmp1 = vextq_f32(tmp1, tmp1, 2);
3120 minor1 = vaddq_f32(vmulq_f32(row2, tmp1), minor1);
3121 minor2 = vsubq_f32(minor2, vmulq_f32(row1, tmp1));
3123 tmp1 = vmulq_f32(row0, row2);
3124 tmp1 = vrev64q_f32(tmp1);
3125 minor1 = vaddq_f32(vmulq_f32(row3, tmp1), minor1);
3126 minor3 = vsubq_f32(minor3, vmulq_f32(row1, tmp1));
3127 tmp1 = vextq_f32(tmp1, tmp1, 2);
3128 minor1 = vsubq_f32(minor1, vmulq_f32(row3, tmp1));
3129 minor3 = vaddq_f32(vmulq_f32(row1, tmp1), minor3);
3131 det = vmulq_f32(row0, minor0);
3132 det = vaddq_f32(vextq_f32(det, det, 2), det);
3133 det = vaddq_f32(vrev64q_f32(det), det);
3134 det = vdupq_lane_f32(VRECIPE(vget_low_f32(det)), 0);
3136 minor0 = vmulq_f32(det, minor0);
3137 minor1 = vmulq_f32(det, minor1);
3138 minor2 = vmulq_f32(det, minor2);
3139 minor3 = vmulq_f32(det, minor3);
3140 Mat44V invTrans(minor0, minor1, minor2, minor3);
3141 return M44Trnsps(invTrans);
3144PX_FORCE_INLINE Vec4V V4LoadXYZW(
const PxF32& x,
const PxF32& y,
const PxF32& z,
const PxF32& w)
3146 const float32x4_t ret = { x, y, z, w };
3157PX_FORCE_INLINE VecU32V V4U32Sel(
const BoolV c,
const VecU32V a,
const VecU32V b)
3159 return vbslq_u32(c, a, b);
3164 return vorrq_u32(a, b);
3169 return veorq_u32(a, b);
3174 return vandq_u32(a, b);
3180 return vandq_u32(a, vmvnq_u32(b));
3203PX_FORCE_INLINE VecI32V I4LoadXYZW(
const PxI32& x,
const PxI32& y,
const PxI32& z,
const PxI32& w)
3205 const int32x4_t ret = { x, y, z, w };
3211 return vdupq_n_s32(i);
3216 return vld1q_s32(i);
3221 return vld1q_s32(i);
3224PX_FORCE_INLINE VecI32V VecI32V_Add(
const VecI32VArg a,
const VecI32VArg b)
3226 return vaddq_s32(a, b);
3229PX_FORCE_INLINE VecI32V VecI32V_Sub(
const VecI32VArg a,
const VecI32VArg b)
3231 return vsubq_s32(a, b);
3234PX_FORCE_INLINE BoolV VecI32V_IsGrtr(
const VecI32VArg a,
const VecI32VArg b)
3236 return vcgtq_s32(a, b);
3239PX_FORCE_INLINE BoolV VecI32V_IsEq(
const VecI32VArg a,
const VecI32VArg b)
3241 return vceqq_s32(a, b);
3244PX_FORCE_INLINE VecI32V V4I32Sel(
const BoolV c,
const VecI32V a,
const VecI32V b)
3246 return vbslq_s32(c, a, b);
3251 return vdupq_n_s32(0);
3256 return vdupq_n_s32(1);
3261 return vdupq_n_s32(2);
3266 return vdupq_n_s32(-1);
3289PX_FORCE_INLINE VecI32V VecI32V_LeftShift(
const VecI32VArg a,
const VecShiftVArg count)
3291 return vshlq_s32(a, count);
3294PX_FORCE_INLINE VecI32V VecI32V_RightShift(
const VecI32VArg a,
const VecShiftVArg count)
3296 return vshlq_s32(a, VecI32V_Sub(I4Load(0), count));
3299PX_FORCE_INLINE VecI32V VecI32V_LeftShift(
const VecI32VArg a,
const PxU32 count)
3301 const int32x4_t shiftCount = { (PxI32)count, (PxI32)count, (PxI32)count, (PxI32)count };
3302 return vshlq_s32(a, shiftCount);
3305PX_FORCE_INLINE VecI32V VecI32V_RightShift(
const VecI32VArg a,
const PxU32 count)
3307 const int32x4_t shiftCount = { -(PxI32)count, -(PxI32)count, -(PxI32)count, -(PxI32)count };
3308 return vshlq_s32(a, shiftCount);
3311PX_FORCE_INLINE VecI32V VecI32V_And(
const VecI32VArg a,
const VecI32VArg b)
3313 return vandq_s32(a, b);
3316PX_FORCE_INLINE VecI32V VecI32V_Or(
const VecI32VArg a,
const VecI32VArg b)
3318 return vorrq_s32(a, b);
3323 const int32x2_t fLow = vget_low_s32(f);
3324 return vdupq_lane_s32(fLow, 0);
3329 const int32x2_t fLow = vget_low_s32(f);
3330 return vdupq_lane_s32(fLow, 1);
3335 const int32x2_t fHigh = vget_high_s32(f);
3336 return vdupq_lane_s32(fHigh, 0);
3341 const int32x2_t fHigh = vget_high_s32(f);
3342 return vdupq_lane_s32(fHigh, 1);
3345PX_FORCE_INLINE VecI32V VecI32V_Sel(
const BoolV c,
const VecI32VArg a,
const VecI32VArg b)
3347 return vbslq_s32(c, a, b);
3352 *i = vgetq_lane_s32(a, 0);
3355PX_FORCE_INLINE VecI32V VecI32V_Merge(
const VecI32VArg a,
const VecI32VArg b,
const VecI32VArg c,
const VecI32VArg d)
3357 const int32x2_t aLow = vget_low_s32(a);
3358 const int32x2_t bLow = vget_low_s32(b);
3359 const int32x2_t cLow = vget_low_s32(c);
3360 const int32x2_t dLow = vget_low_s32(d);
3362 const int32x2_t low = vext_s32(aLow, bLow, 1);
3363 const int32x2_t high = vext_s32(cLow, dLow, 1);
3365 return vcombine_s32(low, high);
3370 return vreinterpretq_s32_u32(a);
3399 vst1q_u32(
reinterpret_cast<uint32_t*
>(address), val);
3404 return vld1q_f32(
reinterpret_cast<float32_t*
>(addr));
3409 return vld1q_f32(
reinterpret_cast<float32_t*
>(addr));
3414 return vreinterpretq_f32_u32(V4U32Andc(vreinterpretq_u32_f32(a), b));
3419 return V4IsGrtr(a, b);
3424 return vld1q_u16(
reinterpret_cast<uint16_t*
>(addr));
3429 return vld1q_u16(
reinterpret_cast<uint16_t*
>(addr));
3434 return vcgtq_u16(a, b);
3439 return vcgtq_s16(a, b);
3444 return vcvtq_f32_u32(a);
3449 return vcvtq_f32_s32(a);
3454 return vcvtq_s32_f32(a);
3459 return vreinterpretq_f32_u32(a);
3464 return vreinterpretq_f32_s32(a);
3469 return vreinterpretq_u32_f32(a);
3474 return vreinterpretq_s32_f32(a);
3483 return vdupq_lane_u32(vget_low_u32(a), index);
3487 return vdupq_lane_u32(vget_high_u32(a), 0);
3491 return vdupq_lane_u32(vget_high_u32(a), 1);
3497template<>
PX_FORCE_INLINE BoolV BSplatElement<0>(BoolV a) {
return vdupq_lane_u32(vget_low_u32(a), 0); }
3498template<>
PX_FORCE_INLINE BoolV BSplatElement<1>(BoolV a) {
return vdupq_lane_u32(vget_low_u32(a), 1); }
3499template<>
PX_FORCE_INLINE BoolV BSplatElement<2>(BoolV a) {
return vdupq_lane_u32(vget_high_u32(a), 0); }
3500template<>
PX_FORCE_INLINE BoolV BSplatElement<3>(BoolV a) {
return vdupq_lane_u32(vget_high_u32(a), 1); }
3509 return vdupq_lane_u32(vget_low_u32(a), index);
3513 return vdupq_lane_u32(vget_high_u32(a), 0);
3517 return vdupq_lane_u32(vget_high_u32(a), 1);
3522template <
int index>
PX_FORCE_INLINE VecU32V V4U32SplatElement(VecU32V a);
3523template <>
PX_FORCE_INLINE VecU32V V4U32SplatElement<0>(VecU32V a) {
return vdupq_lane_u32(vget_low_u32(a), 0); }
3524template <>
PX_FORCE_INLINE VecU32V V4U32SplatElement<1>(VecU32V a) {
return vdupq_lane_u32(vget_low_u32(a), 1); }
3525template <>
PX_FORCE_INLINE VecU32V V4U32SplatElement<2>(VecU32V a) {
return vdupq_lane_u32(vget_high_u32(a), 0); }
3526template <>
PX_FORCE_INLINE VecU32V V4U32SplatElement<3>(VecU32V a) {
return vdupq_lane_u32(vget_high_u32(a), 1); }
3535 return vdupq_lane_f32(vget_low_f32(a), index);
3539 return vdupq_lane_f32(vget_high_f32(a), 0);
3543 return vdupq_lane_f32(vget_high_f32(a), 1);
3549template <>
PX_FORCE_INLINE Vec4V V4SplatElement<0>(Vec4V a) {
return vdupq_lane_f32(vget_low_f32(a), 0); }
3550template <>
PX_FORCE_INLINE Vec4V V4SplatElement<1>(Vec4V a) {
return vdupq_lane_f32(vget_low_f32(a), 1); }
3551template <>
PX_FORCE_INLINE Vec4V V4SplatElement<2>(Vec4V a) {
return vdupq_lane_f32(vget_high_f32(a), 0); }
3552template <>
PX_FORCE_INLINE Vec4V V4SplatElement<3>(Vec4V a) {
return vdupq_lane_f32(vget_high_f32(a), 1); }
3557 const uint32x4_t ret = { x, y, z, w };
3563 return vdupq_n_u32(i);
3568 return vld1q_u32(i);
3573 return vld1q_u32(i);
3578 const float32x4_t ones = vdupq_n_f32(1.0f);
3579 const float32x4_t rdToZero = vcvtq_f32_s32(vcvtq_s32_f32(in));
3580 const float32x4_t rdToZeroPlusOne = vaddq_f32(rdToZero, ones);
3581 const uint32x4_t gt = vcgtq_f32(in, rdToZero);
3582 return vbslq_f32(gt, rdToZeroPlusOne, rdToZero);
3587 const float32x4_t ones = vdupq_n_f32(1.0f);
3588 const float32x4_t rdToZero = vcvtq_f32_s32(vcvtq_s32_f32(in));
3589 const float32x4_t rdToZeroMinusOne = vsubq_f32(rdToZero, ones);
3590 const uint32x4_t lt = vcltq_f32(in, rdToZero);
3591 return vbslq_f32(lt, rdToZeroMinusOne, rdToZero);
3594PX_FORCE_INLINE VecU32V V4ConvertToU32VSaturate(
const Vec4V in, PxU32 power)
3596 PX_ASSERT(power == 0 &&
"Non-zero power not supported in convertToU32VSaturate");
3599 return vcvtq_u32_f32(in);
3602PX_FORCE_INLINE void QuatGetMat33V(
const QuatVArg q, Vec3V& column0, Vec3V& column1, Vec3V& column2)
3604 const FloatV one = FOne();
3605 const FloatV x = V4GetX(q);
3606 const FloatV y = V4GetY(q);
3607 const FloatV z = V4GetZ(q);
3608 const FloatV w = V4GetW(q);
3610 const FloatV x2 = FAdd(x, x);
3611 const FloatV y2 = FAdd(y, y);
3612 const FloatV z2 = FAdd(z, z);
3614 const FloatV xx = FMul(x2, x);
3615 const FloatV yy = FMul(y2, y);
3616 const FloatV zz = FMul(z2, z);
3618 const FloatV xy = FMul(x2, y);
3619 const FloatV xz = FMul(x2, z);
3620 const FloatV xw = FMul(x2, w);
3622 const FloatV yz = FMul(y2, z);
3623 const FloatV yw = FMul(y2, w);
3624 const FloatV zw = FMul(z2, w);
3626 const FloatV v = FSub(one, xx);
3628 column0 = V3Merge(FSub(FSub(one, yy), zz), FAdd(xy, zw), FSub(xz, yw));
3629 column1 = V3Merge(FSub(xy, zw), FSub(v, zz), FAdd(yz, xw));
3630 column2 = V3Merge(FAdd(xz, yw), FSub(yz, xw), FSub(v, yy));
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_ALIGN(alignment, decl)
Definition PxPreprocessor.h:402
GLM_FUNC_DECL GLM_CONSTEXPR genType zero()
Definition constants.inl:6
uint64 uint64_t
Definition fwd.hpp:145
float float32_t
Definition fwd.hpp:162
uint32 uint32_t
Definition fwd.hpp:131
int32 int32_t
Definition fwd.hpp:71
uint16 uint16_t
Definition fwd.hpp:117
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(float f)
returns true if the passed number is a finite floating point number as opposed to INF,...
Definition PxMath.h:326