From 4cd44deba558971533692f93866322cc0617a1d4 Mon Sep 17 00:00:00 2001 From: Rye Date: Mon, 11 Nov 2024 08:25:38 -0500 Subject: [PATCH] Restore various llmath types to trivially copyable/movable and restore SIMD types to trivial --- indra/llmath/llbbox.h | 4 ++++ indra/llmath/llbboxlocal.h | 5 ++++- indra/llmath/llline.h | 4 +++- indra/llmath/llmatrix3a.h | 9 +++++++-- indra/llmath/llmatrix4a.h | 7 +++---- indra/llmath/llplane.h | 3 ++- indra/llmath/llquaternion.h | 4 ++++ indra/llmath/llquaternion2.h | 4 +++- indra/llmath/llrect.h | 8 ++++---- indra/llmath/llsimdtypes.h | 12 ++++++++---- indra/llmath/llvector4a.h | 13 ++++--------- indra/llmath/llvector4a.inl | 12 ------------ indra/llmath/llvector4logical.h | 6 ++++-- indra/llmath/m3math.h | 4 ++++ indra/llmath/m4math.cpp | 10 ---------- indra/llmath/m4math.h | 7 ++++--- indra/llmath/v2math.h | 3 +++ indra/llmath/v3color.h | 4 ++++ indra/llmath/v3dmath.h | 4 ++++ indra/llmath/v3math.h | 4 ++++ indra/llmath/v4color.h | 4 ++++ indra/llmath/v4coloru.h | 4 ++++ indra/llmath/v4math.h | 4 ++++ indra/newview/llcontrolavatar.cpp | 2 +- indra/newview/llface.cpp | 5 ----- indra/newview/llmodelpreview.cpp | 2 +- 26 files changed, 87 insertions(+), 61 deletions(-) diff --git a/indra/llmath/llbbox.h b/indra/llmath/llbbox.h index 5617eaebde0..3a4e09a5989 100644 --- a/indra/llmath/llbbox.h +++ b/indra/llmath/llbbox.h @@ -95,6 +95,10 @@ class LLBBox bool mEmpty; // Nothing has been added to this bbox yet }; +static_assert(std::is_trivially_copyable::value, "LLBBox must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLBBox must be trivial move"); +static_assert(std::is_standard_layout::value, "LLBBox must be a standard layout type"); + //LLBBox operator*(const LLBBox &a, const LLMatrix4 &b); diff --git a/indra/llmath/llbboxlocal.h b/indra/llmath/llbboxlocal.h index e215e554608..afe757c8d52 100644 --- a/indra/llmath/llbboxlocal.h +++ b/indra/llmath/llbboxlocal.h @@ -34,7 +34,7 @@ class LLMatrix4; class LLBBoxLocal { public: - LLBBoxLocal() {} + LLBBoxLocal() = default; LLBBoxLocal( const LLVector3& min, const LLVector3& max ) : mMin( min ), mMax( max ) {} // Default copy constructor is OK. @@ -61,5 +61,8 @@ class LLBBoxLocal LLBBoxLocal operator*(const LLBBoxLocal &a, const LLMatrix4 &b); +static_assert(std::is_trivially_copyable::value, "LLBBoxLocal must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLBBoxLocal must be trivial move"); +static_assert(std::is_standard_layout::value, "LLBBoxLocal must be a standard layout type"); #endif // LL_BBOXLOCAL_H diff --git a/indra/llmath/llline.h b/indra/llmath/llline.h index e98e173d1f7..37e73e7600f 100644 --- a/indra/llmath/llline.h +++ b/indra/llmath/llline.h @@ -40,7 +40,6 @@ class LLLine public: LLLine(); LLLine( const LLVector3& first_point, const LLVector3& second_point ); - virtual ~LLLine() {}; void setPointDirection( const LLVector3& first_point, const LLVector3& second_point ); void setPoints( const LLVector3& first_point, const LLVector3& second_point ); @@ -76,5 +75,8 @@ class LLLine LLVector3 mDirection; }; +static_assert(std::is_trivially_copyable::value, "LLLine must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLLine must be trivial move"); +static_assert(std::is_standard_layout::value, "LLLine must be a standard layout type"); #endif diff --git a/indra/llmath/llmatrix3a.h b/indra/llmath/llmatrix3a.h index dff6604ae5b..3b9c6569af6 100644 --- a/indra/llmath/llmatrix3a.h +++ b/indra/llmath/llmatrix3a.h @@ -56,7 +56,7 @@ class LLMatrix3a ////////////////////////// // Ctor - LLMatrix3a() {} + LLMatrix3a() = default; // Ctor for setting by columns inline LLMatrix3a( const LLVector4a& c0, const LLVector4a& c1, const LLVector4a& c2 ); @@ -115,14 +115,19 @@ class LLMatrix3a }; +static_assert(std::is_trivial::value, "LLMatrix3a must be a trivial type"); + class LLRotation : public LLMatrix3a { public: - LLRotation() {} + LLRotation() = default; // Returns true if this rotation is orthonormal with det ~= 1 inline bool isOkRotation() const; }; +static_assert(std::is_trivial::value, "LLRotation must be a trivial type"); + + #endif diff --git a/indra/llmath/llmatrix4a.h b/indra/llmath/llmatrix4a.h index 3b423f783a0..377203098e2 100644 --- a/indra/llmath/llmatrix4a.h +++ b/indra/llmath/llmatrix4a.h @@ -36,10 +36,7 @@ class LLMatrix4a public: LL_ALIGN_16(LLVector4a mMatrix[4]); - LLMatrix4a() - { - - } + LLMatrix4a() = default; explicit LLMatrix4a(const LLMatrix4& val) { @@ -228,6 +225,8 @@ class LLMatrix4a const LLVector4a& getTranslation() const { return mMatrix[3]; } }; +static_assert(std::is_trivial::value, "LLMatrix4a must be a trivial type"); + inline LLVector4a rowMul(const LLVector4a &row, const LLMatrix4a &mat) { LLVector4a result; diff --git a/indra/llmath/llplane.h b/indra/llmath/llplane.h index 4e8546e32b0..19bc0cebe9a 100644 --- a/indra/llmath/llplane.h +++ b/indra/llmath/llplane.h @@ -43,7 +43,7 @@ class LLPlane public: // Constructors - LLPlane() {}; // no default constructor + LLPlane() = default; // no default constructor LLPlane(const LLVector3 &p0, F32 d) { setVec(p0, d); } LLPlane(const LLVector3 &p0, const LLVector3 &n) { setVec(p0, n); } inline void setVec(const LLVector3 &p0, F32 d) { mV.set(p0[0], p0[1], p0[2], d); } @@ -104,6 +104,7 @@ class LLPlane LLVector4a mV; } LL_ALIGN_POSTFIX(16); +static_assert(std::is_trivial::value, "LLPlane must be a trivial type"); #endif // LL_LLPLANE_H diff --git a/indra/llmath/llquaternion.h b/indra/llmath/llquaternion.h index 762d13eded7..472d7ca62dc 100644 --- a/indra/llmath/llquaternion.h +++ b/indra/llmath/llquaternion.h @@ -174,6 +174,10 @@ class LLQuaternion //static U32 mMultCount; }; +static_assert(std::is_trivially_copyable::value, "LLQuaternion must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLQuaternion must be trivial move"); +static_assert(std::is_standard_layout::value, "LLQuaternion must be a standard layout type"); + inline LLSD LLQuaternion::getValue() const { LLSD ret; diff --git a/indra/llmath/llquaternion2.h b/indra/llmath/llquaternion2.h index 902bfb71342..c9dcc4573fa 100644 --- a/indra/llmath/llquaternion2.h +++ b/indra/llmath/llquaternion2.h @@ -49,7 +49,7 @@ class LLQuaternion2 ////////////////////////// // Ctor - LLQuaternion2() {} + LLQuaternion2() = default; // Ctor from LLQuaternion explicit LLQuaternion2( const class LLQuaternion& quat ); @@ -102,4 +102,6 @@ class LLQuaternion2 }; +static_assert(std::is_trivial::value, "LLQuaternion2 must be a trivial type"); + #endif diff --git a/indra/llmath/llrect.h b/indra/llmath/llrect.h index 317578da06d..0a3da2fee0c 100644 --- a/indra/llmath/llrect.h +++ b/indra/llmath/llrect.h @@ -51,10 +51,6 @@ template class LLRectBase LLRectBase(): mLeft(0), mTop(0), mRight(0), mBottom(0) {} - LLRectBase(const LLRectBase &r): - mLeft(r.mLeft), mTop(r.mTop), mRight(r.mRight), mBottom(r.mBottom) - {} - LLRectBase(Type left, Type top, Type right, Type bottom): mLeft(left), mTop(top), mRight(right), mBottom(bottom) {} @@ -295,4 +291,8 @@ template LLRectBase LLRectBase::null(0,0,0,0); typedef LLRectBase LLRect; typedef LLRectBase LLRectf; +static_assert(std::is_trivially_copyable::value, "LLRect must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLRect must be trivial move"); +static_assert(std::is_standard_layout::value, "LLRect must be a standard layout type"); + #endif diff --git a/indra/llmath/llsimdtypes.h b/indra/llmath/llsimdtypes.h index a407f51029e..6c4f55b0c08 100644 --- a/indra/llmath/llsimdtypes.h +++ b/indra/llmath/llsimdtypes.h @@ -36,7 +36,7 @@ typedef __m128 LLQuad; class LLBool32 { public: - inline LLBool32() {} + inline LLBool32() = default; inline LLBool32(int rhs) : m_bool(rhs) {} inline LLBool32(unsigned int rhs) : m_bool(rhs) {} inline LLBool32(bool rhs) { m_bool = static_cast(rhs); } @@ -46,13 +46,15 @@ class LLBool32 inline operator bool() const { return static_cast(m_bool); } private: - int m_bool{ 0 }; + int m_bool; }; +static_assert(std::is_trivial::value, "LLBool32 must be a standard layout type"); + class LLSimdScalar { public: - inline LLSimdScalar() {} + inline LLSimdScalar() = default; inline LLSimdScalar(LLQuad q) { mQ = q; @@ -100,7 +102,9 @@ class LLSimdScalar } private: - LLQuad mQ{}; + LLQuad mQ; }; +static_assert(std::is_trivial::value, "LLSimdScalar must be a standard layout type"); + #endif //LL_SIMD_TYPES_H diff --git a/indra/llmath/llvector4a.h b/indra/llmath/llvector4a.h index 8ef560dadf4..0fc55da12d0 100644 --- a/indra/llmath/llvector4a.h +++ b/indra/llmath/llvector4a.h @@ -92,10 +92,7 @@ class alignas(16) LLVector4a //////////////////////////////////// //LLVector4a is plain data which should never have a default constructor or destructor(malloc&free won't trigger it) - LLVector4a() - { //DO NOT INITIALIZE -- The overhead is completely unnecessary - ll_assert_aligned(this,16); - } + LLVector4a() = default; LLVector4a(F32 x, F32 y, F32 z, F32 w = 0.f) { @@ -358,16 +355,14 @@ class alignas(16) LLVector4a //////////////////////////////////// // Do NOT add aditional operators without consulting someone with SSE experience - inline const LLVector4a& operator= ( const LLVector4a& rhs ); - - inline const LLVector4a& operator= ( const LLQuad& rhs ); - inline operator LLQuad() const; private: - LLQuad mQ{}; + LLQuad mQ; }; +static_assert(std::is_trivial::value, "LLVector4a must be a trivial type"); + inline void update_min_max(LLVector4a& min, LLVector4a& max, const LLVector4a& p) { min.setMin(min, p); diff --git a/indra/llmath/llvector4a.inl b/indra/llmath/llvector4a.inl index 36dbec078cb..ddd7c72fb23 100644 --- a/indra/llmath/llvector4a.inl +++ b/indra/llmath/llvector4a.inl @@ -593,18 +593,6 @@ inline bool LLVector4a::equals3(const LLVector4a& rhs, F32 tolerance ) const //////////////////////////////////// // Do NOT add aditional operators without consulting someone with SSE experience -inline const LLVector4a& LLVector4a::operator= ( const LLVector4a& rhs ) -{ - mQ = rhs.mQ; - return *this; -} - -inline const LLVector4a& LLVector4a::operator= ( const LLQuad& rhs ) -{ - mQ = rhs; - return *this; -} - inline LLVector4a::operator LLQuad() const { return mQ; diff --git a/indra/llmath/llvector4logical.h b/indra/llmath/llvector4logical.h index 70759eef5c9..77cb5862e56 100644 --- a/indra/llmath/llvector4logical.h +++ b/indra/llmath/llvector4logical.h @@ -61,7 +61,7 @@ class LLVector4Logical }; // Empty default ctor - LLVector4Logical() {} + LLVector4Logical() = default; LLVector4Logical( const LLQuad& quad ) { @@ -120,7 +120,9 @@ class LLVector4Logical private: - LLQuad mQ{}; + LLQuad mQ; }; +static_assert(std::is_trivial::value, "LLVector4Logical must be a standard layout type"); + #endif //LL_VECTOR4ALOGICAL_H diff --git a/indra/llmath/m3math.h b/indra/llmath/m3math.h index 22b11d13b15..fba506510d6 100644 --- a/indra/llmath/m3math.h +++ b/indra/llmath/m3math.h @@ -141,6 +141,10 @@ class LLMatrix3 friend std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a); // Stream a }; +static_assert(std::is_trivially_copyable::value, "LLMatrix3 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLMatrix3 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLMatrix3 must be a standard layout type"); + inline LLMatrix3::LLMatrix3(void) { mMatrix[0][0] = 1.f; diff --git a/indra/llmath/m4math.cpp b/indra/llmath/m4math.cpp index a9853fe7e92..2a55ef5f869 100644 --- a/indra/llmath/m4math.cpp +++ b/indra/llmath/m4math.cpp @@ -113,12 +113,6 @@ LLMatrix4::LLMatrix4(const LLQuaternion &q) *this = initRotation(q); } -LLMatrix4::LLMatrix4(const LLMatrix4a& mat) - : LLMatrix4(mat.getF32ptr()) -{ - -} - LLMatrix4::LLMatrix4(const LLQuaternion &q, const LLVector4 &pos) { *this = initRotTrans(q, pos); @@ -156,10 +150,6 @@ LLMatrix4::LLMatrix4(const F32 roll, const F32 pitch, const F32 yaw) mMatrix[3][3] = 1.f; } -LLMatrix4::~LLMatrix4(void) -{ -} - // Clear and Assignment Functions const LLMatrix4& LLMatrix4::setZero() diff --git a/indra/llmath/m4math.h b/indra/llmath/m4math.h index b0f8c90cdfd..e1ca0bbdcb1 100644 --- a/indra/llmath/m4math.h +++ b/indra/llmath/m4math.h @@ -105,7 +105,6 @@ class LLMatrix4 explicit LLMatrix4(const F32 *mat); // Initializes Matrix to values in mat explicit LLMatrix4(const LLMatrix3 &mat); // Initializes Matrix to values in mat and sets position to (0,0,0) explicit LLMatrix4(const LLQuaternion &q); // Initializes Matrix with rotation q and sets position to (0,0,0) - explicit LLMatrix4(const LLMatrix4a& mat); LLMatrix4(const LLMatrix3 &mat, const LLVector4 &pos); // Initializes Matrix to values in mat and pos @@ -119,8 +118,6 @@ class LLMatrix4 const LLVector4 &pos); // Initializes Matrix with Euler angles LLMatrix4(const F32 roll, const F32 pitch, const F32 yaw); // Initializes Matrix with Euler angles - ~LLMatrix4(void); // Destructor - LLSD getValue() const; void setValue(const LLSD&); @@ -242,6 +239,10 @@ class LLMatrix4 friend std::ostream& operator<<(std::ostream& s, const LLMatrix4 &a); // Stream a }; +static_assert(std::is_trivially_copyable::value, "LLMatrix4 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLMatrix4 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLMatrix4 must be a standard layout type"); + inline const LLMatrix4& LLMatrix4::setIdentity() { mMatrix[0][0] = 1.f; diff --git a/indra/llmath/v2math.h b/indra/llmath/v2math.h index a0ba3ec5051..0d243698239 100644 --- a/indra/llmath/v2math.h +++ b/indra/llmath/v2math.h @@ -110,6 +110,9 @@ class LLVector2 friend std::ostream& operator<<(std::ostream& s, const LLVector2 &a); // Stream a }; +static_assert(std::is_trivially_copyable::value, "LLVector2 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLVector2 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLVector2 must be a standard layout type"); // Non-member functions diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 3763fc67258..122aaf6e7d4 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -144,6 +144,10 @@ class LLColor3 inline void exp(); // Do an exponential on the color }; +static_assert(std::is_trivially_copyable::value, "LLColor3 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLColor3 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLColor3 must be a standard layout type"); + LLColor3 lerp(const LLColor3& a, const LLColor3& b, F32 u); void LLColor3::clamp() diff --git a/indra/llmath/v3dmath.h b/indra/llmath/v3dmath.h index 7c94ebdf9be..2906be92949 100644 --- a/indra/llmath/v3dmath.h +++ b/indra/llmath/v3dmath.h @@ -130,6 +130,10 @@ class LLVector3d }; +static_assert(std::is_trivially_copyable::value, "LLVector3d must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLVector3d must be trivial move"); +static_assert(std::is_standard_layout::value, "LLVector3d must be a standard layout type"); + typedef LLVector3d LLGlobalVec; inline const LLVector3d &LLVector3d::set(const LLVector3 &vec) diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index 53491533c21..bc08a382f77 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -152,6 +152,10 @@ class LLVector3 static bool parseVector3(const std::string& buf, LLVector3* value); }; +static_assert(std::is_trivially_copyable::value, "LLVector3 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLVector3 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLVector3 must be a standard layout type"); + typedef LLVector3 LLSimLocalVec; // Non-member functions diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index a26db0428b2..e127cf83375 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -231,6 +231,10 @@ class LLColor4 inline void clamp(); }; +static_assert(std::is_trivially_copyable::value, "LLColor4 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLColor4 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLColor4 must be a standard layout type"); + // Non-member functions F32 distVec(const LLColor4& a, const LLColor4& b); // Returns distance between a and b F32 distVec_squared(const LLColor4& a, const LLColor4& b); // Returns distance squared between a and b diff --git a/indra/llmath/v4coloru.h b/indra/llmath/v4coloru.h index e1a02064614..1d19994dd6e 100644 --- a/indra/llmath/v4coloru.h +++ b/indra/llmath/v4coloru.h @@ -123,6 +123,10 @@ class LLColor4U static LLColor4U blue; }; +static_assert(std::is_trivially_copyable::value, "LLColor4U must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLColor4U must be trivial move"); +static_assert(std::is_standard_layout::value, "LLColor4U must be a standard layout type"); + // Non-member functions F32 distVec(const LLColor4U& a, const LLColor4U& b); // Returns distance between a and b F32 distVec_squared(const LLColor4U& a, const LLColor4U& b); // Returns distance squared between a and b diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index e2092d12773..cfa737f1dca 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -135,6 +135,10 @@ class LLVector4 friend LLVector4 operator-(const LLVector4 &a); // Return vector -a }; +static_assert(std::is_trivially_copyable::value, "LLVector4 must be trivial copy"); +static_assert(std::is_trivially_move_assignable::value, "LLVector4 must be trivial move"); +static_assert(std::is_standard_layout::value, "LLVector4 must be a standard layout type"); + // Non-member functions F32 angle_between(const LLVector4 &a, const LLVector4 &b); // Returns angle (radians) between a and b bool are_parallel(const LLVector4 &a, const LLVector4 &b, F32 epsilon = F_APPROXIMATELY_ZERO); // Returns true if a and b are very close to parallel diff --git a/indra/newview/llcontrolavatar.cpp b/indra/newview/llcontrolavatar.cpp index 92012418569..4b7cbfb4402 100644 --- a/indra/newview/llcontrolavatar.cpp +++ b/indra/newview/llcontrolavatar.cpp @@ -232,7 +232,7 @@ void LLControlAvatar::matchVolumeTransform() if (skin_info) { LL_DEBUGS("BindShape") << getFullname() << " bind shape " << skin_info->mBindShapeMatrix << LL_ENDL; - bind_rot = LLSkinningUtil::getUnscaledQuaternion(LLMatrix4(skin_info->mBindShapeMatrix)); + bind_rot = LLSkinningUtil::getUnscaledQuaternion(LLMatrix4(skin_info->mBindShapeMatrix.getF32ptr())); } #endif setRotation(bind_rot*obj_rot); diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index b726e21380f..a0b5ee36be3 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -761,9 +761,6 @@ static void xform4a(LLVector4a &tex_coord, const LLVector4a& trans, const LLVect // Texture transforms are done about the center of the face. st.setAdd(tex_coord, trans); - // Handle rotation - LLVector4a rot_st; - // LLVector4a s0; s0.splat(st, 0); @@ -2231,8 +2228,6 @@ bool LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius) if (joint) { - LLVector4a jointPos; - LLMatrix4a worldMat; worldMat.loadu((F32*)&joint->getWorldMatrix().mMatrix[0][0]); diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp index ecca593d513..34166c03dd9 100644 --- a/indra/newview/llmodelpreview.cpp +++ b/indra/newview/llmodelpreview.cpp @@ -518,7 +518,7 @@ void LLModelPreview::rebuildUploadData() bool upload_skinweights = fmp && fmp->childGetValue("upload_skin").asBoolean(); if (upload_skinweights && high_lod_model->mSkinInfo.mJointNames.size() > 0) { - LLQuaternion bind_rot = LLSkinningUtil::getUnscaledQuaternion(LLMatrix4(high_lod_model->mSkinInfo.mBindShapeMatrix)); + LLQuaternion bind_rot = LLSkinningUtil::getUnscaledQuaternion(LLMatrix4(high_lod_model->mSkinInfo.mBindShapeMatrix.getF32ptr())); LLQuaternion identity; if (!bind_rot.isEqualEps(identity, 0.01)) {