summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MathUtil.h
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-05-10 19:06:19 -0400
committerLioncash <mathew1800@gmail.com>2018-05-10 19:42:20 -0400
commitba01f6dba3cf1858ed64bc7f1abee744ffd313ec (patch)
tree277ae9faa7dabc173cbe2d2c9b77db850d5c682e /Source/Core/Common/MathUtil.h
parent3cca05185029ae4572529bf986675c772cc0ac5a (diff)
CommonFuncs: Convert ROUND_UP_POW2 macro to a function
Also move it to MathUtils where it belongs with the rest of the power-of-two functions. This gets rid of pollution of the current scope of any translation unit with b<value> macros that aren't intended to be used directly.
Diffstat (limited to 'Source/Core/Common/MathUtil.h')
-rw-r--r--Source/Core/Common/MathUtil.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h
index 06ab1afd62..bc0162b9ee 100644
--- a/Source/Core/Common/MathUtil.h
+++ b/Source/Core/Common/MathUtil.h
@@ -29,6 +29,19 @@ constexpr bool IsPow2(T imm)
return imm > 0 && (imm & (imm - 1)) == 0;
}
+constexpr u32 NextPowerOf2(u32 value)
+{
+ --value;
+ value |= value >> 1;
+ value |= value >> 2;
+ value |= value >> 4;
+ value |= value >> 8;
+ value |= value >> 16;
+ ++value;
+
+ return value;
+}
+
template <class T>
struct Rectangle
{