Drake's trivially copyable optimop

This commit is contained in:
Lirusaito
2019-04-11 05:02:43 -04:00
parent 7fc90d3dce
commit c9eac98d53
20 changed files with 52 additions and 65 deletions

View File

@@ -57,10 +57,10 @@ public:
LLUUID(); LLUUID();
explicit LLUUID(const char *in_string); // Convert from string. explicit LLUUID(const char *in_string); // Convert from string.
explicit LLUUID(const std::string& in_string); // Convert from string. explicit LLUUID(const std::string& in_string); // Convert from string.
LLUUID(const LLUUID &in); LLUUID(const LLUUID &in) = default;
LLUUID &operator=(const LLUUID &rhs); LLUUID &operator=(const LLUUID &rhs) = default;
~LLUUID(); ~LLUUID() = default;
// //
// MANIPULATORS // MANIPULATORS
@@ -193,24 +193,6 @@ inline BOOL LLUUID::isNull() const
return !memcmp(mData, null.mData, sizeof(mData)); // <alchemy/> return !memcmp(mData, null.mData, sizeof(mData)); // <alchemy/>
} }
// Copy constructor
inline LLUUID::LLUUID(const LLUUID& rhs)
{
memcpy(mData, rhs.mData, sizeof(mData)); // <alchemy/>
}
inline LLUUID::~LLUUID()
{
}
// Assignment
inline LLUUID& LLUUID::operator=(const LLUUID& rhs)
{
memcpy(mData, rhs.mData, sizeof(mData)); // <alchemy/>
return *this;
}
inline LLUUID::LLUUID(const char *in_string) inline LLUUID::LLUUID(const char *in_string)
{ {
if (!in_string || in_string[0] == 0) if (!in_string || in_string[0] == 0)
@@ -289,6 +271,8 @@ inline U32 LLUUID::getCRC32() const
// </alchemy> // </alchemy>
} }
static_assert(std::is_trivially_copyable<LLUUID>{}, "LLUUID must be a trivially copyable type");
typedef std::vector<LLUUID> uuid_vec_t; typedef std::vector<LLUUID> uuid_vec_t;
typedef boost::unordered_set<LLUUID> uuid_set_t; typedef boost::unordered_set<LLUUID> uuid_set_t;

View File

@@ -127,4 +127,6 @@ public:
inline bool isOkRotation() const; inline bool isOkRotation() const;
} LL_ALIGN_POSTFIX(16); } LL_ALIGN_POSTFIX(16);
static_assert(std::is_trivially_copyable<LLMatrix3a>{}, "LLMatrix3a must be a trivially copyable type");
static_assert(std::is_trivially_copyable<LLRotation>{}, "LLRotation must be a trivially copyable type");
#endif #endif

View File

@@ -708,4 +708,6 @@ inline std::ostream& operator<<(std::ostream& s, const LLMatrix4a& m)
} }
void matMulBoundBox(const LLMatrix4a &a, const LLVector4a *in_extents, LLVector4a *out_extents); void matMulBoundBox(const LLMatrix4a &a, const LLVector4a *in_extents, LLVector4a *out_extents);
static_assert(std::is_trivially_copyable<LLMatrix4a>{}, "LLMatrix4a must be a trivially copyable type");
#endif #endif

View File

@@ -191,6 +191,8 @@ inline void LLQuaternion::setValue(const LLSD& sd)
mQ[3] = sd[3].asReal(); mQ[3] = sd[3].asReal();
} }
static_assert(std::is_trivially_copyable<LLQuaternion>{}, "LLQuaternion must be a trivially copyable type");
// checker // checker
inline BOOL LLQuaternion::isFinite() const inline BOOL LLQuaternion::isFinite() const
{ {

View File

@@ -105,4 +105,6 @@ protected:
} LL_ALIGN_POSTFIX(16); } LL_ALIGN_POSTFIX(16);
static_assert(std::is_trivially_copyable<LLQuaternion2>{}, "LLQuaternion2 must be a trivially copyable type");
#endif #endif

View File

@@ -121,4 +121,7 @@ private:
LLQuad mQ; LLQuad mQ;
}; };
static_assert(std::is_trivially_copyable<LLBool32>{}, "LLBool32 must be a trivially copyable type");
static_assert(std::is_trivially_copyable<LLSimdScalar>{}, "LLSimdScalar must be a trivially copyable type");
#endif //LL_SIMD_TYPES_H #endif //LL_SIMD_TYPES_H

