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
```

Reported-by: Zhou Qiankang <wszqk...@qq.com>
Signed-off-by: WANG Rui <wang...@loongson.cn>
---
 target/loongarch/tcg/insn_trans/trans_vec.c.inc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc 
b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
index 78730029cb..ee10a9ebe1 100644
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
@@ -3585,11 +3585,6 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, 
uint32_t oprsz)
     int sel, vece;
     uint64_t value;
 
-    if (!check_valid_vldi_mode(a)) {
-        generate_exception(ctx, EXCCODE_INE);
-        return true;
-    }
-
     if (!check_vec(ctx, oprsz)) {
         return true;
     }
@@ -3597,6 +3592,11 @@ static bool gen_vldi(DisasContext *ctx, arg_vldi *a, 
uint32_t oprsz)
     sel = (a->imm >> 12) & 0x1;
 
     if (sel) {
+        if (!check_valid_vldi_mode(a)) {
+            generate_exception(ctx, EXCCODE_INE);
+            return true;
+        }
+
         value = vldi_get_value(ctx, a->imm);
         vece = MO_64;
     } else {
-- 
2.50.1


Reply via email to