[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 4/8] mips: Fill delay slots of J in jit_jmpi
From: |
Paul Cercueil |
Subject: |
[PATCH v2 4/8] mips: Fill delay slots of J in jit_jmpi |
Date: |
Mon, 9 Jan 2023 23:04:07 +0000 |
When we know that the last generated opcode is not the target of a jump,
we can swap it with the J opcode, so that it now becomes the delay slot
of the J opcode.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
lib/jit_mips-cpu.c | 37 +++++++++++++++++++++++++++++++------
lib/jit_mips.c | 6 +++---
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/lib/jit_mips-cpu.c b/lib/jit_mips-cpu.c
index 512ec7e..ec2745b 100644
--- a/lib/jit_mips-cpu.c
+++ b/lib/jit_mips-cpu.c
@@ -715,8 +715,8 @@ static jit_word_t
_bner(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
static jit_word_t _bnei(jit_state_t*,jit_word_t,jit_int32_t,jit_word_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) _jmpi(_jit,i0)
-static jit_word_t _jmpi(jit_state_t*,jit_word_t);
+# define jmpi(i0,no_flag) _jmpi(_jit,i0,no_flag)
+static jit_word_t _jmpi(jit_state_t*,jit_word_t,jit_bool_t);
# define boaddr(i0,r0,r1) _boaddr(_jit,i0,r0,r1)
static jit_word_t _boaddr(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
# define boaddi(i0,r0,i1) _boaddi(_jit,i0,r0,i1)
@@ -2558,20 +2558,45 @@ _jmpr(jit_state_t *_jit, jit_int32_t r0, jit_bool_t
no_flag)
}
static jit_word_t
-_jmpi(jit_state_t *_jit, jit_word_t i0)
+_jmpi(jit_state_t *_jit, jit_word_t i0, jit_bool_t no_flag)
{
jit_word_t w;
- jit_int32_t reg;
+ jit_int32_t reg, prev, offset;
+ jit_bool_t swap_ds;
+
+ offset = ((jit_word_t)_jit->pc.ui - (jit_word_t)_jit->code.ptr) /
sizeof(jit_int32_t);
+ swap_ds = no_flag
+ && (offset < 2 || !has_delay_slot((jit_instr_t)*(_jit->pc.ui - 2)));
w = _jit->pc.w;
if (((w + sizeof(jit_int32_t)) & 0xf0000000) == (i0 & 0xf0000000)) {
+
+ if (swap_ds) {
+ prev = *--_jit->pc.ui;
+ w -= sizeof(jit_int32_t);
+ }
+
J((i0 & ~0xf0000000) >> 2);
- NOP(1);
+ if (swap_ds)
+ ii(prev);
+ else
+ NOP(1);
}
else {
reg = jit_get_reg(jit_class_gpr|jit_class_nospill);
+
+ if (swap_ds) {
+ prev = *--_jit->pc.ui;
+ w -= sizeof(jit_int32_t);
+ }
+
movi_p(rn(reg), i0);
- jmpr(rn(reg), 0);
+ JR(rn(reg));
+ 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 fc303b2..cf917aa 100644
--- a/lib/jit_mips.c
+++ b/lib/jit_mips.c
@@ -1696,14 +1696,14 @@ _emit_code(jit_state_t *_jit)
assert(temp->code == jit_code_label ||
temp->code == jit_code_epilog);
if (temp->flag & jit_flag_patch)
- jmpi(temp->u.w);
+ jmpi(temp->u.w, no_flag);
else {
- word = jmpi(_jit->pc.w);
+ word = jmpi(_jit->pc.w, no_flag);
patch(word, node);
}
}
else
- jmpi(node->u.w);
+ jmpi(node->u.w, no_flag);
break;
case jit_code_callr:
callr(rn(node->u.w), no_flag);
--
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, 2023/01/09
- [PATCH v2 4/8] mips: Fill delay slots of J in jit_jmpi,
Paul Cercueil <=
- [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