View File

@@ -96,12 +96,12 @@ public:
{ //DO NOT INITIALIZE -- The overhead is completely unnecessary { //DO NOT INITIALIZE -- The overhead is completely unnecessary
ll_assert_aligned(this,16); ll_assert_aligned(this,16);
} }
LLVector4a(F32 x, F32 y, F32 z, F32 w = 0.f) LLVector4a(F32 x, F32 y, F32 z, F32 w = 0.f)
{ {
set(x,y,z,w); set(x, y, z, w);
} }
LLVector4a(F32 x) LLVector4a(F32 x)
{ {
splat(x); splat(x);
@@ -320,9 +320,13 @@ public:
//////////////////////////////////// ////////////////////////////////////
// Do NOT add aditional operators without consulting someone with SSE experience // Do NOT add aditional operators without consulting someone with SSE experience
inline const LLVector4a& operator= ( const LLVector4a& rhs ); //inline const LLVector4a& operator= ( const LLVector4a& rhs );
//{
// mQ = rhs.mQ;
// return *this;
//}
inline const LLVector4a& operator= ( const LLQuad& rhs ); inline const LLVector4a& operator= (const LLQuad& rhs);
inline operator LLQuad() const; inline operator LLQuad() const;
@@ -341,4 +345,6 @@ inline std::ostream& operator<<(std::ostream& s, const LLVector4a& v)
s << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")"; s << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
return s; return s;
} }
static_assert(std::is_trivially_copyable<LLVector4a>{}, "LLVector4a must be a trivially copyable type");
#endif #endif

View File

@@ -605,13 +605,7 @@ inline bool LLVector4a::equals3(const LLVector4a& rhs, F32 tolerance ) const
//////////////////////////////////// ////////////////////////////////////
// Do NOT add aditional operators without consulting someone with SSE experience // Do NOT add aditional operators without consulting someone with SSE experience
inline const LLVector4a& LLVector4a::operator= ( const LLVector4a& rhs ) inline const LLVector4a& LLVector4a::operator= (const LLQuad& rhs)
{
mQ = rhs.mQ;
return *this;
}
inline const LLVector4a& LLVector4a::operator= ( const LLQuad& rhs )
{ {
mQ = rhs; mQ = rhs;
return *this; return *this;

View File

@@ -144,6 +144,8 @@ class LLMatrix3
friend std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a); // Stream a friend std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a); // Stream a
}; };
static_assert(std::is_trivially_copyable<LLMatrix3>{}, "LLMatrix3 must be a trivially copyable type");
inline LLMatrix3::LLMatrix3(void) inline LLMatrix3::LLMatrix3(void)
{ {
mMatrix[0][0] = 1.f; mMatrix[0][0] = 1.f;

View File

@@ -152,10 +152,6 @@ LLMatrix4::LLMatrix4(const F32 roll, const F32 pitch, const F32 yaw)
mMatrix[3][3] = 1.f; mMatrix[3][3] = 1.f;
} }
LLMatrix4::~LLMatrix4(void)
{
}
// Clear and Assignment Functions // Clear and Assignment Functions
const LLMatrix4& LLMatrix4::setZero() const LLMatrix4& LLMatrix4::setZero()

View File

@@ -117,7 +117,7 @@ public:
const LLVector4 &pos); // Initializes Matrix with Euler angles const LLVector4 &pos); // Initializes Matrix with Euler angles
LLMatrix4(const F32 roll, const F32 pitch, const F32 yaw); // Initializes Matrix with Euler angles LLMatrix4(const F32 roll, const F32 pitch, const F32 yaw); // Initializes Matrix with Euler angles
~LLMatrix4(void); // Destructor ~LLMatrix4() = default; // Destructor
LLSD getValue() const; LLSD getValue() const;
void setValue(const LLSD&); void setValue(const LLSD&);
@@ -246,6 +246,8 @@ public:
friend std::ostream& operator<<(std::ostream& s, const LLMatrix4 &a); // Stream a friend std::ostream& operator<<(std::ostream& s, const LLMatrix4 &a); // Stream a
}; };
static_assert(std::is_trivially_copyable<LLMatrix4>{}, "LLMatrix4 must be a trivially copyable type");
inline const LLMatrix4& LLMatrix4::setIdentity() inline const LLMatrix4& LLMatrix4::setIdentity()
{ {
mMatrix[0][0] = 1.f; mMatrix[0][0] = 1.f;

View File

@@ -110,6 +110,7 @@ class LLVector2
friend std::ostream& operator<<(std::ostream& s, const LLVector2 &a); // Stream a friend std::ostream& operator<<(std::ostream& s, const LLVector2 &a); // Stream a
}; };
static_assert(std::is_trivially_copyable<LLVector2>{}, "LLVector2 must be a trivially copyable type");
// Non-member functions // Non-member functions

