[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 4/8] mips: Fill delay slots of J in jit_jmpi
From: |
Paul Cercueil |
Subject: |
[PATCH v3 4/8] mips: Fill delay slots of J in jit_jmpi |
Date: |
Sat, 14 Jan 2023 15:10:52 +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 | 46 ++++++++++++++++++++++++++++++++++++----------
lib/jit_mips.c | 6 +++---
2 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/lib/jit_mips-cpu.c b/lib/jit_mips-cpu.c
index 028b806..d2852f2 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,prev) _jmpr(_jit,r0,prev)
static void _jmpr(jit_state_t*,jit_int32_t,jit_node_t*);
-# define jmpi(i0) _jmpi(_jit,i0)
-static jit_word_t _jmpi(jit_state_t*,jit_word_t);
+# define jmpi(i0,prev) _jmpi(_jit,i0,prev)
+static jit_word_t _jmpi(jit_state_t*,jit_word_t,jit_node_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)
@@ -2646,21 +2646,47 @@ _jmpr(jit_state_t *_jit, jit_int32_t r0, jit_node_t
*prev)
}
static jit_word_t
-_jmpi(jit_state_t *_jit, jit_word_t i0)
+_jmpi(jit_state_t *_jit, jit_word_t i0, jit_node_t *prev)
{
jit_word_t w;
- jit_int32_t reg;
+ jit_int32_t reg, op, offset;
+ jit_bool_t swap_ds;
+
+ swap_ds = can_swap_ds(prev, 0, 0);
w = _jit->pc.w;
if (((w + sizeof(jit_int32_t)) & 0xf0000000) == (i0 & 0xf0000000)) {
- J((i0 & ~0xf0000000) >> 2);
- NOP(1);
+ if (swap_ds) {
+ op = *--_jit->pc.ui;
+ w -= sizeof(jit_int32_t);
+ }
+
+ J((i0 & ~0xf0000000) >> 2);
+ if (swap_ds)
+ ii(op);
+ else
+ NOP(1);
}
else {
- reg = jit_get_reg(jit_class_gpr|jit_class_nospill);
- movi_p(rn(reg), i0);
- jmpr(rn(reg), NULL);
- jit_unget_reg(reg);
+ reg = get_reg_can_swap(swap_ds);
+ if (reg == JIT_NOREG) {
+ swap_ds = 0;
+ reg = jit_get_reg(jit_class_gpr|jit_class_nospill);
+ }
+
+ if (swap_ds)
+ op = *--_jit->pc.ui;
+
+ movi_p(rn(reg), i0);
+
+ w = _jit->pc.w;
+ JR(rn(reg));
+ if (swap_ds)
+ ii(op);
+ else
+ NOP(1);
+
+ jit_unget_reg(reg);
}
return (w);
diff --git a/lib/jit_mips.c b/lib/jit_mips.c
index a6afec9..6694b5a 100644
--- a/lib/jit_mips.c
+++ b/lib/jit_mips.c
@@ -1695,14 +1695,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, prev);
else {
- word = jmpi(_jit->pc.w);
+ word = jmpi(_jit->pc.w, prev);
patch(word, node);
}
}
else
- jmpi(node->u.w);
+ jmpi(node->u.w, prev);
break;
case jit_code_callr:
callr(rn(node->u.w), prev);
--
2.39.0
- [PATCH v2 0/9] mips: Fill delay slots v3, Paul Cercueil, 2023/01/14
- [PATCH v3 1/8] mips: Optimize jit_eqr / jit_eqi, Paul Cercueil, 2023/01/14
- [PATCH v3 2/8] mips: Fill delay slots of JR opcodes in jit_jmpr, Paul Cercueil, 2023/01/14
- [PATCH v3 3/8] mips: Fill delay slots of JALR opcodes in jit_callr, Paul Cercueil, 2023/01/14
- [PATCH v3 4/8] mips: Fill delay slots of J in jit_jmpi,
Paul Cercueil <=
- [PATCH v3 5/8] mips: Fill delay slots in jit_beqr / jit_beqi, Paul Cercueil, 2023/01/14
- [PATCH v3 6/8] mips: Fill delay slots in jit_bner / jit_bnei, Paul Cercueil, 2023/01/14
- [PATCH v3 7/8] mips: Fill delay slots in jit_bgtr, jit_bgti, jit_bler, jit_blei, Paul Cercueil, 2023/01/14
- [PATCH v3 8/8] mips: Fill delay slots in jit_bger, jit_bgei, jit_bltr, jit_blti, Paul Cercueil, 2023/01/14
- Re: [PATCH v2 0/9] mips: Fill delay slots v3, Paulo César Pereira de Andrade, 2023/01/14