qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] tci: Optimize saving of TCG code address


From: Stefan Weil
Subject: [Qemu-devel] [PATCH] tci: Optimize saving of TCG code address
Date: Tue, 29 Apr 2014 07:57:24 +0200

It is needed by the GETRA() macro which is called in helper functions,
so it is sufficient to set it before calling any of these helper functions.

In current QEMU, all targets use GETRA(). Therefore tci_tb_ptr is now
needed unconditionally. Setting its value is time critical because it
happens in the inner interpreter loop.

Signed-off-by: Stefan Weil <address@hidden>
---
 include/exec/exec-all.h |    6 +-----
 tci.c                   |   32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f9ac332..44b24bd 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -314,11 +314,7 @@ extern uintptr_t tci_tb_ptr;
    to indicate the compressed mode; subtracting two works around that.  It
    is also the case that there are no host isas that contain a call insn
    smaller than 4 bytes, so we don't worry about special-casing this.  */
-#if defined(CONFIG_TCG_INTERPRETER)
-# define GETPC_ADJ   0
-#else
-# define GETPC_ADJ   2
-#endif
+#define GETPC_ADJ   2
 
 #define GETPC()  (GETRA() - GETPC_ADJ)
 
diff --git a/tci.c b/tci.c
index 6523ab8..407dd3a 100644
--- a/tci.c
+++ b/tci.c
@@ -51,13 +51,18 @@ typedef uint64_t (*helper_function)(tcg_target_ulong, 
tcg_target_ulong,
                                     tcg_target_ulong);
 #endif
 
-/* Targets which don't use GETPC also don't need tci_tb_ptr
-   which makes them a little faster. */
-#if defined(GETPC)
+static tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS];
+
+/* The macro GETRA() which is called by many helper functions
+ * uses tci_tb_ptr to get the return address. */
 uintptr_t tci_tb_ptr;
-#endif
 
-static tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS];
+static inline void save_tb_ptr(void *tb_ptr)
+{
+#ifdef CONFIG_SOFTMMU
+    tci_tb_ptr = (uintptr_t)tb_ptr;
+#endif
+}
 
 static tcg_target_ulong tci_read_reg(TCGReg index)
 {
@@ -467,10 +472,6 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
         uint64_t v64;
 #endif
 
-#if defined(GETPC)
-        tci_tb_ptr = (uintptr_t)tb_ptr;
-#endif
-
         /* Skip opcode and size entry. */
         tb_ptr += 2;
 
@@ -489,6 +490,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             TODO();
             break;
         case INDEX_op_call:
+            tci_tb_ptr = (uintptr_t)tb_ptr;
             t0 = tci_read_ri(&tb_ptr);
 #if TCG_TARGET_REG_BITS == 32
             tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0),
@@ -1087,6 +1089,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             tb_ptr += (int32_t)t0;
             continue;
         case INDEX_op_qemu_ld8u:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1098,6 +1101,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             tci_write_reg8(t0, tmp8);
             break;
         case INDEX_op_qemu_ld8s:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1109,6 +1113,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             tci_write_reg8s(t0, tmp8);
             break;
         case INDEX_op_qemu_ld16u:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1120,6 +1125,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             tci_write_reg16(t0, tmp16);
             break;
         case INDEX_op_qemu_ld16s:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1132,6 +1138,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             break;
 #if TCG_TARGET_REG_BITS == 64
         case INDEX_op_qemu_ld32u:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1143,6 +1150,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             tci_write_reg32(t0, tmp32);
             break;
         case INDEX_op_qemu_ld32s:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1155,6 +1163,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             break;
 #endif /* TCG_TARGET_REG_BITS == 64 */
         case INDEX_op_qemu_ld32:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1166,6 +1175,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
             tci_write_reg32(t0, tmp32);
             break;
         case INDEX_op_qemu_ld64:
+            save_tb_ptr(tb_ptr);
             t0 = *tb_ptr++;
 #if TCG_TARGET_REG_BITS == 32
             t1 = *tb_ptr++;
@@ -1183,6 +1193,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 #endif
             break;
         case INDEX_op_qemu_st8:
+            save_tb_ptr(tb_ptr);
             t0 = tci_read_r8(&tb_ptr);
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1194,6 +1205,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 #endif
             break;
         case INDEX_op_qemu_st16:
+            save_tb_ptr(tb_ptr);
             t0 = tci_read_r16(&tb_ptr);
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1205,6 +1217,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 #endif
             break;
         case INDEX_op_qemu_st32:
+            save_tb_ptr(tb_ptr);
             t0 = tci_read_r32(&tb_ptr);
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1216,6 +1229,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 #endif
             break;
         case INDEX_op_qemu_st64:
+            save_tb_ptr(tb_ptr);
             tmp64 = tci_read_r64(&tb_ptr);
             taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
-- 
1.7.10.4




reply via email to

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