lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 3/8] mips: Fill delay slots of JALR opcodes in jit_callr


From: Paul Cercueil
Subject: [PATCH v3 3/8] mips: Fill delay slots of JALR opcodes in jit_callr
Date: Sat, 14 Jan 2023 15:10:51 +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 | 28 ++++++++++++++++++++--------
 lib/jit_mips.c     |  2 +-
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/lib/jit_mips-cpu.c b/lib/jit_mips-cpu.c
index 033315e..028b806 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,prev)               _callr(_jit,r0,prev)
+static void _callr(jit_state_t*,jit_int32_t,jit_node_t*);
 #  define calli(i0)                    _calli(_jit,i0)
 static void _calli(jit_state_t*,jit_word_t);
 #  define calli_p(i0)                  _calli_p(_jit,i0)
@@ -3167,13 +3167,25 @@ _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_node_t *prev)
 {
-    JALR(r0);
-    if (r0 != _T9_REGNO)
-       movr(_T9_REGNO, r0);
-    else
-       NOP(1);
+    jit_bool_t         swap_ds;
+    jit_int32_t                op;
+
+    if (r0 != _T9_REGNO) {
+        JALR(r0);
+        movr(_T9_REGNO, r0);
+    } else {
+        swap_ds = can_swap_ds(prev, r0, 0);
+        if (swap_ds)
+            op = *--_jit->pc.ui;
+
+        JALR(r0);
+        if (swap_ds)
+            ii(op);
+        else
+            NOP(1);
+    }
 }
 
 static void
diff --git a/lib/jit_mips.c b/lib/jit_mips.c
index 24e2d86..a6afec9 100644
--- a/lib/jit_mips.c
+++ b/lib/jit_mips.c
@@ -1705,7 +1705,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), prev);
                break;
            case jit_code_calli:
                if (node->flag & jit_flag_node) {
-- 
2.39.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]