View File

@@ -140,6 +140,8 @@ public:
inline void exp(); // Do an exponential on the color inline void exp(); // Do an exponential on the color
}; };
static_assert(std::is_trivially_copyable<LLColor3>{}, "LLColor3 must be a trivially copyable type");
LLColor3 lerp(const LLColor3 &a, const LLColor3 &b, F32 u); LLColor3 lerp(const LLColor3 &a, const LLColor3 &b, F32 u);

View File

@@ -130,6 +130,8 @@ class LLVector3d
}; };
static_assert(std::is_trivially_copyable<LLVector3d>{}, "LLVector3d must be a trivially copyable type");
typedef LLVector3d LLGlobalVec; typedef LLVector3d LLGlobalVec;
inline const LLVector3d &LLVector3d::set(const LLVector3 &vec) inline const LLVector3d &LLVector3d::set(const LLVector3 &vec)

View File

@@ -149,6 +149,8 @@ class LLVector3
static BOOL parseVector3(const std::string& buf, LLVector3* value); static BOOL parseVector3(const std::string& buf, LLVector3* value);
}; };
static_assert(std::is_trivially_copyable<LLVector3>{}, "LLVector3 must be a trivially copyable type");
typedef LLVector3 LLSimLocalVec; typedef LLVector3 LLSimLocalVec;
// Non-member functions // Non-member functions

View File

@@ -222,6 +222,7 @@ class LLColor4
inline void clamp(); inline void clamp();
}; };
static_assert(std::is_trivially_copyable<LLColor4>{}, "LLColor4 must be a trivially copyable type");
// Non-member functions // Non-member functions
F32 distVec(const LLColor4 &a, const LLColor4 &b); // Returns distance between a and b F32 distVec(const LLColor4 &a, const LLColor4 &b); // Returns distance between a and b

View File

@@ -139,6 +139,7 @@ public:
static LLColor4U blue; static LLColor4U blue;
}; };
static_assert(std::is_trivially_copyable<LLColor4U>{}, "LLColor4U must be a trivially copyable type");
// Non-member functions // Non-member functions
F32 distVec(const LLColor4U &a, const LLColor4U &b); // Returns distance between a and b F32 distVec(const LLColor4U &a, const LLColor4U &b); // Returns distance between a and b

View File

@@ -137,6 +137,8 @@ class LLVector4
friend LLVector4 operator-(const LLVector4 &a); // Return vector -a friend LLVector4 operator-(const LLVector4 &a); // Return vector -a
}; };
static_assert(std::is_trivially_copyable<LLVector4>{}, "LLVector4 must be a trivially copyable type");
// Non-member functions // Non-member functions
F32 angle_between(const LLVector4 &a, const LLVector4 &b); // Returns angle (radians) between a and b 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 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

View File

