Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12010 from TellowKrinkle/AlignUpOpt
Common: Better AlignUp implementation
  • Loading branch information
JMC47 committed Jun 30, 2023
2 parents 7a2352f + d844317 commit ff324ef
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Source/Core/Common/Align.h
Expand Up @@ -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

0 comments on commit ff324ef

Please sign in to comment.