Signed-off-by: Richard Henderson <[email protected]>
---
include/tcg/tcg-op-common.h | 2 -
tcg/tcg-internal.h | 6 +++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 84 +++++++++++-------------------------
4 files changed, 31 insertions(+), 62 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 6b66f050cab..1af9f58df1e 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -211,7 +210,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 0da1a9c440c..76c8f026a64 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -114,6 +114,12 @@ static inline void tcg_gen_op_ttt(TCGOpcode opc, TCGType
type,
tcg_gen_op3(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2));
}
+static inline TCGOp *tcg_gen_op_ttii(TCGOpcode opc, TCGType type, TCGTemp *t0,
+ TCGTemp *t1, TCGArg a2, TCGArg a3)
+{
+ return tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), a2, a3);
+}
+
QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 2108082ce63..f7e7f4d2a1c 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -4,6 +4,7 @@
DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
DEF3(and, TCGV, TCGV, TCGV)
+DEF3(andi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 7832e99dccd..2baddbcfd38 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -382,6 +382,30 @@ void tcg_gen_and(TCGType type, TCGTemp *dst, TCGTemp
*src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_and, type, dst, src1, src2);
}
+void tcg_gen_andi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ if (src2 == 0) {
+ tcg_gen_movi(type, dst, 0);
+ } else if (src2 == -1) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ /*
+ * Canonicalize on extract, if valid. This aids x86 with its
+ * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
+ * which does not require matching operands. Other backends can
+ * trivially expand the extract to AND during code generation.
+ */
+ if (is_power_of_2(src2 + 1)) {
+ unsigned len = cto64(src2);
+ if (TCG_TARGET_extract_valid(type, 0, len)) {
+ tcg_gen_op_ttii(INDEX_op_extract, type, dst, src1, 0, len);
+ return;
+ }
+ }
+ tcg_gen_and(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -485,36 +509,6 @@ void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp
*src1, TCGTemp *src2)
/* 32 bit ops */
-void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- /* Some cases can be optimized here. */
- switch (arg2) {
- case 0:
- tcg_gen_movi_i32(ret, 0);
- return;
- case -1:
- tcg_gen_mov_i32(ret, arg1);
- return;
- default:
- /*
- * Canonicalize on extract, if valid. This aids x86 with its
- * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
- * which does not require matching operands. Other backends can
- * trivially expand the extract to AND during code generation.
- */
- if (!(arg2 & (arg2 + 1))) {
- unsigned len = ctz32(~arg2);
- if (TCG_TARGET_extract_valid(TCG_TYPE_I32, 0, len)) {
- tcg_gen_extract_i32(ret, arg1, 0, len);
- return;
- }
- }
- break;
- }
-
- tcg_gen_and_i32(ret, arg1, tcg_constant_i32(arg2));
-}
-
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* Some cases can be optimized here. */
@@ -1493,36 +1487,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- /* Some cases can be optimized here. */
- switch (arg2) {
- case 0:
- tcg_gen_movi_i64(ret, 0);
- return;
- case -1:
- tcg_gen_mov_i64(ret, arg1);
- return;
- default:
- /*
- * Canonicalize on extract, if valid. This aids x86 with its
- * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
- * which does not require matching operands. Other backends can
- * trivially expand the extract to AND during code generation.
- */
- if (!(arg2 & (arg2 + 1))) {
- unsigned len = ctz64(~arg2);
- if (TCG_TARGET_extract_valid(TCG_TYPE_I64, 0, len)) {
- tcg_gen_extract_i64(ret, arg1, 0, len);
- return;
- }
- }
- break;
- }
-
- tcg_gen_and_i64(ret, arg1, tcg_constant_i64(arg2));
-}
-
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
/* Some cases can be optimized here. */
--
2.53.0