Patchwork [6/8] tcg: Put target helper data into an array.

login
register
mail settings
Submitter Richard Henderson
Date Sept. 15, 2013, 12:03 a.m.
Message ID <1379203434-5680-7-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/274995/
State New
Headers show

Comments

Richard Henderson - Sept. 15, 2013, 12:03 a.m.
One call inside of a loop to tcg_register_helper instead of hundreds
of sequential calls.

Presumably more icache and branch prediction friendly; resulting binary
size mostly unchanged on x86_64, as we're trading 32-bit rip-relative
references in .text for full 64-bit pointers in .rodata.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 include/exec/def-helper.h |  3 +--
 tcg/tcg.c                 | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)

Patch

diff --git a/include/exec/def-helper.h b/include/exec/def-helper.h
index 022a9ce..73d51f9 100644
--- a/include/exec/def-helper.h
+++ b/include/exec/def-helper.h
@@ -240,8 +240,7 @@  static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \
 #elif GEN_HELPER == 2
 /* Register helpers.  */
 
-#define DEF_HELPER_FLAGS_0(name, flags, ret) \
-tcg_register_helper(HELPER(name), #name);
+#define DEF_HELPER_FLAGS_0(name, flags, ret)  { HELPER(name), #name },
 
 #define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \
 DEF_HELPER_FLAGS_0(name, flags, ret)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 59251c0..9ace8fc 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -256,9 +256,19 @@  void tcg_pool_reset(TCGContext *s)
 
 #include "helper.h"
 
+typedef struct TCGHelperInfo {
+    void *func;
+    const char *name;
+} TCGHelperInfo;
+
+static const TCGHelperInfo all_helpers[] = {
+#define GEN_HELPER 2
+#include "helper.h"
+};
+
 void tcg_context_init(TCGContext *s)
 {
-    int op, total_args, n;
+    int op, total_args, n, i;
     TCGOpDef *def;
     TCGArgConstraint *args_ct;
     int *sorted_args;
@@ -288,8 +298,9 @@  void tcg_context_init(TCGContext *s)
     }
 
     /* Register helpers.  */
-#define GEN_HELPER 2
-#include "helper.h"
+    for (i = 0; i < ARRAY_SIZE(all_helpers); ++i) {
+        tcg_register_helper(all_helpers[i].func, all_helpers[i].name);
+    }
 
     tcg_target_init(s);
 }