Skip to contentSkip to conversation

target-arm/translate: Fix RRX operands

PATCH In review Peter Crosthwaite 3 participants 3 messages Oct 16, 2012 – Oct 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm/translate: Fix RRX operands

Instructions that both use the RRX second operand and update CS were incorrect, as the Carry flag was updated too early. An example of such an instruction would be:

ands r12,r13,RRX

Ands, because of the "s" flag will update the carry flag. But the RRX second operand rotates through the C flag which should happen before the update. Fixed the ordering of the two, the old carry is read by "r13,RRX" before being updated.

---
 target-arm/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-arm/translate.c +1 -1
index c6840b7..daccb15 100644
@@ -516,10 +516,10 @@ static inline void gen_arm_shift_im(TCGv var, int shiftop, int shift, int flags)
             tcg_gen_rotri_i32(var, var, shift); break;
         } else {
             TCGv tmp = tcg_temp_new_i32();
+            tcg_gen_shli_i32(tmp, cpu_CF, 31);
             if (flags)
                 shifter_out_im(var, 0);
             tcg_gen_shri_i32(var, var, 1);
-            tcg_gen_shli_i32(tmp, cpu_CF, 31);
             tcg_gen_or_i32(var, var, tmp);
             tcg_temp_free_i32(tmp);
         }
Signature · 1 line
1.7.0.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Peter Crosthwaite

Instructions that both use the RRX second operand and update CS were incorrect, as the Carry flag was updated too early. An example of such an instruction would be:

ands r12,r13,RRX

Ands, because of the "s" flag will update the carry flag. But the RRX second operand rotates through the C flag which should happen before the update. Fixed the ordering of the two, the old carry is read by "r13,RRX" before being updated.

---
 target-arm/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-arm/translate.c +0 -0
index c6840b7..daccb15 100644
@@ -516,10 +516,10 @@ static inline void gen_arm_shift_im(TCGv var, int shiftop, int shift, int flags)
             tcg_gen_rotri_i32(var, var, shift); break;

target-arm/translate.c static inline void gen_arm_shift_im(TCGv var, int shiftop, int shift, int flags) · line 525

Quoted 10 lines
target-arm/translate.c +1 -1
         } else {
             TCGv tmp = tcg_temp_new_i32();
+            tcg_gen_shli_i32(tmp, cpu_CF, 31);
             if (flags)
                 shifter_out_im(var, 0);
             tcg_gen_shri_i32(var, var, 1);
-            tcg_gen_shli_i32(tmp, cpu_CF, 31);
             tcg_gen_or_i32(var, var, tmp);
             tcg_temp_free_i32(tmp);
         }

Looks like this was broken by Aurelien's commit 66c374de8; previously we loaded CF into a tmp before doing the shifter_out_im() [which updates CF], and then used the tmp after the call, rather than directly using CF.

-- PMM

#2 lore raw
Quoted 31 lines · Peter Maydell
Quoted 29 lines · Peter Crosthwaite

Instructions that both use the RRX second operand and update CS were incorrect, as the Carry flag was updated too early. An example of such an instruction would be:

ands r12,r13,RRX

Ands, because of the "s" flag will update the carry flag. But the RRX second operand rotates through the C flag which should happen before the update. Fixed the ordering of the two, the old carry is read by "r13,RRX" before being updated.

---
 target-arm/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-arm/translate.c +1 -0
index c6840b7..daccb15 100644
@@ -516,10 +516,10 @@ static inline void gen_arm_shift_im(TCGv var, int shiftop, int shift, int flags)
             tcg_gen_rotri_i32(var, var, shift); break;
         } else {
             TCGv tmp = tcg_temp_new_i32();
+            tcg_gen_shli_i32(tmp, cpu_CF, 31);
             if (flags)
                 shifter_out_im(var, 0);
             tcg_gen_shri_i32(var, var, 1);
Quoted 8 lines

target-arm/translate.c static inline void gen_arm_shift_im(TCGv var, int shiftop, int shift, int flags) · line 525

Quoted 4 lines
target-arm/translate.c +0 -1
-            tcg_gen_shli_i32(tmp, cpu_CF, 31);
             tcg_gen_or_i32(var, var, tmp);
             tcg_temp_free_i32(tmp);
         }

Looks like this was broken by Aurelien's commit 66c374de8; previously we loaded CF into a tmp before doing the shifter_out_im() [which updates CF], and then used the tmp after the call, rather than directly using CF.

Yes, I am the culprit here, sorry about that.

Quoted 2 lines

And applied.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net