target/riscv: Fix shift count overflow
PATCH v3 1/1 target/riscv: Fix shift count overflow
The result of (8 - 3 - vlmul) is negative when vlmul >= 6, and results in wrong vill.
---
Changes in v2:
- Add vlen var
Changes in v3:
- Fix commit msg typo
target/riscv/vector_helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
target/riscv/vector_helper.c +2 -3
@@ -44,6 +44,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,target_ulong reserved = s2 &MAKE_64BIT_MASK (R_VTYPE_RESERVED_SHIFT , xlen -1 -R_VTYPE_RESERVED_SHIFT ); +uint16_t vlen = cpu->cfg.vlenb <<3 ;int8_t lmul;if (vlmul &4 ) {
@@ -53,10 +54,8 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,* VLEN * LMUL >= SEW * VLEN >> (8 - lmul) >= sew * (vlenb << 3) >> (8 - lmul) >= sew -* vlenb >> (8 - 3 - lmul) >= sew */ -if (vlmul ==4 || - cpu->cfg.vlenb >> (8 -3 - vlmul) < sew) { +if (vlmul ==4 || (vlen >> (8 - vlmul)) < sew) { vill = true; } }
Signature · 1 line
2.43.2
Quoted 5 lines · demin.han
The result of (8 - 3 - vlmul) is negative when vlmul >= 6, and results in wrong vill.
Signed-off-by demin.han <[email protected]>---
Quoted 33 lines
Changes in v2:
- Add vlen varChanges in v3:
- Fix commit msg typotarget/riscv/vector_helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)target/riscv/vector_helper.c +2
-3@@ -44,6 +44,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,target_ulong reserved = s2 &MAKE_64BIT_MASK (R_VTYPE_RESERVED_SHIFT , xlen -1 -R_VTYPE_RESERVED_SHIFT ); +uint16_t vlen = cpu->cfg.vlenb <<3 ;int8_t lmul;if (vlmul &4 ) {@@ -53,10 +54,8 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,* VLEN * LMUL >= SEW * VLEN >> (8 - lmul) >= sew * (vlenb << 3) >> (8 - lmul) >= sew -* vlenb >> (8 - 3 - lmul) >= sew */ -if (vlmul ==4 || - cpu->cfg.vlenb >> (8 -3 - vlmul) < sew) { +if (vlmul ==4 || (vlen >> (8 - vlmul)) < sew) { vill = true; } }
Hi Alistair,
Please don't forget to queue this up. Thanks,
Daniel
Quoted 43 lines · Daniel Henrique Barboza
Quoted 5 lines · demin.han
The result of (8 - 3 - vlmul) is negative when vlmul >= 6, and results in wrong vill.
Signed-off-by demin.han <[email protected]>---
Reviewed-by Daniel Henrique Barboza <[email protected]>Quoted 32 lines
Changes in v2:
- Add vlen varChanges in v3:
- Fix commit msg typo
target/riscv/vector_helper.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)target/riscv/vector_helper.c +0
-0@@ -44,6 +44,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
target_ulongreserved = s2 &MAKE_64BIT_MASK(R_VTYPE_RESERVED_SHIFT, xlen - 1 - R_VTYPE_RESERVED_SHIFT); +uint16_tvlen =cpu->cfg.vlenb<< 3;
int8_tlmul;
if (vlmul & 4) {target/riscv/vector_helper.c +1
-3@@ -53,10 +54,8 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,* VLEN * LMUL >= SEW * VLEN >> (8 - lmul) >= sew * (vlenb << 3) >> (8 - lmul) >= sew -* vlenb >> (8 - 3 - lmul) >= sew */ - if (vlmul == 4 || - cpu->cfg.vlenb >> (8 - 3 - vlmul) < sew) { + if (vlmul == 4 || (vlen >> (8 - vlmul)) < sew) { vill = true; } }
Alistair Francis
AppliedQuoted 5 lines · demin.han
The result of (8 - 3 - vlmul) is negative when vlmul >= 6, and results in wrong vill.
Signed-off-by demin.han <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 38 lines
---
Changes in v2:
- Add vlen varChanges in v3:
- Fix commit msg typotarget/riscv/vector_helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)target/riscv/vector_helper.c +2
-4@@ -44,6 +44,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,target_ulong reserved = s2 &MAKE_64BIT_MASK (R_VTYPE_RESERVED_SHIFT , xlen -1 -R_VTYPE_RESERVED_SHIFT ); +uint16_t vlen = cpu->cfg.vlenb <<3 ;int8_t lmul;if (vlmul &4 ) {@@ -53,10 +54,8 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,* VLEN * LMUL >= SEW * VLEN >> (8 - lmul) >= sew * (vlenb << 3) >> (8 - lmul) >= sew -* vlenb >> (8 - 3 - lmul) >= sew */ -if (vlmul ==4 || - cpu->cfg.vlenb >> (8 -3 - vlmul) < sew) { +if (vlmul ==4 || (vlen >> (8 - vlmul)) < sew) { vill = true; } } --2.43.2