From 45e13b03f372230dbf780f3fa87dd88f388af605 Mon Sep 17 00:00:00 2001 From: arades79 Date: Sat, 11 Feb 2023 13:28:03 -0500 Subject: add static lifetime to constexpr values to force compile time evaluation where possible Signed-off-by: arades79 --- src/common/fixed_point.h | 12 ++++++------ src/common/hex_util.h | 2 +- src/common/tiny_mt.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/common') diff --git a/src/common/fixed_point.h b/src/common/fixed_point.h index f899b0d54..29b80c328 100644 --- a/src/common/fixed_point.h +++ b/src/common/fixed_point.h @@ -107,7 +107,7 @@ constexpr FixedPoint divide( using next_type = typename FixedPoint::next_type; using base_type = typename FixedPoint::base_type; - constexpr size_t fractional_bits = FixedPoint::fractional_bits; + constexpr static size_t fractional_bits = FixedPoint::fractional_bits; next_type t(numerator.to_raw()); t <<= fractional_bits; @@ -127,7 +127,7 @@ constexpr FixedPoint divide( using unsigned_type = typename FixedPoint::unsigned_type; - constexpr int bits = FixedPoint::total_bits; + constexpr static int bits = FixedPoint::total_bits; if (denominator == 0) { throw divide_by_zero(); @@ -198,7 +198,7 @@ constexpr FixedPoint multiply( using next_type = typename FixedPoint::next_type; using base_type = typename FixedPoint::base_type; - constexpr size_t fractional_bits = FixedPoint::fractional_bits; + constexpr static size_t fractional_bits = FixedPoint::fractional_bits; next_type t(static_cast(lhs.to_raw()) * static_cast(rhs.to_raw())); t >>= fractional_bits; @@ -216,9 +216,9 @@ constexpr FixedPoint multiply( using base_type = typename FixedPoint::base_type; - constexpr size_t fractional_bits = FixedPoint::fractional_bits; - constexpr base_type integer_mask = FixedPoint::integer_mask; - constexpr base_type fractional_mask = FixedPoint::fractional_mask; + constexpr static size_t fractional_bits = FixedPoint::fractional_bits; + constexpr static base_type integer_mask = FixedPoint::integer_mask; + constexpr static base_type fractional_mask = FixedPoint::fractional_mask; // more costly but doesn't need a larger type const base_type a_hi = (lhs.to_raw() & integer_mask) >> fractional_bits; diff --git a/src/common/hex_util.h b/src/common/hex_util.h index a00904939..6b024588b 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h @@ -47,7 +47,7 @@ template static_assert(std::is_same_v, "Underlying type within the contiguous container must be u8."); - constexpr std::size_t pad_width = 2; + constexpr static std::size_t pad_width = 2; std::string out; out.reserve(std::size(data) * pad_width); diff --git a/src/common/tiny_mt.h b/src/common/tiny_mt.h index 5d5ebf158..4689fd55b 100644 --- a/src/common/tiny_mt.h +++ b/src/common/tiny_mt.h @@ -223,7 +223,7 @@ public: float GenerateRandomF32() { // Floats have 24 bits of mantissa. - constexpr u32 MantissaBits = 24; + constexpr static u32 MantissaBits = 24; return static_cast(GenerateRandomU24()) * (1.0f / (1U << MantissaBits)); } @@ -234,9 +234,9 @@ public: // Nintendo does not. They use (32 - 5) = 27 bits from the first rnd32() // call, and (32 - 6) bits from the second. We'll do what they do, but // There's not a clear reason why. - constexpr u32 MantissaBits = 53; - constexpr u32 Shift1st = (64 - MantissaBits) / 2; - constexpr u32 Shift2nd = (64 - MantissaBits) - Shift1st; + constexpr static u32 MantissaBits = 53; + constexpr static u32 Shift1st = (64 - MantissaBits) / 2; + constexpr static u32 Shift2nd = (64 - MantissaBits) - Shift1st; const u32 first = (this->GenerateRandomU32() >> Shift1st); const u32 second = (this->GenerateRandomU32() >> Shift2nd); -- cgit v1.2.3