diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/system/align.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/align.h')
-rw-r--r-- | util/system/align.h | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/util/system/align.h b/util/system/align.h index 6674b93694..ea0bbc5b46 100644 --- a/util/system/align.h +++ b/util/system/align.h @@ -1,16 +1,16 @@ #pragma once - -#include "yassert.h" -#include "defaults.h" + +#include "yassert.h" +#include "defaults.h" #include <util/generic/bitops.h> - -template <class T> + +template <class T> static inline T AlignDown(T len, T align) noexcept { Y_ASSERT(IsPowerOf2(align)); // align should be power of 2 - return len & ~(align - 1); -} - -template <class T> + return len & ~(align - 1); +} + +template <class T> static inline T AlignUp(T len, T align) noexcept { const T alignedResult = AlignDown(len + (align - 1), align); Y_ASSERT(alignedResult >= len); // check for overflow @@ -19,31 +19,31 @@ static inline T AlignUp(T len, T align) noexcept { template <class T> static inline T AlignUpSpace(T len, T align) noexcept { - Y_ASSERT(IsPowerOf2(align)); // align should be power of 2 - return ((T)0 - len) & (align - 1); // AlignUp(len, align) - len; + Y_ASSERT(IsPowerOf2(align)); // align should be power of 2 + return ((T)0 - len) & (align - 1); // AlignUp(len, align) - len; } template <class T> static inline T* AlignUp(T* ptr, size_t align) noexcept { return (T*)AlignUp((uintptr_t)ptr, align); -} - -template <class T> +} + +template <class T> static inline T* AlignDown(T* ptr, size_t align) noexcept { return (T*)AlignDown((uintptr_t)ptr, align); -} - -template <class T> +} + +template <class T> static inline T AlignUp(T t) noexcept { - return AlignUp(t, (size_t)PLATFORM_DATA_ALIGN); -} - -template <class T> + return AlignUp(t, (size_t)PLATFORM_DATA_ALIGN); +} + +template <class T> static inline T AlignDown(T t) noexcept { - return AlignDown(t, (size_t)PLATFORM_DATA_ALIGN); -} - -template <class T> + return AlignDown(t, (size_t)PLATFORM_DATA_ALIGN); +} + +template <class T> static inline T Align(T t) noexcept { - return AlignUp(t); -} + return AlignUp(t); +} |