Restore math types to trivially copyable and add static asserts

master
Rye 2025-02-02 03:40:21 -05:00
parent 6fcd349f37
commit 39a13e4088
25 changed files with 84 additions and 40 deletions

View File

@ -95,6 +95,10 @@ private:
bool mEmpty; // Nothing has been added to this bbox yet
};
static_assert(std::is_trivially_copyable<LLBBox>::value, "LLBBox must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLBBox>::value, "LLBBox must be trivial move");
static_assert(std::is_standard_layout<LLBBox>::value, "LLBBox must be a standard layout type");
//LLBBox operator*(const LLBBox &a, const LLMatrix4 &b);

View File

@ -61,5 +61,8 @@ private:
LLBBoxLocal operator*(const LLBBoxLocal &a, const LLMatrix4 &b);
static_assert(std::is_trivially_copyable<LLBBoxLocal>::value, "LLBBoxLocal must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLBBoxLocal>::value, "LLBBoxLocal must be trivial move");
static_assert(std::is_standard_layout<LLBBoxLocal>::value, "LLBBoxLocal must be a standard layout type");
#endif // LL_BBOXLOCAL_H

View File

@ -26,7 +26,6 @@
#include "linden_common.h"
//#include "vmath.h"
#include "v3math.h"
#include "m3math.h"
#include "v4math.h"

View File

@ -40,7 +40,7 @@ class LLLine
public:
LLLine();
LLLine( const LLVector3& first_point, const LLVector3& second_point );
virtual ~LLLine() {};
~LLLine() = default;
void setPointDirection( const LLVector3& first_point, const LLVector3& second_point );
void setPoints( const LLVector3& first_point, const LLVector3& second_point );
@ -76,5 +76,8 @@ protected:
LLVector3 mDirection;
};
static_assert(std::is_trivially_copyable<LLLine>::value, "LLLine must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLLine>::value, "LLLine must be trivial move");
static_assert(std::is_standard_layout<LLLine>::value, "LLLine must be a standard layout type");
#endif

View File

@ -56,7 +56,7 @@ public:
//////////////////////////
// Ctor
LLMatrix3a() {}
LLMatrix3a() = default;
// Ctor for setting by columns
inline LLMatrix3a( const LLVector4a& c0, const LLVector4a& c1, const LLVector4a& c2 );
@ -115,14 +115,18 @@ protected:
};
static_assert(std::is_trivial<LLMatrix3a>::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<LLRotation>::value, "LLRotation must be a trivial type");
#endif

View File

@ -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 @@ public:
const LLVector4a& getTranslation() const { return mMatrix[3]; }
};
static_assert(std::is_trivial<LLMatrix4a>::value, "LLMatrix4a must be a trivial type");
inline LLVector4a rowMul(const LLVector4a &row, const LLMatrix4a &mat)
{
LLVector4a result;

View File

@ -43,7 +43,7 @@ class LLPlane
public:
// Constructors
LLPlane() {}; // no default constructor
LLPlane() = default;
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 @@ private:
LLVector4a mV;
} LL_ALIGN_POSTFIX(16);
static_assert(std::is_trivial<LLPlane>::value, "LLPlane must be a trivial type");
#endif // LL_LLPLANE_H

View File

@ -174,6 +174,10 @@ public:
//static U32 mMultCount;
};
static_assert(std::is_trivially_copyable<LLQuaternion>::value, "LLQuaternion must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLQuaternion>::value, "LLQuaternion must be trivial move");
static_assert(std::is_standard_layout<LLQuaternion>::value, "LLQuaternion must be a standard layout type");
inline LLSD LLQuaternion::getValue() const
{
LLSD ret;

View File

@ -49,7 +49,7 @@ public:
//////////////////////////
// Ctor
LLQuaternion2() {}
LLQuaternion2() = default;
// Ctor from LLQuaternion
explicit LLQuaternion2( const class LLQuaternion& quat );
@ -102,4 +102,6 @@ protected:
};
static_assert(std::is_trivial<LLQuaternion2>::value, "LLQuaternion2 must be a trivial type");
#endif

View File

@ -51,10 +51,6 @@ public:
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 <class Type> LLRectBase<Type> LLRectBase<Type>::null(0,0,0,0);
typedef LLRectBase<S32> LLRect;
typedef LLRectBase<F32> LLRectf;
static_assert(std::is_trivially_copyable<LLRect>::value, "LLRect must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLRect>::value, "LLRect must be trivial move");
static_assert(std::is_standard_layout<LLRect>::value, "LLRect must be a standard layout type");
#endif

View File

@ -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<const int>(rhs); }
@ -46,13 +46,15 @@ public:
inline operator bool() const { return static_cast<const bool&>(m_bool); }
private:
int m_bool{ 0 };
int m_bool;
};
static_assert(std::is_trivial<LLBool32>::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 @@ public:
}
private:
LLQuad mQ{};
LLQuad mQ;
};
static_assert(std::is_trivial<LLSimdScalar>::value, "LLSimdScalar must be a standard layout type");
#endif //LL_SIMD_TYPES_H

View File

