Skip to content

Commit

Permalink
Restore various llmath types to trivially copyable/movable and restor…
Browse files Browse the repository at this point in the history
…e SIMD types to trivial
  • Loading branch information
RyeMutt committed Nov 21, 2024
1 parent 65a99a7 commit 4cd44de
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 61 deletions.
4 changes: 4 additions & 0 deletions indra/llmath/llbbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class LLBBox
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);


Expand Down
5 changes: 4 additions & 1 deletion indra/llmath/llbboxlocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -61,5 +61,8 @@ class LLBBoxLocal

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
4 changes: 3 additions & 1 deletion indra/llmath/llline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -76,5 +75,8 @@ class LLLine
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
9 changes: 7 additions & 2 deletions indra/llmath/llmatrix3a.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -115,14 +115,19 @@ class LLMatrix3a

};

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
7 changes: 3 additions & 4 deletions indra/llmath/llmatrix4a.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class LLMatrix4a
public:
LL_ALIGN_16(LLVector4a mMatrix[4]);

LLMatrix4a()
{

}
LLMatrix4a() = default;

explicit LLMatrix4a(const LLMatrix4& val)
{
Expand Down Expand Up @@ -228,6 +225,8 @@ class LLMatrix4a
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;
Expand Down
3 changes: 2 additions & 1 deletion indra/llmath/llplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -104,6 +104,7 @@ class LLPlane
LLVector4a mV;
} LL_ALIGN_POSTFIX(16);

static_assert(std::is_trivial<LLPlane>::value, "LLPlane must be a trivial type");


#endif // LL_LLPLANE_H
4 changes: 4 additions & 0 deletions indra/llmath/llquaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class LLQuaternion
//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;
Expand Down
4 changes: 3 additions & 1 deletion indra/llmath/llquaternion2.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LLQuaternion2
//////////////////////////

// Ctor
LLQuaternion2() {}
LLQuaternion2() = default;

// Ctor from LLQuaternion
explicit LLQuaternion2( const class LLQuaternion& quat );
Expand Down Expand Up @@ -102,4 +102,6 @@ class LLQuaternion2

};

static_assert(std::is_trivial<LLQuaternion2>::value, "LLQuaternion2 must be a trivial type");

#endif
8 changes: 4 additions & 4 deletions indra/llmath/llrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ template <class Type> 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)
{}
Expand Down Expand Up @@ -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
12 changes: 8 additions & 4 deletions indra/llmath/llsimdtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand All @@ -46,13 +46,15 @@ class LLBool32
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;
Expand Down Expand Up @@ -100,7 +102,9 @@ class LLSimdScalar
}

private:
LLQuad mQ{};
LLQuad mQ;
};

static_assert(std::is_trivial<LLSimdScalar>::value, "LLSimdScalar must be a standard layout type");

#endif //LL_SIMD_TYPES_H
13 changes: 4 additions & 9 deletions indra/llmath/llvector4a.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<LLVector4a>::value, "LLVector4a must be a trivial type");

inline void update_min_max(LLVector4a& min, LLVector4a& max, const LLVector4a& p)
{
min.setMin(min, p);
Expand Down
12 changes: 0 additions & 12 deletions indra/llmath/llvector4a.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions indra/llmath/llvector4logical.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class LLVector4Logical
};

// Empty default ctor
LLVector4Logical() {}
LLVector4Logical() = default;

LLVector4Logical( const LLQuad& quad )
{
Expand Down Expand Up @@ -120,7 +120,9 @@ class LLVector4Logical

private:

LLQuad mQ{};
LLQuad mQ;
};

static_assert(std::is_trivial<LLVector4Logical>::value, "LLVector4Logical must be a standard layout type");

#endif //LL_VECTOR4ALOGICAL_H
4 changes: 4 additions & 0 deletions indra/llmath/m3math.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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;
Expand Down
10 changes: 0 additions & 10 deletions indra/llmath/m4math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions indra/llmath/m4math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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&);

Expand Down Expand Up @@ -242,6 +239,10 @@ class LLMatrix4
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;
Expand Down
3 changes: 3 additions & 0 deletions indra/llmath/v2math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions indra/llmath/v3color.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class LLColor3
inline void exp(); // Do an exponential on the color
};

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()
Expand Down
4 changes: 4 additions & 0 deletions indra/llmath/v3dmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions indra/llmath/v3math.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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
Expand Down
4 changes: 4 additions & 0 deletions indra/llmath/v4color.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ 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
F32 distVec_squared(const LLColor4& a, const LLColor4& b); // Returns distance squared between a and b
Expand Down
4 changes: 4 additions & 0 deletions indra/llmath/v4coloru.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class LLColor4U
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
F32 distVec_squared(const LLColor4U& a, const LLColor4U& b); // Returns distance squared between a and b
Expand Down
Loading

0 comments on commit 4cd44de

Please sign in to comment.