From 5520001117ecca277a12d43461cfa1180af5178f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 Apr 2020 03:16:34 -0400 Subject: [PATCH] General: Mark file-scope constexpr variables as inline Allows the compiler to unify all usages of these constants down to a single address if they're ODR used, rather than creating an individual copy within each translation unit. Unfortunately all file-scope variables don't have inline implied for them by default (only for static class member variables). Shrinks the size of the emitted binary a little bit. --- include/zeus/CAABox.hpp | 4 ++-- include/zeus/CColor.hpp | 24 ++++++++++++------------ include/zeus/CVector2f.hpp | 6 +++--- include/zeus/CVector3d.hpp | 2 +- include/zeus/CVector3f.hpp | 22 +++++++++++----------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/zeus/CAABox.hpp b/include/zeus/CAABox.hpp index dac571c..58c893f 100644 --- a/include/zeus/CAABox.hpp +++ b/include/zeus/CAABox.hpp @@ -309,8 +309,8 @@ public: return max[idx - 3]; } }; -constexpr CAABox skInvertedBox; -constexpr CAABox skNullBox(CVector3f{}, CVector3f{}); +constexpr inline CAABox skInvertedBox; +constexpr inline CAABox skNullBox(CVector3f{}, CVector3f{}); [[nodiscard]] inline bool operator==(const CAABox& left, const CAABox& right) { return (left.min == right.min && left.max == right.max); diff --git a/include/zeus/CColor.hpp b/include/zeus/CColor.hpp index ab64d47..c1a62d1 100644 --- a/include/zeus/CColor.hpp +++ b/include/zeus/CColor.hpp @@ -310,18 +310,18 @@ constexpr CVector4f& CVector4f::operator=(const CColor& other) { return *this; } -constexpr CColor skRed(1.f, 0.f, 0.f, 1.f); -constexpr CColor skBlack(0.f, 0.f, 0.f, 1.f); -constexpr CColor skBlue(0.f, 0.f, 1.f, 1.f); -constexpr CColor skCyan(0.f, 1.f, 1.f, 1.f); -constexpr CColor skGreen(0.f, 1.f, 0.f, 1.f); -constexpr CColor skGrey(0.5f, 0.5f, 0.5f, 1.f); -constexpr CColor skMagenta(1.f, 0.f, 1.f, 1.f); -constexpr CColor skOrange(1.f, 0.43f, 0.f, 1.f); -constexpr CColor skPurple(0.63f, 0.f, 1.f, 1.f); -constexpr CColor skYellow(1.f, 1.f, 0.f, 1.f); -constexpr CColor skWhite(1.f, 1.f, 1.f, 1.f); -constexpr CColor skClear(0.f, 0.f, 0.f, 0.f); +constexpr inline CColor skRed(1.f, 0.f, 0.f, 1.f); +constexpr inline CColor skBlack(0.f, 0.f, 0.f, 1.f); +constexpr inline CColor skBlue(0.f, 0.f, 1.f, 1.f); +constexpr inline CColor skCyan(0.f, 1.f, 1.f, 1.f); +constexpr inline CColor skGreen(0.f, 1.f, 0.f, 1.f); +constexpr inline CColor skGrey(0.5f, 0.5f, 0.5f, 1.f); +constexpr inline CColor skMagenta(1.f, 0.f, 1.f, 1.f); +constexpr inline CColor skOrange(1.f, 0.43f, 0.f, 1.f); +constexpr inline CColor skPurple(0.63f, 0.f, 1.f, 1.f); +constexpr inline CColor skYellow(1.f, 1.f, 0.f, 1.f); +constexpr inline CColor skWhite(1.f, 1.f, 1.f, 1.f); +constexpr inline CColor skClear(0.f, 0.f, 0.f, 0.f); [[nodiscard]] inline CColor operator+(float lhs, const CColor& rhs) { return CColor(simd(lhs) + rhs.mSimd).Clamp(); diff --git a/include/zeus/CVector2f.hpp b/include/zeus/CVector2f.hpp index 266cae1..b05c9d2 100644 --- a/include/zeus/CVector2f.hpp +++ b/include/zeus/CVector2f.hpp @@ -207,9 +207,9 @@ public: [[nodiscard]] simd::reference x() { return mSimd[0]; } [[nodiscard]] simd::reference y() { return mSimd[1]; } }; -constexpr CVector2f skOne2f(1.f); -constexpr CVector2f skNegOne2f(-1.f); -constexpr CVector2f skZero2f(0.f); +constexpr inline CVector2f skOne2f(1.f); +constexpr inline CVector2f skNegOne2f(-1.f); +constexpr inline CVector2f skZero2f(0.f); [[nodiscard]] inline CVector2f operator+(float lhs, const CVector2f& rhs) { return zeus::simd(lhs) + rhs.mSimd; } diff --git a/include/zeus/CVector3d.hpp b/include/zeus/CVector3d.hpp index 9b0918a..943caf0 100644 --- a/include/zeus/CVector3d.hpp +++ b/include/zeus/CVector3d.hpp @@ -79,7 +79,7 @@ public: }; inline CVector3f::CVector3f(const CVector3d& vec) : mSimd(vec.mSimd) {} -constexpr CVector3d skZero3d(0.0); +constexpr inline CVector3d skZero3d(0.0); [[nodiscard]] inline CVector3d operator+(double lhs, const CVector3d& rhs) { return zeus::simd(lhs) + rhs.mSimd; diff --git a/include/zeus/CVector3f.hpp b/include/zeus/CVector3f.hpp index bed85d3..c755065 100644 --- a/include/zeus/CVector3f.hpp +++ b/include/zeus/CVector3f.hpp @@ -209,17 +209,17 @@ public: [[nodiscard]] static inline CVector3f degToRad(const CVector3f& deg); }; -constexpr CVector3f skOne3f(1.f); -constexpr CVector3f skNegOne3f(-1.f); -constexpr CVector3f skZero3f(0.f); -constexpr CVector3f skForward(0.f, 1.f, 0.f); -constexpr CVector3f skBack(0.f, -1.f, 0.f); -constexpr CVector3f skLeft(-1.f, 0.f, 0.f); -constexpr CVector3f skRight(1.f, 0.f, 0.f); -constexpr CVector3f skUp(0.f, 0.f, 1.f); -constexpr CVector3f skDown(0.f, 0.f, -1.f); -constexpr CVector3f skRadToDegVec(180.f / M_PIF); -constexpr CVector3f skDegToRadVec(M_PIF / 180.f); +constexpr inline CVector3f skOne3f(1.f); +constexpr inline CVector3f skNegOne3f(-1.f); +constexpr inline CVector3f skZero3f(0.f); +constexpr inline CVector3f skForward(0.f, 1.f, 0.f); +constexpr inline CVector3f skBack(0.f, -1.f, 0.f); +constexpr inline CVector3f skLeft(-1.f, 0.f, 0.f); +constexpr inline CVector3f skRight(1.f, 0.f, 0.f); +constexpr inline CVector3f skUp(0.f, 0.f, 1.f); +constexpr inline CVector3f skDown(0.f, 0.f, -1.f); +constexpr inline CVector3f skRadToDegVec(180.f / M_PIF); +constexpr inline CVector3f skDegToRadVec(M_PIF / 180.f); [[nodiscard]] inline CVector3f operator+(float lhs, const CVector3f& rhs) { return zeus::simd(lhs) + rhs.mSimd; }