summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorLiam <byteslice@airmail.cc>2023-03-08 01:46:48 +0100
committerLiam <byteslice@airmail.cc>2023-03-08 01:46:48 +0100
commitd45ac00d48352d86a483e7642bfccadf1eb4f4ce (patch)
tree9c8327fa45f820e586835f8547fb4b976bbca500 /src/common
parentMerge pull request #9889 from Morph1984/time-is-ticking (diff)
downloadyuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.tar
yuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.tar.gz
yuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.tar.bz2
yuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.tar.lz
yuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.tar.xz
yuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.tar.zst
yuzu-d45ac00d48352d86a483e7642bfccadf1eb4f4ce.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/overflow.h22
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 58ff5f2f3..61ab68864 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -91,6 +91,7 @@ add_library(common STATIC
multi_level_page_table.h
nvidia_flags.cpp
nvidia_flags.h
+ overflow.h
page_table.cpp
page_table.h
param_package.cpp
diff --git a/src/common/overflow.h b/src/common/overflow.h
new file mode 100644
index 000000000..44d8e7e73
--- /dev/null
+++ b/src/common/overflow.h
@@ -0,0 +1,22 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <type_traits>
+#include "bit_cast.h"
+
+namespace Common {
+
+template <typename T>
+ requires(std::is_integral_v<T> && std::is_signed_v<T>)
+inline T WrappingAdd(T lhs, T rhs) {
+ using U = std::make_unsigned_t<T>;
+
+ U lhs_u = BitCast<U>(lhs);
+ U rhs_u = BitCast<U>(rhs);
+
+ return BitCast<T>(lhs_u + rhs_u);
+}
+
+} // namespace Common