summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2020-11-29 01:41:06 -0800
committerGravatar GitHub2020-11-29 01:41:06 -0800
commit63b3b25715cd1c1a8b196f3cbdf73fc7873f444c (patch)
tree9e8f9e6d7884c8291d6236025c4e2234bb9b8d95 /src
parentMerge pull request #4998 from Morph1984/bioshock-patch (diff)
parentcommon: Add Common::DivCeil and Common::DivCeilLog2 (diff)
downloadyuzu-63b3b25715cd1c1a8b196f3cbdf73fc7873f444c.tar.gz
yuzu-63b3b25715cd1c1a8b196f3cbdf73fc7873f444c.tar.xz
yuzu-63b3b25715cd1c1a8b196f3cbdf73fc7873f444c.zip
Merge pull request #5005 from ReinUsesLisp/div-ceil
common: Add Common::DivCeil and Common::DivCeilLog2
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/div_ceil.h26
2 files changed, 27 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index d20e6c3b5..56c7e21f5 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -112,6 +112,7 @@ add_library(common STATIC
112 common_paths.h 112 common_paths.h
113 common_types.h 113 common_types.h
114 concepts.h 114 concepts.h
115 div_ceil.h
115 dynamic_library.cpp 116 dynamic_library.cpp
116 dynamic_library.h 117 dynamic_library.h
117 fiber.cpp 118 fiber.cpp
diff --git a/src/common/div_ceil.h b/src/common/div_ceil.h
new file mode 100644
index 000000000..6b2c48f91
--- /dev/null
+++ b/src/common/div_ceil.h
@@ -0,0 +1,26 @@
1// Copyright 2020 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <cstddef>
8#include <type_traits>
9
10namespace Common {
11
12/// Ceiled integer division.
13template <typename N, typename D>
14requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr auto DivCeil(
15 N number, D divisor) {
16 return (static_cast<D>(number) + divisor - 1) / divisor;
17}
18
19/// Ceiled integer division with logarithmic divisor in base 2
20template <typename N, typename D>
21requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr auto DivCeilLog2(
22 N value, D alignment_log2) {
23 return (static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2;
24}
25
26} // namespace Common