Skip to contentSkip to conversation

target-arm: Set carry flag correctly for Thumb2 ORNS

PATCH Superseded Peter Maydell 2 participants 2 messages Mar 2, 2011 – Mar 6, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm: Set carry flag correctly for Thumb2 ORNS

The code for Thumb2 ORNS (or negated and set flags) was trashing a TCG input register which was needed later for use in calculating flags, with the effect that the carry flag was always set with the wrong sense. Fix this by using a TCG temporary instead.

---
 target-arm/translate.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
target-arm/translate.c +9 -2
index dbd958b..8f4e16b 100644
@@ -7326,10 +7326,17 @@ gen_thumb2_data_op(DisasContext *s, int op, int conds, uint32_t shifter_out, TCG
         logic_cc = conds;
         break;
     case 3: /* orn */
-        tcg_gen_not_i32(t1, t1);
-        tcg_gen_or_i32(t0, t0, t1);
+    {
+        /* We can't just invert t1 in place because we might need it
+         * to calculate the carry flag later.
+         */
+        TCGv tmp = tcg_temp_new_i32();
+        tcg_gen_not_i32(tmp, t1);
+        tcg_gen_or_i32(t0, t0, tmp);
+        tcg_temp_free_i32(tmp);
         logic_cc = conds;
         break;
+    }
     case 4: /* eor */
         tcg_gen_xor_i32(t0, t0, t1);
         logic_cc = conds;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 18 lines · Peter Maydell

The code for Thumb2 ORNS (or negated and set flags) was trashing a TCG input register which was needed later for use in calculating flags, with the effect that the carry flag was always set with the wrong sense. Fix this by using a TCG temporary instead.

---
 target-arm/translate.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
target-arm/translate.c +0 -0
index dbd958b..8f4e16b 100644
@@ -7326,10 +7326,17 @@ gen_thumb2_data_op(DisasContext *s, int op, int conds, uint32_t shifter_out, TCG
         logic_cc = conds;
         break;
     case 3: /* orn */

target-arm/translate.c gen_thumb2_data_op(DisasContext *s, int op, int conds, uint32_t shifter_out, TCG · line 7336

Quoted 10 lines
target-arm/translate.c +8 -2
-        tcg_gen_not_i32(t1, t1);
-        tcg_gen_or_i32(t0, t0, t1);
+    {
+        /* We can't just invert t1 in place because we might need it
+         * to calculate the carry flag later.
+         */
+        TCGv tmp = tcg_temp_new_i32();
+        tcg_gen_not_i32(tmp, t1);
+        tcg_gen_or_i32(t0, t0, tmp);
+        tcg_temp_free_i32(tmp);

You may want to use tcg_gen_orc_i32() instead, which as a bonus might be implemented directly on some hosts (currently ia64, powerpc and sparc).

Quoted 11 lines
target-arm/translate.c +1 -0
         logic_cc = conds;
         break;
+    }
     case 4: /* eor */
         tcg_gen_xor_i32(t0, t0, t1);
         logic_cc = conds;
Signature · 1 line
1.7.1
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net