Add a helper method AddWithCarry() to the EmulateInstructionARM class.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@125329 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
index a896256..4f9ae3e 100644
--- a/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ b/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -2595,6 +2595,27 @@
     return (ArchVersion() >= ARMv7);
 }
 
+// The main addition and subtraction instructions can produce status information
+// about both unsigned carry and signed overflow conditions.  This status
+// information can be used to synthesize multi-word additions and subtractions.
+EmulateInstructionARM::AddWithCarryResult
+EmulateInstructionARM::AddWithCarry (uint32_t x, uint32_t y, uint8_t carry_in)
+{
+    uint32_t result;
+    uint8_t carry_out;
+    uint8_t overflow;
+
+    uint64_t unsigned_sum = x + y + carry_in;
+    int64_t signed_sum = (int32_t)x + (int32_t)y + (int32_t)carry_in;
+    
+    result = UnsignedBits(unsigned_sum, 31, 0);
+    carry_out = (result == unsigned_sum ? 0 : 1);
+    overflow = ((int32_t)result == signed_sum ? 0 : 1);
+    
+    AddWithCarryResult res = { result, carry_out, overflow };
+    return res;
+}
+
 bool
 EmulateInstructionARM::EvaluateInstruction ()
 {