Skip to contentSkip to conversation

TCG compile fixes and optimize cleanup

PATCH Applied Richard Henderson 5 participants 16 messages Aug 17, 2011 – Aug 23, 2011

lore
Share & tools
lore
#0 lore raw

cover TCG compile fixes and optimize cleanup

As discussed elsewhere, one way to tidy up tcg/optimize.c is to always provide the enum names, even if the host does not support the operation.

As a sanity check, I wanted to include a test to make sure that we never tried to output an opcode that the target does not handle. I did this via a bit in the TCGOpDef flags. In order to get that set, I changed all of the TCG_TARGET_HAS* macros to be true/false rather than def/undef.

That allowed a further cleanup to change ifdefs into C IFs.

Unfortunately, it wasn't really possible to split this into smaller pieces. Using the C IFs requires the enums be present, even if unused.

I cross-compiled --target-list=i386-softmmu,i386-linux-user for each of the tcg hosts. In the process I discovered a number of pure compilation errors.

r~

Richard Henderson (6):
tcg: Add and use TCG_OPF_64BIT.
tcg: Always define all of the TCGOpcode enum members.
tcg: Constant fold neg, andc, orc, eqv, nand, nor.
tcg-hppa: Fix CPU_TEMP_BUF_NLONGS oversight.
tcg-ia64: Fix typos in AREG0 setup in prologue.
tcg-arm: Make tcg_out_addi inline

 tcg/arm/tcg-target.c   |    2 +-
 tcg/arm/tcg-target.h   |   30 +-
 tcg/hppa/tcg-target.c  |    2 +-
 tcg/hppa/tcg-target.h  |   29 +-
 tcg/i386/tcg-target.h  |   68 ++--
 tcg/ia64/tcg-target.c  |    4 +-
 tcg/ia64/tcg-target.h  |   66 ++--
 tcg/mips/tcg-target.h  |   31 +-
 tcg/optimize.c         |  260 +++-----------
 tcg/ppc/tcg-target.h   |   31 +-
 tcg/ppc64/tcg-target.h |   68 ++--
 tcg/s390/tcg-target.h  |   68 ++--
 tcg/sparc/tcg-target.h |   68 ++--
 tcg/tcg-op.h           |  946 +++++++++++++++++++++++-------------------------
 tcg/tcg-opc.h          |  242 +++++--------
 tcg/tcg.c              |    6 +-
 tcg/tcg.h              |   59 +++-
 17 files changed, 886 insertions(+), 1094 deletions(-)
Signature · 1 line
1.7.4.4
#1 lore raw

PATCH 1/6 tcg: Add and use TCG_OPF_64BIT.

This allows the simplification of the op_bits function from tcg/optimize.c.

---
 tcg/optimize.c |   77 ++------------------------------------------
 tcg/tcg-opc.h  |   98 ++++++++++++++++++++++++++++----------------------------
 tcg/tcg.c      |    2 +-
 tcg/tcg.h      |   21 ++++++++----
 4 files changed, 67 insertions(+), 131 deletions(-)
tcg/optimize.c +3 -74
index 7eb5eb1..98c7e3f 100644
@@ -92,81 +92,10 @@ static void reset_temp(TCGArg temp, int nb_temps, int nb_globals)
     }
 }
 
