Skip to contentSkip to conversation

SPARC target : Fix carry flag update in addxcc and subxcc ops

PATCH New Even Rouault 1 participant 1 message Apr 7, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SPARC target : Fix carry flag update in addxcc and subxcc ops

I send a patch that should fix a bug in the update of carry flag for addxcc and subxcc instructions when the carry flag is set before the evaluation of the instruction.
(the fix is identical to what is done in the similar instruction op_adcl_T0_T1_cc for arm target)

? patch-qemu-sparc-xcc_ops.txt
Index: op.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op.c,v
retrieving revision 1.18

op.c +8 -8
diff -u -p -r1.18 op.c
@@ -415,9 +415,9 @@ void OPPROTO op_addx_T1_T0(void)
 void OPPROTO op_addx_T1_T0_cc(void)
 {
     target_ulong src1;
-
+    target_ulong has_carry = FLAG_SET(PSR_CARRY);
     src1 = T0;
-    T0 += T1 + FLAG_SET(PSR_CARRY);
+    T0 += T1 + has_carry;
     env->psr = 0;
 #ifdef TARGET_SPARC64
     if (!(T0 & 0xffffffff))
@@ -435,7 +435,7 @@ void OPPROTO op_addx_T1_T0_cc(void)
 	env->xcc |= PSR_ZERO;
     if ((int64_t) T0 < 0)
 	env->xcc |= PSR_NEG;
-    if (T0 < src1)
+    if (T0 < src1 || (has_carry && T0 <= src1))
 	env->xcc |= PSR_CARRY;
     if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
 	env->xcc |= PSR_OVF;
@@ -444,7 +444,7 @@ void OPPROTO op_addx_T1_T0_cc(void)
 	env->psr |= PSR_ZERO;
     if ((int32_t) T0 < 0)
 	env->psr |= PSR_NEG;
-    if (T0 < src1)
+    if (T0 < src1 || (has_carry && T0 <= src1))
 	env->psr |= PSR_CARRY;
     if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
 	env->psr |= PSR_OVF;
@@ -505,9 +505,9 @@ void OPPROTO op_subx_T1_T0(void)
 void OPPROTO op_subx_T1_T0_cc(void)
 {
     target_ulong src1;
-
+    target_ulong has_carry = FLAG_SET(PSR_CARRY);
     src1 = T0;
-    T0 -= T1 + FLAG_SET(PSR_CARRY);
+    T0 -= T1 + has_carry;
     env->psr = 0;
 #ifdef TARGET_SPARC64
     if (!(T0 & 0xffffffff))
@@ -525,7 +525,7 @@ void OPPROTO op_subx_T1_T0_cc(void)
 	env->xcc |= PSR_ZERO;
     if ((int64_t) T0 < 0)
 	env->xcc |= PSR_NEG;
-    if (src1 < T1)
+    if (src1 < T1 || (has_carry && src1 <= T1))
 	env->xcc |= PSR_CARRY;
     if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
 	env->xcc |= PSR_OVF;
@@ -534,7 +534,7 @@ void OPPROTO op_subx_T1_T0_cc(void)
 	env->psr |= PSR_ZERO;
     if ((int32_t) T0 < 0)
 	env->psr |= PSR_NEG;
-    if (src1 < T1)
+    if (src1 < T1 || (has_carry && src1 <= T1))
 	env->psr |= PSR_CARRY;
     if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
 	env->psr |= PSR_OVF;