@@ -56,15 +56,6 @@ LLMaterialID::LLMaterialID(const void* pMemory)
set(pMemory); set(pMemory);
} }
LLMaterialID::LLMaterialID(const LLMaterialID& pOtherMaterialID)
{
copyFromOtherMaterialID(pOtherMaterialID);
}
LLMaterialID::~LLMaterialID()
{
}
bool LLMaterialID::operator == (const LLMaterialID& pOtherMaterialID) const bool LLMaterialID::operator == (const LLMaterialID& pOtherMaterialID) const
{ {
return (compareToOtherMaterialID(pOtherMaterialID) == 0); return (compareToOtherMaterialID(pOtherMaterialID) == 0);
@@ -95,12 +86,6 @@ bool LLMaterialID::operator >= (const LLMaterialID& pOtherMaterialID) const
return (compareToOtherMaterialID(pOtherMaterialID) >= 0); return (compareToOtherMaterialID(pOtherMaterialID) >= 0);
} }
LLMaterialID& LLMaterialID::operator = (const LLMaterialID& pOtherMaterialID)
{
copyFromOtherMaterialID(pOtherMaterialID);
return (*this);
}
bool LLMaterialID::isNull() const bool LLMaterialID::isNull() const
{ {
return (compareToOtherMaterialID(LLMaterialID::null) == 0); return (compareToOtherMaterialID(LLMaterialID::null) == 0);
@@ -116,12 +101,12 @@ void LLMaterialID::set(const void* pMemory)
llassert(pMemory != NULL); llassert(pMemory != NULL);
// assumes that the required size of memory is available // assumes that the required size of memory is available
memcpy(mID, pMemory, MATERIAL_ID_SIZE * sizeof(U8)); memcpy(mID, pMemory, sizeof(mID));
} }
void LLMaterialID::clear() void LLMaterialID::clear()
{ {
memset(mID, 0, MATERIAL_ID_SIZE * sizeof(U8)); memset(mID, 0, sizeof(mID));
} }
LLSD LLMaterialID::asLLSD() const LLSD LLMaterialID::asLLSD() const
@@ -156,18 +141,12 @@ std::ostream& operator<<(std::ostream& s, const LLMaterialID &material_id)
return s; return s;
} }
void LLMaterialID::parseFromBinary (const LLSD::Binary& pMaterialID) void LLMaterialID::parseFromBinary (const LLSD::Binary& pMaterialID)
{ {
llassert(pMaterialID.size() == (MATERIAL_ID_SIZE * sizeof(U8))); llassert(pMaterialID.size() == (MATERIAL_ID_SIZE * sizeof(U8)));
memcpy(mID, &pMaterialID[0], MATERIAL_ID_SIZE * sizeof(U8)); memcpy(mID, &pMaterialID[0], MATERIAL_ID_SIZE * sizeof(U8));
} }
void LLMaterialID::copyFromOtherMaterialID(const LLMaterialID& pOtherMaterialID)
{
memcpy(mID, pOtherMaterialID.get(), MATERIAL_ID_SIZE * sizeof(U8));
}
int LLMaterialID::compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const int LLMaterialID::compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const
{ {
int retVal = 0; int retVal = 0;

View File

@@ -39,8 +39,8 @@ public:
LLMaterialID(const LLSD& pMaterialID); LLMaterialID(const LLSD& pMaterialID);
LLMaterialID(const LLSD::Binary& pMaterialID); LLMaterialID(const LLSD::Binary& pMaterialID);
LLMaterialID(const void* pMemory); LLMaterialID(const void* pMemory);
LLMaterialID(const LLMaterialID& pOtherMaterialID); LLMaterialID(const LLMaterialID& pOtherMaterialID) = default;
~LLMaterialID(); ~LLMaterialID() = default;
bool operator == (const LLMaterialID& pOtherMaterialID) const; bool operator == (const LLMaterialID& pOtherMaterialID) const;
bool operator != (const LLMaterialID& pOtherMaterialID) const; bool operator != (const LLMaterialID& pOtherMaterialID) const;
@@ -50,7 +50,7 @@ public:
bool operator > (const LLMaterialID& pOtherMaterialID) const; bool operator > (const LLMaterialID& pOtherMaterialID) const;
bool operator >= (const LLMaterialID& pOtherMaterialID) const; bool operator >= (const LLMaterialID& pOtherMaterialID) const;
LLMaterialID& operator = (const LLMaterialID& pOtherMaterialID); LLMaterialID& operator = (const LLMaterialID& pOtherMaterialID) = default;
bool isNull() const; bool isNull() const;
@@ -67,11 +67,13 @@ public:
private: private:
void parseFromBinary(const LLSD::Binary& pMaterialID); void parseFromBinary(const LLSD::Binary& pMaterialID);
void copyFromOtherMaterialID(const LLMaterialID& pOtherMaterialID);
int compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const; int compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const;
U8 mID[MATERIAL_ID_SIZE]; U8 mID[MATERIAL_ID_SIZE];
} ; } ;
static_assert(sizeof(LLMaterialID) == MATERIAL_ID_SIZE, "LLMaterialID must be sizeof(mID)");
static_assert(std::is_trivially_copyable<LLMaterialID>{}, "LLMaterialID must be a trivially copyable type");
#endif // LL_LLMATERIALID_H #endif // LL_LLMATERIALID_H