-static int op_bits(int op)
+static int op_bits(enum TCGOpcode op)
 {
-    switch (op) {
-    case INDEX_op_mov_i32:
-    case INDEX_op_add_i32:
-    case INDEX_op_sub_i32:
-    case INDEX_op_mul_i32:
-    case INDEX_op_and_i32:
-    case INDEX_op_or_i32:
-    case INDEX_op_xor_i32:
-    case INDEX_op_shl_i32:
-    case INDEX_op_shr_i32:
-    case INDEX_op_sar_i32:
-#ifdef TCG_TARGET_HAS_rot_i32
-    case INDEX_op_rotl_i32:
-    case INDEX_op_rotr_i32:
-#endif
-#ifdef TCG_TARGET_HAS_not_i32
-    case INDEX_op_not_i32:
-#endif
-#ifdef TCG_TARGET_HAS_ext8s_i32
-    case INDEX_op_ext8s_i32:
-#endif
-#ifdef TCG_TARGET_HAS_ext16s_i32
-    case INDEX_op_ext16s_i32:
-#endif
-#ifdef TCG_TARGET_HAS_ext8u_i32
-    case INDEX_op_ext8u_i32:
-#endif
-#ifdef TCG_TARGET_HAS_ext16u_i32
-    case INDEX_op_ext16u_i32:
-#endif
-        return 32;
-#if TCG_TARGET_REG_BITS == 64
-    case INDEX_op_mov_i64:
-    case INDEX_op_add_i64:
-    case INDEX_op_sub_i64:
-    case INDEX_op_mul_i64:
-    case INDEX_op_and_i64:
-    case INDEX_op_or_i64:
-    case INDEX_op_xor_i64:
-    case INDEX_op_shl_i64:
-    case INDEX_op_shr_i64:
-    case INDEX_op_sar_i64:
-#ifdef TCG_TARGET_HAS_rot_i64
-    case INDEX_op_rotl_i64:
-    case INDEX_op_rotr_i64:
-#endif
-#ifdef TCG_TARGET_HAS_not_i64
-    case INDEX_op_not_i64:
-#endif
-#ifdef TCG_TARGET_HAS_ext8s_i64
-    case INDEX_op_ext8s_i64:
-#endif
-#ifdef TCG_TARGET_HAS_ext16s_i64
-    case INDEX_op_ext16s_i64:
-#endif
-#ifdef TCG_TARGET_HAS_ext32s_i64
-    case INDEX_op_ext32s_i64:
-#endif
-#ifdef TCG_TARGET_HAS_ext8u_i64
-    case INDEX_op_ext8u_i64:
-#endif
-#ifdef TCG_TARGET_HAS_ext16u_i64
-    case INDEX_op_ext16u_i64:
-#endif
-#ifdef TCG_TARGET_HAS_ext32u_i64
-    case INDEX_op_ext32u_i64:
-#endif
-        return 64;
-#endif
-    default:
-        fprintf(stderr, "Unrecognized operation %d in op_bits.\n", op);
-        tcg_abort();
-    }
+    const TCGOpDef *def = &tcg_op_defs[op];
+    return def->flags & TCG_OPF_64BIT ? 64 : 32;
 }
 
 static int op_to_movi(int op)
tcg/tcg-opc.h +49 -49

147 lines not on this page · raw message

tcg/tcg.c +1 -1
index 92f1989..7179bd4 100644
@@ -68,7 +68,7 @@ static void tcg_target_qemu_prologue(TCGContext *s);
 static void patch_reloc(uint8_t *code_ptr, int type, 
                         tcg_target_long value, tcg_target_long addend);
 
