summaryrefslogtreecommitdiffstats
path: root/src/core/arm/interpreter
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2015-01-12 06:01:46 +0100
committerLioncash <mathew1800@gmail.com>2015-01-12 06:44:28 +0100
commit9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7 (patch)
treeb436a7b0dfed383f339806b09452ad5207f513dc /src/core/arm/interpreter
parentMerge pull request #468 from lioncash/adc (diff)
downloadyuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.tar
yuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.tar.gz
yuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.tar.bz2
yuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.tar.lz
yuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.tar.xz
yuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.tar.zst
yuzu-9c2c89b7e1a93b52b53c567116b0d24bc4cb6ce7.zip
Diffstat (limited to 'src/core/arm/interpreter')
-rw-r--r--src/core/arm/interpreter/armsupp.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp
index 68ac2a0ce..e2626eefb 100644
--- a/src/core/arm/interpreter/armsupp.cpp
+++ b/src/core/arm/interpreter/armsupp.cpp
@@ -418,6 +418,22 @@ ARMul_NegZero (ARMul_State * state, ARMword result)
}
}
+// Add with carry, indicates if a carry-out or signed overflow occurred.
+u32 AddWithCarry(u32 left, u32 right, u32 carry_in, bool* carry_out_occurred, bool* overflow_occurred)
+{
+ u64 unsigned_sum = (u64)left + (u64)right + (u64)carry_in;
+ s64 signed_sum = (s64)(s32)left + (s64)(s32)right + (s64)carry_in;
+ u64 result = (unsigned_sum & 0xFFFFFFFF);
+
+ if (carry_out_occurred)
+ *carry_out_occurred = (result != unsigned_sum);
+
+ if (overflow_occurred)
+ *overflow_occurred = ((s64)(s32)result != signed_sum);
+
+ return (u32)result;
+}
+
// Compute whether an addition of A and B, giving RESULT, overflowed.
bool AddOverflow(ARMword a, ARMword b, ARMword result)
{