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 | 29 +++++++++++-
include/tcg/tcg-op-def.h.inc | 3 ++
tcg/tcg-op.c | 91 ++++++++++++++++++++++++++++++------
3 files changed, 107 insertions(+), 16 deletions(-)
create mode 100644 include/tcg/tcg-op-def.h.inc
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1e826b62574..8a42ff1f456 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -88,6 +88,33 @@ 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 DEF2(NAME, T1, T2) \
+ void glue(glue(tcg_gen_,NAME),TEXT)(T1, T2);
+
+#define TCGV glue(TCGv,TEXT)
+#define TEXT _i32
+#define TINT int32_t
+
+#include "tcg-op-def.h.inc"
+
+#undef TEXT
+#undef TINT
+
+#define TEXT _i64
+#define TINT int64_t
+
+#include "tcg-op-def.h.inc"
+
+#undef TEXT
+#undef TINT
+#undef TCGV
+
+#undef DEF2
+
/* 32 bit ops */
void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg);
@@ -172,7 +199,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 +320,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..ebfaf0b8188
--- /dev/null
+++ b/include/tcg/tcg-op-def.h.inc
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: MIT */
+
+DEF2(mov, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index b738863ea69..511b34b143c 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,78 @@ 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 DEF2(NAME, T1, T2) \
+ static void glue(gen_,NAME)(TCGType, T1, T2);
+
+#define TCGV TCGTemp *
+#define TINT int64_t
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef TINT
+#undef TCGV
+
+#undef DEF2
+
+/*
+ * Templated operations.
+ */
+
+#define DEF2(NAME, T1, T2) \
+ void glue(glue(tcg_gen_,NAME),TEXT)(T1 a, T2 b) \
+ { gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b)); }
+
+#define C_TCGv_i32 tcgv_i32_temp
+#define C_TCGv_i64 tcgv_i64_temp
+#define C_int32_t
+#define C_int64_t
+
+#define TCGV glue(TCGv,TEXT)
+#define TEXT _i32
+#define TINT int32_t
+#define TYPE TCG_TYPE_I32
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef TEXT
+#undef TINT
+#undef TYPE
+
+#define TEXT _i64
+#define TINT int64_t
+#define TYPE TCG_TYPE_I64
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef TEXT
+#undef TINT
+#undef TCGV
+#undef TYPE
+
+#undef C_TCGv_i32
+#undef C_TCGv_i64
+#undef C_int32_t
+#undef C_int64_t
+
+#undef DEF2
+
+/*
+ * Generic expansions for templated operations.
+ * We have used compiler type checks to ensure all TCGTemp
+ * 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);
+ }
+}
+
/* 32 bit ops */
void tcg_gen_discard_i32(TCGv_i32 arg)
@@ -322,13 +399,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 +1466,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