Skip to contentSkip to conversation

check loongarch64 vldi immediates Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2971 Signed-off-by: Lorenz Hetterich <[email protected]>

PATCH In review Lorenz Hetterich 2 participants 2 messages May 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check loongarch64 vldi immediates Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2971 Signed-off-by: Lorenz Hetterich <[email protected]>

---
 target/loongarch/tcg/insn_trans/trans_vec.c.inc | 13 +++++++++++++
 1 file changed, 13 insertions(+)
target/loongarch/tcg/insn_trans/trans_vec.c.inc +13 -0
index dff92772ad..5589a9e865 100644
@@ -3460,6 +3460,16 @@ TRANS(xvmskltz_d, LASX, gen_xx, gen_helper_vmskltz_d)
 TRANS(xvmskgez_b, LASX, gen_xx, gen_helper_vmskgez_b)
 TRANS(xvmsknz_b, LASX, gen_xx, gen_helper_vmsknz_b)
 
+static bool vldi_check_value(DisasContext *ctx, uint32_t imm)
+{
+    if (((imm >> 8) & 0xf) > 12) {
+        generate_exception(ctx, EXCCODE_INE);
+        return false;
+    }
+    return true;
+}
+
+
 #define EXPAND_BYTE(bit)  ((uint64_t)(bit ? 0xff : 0))
 
 static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm)
@@ -3588,6 +3598,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
     sel = (a->imm >> 12) & 0x1;
 
     if (sel) {
+        if (!vldi_check_value(ctx, a->imm)) {
+            return true;
+        }
         value = vldi_get_value(ctx, a->imm);
         vece = MO_64;
     } else {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 26 lines · Lorenz Hetterich
---
  target/loongarch/tcg/insn_trans/trans_vec.c.inc | 13 +++++++++++++
  1 file changed, 13 insertions(+)
target/loongarch/tcg/insn_trans/trans_vec.c.inc +10 -0
index dff92772ad..5589a9e865 100644
@@ -3460,6 +3460,16 @@ TRANS(xvmskltz_d, LASX, gen_xx, gen_helper_vmskltz_d)
  TRANS(xvmskgez_b, LASX, gen_xx, gen_helper_vmskgez_b)
  TRANS(xvmsknz_b, LASX, gen_xx, gen_helper_vmsknz_b)
 
+static bool vldi_check_value(DisasContext *ctx, uint32_t imm)
+{
+    if (((imm >> 8) & 0xf) > 12) {
+        generate_exception(ctx, EXCCODE_INE);
+        return false;
+    }
+    return true;
+}
+
+
  #define EXPAND_BYTE(bit)  ((uint64_t)(bit ? 0xff : 0))
 
  static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm)

target/loongarch/tcg/insn_trans/trans_vec.c.inc static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz) · line 3603

Quoted 6 lines
target/loongarch/tcg/insn_trans/trans_vec.c.inc +3 -0
@@ -3588,6 +3598,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
      sel = (a->imm >> 12) & 0x1;
 
      if (sel) {
+        if (!vldi_check_value(ctx, a->imm)) {
+            return true;
+        }

Hi , sorry for not reply on gitlab,com,  my accout disabled. this is incorrect ,  we should't skip  imm > 12.  imm > 12 is a invalid. you can keep this patch  on your code if you want imm >12 not get  an error.

Thanks.
Song Gao

Quoted 3 lines
target/loongarch/tcg/insn_trans/trans_vec.c.inc +0 -0
          value = vldi_get_value(ctx, a->imm);
          vece = MO_64;
      } else {