// SPDX-FileCopyrightText: 2014 Jannik Vogel // SPDX-License-Identifier: CC0-1.0 #pragma once #include #include namespace Common { template [[nodiscard]] constexpr T AlignUp(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); auto mod{static_cast(value % size)}; value -= mod; return static_cast(mod == T{0} ? value : value + size); } template [[nodiscard]] constexpr T AlignDown(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); return static_cast(value - value % size); } template requires std::is_integral_v [[nodiscard]] constexpr bool Is16KBAligned(T value) { return (value & 0x3FFF) == 0; } } // namespace Common