Skip to contentSkip to conversation

Fix bug in translation of REVSH

PATCH In review Johan Bengtsson 2 participants 2 messages Oct 18, 2010 – Dec 27, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix bug in translation of REVSH

The translation of REVSH shifted the low byte 8 steps left before performing an 8-bit sign extend, causing this part of the expression to alwas be 0. The fix for this is either to extend before shifting or switch to a 16-bit extend. I choose the former.

---
 target-arm/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-arm/translate.c +1 -1
index 652cac9..e2fa4df 100644
@@ -253,8 +253,8 @@ static void gen_revsh(TCGv var)
     TCGv tmp = new_tmp();
     tcg_gen_shri_i32(tmp, var, 8);
     tcg_gen_andi_i32(tmp, tmp, 0x00ff);
-    tcg_gen_shli_i32(var, var, 8);
     tcg_gen_ext8s_i32(var, var);
+    tcg_gen_shli_i32(var, var, 8);
     tcg_gen_or_i32(var, var, tmp);
     dead_tmp(tmp);
 }
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 9 lines · Johan Bengtsson

The translation of REVSH shifted the low byte 8 steps left before performing an 8-bit sign extend, causing this part of the expression to alwas be 0. The fix for this is either to extend before shifting or switch to a 16-bit extend. I choose the former.

---
 target-arm/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Thanks for this patch. While it is correct, I have committed a different fix using tcg_gen_bswap16, so that the generated code can be optimized on some hosts.

Quoted 19 lines
target-arm/translate.c +1 -1
index 652cac9..e2fa4df 100644
@@ -253,8 +253,8 @@ static void gen_revsh(TCGv var)
     TCGv tmp = new_tmp();
     tcg_gen_shri_i32(tmp, var, 8);
     tcg_gen_andi_i32(tmp, tmp, 0x00ff);
-    tcg_gen_shli_i32(var, var, 8);
     tcg_gen_ext8s_i32(var, var);
+    tcg_gen_shli_i32(var, var, 8);
     tcg_gen_or_i32(var, var, tmp);
     dead_tmp(tmp);
 }
Signature · 1 line
1.7.0.4
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net