-static TCGOpDef tcg_op_defs[] = {
+TCGOpDef tcg_op_defs[] = {
 #define DEF(s, oargs, iargs, cargs, flags) { #s, oargs, iargs, cargs, iargs + oargs + cargs, flags },
 #include "tcg-opc.h"
 #undef DEF
tcg/tcg.h +14 -7
index e2a7095..6a4f6e4 100644
@@ -445,13 +445,18 @@ typedef struct TCGArgConstraint {
 
 #define TCG_MAX_OP_ARGS 16
 
-#define TCG_OPF_BB_END     0x01 /* instruction defines the end of a basic
-                                   block */
-#define TCG_OPF_CALL_CLOBBER 0x02 /* instruction clobbers call registers 
-                                   and potentially update globals. */
-#define TCG_OPF_SIDE_EFFECTS 0x04 /* instruction has side effects : it
-                                     cannot be removed if its output
-                                     are not used */
+/* Bits for TCGOpDef->flags, 8 bits available.  */
+enum {
+    /* Instruction defines the end of a basic block.  */
+    TCG_OPF_BB_END       = 0x01,
+    /* Instruction clobbers call registers and potentially update globals.  */
+    TCG_OPF_CALL_CLOBBER = 0x02,
+    /* Instruction has side effects: it cannot be removed
+       if its outputs are not used.  */
+    TCG_OPF_SIDE_EFFECTS = 0x04,
+    /* Instruction operands are 64-bits (otherwise 32-bits).  */
+    TCG_OPF_64BIT        = 0x08,
+};
 
 typedef struct TCGOpDef {
     const char *name;
@@ -463,6 +468,8 @@ typedef struct TCGOpDef {
     int used;
 #endif
 } TCGOpDef;
+
+extern TCGOpDef tcg_op_defs[];
         
 typedef struct TCGTargetOpDef {
     TCGOpcode op;
Signature · 1 line
1.7.4.4
#2 lore raw

PATCH 2/6 tcg: Always define all of the TCGOpcode enum members.

In reply to Richard Henderson

By always defining these symbols, we can eliminate a lot of ifdefs.

To allow this to be checked reliably, the semantics of the TCG_TARGET_HAS_* macros must be changed from def/undef to true/false. This allows even more ifdefs to be removed, converting them into C if statements.

---
 tcg/arm/tcg-target.h   |   30 +-
 tcg/hppa/tcg-target.h  |   29 +-
 tcg/i386/tcg-target.h  |   68 ++--
 tcg/ia64/tcg-target.h  |   66 ++--
 tcg/mips/tcg-target.h  |   31 +-
 tcg/optimize.c         |  156 ++-------
 tcg/ppc/tcg-target.h   |   31 +-
 tcg/ppc64/tcg-target.h |   68 ++--
 tcg/s390/tcg-target.h  |   68 ++--
 tcg/sparc/tcg-target.h |   68 ++--
 tcg/tcg-op.h           |  946 +++++++++++++++++++++++-------------------------
 tcg/tcg-opc.h          |  242 +++++--------
 tcg/tcg.c              |    4 +
 tcg/tcg.h              |   38 ++
 14 files changed, 837 insertions(+), 1008 deletions(-)
tcg/arm/tcg-target.h +16 -14
index d8d7d94..0e0f69a 100644
@@ -58,20 +58,22 @@ enum {
 #define TCG_TARGET_CALL_STACK_OFFSET	0
 
 /* optional instructions */
-#define TCG_TARGET_HAS_ext8s_i32
-#define TCG_TARGET_HAS_ext16s_i32
-#undef TCG_TARGET_HAS_ext8u_i32       /* and r0, r1, #0xff */
-#define TCG_TARGET_HAS_ext16u_i32
-#define TCG_TARGET_HAS_bswap16_i32
-#define TCG_TARGET_HAS_bswap32_i32
-#define TCG_TARGET_HAS_not_i32
-#define TCG_TARGET_HAS_neg_i32
-#define TCG_TARGET_HAS_rot_i32
-#define TCG_TARGET_HAS_andc_i32
-// #define TCG_TARGET_HAS_orc_i32
-// #define TCG_TARGET_HAS_eqv_i32
-// #define TCG_TARGET_HAS_nand_i32
-// #define TCG_TARGET_HAS_nor_i32
+#define TCG_TARGET_HAS_div_i32          0
+#define TCG_TARGET_HAS_ext8s_i32        1
+#define TCG_TARGET_HAS_ext16s_i32       1
+#define TCG_TARGET_HAS_ext8u_i32        0 /* and r0, r1, #0xff */
+#define TCG_TARGET_HAS_ext16u_i32       1
+#define TCG_TARGET_HAS_bswap16_i32      1
+#define TCG_TARGET_HAS_bswap32_i32      1
+#define TCG_TARGET_HAS_not_i32          1
+#define TCG_TARGET_HAS_neg_i32          1
+#define TCG_TARGET_HAS_rot_i32          1
+#define TCG_TARGET_HAS_andc_i32         1
+#define TCG_TARGET_HAS_orc_i32          0
+#define TCG_TARGET_HAS_eqv_i32          0
+#define TCG_TARGET_HAS_nand_i32         0
+#define TCG_TARGET_HAS_nor_i32          0
+#define TCG_TARGET_HAS_deposit_i32      0
 
 #define TCG_TARGET_HAS_GUEST_BASE
 
tcg/hppa/tcg-target.h +16 -13
index f7919ce..ed90efc 100644
@@ -85,21 +85,24 @@ enum {
 #define TCG_TARGET_STACK_GROWSUP
 
 /* optional instructions */
-// #define TCG_TARGET_HAS_div_i32
-#define TCG_TARGET_HAS_rot_i32
-#define TCG_TARGET_HAS_ext8s_i32
-#define TCG_TARGET_HAS_ext16s_i32
-#define TCG_TARGET_HAS_bswap16_i32
-#define TCG_TARGET_HAS_bswap32_i32
-#define TCG_TARGET_HAS_not_i32
-#define TCG_TARGET_HAS_andc_i32
-// #define TCG_TARGET_HAS_orc_i32
-#define TCG_TARGET_HAS_deposit_i32
+#define TCG_TARGET_HAS_div_i32          0
+#define TCG_TARGET_HAS_rot_i32          1
+#define TCG_TARGET_HAS_ext8s_i32        1
+#define TCG_TARGET_HAS_ext16s_i32       1
+#define TCG_TARGET_HAS_bswap16_i32      1
+#define TCG_TARGET_HAS_bswap32_i32      1
+#define TCG_TARGET_HAS_not_i32          1
+#define TCG_TARGET_HAS_andc_i32         1
+#define TCG_TARGET_HAS_orc_i32          0
+#define TCG_TARGET_HAS_eqv_i32          0
+#define TCG_TARGET_HAS_nand_i32         0
+#define TCG_TARGET_HAS_nor_i32          0
+#define TCG_TARGET_HAS_deposit_i32      1
 
 /* optional instructions automatically implemented */
-#undef TCG_TARGET_HAS_neg_i32           /* sub rd, 0, rs */
-#undef TCG_TARGET_HAS_ext8u_i32         /* and rd, rs, 0xff */
-#undef TCG_TARGET_HAS_ext16u_i32        /* and rd, rs, 0xffff */
+#define TCG_TARGET_HAS_neg_i32          0 /* sub rd, 0, rs */
+#define TCG_TARGET_HAS_ext8u_i32        0 /* and rd, rs, 0xff */
+#define TCG_TARGET_HAS_ext16u_i32       0 /* and rd, rs, 0xffff */
 
 #define TCG_TARGET_HAS_GUEST_BASE
 
tcg/i386/tcg-target.h +35 -33

76 lines not on this page · raw message

tcg/ia64/tcg-target.h +35 -31

74 lines not on this page · raw message

tcg/mips/tcg-target.h +16 -15
index 8cb7d88..43c5501 100644
@@ -78,23 +78,24 @@ enum {
 #define TCG_TARGET_CALL_ALIGN_ARGS 1
 
 /* optional instructions */
-#define TCG_TARGET_HAS_div_i32
-#define TCG_TARGET_HAS_not_i32
-#define TCG_TARGET_HAS_nor_i32
-#undef TCG_TARGET_HAS_rot_i32
-#define TCG_TARGET_HAS_ext8s_i32
-#define TCG_TARGET_HAS_ext16s_i32
-#undef TCG_TARGET_HAS_bswap32_i32
-#undef TCG_TARGET_HAS_bswap16_i32
-#undef TCG_TARGET_HAS_andc_i32
-#undef TCG_TARGET_HAS_orc_i32
-#undef TCG_TARGET_HAS_eqv_i32
-#undef TCG_TARGET_HAS_nand_i32
+#define TCG_TARGET_HAS_div_i32          1
+#define TCG_TARGET_HAS_not_i32          1
+#define TCG_TARGET_HAS_nor_i32          1
+#define TCG_TARGET_HAS_rot_i32          0
+#define TCG_TARGET_HAS_ext8s_i32        1
+#define TCG_TARGET_HAS_ext16s_i32       1
+#define TCG_TARGET_HAS_bswap32_i32      0
+#define TCG_TARGET_HAS_bswap16_i32      0
+#define TCG_TARGET_HAS_andc_i32         0
+#define TCG_TARGET_HAS_orc_i32          0
+#define TCG_TARGET_HAS_eqv_i32          0
+#define TCG_TARGET_HAS_nand_i32         0
+#define TCG_TARGET_HAS_deposit_i32      0
 
 /* optional instructions automatically implemented */
-#undef TCG_TARGET_HAS_neg_i32      /* sub  rd, zero, rt   */
-#undef TCG_TARGET_HAS_ext8u_i32    /* andi rt, rs, 0xff   */
-#undef TCG_TARGET_HAS_ext16u_i32   /* andi rt, rs, 0xffff */
+#define TCG_TARGET_HAS_neg_i32          0 /* sub  rd, zero, rt   */
+#define TCG_TARGET_HAS_ext8u_i32        0 /* andi rt, rs, 0xff   */
+#define TCG_TARGET_HAS_ext16u_i32       0 /* andi rt, rs, 0xffff */
 
 /* Note: must be synced with dyngen-exec.h */
 #define TCG_AREG0 TCG_REG_S0
tcg/optimize.c +22 -134

253 lines not on this page · raw message

tcg/ppc/tcg-target.h +16 -15
index a1f8599..8c35c4e 100644
@@ -77,21 +77,22 @@ enum {
 #endif
 
 /* optional instructions */
-#define TCG_TARGET_HAS_div_i32
-#define TCG_TARGET_HAS_rot_i32
-#define TCG_TARGET_HAS_ext8s_i32
-#define TCG_TARGET_HAS_ext16s_i32
-#define TCG_TARGET_HAS_ext8u_i32
-#define TCG_TARGET_HAS_ext16u_i32
-#define TCG_TARGET_HAS_bswap16_i32
-#define TCG_TARGET_HAS_bswap32_i32
-#define TCG_TARGET_HAS_not_i32
-#define TCG_TARGET_HAS_neg_i32
-#define TCG_TARGET_HAS_andc_i32
-#define TCG_TARGET_HAS_orc_i32
-#define TCG_TARGET_HAS_eqv_i32
-#define TCG_TARGET_HAS_nand_i32
-#define TCG_TARGET_HAS_nor_i32
+#define TCG_TARGET_HAS_div_i32          1
+#define TCG_TARGET_HAS_rot_i32          1
+#define TCG_TARGET_HAS_ext8s_i32        1
+#define TCG_TARGET_HAS_ext16s_i32       1
+#define TCG_TARGET_HAS_ext8u_i32        1
+#define TCG_TARGET_HAS_ext16u_i32       1
+#define TCG_TARGET_HAS_bswap16_i32      1
+#define TCG_TARGET_HAS_bswap32_i32      1
+#define TCG_TARGET_HAS_not_i32          1
+#define TCG_TARGET_HAS_neg_i32          1
+#define TCG_TARGET_HAS_andc_i32         1
+#define TCG_TARGET_HAS_orc_i32          1
+#define TCG_TARGET_HAS_eqv_i32          1
+#define TCG_TARGET_HAS_nand_i32         1
+#define TCG_TARGET_HAS_nor_i32          1
+#define TCG_TARGET_HAS_deposit_i32      0
 
 #define TCG_AREG0 TCG_REG_R27
 
tcg/ppc64/tcg-target.h +35 -33

75 lines not on this page · raw message

tcg/s390/tcg-target.h +35 -33

76 lines not on this page · raw message

tcg/sparc/tcg-target.h +35 -33

76 lines not on this page · raw message

tcg/tcg-op.h +446 -500

1,229 lines not on this page · raw message

tcg/tcg-opc.h +88 -154

271 lines not on this page · raw message

tcg/tcg.c +4 -0
index 7179bd4..3e1e972 100644
@@ -2124,6 +2124,10 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
         case INDEX_op_end:
             goto the_end;
         default:
+            /* Sanity check that we've not introduced any unhandled opcodes. */
+            if (def->flags & TCG_OPF_NOT_PRESENT) {
+                tcg_abort();
+            }
             /* Note: in order to speed up the code, it would be much
                faster to have specialized register allocator functions for
                some common argument patterns */
tcg/tcg.h +38 -0
index 6a4f6e4..dc5e9c9 100644
@@ -47,6 +47,42 @@ typedef uint64_t TCGRegSet;
 #error unsupported
 #endif
 
+/* Turn some undef macros into false macros.  */
+#if TCG_TARGET_REG_BITS == 32
+#define TCG_TARGET_HAS_div_i64          0
+#define TCG_TARGET_HAS_div2_i64         0
+#define TCG_TARGET_HAS_rot_i64          0
+#define TCG_TARGET_HAS_ext8s_i64        0
+#define TCG_TARGET_HAS_ext16s_i64       0
+#define TCG_TARGET_HAS_ext32s_i64       0
+#define TCG_TARGET_HAS_ext8u_i64        0
+#define TCG_TARGET_HAS_ext16u_i64       0
+#define TCG_TARGET_HAS_ext32u_i64       0
+#define TCG_TARGET_HAS_bswap16_i64      0
+#define TCG_TARGET_HAS_bswap32_i64      0
+#define TCG_TARGET_HAS_bswap64_i64      0
+#define TCG_TARGET_HAS_neg_i64          0
+#define TCG_TARGET_HAS_not_i64          0
+#define TCG_TARGET_HAS_andc_i64         0
+#define TCG_TARGET_HAS_orc_i64          0
+#define TCG_TARGET_HAS_eqv_i64          0
+#define TCG_TARGET_HAS_nand_i64         0
+#define TCG_TARGET_HAS_nor_i64          0
+#define TCG_TARGET_HAS_deposit_i64      0
+#endif
+
+/* Only one of DIV or DIV2 should be defined.  */
+#if defined(TCG_TARGET_HAS_div_i32)
+#define TCG_TARGET_HAS_div2_i32         0
+#elif defined(TCG_TARGET_HAS_div2_i32)
+#define TCG_TARGET_HAS_div_i32          0
+#endif
+#if defined(TCG_TARGET_HAS_div_i64)
+#define TCG_TARGET_HAS_div2_i64         0
+#elif defined(TCG_TARGET_HAS_div2_i64)
+#define TCG_TARGET_HAS_div_i64          0
+#endif
+
 typedef enum TCGOpcode {
 #define DEF(name, oargs, iargs, cargs, flags) INDEX_op_ ## name,
 #include "tcg-opc.h"
@@ -456,6 +492,8 @@ enum {
     TCG_OPF_SIDE_EFFECTS = 0x04,
     /* Instruction operands are 64-bits (otherwise 32-bits).  */
     TCG_OPF_64BIT        = 0x08,
+    /* Instruction is optional and not implemented by the host.  */
+    TCG_OPF_NOT_PRESENT  = 0x10,
 };
 
 typedef struct TCGOpDef {
Signature · 1 line
1.7.4.4
#3 lore raw

Re: [Qemu-devel] [PATCH 2/6] tcg: Always define all of the TCGOpcode enum members.

Quoted 6 lines · Richard Henderson

By always defining these symbols, we can eliminate a lot of ifdefs.

To allow this to be checked reliably, the semantics of the TCG_TARGET_HAS_* macros must be changed from def/undef to true/false. This allows even more ifdefs to be removed, converting them into C if statements.

This breaks x86-64 hosts if built with --enable-debug:

petmay01@LinaroE102767:~/git/qemu$ ./arm-softmmu/qemu-system-arm
Missing op definition for div_i32
Missing op definition for divu_i32
Missing op definition for rem_i32
Missing op definition for remu_i32
Missing op definition for deposit_i32
Missing op definition for add2_i32
Missing op definition for sub2_i32
Missing op definition for brcond2_i32
Missing op definition for mulu2_i32
Missing op definition for setcond2_i32
Missing op definition for andc_i32
Missing op definition for orc_i32
Missing op definition for eqv_i32
Missing op definition for nand_i32
Missing op definition for nor_i32
Missing op definition for div_i64
Missing op definition for divu_i64
Missing op definition for rem_i64
Missing op definition for remu_i64
Missing op definition for deposit_i64
Missing op definition for andc_i64
Missing op definition for orc_i64
Missing op definition for eqv_i64
Missing op definition for nand_i64
Missing op definition for nor_i64
/home/petmay01/git/qemu/tcg/tcg.c:1148: tcg fatal error
Aborted

A compile-time check that the tcg target has #defined all the TCG_TARGET_HAS_foo to 0/1 and not left any undefined might be useful?

[thanks to mmu_man on irc for the report.]

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH 2/6] tcg: Always define all of the TCGOpcode enum members.

Quoted 3 lines · Peter Maydell

A compile-time check that the tcg target has #defined all the TCG_TARGET_HAS_foo to 0/1 and not left any undefined might be useful?

That compile-time check is the uses in tcg-op.h. If they're not defined you'll get undefined symbol errors in that file.

I'll look into the problem...

r~

#5 lore raw

PATCH 1/1 tcg: Update --enable-debug for TCG_OPF_NOT_PRESENT.

In reply to Peter Maydell
---
 tcg/tcg.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
tcg/tcg.c +8 -7
index 06ce214..411f971 100644
@@ -1128,18 +1128,19 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
 #if defined(CONFIG_DEBUG_TCG)
     i = 0;
     for (op = 0; op < ARRAY_SIZE(tcg_op_defs); op++) {
-        if (op < INDEX_op_call || op == INDEX_op_debug_insn_start) {
+        const TCGOpDef *def = &tcg_op_defs[op];
+        if (op < INDEX_op_call
+            || op == INDEX_op_debug_insn_start
+            || (def->flags & TCG_OPF_NOT_PRESENT)) {
             /* Wrong entry in op definitions? */
-            if (tcg_op_defs[op].used) {
-                fprintf(stderr, "Invalid op definition for %s\n",
-                        tcg_op_defs[op].name);
+            if (def->used) {
+                fprintf(stderr, "Invalid op definition for %s\n", def->name);
                 i = 1;
             }
         } else {
             /* Missing entry in op definitions? */
-            if (!tcg_op_defs[op].used) {
-                fprintf(stderr, "Missing op definition for %s\n",
-                        tcg_op_defs[op].name);
+            if (!def->used) {
+                fprintf(stderr, "Missing op definition for %s\n", def->name);
                 i = 1;
             }
         }
Signature · 1 line
1.7.4.4
#8 lore raw

PATCH 3/6 tcg: Constant fold neg, andc, orc, eqv, nand, nor.

In reply to Richard Henderson
---
 tcg/optimize.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
tcg/optimize.c +27 -0
index 32f928f..7e7f2b2 100644
@@ -215,6 +215,24 @@ static TCGArg do_constant_folding_2(int op, TCGArg x, TCGArg y)
     CASE_OP_32_64(not):
         return ~x;
 
+    CASE_OP_32_64(neg):
+        return -x;
+
+    CASE_OP_32_64(andc):
+        return x & ~y;
+
+    CASE_OP_32_64(orc):
+        return x | ~y;
+
+    CASE_OP_32_64(eqv):
+        return ~(x ^ y);
+
+    CASE_OP_32_64(nand):
+        return ~(x & y);
+
+    CASE_OP_32_64(nor):
+        return ~(x | y);
+
     CASE_OP_32_64(ext8s):
         return (int8_t)x;
 
@@ -290,6 +308,9 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
         CASE_OP_32_64(and):
         CASE_OP_32_64(or):
         CASE_OP_32_64(xor):
+        CASE_OP_32_64(eqv):
+        CASE_OP_32_64(nand):
+        CASE_OP_32_64(nor):
             if (temps[args[1]].state == TCG_TEMP_CONST) {
                 tmp = args[1];
                 args[1] = args[2];
@@ -389,6 +410,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
             args += 2;
             break;
         CASE_OP_32_64(not):
+        CASE_OP_32_64(neg):
         CASE_OP_32_64(ext8s):
         CASE_OP_32_64(ext8u):
         CASE_OP_32_64(ext16s):
@@ -421,6 +443,11 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
         CASE_OP_32_64(sar):
         CASE_OP_32_64(rotl):
         CASE_OP_32_64(rotr):
+        CASE_OP_32_64(andc):
+        CASE_OP_32_64(orc):
+        CASE_OP_32_64(eqv):
+        CASE_OP_32_64(nand):
+        CASE_OP_32_64(nor):
             if (temps[args[1]].state == TCG_TEMP_CONST
                 && temps[args[2]].state == TCG_TEMP_CONST) {
                 gen_opc_buf[op_index] = op_to_movi(op);
Signature · 1 line
1.7.4.4
#9 lore raw

PATCH 4/6 tcg-hppa: Fix CPU_TEMP_BUF_NLONGS oversight.

In reply to Richard Henderson
---
 tcg/hppa/tcg-target.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tcg/hppa/tcg-target.c +1 -1
index 222f33e..71d9677 100644
@@ -1650,7 +1650,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
 
     /* Record the location of the TCG temps.  */
     tcg_set_frame(s, TCG_REG_CALL_STACK, -frame_size + i * 4,
-                  TCG_TEMP_BUF_NLONGS * sizeof(long));
+                  CPU_TEMP_BUF_NLONGS * sizeof(long));
 
 #ifdef CONFIG_USE_GUEST_BASE
     if (GUEST_BASE != 0) {
Signature · 1 line
1.7.4.4
#10 lore raw

PATCH 5/6 tcg-ia64: Fix typos in AREG0 setup in prologue.

In reply to Richard Henderson
---
 tcg/ia64/tcg-target.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tcg/ia64/tcg-target.c +2 -2
index 6386a5b..9db205d 100644
@@ -2308,8 +2308,8 @@ static void tcg_target_qemu_prologue(TCGContext *s)
     }
 
     tcg_out_bundle(s, miB,
-                   tcg_opc_m48(TCG_REG_P0, OPC_MOV_I21,
-                               TCG_REG_AREG0, TCG_REG_R32, 0),
+                   tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4,
+                               TCG_AREG0, 0, TCG_REG_R32),
                    tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4,
                                TCG_REG_R12, -frame_size, TCG_REG_R12),
                    tcg_opc_b4 (TCG_REG_P0, OPC_BR_SPTK_MANY_B4, TCG_REG_B6));
Signature · 1 line
1.7.4.4
#11 lore raw

PATCH 6/6 tcg-arm: Make tcg_out_addi inline

In reply to Richard Henderson

As it's not used, fixes a compilation error.

---
 tcg/arm/tcg-target.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tcg/arm/tcg-target.c +1 -1
index 93eb0f1..c94a354 100644
@@ -1820,7 +1820,7 @@ static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
     tcg_out_st32(s, COND_AL, arg, arg1, arg2);
 }
 
-static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
+static inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
 {
     if (val > 0)
         if (val < 0x100)
Signature · 1 line
1.7.4.4
#13 lore raw

Re: [Qemu-devel] [PATCH 6/6] tcg-arm: Make tcg_out_addi inline

Quoted 2 lines · Peter Maydell
Quoted 1 line · Richard Henderson

As it's not used, fixes a compilation error.

Stefan Weil submitted an identical patch a couple of weeks ago, but I can't see the rationale for inlining. It seems like working around the warning is the only reason for this patch (?), so let's either remove/#if0 out the function or fix the compilation options to not error out on something that's not an error. (I'd prefer the latter but others may object)

Cheers

#14 lore raw

Re: [Qemu-devel] [PATCH 6/6] tcg-arm: Make tcg_out_addi inline

Quoted 10 lines · andrzej zaborowski
Quoted 2 lines · Peter Maydell
Quoted 1 line · Richard Henderson

As it's not used, fixes a compilation error.

Stefan Weil submitted an identical patch a couple of weeks ago, but I can't see the rationale for inlining.  It seems like working around the warning is the only reason for this patch (?), so let's either remove/#if0 out the function or fix the compilation options to not error out on something that's not an error. (I'd prefer the latter but others may object)

Yeah, we could remove the function (I'd prefer that to ifdeffery). I see malc did this for ppc/ppc64 in commits 1a2eb162414 and c24a9c6ef94.

If we do this, for consistency we should also remove the unused implementations in tcg/ia64 and tcg/s390.

-- PMM

Applied
#15 lore raw
In reply to Richard Henderson

Thanks, applied 1 to 5.

Quoted 56 lines · Richard Henderson

As discussed elsewhere, one way to tidy up tcg/optimize.c is to always provide the enum names, even if the host does not support the operation.

As a sanity check, I wanted to include a test to make sure that we never tried to output an opcode that the target does not handle.  I did this via a bit in the TCGOpDef flags. In order to get that set, I changed all of the TCG_TARGET_HAS* macros to be true/false rather than def/undef.

That allowed a further cleanup to change ifdefs into C IFs.

Unfortunately, it wasn't really possible to split this into smaller pieces.  Using the C IFs requires the enums be present, even if unused.

I cross-compiled --target-list=i386-softmmu,i386-linux-user for each of the tcg hosts.  In the process I discovered a number of pure compilation errors.

r~

Richard Henderson (6):
 tcg: Add and use TCG_OPF_64BIT.
 tcg: Always define all of the TCGOpcode enum members.
 tcg: Constant fold neg, andc, orc, eqv, nand, nor.
 tcg-hppa: Fix CPU_TEMP_BUF_NLONGS oversight.
 tcg-ia64: Fix typos in AREG0 setup in prologue.
 tcg-arm: Make tcg_out_addi inline

 tcg/arm/tcg-target.c   |    2 +-
 tcg/arm/tcg-target.h   |   30 +-
 tcg/hppa/tcg-target.c  |    2 +-
 tcg/hppa/tcg-target.h  |   29 +-
 tcg/i386/tcg-target.h  |   68 ++--
 tcg/ia64/tcg-target.c  |    4 +-
 tcg/ia64/tcg-target.h  |   66 ++--
 tcg/mips/tcg-target.h  |   31 +-

 tcg/optimize.c         |  260 +++-----------
 tcg/ppc/tcg-target.h   |   31 +-
 tcg/ppc64/tcg-target.h |   68 ++--
 tcg/s390/tcg-target.h  |   68 ++--
 tcg/sparc/tcg-target.h |   68 ++--
 tcg/tcg-op.h           |  946 +++++++++++++++++++++++------------------------- tcg/tcg-opc.h          |  242 +++++--------
 tcg/tcg.c              |    6 +-
 tcg/tcg.h              |   59 +++-

 17 files changed, 886 insertions(+), 1094 deletions(-)

--
1.7.4.4