From 3f4852a03d8cf174a90ca2c52a2d0e684ac7f7b0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 12 Sep 2015 00:22:48 -0400 Subject: [PATCH] MathUtil: Convert IsPow2 into a constexpr function --- Source/Core/Common/MathUtil.h | 7 +++++-- Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index dbe7a3e6df..b8642bf80d 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -18,6 +18,11 @@ constexpr T Clamp(const T val, const T& min, const T& max) return std::max(min, std::min(max, val)); } +constexpr bool IsPow2(u32 imm) +{ + return (imm & (imm - 1)) == 0; +} + // The most significant bit of the fraction is an is-quiet bit on all architectures we care about. static const u64 DOUBLE_SIGN = 0x8000000000000000ULL, @@ -157,8 +162,6 @@ float MathFloatVectorSum(const std::vector&); #define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) #define ROUND_DOWN(x, a) ((x) & ~((a) - 1)) -inline bool IsPow2(u32 imm) {return (imm & (imm - 1)) == 0;} - // Rounds down. 0 -> undefined inline int IntLog2(u64 val) { diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp index b08f459b44..703b910100 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp @@ -924,7 +924,7 @@ void Jit64::MultiplyImmediate(u32 imm, int a, int d, bool overflow) if (!overflow) { // power of 2; just a shift - if (IsPow2(imm)) + if (MathUtil::IsPow2(imm)) { u32 shift = IntLog2(imm); // use LEA if it saves an op