tcg: Introduce TCG_COND_TST{EQ,NE}
v3 cover tcg: Introduce TCG_COND_TST{EQ,NE}
Expose a pair of comparison operators that map to the "test" comparison that is available on many architectures.
Changes for v3:
* Make support for TCG_COND_TST* optional (paolo)
* Drop riscv, loongarch64 and (unposted) mips backend changes.
* Incorporate Paolo's tcg/i386 TEST improvements
* Convert some target/s390x cases for even more testing.
* Probably some bug fixes in there too...
r~
Paolo Bonzini (1):
tcg/i386: Use TEST r,r to test 8/16/32 bits
Richard Henderson (37):
tcg: Introduce TCG_COND_TST{EQ,NE}
tcg: Introduce TCG_TARGET_HAS_tst
tcg/optimize: Split out arg_is_const_val tcg/optimize: Split out do_constant_folding_cond1 tcg/optimize: Do swap_commutative2 in do_constant_folding_cond2 tcg/optimize: Handle TCG_COND_TST{EQ,NE} tcg/optimize: Lower TCG_COND_TST{EQ,NE} if unsupported target/alpha: Pass immediate value to gen_bcond_internal() target/alpha: Use TCG_COND_TST{EQ,NE} for BLB{C,S} target/alpha: Use TCG_COND_TST{EQ,NE} for CMOVLB{C,S} target/alpha: Use TCG_COND_TSTNE for gen_fold_mzero target/m68k: Use TCG_COND_TST{EQ,NE} in gen_fcc_cond target/sparc: Use TCG_COND_TSTEQ in gen_op_mulscc target/s390x: Use TCG_COND_TSTNE for CC_OP_{TM,ICM} target/s390x: Improve general case of disas_jcc
tcg: Add TCGConst argument to tcg_target_const_match tcg/aarch64: Support TCG_COND_TST{EQ,NE}
tcg/aarch64: Generate TBZ, TBNZ
tcg/aarch64: Generate CBNZ for TSTNE of UINT32_MAX tcg/arm: Factor tcg_out_cmp() out
tcg/arm: Support TCG_COND_TST{EQ,NE}
tcg/i386: Pass x86 condition codes to tcg_out_cmov tcg/i386: Move tcg_cond_to_jcc[] into tcg_out_cmp tcg/i386: Support TCG_COND_TST{EQ,NE}
tcg/i386: Improve TSTNE/TESTEQ vs powers of two tcg/sparc64: Hoist read of tcg_cond_to_rcond tcg/sparc64: Pass TCGCond to tcg_out_cmp
tcg/sparc64: Support TCG_COND_TST{EQ,NE}
tcg/ppc: Sink tcg_to_bc usage into tcg_out_bc tcg/ppc: Use cr0 in tcg_to_bc and tcg_to_isel tcg/ppc: Tidy up tcg_target_const_match
tcg/ppc: Add TCG_CT_CONST_CMP
tcg/ppc: Support TCG_COND_TST{EQ,NE}
tcg/s390x: Split constraint A into J+U
tcg/s390x: Add TCG_CT_CONST_CMP
tcg/s390x: Support TCG_COND_TST{EQ,NE}
tcg/tci: Support TCG_COND_TST{EQ,NE}
docs/devel/tcg-ops.rst | 2 + include/tcg/tcg-cond.h | 74 +++-- tcg/aarch64/tcg-target-con-set.h | 5 +- tcg/aarch64/tcg-target-con-str.h | 1 + tcg/aarch64/tcg-target.h | 2 + tcg/arm/tcg-target.h | 2 + tcg/i386/tcg-target-con-set.h | 6 +- tcg/i386/tcg-target-con-str.h | 1 + tcg/i386/tcg-target.h | 2 + tcg/loongarch64/tcg-target.h | 2 + tcg/mips/tcg-target.h | 2 + tcg/ppc/tcg-target-con-set.h | 5 +- tcg/ppc/tcg-target-con-str.h | 1 + tcg/ppc/tcg-target.h | 2 + tcg/riscv/tcg-target.h | 2 + tcg/s390x/tcg-target-con-set.h | 8 +- tcg/s390x/tcg-target-con-str.h | 3 +- tcg/s390x/tcg-target.h | 2 + tcg/sparc64/tcg-target.h | 2 + tcg/tcg-internal.h | 2 + tcg/tci/tcg-target.h | 2 + target/alpha/translate.c | 94 +++--- target/m68k/translate.c | 74 +++-- target/s390x/tcg/translate.c | 100 +++---- target/sparc/translate.c | 4 +- tcg/optimize.c | 474 +++++++++++++++++++++++-------- tcg/tcg.c | 40 ++- tcg/tci.c | 14 + tcg/aarch64/tcg-target.c.inc | 165 ++++++++--- tcg/arm/tcg-target.c.inc | 62 ++-- tcg/i386/tcg-target.c.inc | 201 +++++++++---- tcg/loongarch64/tcg-target.c.inc | 3 +- tcg/mips/tcg-target.c.inc | 3 +- tcg/ppc/tcg-target.c.inc | 294 ++++++++++++++----- tcg/riscv/tcg-target.c.inc | 3 +- tcg/s390x/tcg-target.c.inc | 246 +++++++++++----- tcg/sparc64/tcg-target.c.inc | 65 +++-- tcg/tci/tcg-target.c.inc | 3 +- 38 files changed, 1378 insertions(+), 595 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/38 tcg: Introduce TCG_COND_TST{EQ,NE}
Add the enumerators, adjust the helpers to match, and dump. Not supported anywhere else just yet.
--- docs/devel/tcg-ops.rst | 2 ++ include/tcg/tcg-cond.h | 74 ++++++++++++++++++++++++++++++------------ tcg/tcg.c | 4 ++- 3 files changed, 58 insertions(+), 22 deletions(-)
docs/devel/tcg-ops.rst +2 -0
@@ -253,6 +253,8 @@ Jumps/Labels | ``TCG_COND_GEU /* unsigned */`` | ``TCG_COND_LEU /* unsigned */`` | ``TCG_COND_GTU /* unsigned */`` + | ``TCG_COND_TSTEQ /* t1 & t2 == 0 */`` + | ``TCG_COND_TSTNE /* t1 & t2 != 0 */`` Arithmetic ----------
include/tcg/tcg-cond.h +53 -21
111 lines not on this page · raw message
tcg/tcg.c +3 -1
@@ -2482,7 +2482,9 @@ static const char * const cond_name[] = [TCG_COND_LTU] = "ltu", [TCG_COND_GEU] = "geu", [TCG_COND_LEU] = "leu", - [TCG_COND_GTU ] ="gtu" + [TCG_COND_GTU] = "gtu", + [TCG_COND_TSTEQ] = "tsteq", + [TCG_COND_TSTNE] = "tstne", }; static const char * const ldst_name[(MO_BSWAP | MO_SSIZE) + 1] =
Signature · 1 line
2.34.1
PATCH v3 2/38 tcg: Introduce TCG_TARGET_HAS_tst
In reply to Richard HendersonDefine as 0 for all tcg backends.
--- tcg/aarch64/tcg-target.h | 2 ++ tcg/arm/tcg-target.h | 2 ++ tcg/i386/tcg-target.h | 2 ++ tcg/loongarch64/tcg-target.h | 2 ++ tcg/mips/tcg-target.h | 2 ++ tcg/ppc/tcg-target.h | 2 ++ tcg/riscv/tcg-target.h | 2 ++ tcg/s390x/tcg-target.h | 2 ++ tcg/sparc64/tcg-target.h | 2 ++ tcg/tci/tcg-target.h | 2 ++ 10 files changed, 20 insertions(+)
tcg/aarch64/tcg-target.h +2 -0
@@ -138,6 +138,8 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 1#endif +#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_v64 1#define TCG_TARGET_HAS_v128 1#define TCG_TARGET_HAS_v256 0
tcg/arm/tcg-target.h +2 -0
@@ -125,6 +125,8 @@ extern bool use_neon_instructions;#define TCG_TARGET_HAS_qemu_ldst_i128 0 +#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_v64 use_neon_instructions#define TCG_TARGET_HAS_v128 use_neon_instructions#define TCG_TARGET_HAS_v256 0
tcg/i386/tcg-target.h +2 -0
@@ -198,6 +198,8 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 \ (TCG_TARGET_REG_BITS == 64 && (cpuinfo & CPUINFO_ATOMIC_VMOVDQA)) +#define TCG_TARGET_HAS_tst 0 +/* We do not support older SSE systems, only beginning with AVX1. */ #define TCG_TARGET_HAS_v64 have_avx1#define TCG_TARGET_HAS_v128 have_avx1
tcg/loongarch64/tcg-target.h +2 -0
@@ -169,6 +169,8 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 (cpuinfo & CPUINFO_LSX) +#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_v64 0#define TCG_TARGET_HAS_v128 (cpuinfo & CPUINFO_LSX)#define TCG_TARGET_HAS_v256 0
tcg/mips/tcg-target.h +2 -0
@@ -194,6 +194,8 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_HAS_qemu_ldst_i128 0 +#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_DEFAULT_MO 0#define TCG_TARGET_NEED_LDST_LABELS #define TCG_TARGET_NEED_POOL_LABELS
tcg/ppc/tcg-target.h +2 -0
@@ -143,6 +143,8 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 \ (TCG_TARGET_REG_BITS == 64 && have_isa_2_07) +#define TCG_TARGET_HAS_tst 0 +/* * While technically Altivec could support V64, it has no 64-bit store * instruction and substituting two 32-bit stores makes the generated
tcg/riscv/tcg-target.h +2 -0
@@ -158,6 +158,8 @@ extern bool have_zbb;#define TCG_TARGET_HAS_qemu_ldst_i128 0 +#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_NEED_LDST_LABELS
tcg/s390x/tcg-target.h +2 -0
@@ -138,6 +138,8 @@ extern uint64_t s390_facilities[3];#define TCG_TARGET_HAS_qemu_ldst_i128 1 +#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_v64 HAVE_FACILITY(VECTOR)#define TCG_TARGET_HAS_v128 HAVE_FACILITY(VECTOR)#define TCG_TARGET_HAS_v256 0
tcg/sparc64/tcg-target.h +2 -0
@@ -149,6 +149,8 @@ extern bool use_vis3_instructions;#define TCG_TARGET_HAS_qemu_ldst_i128 0 +#define TCG_TARGET_HAS_tst 0 +#define TCG_AREG0 TCG_REG_I0#define TCG_TARGET_DEFAULT_MO (0)
tcg/tci/tcg-target.h +2 -0
@@ -117,6 +117,8 @@#define TCG_TARGET_HAS_qemu_ldst_i128 0 +#define TCG_TARGET_HAS_tst 0 +/* Number of registers available. */ #define TCG_TARGET_NB_REGS 16
Signature · 1 line
2.34.1
Re: [PATCH v3 02/38] tcg: Introduce TCG_TARGET_HAS_tst
Quoted 15 lines · Richard Henderson
Define as 0 for all tcg backends.
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.h | 2 ++ tcg/arm/tcg-target.h | 2 ++ tcg/i386/tcg-target.h | 2 ++ tcg/loongarch64/tcg-target.h | 2 ++ tcg/mips/tcg-target.h | 2 ++ tcg/ppc/tcg-target.h | 2 ++ tcg/riscv/tcg-target.h | 2 ++ tcg/s390x/tcg-target.h | 2 ++ tcg/sparc64/tcg-target.h | 2 ++ tcg/tci/tcg-target.h | 2 ++ 10 files changed, 20 insertions(+)
PATCH v3 3/38 tcg/optimize: Split out arg_is_const_val
In reply to Richard Henderson--- tcg/optimize.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
tcg/optimize.c +23 -15
@@ -124,11 +124,22 @@ static inline bool ts_is_const(TCGTemp *ts)return ts_info (ts)->is_const; } +static inline bool ts_is_const_val (TCGTemp *ts,uint64_t val) +{ +TempOptInfo *ti =ts_info (ts); +return ti->is_const && ti->val == val; +} +static inline bool arg_is_const (TCGArg arg) {return ts_is_const (arg_temp (arg)); } +static inline bool arg_is_const_val (TCGArg arg,uint64_t val) +{ +return ts_is_const_val (arg_temp (arg), val); +} +static inline bool ts_is_copy (TCGTemp *ts) {return ts_info (ts)->next_copy != ts;
@@ -689,7 +700,7 @@ static int do_constant_folding_cond(TCGType type, TCGArg x, } }else if (args_are_copies (x, y)) {return do_constant_folding_cond_eq (c); - }else if (arg_is_const (y) &&arg_info (y)->val ==0 ) { + }else if (arg_is_const_val (y,0 )) {switch (c) {case TCG_COND_LTU :return 0 ;
@@ -954,7 +965,7 @@ static bool fold_to_not(OptContext *ctx, TCGOp *op, int idx)/* If the binary operation has first argument @i, fold to @i. */ static bool fold_ix_to_i (OptContext *ctx,TCGOp *op,uint64_t i) { -if (arg_is_const (op->args[1 ]) &&arg_info (op->args[1 ])->val == i) { +if (arg_is_const_val (op->args[1 ], i)) {return tcg_opt_gen_movi (ctx, op, op->args[0 ], i); }return false;
@@ -963,7 +974,7 @@ static bool fold_ix_to_i(OptContext *ctx, TCGOp *op, uint64_t i)/* If the binary operation has first argument @i, fold to NOT. */ static bool fold_ix_to_not (OptContext *ctx,TCGOp *op,uint64_t i) { -if (arg_is_const (op->args[1 ]) &&arg_info (op->args[1 ])->val == i) { +if (arg_is_const_val (op->args[1 ], i)) {return fold_to_not (ctx, op,2 ); }return false;
@@ -972,7 +983,7 @@ static bool fold_ix_to_not(OptContext *ctx, TCGOp *op, uint64_t i)/* If the binary operation has second argument @i, fold to @i. */ static bool fold_xi_to_i (OptContext *ctx,TCGOp *op,uint64_t i) { -if (arg_is_const (op->args[2 ]) &&arg_info (op->args[2 ])->val == i) { +if (arg_is_const_val (op->args[2 ], i)) {return tcg_opt_gen_movi (ctx, op, op->args[0 ], i); }return false;
@@ -981,7 +992,7 @@ static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i)/* If the binary operation has second argument @i, fold to identity. */ static bool fold_xi_to_x (OptContext *ctx,TCGOp *op,uint64_t i) { -if (arg_is_const (op->args[2 ]) &&arg_info (op->args[2 ])->val == i) { +if (arg_is_const_val (op->args[2 ], i)) {return tcg_opt_gen_mov (ctx, op, op->args[0 ], op->args[1 ]); }return false;
@@ -990,7 +1001,7 @@ static bool fold_xi_to_x(OptContext *ctx, TCGOp *op, uint64_t i)/* If the binary operation has second argument @i, fold to NOT. */ static bool fold_xi_to_not (OptContext *ctx,TCGOp *op,uint64_t i) { -if (arg_is_const (op->args[2 ]) &&arg_info (op->args[2 ])->val == i) { +if (arg_is_const_val (op->args[2 ], i)) {return fold_to_not (ctx, op,1 ); }return false;
@@ -1223,8 +1234,8 @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op)* Simplify LT/GE comparisons vs zero to a single compare * vs the high word of the input. */ -if (arg_is_const (op->args[2 ]) &&arg_info (op->args[2 ])->val ==0 && -arg_is_const (op->args[3 ]) &&arg_info (op->args[3 ])->val ==0 ) { +if (arg_is_const_val (op->args[2 ],0 ) && +arg_is_const_val (op->args[3 ],0 )) { goto do_brcond_high; }break ;
@@ -1448,9 +1459,7 @@ static bool fold_deposit(OptContext *ctx, TCGOp *op) }/* Inserting a value into zero at offset 0. */ -if (arg_is_const (op->args[1 ]) - &&arg_info (op->args[1 ])->val ==0 - && op->args[3 ] ==0 ) { +if (arg_is_const_val (op->args[1 ],0 ) && op->args[3 ] ==0 ) {uint64_t mask =MAKE_64BIT_MASK (0 , op->args[4 ]); op->opc = and_opc;
@@ -1461,8 +1470,7 @@ static bool fold_deposit(OptContext *ctx, TCGOp *op) }/* Inserting zero into a value. */ -if (arg_is_const (op->args[2 ]) - &&arg_info (op->args[2 ])->val ==0 ) { +if (arg_is_const_val (op->args[2 ],0 )) {uint64_t mask =deposit64 (-1 , op->args[3 ], op->args[4 ],0 ); op->opc = and_opc;
@@ -2000,8 +2008,8 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)* Simplify LT/GE comparisons vs zero to a single compare * vs the high word of the input. */ -if (arg_is_const (op->args[3 ]) &&arg_info (op->args[3 ])->val ==0 && -arg_is_const (op->args[4 ]) &&arg_info (op->args[4 ])->val ==0 ) { +if (arg_is_const_val (op->args[3 ],0 ) && +arg_is_const_val (op->args[4 ],0 )) { goto do_setcond_high; }break ;
Signature · 1 line
2.34.1
PATCH v3 4/38 tcg/optimize: Split out do_constant_folding_cond1
In reply to Richard HendersonHandle modifications to the arguments and condition in a single place.
--- tcg/optimize.c | 57 ++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 30 deletions(-)
tcg/optimize.c +27 -30
@@ -796,6 +796,23 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2)return false; } +static int do_constant_folding_cond1 (OptContext *ctx,TCGArg dest, +TCGArg *p1,TCGArg *p2,TCGArg *pcond) +{ +TCGCond cond; +bool swap; +int r; + + swap =swap_commutative (dest, p1, p2); + cond = *pcond; +if (swap) { + *pcond = cond =tcg_swap_cond (cond); + } + + r =do_constant_folding_cond (ctx->type, *p1, *p2, cond); +return r; +} +static void init_arguments (OptContext *ctx,TCGOp *op,int nb_args) {for (int i =0 ; i < nb_args; i++) {
@@ -1193,14 +1210,8 @@ static bool fold_andc(OptContext *ctx, TCGOp *op)static bool fold_brcond (OptContext *ctx,TCGOp *op) { -TCGCond cond = op->args[2 ]; -int i; - -if (swap_commutative (NO_DEST , &op->args[0 ], &op->args[1 ])) { - op->args[2 ] = cond =tcg_swap_cond (cond); - } - - i =do_constant_folding_cond (ctx->type, op->args[0 ], op->args[1 ], cond); +int i =do_constant_folding_cond1 (ctx,NO_DEST , &op->args[0 ], + &op->args[1 ], &op->args[2 ]);if (i ==0 ) {tcg_op_remove (ctx->tcg, op);return true;
@@ -1695,21 +1706,18 @@ static bool fold_mov(OptContext *ctx, TCGOp *op)static bool fold_movcond (OptContext *ctx,TCGOp *op) { -TCGCond cond = op->args[5 ];int i; -if (swap_commutative (NO_DEST , &op->args[1 ], &op->args[2 ])) { - op->args[5 ] = cond =tcg_swap_cond (cond); - }/* * Canonicalize the "false" input reg to match the destination reg so * that the tcg backend can implement a "move if true" operation. */ if (swap_commutative (op->args[0 ], &op->args[4 ], &op->args[3 ])) { - op->args[5 ] = cond =tcg_invert_cond (cond); + op->args[5 ] =tcg_invert_cond (op->args[5 ]); } - i =do_constant_folding_cond (ctx->type, op->args[1 ], op->args[2 ], cond); + i =do_constant_folding_cond1 (ctx,NO_DEST , &op->args[1 ], + &op->args[2 ], &op->args[5 ]);if (i >=0 ) {return tcg_opt_gen_mov (ctx, op, op->args[0 ], op->args[4 - i]); }
@@ -1723,6 +1731,7 @@ static bool fold_movcond(OptContext *ctx, TCGOp *op)uint64_t tv =arg_info (op->args[3 ])->val;uint64_t fv =arg_info (op->args[4 ])->val;TCGOpcode opc, negopc =0 ; +TCGCond cond = op->args[5 ];switch (ctx->type) {case TCG_TYPE_I32 :
@@ -1950,14 +1959,8 @@ static bool fold_remainder(OptContext *ctx, TCGOp *op)static bool fold_setcond (OptContext *ctx,TCGOp *op) { -TCGCond cond = op->args[3 ]; -int i; - -if (swap_commutative (op->args[0 ], &op->args[1 ], &op->args[2 ])) { - op->args[3 ] = cond =tcg_swap_cond (cond); - } - - i =do_constant_folding_cond (ctx->type, op->args[1 ], op->args[2 ], cond); +int i =do_constant_folding_cond1 (ctx, op->args[0 ], &op->args[1 ], + &op->args[2 ], &op->args[3 ]);if (i >=0 ) {return tcg_opt_gen_movi (ctx, op, op->args[0 ], i); }
@@ -1969,14 +1972,8 @@ static bool fold_setcond(OptContext *ctx, TCGOp *op)static bool fold_negsetcond (OptContext *ctx,TCGOp *op) { -TCGCond cond = op->args[3 ]; -int i; - -if (swap_commutative (op->args[0 ], &op->args[1 ], &op->args[2 ])) { - op->args[3 ] = cond =tcg_swap_cond (cond); - } - - i =do_constant_folding_cond (ctx->type, op->args[1 ], op->args[2 ], cond); +int i =do_constant_folding_cond1 (ctx, op->args[0 ], &op->args[1 ], + &op->args[2 ], &op->args[3 ]);if (i >=0 ) {return tcg_opt_gen_movi (ctx, op, op->args[0 ], -i); }
Signature · 1 line
2.34.1
PATCH v3 5/38 tcg/optimize: Do swap_commutative2 in do_constant_folding_cond2
In reply to Richard HendersonMirror the new do_constant_folding_cond1 by doing all argument and condition adjustment within one helper.
--- tcg/optimize.c | 107 ++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 50 deletions(-)
tcg/optimize.c +57 -50
@@ -713,43 +713,6 @@ static int do_constant_folding_cond(TCGType type, TCGArg x,return -1 ; } -/* -* Return -1 if the condition can't be simplified, -* and the result of the condition (0 or 1) if it can. -*/ -static int do_constant_folding_cond2 (TCGArg *p1,TCGArg *p2,TCGCond c) -{ -TCGArg al = p1[0 ], ah = p1[1 ]; -TCGArg bl = p2[0 ], bh = p2[1 ]; - -if (arg_is_const (bl) &&arg_is_const (bh)) { -tcg_target_ulong blv =arg_info (bl)->val; -tcg_target_ulong bhv =arg_info (bh)->val; -uint64_t b =deposit64 (blv,32 ,32 , bhv); - -if (arg_is_const (al) &&arg_is_const (ah)) { -tcg_target_ulong alv =arg_info (al)->val; -tcg_target_ulong ahv =arg_info (ah)->val; -uint64_t a =deposit64 (alv,32 ,32 , ahv); -return do_constant_folding_cond_64 (a, b, c); - } -if (b ==0 ) { -switch (c) { -case TCG_COND_LTU : -return 0 ; -case TCG_COND_GEU : -return 1 ; -default : -break ; - } - } - } -if (args_are_copies (al, bl) &&args_are_copies (ah, bh)) { -return do_constant_folding_cond_eq (c); - } -return -1 ; -} -/** * swap_commutative: * @dest: TCGArg of the destination argument, or NO_DEST.
@@ -796,6 +759,10 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2)return false; } +/* +* Return -1 if the condition can't be simplified, +* and the result of the condition (0 or 1) if it can. +*/ static int do_constant_folding_cond1 (OptContext *ctx,TCGArg dest,TCGArg *p1,TCGArg *p2,TCGArg *pcond) {
@@ -813,6 +780,51 @@ static int do_constant_folding_cond1(OptContext *ctx, TCGArg dest,return r; } +static int do_constant_folding_cond2 (OptContext *ctx,TCGArg *args) +{ +TCGArg al, ah, bl, bh; +TCGCond c; +bool swap; + + swap =swap_commutative2 (args, args +2 ); + c = args[4 ]; +if (swap) { + args[4 ] = c =tcg_swap_cond (c); + } + + al = args[0 ]; + ah = args[1 ]; + bl = args[2 ]; + bh = args[3 ]; + +if (arg_is_const (bl) &&arg_is_const (bh)) { +tcg_target_ulong blv =arg_info (bl)->val; +tcg_target_ulong bhv =arg_info (bh)->val; +uint64_t b =deposit64 (blv,32 ,32 , bhv); + +if (arg_is_const (al) &&arg_is_const (ah)) { +tcg_target_ulong alv =arg_info (al)->val; +tcg_target_ulong ahv =arg_info (ah)->val; +uint64_t a =deposit64 (alv,32 ,32 , ahv); +return do_constant_folding_cond_64 (a, b, c); + } +if (b ==0 ) { +switch (c) { +case TCG_COND_LTU : +return 0 ; +case TCG_COND_GEU : +return 1 ; +default : +break ; + } + } + } +if (args_are_copies (al, bl) &&args_are_copies (ah, bh)) { +return do_constant_folding_cond_eq (c); + } +return -1 ; +} +static void init_arguments (OptContext *ctx,TCGOp *op,int nb_args) {for (int i =0 ; i < nb_args; i++) {
@@ -1225,15 +1237,13 @@ static bool fold_brcond(OptContext *ctx, TCGOp *op)static bool fold_brcond2 (OptContext *ctx,TCGOp *op) { -TCGCond cond = op->args[4 ]; -TCGArg label = op->args[5 ]; +TCGCond cond; +TCGArg label;int i, inv =0 ; -if (swap_commutative2 (&op->args[0 ], &op->args[2 ])) { - op->args[4 ] = cond =tcg_swap_cond (cond); - } - - i =do_constant_folding_cond2 (&op->args[0 ], &op->args[2 ], cond); + i =do_constant_folding_cond2 (ctx, &op->args[0 ]); + cond = op->args[4 ]; + label = op->args[5 ];if (i >=0 ) { goto do_brcond_const; }
@@ -1986,14 +1996,11 @@ static bool fold_negsetcond(OptContext *ctx, TCGOp *op)static bool fold_setcond2 (OptContext *ctx,TCGOp *op) { -TCGCond cond = op->args[5 ]; +TCGCond cond;int i, inv =0 ; -if (swap_commutative2 (&op->args[1 ], &op->args[3 ])) { - op->args[5 ] = cond =tcg_swap_cond (cond); - } - - i =do_constant_folding_cond2 (&op->args[1 ], &op->args[3 ], cond); + i =do_constant_folding_cond2 (ctx, &op->args[1 ]); + cond = op->args[5 ];if (i >=0 ) { goto do_setcond_const; }
Signature · 1 line
2.34.1
PATCH v3 6/38 tcg/optimize: Handle TCG_COND_TST{EQ,NE}
In reply to Richard HendersonFold constant comparisons.
Canonicalize "tst x,x" to equality vs zero. Canonicalize "tst x,sign" to sign test vs zero. Fold double-word comparisons with zero parts. Fold setcond of "tst x,pow2" to a bit extract.
--- tcg/optimize.c | 240 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 218 insertions(+), 22 deletions(-)
tcg/optimize.c +218 -22
@@ -625,9 +625,15 @@ static bool do_constant_folding_cond_32(uint32_t x, uint32_t y, TCGCond c)return x <= y;case TCG_COND_GTU :return x > y; -default : -g_assert_not_reached (); +case TCG_COND_TSTEQ : +return (x & y) ==0 ; +case TCG_COND_TSTNE : +return (x & y) !=0 ; +case TCG_COND_ALWAYS : +case TCG_COND_NEVER : +break ; } +g_assert_not_reached (); }static bool do_constant_folding_cond_64 (uint64_t x,uint64_t y,TCGCond c)
@@ -653,12 +659,18 @@ static bool do_constant_folding_cond_64(uint64_t x, uint64_t y, TCGCond c)return x <= y;case TCG_COND_GTU :return x > y; -default : -g_assert_not_reached (); +case TCG_COND_TSTEQ : +return (x & y) ==0 ; +case TCG_COND_TSTNE : +return (x & y) !=0 ; +case TCG_COND_ALWAYS : +case TCG_COND_NEVER : +break ; } +g_assert_not_reached (); } -static bool do_constant_folding_cond_eq (TCGCond c) +static int do_constant_folding_cond_eq (TCGCond c) {switch (c) {case TCG_COND_GT :
@@ -673,9 +685,14 @@ static bool do_constant_folding_cond_eq(TCGCond c)case TCG_COND_LEU :case TCG_COND_EQ :return 1 ; -default : -g_assert_not_reached (); +case TCG_COND_TSTEQ : +case TCG_COND_TSTNE : +return -1 ; +case TCG_COND_ALWAYS : +case TCG_COND_NEVER : +break ; } +g_assert_not_reached (); }/*
@@ -703,8 +720,10 @@ static int do_constant_folding_cond(TCGType type, TCGArg x, }else if (arg_is_const_val (y,0 )) {switch (c) {case TCG_COND_LTU : +case TCG_COND_TSTNE :return 0 ;case TCG_COND_GEU : +case TCG_COND_TSTEQ :return 1 ;default :return -1 ;
@@ -777,7 +796,30 @@ static int do_constant_folding_cond1(OptContext *ctx, TCGArg dest, } r =do_constant_folding_cond (ctx->type, *p1, *p2, cond); -return r; +if (r >=0 ) { +return r; + } +if (!is_tst_cond (cond)) { +return -1 ; + } + +/* +* TSTNE x,x -> NE x,0 +* TSTNE x,-1 -> NE x,0 +*/ +if (args_are_copies (*p1, *p2) ||arg_is_const_val (*p2,-1 )) { + *p2 =arg_new_constant (ctx,0 ); + *pcond =tcg_tst_eqne_cond (cond); +return -1 ; + } + +/* TSTNE x,sign -> LT x,0 */ +if (arg_is_const_val (*p2, (ctx->type ==TCG_TYPE_I32 + ?INT32_MIN :INT64_MIN ))) { + *p2 =arg_new_constant (ctx,0 ); + *pcond =tcg_tst_ltge_cond (cond); + } +return -1 ; }static int do_constant_folding_cond2 (OptContext *ctx,TCGArg *args)
@@ -785,6 +827,7 @@ static int do_constant_folding_cond2(OptContext *ctx, TCGArg *args)TCGArg al, ah, bl, bh;TCGCond c;bool swap; +int r; swap =swap_commutative2 (args, args +2 ); c = args[4 ];
@@ -806,21 +849,54 @@ static int do_constant_folding_cond2(OptContext *ctx, TCGArg *args)tcg_target_ulong alv =arg_info (al)->val;tcg_target_ulong ahv =arg_info (ah)->val;uint64_t a =deposit64 (alv,32 ,32 , ahv); -return do_constant_folding_cond_64 (a, b, c); + + r =do_constant_folding_cond_64 (a, b, c); +if (r >=0 ) { +return r; + } } +if (b ==0 ) {switch (c) {case TCG_COND_LTU : +case TCG_COND_TSTNE :return 0 ;case TCG_COND_GEU : +case TCG_COND_TSTEQ :return 1 ;default :break ; } } + +/* TSTNE x,-1 -> NE x,0 */ +if (b ==-1 &&is_tst_cond (c)) { + args[3 ] = args[2 ] =arg_new_constant (ctx,0 ); + args[4 ] =tcg_tst_eqne_cond (c); +return -1 ; + } + +/* TSTNE x,sign -> LT x,0 */ +if (b ==INT64_MIN &&is_tst_cond (c)) { +/* bl must be 0, so copy that to bh */ + args[3 ] = bl; + args[4 ] =tcg_tst_ltge_cond (c); +return -1 ; + } } +if (args_are_copies (al, bl) &&args_are_copies (ah, bh)) { -return do_constant_folding_cond_eq (c); + r =do_constant_folding_cond_eq (c); +if (r >=0 ) { +return r; + } + +/* TSTNE x,x -> NE x,0 */ +if (is_tst_cond (c)) { + args[3 ] = args[2 ] =arg_new_constant (ctx,0 ); + args[4 ] =tcg_tst_eqne_cond (c); +return -1 ; + } }return -1 ; }
@@ -1284,24 +1360,37 @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op)case 0 : goto do_brcond_const;case 1 : - op->opc = INDEX_op_brcond_i32; - op->args[1 ] = op->args[2 ]; - op->args[2 ] = cond; - op->args[3 ] = label; -break ; + goto do_brcond_low; + } +break ; + +case TCG_COND_TSTEQ : +case TCG_COND_TSTNE : +if (arg_is_const_val (op->args[2 ],0 )) { + goto do_brcond_high; + } +if (arg_is_const_val (op->args[3 ],0 )) { + goto do_brcond_low; }break ;default :break ; + do_brcond_low: + op->opc = INDEX_op_brcond_i32; + op->args[1 ] = op->args[2 ]; + op->args[2 ] = cond; + op->args[3 ] = label; +return fold_brcond (ctx, op); + do_brcond_high: op->opc = INDEX_op_brcond_i32; op->args[0 ] = op->args[1 ]; op->args[1 ] = op->args[3 ]; op->args[2 ] = cond; op->args[3 ] = label; -break ; +return fold_brcond (ctx, op); do_brcond_const:if (i ==0 ) {
@@ -1967,6 +2056,99 @@ static bool fold_remainder(OptContext *ctx, TCGOp *op)return false; } +static void fold_setcond_tst_pow2 (OptContext *ctx,TCGOp *op,bool neg) +{ +TCGOpcode and_opc, sub_opc, xor_opc, neg_opc, shr_opc, uext_opc, sext_opc; +TCGCond cond = op->args[3 ]; +TCGArg ret, src1, src2; +TCGOp *op2; +uint64_t val; +int sh; +bool inv; + +if (!is_tst_cond (cond) || !arg_is_const (op->args[2 ])) { +return ; + } + + src2 = op->args[2 ]; + val =arg_info (src2)->val; +if (!is_power_of_2 (val)) { +return ; + } + sh =ctz64 (val); + +switch (ctx->type) { +case TCG_TYPE_I32 : + and_opc = INDEX_op_and_i32; + sub_opc = INDEX_op_sub_i32; + xor_opc = INDEX_op_xor_i32; + shr_opc = INDEX_op_shr_i32; + neg_opc = INDEX_op_neg_i32; +if (TCG_TARGET_extract_i32_valid (sh,1 )) { + uext_opc = TCG_TARGET_HAS_extract_i32 ? INDEX_op_extract_i32 :0 ; + sext_opc = TCG_TARGET_HAS_sextract_i32 ? INDEX_op_sextract_i32 :0 ; + } +break ; +case TCG_TYPE_I64 : + and_opc = INDEX_op_and_i64; + sub_opc = INDEX_op_sub_i64; + xor_opc = INDEX_op_xor_i64; + shr_opc = INDEX_op_shr_i64; + neg_opc = INDEX_op_neg_i64; +if (TCG_TARGET_extract_i64_valid (sh,1 )) { + uext_opc = TCG_TARGET_HAS_extract_i64 ? INDEX_op_extract_i64 :0 ; + sext_opc = TCG_TARGET_HAS_sextract_i64 ? INDEX_op_sextract_i64 :0 ; + } +break ; +default : +g_assert_not_reached (); + } + + ret = op->args[0 ]; + src1 = op->args[1 ]; + inv = cond ==TCG_COND_TSTEQ ; + +if (sh && sext_opc && neg && !inv) { + op->opc = sext_opc; + op->args[1 ] = src1; + op->args[2 ] = sh; + op->args[3 ] =1 ; +return ; + }else if (sh && uext_opc) { + op->opc = uext_opc; + op->args[1 ] = src1; + op->args[2 ] = sh; + op->args[3 ] =1 ; + }else { +if (sh) { + op2 =tcg_op_insert_before (ctx->tcg, op, shr_opc,3 ); + op2->args[0 ] = ret; + op2->args[1 ] = src1; + op2->args[2 ] =arg_new_constant (ctx, sh); + src1 = ret; + } + op->opc = and_opc; + op->args[1 ] = src1; + op->args[2 ] =arg_new_constant (ctx,1 ); + } + +if (neg && inv) { + op2 =tcg_op_insert_after (ctx->tcg, op, sub_opc,3 ); + op2->args[0 ] = ret; + op2->args[1 ] = ret; + op2->args[2 ] =arg_new_constant (ctx,1 ); + }else if (inv) { + op2 =tcg_op_insert_after (ctx->tcg, op, xor_opc,3 ); + op2->args[0 ] = ret; + op2->args[1 ] = ret; + op2->args[2 ] =arg_new_constant (ctx,1 ); + }else if (neg) { + op2 =tcg_op_insert_after (ctx->tcg, op, neg_opc,2 ); + op2->args[0 ] = ret; + op2->args[1 ] = ret; + } +} +static bool fold_setcond (OptContext *ctx,TCGOp *op) { int i = do_constant_folding_cond1(ctx, op->args[0], &op->args[1],
@@ -1974,6 +2156,7 @@ static bool fold_setcond(OptContext *ctx, TCGOp *op)if (i >=0 ) {return tcg_opt_gen_movi (ctx, op, op->args[0 ], i); } +fold_setcond_tst_pow2 (ctx, op, false); ctx->z_mask =1 ; ctx->s_mask =smask_from_zmask (1 );
@@ -1987,13 +2170,13 @@ static bool fold_negsetcond(OptContext *ctx, TCGOp *op)if (i >=0 ) {return tcg_opt_gen_movi (ctx, op, op->args[0 ], -i); } +fold_setcond_tst_pow2 (ctx, op, true);/* Value is {0,-1} so all bits are repetitions of the sign. */ ctx->s_mask =-1 ;return false; } -static bool fold_setcond2 (OptContext *ctx,TCGOp *op) {TCGCond cond;
@@ -2041,22 +2224,35 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)case 0 : goto do_setcond_const;case 1 : - op->args[2 ] = op->args[3 ]; - op->args[3 ] = cond; - op->opc = INDEX_op_setcond_i32; -break ; + goto do_setcond_low; + } +break ; + +case TCG_COND_TSTEQ : +case TCG_COND_TSTNE : +if (arg_is_const_val (op->args[2 ],0 )) { + goto do_setcond_high; + } +if (arg_is_const_val (op->args[4 ],0 )) { + goto do_setcond_low; }break ;default :break ; + do_setcond_low: + op->args[2 ] = op->args[3 ]; + op->args[3 ] = cond; + op->opc = INDEX_op_setcond_i32; +return fold_setcond (ctx, op); + do_setcond_high: op->args[1 ] = op->args[2 ]; op->args[2 ] = op->args[4 ]; op->args[3 ] = cond; op->opc = INDEX_op_setcond_i32; -break ; +return fold_setcond (ctx, op); } ctx->z_mask =1 ;
Signature · 1 line
2.34.1
PATCH v3 7/38 tcg/optimize: Lower TCG_COND_TST{EQ, NE} if unsupported
In reply to Richard HendersonAfter having performed other simplifications, lower any remaining test comparisons with AND.
--- tcg/tcg-internal.h | 2 ++ tcg/optimize.c | 60 +++++++++++++++++++++++++++++++++++++++------- tcg/tcg.c | 2 +- 3 files changed, 55 insertions(+), 9 deletions(-)
tcg/tcg-internal.h +2 -0
@@ -83,6 +83,8 @@ static inline TCGv_i64 TCGV128_HIGH(TCGv_i128 t)bool tcg_target_has_memory_bswap (MemOp memop); +TCGTemp *tcg_temp_new_internal (TCGType type,TCGTempKind kind); +/* * Locate or create a read-only temporary that is a constant. * This kind of temporary need not be freed, but for convenience
tcg/optimize.c +52 -8
124 lines not on this page · raw message
tcg/tcg.c +1 -1
@@ -1655,7 +1655,7 @@ TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t off, const char *name)return temp_tcgv_ptr (ts); } -static TCGTemp *tcg_temp_new_internal (TCGType type,TCGTempKind kind) +TCGTemp *tcg_temp_new_internal (TCGType type,TCGTempKind kind) {TCGContext *s = tcg_ctx;TCGTemp *ts;
Signature · 1 line
2.34.1
Re: [PATCH v3 07/38] tcg/optimize: Lower TCG_COND_TST{EQ,NE} if unsupported
Quoted 9 lines · Richard Henderson
After having performed other simplifications, lower any remaining test comparisons with AND.
Signed-off-by Richard Henderson <[email protected]>--- tcg/tcg-internal.h | 2 ++ tcg/optimize.c | 60 +++++++++++++++++++++++++++++++++++++++------- tcg/tcg.c | 2 +- 3 files changed, 55 insertions(+), 9 deletions(-)
PATCH v3 8/38 target/alpha: Pass immediate value to gen_bcond_internal()
In reply to Richard HendersonSimplify gen_bcond() by passing an immediate value.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- target/alpha/translate.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
target/alpha/translate.c +7 -14
@@ -453,13 +453,13 @@ static DisasJumpType gen_bdirect(DisasContext *ctx, int ra, int32_t disp) }static DisasJumpType gen_bcond_internal (DisasContext *ctx,TCGCond cond, -TCGv cmp,int32_t disp) +TCGv cmp,uint64_t imm,int32_t disp) {uint64_t dest = ctx->base.pc_next + (disp <<2 );TCGLabel *lab_true =gen_new_label ();if (use_goto_tb (ctx, dest)) { -tcg_gen_brcondi_i64 (cond, cmp,0 , lab_true); +tcg_gen_brcondi_i64 (cond, cmp, imm, lab_true);tcg_gen_goto_tb (0 );tcg_gen_movi_i64 (cpu_pc, ctx->base.pc_next);
@@ -472,11 +472,11 @@ static DisasJumpType gen_bcond_internal(DisasContext *ctx, TCGCond cond,return DISAS_NORETURN ; }else { -TCGv_i64 z =load_zero (ctx); +TCGv_i64 i =tcg_constant_i64 (imm);TCGv_i64 d =tcg_constant_i64 (dest);TCGv_i64 p =tcg_constant_i64 (ctx->base.pc_next); -tcg_gen_movcond_i64 (cond, cpu_pc, cmp, z, d, p); +tcg_gen_movcond_i64 (cond, cpu_pc, cmp, i, d, p);return DISAS_PC_UPDATED ; } }
@@ -484,15 +484,8 @@ static DisasJumpType gen_bcond_internal(DisasContext *ctx, TCGCond cond,static DisasJumpType gen_bcond (DisasContext *ctx,TCGCond cond,int ra,int32_t disp,int mask) { -if (mask) { -TCGv tmp =tcg_temp_new (); -DisasJumpType ret; - -tcg_gen_andi_i64 (tmp,load_gpr (ctx, ra),1 ); - ret =gen_bcond_internal (ctx, cond, tmp, disp); -return ret; - } -return gen_bcond_internal (ctx, cond,load_gpr (ctx, ra), disp); +return gen_bcond_internal (ctx, cond,load_gpr (ctx, ra), + mask, disp); }/* Fold -0.0 for comparison with COND. */
@@ -533,7 +526,7 @@ static DisasJumpType gen_fbcond(DisasContext *ctx, TCGCond cond, int ra,DisasJumpType ret;gen_fold_mzero (cond, cmp_tmp,load_fpr (ctx, ra)); - ret =gen_bcond_internal (ctx, cond, cmp_tmp, disp); + ret =gen_bcond_internal (ctx, cond, cmp_tmp,0 , disp);return ret; }
Signature · 1 line
2.34.1
Re: [PATCH v3 08/38] target/alpha: Pass immediate value to gen_bcond_internal()
Quoted 10 lines · Richard Henderson
Simplify
gen_bcond()by passing an immediate value.Signed-off-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
[PMD: Split from bigger patch, part 1/2]Signed-off-by Philippe Mathieu-Daudé <[email protected]>Message-Id: <[email protected]>
--- target/alpha/translate.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
PATCH v3 9/38 target/alpha: Use TCG_COND_TST{EQ,NE} for BLB{C,S}
In reply to Richard HendersonMessage-Id: <[email protected]>
Message-Id: <[email protected]>
--- target/alpha/translate.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/alpha/translate.c +10 -10
@@ -482,10 +482,10 @@ static DisasJumpType gen_bcond_internal(DisasContext *ctx, TCGCond cond, }static DisasJumpType gen_bcond (DisasContext *ctx,TCGCond cond,int ra, -int32_t disp,int mask) +int32_t disp) {return gen_bcond_internal (ctx, cond,load_gpr (ctx, ra), - mask, disp); +is_tst_cond (cond), disp); }/* Fold -0.0 for comparison with COND. */
@@ -2820,35 +2820,35 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)break ;case 0x38 :/* BLBC */ - ret =gen_bcond (ctx,TCG_COND_EQ , ra, disp21,1 ); + ret =gen_bcond (ctx,TCG_COND_TSTEQ , ra, disp21);break ;case 0x39 :/* BEQ */ - ret =gen_bcond (ctx,TCG_COND_EQ , ra, disp21,0 ); + ret =gen_bcond (ctx,TCG_COND_EQ , ra, disp21);break ;case 0x3A :/* BLT */ - ret =gen_bcond (ctx,TCG_COND_LT , ra, disp21,0 ); + ret =gen_bcond (ctx,TCG_COND_LT , ra, disp21);break ;case 0x3B :/* BLE */ - ret =gen_bcond (ctx,TCG_COND_LE , ra, disp21,0 ); + ret =gen_bcond (ctx,TCG_COND_LE , ra, disp21);break ;case 0x3C :/* BLBS */ - ret =gen_bcond (ctx,TCG_COND_NE , ra, disp21,1 ); + ret =gen_bcond (ctx,TCG_COND_TSTNE , ra, disp21);break ;case 0x3D :/* BNE */ - ret =gen_bcond (ctx,TCG_COND_NE , ra, disp21,0 ); + ret =gen_bcond (ctx,TCG_COND_NE , ra, disp21);break ;case 0x3E :/* BGE */ - ret =gen_bcond (ctx,TCG_COND_GE , ra, disp21,0 ); + ret =gen_bcond (ctx,TCG_COND_GE , ra, disp21);break ;case 0x3F :/* BGT */ - ret =gen_bcond (ctx,TCG_COND_GT , ra, disp21,0 ); + ret =gen_bcond (ctx,TCG_COND_GT , ra, disp21);break ; invalid_opc: ret =gen_invalid (ctx);
Signature · 1 line
2.34.1
Re: [PATCH v3 09/38] target/alpha: Use TCG_COND_TST{EQ,NE} for BLB{C,S}
Quoted 8 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
[PMD: Split from bigger patch, part 2/2]Signed-off-by Philippe Mathieu-Daudé <[email protected]>Message-Id: <[email protected]>
--- target/alpha/translate.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
PATCH v3 10/38 target/alpha: Use TCG_COND_TST{EQ, NE} for CMOVLB{C, S}
In reply to Richard Henderson--- target/alpha/translate.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
target/alpha/translate.c +2 -6
@@ -1676,16 +1676,12 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)break ;case 0x14 :/* CMOVLBS */ - tmp =tcg_temp_new (); -tcg_gen_andi_i64 (tmp, va,1 ); -tcg_gen_movcond_i64 (TCG_COND_NE , vc, tmp,load_zero (ctx), +tcg_gen_movcond_i64 (TCG_COND_TSTNE , vc, va,tcg_constant_i64 (1 ), vb,load_gpr (ctx, rc));break ;case 0x16 :/* CMOVLBC */ - tmp =tcg_temp_new (); -tcg_gen_andi_i64 (tmp, va,1 ); -tcg_gen_movcond_i64 (TCG_COND_EQ , vc, tmp,load_zero (ctx), +tcg_gen_movcond_i64 (TCG_COND_TSTEQ , vc, va,tcg_constant_i64 (1 ), vb,load_gpr (ctx, rc));break ;case 0x20 :
Signature · 1 line
2.34.1
PATCH v3 11/38 target/alpha: Use TCG_COND_TSTNE for gen_fold_mzero
In reply to Richard Henderson--- target/alpha/translate.c | 49 +++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 26 deletions(-)
target/alpha/translate.c +23 -26
@@ -490,56 +490,53 @@ static DisasJumpType gen_bcond(DisasContext *ctx, TCGCond cond, int ra,/* Fold -0.0 for comparison with COND. */ -static void gen_fold_mzero (TCGCond cond,TCGv dest,TCGv src) +static TCGv_i64 gen_fold_mzero (TCGCond *pcond,uint64_t *pimm,TCGv_i64 src) { -uint64_t mzero =1ull <<63 ; +TCGv_i64 tmp; -switch (cond) { + *pimm =0 ; +switch (*pcond) {case TCG_COND_LE :case TCG_COND_GT :/* For <= or >, the -0.0 value directly compares the way we want. */ -tcg_gen_mov_i64 (dest, src); -break ; +return src;case TCG_COND_EQ :case TCG_COND_NE : -/* For == or !=, we can simply mask off the sign bit and compare. */ -tcg_gen_andi_i64 (dest, src, mzero -1 ); -break ; +/* For == or !=, we can compare without the sign bit. */ + *pcond = *pcond ==TCG_COND_EQ ?TCG_COND_TSTEQ :TCG_COND_TSTNE ; + *pimm =INT64_MAX ; +return src;case TCG_COND_GE :case TCG_COND_LT :/* For >= or <, map -0.0 to +0.0. */ -tcg_gen_movcond_i64 (TCG_COND_NE , dest, src,tcg_constant_i64 (mzero), - src,tcg_constant_i64 (0 )); -break ; + tmp =tcg_temp_new_i64 (); +tcg_gen_movcond_i64 (TCG_COND_EQ , tmp, + src,tcg_constant_i64 (INT64_MIN ), +tcg_constant_i64 (0 ), src); +return tmp;default : -abort (); +g_assert_not_reached (); } }static DisasJumpType gen_fbcond (DisasContext *ctx,TCGCond cond,int ra,int32_t disp) { -TCGv cmp_tmp =tcg_temp_new (); -DisasJumpType ret; - -gen_fold_mzero (cond, cmp_tmp,load_fpr (ctx, ra)); - ret =gen_bcond_internal (ctx, cond, cmp_tmp,0 , disp); -return ret; +uint64_t imm; +TCGv_i64 tmp =gen_fold_mzero (&cond, &imm,load_fpr (ctx, ra)); +return gen_bcond_internal (ctx, cond, tmp, imm, disp); }static void gen_fcmov (DisasContext *ctx,TCGCond cond,int ra,int rb,int rc) { -TCGv_i64 va, vb, z; - - z =load_zero (ctx); - vb =load_fpr (ctx, rb); - va =tcg_temp_new (); -gen_fold_mzero (cond, va,load_fpr (ctx, ra)); - -tcg_gen_movcond_i64 (cond,dest_fpr (ctx, rc), va, z, vb,load_fpr (ctx, rc)); +uint64_t imm; +TCGv_i64 tmp =gen_fold_mzero (&cond, &imm,load_fpr (ctx, ra)); +tcg_gen_movcond_i64 (cond,dest_fpr (ctx, rc), + tmp,tcg_constant_i64 (imm), +load_fpr (ctx, rb),load_fpr (ctx, rc)); }#define QUAL_RM_N 0x080/* Round mode nearest even */
Signature · 1 line
2.34.1
PATCH v3 12/38 target/m68k: Use TCG_COND_TST{EQ, NE} in gen_fcc_cond
In reply to Richard Henderson--- target/m68k/translate.c | 74 ++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 41 deletions(-)
target/m68k/translate.c +33 -41
@@ -5129,46 +5129,44 @@ undef:static void gen_fcc_cond (DisasCompare *c,DisasContext *s,int cond) {TCGv fpsr; +int imm =0 ; - c->v2 =tcg_constant_i32 (0 );/* TODO: Raise BSUN exception. */ fpsr =tcg_temp_new ();gen_load_fcr (s, fpsr,M68K_FPSR ); + c->v1 = fpsr; +switch (cond) {case 0 :/* False */ case 16 :/* Signaling False */ - c->v1 = c->v2; c->tcond =TCG_COND_NEVER ;break ;case 1 :/* EQual Z */ case 17 :/* Signaling EQual Z */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_Z ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_Z ; + c->tcond =TCG_COND_TSTNE ;break ;case 2 :/* Ordered Greater Than !(A || Z || N) */ case 18 :/* Greater Than !(A || Z || N) */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr, -FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); - c->tcond =TCG_COND_EQ ; + imm =FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ; + c->tcond =TCG_COND_TSTEQ ;break ;case 3 :/* Ordered Greater than or Equal Z || !(A || N) */ case 19 :/* Greater than or Equal Z || !(A || N) */ c->v1 =tcg_temp_new ();tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A );tcg_gen_shli_i32 (c->v1, c->v1,ctz32 (FPSR_CC_N ) -ctz32 (FPSR_CC_A )); -tcg_gen_andi_i32 (fpsr, fpsr,FPSR_CC_Z |FPSR_CC_N );tcg_gen_or_i32 (c->v1, c->v1, fpsr);tcg_gen_xori_i32 (c->v1, c->v1,FPSR_CC_N ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_Z |FPSR_CC_N ; + c->tcond =TCG_COND_TSTNE ;break ;case 4 :/* Ordered Less Than !(!N || A || Z); */ case 20 :/* Less Than !(!N || A || Z); */ c->v1 =tcg_temp_new ();tcg_gen_xori_i32 (c->v1, fpsr,FPSR_CC_N ); -tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_N |FPSR_CC_A |FPSR_CC_Z ); - c->tcond =TCG_COND_EQ ; + imm =FPSR_CC_N |FPSR_CC_A |FPSR_CC_Z ; + c->tcond =TCG_COND_TSTEQ ;break ;case 5 :/* Ordered Less than or Equal Z || (N && !A) */ case 21 :/* Less than or Equal Z || (N && !A) */
@@ -5176,49 +5174,45 @@ static void gen_fcc_cond(DisasCompare *c, DisasContext *s, int cond)tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A );tcg_gen_shli_i32 (c->v1, c->v1,ctz32 (FPSR_CC_N ) -ctz32 (FPSR_CC_A ));tcg_gen_andc_i32 (c->v1, fpsr, c->v1); -tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_Z |FPSR_CC_N ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_Z |FPSR_CC_N ; + c->tcond =TCG_COND_TSTNE ;break ;case 6 :/* Ordered Greater or Less than !(A || Z) */ case 22 :/* Greater or Less than !(A || Z) */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A |FPSR_CC_Z ); - c->tcond =TCG_COND_EQ ; + imm =FPSR_CC_A |FPSR_CC_Z ; + c->tcond =TCG_COND_TSTEQ ;break ;case 7 :/* Ordered !A */ case 23 :/* Greater, Less or Equal !A */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A ); - c->tcond =TCG_COND_EQ ; + imm =FPSR_CC_A ; + c->tcond =TCG_COND_TSTEQ ;break ;case 8 :/* Unordered A */ case 24 :/* Not Greater, Less or Equal A */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_A ; + c->tcond =TCG_COND_TSTNE ;break ;case 9 :/* Unordered or Equal A || Z */ case 25 :/* Not Greater or Less then A || Z */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A |FPSR_CC_Z ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_A |FPSR_CC_Z ; + c->tcond =TCG_COND_TSTNE ;break ;case 10 :/* Unordered or Greater Than A || !(N || Z)) */ case 26 :/* Not Less or Equal A || !(N || Z)) */ c->v1 =tcg_temp_new ();tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_Z );tcg_gen_shli_i32 (c->v1, c->v1,ctz32 (FPSR_CC_N ) -ctz32 (FPSR_CC_Z )); -tcg_gen_andi_i32 (fpsr, fpsr,FPSR_CC_A |FPSR_CC_N );tcg_gen_or_i32 (c->v1, c->v1, fpsr);tcg_gen_xori_i32 (c->v1, c->v1,FPSR_CC_N ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_A |FPSR_CC_N ; + c->tcond =TCG_COND_TSTNE ;break ;case 11 :/* Unordered or Greater or Equal A || Z || !N */ case 27 :/* Not Less Than A || Z || !N */ c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); -tcg_gen_xori_i32 (c->v1, c->v1,FPSR_CC_N ); - c->tcond =TCG_COND_NE ; +tcg_gen_xori_i32 (c->v1, fpsr,FPSR_CC_N ); + imm =FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ; + c->tcond =TCG_COND_TSTNE ;break ;case 12 :/* Unordered or Less Than A || (N && !Z) */ case 28 :/* Not Greater than or Equal A || (N && !Z) */
@@ -5226,27 +5220,25 @@ static void gen_fcc_cond(DisasCompare *c, DisasContext *s, int cond)tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_Z );tcg_gen_shli_i32 (c->v1, c->v1,ctz32 (FPSR_CC_N ) -ctz32 (FPSR_CC_Z ));tcg_gen_andc_i32 (c->v1, fpsr, c->v1); -tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_A |FPSR_CC_N ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_A |FPSR_CC_N ; + c->tcond =TCG_COND_TSTNE ;break ;case 13 :/* Unordered or Less or Equal A || Z || N */ case 29 :/* Not Greater Than A || Z || N */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); - c->tcond =TCG_COND_NE ; + imm =FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ; + c->tcond =TCG_COND_TSTNE ;break ;case 14 :/* Not Equal !Z */ case 30 :/* Signaling Not Equal !Z */ - c->v1 =tcg_temp_new (); -tcg_gen_andi_i32 (c->v1, fpsr,FPSR_CC_Z ); - c->tcond =TCG_COND_EQ ; + imm =FPSR_CC_Z ; + c->tcond =TCG_COND_TSTEQ ;break ;case 15 :/* True */ case 31 :/* Signaling True */ - c->v1 = c->v2; c->tcond =TCG_COND_ALWAYS ;break ; } + c->v2 =tcg_constant_i32 (imm); }static void gen_fjmpcc (DisasContext *s,int cond,TCGLabel *l1)
Signature · 1 line
2.34.1
Re: [PATCH v3 12/38] target/m68k: Use TCG_COND_TST{EQ,NE} in gen_fcc_cond
Quoted 4 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/m68k/translate.c | 74 ++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 41 deletions(-)
PATCH v3 13/38 target/sparc: Use TCG_COND_TSTEQ in gen_op_mulscc
In reply to Richard Henderson--- target/sparc/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/sparc/translate.c +2 -2
@@ -506,6 +506,7 @@ static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2)static void gen_op_mulscc (TCGv dst,TCGv src1,TCGv src2) {TCGv zero =tcg_constant_tl (0 ); +TCGv one =tcg_constant_tl (1 );TCGv t_src1 =tcg_temp_new ();TCGv t_src2 =tcg_temp_new ();TCGv t0 =tcg_temp_new ();
@@ -517,8 +518,7 @@ static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)* if (!(env->y & 1)) * src2 = 0; */ -tcg_gen_andi_tl (t0, cpu_y,0x1 ); -tcg_gen_movcond_tl (TCG_COND_EQ , t_src2, t0, zero, zero, t_src2); +tcg_gen_movcond_tl (TCG_COND_TSTEQ , t_src2, cpu_y, one, zero, t_src2);/* * b2 = src1 & 1;
Signature · 1 line
2.34.1
Re: [PATCH v3 13/38] target/sparc: Use TCG_COND_TSTEQ in gen_op_mulscc
Quoted 4 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/sparc/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH v3 14/38 target/s390x: Use TCG_COND_TSTNE for CC_OP_{TM,ICM}
In reply to Richard HendersonThese are all test-and-compare type instructions.
--- target/s390x/tcg/translate.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
target/s390x/tcg/translate.c +7 -11
@@ -754,10 +754,10 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_TM_64 :switch (mask) {case 8 : - cond =TCG_COND_EQ ; + cond =TCG_COND_TSTEQ ;break ;case 4 |2 |1 : - cond =TCG_COND_NE ; + cond =TCG_COND_TSTNE ;break ;default : goto do_dynamic;
@@ -768,11 +768,11 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_ICM :switch (mask) {case 8 : - cond =TCG_COND_EQ ; + cond =TCG_COND_TSTEQ ;break ;case 4 |2 |1 :case 4 |2 : - cond =TCG_COND_NE ; + cond =TCG_COND_TSTNE ;break ;default : goto do_dynamic;
@@ -854,18 +854,14 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) c->u.s64.a = cc_dst; c->u.s64.b =tcg_constant_i64 (0 );break ; +case CC_OP_LTGT_64 :case CC_OP_LTUGTU_64 : - c->u.s64.a = cc_src; - c->u.s64.b = cc_dst; -break ; -case CC_OP_TM_32 :case CC_OP_TM_64 :case CC_OP_ICM : - c->u.s64.a =tcg_temp_new_i64 (); - c->u.s64.b =tcg_constant_i64 (0 ); -tcg_gen_and_i64 (c->u.s64.a, cc_src, cc_dst); + c->u.s64.a = cc_src; + c->u.s64.b = cc_dst;break ;case CC_OP_ADDU :
Signature · 1 line
2.34.1
Re: [PATCH v3 14/38] target/s390x: Use TCG_COND_TSTNE for CC_OP_{TM,ICM}
Quoted 50 lines · Richard Henderson
These are all test-and-compare type instructions.
Signed-off-by Richard Henderson <[email protected]>--- target/s390x/tcg/translate.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)target/s390x/tcg/translate.c +5
-8@@ -754,10 +754,10 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_TM_64 :switch (mask) {case 8 : - cond =TCG_COND_EQ ; + cond =TCG_COND_TSTEQ ;break ;case 4 |2 |1 : - cond =TCG_COND_NE ; + cond =TCG_COND_TSTNE ;break ;default : goto do_dynamic;@@ -768,11 +768,11 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_ICM :switch (mask) {case 8 : - cond =TCG_COND_EQ ; + cond =TCG_COND_TSTEQ ;break ;case 4 |2 |1 :case 4 |2 : - cond =TCG_COND_NE ; + cond =TCG_COND_TSTNE ;break ;default : goto do_dynamic;@@ -854,18 +854,14 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) c->u.s64.a = cc_dst; c->u.s64.b =tcg_constant_i64 (0 );break ; +case CC_OP_LTGT_64 :case CC_OP_LTUGTU_64 : - c->u.s64.a = cc_src; - c->u.s64.b = cc_dst; -break ; -case CC_OP_TM_32 :
target/s390x/tcg/translate.c static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) · line 867
Quoted 10 lines
target/s390x/tcg/translate.c +2
-3case CC_OP_TM_64 :case CC_OP_ICM : - c->u.s64.a =tcg_temp_new_i64 (); - c->u.s64.b =tcg_constant_i64 (0 ); -tcg_gen_and_i64 (c->u.s64.a, cc_src, cc_dst); + c->u.s64.a = cc_src; + c->u.s64.b = cc_dst;break ;case CC_OP_ADDU :
To the best of my s390x knowledge:
PATCH v3 15/38 target/s390x: Improve general case of disas_jcc
In reply to Richard HendersonAvoid code duplication by handling 7 of the 14 cases by inverting the test for the other 7 cases.
Use TCG_COND_TSTNE for cc in {1,3}.
Use (cc - 1) <= 1 for cc in {1,2}.
--- target/s390x/tcg/translate.c | 82 +++++++++++++----------------------- 1 file changed, 30 insertions(+), 52 deletions(-)
target/s390x/tcg/translate.c +30 -52
@@ -885,67 +885,45 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_STATIC : c->is_64 = false; c->u.s32.a = cc_op; -switch (mask) { -case 0x8 |0x4 |0x2 :/* cc != 3 */ - cond =TCG_COND_NE ; + +/* Fold half of the cases using bit 3 to invert. */ +switch (mask &8 ? mask ^0xf : mask) { +case 0x1 :/* cc == 3 */ + cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (3 );break ; -case 0x8 |0x4 |0x1 :/* cc != 2 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ; -case 0x8 |0x2 |0x1 :/* cc != 1 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ; -case 0x8 |0x2 :/* cc == 0 || cc == 2 => (cc & 1) == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); -break ; -case 0x8 |0x4 :/* cc < 2 */ - cond =TCG_COND_LTU ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ; -case 0x8 :/* cc == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (0 ); -break ; -case 0x4 |0x2 |0x1 :/* cc != 0 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (0 ); -break ; -case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); -break ; -case 0x4 :/* cc == 1 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ; -case 0x2 |0x1 :/* cc > 1 */ - cond =TCG_COND_GTU ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ;case 0x2 :/* cc == 2 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (2 );break ; -case 0x1 :/* cc == 3 */ +case 0x4 :/* cc == 1 */ cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (3 ); + c->u.s32.b =tcg_constant_i32 (1 ); +break ; +case 0x2 |0x1 :/* cc == 2 || cc == 3 => cc > 1 */ + cond =TCG_COND_GTU ; + c->u.s32.b =tcg_constant_i32 (1 ); +break ; +case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ + cond =TCG_COND_TSTNE ; + c->u.s32.b =tcg_constant_i32 (1 ); +break ; +case 0x4 |0x2 :/* cc == 1 || cc == 2 => (cc - 1) <= 1 */ + cond =TCG_COND_LEU ; + c->u.s32.a =tcg_temp_new_i32 (); + c->u.s32.b =tcg_constant_i32 (1 ); +tcg_gen_addi_i32 (c->u.s32.a, cc_op,-1 ); +break ; +case 0x4 |0x2 |0x1 :/* cc != 0 */ + cond =TCG_COND_NE ; + c->u.s32.b =tcg_constant_i32 (0 );break ;default : -/* CC is masked by something else: (8 >> cc) & mask. */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_shr_i32 (c->u.s32.a,tcg_constant_i32 (8 ), cc_op); -tcg_gen_andi_i32 (c->u.s32.a, c->u.s32.a, mask); -break ; +/* case 0: never, handled above. */ +g_assert_not_reached (); + } +if (mask &8 ) { + cond =tcg_invert_cond (cond); }break ;
Signature · 1 line
2.34.1
Re: [PATCH v3 15/38] target/s390x: Improve general case of disas_jcc
Hi Richard,
Quoted 76 lines · Richard Henderson
Avoid code duplication by handling 7 of the 14 cases by inverting the test for the other 7 cases.
Use
TCG_COND_TSTNEfor cc in {1,3}.
Use (cc - 1) <= 1 for cc in {1,2}.Signed-off-by Richard Henderson <[email protected]>--- target/s390x/tcg/translate.c | 82 +++++++++++++----------------------- 1 file changed, 30 insertions(+), 52 deletions(-)target/s390x/tcg/translate.c +6
-44@@ -885,67 +885,45 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_STATIC : c->is_64 = false; c->u.s32.a = cc_op; -switch (mask) { -case 0x8 |0x4 |0x2 :/* cc != 3 */ - cond =TCG_COND_NE ; + +/* Fold half of the cases using bit 3 to invert. */ +switch (mask &8 ? mask ^0xf : mask) { +case 0x1 :/* cc == 3 */ + cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (3 );break ; -case 0x8 |0x4 |0x1 :/* cc != 2 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ; -case 0x8 |0x2 |0x1 :/* cc != 1 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ; -case 0x8 |0x2 :/* cc == 0 || cc == 2 => (cc & 1) == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); -break ; -case 0x8 |0x4 :/* cc < 2 */ - cond =TCG_COND_LTU ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ; -case 0x8 :/* cc == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (0 ); -break ; -case 0x4 |0x2 |0x1 :/* cc != 0 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (0 ); -break ; -case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); -break ; -case 0x4 :/* cc == 1 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ; -case 0x2 |0x1 :/* cc > 1 */ - cond =TCG_COND_GTU ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ;case 0x2 :/* cc == 2 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (2 );break ; -case 0x1 :/* cc == 3 */ +case 0x4 :/* cc == 1 */ cond =TCG_COND_EQ ;
target/s390x/tcg/translate.c static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) · line 909
Quoted 10 lines
target/s390x/tcg/translate.c +9
-1- c->u.s32.b =tcg_constant_i32 (3 ); + c->u.s32.b =tcg_constant_i32 (1 ); +break ; +case 0x2 |0x1 :/* cc == 2 || cc == 3 => cc > 1 */ + cond =TCG_COND_GTU ; + c->u.s32.b =tcg_constant_i32 (1 ); +break ; +case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ + cond =TCG_COND_TSTNE ; + c->u.s32.b =tcg_constant_i32 (1 );
Don't we need to AND?
c->u.s32.a = tcg_temp_new_i32();
tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);Quoted 27 lines
target/s390x/tcg/translate.c +15
-7+break ; +case 0x4 |0x2 :/* cc == 1 || cc == 2 => (cc - 1) <= 1 */ + cond =TCG_COND_LEU ; + c->u.s32.a =tcg_temp_new_i32 (); + c->u.s32.b =tcg_constant_i32 (1 ); +tcg_gen_addi_i32 (c->u.s32.a, cc_op,-1 ); +break ; +case 0x4 |0x2 |0x1 :/* cc != 0 */ + cond =TCG_COND_NE ; + c->u.s32.b =tcg_constant_i32 (0 );break ;default : -/* CC is masked by something else: (8 >> cc) & mask. */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_shr_i32 (c->u.s32.a,tcg_constant_i32 (8 ), cc_op); -tcg_gen_andi_i32 (c->u.s32.a, c->u.s32.a, mask); -break ; +/* case 0: never, handled above. */ +g_assert_not_reached (); + } +if (mask &8 ) { + cond =tcg_invert_cond (cond); }break ;
Re: [PATCH v3 15/38] target/s390x: Improve general case of disas_jcc
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines
+ case
0x4|0x1: /* cc == 1 || cc == 3 => (cc & 1) != 0 */ + cond =TCG_COND_TSTNE;
+c->u.s32.b=tcg_constant_i32(1);Don't we need to AND?
c->u.s32.a=tcg_temp_new_i32();tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
No, that's the TSTNE cond there.
r~
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH v3 15/38] target/s390x: Improve general case of disas_jcc
Quoted 11 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines
+ case
0x4|0x1: /* cc == 1 || cc == 3 => (cc & 1) != 0 */ + cond =TCG_COND_TSTNE;
+c->u.s32.b=tcg_constant_i32(1);Don't we need to AND?
c->u.s32.a=tcg_temp_new_i32();tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);No, that's the TSTNE cond there.
This patch as is was too complex for me so I split it in very dumb steps to get a trivial patch:
https://lore.kernel.org/qemu-devel/[email protected]/.
PATCH v3 1/6 target/s390x: Reorder CC_OP_STATIC switch case in disas_jcc (1/5)
In reply to Richard HendersonCode movement to ease review, no logical change.
--- target/s390x/tcg/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/s390x/tcg/translate.c +4 -4
@@ -916,6 +916,10 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (0 );break ; +case 0x2 |0x1 :/* cc > 1 */ + cond =TCG_COND_GTU ; + c->u.s32.b =tcg_constant_i32 (1 ); +break ;case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ cond =TCG_COND_NE ; c->u.s32.a =tcg_temp_new_i32 ();
@@ -926,10 +930,6 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (1 );break ; -case 0x2 |0x1 :/* cc > 1 */ - cond =TCG_COND_GTU ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ;case 0x2 :/* cc == 2 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (2 );
Signature · 1 line
2.41.0
PATCH v3 2/6 target/s390x: Reorder CC_OP_STATIC switch case in disas_jcc (2/5)
In reply to Richard HendersonCode movement to ease review, no logical change.
--- target/s390x/tcg/translate.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
target/s390x/tcg/translate.c +12 -12
@@ -886,14 +886,26 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) c->is_64 = false; c->u.s32.a = cc_op;switch (mask) { +case 0x1 :/* cc == 3 */ + cond =TCG_COND_EQ ; + c->u.s32.b =tcg_constant_i32 (3 ); +break ;case 0x8 |0x4 |0x2 :/* cc != 3 */ cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (3 );break ; +case 0x2 :/* cc == 2 */ + cond =TCG_COND_EQ ; + c->u.s32.b =tcg_constant_i32 (2 ); +break ;case 0x8 |0x4 |0x1 :/* cc != 2 */ cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (2 );break ; +case 0x4 :/* cc == 1 */ + cond =TCG_COND_EQ ; + c->u.s32.b =tcg_constant_i32 (1 ); +break ;case 0x8 |0x2 |0x1 :/* cc != 1 */ cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (1 );
@@ -926,18 +938,6 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) c->u.s32.b =tcg_constant_i32 (0 );tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 );break ; -case 0x4 :/* cc == 1 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ; -case 0x2 :/* cc == 2 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ; -case 0x1 :/* cc == 3 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (3 ); -break ;default :/* CC is masked by something else: (8 >> cc) & mask. */ cond =TCG_COND_NE ;
Signature · 1 line
2.41.0
PATCH v3 3/6 target/s390x: Reorder CC_OP_STATIC switch case in disas_jcc (3/5)
In reply to Richard HendersonCode movement to ease review, no logical change.
--- target/s390x/tcg/translate.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
target/s390x/tcg/translate.c +12 -12
@@ -910,12 +910,6 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (1 );break ; -case 0x8 |0x2 :/* cc == 0 || cc == 2 => (cc & 1) == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); -break ;case 0x8 |0x4 :/* cc < 2 */ cond =TCG_COND_LTU ; c->u.s32.b =tcg_constant_i32 (2 );
@@ -924,6 +918,18 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (0 );break ; +case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ + cond =TCG_COND_NE ; + c->u.s32.a =tcg_temp_new_i32 (); + c->u.s32.b =tcg_constant_i32 (0 ); +tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); +break ; +case 0x8 |0x2 :/* cc == 0 || cc == 2 => (cc & 1) == 0 */ + cond =TCG_COND_EQ ; + c->u.s32.a =tcg_temp_new_i32 (); + c->u.s32.b =tcg_constant_i32 (0 ); +tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); +break ;case 0x4 |0x2 |0x1 :/* cc != 0 */ cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (0 );
@@ -932,12 +938,6 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_GTU ; c->u.s32.b =tcg_constant_i32 (1 );break ; -case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); -break ;default :/* CC is masked by something else: (8 >> cc) & mask. */ cond =TCG_COND_NE ;
Signature · 1 line
2.41.0
PATCH v3 4/6 target/s390x: Reorder CC_OP_STATIC switch case in disas_jcc (4/5)
In reply to Richard HendersonCode movement to ease review, no logical change.
--- target/s390x/tcg/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/s390x/tcg/translate.c +4 -4
@@ -914,10 +914,6 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_LTU ; c->u.s32.b =tcg_constant_i32 (2 );break ; -case 0x8 :/* cc == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (0 ); -break ;case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ cond =TCG_COND_NE ; c->u.s32.a =tcg_temp_new_i32 ();
@@ -938,6 +934,10 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_GTU ; c->u.s32.b =tcg_constant_i32 (1 );break ; +case 0x8 :/* cc == 0 */ + cond =TCG_COND_EQ ; + c->u.s32.b =tcg_constant_i32 (0 ); +break ;default :/* CC is masked by something else: (8 >> cc) & mask. */ cond =TCG_COND_NE ;
Signature · 1 line
2.41.0
PATCH v3 5/6 target/s390x: Reorder CC_OP_STATIC switch case in disas_jcc (5/5)
In reply to Richard HendersonCode movement to ease review, no logical change.
--- target/s390x/tcg/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/s390x/tcg/translate.c +4 -4
@@ -914,6 +914,10 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_LTU ; c->u.s32.b =tcg_constant_i32 (2 );break ; +case 0x2 |0x1 :/* cc > 1 */ + cond =TCG_COND_GTU ; + c->u.s32.b =tcg_constant_i32 (1 ); +break ;case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ cond =TCG_COND_NE ; c->u.s32.a =tcg_temp_new_i32 ();
@@ -930,10 +934,6 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (0 );break ; -case 0x2 |0x1 :/* cc > 1 */ - cond =TCG_COND_GTU ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ;case 0x8 :/* cc == 0 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (0 );
Signature · 1 line
2.41.0
PATCH v3 6/6 target/s390x: Improve general case of disas_jcc
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
Avoid code duplication by handling 7 of the 14 cases by inverting the test for the other 7 cases.
Use TCG_COND_TSTNE for cc in {1,3}.
Use (cc - 1) <= 1 for cc in {1,2}.
--- target/s390x/tcg/translate.c | 52 +++++++++++------------------------- 1 file changed, 15 insertions(+), 37 deletions(-)
target/s390x/tcg/translate.c +15 -37
@@ -885,67 +885,45 @@ static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)case CC_OP_STATIC : c->is_64 = false; c->u.s32.a = cc_op; -switch (mask) { + +/* Fold half of the cases using bit 3 to invert. */ +switch (mask &8 ? mask ^0xf : mask) {case 0x1 :/* cc == 3 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (3 );break ; -case 0x8 |0x4 |0x2 :/* cc != 3 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (3 ); -break ;case 0x2 :/* cc == 2 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (2 );break ; -case 0x8 |0x4 |0x1 :/* cc != 2 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ;case 0x4 :/* cc == 1 */ cond =TCG_COND_EQ ; c->u.s32.b =tcg_constant_i32 (1 );break ; -case 0x8 |0x2 |0x1 :/* cc != 1 */ - cond =TCG_COND_NE ; - c->u.s32.b =tcg_constant_i32 (1 ); -break ; -case 0x8 |0x4 :/* cc < 2 */ - cond =TCG_COND_LTU ; - c->u.s32.b =tcg_constant_i32 (2 ); -break ; -case 0x2 |0x1 :/* cc > 1 */ +case 0x2 |0x1 :/* cc == 2 || cc == 3 => cc > 1 */ cond =TCG_COND_GTU ; c->u.s32.b =tcg_constant_i32 (1 );break ;case 0x4 |0x1 :/* cc == 1 || cc == 3 => (cc & 1) != 0 */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); + cond =TCG_COND_TSTNE ; + c->u.s32.b =tcg_constant_i32 (1 );break ; -case 0x8 |0x2 :/* cc == 0 || cc == 2 => (cc & 1) == 0 */ - cond =TCG_COND_EQ ; +case 0x4 |0x2 :/* cc == 1 || cc == 2 => (cc - 1) <= 1 */ + cond =TCG_COND_LEU ; c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_andi_i32 (c->u.s32.a, cc_op,1 ); + c->u.s32.b =tcg_constant_i32 (1 ); +tcg_gen_addi_i32 (c->u.s32.a, cc_op,-1 );break ;case 0x4 |0x2 |0x1 :/* cc != 0 */ cond =TCG_COND_NE ; c->u.s32.b =tcg_constant_i32 (0 );break ; -case 0x8 :/* cc == 0 */ - cond =TCG_COND_EQ ; - c->u.s32.b =tcg_constant_i32 (0 ); -break ;default : -/* CC is masked by something else: (8 >> cc) & mask. */ - cond =TCG_COND_NE ; - c->u.s32.a =tcg_temp_new_i32 (); - c->u.s32.b =tcg_constant_i32 (0 ); -tcg_gen_shr_i32 (c->u.s32.a,tcg_constant_i32 (8 ), cc_op); -tcg_gen_andi_i32 (c->u.s32.a, c->u.s32.a, mask); -break ; +/* case 0: never, handled above. */ +g_assert_not_reached (); + } +if (mask &8 ) { + cond =tcg_invert_cond (cond); }break ;
Signature · 1 line
2.41.0
Re: [PATCH v3 15/38 6/6] target/s390x: Improve general case of disas_jcc
Quoted 5 lines · Philippe Mathieu-Daudé
From: Richard Henderson <[email protected]>
Avoid code duplication by handling 7 of the 14 cases by inverting the test for the other 7 cases.
Quoted 8 lines
Use
TCG_COND_TSTNEfor cc in {1,3}.
Use (cc - 1) <= 1 for cc in {1,2}.Signed-off-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/translate.c | 52 +++++++++++------------------------- 1 file changed, 15 insertions(+), 37 deletions(-)
Re: [PATCH v3 15/38 6/6] target/s390x: Improve general case of disas_jcc
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
From: Richard Henderson <[email protected]>
Avoid code duplication by handling 7 of the 14 cases by inverting the test for the other 7 cases.
Quoted 8 lines
Use
TCG_COND_TSTNEfor cc in {1,3}.
Use (cc - 1) <= 1 for cc in {1,2}.Signed-off-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/translate.c | 52 +++++++++++------------------------- 1 file changed, 15 insertions(+), 37 deletions(-)
PATCH v3 16/38 tcg: Add TCGConst argument to tcg_target_const_match
In reply to Richard HendersonFill the new argument from any condition within the opcode. Not yet used within any backend.
--- tcg/tcg.c | 34 ++++++++++++++++++++++++++++++-- tcg/aarch64/tcg-target.c.inc | 3 ++- tcg/arm/tcg-target.c.inc | 3 ++- tcg/i386/tcg-target.c.inc | 3 ++- tcg/loongarch64/tcg-target.c.inc | 3 ++- tcg/mips/tcg-target.c.inc | 3 ++- tcg/ppc/tcg-target.c.inc | 3 ++- tcg/riscv/tcg-target.c.inc | 3 ++- tcg/s390x/tcg-target.c.inc | 3 ++- tcg/sparc64/tcg-target.c.inc | 3 ++- tcg/tci/tcg-target.c.inc | 3 ++- 11 files changed, 52 insertions(+), 12 deletions(-)
tcg/tcg.c +32 -2
@@ -173,7 +173,8 @@ static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,static void tcg_out_call (TCGContext *s,const tcg_insn_unit *target,const TCGHelperInfo *info);static TCGReg tcg_target_call_oarg_reg (TCGCallReturnKind kind,int slot); -static bool tcg_target_const_match (int64_t val,TCGType type,int ct,int vece); +static bool tcg_target_const_match (int64_t val,int ct, +TCGType type,TCGCond cond,int vece);#ifdef TCG_TARGET_NEED_LDST_LABELS static int tcg_out_ldst_finalize (TCGContext *s);#endif
@@ -4786,6 +4787,7 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)TCGTemp *ts;TCGArg new_args[TCG_MAX_OP_ARGS ];int const_args[TCG_MAX_OP_ARGS ]; +TCGCond op_cond; nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs;
@@ -4798,6 +4800,33 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op) i_allocated_regs = s->reserved_regs; o_allocated_regs = s->reserved_regs; +switch (op->opc) { +case INDEX_op_brcond_i32: +case INDEX_op_brcond_i64: + op_cond = op->args[2 ]; +break ; +case INDEX_op_setcond_i32: +case INDEX_op_setcond_i64: +case INDEX_op_negsetcond_i32: +case INDEX_op_negsetcond_i64: +case INDEX_op_cmp_vec: + op_cond = op->args[3 ]; +break ; +case INDEX_op_brcond2_i32: + op_cond = op->args[4 ]; +break ; +case INDEX_op_movcond_i32: +case INDEX_op_movcond_i64: +case INDEX_op_setcond2_i32: +case INDEX_op_cmpsel_vec: + op_cond = op->args[5 ]; +break ; +default : +/* No condition within opcode. */ + op_cond =TCG_COND_ALWAYS ; +break ; + } +/* satisfy input constraints */ for (k =0 ; k < nb_iargs; k++) {TCGRegSet i_preferred_regs, i_required_regs;
@@ -4811,7 +4840,8 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op) ts =arg_temp (arg);if (ts->val_type ==TEMP_VAL_CONST - &&tcg_target_const_match (ts->val, ts->type, arg_ct->ct,TCGOP_VECE (op))) { + &&tcg_target_const_match (ts->val, arg_ct->ct, ts->type, + op_cond,TCGOP_VECE (op))) {/* constant is OK for instruction */ const_args[i] =1 ; new_args[i] = ts->val;
tcg/aarch64/tcg-target.c.inc +2 -1
@@ -270,7 +270,8 @@ static bool is_shimm1632(uint32_t v32, int *cmode, int *imm8) } } -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/arm/tcg-target.c.inc +2 -1
@@ -501,7 +501,8 @@ static bool is_shimm1632(uint32_t v32, int *cmode, int *imm8) * mov operand2: values represented with x << (2 * y), x < 0x100 * add, sub, eor...: ditto */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/i386/tcg-target.c.inc +2 -1
@@ -195,7 +195,8 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, } /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/loongarch64/tcg-target.c.inc +2 -1
@@ -183,7 +183,8 @@ static inline tcg_target_long sextreg(tcg_target_long val, int pos, int len) } /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return true;
tcg/mips/tcg-target.c.inc +2 -1
@@ -188,7 +188,8 @@ static bool is_p2m1(tcg_target_long val) } /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/ppc/tcg-target.c.inc +2 -1
@@ -282,7 +282,8 @@ static bool reloc_pc34(tcg_insn_unit *src_rw, const tcg_insn_unit *target) } /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/riscv/tcg-target.c.inc +2 -1
@@ -145,7 +145,8 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) #define sextreg sextract64 /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/s390x/tcg-target.c.inc +2 -1
@@ -538,7 +538,8 @@ static bool risbg_mask(uint64_t c) } /* Test if a constant matches the constraint. */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/sparc64/tcg-target.c.inc +2 -1
@@ -322,7 +322,8 @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type, } /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { return 1;
tcg/tci/tcg-target.c.inc +2 -1
@@ -913,7 +913,8 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, } /* Test if a constant matches the constraint. */ -static bool tcg_target_const_match(int64_t val, TCGType type, int ct, int vece) +static bool tcg_target_const_match(int64_t val, int ct, + TCGType type, TCGCond cond, int vece) { return ct & TCG_CT_CONST; }
Signature · 1 line
2.34.1
PATCH v3 17/38 tcg/aarch64: Support TCG_COND_TST{EQ,NE}
In reply to Richard Henderson--- tcg/aarch64/tcg-target-con-set.h | 5 +-- tcg/aarch64/tcg-target-con-str.h | 1 + tcg/aarch64/tcg-target.h | 2 +- tcg/aarch64/tcg-target.c.inc | 56 ++++++++++++++++++++++---------- 4 files changed, 44 insertions(+), 20 deletions(-)
tcg/aarch64/tcg-target-con-set.h +3 -2
@@ -10,7 +10,7 @@* tcg-target-con-str.h; the constraint combination is inclusive or. */ C_O0_I1(r) -C_O0_I2(r, rA) +C_O0_I2(r, rC) C_O0_I2(rZ, r) C_O0_I2(w, r) C_O0_I3(rZ, rZ, r)
@@ -22,6 +22,7 @@ C_O1_I2(r, 0, rZ) C_O1_I2(r, r, r) C_O1_I2(r, r, rA) C_O1_I2(r, r, rAL) +C_O1_I2(r, r, rC) C_O1_I2(r, r, ri) C_O1_I2(r, r, rL)C_O1_I2 (r, rZ, rZ)
@@ -31,6 +32,6 @@ C_O1_I2(w, w, wN) C_O1_I2(w, w, wO) C_O1_I2(w, w, wZ) C_O1_I3(w, w, w, w) -C_O1_I4(r, r, rA, rZ, rZ) +C_O1_I4(r, r, rC, rZ, rZ) C_O2_I1(r, r, r)C_O2_I4 (r, r, rZ, rZ, rA, rMZ)
tcg/aarch64/tcg-target-con-str.h +1 -0
@@ -16,6 +16,7 @@ REGS('w', ALL_VECTOR_REGS)* CONST(letter, TCG_CT_CONST_* bit set) */ CONST('A', TCG_CT_CONST_AIMM) +CONST('C', TCG_CT_CONST_CMP) CONST('L', TCG_CT_CONST_LIMM) CONST('M', TCG_CT_CONST_MONE)CONST ('O' ,TCG_CT_CONST_ORRI )
tcg/aarch64/tcg-target.h +1 -1
@@ -138,7 +138,7 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 1#endif -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1#define TCG_TARGET_HAS_v64 1#define TCG_TARGET_HAS_v128 1
tcg/aarch64/tcg-target.c.inc +39 -17
140 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 17/38] tcg/aarch64: Support TCG_COND_TST{EQ,NE}
Quoted 7 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target-con-set.h | 5 +-- tcg/aarch64/tcg-target-con-str.h | 1 + tcg/aarch64/tcg-target.h | 2 +- tcg/aarch64/tcg-target.c.inc | 56 ++++++++++++++++++++++---------- 4 files changed, 44 insertions(+), 20 deletions(-)
To the best of my Aarch64 knowledge:
PATCH v3 18/38 tcg/aarch64: Generate TBZ, TBNZ
In reply to Richard HendersonTest the sign bit for LT/GE vs 0, and TSTNE/EQ vs a power of 2.
--- tcg/aarch64/tcg-target.c.inc | 100 ++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 19 deletions(-)
tcg/aarch64/tcg-target.c.inc +81 -19
@@ -105,6 +105,18 @@ static bool reloc_pc19(tcg_insn_unit *src_rw, const tcg_insn_unit *target) return false; } +static bool reloc_pc14(tcg_insn_unit *src_rw, const tcg_insn_unit *target) +{ + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + ptrdiff_t offset = target - src_rx; + + if (offset == sextract64(offset, 0, 14)) { + *src_rw = deposit32(*src_rw, 5, 14, offset); + return true; + } + return false; +} + static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) {
@@ -115,6 +127,8 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, return reloc_pc26(code_ptr, (const tcg_insn_unit *)value); case R_AARCH64_CONDBR19: return reloc_pc19(code_ptr, (const tcg_insn_unit *)value); + case R_AARCH64_TSTBR14: + return reloc_pc14(code_ptr, (const tcg_insn_unit *)value); default: g_assert_not_reached(); }
@@ -380,6 +394,10 @@ typedef enum { /* Conditional branch (immediate). */ I3202_B_C = 0x54000000, + /* Test and branch (immediate). */ + I3205_TBZ = 0x36000000, + I3205_TBNZ = 0x37000000, + /* Unconditional branch (immediate). */ I3206_B = 0x14000000, I3206_BL = 0x94000000,
@@ -660,6 +678,14 @@ static void tcg_out_insn_3202(TCGContext *s, AArch64Insn insn, tcg_out32(s, insn | tcg_cond_to_aarch64[c] | (imm19 & 0x7ffff) << 5); } +static void tcg_out_insn_3205(TCGContext *s, AArch64Insn insn, + TCGReg rt, int imm6, int imm14) +{ + insn |= (imm6 & 0x20) << (31 - 5); + insn |= (imm6 & 0x1f) << 19; + tcg_out32(s, insn | (imm14 & 0x3fff) << 5 | rt); +} + static void tcg_out_insn_3206(TCGContext *s, AArch64Insn insn, int imm26) { tcg_out32(s, insn | (imm26 & 0x03ffffff));
@@ -1415,30 +1441,66 @@ static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l) static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, TCGArg b, bool b_const, TCGLabel *l) { - intptr_t offset; - bool need_cmp; + int tbit = -1; + bool need_cmp = true; - if (b_const && b == 0 && (c == TCG_COND_EQ || c == TCG_COND_NE)) { - need_cmp = false; - } else { - need_cmp = true; - tcg_out_cmp(s, ext, c, a, b, b_const); - } - - if (!l->has_value) { - tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); - offset = tcg_in32(s) >> 5; - } else { - offset = tcg_pcrel_diff(s, l->u.value_ptr) >> 2; - tcg_debug_assert(offset == sextract64(offset, 0, 19)); + switch (c) { + case TCG_COND_EQ: + case TCG_COND_NE: + if (b_const && b == 0) { + need_cmp = false; + } + break; + case TCG_COND_LT: + case TCG_COND_GE: + if (b_const && b == 0) { + c = (c == TCG_COND_LT ? TCG_COND_TSTNE : TCG_COND_TSTEQ); + tbit = ext ? 63 : 31; + need_cmp = false; + } + break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + if (b_const && is_power_of_2(b)) { + tbit = ctz64(b); + need_cmp = false; + } + break; + default: + break; } if (need_cmp) { - tcg_out_insn(s, 3202, B_C, c, offset); - } else if (c == TCG_COND_EQ) { - tcg_out_insn(s, 3201, CBZ, ext, a, offset); + tcg_out_cmp(s, ext, c, a, b, b_const); + tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); + tcg_out_insn(s, 3202, B_C, c, 0); + return; + } + + if (tbit >= 0) { + tcg_out_reloc(s, s->code_ptr, R_AARCH64_TSTBR14, l, 0); + switch (c) { + case TCG_COND_TSTEQ: + tcg_out_insn(s, 3205, TBZ, a, tbit, 0); + break; + case TCG_COND_TSTNE: + tcg_out_insn(s, 3205, TBNZ, a, tbit, 0); + break; + default: + g_assert_not_reached(); + } } else { - tcg_out_insn(s, 3201, CBNZ, ext, a, offset); + tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); + switch (c) { + case TCG_COND_EQ: + tcg_out_insn(s, 3201, CBZ, ext, a, 0); + break; + case TCG_COND_NE: + tcg_out_insn(s, 3201, CBNZ, ext, a, 0); + break; + default: + g_assert_not_reached(); + } } }
Signature · 1 line
2.34.1
PATCH v3 1/2 tcg/aarch64: Massage tcg_out_brcond()
In order to ease next commit review, modify tcg_out_brcond() to switch over TCGCond. No logical change intended.
--- tcg/aarch64/tcg-target.c.inc | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
tcg/aarch64/tcg-target.c.inc +23 -8
@@ -1416,12 +1416,20 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, TCGArg b, bool b_const, TCGLabel *l) { intptr_t offset; - bool need_cmp; + bool need_cmp = true; - if (b_const && b == 0 && (c == TCG_COND_EQ || c == TCG_COND_NE)) { - need_cmp = false; - } else { - need_cmp = true; + switch (c) { + case TCG_COND_EQ: + case TCG_COND_NE: + if (b_const && b == 0) { + need_cmp = false; + } + break; + default: + break; + } + + if (need_cmp) { tcg_out_cmp(s, ext, c, a, b, b_const); }
@@ -1435,10 +1443,17 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, if (need_cmp) { tcg_out_insn(s, 3202, B_C, c, offset); - } else if (c == TCG_COND_EQ) { - tcg_out_insn(s, 3201, CBZ, ext, a, offset); } else { - tcg_out_insn(s, 3201, CBNZ, ext, a, offset); + switch (c) { + case TCG_COND_EQ: + tcg_out_insn(s, 3201, CBZ, ext, a, offset); + break; + case TCG_COND_NE: + tcg_out_insn(s, 3201, CBNZ, ext, a, offset); + break; + default: + g_assert_not_reached(); + } } }
Signature · 1 line
2.41.0
PATCH v3 2/2 tcg/aarch64: Generate TBZ, TBNZ
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
Test the sign bit for LT/GE vs 0, and TSTNE/EQ vs a power of 2.
--- tcg/aarch64/tcg-target.c.inc | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 12 deletions(-)
tcg/aarch64/tcg-target.c.inc +59 -12
@@ -105,6 +105,18 @@ static bool reloc_pc19(tcg_insn_unit *src_rw, const tcg_insn_unit *target) return false; } +static bool reloc_pc14(tcg_insn_unit *src_rw, const tcg_insn_unit *target) +{ + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + ptrdiff_t offset = target - src_rx; + + if (offset == sextract64(offset, 0, 14)) { + *src_rw = deposit32(*src_rw, 5, 14, offset); + return true; + } + return false; +} + static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) {
@@ -115,6 +127,8 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, return reloc_pc26(code_ptr, (const tcg_insn_unit *)value); case R_AARCH64_CONDBR19: return reloc_pc19(code_ptr, (const tcg_insn_unit *)value); + case R_AARCH64_TSTBR14: + return reloc_pc14(code_ptr, (const tcg_insn_unit *)value); default: g_assert_not_reached(); }
@@ -380,6 +394,10 @@ typedef enum { /* Conditional branch (immediate). */ I3202_B_C = 0x54000000, + /* Test and branch (immediate). */ + I3205_TBZ = 0x36000000, + I3205_TBNZ = 0x37000000, + /* Unconditional branch (immediate). */ I3206_B = 0x14000000, I3206_BL = 0x94000000,
@@ -660,6 +678,14 @@ static void tcg_out_insn_3202(TCGContext *s, AArch64Insn insn, tcg_out32(s, insn | tcg_cond_to_aarch64[c] | (imm19 & 0x7ffff) << 5); } +static void tcg_out_insn_3205(TCGContext *s, AArch64Insn insn, + TCGReg rt, int imm6, int imm14) +{ + insn |= (imm6 & 0x20) << (31 - 5); + insn |= (imm6 & 0x1f) << 19; + tcg_out32(s, insn | (imm14 & 0x3fff) << 5 | rt); +} + static void tcg_out_insn_3206(TCGContext *s, AArch64Insn insn, int imm26) { tcg_out32(s, insn | (imm26 & 0x03ffffff));
@@ -1415,7 +1441,7 @@ static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l) static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, TCGArg b, bool b_const, TCGLabel *l) { - intptr_t offset; + int tbit = -1; bool need_cmp = true; switch (c) {
@@ -1425,31 +1451,52 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, need_cmp = false; } break; + case TCG_COND_LT: + case TCG_COND_GE: + if (b_const && b == 0) { + c = (c == TCG_COND_LT ? TCG_COND_TSTNE : TCG_COND_TSTEQ); + tbit = ext ? 63 : 31; + need_cmp = false; + } + break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + if (b_const && is_power_of_2(b)) { + tbit = ctz64(b); + need_cmp = false; + } + break; default: break; } if (need_cmp) { tcg_out_cmp(s, ext, c, a, b, b_const); - } - - if (!l->has_value) { tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); - offset = tcg_in32(s) >> 5; - } else { - offset = tcg_pcrel_diff(s, l->u.value_ptr) >> 2; - tcg_debug_assert(offset == sextract64(offset, 0, 19)); + tcg_out_insn(s, 3202, B_C, c, 0); + return; } - if (need_cmp) { - tcg_out_insn(s, 3202, B_C, c, offset); + if (tbit >= 0) { + tcg_out_reloc(s, s->code_ptr, R_AARCH64_TSTBR14, l, 0); + switch (c) { + case TCG_COND_TSTEQ: + tcg_out_insn(s, 3205, TBZ, a, tbit, 0); + break; + case TCG_COND_TSTNE: + tcg_out_insn(s, 3205, TBNZ, a, tbit, 0); + break; + default: + g_assert_not_reached(); + } } else { + tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); switch (c) { case TCG_COND_EQ: - tcg_out_insn(s, 3201, CBZ, ext, a, offset); + tcg_out_insn(s, 3201, CBZ, ext, a, 0); break; case TCG_COND_NE: - tcg_out_insn(s, 3201, CBNZ, ext, a, offset); + tcg_out_insn(s, 3201, CBNZ, ext, a, 0); break; default: g_assert_not_reached();
Signature · 1 line
2.41.0
PATCH v3 19/38 tcg/aarch64: Generate CBNZ for TSTNE of UINT32_MAX
In reply to Richard Henderson... and the inverse, CBZ for TSTEQ.
--- tcg/aarch64/tcg-target.c.inc | 8 ++++++++ 1 file changed, 8 insertions(+)
tcg/aarch64/tcg-target.c.inc +8 -0
@@ -1453,6 +1453,7 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, break; case TCG_COND_LT: case TCG_COND_GE: + /* cmp xN,0; b.mi L -> tbnz xN,63,L */ if (b_const && b == 0) { c = (c == TCG_COND_LT ? TCG_COND_TSTNE : TCG_COND_TSTEQ); tbit = ext ? 63 : 31;
@@ -1461,6 +1462,13 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, break; case TCG_COND_TSTEQ: case TCG_COND_TSTNE: + /* tst xN,0xffffffff; b.ne L -> cbnz wN,L */ + if (b_const && b == UINT32_MAX) { + ext = TCG_TYPE_I32; + need_cmp = false; + break; + } + /* tst xN,1<<B; b.ne L -> tbnz xN,B,L */ if (b_const && is_power_of_2(b)) { tbit = ctz64(b); need_cmp = false;
Signature · 1 line
2.34.1
Re: [PATCH v3 19/38] tcg/aarch64: Generate CBNZ for TSTNE of UINT32_MAX
Quoted 13 lines · Richard Henderson
... and the inverse, CBZ for TSTEQ.
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.c.inc | 8 ++++++++ 1 file changed, 8 insertions(+)tcg/aarch64/tcg-target.c.inc +0
-0
tcg/aarch64/tcg-target.c.inc static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, · line 1458
Quoted 6 lines
tcg/aarch64/tcg-target.c.inc +1
-0@@ -1453,6 +1453,7 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, break; case TCG_COND_LT: case TCG_COND_GE: + /* cmp xN,0; b.mi L -> tbnz xN,63,L */ if (b_const && b == 0) { c = (c == TCG_COND_LT ? TCG_COND_TSTNE : TCG_COND_TSTEQ);
This comment ...
tcg/aarch64/tcg-target.c.inc static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, · line 1471
Quoted 12 lines
tcg/aarch64/tcg-target.c.inc +7
-0tbit = ext ? 63 : 31;@@ -1461,6 +1462,13 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, break; case TCG_COND_TSTEQ: case TCG_COND_TSTNE: + /* tst xN,0xffffffff; b.ne L -> cbnz wN,L */ + if (b_const && b == UINT32_MAX) { + ext = TCG_TYPE_I32; + need_cmp = false; + break; + } + /* tst xN,1<<B; b.ne L -> tbnz xN,B,L */
... and this one belong to the previous patch. Otherwise:
Quoted 3 lines
tcg/aarch64/tcg-target.c.inc +0
-0if (b_const && is_power_of_2(b)) { tbit = ctz64(b); need_cmp = false;
PATCH v3 20/38 tcg/arm: Factor tcg_out_cmp() out
In reply to Richard HendersonMessage-Id: <[email protected]>
Message-Id: <[email protected]>
--- tcg/arm/tcg-target.c.inc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
tcg/arm/tcg-target.c.inc +17 -15
@@ -1191,6 +1191,13 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) } } +static TCGCond tcg_out_cmp(TCGContext *s, TCGCond cond, TCGReg a, + TCGArg b, int b_const) +{ + tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, a, b, b_const); + return cond; +} + static TCGCond tcg_out_cmp2(TCGContext *s, const TCGArg *args, const int *const_args) {
@@ -1806,9 +1813,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, /* Constraints mean that v2 is always in the same register as dest, * so we only need to do "if condition passed, move v1 to dest". */ - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, - args[1], args[2], const_args[2]); - tcg_out_dat_rIK(s, tcg_cond_to_arm_cond[args[5]], ARITH_MOV, + c = tcg_out_cmp(s, args[5], args[1], args[2], const_args[2]); + tcg_out_dat_rIK(s, tcg_cond_to_arm_cond[c], ARITH_MOV, ARITH_MVN, args[0], 0, args[3], const_args[3]); break; case INDEX_op_add_i32:
@@ -1958,25 +1964,21 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, break; case INDEX_op_brcond_i32: - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, - args[0], args[1], const_args[1]); - tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[2]], - arg_label(args[3])); + c = tcg_out_cmp(s, args[2], args[0], args[1], const_args[1]); + tcg_out_goto_label(s, tcg_cond_to_arm_cond[c], arg_label(args[3])); break; case INDEX_op_setcond_i32: - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, - args[1], args[2], const_args[2]); - tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[3]], + c = tcg_out_cmp(s, args[3], args[1], args[2], const_args[2]); + tcg_out_dat_imm(s, tcg_cond_to_arm_cond[c], ARITH_MOV, args[0], 0, 1); - tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[3])], + tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(c)], ARITH_MOV, args[0], 0, 0); break; case INDEX_op_negsetcond_i32: - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, - args[1], args[2], const_args[2]); - tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[3]], + c = tcg_out_cmp(s, args[3], args[1], args[2], const_args[2]); + tcg_out_dat_imm(s, tcg_cond_to_arm_cond[c], ARITH_MVN, args[0], 0, 0); - tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[3])], + tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(c)], ARITH_MOV, args[0], 0, 0); break;
Signature · 1 line
2.34.1
Re: [PATCH v3 20/38] tcg/arm: Factor tcg_out_cmp() out
Quoted 8 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
[PMD: Split from bigger patch, part 1/2]Signed-off-by Philippe Mathieu-Daudé <[email protected]>Message-Id: <[email protected]>
--- tcg/arm/tcg-target.c.inc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
PATCH v3 21/38 tcg/arm: Support TCG_COND_TST{EQ,NE}
In reply to Richard HendersonMessage-Id: <[email protected]>
Message-Id: <[email protected]>
--- tcg/arm/tcg-target.h | 2 +- tcg/arm/tcg-target.c.inc | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-)
tcg/arm/tcg-target.h +1 -1
@@ -125,7 +125,7 @@ extern bool use_neon_instructions;#define TCG_TARGET_HAS_qemu_ldst_i128 0 -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1#define TCG_TARGET_HAS_v64 use_neon_instructions#define TCG_TARGET_HAS_v128 use_neon_instructions
tcg/arm/tcg-target.c.inc +28 -1
@@ -1194,7 +1194,27 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) static TCGCond tcg_out_cmp(TCGContext *s, TCGCond cond, TCGReg a, TCGArg b, int b_const) { - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, a, b, b_const); + if (!is_tst_cond(cond)) { + tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, a, b, b_const); + return cond; + } + + cond = tcg_tst_eqne_cond(cond); + if (b_const) { + int imm12 = encode_imm(b); + + /* + * The compare constraints allow rIN, but TST does not support N. + * Be prepared to load the constant into a scratch register. + */ + if (imm12 >= 0) { + tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, a, imm12); + return cond; + } + tcg_out_movi32(s, COND_AL, TCG_REG_TMP, b); + b = TCG_REG_TMP; + } + tcg_out_dat_reg(s, COND_AL, ARITH_TST, 0, a, b, SHIFT_IMM_LSL(0)); return cond; }
@@ -1225,6 +1245,13 @@ static TCGCond tcg_out_cmp2(TCGContext *s, const TCGArg *args, tcg_out_dat_rI(s, COND_EQ, ARITH_CMP, 0, al, bl, const_bl); return cond; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + /* Similar, but with TST instead of CMP. */ + tcg_out_dat_rI(s, COND_AL, ARITH_TST, 0, ah, bh, const_bh); + tcg_out_dat_rI(s, COND_EQ, ARITH_TST, 0, al, bl, const_bl); + return tcg_tst_eqne_cond(cond); + case TCG_COND_LT: case TCG_COND_GE: /* We perform a double-word subtraction and examine the result.
Signature · 1 line
2.34.1
Re: [PATCH v3 21/38] tcg/arm: Support TCG_COND_TST{EQ,NE}
Quoted 9 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
[PMD: Split from bigger patch, part 2/2]Signed-off-by Philippe Mathieu-Daudé <[email protected]>Message-Id: <[email protected]>
--- tcg/arm/tcg-target.h | 2 +- tcg/arm/tcg-target.c.inc | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-)
PATCH v3 22/38 tcg/i386: Pass x86 condition codes to tcg_out_cmov
In reply to Richard HendersonHoist the tcg_cond_to_jcc index outside the function.
--- tcg/i386/tcg-target.c.inc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tcg/i386/tcg-target.c.inc +8 -8
@@ -1699,14 +1699,14 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, } #endif -static void tcg_out_cmov(TCGContext *s, TCGCond cond, int rexw, +static void tcg_out_cmov(TCGContext *s, int jcc, int rexw, TCGReg dest, TCGReg v1) { if (have_cmov) { - tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond] | rexw, dest, v1); + tcg_out_modrm(s, OPC_CMOVCC | jcc | rexw, dest, v1); } else { TCGLabel *over = gen_new_label(); - tcg_out_jxx(s, tcg_cond_to_jcc[tcg_invert_cond(cond)], over, 1); + tcg_out_jxx(s, jcc ^ 1, over, 1); tcg_out_mov(s, TCG_TYPE_I32, dest, v1); tcg_out_label(s, over); }
@@ -1717,7 +1717,7 @@ static void tcg_out_movcond(TCGContext *s, int rexw, TCGCond cond, TCGReg v1) { tcg_out_cmp(s, c1, c2, const_c2, rexw); - tcg_out_cmov(s, cond, rexw, dest, v1); + tcg_out_cmov(s, tcg_cond_to_jcc[cond], rexw, dest, v1); } static void tcg_out_ctz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1,
@@ -1729,12 +1729,12 @@ static void tcg_out_ctz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1, tcg_debug_assert(arg2 == (rexw ? 64 : 32)); } else { tcg_debug_assert(dest != arg2); - tcg_out_cmov(s, TCG_COND_LTU, rexw, dest, arg2); + tcg_out_cmov(s, JCC_JB, rexw, dest, arg2); } } else { tcg_debug_assert(dest != arg2); tcg_out_modrm(s, OPC_BSF + rexw, dest, arg1); - tcg_out_cmov(s, TCG_COND_EQ, rexw, dest, arg2); + tcg_out_cmov(s, JCC_JE, rexw, dest, arg2); } }
@@ -1747,7 +1747,7 @@ static void tcg_out_clz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1, tcg_debug_assert(arg2 == (rexw ? 64 : 32)); } else { tcg_debug_assert(dest != arg2); - tcg_out_cmov(s, TCG_COND_LTU, rexw, dest, arg2); + tcg_out_cmov(s, JCC_JB, rexw, dest, arg2); } } else { tcg_debug_assert(!const_a2);
@@ -1760,7 +1760,7 @@ static void tcg_out_clz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1, /* Since we have destroyed the flags from BSR, we have to re-test. */ tcg_out_cmp(s, arg1, 0, 1, rexw); - tcg_out_cmov(s, TCG_COND_EQ, rexw, dest, arg2); + tcg_out_cmov(s, JCC_JE, rexw, dest, arg2); } }
Signature · 1 line
2.34.1
PATCH v3 23/38 tcg/i386: Move tcg_cond_to_jcc[] into tcg_out_cmp
In reply to Richard HendersonReturn the x86 condition codes to use after the compare.
--- tcg/i386/tcg-target.c.inc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
tcg/i386/tcg-target.c.inc +13 -11
@@ -1449,8 +1449,8 @@ static void tcg_out_jxx(TCGContext *s, int opc, TCGLabel *l, bool small) } } -static void tcg_out_cmp(TCGContext *s, TCGArg arg1, TCGArg arg2, - int const_arg2, int rexw) +static int tcg_out_cmp(TCGContext *s, TCGCond cond, TCGArg arg1, + TCGArg arg2, int const_arg2, int rexw) { if (const_arg2) { if (arg2 == 0) {
@@ -1462,14 +1462,15 @@ static void tcg_out_cmp(TCGContext *s, TCGArg arg1, TCGArg arg2, } else { tgen_arithr(s, ARITH_CMP + rexw, arg1, arg2); } + return tcg_cond_to_jcc[cond]; } static void tcg_out_brcond(TCGContext *s, int rexw, TCGCond cond, TCGArg arg1, TCGArg arg2, int const_arg2, TCGLabel *label, bool small) { - tcg_out_cmp(s, arg1, arg2, const_arg2, rexw); - tcg_out_jxx(s, tcg_cond_to_jcc[cond], label, small); + int jcc = tcg_out_cmp(s, cond, arg1, arg2, const_arg2, rexw); + tcg_out_jxx(s, jcc, label, small); } #if TCG_TARGET_REG_BITS == 32
@@ -1561,6 +1562,7 @@ static void tcg_out_setcond(TCGContext *s, int rexw, TCGCond cond, { bool inv = false; bool cleared; + int jcc; switch (cond) { case TCG_COND_NE:
@@ -1597,7 +1599,7 @@ static void tcg_out_setcond(TCGContext *s, int rexw, TCGCond cond, * We can then use NEG or INC to produce the desired result. * This is always smaller than the SETCC expansion. */ - tcg_out_cmp(s, arg1, arg2, const_arg2, rexw); + tcg_out_cmp(s, TCG_COND_LTU, arg1, arg2, const_arg2, rexw); /* X - X - C = -C = (C ? -1 : 0) */ tgen_arithr(s, ARITH_SBB + (neg ? rexw : 0), dest, dest);
@@ -1644,8 +1646,8 @@ static void tcg_out_setcond(TCGContext *s, int rexw, TCGCond cond, cleared = true; } - tcg_out_cmp(s, arg1, arg2, const_arg2, rexw); - tcg_out_modrm(s, OPC_SETCC | tcg_cond_to_jcc[cond], 0, dest); + jcc = tcg_out_cmp(s, cond, arg1, arg2, const_arg2, rexw); + tcg_out_modrm(s, OPC_SETCC | jcc, 0, dest); if (!cleared) { tcg_out_ext8u(s, dest, dest);
@@ -1716,8 +1718,8 @@ static void tcg_out_movcond(TCGContext *s, int rexw, TCGCond cond, TCGReg dest, TCGReg c1, TCGArg c2, int const_c2, TCGReg v1) { - tcg_out_cmp(s, c1, c2, const_c2, rexw); - tcg_out_cmov(s, tcg_cond_to_jcc[cond], rexw, dest, v1); + int jcc = tcg_out_cmp(s, cond, c1, c2, const_c2, rexw); + tcg_out_cmov(s, jcc, rexw, dest, v1); } static void tcg_out_ctz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1,
@@ -1759,8 +1761,8 @@ static void tcg_out_clz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1, tgen_arithi(s, ARITH_XOR + rexw, dest, rexw ? 63 : 31, 0); /* Since we have destroyed the flags from BSR, we have to re-test. */ - tcg_out_cmp(s, arg1, 0, 1, rexw); - tcg_out_cmov(s, JCC_JE, rexw, dest, arg2); + int jcc = tcg_out_cmp(s, TCG_COND_EQ, arg1, 0, 1, rexw); + tcg_out_cmov(s, jcc, rexw, dest, arg2); } }
Signature · 1 line
2.34.1
PATCH v3 24/38 tcg/i386: Support TCG_COND_TST{EQ,NE}
In reply to Richard HendersonMerge tcg_out_testi into tcg_out_cmp and adjust the two uses.
--- tcg/i386/tcg-target.h | 2 +- tcg/i386/tcg-target.c.inc | 95 ++++++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 37 deletions(-)
tcg/i386/tcg-target.h +1 -1
@@ -198,7 +198,7 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 \ (TCG_TARGET_REG_BITS == 64 && (cpuinfo & CPUINFO_ATOMIC_VMOVDQA)) -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1/* We do not support older SSE systems, only beginning with AVX1. */ #define TCG_TARGET_HAS_v64 have_avx1
tcg/i386/tcg-target.c.inc +59 -36
157 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 25/38 tcg/i386: Improve TSTNE/TESTEQ vs powers of two
In reply to Richard HendersonUse "test x,x" when the bit is one of the 4 sign bits. Use "bt imm,x" otherwise.
--- tcg/i386/tcg-target-con-set.h | 6 ++-- tcg/i386/tcg-target-con-str.h | 1 + tcg/i386/tcg-target.c.inc | 54 +++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 8 deletions(-)
tcg/i386/tcg-target-con-set.h +3 -3
@@ -20,7 +20,7 @@ C_O0_I2(L, L) C_O0_I2(qi, r) C_O0_I2(re, r) C_O0_I2(ri, r) -C_O0_I2(r, re) +C_O0_I2(r, reT) C_O0_I2(s, L) C_O0_I2(x, r)C_O0_I3 (L ,L ,L )
@@ -34,7 +34,7 @@ C_O1_I1(r, r) C_O1_I1(x, r) C_O1_I1(x, x) C_O1_I2(q, 0, qi) -C_O1_I2(q, r, re) +C_O1_I2(q, r, reT) C_O1_I2(r, 0, ci) C_O1_I2(r, 0, r)C_O1_I2 (r,0 , re)
@@ -50,7 +50,7 @@ C_N1_I2(r, r, r) C_N1_I2(r, r, rW) C_O1_I3(x, 0, x, x) C_O1_I3(x, x, x, x) -C_O1_I4(r, r, re, r, 0) +C_O1_I4(r, r, reT, r, 0) C_O1_I4(r, r, r, ri, ri) C_O2_I1(r, r, L)C_O2_I2 (a, d, a, r)
tcg/i386/tcg-target-con-str.h +1 -0
@@ -28,5 +28,6 @@ REGS('s', ALL_BYTEL_REGS & ~SOFTMMU_RESERVE_REGS) /* qemu_st8_i32 data */*/ CONST('e', TCG_CT_CONST_S32) CONST('I', TCG_CT_CONST_I32) +CONST('T', TCG_CT_CONST_TST) CONST('W', TCG_CT_CONST_WSZ)CONST ('Z' ,TCG_CT_CONST_U32 )
tcg/i386/tcg-target.c.inc +49 -5
128 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 26/38 tcg/i386: Use TEST r,r to test 8/16/32 bits
In reply to Richard HendersonFrom: Paolo Bonzini <[email protected]>
Just like when testing against the sign bits, TEST r,r can be used when the immediate is 0xff, 0xff00, 0xffff, 0xffffffff.
--- tcg/i386/tcg-target.c.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
tcg/i386/tcg-target.c.inc +17 -0
@@ -1501,6 +1501,10 @@ static int tcg_out_cmp(TCGContext *s, TCGCond cond, TCGArg arg1, tcg_out_modrm(s, OPC_TESTB | P_REXB_R, arg1, arg1); return js; } + if (arg2 == 0xff) { + tcg_out_modrm(s, OPC_TESTB | P_REXB_R, arg1, arg1); + return jz; + } tcg_out_modrm(s, OPC_GRP3_Eb | P_REXB_RM, EXT3_TESTi, arg1); tcg_out8(s, arg2); return jz;
@@ -1511,11 +1515,24 @@ static int tcg_out_cmp(TCGContext *s, TCGCond cond, TCGArg arg1, tcg_out_modrm(s, OPC_TESTB, arg1 + 4, arg1 + 4); return js; } + if (arg2 == 0xff00) { + tcg_out_modrm(s, OPC_TESTB, arg1 + 4, arg1 + 4); + return jz; + } tcg_out_modrm(s, OPC_GRP3_Eb, EXT3_TESTi, arg1 + 4); tcg_out8(s, arg2 >> 8); return jz; } + if (arg2 == 0xffff) { + tcg_out_modrm(s, OPC_TESTL | P_DATA16, arg1, arg1); + return jz; + } + if (arg2 == 0xffffffffu) { + tcg_out_modrm(s, OPC_TESTL, arg1, arg1); + return jz; + } + if (is_power_of_2(rexw ? arg2 : (uint32_t)arg2)) { int jc = (cond == TCG_COND_TSTNE ? JCC_JB : JCC_JAE); int sh = ctz64(arg2);
Signature · 1 line
2.34.1
Re: [PATCH v3 26/38] tcg/i386: Use TEST r,r to test 8/16/32 bits
Quoted 11 lines · Richard Henderson
From: Paolo Bonzini <[email protected]>
Just like when testing against the sign bits, TEST r,r can be used when the immediate is
0xff,0xff00,0xffff,0xffffffff.Signed-off-by Paolo Bonzini <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.c.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
PATCH v3 27/38 tcg/sparc64: Hoist read of tcg_cond_to_rcond
In reply to Richard HendersonUse a non-zero value here (an illegal encoding) as a better condition than is_unsigned_cond for when MOVR/BPR is usable.
--- tcg/sparc64/tcg-target.c.inc | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
tcg/sparc64/tcg-target.c.inc +14 -11
@@ -620,7 +620,7 @@ static const uint8_t tcg_cond_to_bcond[] = { [TCG_COND_GTU] = COND_GU, }; -static const uint8_t tcg_cond_to_rcond[] = { +static const uint8_t tcg_cond_to_rcond[16] = { [TCG_COND_EQ] = RCOND_Z, [TCG_COND_NE] = RCOND_NZ, [TCG_COND_LT] = RCOND_LZ,
@@ -679,7 +679,8 @@ static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, TCGReg arg1, int32_t arg2, int const_arg2, TCGLabel *l) { /* For 64-bit signed comparisons vs zero, we can avoid the compare. */ - if (arg2 == 0 && !is_unsigned_cond(cond)) { + int rcond = tcg_cond_to_rcond[cond]; + if (arg2 == 0 && rcond) { int off16 = 0; if (l->has_value) {
@@ -688,7 +689,7 @@ static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, TCGReg arg1, tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP16, l, 0); } tcg_out32(s, INSN_OP(0) | INSN_OP2(3) | BPR_PT | INSN_RS1(arg1) - | INSN_COND(tcg_cond_to_rcond[cond]) | off16); + | INSN_COND(rcond) | off16); } else { tcg_out_cmp(s, arg1, arg2, const_arg2); tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_XCC | BPCC_PT, l);
@@ -696,11 +697,10 @@ static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, TCGReg arg1, tcg_out_nop(s); } -static void tcg_out_movr(TCGContext *s, TCGCond cond, TCGReg ret, TCGReg c1, +static void tcg_out_movr(TCGContext *s, int rcond, TCGReg ret, TCGReg c1, int32_t v1, int v1const) { - tcg_out32(s, ARITH_MOVR | INSN_RD(ret) | INSN_RS1(c1) - | (tcg_cond_to_rcond[cond] << 10) + tcg_out32(s, ARITH_MOVR | INSN_RD(ret) | INSN_RS1(c1) | (rcond << 10) | (v1const ? INSN_IMM10(v1) : INSN_RS2(v1))); }
@@ -711,9 +711,9 @@ static void tcg_out_movcond_i64(TCGContext *s, TCGCond cond, TCGReg ret, /* For 64-bit signed comparisons vs zero, we can avoid the compare. Note that the immediate range is one bit smaller, so we must check for that as well. */ - if (c2 == 0 && !is_unsigned_cond(cond) - && (!v1const || check_fit_i32(v1, 10))) { - tcg_out_movr(s, cond, ret, c1, v1, v1const); + int rcond = tcg_cond_to_rcond[cond]; + if (c2 == 0 && rcond && (!v1const || check_fit_i32(v1, 10))) { + tcg_out_movr(s, rcond, ret, c1, v1, v1const); } else { tcg_out_cmp(s, c1, c2, c2const); tcg_out_movcc(s, cond, MOVCC_XCC, ret, v1, v1const);
@@ -788,6 +788,8 @@ static void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGReg ret, static void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGReg ret, TCGReg c1, int32_t c2, int c2const, bool neg) { + int rcond; + if (use_vis3_instructions && !neg) { switch (cond) { case TCG_COND_NE:
@@ -807,9 +809,10 @@ static void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGReg ret, /* For 64-bit signed comparisons vs zero, we can avoid the compare if the input does not overlap the output. */ - if (c2 == 0 && !is_unsigned_cond(cond) && c1 != ret) { + rcond = tcg_cond_to_rcond[cond]; + if (c2 == 0 && rcond && c1 != ret) { tcg_out_movi_s13(s, ret, 0); - tcg_out_movr(s, cond, ret, c1, neg ? -1 : 1, 1); + tcg_out_movr(s, rcond, ret, c1, neg ? -1 : 1, 1); } else { tcg_out_cmp(s, c1, c2, c2const); tcg_out_movi_s13(s, ret, 0);
Signature · 1 line
2.34.1
PATCH v3 28/38 tcg/sparc64: Pass TCGCond to tcg_out_cmp
In reply to Richard Henderson--- tcg/sparc64/tcg-target.c.inc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
tcg/sparc64/tcg-target.c.inc +11 -10
@@ -646,7 +646,8 @@ static void tcg_out_bpcc(TCGContext *s, int scond, int flags, TCGLabel *l) tcg_out_bpcc0(s, scond, flags, off19); } -static void tcg_out_cmp(TCGContext *s, TCGReg c1, int32_t c2, int c2const) +static void tcg_out_cmp(TCGContext *s, TCGCond cond, + TCGReg c1, int32_t c2, int c2const) { tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, ARITH_SUBCC); }
@@ -654,7 +655,7 @@ static void tcg_out_cmp(TCGContext *s, TCGReg c1, int32_t c2, int c2const) static void tcg_out_brcond_i32(TCGContext *s, TCGCond cond, TCGReg arg1, int32_t arg2, int const_arg2, TCGLabel *l) { - tcg_out_cmp(s, arg1, arg2, const_arg2); + tcg_out_cmp(s, cond, arg1, arg2, const_arg2); tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_ICC | BPCC_PT, l); tcg_out_nop(s); }
@@ -671,7 +672,7 @@ static void tcg_out_movcond_i32(TCGContext *s, TCGCond cond, TCGReg ret, TCGReg c1, int32_t c2, int c2const, int32_t v1, int v1const) { - tcg_out_cmp(s, c1, c2, c2const); + tcg_out_cmp(s, cond, c1, c2, c2const); tcg_out_movcc(s, cond, MOVCC_ICC, ret, v1, v1const); }
@@ -691,7 +692,7 @@ static void tcg_out_brcond_i64(TCGContext *s, TCGCond cond, TCGReg arg1, tcg_out32(s, INSN_OP(0) | INSN_OP2(3) | BPR_PT | INSN_RS1(arg1) | INSN_COND(rcond) | off16); } else { - tcg_out_cmp(s, arg1, arg2, const_arg2); + tcg_out_cmp(s, cond, arg1, arg2, const_arg2); tcg_out_bpcc(s, tcg_cond_to_bcond[cond], BPCC_XCC | BPCC_PT, l); } tcg_out_nop(s);
@@ -715,7 +716,7 @@ static void tcg_out_movcond_i64(TCGContext *s, TCGCond cond, TCGReg ret, if (c2 == 0 && rcond && (!v1const || check_fit_i32(v1, 10))) { tcg_out_movr(s, rcond, ret, c1, v1, v1const); } else { - tcg_out_cmp(s, c1, c2, c2const); + tcg_out_cmp(s, cond, c1, c2, c2const); tcg_out_movcc(s, cond, MOVCC_XCC, ret, v1, v1const); } }
@@ -759,13 +760,13 @@ static void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGReg ret, /* FALLTHRU */ default: - tcg_out_cmp(s, c1, c2, c2const); + tcg_out_cmp(s, cond, c1, c2, c2const); tcg_out_movi_s13(s, ret, 0); tcg_out_movcc(s, cond, MOVCC_ICC, ret, neg ? -1 : 1, 1); return; } - tcg_out_cmp(s, c1, c2, c2const); + tcg_out_cmp(s, cond, c1, c2, c2const); if (cond == TCG_COND_LTU) { if (neg) { /* 0 - 0 - C = -C = (C ? -1 : 0) */
@@ -799,7 +800,7 @@ static void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGReg ret, c2 = c1, c2const = 0, c1 = TCG_REG_G0; /* FALLTHRU */ case TCG_COND_LTU: - tcg_out_cmp(s, c1, c2, c2const); + tcg_out_cmp(s, cond, c1, c2, c2const); tcg_out_arith(s, ret, TCG_REG_G0, TCG_REG_G0, ARITH_ADDXC); return; default:
@@ -814,7 +815,7 @@ static void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGReg ret, tcg_out_movi_s13(s, ret, 0); tcg_out_movr(s, rcond, ret, c1, neg ? -1 : 1, 1); } else { - tcg_out_cmp(s, c1, c2, c2const); + tcg_out_cmp(s, cond, c1, c2, c2const); tcg_out_movi_s13(s, ret, 0); tcg_out_movcc(s, cond, MOVCC_XCC, ret, neg ? -1 : 1, 1); }
@@ -1102,7 +1103,7 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, tcg_out_movi_s32(s, TCG_REG_T3, compare_mask); tcg_out_arith(s, TCG_REG_T3, addr_reg, TCG_REG_T3, ARITH_AND); } - tcg_out_cmp(s, TCG_REG_T2, TCG_REG_T3, 0); + tcg_out_cmp(s, TCG_COND_NE, TCG_REG_T2, TCG_REG_T3, 0); ldst = new_ldst_label(s); ldst->is_ld = is_ld;
Signature · 1 line
2.34.1
PATCH v3 29/38 tcg/sparc64: Support TCG_COND_TST{EQ,NE}
In reply to Richard Henderson--- tcg/sparc64/tcg-target.h | 2 +- tcg/sparc64/tcg-target.c.inc | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)
tcg/sparc64/tcg-target.h +1 -1
@@ -149,7 +149,7 @@ extern bool use_vis3_instructions;#define TCG_TARGET_HAS_qemu_ldst_i128 0 -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1#define TCG_AREG0 TCG_REG_I0
tcg/sparc64/tcg-target.c.inc +14 -2
@@ -607,9 +607,11 @@ static void tcg_out_div32(TCGContext *s, TCGReg rd, TCGReg rs1, uns ? ARITH_UDIV : ARITH_SDIV); } -static const uint8_t tcg_cond_to_bcond[] = { +static const uint8_t tcg_cond_to_bcond[16] = { [TCG_COND_EQ] = COND_E, [TCG_COND_NE] = COND_NE, + [TCG_COND_TSTEQ] = COND_E, + [TCG_COND_TSTNE] = COND_NE, [TCG_COND_LT] = COND_L, [TCG_COND_GE] = COND_GE, [TCG_COND_LE] = COND_LE,
@@ -649,7 +651,8 @@ static void tcg_out_bpcc(TCGContext *s, int scond, int flags, TCGLabel *l) static void tcg_out_cmp(TCGContext *s, TCGCond cond, TCGReg c1, int32_t c2, int c2const) { - tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, ARITH_SUBCC); + tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, + is_tst_cond(cond) ? ARITH_ANDCC : ARITH_SUBCC); } static void tcg_out_brcond_i32(TCGContext *s, TCGCond cond, TCGReg arg1,
@@ -744,6 +747,15 @@ static void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGReg ret, cond = (cond == TCG_COND_EQ ? TCG_COND_GEU : TCG_COND_LTU); break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + /* Transform to inequality vs zero. */ + tcg_out_arithc(s, TCG_REG_T1, c1, c2, c2const, ARITH_AND); + c1 = TCG_REG_G0; + c2 = TCG_REG_T1, c2const = 0; + cond = (cond == TCG_COND_TSTEQ ? TCG_COND_GEU : TCG_COND_LTU); + break; + case TCG_COND_GTU: case TCG_COND_LEU: /* If we don't need to load a constant into a register, we can
Signature · 1 line
2.34.1
PATCH v3 30/38 tcg/ppc: Sink tcg_to_bc usage into tcg_out_bc
In reply to Richard HendersonRename the current tcg_out_bc function to tcg_out_bc_lab, and create a new function that takes an integer displacement + link.
--- tcg/ppc/tcg-target.c.inc | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
tcg/ppc/tcg-target.c.inc +17 -11
@@ -1946,14 +1946,20 @@ static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond, } } -static void tcg_out_bc(TCGContext *s, int bc, TCGLabel *l) +static void tcg_out_bc(TCGContext *s, TCGCond cond, int bd) { + tcg_out32(s, tcg_to_bc[cond] | bd); +} + +static void tcg_out_bc_lab(TCGContext *s, TCGCond cond, TCGLabel *l) +{ + int bd = 0; if (l->has_value) { - bc |= reloc_pc14_val(tcg_splitwx_to_rx(s->code_ptr), l->u.value_ptr); + bd = reloc_pc14_val(tcg_splitwx_to_rx(s->code_ptr), l->u.value_ptr); } else { tcg_out_reloc(s, s->code_ptr, R_PPC_REL14, l, 0); } - tcg_out32(s, bc); + tcg_out_bc(s, cond, bd); } static void tcg_out_brcond(TCGContext *s, TCGCond cond,
@@ -1961,7 +1967,7 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGLabel *l, TCGType type) { tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type); - tcg_out_bc(s, tcg_to_bc[cond], l); + tcg_out_bc_lab(s, cond, l); } static void tcg_out_movcond(TCGContext *s, TCGType type, TCGCond cond,
@@ -2003,7 +2009,7 @@ static void tcg_out_movcond(TCGContext *s, TCGType type, TCGCond cond, } } /* Branch forward over one insn */ - tcg_out32(s, tcg_to_bc[cond] | 8); + tcg_out_bc(s, cond, 8); if (v2 == 0) { tcg_out_movi(s, type, dest, 0); } else {
@@ -2024,11 +2030,11 @@ static void tcg_out_cntxz(TCGContext *s, TCGType type, uint32_t opc, tcg_out32(s, opc | RA(TCG_REG_R0) | RS(a1)); tcg_out32(s, tcg_to_isel[TCG_COND_EQ] | TAB(a0, a2, TCG_REG_R0)); } else if (!const_a2 && a0 == a2) { - tcg_out32(s, tcg_to_bc[TCG_COND_EQ] | 8); + tcg_out_bc(s, TCG_COND_EQ, 8); tcg_out32(s, opc | RA(a0) | RS(a1)); } else { tcg_out32(s, opc | RA(a0) | RS(a1)); - tcg_out32(s, tcg_to_bc[TCG_COND_NE] | 8); + tcg_out_bc(s, TCG_COND_NE, 8); if (const_a2) { tcg_out_movi(s, type, a0, 0); } else {
@@ -2108,11 +2114,11 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, tcg_out_rlw(s, RLWINM, args[0], TCG_REG_R0, 31, 31, 31); } -static void tcg_out_brcond2 (TCGContext *s, const TCGArg *args, - const int *const_args) +static void tcg_out_brcond2(TCGContext *s, const TCGArg *args, + const int *const_args) { tcg_out_cmp2(s, args, const_args); - tcg_out_bc(s, BC | BI(7, CR_EQ) | BO_COND_TRUE, arg_label(args[5])); + tcg_out_bc_lab(s, TCG_COND_EQ, arg_label(args[5])); } static void tcg_out_mb(TCGContext *s, TCGArg a0)
@@ -2446,7 +2452,7 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, /* Load a pointer into the current opcode w/conditional branch-link. */ ldst->label_ptr[0] = s->code_ptr; - tcg_out32(s, BC | BI(7, CR_EQ) | BO_COND_FALSE | LK); + tcg_out_bc(s, TCG_COND_NE, LK); h->base = TCG_REG_TMP1; } else {
Signature · 1 line
2.34.1
PATCH v3 31/38 tcg/ppc: Use cr0 in tcg_to_bc and tcg_to_isel
In reply to Richard HendersonUsing cr0 means we could choose to use rc=1 to compute the condition. Adjust the tables and tcg_out_cmp that feeds them.
--- tcg/ppc/tcg-target.c.inc | 68 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-)
tcg/ppc/tcg-target.c.inc +34 -34
@@ -671,30 +671,30 @@ enum { }; static const uint32_t tcg_to_bc[] = { - [TCG_COND_EQ] = BC | BI(7, CR_EQ) | BO_COND_TRUE, - [TCG_COND_NE] = BC | BI(7, CR_EQ) | BO_COND_FALSE, - [TCG_COND_LT] = BC | BI(7, CR_LT) | BO_COND_TRUE, - [TCG_COND_GE] = BC | BI(7, CR_LT) | BO_COND_FALSE, - [TCG_COND_LE] = BC | BI(7, CR_GT) | BO_COND_FALSE, - [TCG_COND_GT] = BC | BI(7, CR_GT) | BO_COND_TRUE, - [TCG_COND_LTU] = BC | BI(7, CR_LT) | BO_COND_TRUE, - [TCG_COND_GEU] = BC | BI(7, CR_LT) | BO_COND_FALSE, - [TCG_COND_LEU] = BC | BI(7, CR_GT) | BO_COND_FALSE, - [TCG_COND_GTU] = BC | BI(7, CR_GT) | BO_COND_TRUE, + [TCG_COND_EQ] = BC | BI(0, CR_EQ) | BO_COND_TRUE, + [TCG_COND_NE] = BC | BI(0, CR_EQ) | BO_COND_FALSE, + [TCG_COND_LT] = BC | BI(0, CR_LT) | BO_COND_TRUE, + [TCG_COND_GE] = BC | BI(0, CR_LT) | BO_COND_FALSE, + [TCG_COND_LE] = BC | BI(0, CR_GT) | BO_COND_FALSE, + [TCG_COND_GT] = BC | BI(0, CR_GT) | BO_COND_TRUE, + [TCG_COND_LTU] = BC | BI(0, CR_LT) | BO_COND_TRUE, + [TCG_COND_GEU] = BC | BI(0, CR_LT) | BO_COND_FALSE, + [TCG_COND_LEU] = BC | BI(0, CR_GT) | BO_COND_FALSE, + [TCG_COND_GTU] = BC | BI(0, CR_GT) | BO_COND_TRUE, }; /* The low bit here is set if the RA and RB fields must be inverted. */ static const uint32_t tcg_to_isel[] = { - [TCG_COND_EQ] = ISEL | BC_(7, CR_EQ), - [TCG_COND_NE] = ISEL | BC_(7, CR_EQ) | 1, - [TCG_COND_LT] = ISEL | BC_(7, CR_LT), - [TCG_COND_GE] = ISEL | BC_(7, CR_LT) | 1, - [TCG_COND_LE] = ISEL | BC_(7, CR_GT) | 1, - [TCG_COND_GT] = ISEL | BC_(7, CR_GT), - [TCG_COND_LTU] = ISEL | BC_(7, CR_LT), - [TCG_COND_GEU] = ISEL | BC_(7, CR_LT) | 1, - [TCG_COND_LEU] = ISEL | BC_(7, CR_GT) | 1, - [TCG_COND_GTU] = ISEL | BC_(7, CR_GT), + [TCG_COND_EQ] = ISEL | BC_(0, CR_EQ), + [TCG_COND_NE] = ISEL | BC_(0, CR_EQ) | 1, + [TCG_COND_LT] = ISEL | BC_(0, CR_LT), + [TCG_COND_GE] = ISEL | BC_(0, CR_LT) | 1, + [TCG_COND_LE] = ISEL | BC_(0, CR_GT) | 1, + [TCG_COND_GT] = ISEL | BC_(0, CR_GT), + [TCG_COND_LTU] = ISEL | BC_(0, CR_LT), + [TCG_COND_GEU] = ISEL | BC_(0, CR_LT) | 1, + [TCG_COND_LEU] = ISEL | BC_(0, CR_GT) | 1, + [TCG_COND_GTU] = ISEL | BC_(0, CR_GT), }; static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
@@ -1827,7 +1827,7 @@ static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond, if (have_isa_3_10) { tcg_insn_unit bi, opc; - tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type); + tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 0, type); /* Re-use tcg_to_bc for BI and BO_COND_{TRUE,FALSE}. */ bi = tcg_to_bc[cond] & (0x1f << 16);
@@ -1880,7 +1880,7 @@ static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond, if (have_isel) { int isel, tab; - tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type); + tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 0, type); isel = tcg_to_isel[cond];
@@ -1966,7 +1966,7 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGArg arg1, TCGArg arg2, int const_arg2, TCGLabel *l, TCGType type) { - tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type); + tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 0, type); tcg_out_bc_lab(s, cond, l); }
@@ -1980,7 +1980,7 @@ static void tcg_out_movcond(TCGContext *s, TCGType type, TCGCond cond, return; } - tcg_out_cmp(s, cond, c1, c2, const_c2, 7, type); + tcg_out_cmp(s, cond, c1, c2, const_c2, 0, type); if (have_isel) { int isel = tcg_to_isel[cond];
@@ -2024,7 +2024,7 @@ static void tcg_out_cntxz(TCGContext *s, TCGType type, uint32_t opc, if (const_a2 && a2 == (type == TCG_TYPE_I32 ? 32 : 64)) { tcg_out32(s, opc | RA(a0) | RS(a1)); } else { - tcg_out_cmp(s, TCG_COND_EQ, a1, 0, 1, 7, type); + tcg_out_cmp(s, TCG_COND_EQ, a1, 0, 1, 0, type); /* Note that the only other valid constant for a2 is 0. */ if (have_isel) { tcg_out32(s, opc | RA(TCG_REG_R0) | RS(a1));
@@ -2079,7 +2079,7 @@ static void tcg_out_cmp2(TCGContext *s, const TCGArg *args, do_equality: tcg_out_cmp(s, cond, al, bl, blconst, 6, TCG_TYPE_I32); tcg_out_cmp(s, cond, ah, bh, bhconst, 7, TCG_TYPE_I32); - tcg_out32(s, op | BT(7, CR_EQ) | BA(6, CR_EQ) | BB(7, CR_EQ)); + tcg_out32(s, op | BT(0, CR_EQ) | BA(6, CR_EQ) | BB(7, CR_EQ)); break; case TCG_COND_LT:
@@ -2097,8 +2097,8 @@ static void tcg_out_cmp2(TCGContext *s, const TCGArg *args, tcg_out_cmp(s, cond, ah, bh, bhconst, 6, TCG_TYPE_I32); tcg_out_cmp(s, cond2, al, bl, blconst, 7, TCG_TYPE_I32); - tcg_out32(s, op | BT(7, CR_EQ) | BA(6, CR_EQ) | BB(7, bit2)); - tcg_out32(s, CROR | BT(7, CR_EQ) | BA(6, bit1) | BB(7, CR_EQ)); + tcg_out32(s, op | BT(0, CR_EQ) | BA(6, CR_EQ) | BB(7, bit2)); + tcg_out32(s, CROR | BT(0, CR_EQ) | BA(6, bit1) | BB(0, CR_EQ)); break; default:
@@ -2110,8 +2110,8 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, const int *const_args) { tcg_out_cmp2(s, args + 1, const_args + 1); - tcg_out32(s, MFOCRF | RT(TCG_REG_R0) | FXM(7)); - tcg_out_rlw(s, RLWINM, args[0], TCG_REG_R0, 31, 31, 31); + tcg_out32(s, MFOCRF | RT(TCG_REG_R0) | FXM(0)); + tcg_out_rlw(s, RLWINM, args[0], TCG_REG_R0, CR_EQ + 0*4 + 1, 31, 31); } static void tcg_out_brcond2(TCGContext *s, const TCGArg *args,
@@ -2442,12 +2442,12 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, tcg_out_cmp(s, TCG_COND_EQ, addrhi, TCG_REG_TMP2, 0, 6, TCG_TYPE_I32); - /* Combine comparisons into cr7. */ - tcg_out32(s, CRAND | BT(7, CR_EQ) | BA(6, CR_EQ) | BB(7, CR_EQ)); + /* Combine comparisons into cr0. */ + tcg_out32(s, CRAND | BT(0, CR_EQ) | BA(6, CR_EQ) | BB(7, CR_EQ)); } else { - /* Full comparison into cr7. */ + /* Full comparison into cr0. */ tcg_out_cmp(s, TCG_COND_EQ, TCG_REG_R0, TCG_REG_TMP2, - 0, 7, addr_type); + 0, 0, addr_type); } /* Load a pointer into the current opcode w/conditional branch-link. */
Signature · 1 line
2.34.1
Re: [PATCH v3 31/38] tcg/ppc: Use cr0 in tcg_to_bc and tcg_to_isel
Quoted 7 lines · Richard Henderson
Using cr0 means we could choose to use rc=1 to compute the condition. Adjust the tables and
tcg_out_cmpthat feeds them.Signed-off-by Richard Henderson <[email protected]>--- tcg/ppc/tcg-target.c.inc | 68 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-)
PATCH v3 32/38 tcg/ppc: Tidy up tcg_target_const_match
In reply to Richard Henderson--- tcg/ppc/tcg-target.c.inc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
tcg/ppc/tcg-target.c.inc +16 -11
@@ -282,31 +282,36 @@ static bool reloc_pc34(tcg_insn_unit *src_rw, const tcg_insn_unit *target) } /* test if a constant matches the constraint */ -static bool tcg_target_const_match(int64_t val, int ct, +static bool tcg_target_const_match(int64_t sval, int ct, TCGType type, TCGCond cond, int vece) { + uint64_t uval = sval; + if (ct & TCG_CT_CONST) { return 1; } - /* The only 32-bit constraint we use aside from - TCG_CT_CONST is TCG_CT_CONST_S16. */ if (type == TCG_TYPE_I32) { - val = (int32_t)val; + uval = (uint32_t)sval; + sval = (int32_t)sval; } - if ((ct & TCG_CT_CONST_S16) && val == (int16_t)val) { + if ((ct & TCG_CT_CONST_S16) && sval == (int16_t)sval) { return 1; - } else if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) { + } + if ((ct & TCG_CT_CONST_S32) && sval == (int32_t)sval) { return 1; - } else if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) { + } + if ((ct & TCG_CT_CONST_U32) && uval == (uint32_t)uval) { return 1; - } else if ((ct & TCG_CT_CONST_ZERO) && val == 0) { + } + if ((ct & TCG_CT_CONST_ZERO) && sval == 0) { return 1; - } else if ((ct & TCG_CT_CONST_MONE) && val == -1) { + } + if ((ct & TCG_CT_CONST_MONE) && sval == -1) { return 1; - } else if ((ct & TCG_CT_CONST_WSZ) - && val == (type == TCG_TYPE_I32 ? 32 : 64)) { + } + if ((ct & TCG_CT_CONST_WSZ) && sval == (type == TCG_TYPE_I32 ? 32 : 64)) { return 1; } return 0;
Signature · 1 line
2.34.1
PATCH v3 33/38 tcg/ppc: Add TCG_CT_CONST_CMP
In reply to Richard HendersonBetter constraint for tcg_out_cmp, based on the comparison. We can't yet remove the fallback to load constants into a scratch because of tcg_out_cmp2, but that path should not be as frequent.
--- tcg/ppc/tcg-target-con-set.h | 5 ++-- tcg/ppc/tcg-target-con-str.h | 1 + tcg/ppc/tcg-target.c.inc | 48 ++++++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 10 deletions(-)
tcg/ppc/tcg-target-con-set.h +3 -2
@@ -11,7 +11,7 @@*/ C_O0_I1(r) C_O0_I2(r, r) -C_O0_I2(r, ri) +C_O0_I2(r, rC) C_O0_I2(v, r) C_O0_I3(r, r, r) C_O0_I3(o, m, r)
@@ -26,13 +26,14 @@ C_O1_I2(r, rI, ri) C_O1_I2(r, rI, rT) C_O1_I2(r, r, r) C_O1_I2(r, r, ri) +C_O1_I2(r, r, rC) C_O1_I2(r, r, rI) C_O1_I2(r, r, rT) C_O1_I2(r, r, rU) C_O1_I2(r, r, rZW) C_O1_I2(v, v, v) C_O1_I3(v, v, v, v) -C_O1_I4(r, r, ri, rZ, rZ) +C_O1_I4(r, r, rC, rZ, rZ) C_O1_I4(r, r, r, ri, ri) C_O2_I1(r, r, r)C_N1O1_I1 (o, m, r)
tcg/ppc/tcg-target-con-str.h +1 -0
@@ -16,6 +16,7 @@ REGS('v', ALL_VECTOR_REGS)* Define constraint letters for constants: * CONST(letter, TCG_CT_CONST_* bit set) */ +CONST('C', TCG_CT_CONST_CMP) CONST('I', TCG_CT_CONST_S16) CONST('M', TCG_CT_CONST_MONE)CONST ('T' ,TCG_CT_CONST_S32 )
tcg/ppc/tcg-target.c.inc +40 -8
94 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 33/38] tcg/ppc: Add TCG_CT_CONST_CMP
Quoted 11 lines · Richard Henderson
Better constraint for
tcg_out_cmp, based on the comparison. We can't yet remove the fallback to load constants into a scratch because oftcg_out_cmp2, but that path should not be as frequent.Signed-off-by Richard Henderson <[email protected]>--- tcg/ppc/tcg-target-con-set.h | 5 ++-- tcg/ppc/tcg-target-con-str.h | 1 + tcg/ppc/tcg-target.c.inc | 48 ++++++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 10 deletions(-)
PATCH v3 34/38 tcg/ppc: Support TCG_COND_TST{EQ,NE}
In reply to Richard Henderson--- tcg/ppc/tcg-target.h | 2 +- tcg/ppc/tcg-target.c.inc | 122 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 115 insertions(+), 9 deletions(-)
tcg/ppc/tcg-target.h +1 -1
@@ -143,7 +143,7 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 \ (TCG_TARGET_REG_BITS == 64 && have_isa_2_07) -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1/* * While technically Altivec could support V64, it has no 64-bit store
tcg/ppc/tcg-target.c.inc +114 -8
192 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 34/38] tcg/ppc: Support TCG_COND_TST{EQ,NE}
Quoted 214 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/ppc/tcg-target.h | 2 +- tcg/ppc/tcg-target.c.inc | 122 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 115 insertions(+), 9 deletions(-)tcg/ppc/tcg-target.h +1
-1@@ -143,7 +143,7 @@ typedef enum {#define TCG_TARGET_HAS_qemu_ldst_i128 \ (TCG_TARGET_REG_BITS == 64 && have_isa_2_07) -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1/* * While technically Altivec could support V64, it has no 64-bit store tcg/ppc/tcg-target.c.inc +107
-8@@ -283,11 +283,15 @@ static bool reloc_pc34(tcg_insn_unit *src_rw, const tcg_insn_unit *target) return false; } +static bool mask_operand(uint32_t c, int *mb, int *me); +static bool mask64_operand(uint64_t c, int *mb, int *me); + /* test if a constant matches the constraint */ static bool tcg_target_const_match(int64_t sval, int ct, TCGType type, TCGCond cond, int vece) { uint64_t uval = sval; + int mb, me; if (ct & TCG_CT_CONST) { return 1;@@ -316,6 +320,17 @@ static bool tcg_target_const_match(int64_t sval, int ct, case TCG_COND_GTU: ct |= TCG_CT_CONST_U16; break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + if ((uval & ~0xffff) == 0 || (uval & ~0xffff0000ull) == 0) { + return 1; + } + if (TCG_TARGET_REG_BITS == 32 || type == TCG_TYPE_I32 + ? mask_operand(uval, &mb, &me) + : mask64_operand(uval << clz64(uval), &mb, &me)) { + return 1; + } + return 0; default: g_assert_not_reached(); }@@ -703,9 +718,11 @@ enum { CR_SO }; -static const uint32_t tcg_to_bc[] = { +static const uint32_t tcg_to_bc[16] = { [TCG_COND_EQ] = BC | BI(0, CR_EQ) | BO_COND_TRUE, [TCG_COND_NE] = BC | BI(0, CR_EQ) | BO_COND_FALSE, + [TCG_COND_TSTEQ] = BC | BI(0, CR_EQ) | BO_COND_TRUE, + [TCG_COND_TSTNE] = BC | BI(0, CR_EQ) | BO_COND_FALSE, [TCG_COND_LT] = BC | BI(0, CR_LT) | BO_COND_TRUE, [TCG_COND_GE] = BC | BI(0, CR_LT) | BO_COND_FALSE, [TCG_COND_LE] = BC | BI(0, CR_GT) | BO_COND_FALSE,@@ -717,9 +734,11 @@ static const uint32_t tcg_to_bc[] = { }; /* The low bit here is set if the RA and RB fields must be inverted. */ -static const uint32_t tcg_to_isel[] = { +static const uint32_t tcg_to_isel[16] = { [TCG_COND_EQ] = ISEL | BC_(0, CR_EQ), [TCG_COND_NE] = ISEL | BC_(0, CR_EQ) | 1, + [TCG_COND_TSTEQ] = ISEL | BC_(0, CR_EQ), + [TCG_COND_TSTNE] = ISEL | BC_(0, CR_EQ) | 1, [TCG_COND_LT] = ISEL | BC_(0, CR_LT), [TCG_COND_GE] = ISEL | BC_(0, CR_LT) | 1, [TCG_COND_LE] = ISEL | BC_(0, CR_GT) | 1,@@ -872,19 +891,31 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) return true; } -static inline void tcg_out_rld(TCGContext *s, int op, TCGReg ra, TCGReg rs, - int sh, int mb) +static void tcg_out_rld_rc(TCGContext *s, int op, TCGReg ra, TCGReg rs, + int sh, int mb, bool rc) { tcg_debug_assert(TCG_TARGET_REG_BITS == 64); sh = SH(sh & 0x1f) | (((sh >> 5) & 1) << 1); mb = MB64((mb >> 5) | ((mb << 1) & 0x3f)); - tcg_out32(s, op | RA(ra) | RS(rs) | sh | mb); + tcg_out32(s, op | RA(ra) | RS(rs) | sh | mb | rc); } -static inline void tcg_out_rlw(TCGContext *s, int op, TCGReg ra, TCGReg rs, - int sh, int mb, int me) +static void tcg_out_rld(TCGContext *s, int op, TCGReg ra, TCGReg rs, + int sh, int mb) { - tcg_out32(s, op | RA(ra) | RS(rs) | SH(sh) | MB(mb) | ME(me)); + tcg_out_rld_rc(s, op, ra, rs, sh, mb, false); +} + +static void tcg_out_rlw_rc(TCGContext *s, int op, TCGReg ra, TCGReg rs, + int sh, int mb, int me, bool rc) +{ + tcg_out32(s, op | RA(ra) | RS(rs) | SH(sh) | MB(mb) | ME(me) | rc); +} + +static void tcg_out_rlw(TCGContext *s, int op, TCGReg ra, TCGReg rs, + int sh, int mb, int me) +{ + tcg_out_rlw_rc(s, op, ra, rs, sh, mb, me, false); } static void tcg_out_ext8s(TCGContext *s, TCGType type, TCGReg dst, TCGReg src)@@ -1702,6 +1733,50 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, return false; } +/* + * Set dest non-zero if and only if (arg1 & arg2) is non-zero. + * If RC, then also set RC0. + */ +static void tcg_out_test(TCGContext *s, TCGReg dest, TCGReg arg1, TCGArg arg2, + bool const_arg2, TCGType type, bool rc) +{ + int mb, me; + + if (!const_arg2) { + tcg_out32(s, AND | SAB(arg1, dest, arg2) | rc); + return; + } + + if (type == TCG_TYPE_I32) { + arg2 = (uint32_t)arg2; + } else if (arg2 == (uint32_t)arg2) { + type = TCG_TYPE_I32; + } + + if ((arg2 & ~0xffff) == 0) { + tcg_out32(s, ANDI | SAI(arg1, dest, arg2)); + return; + } + if ((arg2 & ~0xffff0000ull) == 0) { + tcg_out32(s, ANDIS | SAI(arg1, dest, arg2 >> 16)); + return; + } + if (TCG_TARGET_REG_BITS == 32 || type == TCG_TYPE_I32) { + if (mask_operand(arg2, &mb, &me)) { + tcg_out_rlw_rc(s, RLWINM, dest, arg1, 0, mb, me, rc); + return; + } + } else { + int sh = clz64(arg2); + if (mask64_operand(arg2 << sh, &mb, &me)) { + tcg_out_rld_rc(s, RLDICR, dest, arg1, sh, me, rc); + return; + } + } + /* Constraints should satisfy this. */ + g_assert_not_reached(); +} + static void tcg_out_cmp(TCGContext *s, int cond, TCGArg arg1, TCGArg arg2, int const_arg2, int cr, TCGType type) {@@ -1736,6 +1811,12 @@ static void tcg_out_cmp(TCGContext *s, int cond, TCGArg arg1, TCGArg arg2, imm = 0; break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + tcg_debug_assert(cr == 0); + tcg_out_test(s, TCG_REG_R0, arg1, arg2, const_arg2, type, true); + return; + case TCG_COND_LT: case TCG_COND_GE: case TCG_COND_LE:@@ -1946,6 +2027,16 @@ static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond, tcg_out_setcond_ne0(s, type, arg0, arg1, neg); break; + case TCG_COND_TSTEQ: + tcg_out_test(s, TCG_REG_R0, arg1, arg2, const_arg2, type, false); + tcg_out_setcond_eq0(s, type, arg0, TCG_REG_R0, neg); + break; + + case TCG_COND_TSTNE: + tcg_out_test(s, TCG_REG_R0, arg1, arg2, const_arg2, type, false); + tcg_out_setcond_ne0(s, type, arg0, TCG_REG_R0, neg); + break; + case TCG_COND_LE: case TCG_COND_LEU: inv = true;@@ -2118,6 +2209,21 @@ static void tcg_out_cmp2(TCGContext *s, const TCGArg *args, tcg_out32(s, op | BT(0, CR_EQ) | BA(6, CR_EQ) | BB(7, CR_EQ)); break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + if (blconst) { + tcg_out_andi32(s, TCG_REG_R0, al, bl); + } else { + tcg_out32(s, AND | SAB(al, TCG_REG_R0, bl)); + } + if (bhconst) {
tcg/ppc/tcg-target.c.inc static void tcg_out_cmp2(TCGContext *s, const TCGArg *args, · line 2229
Quoted 10 lines
tcg/ppc/tcg-target.c.inc +7
-0+ tcg_out_andi32(s, TCG_REG_TMP1, ah, bh); + } else { + tcg_out32(s, AND | SAB(ah, TCG_REG_TMP1, bh)); + } + tcg_out32(s, OR | SAB(TCG_REG_R0, TCG_REG_R0, TCG_REG_TMP1) | 1); + break; + case TCG_COND_LT: case TCG_COND_LE: case TCG_COND_GT:
To the best of my PPC knowledge:
PATCH v3 35/38 tcg/s390x: Split constraint A into J+U
In reply to Richard HendersonSigned 33-bit == signed 32-bit + unsigned 32-bit.
--- tcg/s390x/tcg-target-con-set.h | 8 ++++---- tcg/s390x/tcg-target-con-str.h | 2 +- tcg/s390x/tcg-target.c.inc | 36 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 23 deletions(-)
tcg/s390x/tcg-target-con-set.h +4 -4
@@ -15,7 +15,7 @@ C_O0_I1(r) C_O0_I2(r, r) C_O0_I2(r, ri) -C_O0_I2(r, rA) +C_O0_I2(r, rJU) C_O0_I2(v, r) C_O0_I3(o, m, r) C_O1_I1(r, r)
@@ -27,7 +27,7 @@ C_O1_I2(r, 0, rI) C_O1_I2(r, 0, rJ) C_O1_I2(r, r, r) C_O1_I2(r, r, ri) -C_O1_I2(r, r, rA) +C_O1_I2(r, r, rJU) C_O1_I2(r, r, rI) C_O1_I2(r, r, rJ)C_O1_I2 (r, r, rK)
@@ -39,10 +39,10 @@ C_O1_I2(v, v, r) C_O1_I2(v, v, v) C_O1_I3(v, v, v, v) C_O1_I4(r, r, ri, rI, r) -C_O1_I4(r, r, rA, rI, r) +C_O1_I4(r, r, rJU, rI, r) C_O2_I1(o, m, r) C_O2_I2(o, m, 0, r) C_O2_I2(o, m, r, r) C_O2_I3(o, m, 0, 1, r) C_N1_O1_I4(r, r, 0, 1, ri, r) -C_N1_O1_I4 (r, r,0 ,1 , rA, r) +C_N1_O1_I4 (r, r,0 ,1 , rJU, r)
tcg/s390x/tcg-target-con-str.h +1 -1
@@ -16,10 +16,10 @@ REGS('o', 0xaaaa) /* odd numbered general regs */* Define constraint letters for constants: * CONST(letter, TCG_CT_CONST_* bit set) */ -CONST('A', TCG_CT_CONST_S33) CONST('I', TCG_CT_CONST_S16) CONST('J', TCG_CT_CONST_S32) CONST('K', TCG_CT_CONST_P32) CONST('N', TCG_CT_CONST_INV) CONST('R', TCG_CT_CONST_INVRISBG) +CONST('U', TCG_CT_CONST_U32)CONST ('Z' ,TCG_CT_CONST_ZERO )
tcg/s390x/tcg-target.c.inc +18 -18
@@ -30,7 +30,7 @@ #define TCG_CT_CONST_S16 (1 << 8) #define TCG_CT_CONST_S32 (1 << 9) -#define TCG_CT_CONST_S33 (1 << 10) +#define TCG_CT_CONST_U32 (1 << 10) #define TCG_CT_CONST_ZERO (1 << 11) #define TCG_CT_CONST_P32 (1 << 12) #define TCG_CT_CONST_INV (1 << 13)
@@ -542,22 +542,23 @@ static bool tcg_target_const_match(int64_t val, int ct, TCGType type, TCGCond cond, int vece) { if (ct & TCG_CT_CONST) { - return 1; + return true; } - if (type == TCG_TYPE_I32) { val = (int32_t)val; } - /* The following are mutually exclusive. */ - if (ct & TCG_CT_CONST_S16) { - return val == (int16_t)val; - } else if (ct & TCG_CT_CONST_S32) { - return val == (int32_t)val; - } else if (ct & TCG_CT_CONST_S33) { - return val >= -0xffffffffll && val <= 0xffffffffll; - } else if (ct & TCG_CT_CONST_ZERO) { - return val == 0; + if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) { + return true; + } + if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) { + return true; + } + if ((ct & TCG_CT_CONST_S16) && val == (int16_t)val) { + return true; + } + if ((ct & TCG_CT_CONST_ZERO) && val == 0) { + return true; } if (ct & TCG_CT_CONST_INV) {
@@ -573,8 +574,7 @@ static bool tcg_target_const_match(int64_t val, int ct, if ((ct & TCG_CT_CONST_INVRISBG) && risbg_mask(~val)) { return true; } - - return 0; + return false; } /* Emit instructions according to the given instruction format. */
@@ -3137,7 +3137,7 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) return C_O1_I2(r, r, ri); case INDEX_op_setcond_i64: case INDEX_op_negsetcond_i64: - return C_O1_I2(r, r, rA); + return C_O1_I2(r, r, rJU); case INDEX_op_clz_i64: return C_O1_I2(r, r, rI);
@@ -3187,7 +3187,7 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_brcond_i32: return C_O0_I2(r, ri); case INDEX_op_brcond_i64: - return C_O0_I2(r, rA); + return C_O0_I2(r, rJU); case INDEX_op_bswap16_i32: case INDEX_op_bswap16_i64:
@@ -3240,7 +3240,7 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_movcond_i32: return C_O1_I4(r, r, ri, rI, r); case INDEX_op_movcond_i64: - return C_O1_I4(r, r, rA, rI, r); + return C_O1_I4(r, r, rJU, rI, r); case INDEX_op_div2_i32: case INDEX_op_div2_i64:
@@ -3259,7 +3259,7 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_add2_i64: case INDEX_op_sub2_i64: - return C_N1_O1_I4(r, r, 0, 1, rA, r); + return C_N1_O1_I4(r, r, 0, 1, rJU, r); case INDEX_op_st_vec: return C_O0_I2(v, r);
Signature · 1 line
2.34.1
Re: [PATCH v3 35/38] tcg/s390x: Split constraint A into J+U
Quoted 8 lines · Richard Henderson
Signed 33-bit == signed 32-bit + unsigned 32-bit.
Signed-off-by Richard Henderson <[email protected]>--- tcg/s390x/tcg-target-con-set.h | 8 ++++---- tcg/s390x/tcg-target-con-str.h | 2 +- tcg/s390x/tcg-target.c.inc | 36 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 23 deletions(-)
PATCH v3 36/38 tcg/s390x: Add TCG_CT_CONST_CMP
In reply to Richard HendersonBetter constraint for tcg_out_cmp, based on the comparison.
--- tcg/s390x/tcg-target-con-set.h | 6 +-- tcg/s390x/tcg-target-con-str.h | 1 + tcg/s390x/tcg-target.c.inc | 72 +++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 21 deletions(-)
tcg/s390x/tcg-target-con-set.h +3 -3
@@ -15,7 +15,7 @@ C_O0_I1(r) C_O0_I2(r, r) C_O0_I2(r, ri) -C_O0_I2(r, rJU) +C_O0_I2(r, rC) C_O0_I2(v, r) C_O0_I3(o, m, r) C_O1_I1(r, r)
@@ -27,7 +27,7 @@ C_O1_I2(r, 0, rI) C_O1_I2(r, 0, rJ) C_O1_I2(r, r, r) C_O1_I2(r, r, ri) -C_O1_I2(r, r, rJU) +C_O1_I2(r, r, rC) C_O1_I2(r, r, rI) C_O1_I2(r, r, rJ)C_O1_I2 (r, r, rK)
@@ -39,7 +39,7 @@ C_O1_I2(v, v, r) C_O1_I2(v, v, v) C_O1_I3(v, v, v, v) C_O1_I4(r, r, ri, rI, r) -C_O1_I4(r, r, rJU, rI, r) +C_O1_I4(r, r, rC, rI, r) C_O2_I1(o, m, r) C_O2_I2(o, m, 0, r)C_O2_I2 (o, m, r, r)
tcg/s390x/tcg-target-con-str.h +1 -0
@@ -16,6 +16,7 @@ REGS('o', 0xaaaa) /* odd numbered general regs */* Define constraint letters for constants: * CONST(letter, TCG_CT_CONST_* bit set) */ +CONST('C', TCG_CT_CONST_CMP) CONST('I', TCG_CT_CONST_S16) CONST('J', TCG_CT_CONST_S32)CONST ('K' ,TCG_CT_CONST_P32 )
tcg/s390x/tcg-target.c.inc +54 -18
109 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 36/38] tcg/s390x: Add TCG_CT_CONST_CMP
Quoted 8 lines · Richard Henderson
Better constraint for
tcg_out_cmp, based on the comparison.Signed-off-by Richard Henderson <[email protected]>--- tcg/s390x/tcg-target-con-set.h | 6 +-- tcg/s390x/tcg-target-con-str.h | 1 + tcg/s390x/tcg-target.c.inc | 72 +++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 21 deletions(-)
PATCH v3 37/38 tcg/s390x: Support TCG_COND_TST{EQ,NE}
In reply to Richard Henderson--- tcg/s390x/tcg-target.h | 2 +- tcg/s390x/tcg-target.c.inc | 139 +++++++++++++++++++++++++------------ 2 files changed, 97 insertions(+), 44 deletions(-)
tcg/s390x/tcg-target.h +1 -1
@@ -138,7 +138,7 @@ extern uint64_t s390_facilities[3];#define TCG_TARGET_HAS_qemu_ldst_i128 1 -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1#define TCG_TARGET_HAS_v64 HAVE_FACILITY(VECTOR)#define TCG_TARGET_HAS_v128 HAVE_FACILITY(VECTOR)
tcg/s390x/tcg-target.c.inc +96 -43
223 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 37/38] tcg/s390x: Support TCG_COND_TST{EQ,NE}
+Ilya/David
Quoted 257 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/s390x/tcg-target.h | 2 +- tcg/s390x/tcg-target.c.inc | 139 +++++++++++++++++++++++++------------ 2 files changed, 97 insertions(+), 44 deletions(-)tcg/s390x/tcg-target.h +1
-1@@ -138,7 +138,7 @@ extern uint64_t s390_facilities[3];#define TCG_TARGET_HAS_qemu_ldst_i128 1 -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1#define TCG_TARGET_HAS_v64 HAVE_FACILITY(VECTOR)#define TCG_TARGET_HAS_v128 HAVE_FACILITY(VECTOR)tcg/s390x/tcg-target.c.inc +96
-43@@ -112,6 +112,9 @@ typedef enum S390Opcode { RI_OILH = 0xa50a, RI_OILL = 0xa50b, RI_TMLL = 0xa701, + RI_TMLH = 0xa700, + RI_TMHL = 0xa703, + RI_TMHH = 0xa702, RIEb_CGRJ = 0xec64, RIEb_CLGRJ = 0xec65,@@ -404,10 +407,15 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) #define S390_CC_NEVER 0 #define S390_CC_ALWAYS 15 +#define S390_TM_EQ 8 /* CC == 0 */ +#define S390_TM_NE 7 /* CC in {1,2,3} */ + /* Condition codes that result from a COMPARE and COMPARE LOGICAL. */ -static const uint8_t tcg_cond_to_s390_cond[] = { +static const uint8_t tcg_cond_to_s390_cond[16] = { [TCG_COND_EQ] = S390_CC_EQ, [TCG_COND_NE] = S390_CC_NE, + [TCG_COND_TSTEQ] = S390_CC_EQ, + [TCG_COND_TSTNE] = S390_CC_NE, [TCG_COND_LT] = S390_CC_LT, [TCG_COND_LE] = S390_CC_LE, [TCG_COND_GT] = S390_CC_GT,@@ -421,9 +429,11 @@ static const uint8_t tcg_cond_to_s390_cond[] = { /* Condition codes that result from a LOAD AND TEST. Here, we have no unsigned instruction variation, however since the test is vs zero we can re-map the outcomes appropriately. */ -static const uint8_t tcg_cond_to_ltr_cond[] = { +static const uint8_t tcg_cond_to_ltr_cond[16] = { [TCG_COND_EQ] = S390_CC_EQ, [TCG_COND_NE] = S390_CC_NE, + [TCG_COND_TSTEQ] = S390_CC_ALWAYS, + [TCG_COND_TSTNE] = S390_CC_NEVER, [TCG_COND_LT] = S390_CC_LT, [TCG_COND_LE] = S390_CC_LE, [TCG_COND_GT] = S390_CC_GT,@@ -542,10 +552,13 @@ static bool risbg_mask(uint64_t c) static bool tcg_target_const_match(int64_t val, int ct, TCGType type, TCGCond cond, int vece) { + uint64_t uval = val; + if (ct & TCG_CT_CONST) { return true; } if (type == TCG_TYPE_I32) { + uval = (uint32_t)val; val = (int32_t)val; }@@ -567,6 +580,15 @@ static bool tcg_target_const_match(int64_t val, int ct, case TCG_COND_GTU: ct |= TCG_CT_CONST_U32; /* CLGFI */ break; + case TCG_COND_TSTNE: + case TCG_COND_TSTEQ: + if (is_const_p16(uval) >= 0) { + return true; /* TMxx */ + } + if (risbg_mask(uval)) { + return true; /* RISBG */ + } + break; default: g_assert_not_reached(); }@@ -588,10 +610,6 @@ static bool tcg_target_const_match(int64_t val, int ct, if (ct & TCG_CT_CONST_INV) { val = ~val; } - /* - * Note that is_const_p16 is a subset of is_const_p32, - * so we don't need both constraints. - */ if ((ct & TCG_CT_CONST_P32) && is_const_p32(val) >= 0) { return true; }@@ -868,6 +886,9 @@ static const S390Opcode oi_insns[4] = { static const S390Opcode lif_insns[2] = { RIL_LLILF, RIL_LLIHF, }; +static const S390Opcode tm_insns[4] = { + RI_TMLL, RI_TMLH, RI_TMHL, RI_TMHH +}; /* load a register with an immediate value */ static void tcg_out_movi(TCGContext *s, TCGType type,@@ -1228,6 +1249,36 @@ static int tgen_cmp2(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, TCGCond inv_c = tcg_invert_cond(c); S390Opcode op; + if (is_tst_cond(c)) { + tcg_debug_assert(!need_carry); + + if (!c2const) { + if (type == TCG_TYPE_I32) { + tcg_out_insn(s, RRFa, NRK, TCG_REG_R0, r1, c2); + } else { + tcg_out_insn(s, RRFa, NGRK, TCG_REG_R0, r1, c2); + } + goto exit; + } + + if (type == TCG_TYPE_I32) { + c2 = (uint32_t)c2; + } + + int i = is_const_p16(c2); + if (i >= 0) { + tcg_out_insn_RI(s, tm_insns[i], r1, c2 >> (i * 16)); + *inv_cc = TCG_COND_TSTEQ ? S390_TM_NE : S390_TM_EQ; + return *inv_cc ^ 15; + } + + if (risbg_mask(c2)) { + tgen_andi_risbg(s, TCG_REG_R0, r1, c2); + goto exit; + } + g_assert_not_reached(); + } + if (c2const) { if (c2 == 0) { if (!(is_unsigned && need_carry)) {@@ -1553,46 +1604,49 @@ static void tgen_brcond(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, TCGArg c2, int c2const, TCGLabel *l) { int cc; - bool is_unsigned = is_unsigned_cond(c); - bool in_range; - S390Opcode opc; - cc = tcg_cond_to_s390_cond[c]; + if (!is_tst_cond(c)) { + bool is_unsigned = is_unsigned_cond(c); + bool in_range; + S390Opcode opc; - if (!c2const) { - opc = (type == TCG_TYPE_I32 - ? (is_unsigned ? RIEb_CLRJ : RIEb_CRJ) - : (is_unsigned ? RIEb_CLGRJ : RIEb_CGRJ)); - tgen_compare_branch(s, opc, cc, r1, c2, l); - return; - } + cc = tcg_cond_to_s390_cond[c]; - /* - * COMPARE IMMEDIATE AND BRANCH RELATIVE has an 8-bit immediate field. - * If the immediate we've been given does not fit that range, we'll - * fall back to separate compare and branch instructions using the - * larger comparison range afforded by COMPARE IMMEDIATE. - */ - if (type == TCG_TYPE_I32) { - if (is_unsigned) { - opc = RIEc_CLIJ; - in_range = (uint32_t)c2 == (uint8_t)c2; - } else { - opc = RIEc_CIJ; - in_range = (int32_t)c2 == (int8_t)c2; + if (!c2const) { + opc = (type == TCG_TYPE_I32 + ? (is_unsigned ? RIEb_CLRJ : RIEb_CRJ) + : (is_unsigned ? RIEb_CLGRJ : RIEb_CGRJ)); + tgen_compare_branch(s, opc, cc, r1, c2, l); + return; } - } else { - if (is_unsigned) { - opc = RIEc_CLGIJ; - in_range = (uint64_t)c2 == (uint8_t)c2; + + /* + * COMPARE IMMEDIATE AND BRANCH RELATIVE has an 8-bit immediate field. + * If the immediate we've been given does not fit that range, we'll + * fall back to separate compare and branch instructions using the + * larger comparison range afforded by COMPARE IMMEDIATE. + */ + if (type == TCG_TYPE_I32) { + if (is_unsigned) { + opc = RIEc_CLIJ; + in_range = (uint32_t)c2 == (uint8_t)c2; + } else { + opc = RIEc_CIJ; + in_range = (int32_t)c2 == (int8_t)c2; + } } else { - opc = RIEc_CGIJ; - in_range = (int64_t)c2 == (int8_t)c2; + if (is_unsigned) { + opc = RIEc_CLGIJ; + in_range = (uint64_t)c2 == (uint8_t)c2; + } else { + opc = RIEc_CGIJ; + in_range = (int64_t)c2 == (int8_t)c2; + } + } + if (in_range) { + tgen_compare_imm_branch(s, opc, cc, r1, c2, l); + return; } - } - if (in_range) { - tgen_compare_imm_branch(s, opc, cc, r1, c2, l); - return; } cc = tgen_cmp(s, type, c, r1, c2, c2const, false);@@ -1871,11 +1925,10 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, ldst->oi = oi; ldst->addrlo_reg = addr_reg; - /* We are expecting a_bits to max out at 7, much lower than TMLL. */ tcg_debug_assert(a_mask <= 0xffff); tcg_out_insn(s, RI, TMLL, addr_reg, a_mask); - tcg_out16(s, RI_BRC | (7 << 4)); /* CC in {1,2,3} */ + tcg_out16(s, RI_BRC | (S390_TM_NE << 4)); ldst->label_ptr[0] = s->code_ptr++; }@@ -1956,7 +2009,7 @@ static void tcg_out_qemu_ldst_i128(TCGContext *s, TCGReg datalo, TCGReg datahi, l2 = gen_new_label(); tcg_out_insn(s, RI, TMLL, addr_reg, 15); - tgen_branch(s, 7, l1); /* CC in {1,2,3} */ + tgen_branch(s, S390_TM_NE, l1); } tcg_debug_assert(!need_bswap);
PATCH v3 38/38 tcg/tci: Support TCG_COND_TST{EQ,NE}
In reply to Richard Henderson--- tcg/tci/tcg-target.h | 2 +- tcg/tci.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
tcg/tci/tcg-target.h +1 -1
@@ -117,7 +117,7 @@#define TCG_TARGET_HAS_qemu_ldst_i128 0 -#define TCG_TARGET_HAS_tst 0 +#define TCG_TARGET_HAS_tst 1/* Number of registers available. */ #define TCG_TARGET_NB_REGS 16
tcg/tci.c +14 -0
@@ -228,6 +228,12 @@ static bool tci_compare32(uint32_t u0, uint32_t u1, TCGCond condition)case TCG_COND_GTU : result = (u0 > u1);break ; +case TCG_COND_TSTEQ : + result = (u0 & u1) ==0 ; +break ; +case TCG_COND_TSTNE : + result = (u0 & u1) !=0 ; +break ;default :g_assert_not_reached (); }
@@ -270,6 +276,12 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)case TCG_COND_GTU : result = (u0 > u1);break ; +case TCG_COND_TSTEQ : + result = (u0 & u1) ==0 ; +break ; +case TCG_COND_TSTNE : + result = (u0 & u1) !=0 ; +break ;default :g_assert_not_reached (); }
@@ -1041,6 +1053,8 @@ static const char *str_c(TCGCond c) [TCG_COND_GEU] = "geu", [TCG_COND_LEU] = "leu", [TCG_COND_GTU] = "gtu", + [TCG_COND_TSTEQ] = "tsteq", + [TCG_COND_TSTNE ] ="tstne" , };assert ((unsigned )c <ARRAY_SIZE (cond));
Signature · 1 line
2.34.1