On Sun, 2026-11-08 at 00:46 -0600, Rishab Pradeep wrote:
> From: Rishab Pradeep <[email protected]>
> 
> Move the addr_xl/addr_signed extract, which applies address-width
> truncation and the pointer-masking ignore transformation, out of
> get_address() and get_address_indexed() into a new helper,
> gen_pm_adjust_addr(), so it can be applied to addresses that are not
> formed from a GPR. No functional change.
> 
> Co-developed-by: Tarun Patanjali <[email protected]>
> Signed-off-by: Tarun Patanjali <[email protected]>
> Co-developed-by: Chris Elwood <[email protected]>
> Signed-off-by: Chris Elwood <[email protected]>
> Reviewed-by: Daniel Henrique Barboza
> <[email protected]>
> Signed-off-by: Rishab Pradeep <[email protected]>

Reviewed-by: Alistair Francis <[email protected]>

Alistair

> ---
>  target/riscv/tcg/translate.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/target/riscv/tcg/translate.c
> b/target/riscv/tcg/translate.c
> index 79b0f444ef..72d36764d8 100644
> --- a/target/riscv/tcg/translate.c
> +++ b/target/riscv/tcg/translate.c
> @@ -654,6 +654,15 @@ static void gen_jal(DisasContext *ctx, int rd,
> target_ulong imm)
>      ctx->base.is_jmp = DISAS_NORETURN;
>  }
>  
> +static void gen_pm_adjust_addr(DisasContext *ctx, TCGv dest, TCGv
> src)
> +{
> +    if (ctx->addr_signed) {
> +        tcg_gen_sextract_tl(dest, src, 0, ctx->addr_xl);
> +    } else {
> +        tcg_gen_extract_tl(dest, src, 0, ctx->addr_xl);
> +    }
> +}
> +
>  /* Compute a canonical address from a register plus offset. */
>  static TCGv get_address(DisasContext *ctx, int rs1, int imm)
>  {
> @@ -661,11 +670,7 @@ static TCGv get_address(DisasContext *ctx, int
> rs1, int imm)
>      TCGv src1 = get_gpr(ctx, rs1, EXT_NONE);
>  
>      tcg_gen_addi_tl(addr, src1, imm);
> -    if (ctx->addr_signed) {
> -        tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl);
> -    } else {
> -        tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl);
> -    }
> +    gen_pm_adjust_addr(ctx, addr, addr);
>  
>      return addr;
>  }
> @@ -677,11 +682,7 @@ static TCGv get_address_indexed(DisasContext
> *ctx, int rs1, TCGv offs)
>      TCGv src1 = get_gpr(ctx, rs1, EXT_NONE);
>  
>      tcg_gen_add_tl(addr, src1, offs);
> -    if (ctx->addr_signed) {
> -        tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl);
> -    } else {
> -        tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl);
> -    }
> +    gen_pm_adjust_addr(ctx, addr, addr);
>  
>      return addr;
>  }

Reply via email to