Skip to contentSkip to conversation

target/loongarch: Fix [X]VLDI raising exception incorrectly

PATCH In review WANG Rui 2 participants 2 messages Aug 4, 2025 – Aug 6, 2025

lore
Share & tools
lore

WANG Rui

author
#0 lore raw

PATCH v2 1/1 target/loongarch: Fix [X]VLDI raising exception incorrectly

According to the specification, [X]VLDI should trigger an invalid instruction exception only when Bit[12] is 1 and Bit[11:8] > 12. This patch fixes an issue where an exception was incorrectly raised even when Bit[12] was 0.

Test case:

```
    .global main
main:
    vldi    $vr0, 3328
    ret
```

---
v1 -> v2:
- Keep the INE exception prioritized over the [A]SXD.

---
 target/loongarch/tcg/insn_trans/trans_vec.c.inc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/loongarch/tcg/insn_trans/trans_vec.c.inc +3 -3
index 78730029cb..38bccf2838 100644
@@ -3585,7 +3585,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
     int sel, vece;
     uint64_t value;
 
-    if (!check_valid_vldi_mode(a)) {
+    sel = (a->imm >> 12) & 0x1;
+
+    if (sel && !check_valid_vldi_mode(a)) {
         generate_exception(ctx, EXCCODE_INE);
         return true;
     }
@@ -3594,8 +3596,6 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
         return true;
     }
 
-    sel = (a->imm >> 12) & 0x1;
-
     if (sel) {
         value = vldi_get_value(ctx, a->imm);
         vece = MO_64;
Signature · 1 line
2.50.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · WANG Rui

According to the specification, [X]VLDI should trigger an invalid instruction exception only when Bit[12] is 1 and Bit[11:8] > 12. This patch fixes an issue where an exception was incorrectly raised even when Bit[12] was 0.

Test case:

```
     .global main
main:
     vldi    $vr0, 3328
     ret
```
Quoted 8 lines

---
v1 -> v2:
- Keep the INE exception prioritized over the [A]SXD.

---
  target/loongarch/tcg/insn_trans/trans_vec.c.inc | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

Thanks
Song Gao

Quoted 24 lines
target/loongarch/tcg/insn_trans/trans_vec.c.inc +3 -3
index 78730029cb..38bccf2838 100644
@@ -3585,7 +3585,9 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
      int sel, vece;
      uint64_t value;
 
-    if (!check_valid_vldi_mode(a)) {
+    sel = (a->imm >> 12) & 0x1;
+
+    if (sel && !check_valid_vldi_mode(a)) {
          generate_exception(ctx, EXCCODE_INE);
          return true;
      }
@@ -3594,8 +3596,6 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, uint32_t oprsz)
          return true;
      }
 
-    sel = (a->imm >> 12) & 0x1;
-
      if (sel) {
          value = vldi_get_value(ctx, a->imm);
          vece = MO_64;