[PATCH 09/13] target/riscv/cpu.h: use 'vlenb' in vext_get_vlmax()

Daniel Henrique Barboza posted 13 patches 8 months, 1 week ago
There is a newer version of this series
[PATCH 09/13] target/riscv/cpu.h: use 'vlenb' in vext_get_vlmax()
Posted by Daniel Henrique Barboza 8 months, 1 week ago
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 target/riscv/cpu.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 11df226a00..628ef67d5f 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -692,7 +692,8 @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, target_ulong vtype)
 {
     uint8_t sew = FIELD_EX64(vtype, VTYPE, VSEW);
     int8_t lmul = sextract32(FIELD_EX64(vtype, VTYPE, VLMUL), 0, 3);
-    return cpu->cfg.vlen >> (sew + 3 - lmul);
+    /* vlen = vlenb << 3 */
+    return (cpu->cfg.vlenb << 3) >> (sew + 3 - lmul);
 }
 
 void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
-- 
2.43.0
Re: [PATCH 09/13] target/riscv/cpu.h: use 'vlenb' in vext_get_vlmax()
Posted by Richard Henderson 8 months, 1 week ago
On 1/13/24 08:38, Daniel Henrique Barboza wrote:
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>   target/riscv/cpu.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 11df226a00..628ef67d5f 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -692,7 +692,8 @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, target_ulong vtype)
>   {
>       uint8_t sew = FIELD_EX64(vtype, VTYPE, VSEW);
>       int8_t lmul = sextract32(FIELD_EX64(vtype, VTYPE, VLMUL), 0, 3);
> -    return cpu->cfg.vlen >> (sew + 3 - lmul);
> +    /* vlen = vlenb << 3 */
> +    return (cpu->cfg.vlenb << 3) >> (sew + 3 - lmul);
>   }

Better to simplify the arithmetic:

-    return cpu->cfg.vlen >> (sew + 3 - lmul);
+    return cpu->cfg.vlenb >> (sew - lmul);


r~