Begin sharing code in the expansion of operations
for various TCG types.

Signed-off-by: Richard Henderson <[email protected]>
---
 include/tcg/tcg-op-common.h   | 13 +++++++--
 include/tcg/tcg-op-def.h.inc  | 29 ++++++++++++++++++
 include/tcg/tcg-op-def2.h.inc |  3 ++
 tcg/tcg-op.c                  | 55 ++++++++++++++++++++++++++---------
 4 files changed, 84 insertions(+), 16 deletions(-)
 create mode 100644 include/tcg/tcg-op-def.h.inc
 create mode 100644 include/tcg/tcg-op-def2.h.inc

diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1e826b62574..2f5276c8a2c 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -88,6 +88,17 @@ void tcg_gen_lookup_and_goto_ptr(void);
 void tcg_gen_plugin_cb(unsigned from);
 void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
 
+/*
+ * Construct operations from templates.
+ */
+
+#define DEF_RR(NAME) \
+    void glue(glue(tcg_gen_,NAME),TEXT)(TCGV a, TCGV b);
+
+#include "tcg-op-def.h.inc"
+
+#undef DEF_RR
+
 /* 32 bit ops */
 
 void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg);
@@ -172,7 +183,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
 void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
 
 void tcg_gen_discard_i32(TCGv_i32 arg);
-void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg);
 
 void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
 void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
@@ -294,7 +304,6 @@ void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 
arg2);
 void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
 
 void tcg_gen_discard_i64(TCGv_i64 arg);
-void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg);
 void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
 void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
 void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
new file mode 100644
index 00000000000..a24fb3d7372
--- /dev/null
+++ b/include/tcg/tcg-op-def.h.inc
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: MIT */
+
+#define TEXT    _i32
+#define TYPE    TCG_TYPE_I32
+#define TCGV    TCGv_i32
+#define TINT    int32_t
+#define TTMP    tcgv_i32_temp
+
+#include "tcg-op-def2.h.inc"
+
+#undef TEXT
+#undef TYPE
+#undef TCGV
+#undef TINT
+#undef TTMP
+
+#define TEXT    _i64
+#define TYPE    TCG_TYPE_I64
+#define TCGV    TCGv_i64
+#define TINT    int64_t
+#define TTMP    tcgv_i64_temp
+
+#include "tcg-op-def2.h.inc"
+
+#undef TEXT
+#undef TYPE
+#undef TCGV
+#undef TINT
+#undef TTMP
diff --git a/include/tcg/tcg-op-def2.h.inc b/include/tcg/tcg-op-def2.h.inc
new file mode 100644
index 00000000000..86777f54bad
--- /dev/null
+++ b/include/tcg/tcg-op-def2.h.inc
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: MIT */
+
+DEF_RR(mov)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index b738863ea69..eda87960380 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -104,6 +104,11 @@ TCGOp * NI tcg_gen_op6(TCGOpcode opc, TCGType type, TCGArg 
a1, TCGArg a2,
     return op;
 }
 
+static void gen_op_tt(TCGOpcode opc, TCGType type, TCGTemp *t0, TCGTemp *t1)
+{
+    tcg_gen_op2(opc, type, temp_arg(t0), temp_arg(t1));
+}
+
 /*
  * With CONFIG_DEBUG_TCG, tcgv_*_tmp via tcgv_*_arg, is an out-of-line
  * assertion check.  Force tail calls to avoid too much code expansion.
@@ -315,6 +320,42 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
     tcg_gen_op2(INDEX_op_plugin_mem_cb, 0, tcgv_i64_arg(addr), meminfo);
 }
 
+/*
+ * Forward declarations of generic expansions.
+ */
+
+#define DEF_RR(NAME) \
+    static void glue(gen_,NAME)(TCGType, TCGTemp *, TCGTemp *);
+
+#include "tcg/tcg-op-def2.h.inc"
+
+#undef DEF_RR
+
+/*
+ * Generic expansions for templated operations.
+ * We have used compiler type checks to ensure all operands
+ * are of the proper type.
+ */
+
+static void gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+    if (src != dst) {
+        gen_op_tt(INDEX_op_mov, type, dst, src);
+    }
+}
+
+/*
+ * Templated operations.
+ */
+
+#define DEF_RR(NAME)                                                    \
+    DNI void glue(glue(tcg_gen_,NAME),TEXT)(TCGV a, TCGV b)             \
+    { gen_##NAME(TYPE, TTMP(a), TTMP(b)); }
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef DEF_RR
+
 /* 32 bit ops */
 
 void tcg_gen_discard_i32(TCGv_i32 arg)
@@ -322,13 +363,6 @@ void tcg_gen_discard_i32(TCGv_i32 arg)
     tcg_gen_op1_i32(INDEX_op_discard, TCG_TYPE_I32, arg);
 }
 
-void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
-    if (ret != arg) {
-        tcg_gen_op2_i32(INDEX_op_mov, ret, arg);
-    }
-}
-
 void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
 {
     tcg_gen_mov_i32(ret, tcg_constant_i32(arg));
@@ -1396,13 +1430,6 @@ void tcg_gen_discard_i64(TCGv_i64 arg)
     tcg_gen_op1_i64(INDEX_op_discard, TCG_TYPE_I64, arg);
 }
 
-void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
-    if (ret != arg) {
-        tcg_gen_op2_i64(INDEX_op_mov, ret, arg);
-    }
-}
-
 void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
 {
     tcg_gen_mov_i64(ret, tcg_constant_i64(arg));
-- 
2.53.0


Reply via email to