#pragma once namespace Common { template constexpr bool IsAligned(T value, unsigned int alignment) { return (value % static_cast(alignment)) == 0; } template constexpr T AlignUp(T value, unsigned int alignment) { return (value + static_cast(alignment - 1)) / static_cast(alignment) * static_cast(alignment); } template constexpr T AlignDown(T value, unsigned int alignment) { return value / static_cast(alignment) * static_cast(alignment); } template constexpr bool IsAlignedPow2(T value, unsigned int alignment) { return (value & static_cast(alignment - 1)) == 0; } template constexpr T AlignUpPow2(T value, unsigned int alignment) { return (value + static_cast(alignment - 1)) & static_cast(~static_cast(alignment - 1)); } template constexpr T AlignDownPow2(T value, unsigned int alignment) { return value & static_cast(~static_cast(alignment - 1)); } template constexpr bool IsPow2(T value) { return (value & (value - 1)) == 0; } template constexpr T PreviousPow2(T value) { if (value == static_cast(0)) return 0; value |= (value >> 1); value |= (value >> 2); value |= (value >> 4); value |= (value >> 8); value |= (value >> 16); return value - (value >> 1); } } // namespace Common