Skip to contentSkip to conversation

target/loongarch: Sign-extend REVB.2H result

RFC PATCH In review Philippe Mathieu-Daudé 2 participants 2 messages Aug 22, 2023

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 target/loongarch: Sign-extend REVB.2H result

Per [*]:

The REVB.2H instruction performs [...] and write the 32-bit intermediate result sign extended to the general register 'rd'.

Add the missing sign extension.

[*] https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_revb_2h4h2wd

Fixes ad08cb3f97 ("target/loongarch: Add fixed point bit instruction translation")

---
RFC: Totally untested, only noticed during code review.

---
 target/loongarch/insn_trans/trans_bit.c.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/loongarch/insn_trans/trans_bit.c.inc +2 -1
index 25b4d7858b..a98c46d8cb 100644
@@ -121,7 +121,8 @@ static void gen_revb_2h(TCGv dest, TCGv src1)
     tcg_gen_and_tl(t0, t0, mask);
     tcg_gen_and_tl(t1, src1, mask);
     tcg_gen_shli_tl(t1, t1, 8);
-    tcg_gen_or_tl(dest, t0, t1);
+    tcg_gen_or_tl(t0, t0, t1);
+    tcg_gen_ext32s_tl(dest, t0);
 }
 
 static void gen_revb_4h(TCGv dest, TCGv src1)
Signature · 1 line
2.41.0
#1 lore raw
Quoted 22 lines · Philippe Mathieu-Daudé

Per [*]:

The REVB.2H instruction performs [...] and write the 32-bit intermediate result sign extended to the general register 'rd'.

Add the missing sign extension.

[*] https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_revb_2h4h2wd

Fixes ad08cb3f97 ("target/loongarch: Add fixed point bit instruction translation")

---
RFC: Totally untested, only noticed during code review.

---
  target/loongarch/insn_trans/trans_bit.c.inc | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/loongarch/insn_trans/trans_bit.c.inc +0 -0
index 25b4d7858b..a98c46d8cb 100644

target/loongarch/insn_trans/trans_bit.c.inc static void gen_revb_2h(TCGv dest, TCGv src1) · line 126

Quoted 7 lines
target/loongarch/insn_trans/trans_bit.c.inc +2 -1
@@ -121,7 +121,8 @@ static void gen_revb_2h(TCGv dest, TCGv src1)
      tcg_gen_and_tl(t0, t0, mask);
      tcg_gen_and_tl(t1, src1, mask);
      tcg_gen_shli_tl(t1, t1, 8);
-    tcg_gen_or_tl(dest, t0, t1);
+    tcg_gen_or_tl(t0, t0, t1);
+    tcg_gen_ext32s_tl(dest, t0);
  }

Nack. This is handled via EXT_SIGN in

TRANS(revb_2h, gen_rr, EXT_NONE, EXT_SIGN, gen_revb_2h)

r~