[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/8] mips: Fill delay slots in jit_bner / jit_bnei
From: |
Paul Cercueil |
Subject: |
[PATCH 6/8] mips: Fill delay slots in jit_bner / jit_bnei |
Date: |
Sat, 7 Jan 2023 20:35:48 +0000 |
When we know that the last generated opcode is not the target of a jump,
and that it does not write to the source registers of the BNE opcode, we
can swap it with the BNE opcode, so that it now becomes the delay slot
of the BNE opcode.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
lib/jit_mips-cpu.c | 52 +++++++++++++++++++++++++++++++++++-----------
lib/jit_mips.c | 4 ++--
2 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/lib/jit_mips-cpu.c b/lib/jit_mips-cpu.c
index a162d93..748db89 100644
--- a/lib/jit_mips-cpu.c
+++ b/lib/jit_mips-cpu.c
@@ -709,10 +709,10 @@ static jit_word_t
_bgtr_u(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
static jit_word_t _bgti(jit_state_t*,jit_word_t,jit_int32_t,jit_word_t);
#define bgti_u(i0,r0,i1) _bgti_u(_jit,i0,r0,i1)
static jit_word_t _bgti_u(jit_state_t*,jit_word_t,jit_int32_t,jit_word_t);
-#define bner(i0,r0,r1) _bner(_jit,i0,r0,r1)
-static jit_word_t _bner(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
-#define bnei(i0,r0,i1) _bnei(_jit,i0,r0,i1)
-static jit_word_t _bnei(jit_state_t*,jit_word_t,jit_int32_t,jit_word_t);
+#define bner(i0,r0,r1,no_flag) _bner(_jit,i0,r0,r1,no_flag)
+static jit_word_t
_bner(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t,jit_bool_t);
+#define bnei(i0,r0,i1,no_flag) _bnei(_jit,i0,r0,i1,no_flag)
+static jit_word_t
_bnei(jit_state_t*,jit_word_t,jit_int32_t,jit_word_t,jit_bool_t);
# define jmpr(r0,no_flag) _jmpr(_jit,r0,no_flag)
static void _jmpr(jit_state_t*,jit_int32_t,jit_bool_t);
# define jmpi(i0,no_flag) _jmpi(_jit,i0,no_flag)
@@ -2512,32 +2512,60 @@ _bgti_u(jit_state_t *_jit, jit_word_t i0, jit_int32_t
r0, jit_word_t i1)
}
static jit_word_t
-_bner(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
+_bner(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1,
jit_bool_t no_flag)
{
jit_word_t w;
+ jit_int32_t prev, offset;
+ jit_bool_t swap_ds;
+
+ offset = ((jit_word_t)_jit->pc.ui - (jit_word_t)_jit->code.ptr) /
sizeof(jit_instr_t);
+ swap_ds = 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)
+ && !op_writes_register((jit_instr_t)*(_jit->pc.ui - 1), r1);
+
+ if (swap_ds)
+ prev = *--_jit->pc.ui;
w = _jit->pc.w;
BNE(r0, r1, ((i0 - w) >> 2) - 1);
- NOP(1);
+ if (swap_ds)
+ ii(prev);
+ else
+ NOP(1);
return (w);
}
static jit_word_t
-_bnei(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_word_t i1)
+_bnei(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_word_t i1,
jit_bool_t no_flag)
{
jit_word_t w;
- jit_int32_t reg;
+ jit_int32_t reg, prev, offset;
+ jit_bool_t swap_ds;
if (i1 == 0) {
- w = _jit->pc.w;
- BNE(r0, _ZERO_REGNO, ((i0 - w) >> 2) - 1);
- NOP(1);
+ w = bner(i0, r0, _ZERO_REGNO, no_flag);
}
else {
+ offset = ((jit_word_t)_jit->pc.ui - (jit_word_t)_jit->code.ptr) /
sizeof(jit_instr_t);
+ swap_ds = 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);
+
reg = jit_get_reg(jit_class_gpr|jit_class_nospill);
+
+ if (swap_ds)
+ prev = *--_jit->pc.ui;
+
movi(rn(reg), i1);
- w = bner(i0, r0, rn(reg));
+ w = _jit->pc.w;
+ BNE(r0, rn(reg), ((i0 - w) >> 2) - 1);
+ if (swap_ds)
+ ii(prev);
+ else
+ NOP(1);
+
jit_unget_reg(reg);
}
diff --git a/lib/jit_mips.c b/lib/jit_mips.c
index c3898aa..7683aeb 100644
--- a/lib/jit_mips.c
+++ b/lib/jit_mips.c
@@ -1529,8 +1529,8 @@ _emit_code(jit_state_t *_jit)
case_brw(bgt,);
case_brr(bgt, _u);
case_brw(bgt, _u);
- case_brr(bne,);
- case_brw(bne,);
+ case_brrn(bne,, no_flag);
+ case_brwn(bne,, no_flag);
case_brr(boadd,);
case_brw(boadd,);
case_brr(boadd, _u);
--
2.39.0
- [PATCH 0/8] mips: Fill delay slots, Paul Cercueil, 2023/01/07
- [PATCH 1/8] mips: Optimize jit_eqr / jit_eqi, Paul Cercueil, 2023/01/07
- [PATCH 2/8] mips: Fill delay slots of JR opcodes in jit_jmpr, Paul Cercueil, 2023/01/07
- [PATCH 3/8] mips: Fill delay slots of JALR opcodes in jit_callr, Paul Cercueil, 2023/01/07
- [PATCH 4/8] mips: Fill delay slots of J in jit_jmpi, Paul Cercueil, 2023/01/07
- [PATCH 5/8] mips: Fill delay slots in jit_beqr / jit_beqi, Paul Cercueil, 2023/01/07
- [PATCH 6/8] mips: Fill delay slots in jit_bner / jit_bnei,
Paul Cercueil <=
- [PATCH 7/8] mips: Fill delay slots in jit_bgtr, jit_bgti, jit_bler, jit_blei, Paul Cercueil, 2023/01/07
- [PATCH 8/8] mips: Fill delay slots in jit_bger, jit_bgei, jit_bltr, jit_blti, Paul Cercueil, 2023/01/07