On 04/29/2014 04:12 AM, Alex Bennée wrote: > > Richard Henderson <r...@twiddle.net> writes: > >> And use tcg pointer differencing functions as appropriate. >> >> Reviewed-by: Peter Maydell <peter.mayd...@linaro.org> >> Signed-off-by: Richard Henderson <r...@twiddle.net> > <snip> >> >> -static void tcg_out_branch(TCGContext *s, int call, uintptr_t dest) >> +static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest) >> { >> - intptr_t disp = dest - (intptr_t)s->code_ptr - 5; >> + intptr_t disp = tcg_pcrel_diff(s, dest) - 5; >> >> if (disp == (int32_t)disp) { >> tcg_out_opc(s, call ? OPC_CALL_Jz : OPC_JMP_long, 0, 0, 0); >> tcg_out32(s, disp); >> } else { >> - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R10, dest); >> + tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R10, (uintptr_t)dest); >> tcg_out_modrm(s, OPC_GRP5, >> call ? EXT5_CALLN_Ev : EXT5_JMPN_Ev, TCG_REG_R10); >> } >> } > > I'm a little unclear on where the -5 came from? Is this a relative > address based on where we will be after we've emitted the code?
The branch is relative to the end of the branch insn, which itself is 5 bytes long. I suppose this could be written dest - (s->code_ptr + 5) though I don't know if that's any more or less clear. r~