lightning
[Top][All Lists]
Advanced

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

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


From: Paul Cercueil
Subject: [PATCH 3/8] mips: Fill delay slots of JALR opcodes in jit_callr
Date: Sat, 7 Jan 2023 20:35:45 +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 5fd3007..357fa5e 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)
@@ -3058,13 +3058,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 847bf15..3447a66 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




reply via email to

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