Patchwork [v3,07/20] tcg-arm: Fold epilogue into INDEX_op_exit_tb

login
register
mail settings
Submitter Richard Henderson
Date March 28, 2013, 3:32 p.m.
Message ID <1364484781-15561-8-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/232089/
State New
Headers show

Comments

Richard Henderson - March 28, 2013, 3:32 p.m.
The epilogue on ARM is one pop instruction, that pops the return
address into PC.  Avoid the jump to jump for this case.  Use the
standard movi32 routine for loading the return value if it's easy.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/arm/tcg-target.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Patch

diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
index 5333fad..88f5689 100644
--- a/tcg/arm/tcg-target.c
+++ b/tcg/arm/tcg-target.c
@@ -1559,7 +1559,7 @@  static inline void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int opc)
 #endif
 }
 
-static uint8_t *tb_ret_addr;
+static uint32_t tb_pop_ret;
 
 static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
                 const TCGArg *args, const int *const_args)
@@ -1569,17 +1569,15 @@  static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
 
     switch (opc) {
     case INDEX_op_exit_tb:
-        {
-            uint8_t *ld_ptr = s->code_ptr;
-            if (args[0] >> 8)
-                tcg_out_ld32_12(s, COND_AL, TCG_REG_R0, TCG_REG_PC, 0);
-            else
-                tcg_out_dat_imm(s, COND_AL, ARITH_MOV, TCG_REG_R0, 0, args[0]);
-            tcg_out_goto(s, COND_AL, (tcg_target_ulong) tb_ret_addr);
-            if (args[0] >> 8) {
-                *ld_ptr = (uint8_t) (s->code_ptr - ld_ptr) - 8;
-                tcg_out32(s, args[0]);
-            }
+        a0 = args[0];
+        if (use_armv7_instructions || check_fit_imm(a0)) {
+            tcg_out_movi32(s, COND_AL, TCG_REG_R0, args[0]);
+            tcg_out32(s, tb_pop_ret);
+        } else {
+            /* pc is always current address + 8, so 0 reads the word.  */
+            tcg_out_ld32_12(s, COND_AL, TCG_REG_R0, TCG_REG_PC, 0);
+            tcg_out32(s, tb_pop_ret);
+            tcg_out32(s, args[0]);
         }
         break;
     case INDEX_op_goto_tb:
@@ -2025,8 +2023,7 @@  static void tcg_target_qemu_prologue(TCGContext *s)
     tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
 
     tcg_out_bx(s, COND_AL, tcg_target_call_iarg_regs[1]);
-    tb_ret_addr = s->code_ptr;
 
     /* ldmia sp!, { r4 - r12, pc } */
-    tcg_out32(s, (COND_AL << 28) | 0x08bd9ff0);
+    tb_pop_ret = (COND_AL << 28) | 0x08bd9ff0;
 }