Skip to contentSkip to conversation

tcg/riscv64: Set vtype before whole-register vector moves

PATCH Superseded Max Chou 4 participants 5 messages Sep 3 – Sep 15 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Max Chou

author
#0 lore raw

PATCH 1/1 tcg/riscv64: Set vtype before whole-register vector moves

According to the RISC-V unpriviledge spec,
"vset{i}vl{i} and whole register loads and stores do not depend upon
vtype."
The whole-register vector move instructions reuqire legal vtype that trap when VILL is set.

The tcg_out_mov in tcg/riscv64 missed the vtype setup before emitting the OPC_VMVNR_V.

Fixes d4be6ee1111 ("tcg/riscv: Implement vector mov/dup{m/i}")
---
 tcg/riscv64/tcg-target.c.inc | 2 ++
 1 file changed, 2 insertions(+)
tcg/riscv64/tcg-target.c.inc +2 -0
index 2ce9d47a633..fbfb4c44470 100644
@@ -778,6 +778,8 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg)
         {
             int lmul = type - riscv_lg2_vlenb;
             int nf = 1 << MAX(lmul, 0);
+
+            set_vtype_len(s, type);
             tcg_out_opc_vi(s, OPC_VMVNR_V, ret, arg, nf - 1);
         }
         break;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Max Chou

According to the RISC-V unpriviledge spec,
"vset{i}vl{i} and whole register loads and stores do not depend upon

    vtype."

The whole-register vector move instructions reuqire legal vtype that trap when VILL is set.

Quoted 6 lines

The tcg_out_mov in tcg/riscv64 missed the vtype setup before emitting the OPC_VMVNR_V.

Fixes d4be6ee1111 ("tcg/riscv: Implement vector mov/dup{m/i}")

---

Quoted 16 lines
  tcg/riscv64/tcg-target.c.inc | 2 ++
  1 file changed, 2 insertions(+)
tcg/riscv64/tcg-target.c.inc +2 -0
index 2ce9d47a633..fbfb4c44470 100644
@@ -778,6 +778,8 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg)
          {
              int lmul = type - riscv_lg2_vlenb;
              int nf = 1 << MAX(lmul, 0);
+
+            set_vtype_len(s, type);
              tcg_out_opc_vi(s, OPC_VMVNR_V, ret, arg, nf - 1);
          }
          break;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Max Chou
Quoted 7 lines · Max Chou

According to the RISC-V unpriviledge spec,
"vset{i}vl{i} and whole register loads and stores do not depend upon
vtype."
The whole-register vector move instructions reuqire legal vtype that trap when VILL is set.

Quoted 5 lines

The tcg_out_mov in tcg/riscv64 missed the vtype setup before emitting the OPC_VMVNR_V.

Fixes d4be6ee1111 ("tcg/riscv: Implement vector mov/dup{m/i}")

Thanks! I had the same patch in my tree.

I hit a crash running qemu-x86_64 on top of qemu-system-riscv64 -cpu rva23u64. Notably the spacemit K3 doesn't crash, but other (stricter) implementations will.

Cheers,

Joel

#3 lore raw
In reply to Max Chou
Quoted 20 lines · Max Chou

According to the RISC-V unpriviledge spec,
"vset{i}vl{i} and whole register loads and stores do not depend upon

    vtype."

The whole-register vector move instructions reuqire legal vtype that trap when VILL is set.

The tcg_out_mov in tcg/riscv64 missed the vtype setup before emitting the OPC_VMVNR_V.

Fixes d4be6ee1111 ("tcg/riscv: Implement vector mov/dup{m/i}")
---
  tcg/riscv64/tcg-target.c.inc | 2 ++
  1 file changed, 2 insertions(+)
tcg/riscv64/tcg-target.c.inc +0 -0
index 2ce9d47a633..fbfb4c44470 100644

tcg/riscv64/tcg-target.c.inc static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) · line 785

Quoted 8 lines
tcg/riscv64/tcg-target.c.inc +2 -0
@@ -778,6 +778,8 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg)
          {
              int lmul = type - riscv_lg2_vlenb;
              int nf = 1 << MAX(lmul, 0);
+
+            set_vtype_len(s, type);
              tcg_out_opc_vi(s, OPC_VMVNR_V, ret, arg, nf - 1);
          }
          break;

If I understand correctly, this happens when vtype is completely unset, such as the first use within the TB, or call-clobbered after a helper.

We don't actually need @type, just not the "uninitialized" type, TCG_TYPE_COUNT, per init_setting_vtype.

That you encountered a reg-reg move in such a situation makes me wonder if we have failed to correctly mark all of these vector registers call-clobbered?

r~

author
#4 lore raw
Quoted 33 lines · Richard Henderson
Quoted 20 lines · Max Chou

According to the RISC-V unpriviledge spec,
"vset{i}vl{i} and whole register loads and stores do not depend upon

    vtype."

The whole-register vector move instructions reuqire legal vtype that trap when VILL is set.

The tcg_out_mov in tcg/riscv64 missed the vtype setup before emitting the OPC_VMVNR_V.

Fixes d4be6ee1111 ("tcg/riscv: Implement vector mov/dup{m/i}")
---
  tcg/riscv64/tcg-target.c.inc | 2 ++
  1 file changed, 2 insertions(+)
tcg/riscv64/tcg-target.c.inc +0 -0
index 2ce9d47a633..fbfb4c44470 100644

tcg/riscv64/tcg-target.c.inc static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) · line 785

Quoted 8 lines
tcg/riscv64/tcg-target.c.inc +2 -0
@@ -778,6 +778,8 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg)
          {
              int lmul = type - riscv_lg2_vlenb;
              int nf = 1 << MAX(lmul, 0);
+
+            set_vtype_len(s, type);
              tcg_out_opc_vi(s, OPC_VMVNR_V, ret, arg, nf - 1);
          }
          break;

If I understand correctly, this happens when vtype is completely unset, such as the first use within the TB, or call-clobbered after a helper.

Quoted 3 lines

We don't actually need @type, just not the "uninitialized" type, TCG_TYPE_COUNT, per init_setting_vtype.

Hi Richard,

Thanks for the suggestion. Will send v2 for this part.

Quoted 3 lines

That you encountered a reg-reg move in such a situation makes me wonder if we have failed to correctly mark all of these vector registers call-clobbered?

I just checked the tcg_target_init to confirm that all the vector registers (v0-v31) are marked call-clobbered.

rnax

Quoted 3 lines

r~