diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2021-09-24 22:44:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-24 22:44:25 +0200 |
commit | 9a53173e4de2194a128a33764d3f50f02f358efa (patch) | |
tree | 6f6cf76701e48f6c83e105ab06b2e6f82627dbf9 /src/common/alignment.h | |
parent | Merge pull request #7069 from lioncash/uuid (diff) | |
parent | CMakeLists: Update to clang format version 12 (diff) | |
download | yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.tar yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.tar.gz yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.tar.bz2 yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.tar.lz yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.tar.xz yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.tar.zst yuzu-9a53173e4de2194a128a33764d3f50f02f358efa.zip |
Diffstat (limited to 'src/common/alignment.h')
-rw-r--r-- | src/common/alignment.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h index 32d796ffa..1b56569d1 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -9,41 +9,48 @@ namespace Common { template <typename T> -requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUp(T value, size_t size) { +requires std::is_unsigned_v<T> +[[nodiscard]] constexpr T AlignUp(T value, size_t size) { auto mod{static_cast<T>(value % size)}; value -= mod; return static_cast<T>(mod == T{0} ? value : value + size); } template <typename T> -requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { +requires std::is_unsigned_v<T> +[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); } template <typename T> -requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignDown(T value, size_t size) { +requires std::is_unsigned_v<T> +[[nodiscard]] constexpr T AlignDown(T value, size_t size) { return static_cast<T>(value - value % size); } template <typename T> -requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool Is4KBAligned(T value) { +requires std::is_unsigned_v<T> +[[nodiscard]] constexpr bool Is4KBAligned(T value) { return (value & 0xFFF) == 0; } template <typename T> -requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool IsWordAligned(T value) { +requires std::is_unsigned_v<T> +[[nodiscard]] constexpr bool IsWordAligned(T value) { return (value & 0b11) == 0; } template <typename T> -requires std::is_integral_v<T>[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { +requires std::is_integral_v<T> +[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { using U = typename std::make_unsigned_t<T>; const U mask = static_cast<U>(alignment - 1); return (value & mask) == 0; } template <typename T, typename U> -requires std::is_integral_v<T>[[nodiscard]] constexpr T DivideUp(T x, U y) { +requires std::is_integral_v<T> +[[nodiscard]] constexpr T DivideUp(T x, U y) { return (x + (y - 1)) / y; } |