summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-11-25 23:03:50 -0300
committerGravatar ReinUsesLisp2020-11-25 23:37:56 -0300
commit630823e3630f2bb77a3a5e4aa0f8f87859d05ee1 (patch)
tree27934d718688e07bea205e85bdc3968a5f4bf461
parentMerge pull request #4976 from comex/poll-events (diff)
downloadyuzu-630823e3630f2bb77a3a5e4aa0f8f87859d05ee1.tar.gz
yuzu-630823e3630f2bb77a3a5e4aa0f8f87859d05ee1.tar.xz
yuzu-630823e3630f2bb77a3a5e4aa0f8f87859d05ee1.zip
common: Add Common::DivCeil and Common::DivCeilLog2
Add an equivalent to 'Common::AlignUp(n, d) / d' and a log2 alternative.
-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