From 79f40fb8d7b5a0d1efb47cd2d4a0661be9772d0e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 23 Mar 2018 09:50:09 -0400 Subject: [PATCH] MathUtil: Generify IsPow2 This will allow it to also be used in the AArch64 emitter. --- Source/Core/Common/MathUtil.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index becaf09792..58aad3522d 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -49,9 +49,10 @@ 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) +template +constexpr bool IsPow2(T imm) { - return (imm & (imm - 1)) == 0; + return imm > 0 && (imm & (imm - 1)) == 0; } // The most significant bit of the fraction is an is-quiet bit on all architectures we care about.