[PATCH v2 13/23] target/loongarch: Fix rdtimer on 32bit build

Jiaxun Yang posted 23 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH v2 13/23] target/loongarch: Fix rdtimer on 32bit build
Posted by Jiaxun Yang 3 months, 2 weeks ago
Use TCGv_i64 for intermediate values and perform truncation as necessary.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 target/loongarch/tcg/insn_trans/trans_extra.c.inc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/target/loongarch/tcg/insn_trans/trans_extra.c.inc b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
index cfa361fecfa9ba569034b2c591b910ae7a3c6427..f9fb828ce51f2ee925edde7330d3054da534ecb3 100644
--- a/target/loongarch/tcg/insn_trans/trans_extra.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
@@ -46,13 +46,15 @@ static bool gen_rdtime(DisasContext *ctx, arg_rr *a,
 {
     TCGv dst1 = gpr_dst(ctx, a->rd, EXT_NONE);
     TCGv dst2 = gpr_dst(ctx, a->rj, EXT_NONE);
+    TCGv_i64 val = tcg_temp_new_i64();
 
     translator_io_start(&ctx->base);
-    gen_helper_rdtime_d(dst1, tcg_env);
+    gen_helper_rdtime_d(val, tcg_env);
     if (word) {
-        tcg_gen_sextract_tl(dst1, dst1, high ? 32 : 0, 32);
+        tcg_gen_sextract_i64(val, val, high ? 32 : 0, 32);
+        tcg_gen_trunc_i64_tl(dst1, val);
     }
-    tcg_gen_ld_i64(dst2, tcg_env, offsetof(CPULoongArchState, CSR_TID));
+    tcg_gen_ld_tl(dst2, tcg_env, offsetof(CPULoongArchState, CSR_TID));
 
     return true;
 }

-- 
2.43.0
Re: [PATCH v2 13/23] target/loongarch: Fix rdtimer on 32bit build
Posted by Richard Henderson 3 months, 2 weeks ago
On 12/26/24 13:19, Jiaxun Yang wrote:
> Use TCGv_i64 for intermediate values and perform truncation as necessary.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>   target/loongarch/tcg/insn_trans/trans_extra.c.inc | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/target/loongarch/tcg/insn_trans/trans_extra.c.inc b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
> index cfa361fecfa9ba569034b2c591b910ae7a3c6427..f9fb828ce51f2ee925edde7330d3054da534ecb3 100644
> --- a/target/loongarch/tcg/insn_trans/trans_extra.c.inc
> +++ b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
> @@ -46,13 +46,15 @@ static bool gen_rdtime(DisasContext *ctx, arg_rr *a,
>   {
>       TCGv dst1 = gpr_dst(ctx, a->rd, EXT_NONE);
>       TCGv dst2 = gpr_dst(ctx, a->rj, EXT_NONE);
> +    TCGv_i64 val = tcg_temp_new_i64();
>   
>       translator_io_start(&ctx->base);
> -    gen_helper_rdtime_d(dst1, tcg_env);
> +    gen_helper_rdtime_d(val, tcg_env);
>       if (word) {
> -        tcg_gen_sextract_tl(dst1, dst1, high ? 32 : 0, 32);
> +        tcg_gen_sextract_i64(val, val, high ? 32 : 0, 32);
> +        tcg_gen_trunc_i64_tl(dst1, val);
>       }

If !word, you are no longer assigning to dst1.
The trunc must be moved below if (word).


r~