dolphin/Source/Core/Common/Align.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
533 B
C
Raw Normal View History

// SPDX-License-Identifier: CC0-1.0
#pragma once
#include <cstddef>
#include <type_traits>
namespace Common
{
2023-06-29 00:32:51 -06:00
template <typename T>
2023-06-29 00:32:51 -06:00
constexpr T AlignDown(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
2023-06-29 00:32:51 -06:00
return static_cast<T>(value - value % size);
}
template <typename T>
2023-06-29 00:32:51 -06:00
constexpr T AlignUp(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
2023-06-29 00:32:51 -06:00
return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
}
} // namespace Common