summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar arades792023-02-11 13:28:03 -0500
committerGravatar arades792023-02-14 12:33:11 -0500
commit45e13b03f372230dbf780f3fa87dd88f388af605 (patch)
tree555593e7e5016b6ba2a777d7417ada244abce458 /src/common
parentMerge pull request #9795 from Kelebek1/biquad_fix (diff)
downloadyuzu-45e13b03f372230dbf780f3fa87dd88f388af605.tar.gz
yuzu-45e13b03f372230dbf780f3fa87dd88f388af605.tar.xz
yuzu-45e13b03f372230dbf780f3fa87dd88f388af605.zip
add static lifetime to constexpr values to force compile time evaluation where possible
Signed-off-by: arades79 <scravers@protonmail.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fixed_point.h12
-rw-r--r--src/common/hex_util.h2
-rw-r--r--src/common/tiny_mt.h8
3 files changed, 11 insertions, 11 deletions
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<I, F> divide(
107 107
108 using next_type = typename FixedPoint<I, F>::next_type; 108 using next_type = typename FixedPoint<I, F>::next_type;
109 using base_type = typename FixedPoint<I, F>::base_type; 109 using base_type = typename FixedPoint<I, F>::base_type;
110 constexpr size_t fractional_bits = FixedPoint<I, F>::fractional_bits; 110 constexpr static size_t fractional_bits = FixedPoint<I, F>::fractional_bits;
111 111
112 next_type t(numerator.to_raw()); 112 next_type t(numerator.to_raw());
113 t <<= fractional_bits; 113 t <<= fractional_bits;
@@ -127,7 +127,7 @@ constexpr FixedPoint<I, F> divide(
127 127
128 using unsigned_type = typename FixedPoint<I, F>::unsigned_type; 128 using unsigned_type = typename FixedPoint<I, F>::unsigned_type;
129 129
130 constexpr int bits = FixedPoint<I, F>::total_bits; 130 constexpr static int bits = FixedPoint<I, F>::total_bits;
131 131
132 if (denominator == 0) { 132 if (denominator == 0) {
133 throw divide_by_zero(); 133 throw divide_by_zero();
@@ -198,7 +198,7 @@ constexpr FixedPoint<I, F> multiply(
198 using next_type = typename FixedPoint<I, F>::next_type; 198 using next_type = typename FixedPoint<I, F>::next_type;
199 using base_type = typename FixedPoint<I, F>::base_type; 199 using base_type = typename FixedPoint<I, F>::base_type;
200 200
201 constexpr size_t fractional_bits = FixedPoint<I, F>::fractional_bits; 201 constexpr static size_t fractional_bits = FixedPoint<I, F>::fractional_bits;
202 202
203 next_type t(static_cast<next_type>(lhs.to_raw()) * static_cast<next_type>(rhs.to_raw())); 203 next_type t(static_cast<next_type>(lhs.to_raw()) * static_cast<next_type>(rhs.to_raw()));
204 t >>= fractional_bits; 204 t >>= fractional_bits;
@@ -216,9 +216,9 @@ constexpr FixedPoint<I, F> multiply(
216 216
217 using base_type = typename FixedPoint<I, F>::base_type; 217 using base_type = typename FixedPoint<I, F>::base_type;
218 218
219 constexpr size_t fractional_bits = FixedPoint<I, F>::fractional_bits; 219 constexpr static size_t fractional_bits = FixedPoint<I, F>::fractional_bits;
220 constexpr base_type integer_mask = FixedPoint<I, F>::integer_mask; 220 constexpr static base_type integer_mask = FixedPoint<I, F>::integer_mask;
221 constexpr base_type fractional_mask = FixedPoint<I, F>::fractional_mask; 221 constexpr static base_type fractional_mask = FixedPoint<I, F>::fractional_mask;
222 222
223 // more costly but doesn't need a larger type 223 // more costly but doesn't need a larger type
224 const base_type a_hi = (lhs.to_raw() & integer_mask) >> fractional_bits; 224 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 <typename ContiguousContainer>
47 static_assert(std::is_same_v<typename ContiguousContainer::value_type, u8>, 47 static_assert(std::is_same_v<typename ContiguousContainer::value_type, u8>,
48 "Underlying type within the contiguous container must be u8."); 48 "Underlying type within the contiguous container must be u8.");
49 49
50 constexpr std::size_t pad_width = 2; 50 constexpr static std::size_t pad_width = 2;
51 51
52 std::string out; 52 std::string out;
53 out.reserve(std::size(data) * pad_width); 53 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:
223 223
224 float GenerateRandomF32() { 224 float GenerateRandomF32() {
225 // Floats have 24 bits of mantissa. 225 // Floats have 24 bits of mantissa.
226 constexpr u32 MantissaBits = 24; 226 constexpr static u32 MantissaBits = 24;
227 return static_cast<float>(GenerateRandomU24()) * (1.0f / (1U << MantissaBits)); 227 return static_cast<float>(GenerateRandomU24()) * (1.0f / (1U << MantissaBits));
228 } 228 }
229 229
@@ -234,9 +234,9 @@ public:
234 // Nintendo does not. They use (32 - 5) = 27 bits from the first rnd32() 234 // Nintendo does not. They use (32 - 5) = 27 bits from the first rnd32()
235 // call, and (32 - 6) bits from the second. We'll do what they do, but 235 // call, and (32 - 6) bits from the second. We'll do what they do, but
236 // There's not a clear reason why. 236 // There's not a clear reason why.
237 constexpr u32 MantissaBits = 53; 237 constexpr static u32 MantissaBits = 53;
238 constexpr u32 Shift1st = (64 - MantissaBits) / 2; 238 constexpr static u32 Shift1st = (64 - MantissaBits) / 2;
239 constexpr u32 Shift2nd = (64 - MantissaBits) - Shift1st; 239 constexpr static u32 Shift2nd = (64 - MantissaBits) - Shift1st;
240 240
241 const u32 first = (this->GenerateRandomU32() >> Shift1st); 241 const u32 first = (this->GenerateRandomU32() >> Shift1st);
242 const u32 second = (this->GenerateRandomU32() >> Shift2nd); 242 const u32 second = (this->GenerateRandomU32() >> Shift2nd);