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

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

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 11df226a00..7304e478c2 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -692,7 +692,11 @@ 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);
+    /*
+     * vlmax = vlen >> (sew + 3 - lmul). With vlenb,
+     * 3 less shifts: vlenb >> (sew + 3 - 3 - lmul)
+     */
+    return cpu->cfg.vlenb >> (sew - lmul);
 }
 
 void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
-- 
2.43.0
Re: [PATCH v2 09/12] target/riscv/cpu.h: use 'vlenb' in vext_get_vlmax()
Posted by Richard Henderson 10 months, 2 weeks ago
On 1/16/24 09:25, Daniel Henrique Barboza wrote:
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>   target/riscv/cpu.h | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 11df226a00..7304e478c2 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -692,7 +692,11 @@ 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);
> +    /*
> +     * vlmax = vlen >> (sew + 3 - lmul). With vlenb,
> +     * 3 less shifts: vlenb >> (sew + 3 - 3 - lmul)
> +     */
> +    return cpu->cfg.vlenb >> (sew - lmul);
>   }

I take it back -- this doesn't work without the + 3:

   sew = 0
   lmul = 3

    vlenb >> (0 - 3)
  = vlenb >> -3

Need

   vlen = vlenb << 3
   vlmax = vlen >> (0 + 3 - 3)
         = vlen >> 0
         = vlen


r~
Re: [PATCH v2 09/12] target/riscv/cpu.h: use 'vlenb' in vext_get_vlmax()
Posted by Daniel Henrique Barboza 10 months, 2 weeks ago

On 1/15/24 20:14, Richard Henderson wrote:
> On 1/16/24 09:25, Daniel Henrique Barboza wrote:
>> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
>> ---
>>   target/riscv/cpu.h | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
>> index 11df226a00..7304e478c2 100644
>> --- a/target/riscv/cpu.h
>> +++ b/target/riscv/cpu.h
>> @@ -692,7 +692,11 @@ 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);
>> +    /*
>> +     * vlmax = vlen >> (sew + 3 - lmul). With vlenb,
>> +     * 3 less shifts: vlenb >> (sew + 3 - 3 - lmul)
>> +     */
>> +    return cpu->cfg.vlenb >> (sew - lmul);
>>   }
> 
> I take it back -- this doesn't work without the + 3:
> 
>    sew = 0
>    lmul = 3
> 
>     vlenb >> (0 - 3)
>   = vlenb >> -3
> 
> Need
> 
>    vlen = vlenb << 3
>    vlmax = vlen >> (0 + 3 - 3)
>          = vlen >> 0
>          = vlen

I got tricked by the 'sew' variable name there. This formula is using vsew.

I'll fix and re-send. Thanks,


Daniel


> 
> 
> r~
> 
> 

Re: [PATCH v2 09/12] target/riscv/cpu.h: use 'vlenb' in vext_get_vlmax()
Posted by Richard Henderson 10 months, 2 weeks ago
On 1/16/24 09:25, Daniel Henrique Barboza wrote:
> Signed-off-by: Daniel Henrique Barboza<dbarboza@ventanamicro.com>
> ---
>   target/riscv/cpu.h | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~