tcg/loongarch64: Implement tcg_out_call
Signed-off-by: WANG Xuerui <git@xen0n.name> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20211221054105.178795-22-git@xen0n.name> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
9ee775cf29
commit
a26d99d72f
@ -532,6 +532,39 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1,
|
||||
tcg_out32(s, encode_djsk16_insn(op, arg1, arg2, 0));
|
||||
}
|
||||
|
||||
static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
{
|
||||
TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, arg);
|
||||
|
||||
tcg_debug_assert((offset & 3) == 0);
|
||||
if (offset == sextreg(offset, 0, 28)) {
|
||||
/* short jump: +/- 256MiB */
|
||||
if (tail) {
|
||||
tcg_out_opc_b(s, offset >> 2);
|
||||
} else {
|
||||
tcg_out_opc_bl(s, offset >> 2);
|
||||
}
|
||||
} else if (offset == sextreg(offset, 0, 38)) {
|
||||
/* long jump: +/- 256GiB */
|
||||
tcg_target_long lo = sextreg(offset, 0, 18);
|
||||
tcg_target_long hi = offset - lo;
|
||||
tcg_out_opc_pcaddu18i(s, TCG_REG_TMP0, hi >> 18);
|
||||
tcg_out_opc_jirl(s, link, TCG_REG_TMP0, lo >> 2);
|
||||
} else {
|
||||
/* far jump: 64-bit */
|
||||
tcg_target_long lo = sextreg((tcg_target_long)arg, 0, 18);
|
||||
tcg_target_long hi = (tcg_target_long)arg - lo;
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_TMP0, hi);
|
||||
tcg_out_opc_jirl(s, link, TCG_REG_TMP0, lo >> 2);
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Entry-points
|
||||
*/
|
||||
@ -882,6 +915,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
|
||||
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
|
||||
case INDEX_op_mov_i64:
|
||||
case INDEX_op_call: /* Always emitted via tcg_out_call. */
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user