Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ppc64le] Performance improvements while branching during function calls #90656

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/mono/mono/mini/mini-ppc.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ gboolean
mono_ppc_is_direct_call_sequence (guint32 *code)
{
#ifdef TARGET_POWERPC64
g_assert(*code == 0x4e800021 || *code == 0x4e800020 || *code == 0x4e800420);
g_assert(*code == 0x4e800021 || *code == 0x4e800020 || *code == 0x4e800421 || *code == 0x4e800420);

/* the thunk-less direct call sequence: lis/ori/sldi/oris/ori/mtlr/blrl */
if (ppc_opcode (code [-1]) == 31) { /* mtlr */
Expand Down Expand Up @@ -2939,7 +2939,7 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i
return;
}

if (prim == 15 || ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800420) {
if (prim == 15 || ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800421 || ins == 0x4e800420) {
#ifdef TARGET_POWERPC64
#if !defined(PPC_USES_FUNCTION_DESCRIPTOR)
handle_thunk (cfg, code, target);
Expand All @@ -2948,7 +2948,7 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i
guint32 *branch_ins;

/* the trampoline code will try to patch the blrl, blr, bcctr */
if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800420) {
if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800421 || ins == 0x4e800420) {
branch_ins = seq;
if (ppc_is_load_op (seq [-3]) || ppc_opcode (seq [-3]) == 31) /* ld || lwz || mr */
code -= 32;
Expand Down Expand Up @@ -2996,15 +2996,15 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i
#else
guint32 *seq;
/* the trampoline code will try to patch the blrl, blr, bcctr */
if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800420) {
if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800421 || ins == 0x4e800420) {
code -= 12;
}
/* this is the lis/ori/mtlr/blrl sequence */
seq = (guint32*)code;
g_assert ((seq [0] >> 26) == 15);
g_assert ((seq [1] >> 26) == 24);
g_assert ((seq [2] >> 26) == 31);
g_assert (seq [3] == 0x4e800021 || seq [3] == 0x4e800020 || seq [3] == 0x4e800420);
g_assert (seq [3] == 0x4e800021 || seq [3] == 0x4e800020 || seq [3] == 0x4e800421 || seq [3] == 0x4e800420);
/* FIXME: make this thread safe */
ppc_lis (code, PPC_CALL_REG, (guint32)(target) >> 16);
ppc_ori (code, PPC_CALL_REG, PPC_CALL_REG, (guint32)(target) & 0xffff);
Expand Down Expand Up @@ -3426,8 +3426,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
cfg->thunk_area += THUNK_SIZE;
#endif
ppc_mtlr (code, PPC_CALL_REG);
ppc_blrl (code);
ppc_mtctr (code, PPC_CALL_REG);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
} else {
ppc_bl (code, 0);
}
Expand Down Expand Up @@ -3913,8 +3913,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
cfg->thunk_area += THUNK_SIZE;
#endif
ppc_mtlr (code, PPC_CALL_REG);
ppc_blrl (code);
ppc_mtctr (code, PPC_CALL_REG);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
} else {
ppc_bl (code, 0);
}
Expand Down Expand Up @@ -3945,9 +3945,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
}
}
#endif
ppc_mtlr (code, ins->sreg1);
ppc_mtctr (code, ins->sreg1);
#endif
ppc_blrl (code);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
/* FIXME: this should be handled somewhere else in the new jit */
code = emit_move_return_value (cfg, ins, code);
break;
Expand All @@ -3965,8 +3965,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
} else {
ppc_ldptr (code, ppc_r12, ins->inst_offset, ins->sreg1);
}
ppc_mtlr (code, ppc_r12);
ppc_blrl (code);
ppc_mtctr (code, ppc_r12);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
/* FIXME: this should be handled somewhere else in the new jit */
code = emit_move_return_value (cfg, ins, code);
break;
Expand Down Expand Up @@ -4022,8 +4022,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
cfg->thunk_area += THUNK_SIZE;
#endif
ppc_mtlr (code, PPC_CALL_REG);
ppc_blrl (code);
ppc_mtctr (code, PPC_CALL_REG);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
} else {
ppc_bl (code, 0);
}
Expand All @@ -4040,8 +4040,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
cfg->thunk_area += THUNK_SIZE;
#endif
ppc_mtlr (code, PPC_CALL_REG);
ppc_blrl (code);
ppc_mtctr (code, PPC_CALL_REG);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
} else {
ppc_bl (code, 0);
}
Expand Down Expand Up @@ -4725,8 +4725,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
cfg->thunk_area += THUNK_SIZE;
#endif
ppc_mtlr (code, PPC_CALL_REG);
ppc_blrl (code);
ppc_mtctr (code, PPC_CALL_REG);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
} else {
ppc_bl (code, 0);
}
Expand Down Expand Up @@ -5348,8 +5348,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG);
cfg->thunk_area += THUNK_SIZE;
#endif
ppc_mtlr (code, PPC_CALL_REG);
ppc_blrl (code);
ppc_mtctr (code, PPC_CALL_REG);
ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
} else {
ppc_bl (code, 0);
}
Expand Down
Loading