Skip to contentSkip to conversation

target/riscv: rvv: Handle source overlap of vector widening reduction instructions

PATCH Applied Anton Blanchard 3 participants 4 messages Apr 17 – May 25 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: rvv: Handle source overlap of vector widening reduction instructions

Widening reductions read vs2 as a vector of SEW elements and vs1[0] as a scalar of 2*SEW. The ISA does not allow the same vector register to be read with different EEWs, so they must not overlap.

vs1 is read as a scalar from element 0, so it is treated as a single vector register (independent of LMUL) when checking overlap.

---
 target/riscv/insn_trans/trans_rvv.c.inc | 1 +
 1 file changed, 1 insertion(+)
target/riscv/insn_trans/trans_rvv.c.inc +1 -0
index 4df9a40b44..d9a0027e0b 100644
@@ -3062,6 +3062,7 @@ GEN_OPIVV_TRANS(vredxor_vs, reduction_check)
 static bool reduction_widen_check(DisasContext *s, arg_rmrr *a)
 {
     return reduction_check(s, a) && (s->sew < MO_64) &&
+           !is_overlapped(a->rs1, 1, a->rs2, 1 << MAX(s->lmul, 0)) &&
            ((s->sew + 1) <= (s->cfg_ptr->elen >> 4));
 }
 
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Anton Blanchard

Widening reductions read vs2 as a vector of SEW elements and vs1[0] as a scalar of 2*SEW. The ISA does not allow the same vector register to be read with different EEWs, so they must not overlap.

vs1 is read as a scalar from element 0, so it is treated as a single vector register (independent of LMUL) when checking overlap.

I assume this resolves https://gitlab.com/qemu-project/qemu/-/work_items/3208

Quoted 2 lines

Alistair

Quoted 20 lines
---
 target/riscv/insn_trans/trans_rvv.c.inc | 1 +
 1 file changed, 1 insertion(+)
target/riscv/insn_trans/trans_rvv.c.inc +1 -1
index 4df9a40b44..d9a0027e0b 100644
@@ -3062,6 +3062,7 @@ GEN_OPIVV_TRANS(vredxor_vs, reduction_check)
 static bool reduction_widen_check(DisasContext *s, arg_rmrr *a)
 {
     return reduction_check(s, a) && (s->sew < MO_64) &&
+           !is_overlapped(a->rs1, 1, a->rs2, 1 << MAX(s->lmul, 0)) &&
            ((s->sew + 1) <= (s->cfg_ptr->elen >> 4));
 }
 
--

2.34.1

#2 lore raw
In reply to Anton Blanchard
Quoted 9 lines · Anton Blanchard

Widening reductions read vs2 as a vector of SEW elements and vs1[0] as a scalar of 2*SEW. The ISA does not allow the same vector register to be read with different EEWs, so they must not overlap.

vs1 is read as a scalar from element 0, so it is treated as a single vector register (independent of LMUL) when checking overlap.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 20 lines
---
 target/riscv/insn_trans/trans_rvv.c.inc | 1 +
 1 file changed, 1 insertion(+)
target/riscv/insn_trans/trans_rvv.c.inc +1 -1
index 4df9a40b44..d9a0027e0b 100644
@@ -3062,6 +3062,7 @@ GEN_OPIVV_TRANS(vredxor_vs, reduction_check)
 static bool reduction_widen_check(DisasContext *s, arg_rmrr *a)
 {
     return reduction_check(s, a) && (s->sew < MO_64) &&
+           !is_overlapped(a->rs1, 1, a->rs2, 1 << MAX(s->lmul, 0)) &&
            ((s->sew + 1) <= (s->cfg_ptr->elen >> 4));
 }
 
--

2.34.1

#3 lore raw
In reply to Anton Blanchard
Quoted 17 lines · Anton Blanchard

Widening reductions read vs2 as a vector of SEW elements and vs1[0] as a scalar of 2*SEW. The ISA does not allow the same vector register to be read with different EEWs, so they must not overlap.

vs1 is read as a scalar from element 0, so it is treated as a single vector register (independent of LMUL) when checking overlap.

---
  target/riscv/insn_trans/trans_rvv.c.inc | 1 +
  1 file changed, 1 insertion(+)
target/riscv/insn_trans/trans_rvv.c.inc +0 -0
index 4df9a40b44..d9a0027e0b 100644

target/riscv/insn_trans/trans_rvv.c.inc GEN_OPIVV_TRANS(vredxor_vs, reduction_check) · line 3068

Quoted 7 lines
target/riscv/insn_trans/trans_rvv.c.inc +1 -0
@@ -3062,6 +3062,7 @@ GEN_OPIVV_TRANS(vredxor_vs, reduction_check)
  static bool reduction_widen_check(DisasContext *s, arg_rmrr *a)
  {
      return reduction_check(s, a) && (s->sew < MO_64) &&
+           !is_overlapped(a->rs1, 1, a->rs2, 1 << MAX(s->lmul, 0)) &&
             ((s->sew + 1) <= (s->cfg_ptr->elen >> 4));
  }
 

Shouldn't this change be in stable qemu series?
Or is it not important there?

I'm picking it up, please let me know if I shouldn't.

Thanks,

/mjt