On 04/25/2017 09:53 AM, Emilio G. Cota wrote:
+    case INDEX_op_goto_ptr:
+        /* save target address into new register */
+        tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_EDX, a0);
+        /* set return value to 0 */
+        tgen_arithr(s, ARITH_XOR, TCG_REG_EAX, TCG_REG_EAX);
+        /* jmp to the target address (could be epilogue) */
+        tcg_out_modrm(s, OPC_GRP5, EXT5_JMPN_Ev, TCG_REG_EDX);
+        break;

I've just thought of an improvement to be made here -- move the xor after the jump (and therefore just before the "normal" epilogue) like so.


r~


diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c
index f6fb03e..f636557 100644
--- a/tcg/i386/tcg-target.inc.c
+++ b/tcg/i386/tcg-target.inc.c
@@ -1907,12 +1907,8 @@ static inline void tcg_out_op
         s->tb_jmp_reset_offset[a0] = tcg_current_code_size(s);
         break;
     case INDEX_op_goto_ptr:
-        /* save target address into new register */
-        tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_EDX, a0);
-        /* set return value to 0 */
-        tgen_arithr(s, ARITH_XOR, TCG_REG_EAX, TCG_REG_EAX);
-        /* jmp to the target address (could be epilogue) */
-        tcg_out_modrm(s, OPC_GRP5, EXT5_JMPN_Ev, TCG_REG_EDX);
+        /* jmp to the given host address (could be epilogue) */
+        tcg_out_modrm(s, OPC_GRP5, EXT5_JMPN_Ev, a0);
         break;
     case INDEX_op_br:
         tcg_out_jxx(s, JCC_JMP, arg_label(a0), 0);
@@ -2579,10 +2575,13 @@ static void tcg_target_qemu_prologue
     tcg_out_modrm(s, OPC_GRP5, EXT5_JMPN_Ev, tcg_target_call_iarg_regs[1]);
 #endif

-    /* TB epilogue */
-    tb_ret_addr = s->code_ptr;
+    /* Return path for goto_ptr.  Set return value to 0, a-la exit_tb,
+       and fall through to the rest of the epilogue.  */
     s->code_gen_epilogue = s->code_ptr;
+    tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_EAX, 0);

+    /* TB epilogue */
+    tb_ret_addr = s->code_ptr;
     tcg_out_addi(s, TCG_REG_CALL_STACK, stack_addend);

     for (i = ARRAY_SIZE(tcg_target_callee_save_regs) - 1; i >= 0; i--) {


Reply via email to