On Tue, 4 Oct 2022 at 21:57, Richard Henderson <richard.hender...@linaro.org> wrote: > > On 10/4/22 08:58, Peter Maydell wrote: > > On Fri, 30 Sept 2022 at 23:10, Richard Henderson > > <richard.hender...@linaro.org> wrote: > >> > >> In preparation for TARGET_TB_PCREL, reduce reliance on absolute values. > >> > >> Signed-off-by: Richard Henderson <richard.hender...@linaro.org> > >> --- > >> target/arm/translate.c | 37 +++++++++++++++++++++---------------- > >> 1 file changed, 21 insertions(+), 16 deletions(-) > > > >> @@ -8368,7 +8372,8 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i > >> *a) > >> } > >> tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); > >> store_cpu_field_constant(!s->thumb, thumb); > >> - gen_jmp(s, (read_pc(s) & ~3) + a->imm); > >> + /* This difference computes a page offset so ok for TARGET_TB_PCREL. > >> */ > >> + gen_jmp(s, (read_pc(s) & ~3) - s->pc_curr + a->imm); > > > > Could we just calculate the offset of the jump target instead? > > read_pc() returns s->pc_curr + a constant, so the s->pc_curr cancels > > out anyway: > > > > (read_pc(s) & ~3) - s->pc_curr + a->imm > > == > > (pc_curr + (s->thumb ? 4 : 8) & ~3) - pc_curr + imm > > == pc_curr - pc_curr_low_bits - pc_curr + 4-or-8 + imm > > == imm + 4-or-8 - low_bits_of_pc > > > > That's then more obviously not dependent on the absolute value > > of the PC. > > Yes, this works: > > - gen_jmp(s, (read_pc(s) & ~3) + a->imm); > > + /* This jump is computed from an aligned PC: subtract off the low bits. > */ > > + gen_jmp(s, jmp_diff(s, a->imm - (s->pc_curr & 3)));
Cool, that looks a lot clearer. With that change, Reviewed-by: Peter Maydell <peter.mayd...@linaro.org> thanks -- PMM