Common/Align: Make constexpr

This commit is contained in:
Connor McLaughlin 2020-10-11 20:34:56 +10:00
parent 36bede11ae
commit 3ecae0f409

View file

@ -2,37 +2,37 @@
namespace Common {
template<typename T>
bool IsAligned(T value, unsigned int alignment)
constexpr bool IsAligned(T value, unsigned int alignment)
{
return (value % static_cast<T>(alignment)) == 0;
}
template<typename T>
T AlignUp(T value, unsigned int alignment)
constexpr T AlignUp(T value, unsigned int alignment)
{
return (value + static_cast<T>(alignment - 1)) / static_cast<T>(alignment) * static_cast<T>(alignment);
}
template<typename T>
T AlignDown(T value, unsigned int alignment)
constexpr T AlignDown(T value, unsigned int alignment)
{
return value / static_cast<T>(alignment) * static_cast<T>(alignment);
}
template<typename T>
bool IsAlignedPow2(T value, unsigned int alignment)
constexpr bool IsAlignedPow2(T value, unsigned int alignment)
{
return (value & static_cast<T>(alignment - 1)) == 0;
}
template<typename T>
T AlignUpPow2(T value, unsigned int alignment)
constexpr T AlignUpPow2(T value, unsigned int alignment)
{
return (value + static_cast<T>(alignment - 1)) & static_cast<T>(~static_cast<T>(alignment - 1));
}
template<typename T>
T AlignDownPow2(T value, unsigned int alignment)
constexpr T AlignDownPow2(T value, unsigned int alignment)
{
return value & static_cast<T>(~static_cast<T>(alignment - 1));
}
template<typename T>
bool IsPow2(T value)
constexpr bool IsPow2(T value)
{
return (value & (value - 1)) == 0;
}