@ -24,6 +24,8 @@
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llmemory.h"
#include "llmath.h"
#include "llquantize.h"

View File

@ -95,10 +95,7 @@ public:
////////////////////////////////////
//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)
{
@ -361,8 +358,6 @@ public:
////////////////////////////////////
// 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;
@ -378,9 +373,11 @@ public:
};
private:
LLQuad mQ{};
LLQuad mQ;
};
static_assert(std::is_trivial<LLVector4a>::value, "LLVector4a must be a trivial type");
inline void update_min_max(LLVector4a& min, LLVector4a& max, const LLVector4a& p)
{
min.setMin(min, p);

View File

@ -593,12 +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;

View File

@ -61,7 +61,7 @@ public:
};
// Empty default ctor
LLVector4Logical() {}
LLVector4Logical() = default;
LLVector4Logical( const LLQuad& quad )
{
@ -120,7 +120,9 @@ public:
private:
LLQuad mQ{};
LLQuad mQ;
};
static_assert(std::is_trivial<LLVector4Logical>::value, "LLVector4Logical must be a standard layout type");
#endif //LL_VECTOR4ALOGICAL_H

View File

@ -142,6 +142,10 @@ class LLMatrix3
friend std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a); // Stream a
};
static_assert(std::is_trivially_copyable<LLMatrix3>::value, "LLMatrix3 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLMatrix3>::value, "LLMatrix3 must be trivial move");
static_assert(std::is_standard_layout<LLMatrix3>::value, "LLMatrix3 must be a standard layout type");
inline LLMatrix3::LLMatrix3(void)
{
mMatrix[0][0] = 1.f;

View File

@ -157,10 +157,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()

View File

@ -119,8 +119,6 @@ public:
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 +240,10 @@ public:
friend std::ostream& operator<<(std::ostream& s, const LLMatrix4 &a); // Stream a
};
static_assert(std::is_trivially_copyable<LLMatrix4>::value, "LLMatrix4 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLMatrix4>::value, "LLMatrix4 must be trivial move");
static_assert(std::is_standard_layout<LLMatrix4>::value, "LLMatrix4 must be a standard layout type");
inline const LLMatrix4& LLMatrix4::setIdentity()
{
mMatrix[0][0] = 1.f;

View File

@ -110,6 +110,9 @@ class LLVector2
friend std::ostream& operator<<(std::ostream& s, const LLVector2 &a); // Stream a
};
static_assert(std::is_trivially_copyable<LLVector2>::value, "LLVector2 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLVector2>::value, "LLVector2 must be trivial move");
static_assert(std::is_standard_layout<LLVector2>::value, "LLVector2 must be a standard layout type");
// Non-member functions

View File

@ -151,8 +151,11 @@ public:
inline void exp(); // Do an exponential on the color
};
LLColor3 lerp(const LLColor3 &a, const LLColor3 &b, F32 u);
static_assert(std::is_trivially_copyable<LLColor3>::value, "LLColor3 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLColor3>::value, "LLColor3 must be trivial move");
static_assert(std::is_standard_layout<LLColor3>::value, "LLColor3 must be a standard layout type");
LLColor3 lerp(const LLColor3& a, const LLColor3& b, F32 u);
void LLColor3::clamp()
{

View File

@ -130,6 +130,10 @@ class LLVector3d
};
static_assert(std::is_trivially_copyable<LLVector3d>::value, "LLVector3d must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLVector3d>::value, "LLVector3d must be trivial move");
static_assert(std::is_standard_layout<LLVector3d>::value, "LLVector3d must be a standard layout type");
typedef LLVector3d LLGlobalVec;
inline const LLVector3d &LLVector3d::set(const LLVector3 &vec)

View File

@ -164,6 +164,10 @@ class LLVector3
static bool parseVector3(const std::string& buf, LLVector3* value);
};
static_assert(std::is_trivially_copyable<LLVector3>::value, "LLVector3 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLVector3>::value, "LLVector3 must be trivial move");
static_assert(std::is_standard_layout<LLVector3>::value, "LLVector3 must be a standard layout type");
typedef LLVector3 LLSimLocalVec;
// Non-member functions

View File

@ -232,6 +232,9 @@ class LLColor4
inline void clamp();
};
static_assert(std::is_trivially_copyable<LLColor4>::value, "LLColor4 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLColor4>::value, "LLColor4 must be trivial move");
static_assert(std::is_standard_layout<LLColor4>::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

View File

@ -134,6 +134,9 @@ public:
static LLColor4U blue;
};
static_assert(std::is_trivially_copyable<LLColor4U>::value, "LLColor4U must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLColor4U>::value, "LLColor4U must be trivial move");
static_assert(std::is_standard_layout<LLColor4U>::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

View File

@ -146,6 +146,10 @@ class LLVector4
friend LLVector4 operator-(const LLVector4 &a); // Return vector -a
};
static_assert(std::is_trivially_copyable<LLVector4>::value, "LLVector4 must be trivial copy");
static_assert(std::is_trivially_move_assignable<LLVector4>::value, "LLVector4 must be trivial move");
static_assert(std::is_standard_layout<LLVector4>::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