summaryrefslogtreecommitdiff
path: root/Source/Core
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
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')
-rw-r--r--Source/Core/Common/CommonFuncs.h7
-rw-r--r--Source/Core/Common/MathUtil.h13
-rw-r--r--Source/Core/Core/HW/Memmap.h4
-rw-r--r--Source/Core/VideoBackends/OGL/StreamBuffer.cpp6
-rw-r--r--Source/Core/VideoCommon/VertexManagerBase.h6
5 files changed, 21 insertions, 15 deletions
diff --git a/Source/Core/Common/CommonFuncs.h b/Source/Core/Common/CommonFuncs.h
index 11828a72c1..abd7b27c34 100644
--- a/Source/Core/Common/CommonFuncs.h
+++ b/Source/Core/Common/CommonFuncs.h
@@ -15,13 +15,6 @@ constexpr size_t ArraySize(T (&arr)[N])
return N;
}
-#define b2(x) ((x) | ((x) >> 1))
-#define b4(x) (b2(x) | (b2(x) >> 2))
-#define b8(x) (b4(x) | (b4(x) >> 4))
-#define b16(x) (b8(x) | (b8(x) >> 8))
-#define b32(x) (b16(x) | (b16(x) >> 16))
-#define ROUND_UP_POW2(x) (b32(x - 1) + 1)
-
#ifndef _WIN32
// go to debugger mode
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
{
diff --git a/Source/Core/Core/HW/Memmap.h b/Source/Core/Core/HW/Memmap.h
index 186dfcc610..329912f01f 100644
--- a/Source/Core/Core/HW/Memmap.h
+++ b/Source/Core/Core/HW/Memmap.h
@@ -7,8 +7,8 @@
#include <memory>
#include <string>
-#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
+#include "Common/MathUtil.h"
#include "Common/Swap.h"
#include "Core/PowerPC/PowerPC.h"
@@ -44,7 +44,7 @@ enum
// Note: Writing to lowmem is done by IPL. If using retail IPL, it will
// always be set to 24MB.
REALRAM_SIZE = 0x01800000,
- RAM_SIZE = ROUND_UP_POW2(REALRAM_SIZE),
+ RAM_SIZE = MathUtil::NextPowerOf2(REALRAM_SIZE),
RAM_MASK = RAM_SIZE - 1,
FAKEVMEM_SIZE = 0x02000000,
FAKEVMEM_MASK = FAKEVMEM_SIZE - 1,
diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp
index 1307350086..e32afd9a47 100644
--- a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp
+++ b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp
@@ -5,8 +5,8 @@
#include "VideoBackends/OGL/StreamBuffer.h"
#include "Common/Align.h"
-#include "Common/CommonFuncs.h"
#include "Common/GL/GLUtil.h"
+#include "Common/MathUtil.h"
#include "Common/MemoryUtil.h"
#include "VideoBackends/OGL/Render.h"
@@ -25,8 +25,8 @@ static u32 GenBuffer()
}
StreamBuffer::StreamBuffer(u32 type, u32 size)
- : m_buffer(GenBuffer()), m_buffertype(type), m_size(ROUND_UP_POW2(size)),
- m_bit_per_slot(IntLog2(ROUND_UP_POW2(size) / SYNC_POINTS))
+ : m_buffer(GenBuffer()), m_buffertype(type), m_size(MathUtil::NextPowerOf2(size)),
+ m_bit_per_slot(IntLog2(MathUtil::NextPowerOf2(size) / SYNC_POINTS))
{
m_iterator = 0;
m_used_iterator = 0;
diff --git a/Source/Core/VideoCommon/VertexManagerBase.h b/Source/Core/VideoCommon/VertexManagerBase.h
index 4d07b08411..88d9d9fbe0 100644
--- a/Source/Core/VideoCommon/VertexManagerBase.h
+++ b/Source/Core/VideoCommon/VertexManagerBase.h
@@ -7,8 +7,8 @@
#include <memory>
#include <vector>
-#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
+#include "Common/MathUtil.h"
#include "VideoCommon/RenderState.h"
#include "VideoCommon/ShaderCache.h"
@@ -37,10 +37,10 @@ private:
public:
static constexpr u32 MAXVBUFFERSIZE =
- ROUND_UP_POW2(MAX_PRIMITIVES_PER_COMMAND * LARGEST_POSSIBLE_VERTEX);
+ MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * LARGEST_POSSIBLE_VERTEX);
// We may convert triangle-fans to triangle-lists, almost 3x as many indices.
- static constexpr u32 MAXIBUFFERSIZE = ROUND_UP_POW2(MAX_PRIMITIVES_PER_COMMAND * 3);
+ static constexpr u32 MAXIBUFFERSIZE = MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * 3);
VertexManagerBase();
// needs to be virtual for DX11's dtor