From ddb704bc22528d33ee8b82986acc82b3e25fed43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 14 Jan 2022 23:52:53 +0100 Subject: [PATCH] Havok: Add hkMathHeaderConstants --- lib/hkStubs/CMakeLists.txt | 1 + .../Base/Math/Header/hkMathHeaderConstants.h | 70 +++++++++++++++++++ .../Common/Base/Math/Vector/hkSimdFloat32.h | 14 ++++ .../Common/Base/Math/Vector/hkVector4f.h | 3 + .../Common/Base/Math/Vector/hkVector4f.inl | 5 ++ lib/hkStubs/Havok/Common/Base/Math/hkMath.h | 1 + 6 files changed, 94 insertions(+) create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Header/hkMathHeaderConstants.h diff --git a/lib/hkStubs/CMakeLists.txt b/lib/hkStubs/CMakeLists.txt index 39da1fef..f891710f 100644 --- a/lib/hkStubs/CMakeLists.txt +++ b/lib/hkStubs/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(hkStubs OBJECT Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h Havok/Common/Base/Math/hkMath.h + Havok/Common/Base/Math/Header/hkMathHeaderConstants.h Havok/Common/Base/Math/Matrix/hkMatrix3.h Havok/Common/Base/Math/Matrix/hkMatrix3f.h Havok/Common/Base/Math/Matrix/hkRotation.h diff --git a/lib/hkStubs/Havok/Common/Base/Math/Header/hkMathHeaderConstants.h b/lib/hkStubs/Havok/Common/Base/Math/Header/hkMathHeaderConstants.h new file mode 100644 index 00000000..37689d33 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Header/hkMathHeaderConstants.h @@ -0,0 +1,70 @@ +#pragma once + +enum hkVectorConstant { + HK_QUADREAL_BEGIN, + + HK_QUADREAL_MINUS1, + HK_QUADREAL_0, + HK_QUADREAL_1, + HK_QUADREAL_2, + HK_QUADREAL_3, + HK_QUADREAL_4, + HK_QUADREAL_5, + HK_QUADREAL_6, + HK_QUADREAL_7, + HK_QUADREAL_8, + HK_QUADREAL_15, + HK_QUADREAL_16, + HK_QUADREAL_255, + HK_QUADREAL_256, + HK_QUADREAL_2_POW_23, + + HK_QUADREAL_INV_0, + HK_QUADREAL_INV_1, + HK_QUADREAL_INV_2, + HK_QUADREAL_INV_3, + HK_QUADREAL_INV_4, + HK_QUADREAL_INV_5, + HK_QUADREAL_INV_6, + HK_QUADREAL_INV_7, + HK_QUADREAL_INV_8, + HK_QUADREAL_INV_15, + HK_QUADREAL_INV_127, + HK_QUADREAL_INV_226, + HK_QUADREAL_INV_255, + HK_QUADREAL_1000, + HK_QUADREAL_0100, + HK_QUADREAL_0010, + HK_QUADREAL_0001, + HK_QUADREAL_MAX, + HK_QUADREAL_HIGH, + HK_QUADREAL_EPS, + HK_QUADREAL_EPS_SQRD, + HK_QUADREAL_MIN, + HK_QUADREAL_MINUS_MAX, + HK_QUADREAL_MINUS_MIN, + HK_QUADREAL_m11m11, + HK_QUADREAL_1m11m1, + HK_QUADREAL_1010, + HK_QUADREAL_1100, + HK_QUADREAL_0011, + HK_QUADREAL_1248, + HK_QUADREAL_8421, + HK_QUADREAL_PACK_HALF, + HK_QUADREAL_PACK16_UNIT_VEC, + HK_QUADREAL_UNPACK16_UNIT_VEC, + HK_QUADREAL_PI, + HK_QUADREAL_PI_HALF, + HK_QUADREAL_PI_QUARTER, + HK_QUADREAL_FOUR_PI_THIRD, + HK_QUADREAL_TWO_PI, + HK_QUADREAL_FOUR_PI, + HK_QUADREAL_DEG2RAD, + HK_QUADREAL_RAD2DEG, + + HK_QUADREAL_END +}; + +#define hkSimdReal_1 (hkSimdReal::getConstant()) + +extern const m128 g_vectorfConstants[HK_QUADREAL_END]; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h index 33a0332e..5c1f5fc8 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h @@ -18,6 +18,8 @@ public: #ifdef HK_SIMD_FLOAT32_AARCH64_NEON // NOLINTNEXTLINE(google-explicit-constructor) hkSimdFloat32(const float& x) { m_real = vdup_n_f32(x); } + // NOLINTNEXTLINE(google-explicit-constructor) + hkSimdFloat32(__attribute__((vector_size(2 * sizeof(float)))) float x) { m_real = x; } hkFloat32 val() const { return m_real[0]; } #else hkSimdFloat32(float x) : m_real{x} {} // NOLINT(google-explicit-constructor) @@ -26,6 +28,9 @@ public: operator float() const { return val(); } // NOLINT(google-explicit-constructor) + template + HK_FORCE_INLINE static hkSimdFloat32 getConstant(); + void setAbs(hkSimdFloat32Parameter x); #ifdef HK_SIMD_FLOAT32_AARCH64_NEON @@ -35,6 +40,15 @@ public: #endif }; +template +inline hkSimdFloat32 hkSimdFloat32::getConstant() { +#ifdef HK_SIMD_FLOAT32_AARCH64_NEON + return vget_low_f32(g_vectorfConstants[Constant]); +#else + return g_vectorfConstants[Constant][0]; +#endif +} + inline void hkSimdFloat32::setAbs(hkSimdFloat32Parameter x) { #ifdef HK_SIMD_FLOAT32_AARCH64_NEON m_real = vabs_f32(m_real); diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h index 953b991b..78df61b0 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h @@ -146,6 +146,9 @@ public: // ========== Load/store + template + HK_FORCE_INLINE static const hkVector4f& getConstant(); + /// Store N floats to out. template void store(hkFloat32* out) const; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.inl b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.inl index af8e5e80..e9e04d32 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.inl +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.inl @@ -354,6 +354,11 @@ inline hkSimdFloat32 hkVector4f::lengthSquared() const { return dot(*this); } +template +inline const hkVector4f& hkVector4f::getConstant() { + return reinterpret_cast(g_vectorfConstants[Constant]); +} + template inline void hkVector4f::store(hkFloat32* out) const { static_assert(1 <= N && N <= 4, "invalid N"); diff --git a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h index 12d948d3..b928b610 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h +++ b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h @@ -4,6 +4,7 @@ #include +#include #include #include #include