From fe494a0ccdddc8e7a7f54ca93de090100fc3fb8a Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 15 Jan 2021 04:02:37 -0300 Subject: common/alignment: Rename AlignBits to AlignUpLog2 AlignUpLog2 describes what the function does better than AlignBits. --- src/common/alignment.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/common') diff --git a/src/common/alignment.h b/src/common/alignment.h index 5040043de..2127dc186 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -17,15 +17,14 @@ template } 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); +requires std::is_unsigned_v[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { + return static_cast((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); } template -[[nodiscard]] constexpr T AlignBits(T value, std::size_t align) { +[[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 + ((1ULL << align) - 1)) >> align << align); + return static_cast(value - value % size); } template -- cgit v1.2.3