Skip to content

Commit bc502d4

Browse files
rnaxantonblanchard
authored andcommitted
target/riscv: rvv: Apply vext_check_input_eew to vrgather instructions to check mismatched input EEWs encoding constraint
According to the v spec, a vector register cannot be used to provide source operands with more than one EEW for a single instruction. The vs1 EEW of vrgatherei16.vv is 16. Co-authored-by: Anton Blanchard <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Signed-off-by: Max Chou <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]> Cc: [email protected] (cherry picked from commit 629c2a8) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 027ea4a commit bc502d4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

target/riscv/insn_trans/trans_rvv.c.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,35 @@ static bool vext_check_ld_index(DisasContext *s, int vd, int vs2,
379379
return ret;
380380
}
381381

382+
/*
383+
* Check whether a vector register is used to provide source operands with
384+
* more than one EEW for the vector instruction.
385+
* Returns true if the instruction has valid encoding
386+
* Returns false if encoding violates the mismatched input EEWs constraint
387+
*/
388+
static bool vext_check_input_eew(DisasContext *s, int vs1, uint8_t eew_vs1,
389+
int vs2, uint8_t eew_vs2, int vm)
390+
{
391+
bool is_valid = true;
392+
int8_t emul_vs1 = eew_vs1 - s->sew + s->lmul;
393+
int8_t emul_vs2 = eew_vs2 - s->sew + s->lmul;
394+
395+
/* When vm is 0, vs1 & vs2(EEW!=1) group can't overlap v0 (EEW=1) */
396+
if ((vs1 != -1 && !require_vm(vm, vs1)) ||
397+
(vs2 != -1 && !require_vm(vm, vs2))) {
398+
is_valid = false;
399+
}
400+
401+
/* When eew_vs1 != eew_vs2, check whether vs1 and vs2 are overlapped */
402+
if ((vs1 != -1 && vs2 != -1) && (eew_vs1 != eew_vs2) &&
403+
is_overlapped(vs1, 1 << MAX(emul_vs1, 0),
404+
vs2, 1 << MAX(emul_vs2, 0))) {
405+
is_valid = false;
406+
}
407+
408+
return is_valid;
409+
}
410+
382411
static bool vext_check_ss(DisasContext *s, int vd, int vs, int vm)
383412
{
384413
return require_vm(vm, vd) &&
@@ -3449,6 +3478,7 @@ static bool vrgather_vv_check(DisasContext *s, arg_rmrr *a)
34493478
{
34503479
return require_rvv(s) &&
34513480
vext_check_isa_ill(s) &&
3481+
vext_check_input_eew(s, a->rs1, s->sew, a->rs2, s->sew, a->vm) &&
34523482
require_align(a->rd, s->lmul) &&
34533483
require_align(a->rs1, s->lmul) &&
34543484
require_align(a->rs2, s->lmul) &&
@@ -3461,6 +3491,7 @@ static bool vrgatherei16_vv_check(DisasContext *s, arg_rmrr *a)
34613491
int8_t emul = MO_16 - s->sew + s->lmul;
34623492
return require_rvv(s) &&
34633493
vext_check_isa_ill(s) &&
3494+
vext_check_input_eew(s, a->rs1, MO_16, a->rs2, s->sew, a->vm) &&
34643495
(emul >= -3 && emul <= 3) &&
34653496
require_align(a->rd, s->lmul) &&
34663497
require_align(a->rs1, emul) &&
@@ -3480,6 +3511,7 @@ static bool vrgather_vx_check(DisasContext *s, arg_rmrr *a)
34803511
{
34813512
return require_rvv(s) &&
34823513
vext_check_isa_ill(s) &&
3514+
vext_check_input_eew(s, -1, MO_64, a->rs2, s->sew, a->vm) &&
34833515
require_align(a->rd, s->lmul) &&
34843516
require_align(a->rs2, s->lmul) &&
34853517
(a->rd != a->rs2) &&

0 commit comments

Comments
 (0)