Sometimes it may be required to perform calls and jumps to absolute address on 64-bit AMD. Unfortunately, x86_64 instruction set only allows 32-bit displacements, so traditional approach is to move desired address into register and
call or jump using it. Unfortunately, it requires scratch register, or push/pop of register.
In case of jump, it also problematic if we wish not touch registers. Here I suggest alternative approach, using ret
instructions for long jumps. While not too complicated, this trick can help some compiler/JIT writers to handle very long jumps.
DECLINLINE(void) tcg_out_pushq(TCGContext \*s, tcg_target_long val)
tcg_out8(s, 0x68); /\* push imm32, subs 8 from rsp \*/
tcg_out32(s, val); /\* imm32 \*/
if ((val >> 32) != 0)
tcg_out8(s, 0xc7); /\* mov imm32, 4(%rsp) \*/
tcg_out32(s, ((uint64_t)val) >> 32); /\* imm32 \*/
DECLINLINE(void) tcg_out_long_jmp(TCGContext \*s, tcg_target_long dst)
tcg_out8(s, 0xc3); /\* ret \*/