]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
target/loongarch: Fix [X]VLDI raising exception incorrectly
authorWANG Rui <wangrui@loongson.cn>
Mon, 4 Aug 2025 13:22:12 +0000 (21:22 +0800)
committerSong Gao <gaosong@loongson.cn>
Fri, 8 Aug 2025 01:18:44 +0000 (09:18 +0800)
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 <wszqkzqk@qq.com>
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Message-ID: <20250804132212.4816-1-wangrui@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
target/loongarch/tcg/insn_trans/trans_vec.c.inc

index 78730029cbaad8d0325b4ed9bf262229536366e8..38bccf28386fce8a9813d0de4b946c68456e6d08 100644 (file)
@@ -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;