[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/8] mips: Fill delay slots of JALR opcodes in jit_callr
From: |
Paul Cercueil |
Subject: |
[PATCH v2 3/8] mips: Fill delay slots of JALR opcodes in jit_callr |
Date: |
Mon, 9 Jan 2023 23:04:06 +0000 |
Fill the delay slot of the generated JALR opcode, if it is not already
used to set the $t9 register.
When we know that the last generated opcode is not the target of a jump,
and that it does not write the register used by the JALR opcode, we can
swap it with the JALR opcode, so that it now becomes the delay slot of
the JALR opcode.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
lib/jit_mips-cpu.c | 31 +++++++++++++++++++++++--------
lib/jit_mips.c | 2 +-
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/lib/jit_mips-cpu.c b/lib/jit_mips-cpu.c
index cd21d90..512ec7e 100644
--- a/lib/jit_mips-cpu.c
+++ b/lib/jit_mips-cpu.c
@@ -757,8 +757,8 @@ static jit_word_t
_bmsi(jit_state_t*,jit_word_t,jit_int32_t,jit_word_t);
static jit_word_t _bmcr(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
# define bmci(i0,r0,i1) _bmci(_jit,i0,r0,i1)
static jit_word_t _bmci(jit_state_t*,jit_word_t,jit_int32_t,jit_word_t);
-# define callr(r0) _callr(_jit,r0)
-static void _callr(jit_state_t*,jit_int32_t);
+# define callr(r0,no_flag) _callr(_jit,r0,no_flag)
+static void _callr(jit_state_t*,jit_int32_t,jit_bool_t);
# define calli(i0) _calli(_jit,i0)
static void _calli(jit_state_t*,jit_word_t);
# define calli_p(i0) _calli_p(_jit,i0)
@@ -3079,13 +3079,28 @@ _bmci(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0,
jit_word_t i1)
}
static void
-_callr(jit_state_t *_jit, jit_int32_t r0)
+_callr(jit_state_t *_jit, jit_int32_t r0, jit_bool_t no_flag)
{
- JALR(r0);
- if (r0 != _T9_REGNO)
- movr(_T9_REGNO, r0);
- else
- NOP(1);
+ jit_int32_t prev, offset;
+
+ if (r0 != _T9_REGNO) {
+ JALR(r0);
+ movr(_T9_REGNO, r0);
+ } else {
+ offset = ((jit_word_t)_jit->pc.ui - (jit_word_t)_jit->code.ptr) /
sizeof(jit_int32_t);
+
+ if (no_flag
+ && (offset < 2 || !has_delay_slot((jit_instr_t)*(_jit->pc.ui - 2)))
+ && !op_writes_register((jit_instr_t)*(_jit->pc.ui - 1), r0)) {
+ prev = *--_jit->pc.ui;
+
+ JALR(r0);
+ ii(prev);
+ } else {
+ JALR(r0);
+ NOP(1);
+ }
+ }
}
static void
diff --git a/lib/jit_mips.c b/lib/jit_mips.c
index 6fba5ba..fc303b2 100644
--- a/lib/jit_mips.c
+++ b/lib/jit_mips.c
@@ -1706,7 +1706,7 @@ _emit_code(jit_state_t *_jit)
jmpi(node->u.w);
break;
case jit_code_callr:
- callr(rn(node->u.w));
+ callr(rn(node->u.w), no_flag);
break;
case jit_code_calli:
if (node->flag & jit_flag_node) {
--
2.39.0
- [PATCH v2 0/9] mips: Fill delay slots v2, Paul Cercueil, 2023/01/09
- [PATCH v2 1/8] mips: Optimize jit_eqr / jit_eqi, Paul Cercueil, 2023/01/09
- [PATCH v2 2/8] mips: Fill delay slots of JR opcodes in jit_jmpr, Paul Cercueil, 2023/01/09
- [PATCH v2 3/8] mips: Fill delay slots of JALR opcodes in jit_callr,
Paul Cercueil <=
- [PATCH v2 4/8] mips: Fill delay slots of J in jit_jmpi, Paul Cercueil, 2023/01/09
- [PATCH v2 5/8] mips: Fill delay slots in jit_beqr / jit_beqi, Paul Cercueil, 2023/01/09
- [PATCH v2 6/8] mips: Fill delay slots in jit_bner / jit_bnei, Paul Cercueil, 2023/01/09
- [PATCH v2 7/8] mips: Fill delay slots in jit_bgtr, jit_bgti, jit_bler, jit_blei, Paul Cercueil, 2023/01/09
- [PATCH v2 8/8] mips: Fill delay slots in jit_bger, jit_bgei, jit_bltr, jit_blti, Paul Cercueil, 2023/01/09
- Re: [PATCH v2 0/9] mips: Fill delay slots v2, Paulo César Pereira de Andrade, 2023/01/10