summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2023-06-29 20:30:13 -0400
committerGitHub <noreply@github.com>2023-06-29 20:30:13 -0400
commitff324ef6602245ff11c815ba312ef443ee789b27 (patch)
tree629017363207dcfcd649d3429aa7f1fc06220ee8 /Source/Core
parent7a2352f90c44872fd58818f1cd7d7b3ea097abc2 (diff)
parentd844317a6dbb3034075aa2923ee9430625b97dc0 (diff)
Merge pull request #12010 from TellowKrinkle/AlignUpOpt
Common: Better AlignUp implementation
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/Align.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/Source/Core/Common/Align.h b/Source/Core/Common/Align.h
index 8e51b8aacc..994e505617 100644
--- a/Source/Core/Common/Align.h
+++ b/Source/Core/Common/Align.h
@@ -7,18 +7,19 @@
namespace Common
{
+
template <typename T>
-constexpr T AlignUp(T value, size_t size)
+constexpr T AlignDown(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
- return static_cast<T>(value + (size - value % size) % size);
+ return static_cast<T>(value - value % size);
}
template <typename T>
-constexpr T AlignDown(T value, size_t size)
+constexpr T AlignUp(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
- return static_cast<T>(value - value % size);
+ return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
}
} // namespace Common