tcg field extract primitives
v3 cover tcg field extract primitives
Changes since v2:
* Fixes to aarch64 guest. Some tcg_debug_asserts were triggering.
* Silly typo fixed in tcg/mips
* tcg/README updated.
Changes since v1:
* Added tcg_gen_deposit_z_*. Depositing into zero turns out to be quite common among targets. Providing that as a primitive expander allows us to easily generate optimal-ish code for hosts with and without a real deposit operation.
* Cleanups in tcg/s390 akin to those I already did for tcg/arm.
* Add support in tcg/s390 for deposit into zero.
* More special cases in the expanders for better code generation, especially on an x86 host *without* the extract primitives.
* Silly think-o on aarch64 host.
r~
Richard Henderson (18):
tcg: Add field extraction primitives
tcg: Minor adjustments to deposit expanders
tcg: Add deposit_z expander
tcg/aarch64: Implement field extraction opcodes tcg/arm: Move isa detection to tcg-target.h tcg/arm: Implement field extraction opcodes tcg/i386: Implement field extraction opcodes tcg/mips: Implement field extraction opcodes tcg/ppc: Implement field extraction opcodes tcg/s390: Expose host facilities to tcg-target.h tcg/s390: Implement field extraction opcodes tcg/s390: Support deposit into zero
target-alpha: Use deposit and extract ops
target-arm: Use new deposit and extract ops
target-i386: Use new deposit and extract ops
target-mips: Use the new extract op
target-ppc: Use the new deposit and extract ops
target-s390x: Use the new deposit and extract ops
target-alpha/translate.c | 67 +++--- target-arm/translate-a64.c | 79 +++----- target-arm/translate.c | 37 +--- target-i386/translate.c | 45 +++-- target-mips/translate.c | 12 +- target-ppc/translate.c | 35 ++-- target-s390x/translate.c | 34 ++-- tcg/README | 20 +- tcg/aarch64/tcg-target.h | 4 + tcg/aarch64/tcg-target.inc.c | 14 ++ tcg/arm/tcg-target.h | 38 +++- tcg/arm/tcg-target.inc.c | 63 +++--- tcg/i386/tcg-target.h | 10 + tcg/i386/tcg-target.inc.c | 38 ++++ tcg/ia64/tcg-target.h | 4 + tcg/mips/tcg-target.h | 2 + tcg/mips/tcg-target.inc.c | 4 + tcg/optimize.c | 29 +++ tcg/ppc/tcg-target.h | 4 + tcg/ppc/tcg-target.inc.c | 10 + tcg/s390/tcg-target.h | 122 ++++++----- tcg/s390/tcg-target.inc.c | 113 ++++++----- tcg/sparc/tcg-target.h | 4 + tcg/tcg-op.c | 472 ++++++++++++++++++++++++++++++++++++++++++- tcg/tcg-op.h | 18 ++ tcg/tcg-opc.h | 4 + tcg/tcg.h | 8 + tcg/tci/tcg-target.h | 4 + 28 files changed, 979 insertions(+), 315 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/18 tcg: Add field extraction primitives
Adds tcg_gen_extract_* and tcg_gen_sextract_* for extraction of fixed position bitfields, much like we already have for deposit.
--- tcg/README | 20 ++- tcg/aarch64/tcg-target.h | 4 + tcg/arm/tcg-target.h | 2 + tcg/i386/tcg-target.h | 4 + tcg/ia64/tcg-target.h | 4 + tcg/mips/tcg-target.h | 2 + tcg/optimize.c | 29 +++++ tcg/ppc/tcg-target.h | 4 + tcg/s390/tcg-target.h | 4 + tcg/sparc/tcg-target.h | 4 + tcg/tcg-op.c | 323 +++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg-op.h | 12 ++ tcg/tcg-opc.h | 4 + tcg/tcg.h | 8 ++ tcg/tci/tcg-target.h | 4 + 15 files changed, 426 insertions(+), 2 deletions(-)
tcg/README +18 -2
@@ -314,11 +314,27 @@ The bitfield is described by POS/LEN, which are immediate values: LEN - the length of the bitfield POS - the position of the first bit, counting from the LSB -For example, pos=8, len=4 indicates a 4-bit field at bit 8. -This operation would be equivalent to +For example, "deposit_i32 dest, t1, t2, 8, 4" indicates a 4-bit field +at bit 8. This operation would be equivalent to dest = (t1 & ~0x0f00) | ((t2 << 8) & 0x0f00) +* extract_i32/i64 dest, t1, pos, len +* sextract_i32/i64 dest, t1, pos, len + +Extract a bitfield from T1, placing the result in DEST. +The bitfield is described by POS/LEN, which are immediate values, +as above for deposit. For extract_*, the result will be extended +to the left with zeros; for sextract_*, the result will be extended +to the left with copies of the bitfield sign bit at pos + len - 1. + +For example, "sextract_i32 dest, t1, 8, 4" indicates a 4-bit field +at bit 8. This operation would be equivalent to + + dest = (t1 << 20) >> 28 + +(using an arithmetic right shift). + * extrl_i64_i32 t0, t1 For 64-bit hosts only, extract the low 32-bits of input T1 and place it
tcg/aarch64/tcg-target.h +4 -0
@@ -63,6 +63,8 @@ typedef enum {#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1#define TCG_TARGET_HAS_sub2_i32 1
@@ -93,6 +95,8 @@ typedef enum {#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 1 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1#define TCG_TARGET_HAS_sub2_i64 1
tcg/arm/tcg-target.h +2 -0
@@ -80,6 +80,8 @@ extern bool use_idiv_instructions;#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_mulu2_i32 1#define TCG_TARGET_HAS_muls2_i32 1
tcg/i386/tcg-target.h +4 -0
@@ -94,6 +94,8 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1#define TCG_TARGET_HAS_sub2_i32 1
@@ -124,6 +126,8 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 1 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1#define TCG_TARGET_HAS_sub2_i64 1
tcg/ia64/tcg-target.h +4 -0
@@ -149,6 +149,10 @@ typedef enum {#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_deposit_i32 1#define TCG_TARGET_HAS_deposit_i64 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i32 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_add2_i32 0#define TCG_TARGET_HAS_add2_i64 0#define TCG_TARGET_HAS_sub2_i32 0
tcg/mips/tcg-target.h +2 -0
@@ -123,6 +123,8 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_HAS_bswap16_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_bswap32_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_deposit_i32 use_mips32r2_instructions +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_ext8s_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_ext16s_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_rot_i32 use_mips32r2_instructions
tcg/optimize.c +29 -0
@@ -878,6 +878,19 @@ void tcg_optimize(TCGContext *s) temps[args[2]].mask);break ; + CASE_OP_32_64(extract): + mask =extract64 (temps[args[1 ]].mask, args[2 ], args[3 ]); +if (args[2 ] ==0 ) { + affected = temps[args[1 ]].mask & ~mask; + } +break ; + CASE_OP_32_64(sextract): + mask =sextract64 (temps[args[1 ]].mask, args[2 ], args[3 ]); +if (args[2 ] ==0 && (tcg_target_long )mask >=0 ) { + affected = temps[args[1 ]].mask & ~mask; + } +break ; + CASE_OP_32_64(or): CASE_OP_32_64(xor): mask = temps[args[1]].mask | temps[args[2]].mask;
@@ -1048,6 +1061,22 @@ void tcg_optimize(TCGContext *s) } goto do_default; + CASE_OP_32_64(extract): + if (temp_is_const(args[1])) { + tmp =extract64 (temps[args[1 ]].val, args[2 ], args[3 ]); +tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +break ; + } + goto do_default; + + CASE_OP_32_64(sextract): + if (temp_is_const(args[1])) { + tmp =sextract64 (temps[args[1 ]].val, args[2 ], args[3 ]); +tcg_opt_gen_movi (s, op, args, args[0 ], tmp); +break ; + } + goto do_default; + CASE_OP_32_64(setcond): tmp =do_constant_folding_cond (opc, args[1 ], args[2 ], args[3 ]);if (tmp !=2 ) {
tcg/ppc/tcg-target.h +4 -0
@@ -69,6 +69,8 @@ typedef enum {#define TCG_TARGET_HAS_nand_i32 1#define TCG_TARGET_HAS_nor_i32 1#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_mulu2_i32 0#define TCG_TARGET_HAS_muls2_i32 0
@@ -100,6 +102,8 @@ typedef enum {#define TCG_TARGET_HAS_nand_i64 1#define TCG_TARGET_HAS_nor_i64 1#define TCG_TARGET_HAS_deposit_i64 1 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1#define TCG_TARGET_HAS_sub2_i64 1
tcg/s390/tcg-target.h +4 -0
@@ -66,6 +66,8 @@ typedef enum TCGReg {#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1#define TCG_TARGET_HAS_sub2_i32 1
@@ -95,6 +97,8 @@ typedef enum TCGReg {#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 1 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1#define TCG_TARGET_HAS_sub2_i64 1
tcg/sparc/tcg-target.h +4 -0
@@ -111,6 +111,8 @@ extern bool use_vis3_instructions;#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 0 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1#define TCG_TARGET_HAS_sub2_i32 1
@@ -141,6 +143,8 @@ extern bool use_vis3_instructions;#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 0 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1#define TCG_TARGET_HAS_sub2_i64 1
tcg/tcg-op.c +323 -0
335 lines not on this page · raw message
tcg/tcg-op.h +12 -0
@@ -292,6 +292,10 @@ void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);void tcg_gen_rotri_i32 (TCGv_i32 ret,TCGv_i32 arg1,unsigned arg2);void tcg_gen_deposit_i32 (TCGv_i32 ret,TCGv_i32 arg1,TCGv_i32 arg2,unsigned int ofs,unsigned int len); +void tcg_gen_extract_i32 (TCGv_i32 ret,TCGv_i32 arg, +unsigned int ofs,unsigned int len); +void tcg_gen_sextract_i32 (TCGv_i32 ret,TCGv_i32 arg, +unsigned int ofs,unsigned int len);void tcg_gen_brcond_i32 (TCGCond cond,TCGv_i32 arg1,TCGv_i32 arg2,TCGLabel *);void tcg_gen_brcondi_i32 (TCGCond cond,TCGv_i32 arg1,int32_t arg2,TCGLabel *); void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
@@ -469,6 +473,10 @@ void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);void tcg_gen_rotri_i64 (TCGv_i64 ret,TCGv_i64 arg1,unsigned arg2);void tcg_gen_deposit_i64 (TCGv_i64 ret,TCGv_i64 arg1,TCGv_i64 arg2,unsigned int ofs,unsigned int len); +void tcg_gen_extract_i64 (TCGv_i64 ret,TCGv_i64 arg, +unsigned int ofs,unsigned int len); +void tcg_gen_sextract_i64 (TCGv_i64 ret,TCGv_i64 arg, +unsigned int ofs,unsigned int len);void tcg_gen_brcond_i64 (TCGCond cond,TCGv_i64 arg1,TCGv_i64 arg2,TCGLabel *);void tcg_gen_brcondi_i64 (TCGCond cond,TCGv_i64 arg1,int64_t arg2,TCGLabel *); void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
@@ -951,6 +959,8 @@ void tcg_gen_atomic_xor_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp);#define tcg_gen_rotr_tl tcg_gen_rotr_i64#define tcg_gen_rotri_tl tcg_gen_rotri_i64#define tcg_gen_deposit_tl tcg_gen_deposit_i64 +#define tcg_gen_extract_tl tcg_gen_extract_i64 +#define tcg_gen_sextract_tl tcg_gen_sextract_i64#define tcg_const_tl tcg_const_i64#define tcg_const_local_tl tcg_const_local_i64#define tcg_gen_movcond_tl tcg_gen_movcond_i64
@@ -1039,6 +1049,8 @@ void tcg_gen_atomic_xor_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp);#define tcg_gen_rotr_tl tcg_gen_rotr_i32#define tcg_gen_rotri_tl tcg_gen_rotri_i32#define tcg_gen_deposit_tl tcg_gen_deposit_i32 +#define tcg_gen_extract_tl tcg_gen_extract_i32 +#define tcg_gen_sextract_tl tcg_gen_sextract_i32#define tcg_const_tl tcg_const_i32#define tcg_const_local_tl tcg_const_local_i32#define tcg_gen_movcond_tl tcg_gen_movcond_i32
tcg/tcg-opc.h +4 -0
@@ -77,6 +77,8 @@ DEF(sar_i32, 1, 2, 0, 0) DEF(rotl_i32, 1, 2, 0, IMPL(TCG_TARGET_HAS_rot_i32)) DEF(rotr_i32, 1, 2, 0, IMPL(TCG_TARGET_HAS_rot_i32)) DEF(deposit_i32, 1, 2, 2, IMPL(TCG_TARGET_HAS_deposit_i32)) +DEF(extract_i32, 1, 1, 2, IMPL(TCG_TARGET_HAS_extract_i32)) +DEF(sextract_i32, 1, 1, 2, IMPL(TCG_TARGET_HAS_sextract_i32))DEF (brcond_i32,0 ,2 ,2 ,TCG_OPF_BB_END )
@@ -139,6 +141,8 @@ DEF(sar_i64, 1, 2, 0, IMPL64) DEF(rotl_i64, 1, 2, 0, IMPL64 | IMPL(TCG_TARGET_HAS_rot_i64)) DEF(rotr_i64, 1, 2, 0, IMPL64 | IMPL(TCG_TARGET_HAS_rot_i64)) DEF(deposit_i64, 1, 2, 2, IMPL64 | IMPL(TCG_TARGET_HAS_deposit_i64)) +DEF(extract_i64, 1, 1, 2, IMPL64 | IMPL(TCG_TARGET_HAS_extract_i64)) +DEF (sextract_i64,1 ,1 ,2 ,IMPL64 |IMPL (TCG_TARGET_HAS_sextract_i64)) /* size changing ops */DEF (ext_i32_i64,1 ,1 ,0 ,IMPL64 )
tcg/tcg.h +8 -0
@@ -112,6 +112,8 @@ typedef uint64_t TCGRegSet;#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 0 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 0#define TCG_TARGET_HAS_add2_i64 0#define TCG_TARGET_HAS_sub2_i64 0
@@ -130,6 +132,12 @@ typedef uint64_t TCGRegSet;#ifndef TCG_TARGET_deposit_i64_valid#define TCG_TARGET_deposit_i64_valid (ofs, len) 1#endif +#ifndef TCG_TARGET_extract_i32_valid +#define TCG_TARGET_extract_i32_valid (ofs, len) 1 +#endif +#ifndef TCG_TARGET_extract_i64_valid +#define TCG_TARGET_extract_i64_valid (ofs, len) 1 +#endif /* Only one of DIV or DIV2 should be defined. */ #if defined(TCG_TARGET_HAS_div_i32)
tcg/tci/tcg-target.h +4 -0
@@ -69,6 +69,8 @@#define TCG_TARGET_HAS_ext16u_i32 1#define TCG_TARGET_HAS_andc_i32 0#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_eqv_i32 0#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0
@@ -88,6 +90,8 @@#define TCG_TARGET_HAS_bswap32_i64 1#define TCG_TARGET_HAS_bswap64_i64 1#define TCG_TARGET_HAS_deposit_i64 1 +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_div_i64 0#define TCG_TARGET_HAS_rem_i64 0#define TCG_TARGET_HAS_ext8s_i64 1
Signature · 1 line
2.7.4
PATCH v3 2/18 tcg: Minor adjustments to deposit expanders
In reply to Richard HendersonAssert that len is not 0.
Since we have asserted that ofs + len <= N, a later check for len == N implies that ofs == 0.
--- tcg/tcg-op.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tcg/tcg-op.c +4 -2
@@ -533,10 +533,11 @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,TCGv_i32 t1;tcg_debug_assert (ofs <32 ); +tcg_debug_assert (len >0 );tcg_debug_assert (len <=32 );tcg_debug_assert (ofs + len <=32 ); -if (ofs ==0 && len ==32 ) { +if (len ==32 ) {tcg_gen_mov_i32 (ret, arg2);return ; }
@@ -1718,10 +1719,11 @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,TCGv_i64 t1;tcg_debug_assert (ofs <64 ); +tcg_debug_assert (len >0 );tcg_debug_assert (len <=64 );tcg_debug_assert (ofs + len <=64 ); -if (ofs ==0 && len ==64 ) { +if (len ==64 ) {tcg_gen_mov_i64 (ret, arg2);return ; }
Signature · 1 line
2.7.4
PATCH v3 3/18 tcg: Add deposit_z expander
In reply to Richard HendersonWhile we don't require a new opcode, it is handy to have an expander that knows the first source is zero.
--- tcg/tcg-op.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg-op.h | 6 +++ 2 files changed, 149 insertions(+)
tcg/tcg-op.c +143 -0
@@ -561,6 +561,64 @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,tcg_temp_free_i32 (t1); } +void tcg_gen_deposit_z_i32 (TCGv_i32 ret,TCGv_i32 arg, +unsigned int ofs,unsigned int len) +{ +tcg_debug_assert (ofs <32 ); +tcg_debug_assert (len >0 ); +tcg_debug_assert (len <=32 ); +tcg_debug_assert (ofs + len <=32 ); + +if (ofs + len ==32 ) { +tcg_gen_shli_i32 (ret, arg, ofs); + }else if (ofs ==0 ) { +tcg_gen_andi_i32 (ret, arg, (1u << len) -1 ); + }else if (TCG_TARGET_HAS_deposit_i32 + &&TCG_TARGET_deposit_i32_valid (ofs, len)) { +TCGv_i32 zero =tcg_const_i32 (0 ); +tcg_gen_op5ii_i32 (INDEX_op_deposit_i32, ret, zero, arg, ofs, len); +tcg_temp_free_i32 (zero); + }else { +/* To help two-operand hosts we prefer to zero-extend first, +which allows ARG to stay live. */ +switch (len) { +case 16 : +if (TCG_TARGET_HAS_ext16u_i32) { +tcg_gen_ext16u_i32 (ret, arg); +tcg_gen_shli_i32 (ret, ret, ofs); +return ; + } +break ; +case 8 : +if (TCG_TARGET_HAS_ext8u_i32) { +tcg_gen_ext8u_i32 (ret, arg); +tcg_gen_shli_i32 (ret, ret, ofs); +return ; + } +break ; + } +/* Otherwise prefer zero-extension over AND for code size. */ +switch (ofs + len) { +case 16 : +if (TCG_TARGET_HAS_ext16u_i32) { +tcg_gen_shli_i32 (ret, arg, ofs); +tcg_gen_ext16u_i32 (ret, ret); +return ; + } +break ; +case 8 : +if (TCG_TARGET_HAS_ext8u_i32) { +tcg_gen_shli_i32 (ret, arg, ofs); +tcg_gen_ext8u_i32 (ret, ret); +return ; + } +break ; + } +tcg_gen_andi_i32 (ret, arg, (1u << len) -1 ); +tcg_gen_shli_i32 (ret, ret, ofs); + } +} +void tcg_gen_extract_i32 (TCGv_i32 ret,TCGv_i32 arg,unsigned int ofs,unsigned int len) {
@@ -1762,6 +1820,91 @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,tcg_temp_free_i64 (t1); } +void tcg_gen_deposit_z_i64 (TCGv_i64 ret,TCGv_i64 arg, +unsigned int ofs,unsigned int len) +{ +tcg_debug_assert (ofs <64 ); +tcg_debug_assert (len >0 ); +tcg_debug_assert (len <=64 ); +tcg_debug_assert (ofs + len <=64 ); + +if (ofs + len ==64 ) { +tcg_gen_shli_i64 (ret, arg, ofs); + }else if (ofs ==0 ) { +tcg_gen_andi_i64 (ret, arg, (1ull << len) -1 ); + }else if (TCG_TARGET_HAS_deposit_i64 + &&TCG_TARGET_deposit_i64_valid (ofs, len)) { +TCGv_i64 zero =tcg_const_i64 (0 ); +tcg_gen_op5ii_i64 (INDEX_op_deposit_i64, ret, zero, arg, ofs, len); +tcg_temp_free_i64 (zero); + }else { +if (TCG_TARGET_REG_BITS ==32 ) { +if (ofs >=32 ) { +tcg_gen_deposit_z_i32 (TCGV_HIGH (ret),TCGV_LOW (arg), + ofs -32 , len); +tcg_gen_movi_i32 (TCGV_LOW (ret),0 ); +return ; + } +if (ofs + len <=32 ) { +tcg_gen_deposit_z_i32 (TCGV_LOW (ret),TCGV_LOW (arg), ofs, len); +tcg_gen_movi_i32 (TCGV_HIGH (ret),0 ); +return ; + } + } +/* To help two-operand hosts we prefer to zero-extend first, +which allows ARG to stay live. */ +switch (len) { +case 32 : +if (TCG_TARGET_HAS_ext32u_i64) { +tcg_gen_ext32u_i64 (ret, arg); +tcg_gen_shli_i64 (ret, ret, ofs); +return ; + } +break ; +case 16 : +if (TCG_TARGET_HAS_ext16u_i64) { +tcg_gen_ext16u_i64 (ret, arg); +tcg_gen_shli_i64 (ret, ret, ofs); +return ; + } +break ; +case 8 : +if (TCG_TARGET_HAS_ext8u_i64) { +tcg_gen_ext8u_i64 (ret, arg); +tcg_gen_shli_i64 (ret, ret, ofs); +return ; + } +break ; + } +/* Otherwise prefer zero-extension over AND for code size. */ +switch (ofs + len) { +case 32 : +if (TCG_TARGET_HAS_ext32u_i64) { +tcg_gen_shli_i64 (ret, arg, ofs); +tcg_gen_ext32u_i64 (ret, ret); +return ; + } +break ; +case 16 : +if (TCG_TARGET_HAS_ext16u_i64) { +tcg_gen_shli_i64 (ret, arg, ofs); +tcg_gen_ext16u_i64 (ret, ret); +return ; + } +break ; +case 8 : +if (TCG_TARGET_HAS_ext8u_i64) { +tcg_gen_shli_i64 (ret, arg, ofs); +tcg_gen_ext8u_i64 (ret, ret); +return ; + } +break ; + } +tcg_gen_andi_i64 (ret, arg, (1ull << len) -1 ); +tcg_gen_shli_i64 (ret, ret, ofs); + } +} +void tcg_gen_extract_i64 (TCGv_i64 ret,TCGv_i64 arg,unsigned int ofs,unsigned int len) {
tcg/tcg-op.h +6 -0
@@ -292,6 +292,8 @@ void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);void tcg_gen_rotri_i32 (TCGv_i32 ret,TCGv_i32 arg1,unsigned arg2);void tcg_gen_deposit_i32 (TCGv_i32 ret,TCGv_i32 arg1,TCGv_i32 arg2,unsigned int ofs,unsigned int len); +void tcg_gen_deposit_z_i32 (TCGv_i32 ret,TCGv_i32 arg, +unsigned int ofs,unsigned int len);void tcg_gen_extract_i32 (TCGv_i32 ret,TCGv_i32 arg,unsigned int ofs,unsigned int len); void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
@@ -473,6 +475,8 @@ void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);void tcg_gen_rotri_i64 (TCGv_i64 ret,TCGv_i64 arg1,unsigned arg2);void tcg_gen_deposit_i64 (TCGv_i64 ret,TCGv_i64 arg1,TCGv_i64 arg2,unsigned int ofs,unsigned int len); +void tcg_gen_deposit_z_i64 (TCGv_i64 ret,TCGv_i64 arg, +unsigned int ofs,unsigned int len);void tcg_gen_extract_i64 (TCGv_i64 ret,TCGv_i64 arg,unsigned int ofs,unsigned int len); void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
@@ -959,6 +963,7 @@ void tcg_gen_atomic_xor_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp);#define tcg_gen_rotr_tl tcg_gen_rotr_i64#define tcg_gen_rotri_tl tcg_gen_rotri_i64#define tcg_gen_deposit_tl tcg_gen_deposit_i64 +#define tcg_gen_deposit_z_tl tcg_gen_deposit_z_i64#define tcg_gen_extract_tl tcg_gen_extract_i64#define tcg_gen_sextract_tl tcg_gen_sextract_i64#define tcg_const_tl tcg_const_i64
@@ -1049,6 +1054,7 @@ void tcg_gen_atomic_xor_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp);#define tcg_gen_rotr_tl tcg_gen_rotr_i32#define tcg_gen_rotri_tl tcg_gen_rotri_i32#define tcg_gen_deposit_tl tcg_gen_deposit_i32 +#define tcg_gen_deposit_z_tl tcg_gen_deposit_z_i32#define tcg_gen_extract_tl tcg_gen_extract_i32#define tcg_gen_sextract_tl tcg_gen_sextract_i32#define tcg_const_tl tcg_const_i32
Signature · 1 line
2.7.4
PATCH v3 4/18 tcg/aarch64: Implement field extraction opcodes
In reply to Richard Henderson--- tcg/aarch64/tcg-target.h | 8 ++++---- tcg/aarch64/tcg-target.inc.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)
tcg/aarch64/tcg-target.h +4 -4
@@ -63,8 +63,8 @@ typedef enum {#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 1 -#define TCG_TARGET_HAS_extract_i32 0 -#define TCG_TARGET_HAS_sextract_i32 0 +#define TCG_TARGET_HAS_extract_i32 1 +#define TCG_TARGET_HAS_sextract_i32 1#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1#define TCG_TARGET_HAS_sub2_i32 1
@@ -95,8 +95,8 @@ typedef enum {#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 1 -#define TCG_TARGET_HAS_extract_i64 0 -#define TCG_TARGET_HAS_sextract_i64 0 +#define TCG_TARGET_HAS_extract_i64 1 +#define TCG_TARGET_HAS_sextract_i64 1#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1#define TCG_TARGET_HAS_sub2_i64 1
tcg/aarch64/tcg-target.inc.c +14 -0
@@ -1640,6 +1640,16 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,tcg_out_dep (s, ext, a0,REG0 (2 ), args[3 ], args[4 ]);break ; +case INDEX_op_extract_i64: +case INDEX_op_extract_i32: +tcg_out_ubfm (s, ext, a0, a1, a2, a2 + args[3 ] -1 ); +break ; + +case INDEX_op_sextract_i64: +case INDEX_op_sextract_i32: +tcg_out_sbfm (s, ext, a0, a1, a2, a2 + args[3 ] -1 ); +break ; +case INDEX_op_add2_i32: tcg_out_addsub2(s, TCG_TYPE_I32, a0, a1, REG0(2), REG0(3), (int32_t)args[4], args[5], const_args[4],
@@ -1785,6 +1795,10 @@ static const TCGTargetOpDef aarch64_op_defs[] = { { INDEX_op_deposit_i32, { "r", "0", "rZ" } }, { INDEX_op_deposit_i64, { "r", "0", "rZ" } }, + { INDEX_op_extract_i32, { "r", "r" } }, + { INDEX_op_extract_i64, { "r", "r" } }, + { INDEX_op_sextract_i32, { "r", "r" } }, + { INDEX_op_sextract_i64, { "r", "r" } }, { INDEX_op_add2_i32, { "r", "r", "rZ", "rZ", "rA", "rMZ" } }, { INDEX_op_add2_i64, { "r", "r", "rZ", "rZ", "rA", "rMZ" } },
Signature · 1 line
2.7.4
PATCH v3 5/18 tcg/arm: Move isa detection to tcg-target.h
In reply to Richard Henderson--- tcg/arm/tcg-target.h | 36 ++++++++++++++++++++++++++++++++---- tcg/arm/tcg-target.inc.c | 41 +---------------------------------------- 2 files changed, 33 insertions(+), 44 deletions(-)
tcg/arm/tcg-target.h +32 -4
@@ -26,6 +26,37 @@#ifndef ARM_TCG_TARGET_H #define ARM_TCG_TARGET_H +/* The __ARM_ARCH define is provided by gcc 4.8. Construct it otherwise. */ +#ifndef __ARM_ARCH +# if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ + || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ + || defined(__ARM_ARCH_7EM__) +# define __ARM_ARCH 7 +# elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ + || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \ + || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) +# define __ARM_ARCH 6 +# elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5E__) \ + || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) \ + || defined(__ARM_ARCH_5TEJ__) +# define __ARM_ARCH 5 +# else +# define __ARM_ARCH 4 +# endif +#endif + +extern int arm_arch; + +#if defined(__ARM_ARCH_5T__) \ + || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__) +# define use_armv5t_instructions 1 +#else +# define use_armv5t_instructions use_armv6_instructions +#endif + +#define use_armv6_instructions (__ARM_ARCH >= 6 || arm_arch >= 6) +#define use_armv7_instructions (__ARM_ARCH >= 7 || arm_arch >= 7) +#undef TCG_TARGET_STACK_GROWSUP#define TCG_TARGET_INSN_UNIT_SIZE 4#define TCG_TARGET_TLB_DISPLACEMENT_BITS 16
@@ -79,7 +110,7 @@ extern bool use_idiv_instructions;#define TCG_TARGET_HAS_eqv_i32 0#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0 -#define TCG_TARGET_HAS_deposit_i32 1 +#define TCG_TARGET_HAS_deposit_i32 use_armv7_instructions#define TCG_TARGET_HAS_extract_i32 0#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1
@@ -90,9 +121,6 @@ extern bool use_idiv_instructions;#define TCG_TARGET_HAS_div_i32 use_idiv_instructions#define TCG_TARGET_HAS_rem_i32 0 -extern bool tcg_target_deposit_valid (int ofs,int len); -#define TCG_TARGET_deposit_i32_valid tcg_target_deposit_valid -enum {TCG_AREG0 =TCG_REG_R6 , };
tcg/arm/tcg-target.inc.c +1 -40
53 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 6/18 tcg/arm: Implement field extraction opcodes
In reply to Richard Henderson--- tcg/arm/tcg-target.h | 4 ++-- tcg/arm/tcg-target.inc.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-)
tcg/arm/tcg-target.h +2 -2
@@ -111,8 +111,8 @@ extern bool use_idiv_instructions;#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 use_armv7_instructions -#define TCG_TARGET_HAS_extract_i32 0 -#define TCG_TARGET_HAS_sextract_i32 0 +#define TCG_TARGET_HAS_extract_i32 use_armv7_instructions +#define TCG_TARGET_HAS_sextract_i32 use_armv7_instructions#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_mulu2_i32 1#define TCG_TARGET_HAS_muls2_i32 1
tcg/arm/tcg-target.inc.c +22 -0
@@ -713,6 +713,20 @@ static inline void tcg_out_deposit(TCGContext *s, int cond, TCGReg rd, | (ofs << 7) | ((ofs + len - 1) << 16)); } +static inline void tcg_out_extract (TCGContext *s,int cond,TCGReg rd, +TCGArg a1,int ofs,int len) +{ +tcg_out32 (s,0x07e00050 | (cond <<28 ) | (rd <<12 ) | a1 + | (ofs <<7 ) | ((len -1 ) <<16 )); +} + +static inline void tcg_out_sextract (TCGContext *s,int cond,TCGReg rd, +TCGArg a1,int ofs,int len) +{ +tcg_out32 (s,0x07a00050 | (cond <<28 ) | (rd <<12 ) | a1 + | (ofs <<7 ) | ((len -1 ) <<16 )); +} +/* Note that this routine is used for both LDR and LDRH formats, so we do not wish to include an immediate shift at this point. */ static void tcg_out_memop_r(TCGContext *s, int cond, ARMInsn opc, TCGReg rt,
@@ -1894,6 +1908,12 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,tcg_out_deposit (s,COND_AL , args[0 ], args[2 ], args[3 ], args[4 ], const_args[2 ]);break ; +case INDEX_op_extract_i32: +tcg_out_extract (s,COND_AL , args[0 ], args[1 ], args[2 ], args[3 ]); +break ; +case INDEX_op_sextract_i32: +tcg_out_sextract (s,COND_AL , args[0 ], args[1 ], args[2 ], args[3 ]); +break ;case INDEX_op_div_i32:tcg_out_sdiv (s,COND_AL , args[0 ], args[1 ], args[2 ]);
@@ -1976,6 +1996,8 @@ static const TCGTargetOpDef arm_op_defs[] = { { INDEX_op_ext16u_i32, { "r", "r" } }, { INDEX_op_deposit_i32, { "r", "0", "rZ" } }, + { INDEX_op_extract_i32, { "r", "r" } }, + { INDEX_op_sextract_i32, { "r", "r" } }, { INDEX_op_div_i32, { "r", "r", "r" } }, { INDEX_op_divu_i32, { "r", "r", "r" } },
Signature · 1 line
2.7.4
PATCH v3 7/18 tcg/i386: Implement field extraction opcodes
In reply to Richard Henderson--- tcg/i386/tcg-target.h | 12 +++++++++--- tcg/i386/tcg-target.inc.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-)
tcg/i386/tcg-target.h +9 -3
@@ -94,8 +94,8 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 1 -#define TCG_TARGET_HAS_extract_i32 0 -#define TCG_TARGET_HAS_sextract_i32 0 +#define TCG_TARGET_HAS_extract_i32 1 +#define TCG_TARGET_HAS_sextract_i32 1#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1#define TCG_TARGET_HAS_sub2_i32 1
@@ -126,7 +126,7 @@ extern bool have_bmi1;#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 1 -#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_extract_i64 1#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1
@@ -142,6 +142,12 @@ extern bool have_bmi1; ((ofs) == 0 && (len) == 16))#define TCG_TARGET_deposit_i64_valid TCG_TARGET_deposit_i32_valid +/* Check for the possibility of high-byte extraction and, for 64-bit, +zero-extending 32-bit right-shift. */ +#define TCG_TARGET_extract_i32_valid (ofs, len) ((ofs) == 8 && (len) == 8) +#define TCG_TARGET_extract_i64_valid (ofs, len) \ + (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) +#if TCG_TARGET_REG_BITS ==64 # define TCG_AREG0 TCG_REG_R14#else
tcg/i386/tcg-target.inc.c +38 -0
@@ -2143,6 +2143,40 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, }break ; +case INDEX_op_extract_i64: +if (args[2 ] + args[3 ] ==32 ) { +/* This is a 32-bit zero-extending right shift. */ +tcg_out_mov (s,TCG_TYPE_I32 , args[0 ], args[1 ]); +tcg_out_shifti (s,SHIFT_SHR , args[0 ], args[2 ]); +break ; + } +/* FALLTHRU */ +case INDEX_op_extract_i32: +/* On the off-chance that we can use the high-byte registers. +Otherwise we emit the same ext16 + shift pattern that we +would have gotten from the normal tcg-op.c expansion. */ +tcg_debug_assert (args[2 ] ==8 && args[3 ] ==8 ); +if (args[1 ] <4 && args[0 ] <8 ) { +tcg_out_modrm (s,OPC_MOVZBL , args[0 ], args[1 ] +4 ); + }else { +tcg_out_ext16u (s, args[0 ], args[1 ]); +tcg_out_shifti (s,SHIFT_SHR , args[0 ],8 ); + } +break ; + +case INDEX_op_sextract_i32: +/* We don't implement sextract_i64, as we cannot sign-extend to +64-bits without using the REX prefix that explicitly excludes +access to the high-byte registers. */ +tcg_debug_assert (args[2 ] ==8 && args[3 ] ==8 ); +if (args[1 ] <4 && args[0 ] <8 ) { +tcg_out_modrm (s,OPC_MOVSBL , args[0 ], args[1 ] +4 ); + }else { +tcg_out_ext16s (s, args[0 ], args[1 ],0 ); +tcg_out_shifti (s,SHIFT_SAR , args[0 ],8 ); + } +break ; +case INDEX_op_mb:tcg_out_mb (s, args[0 ]);break ;
@@ -2204,6 +2238,9 @@ static const TCGTargetOpDef x86_op_defs[] = { { INDEX_op_setcond_i32, { "q", "r", "ri" } }, { INDEX_op_deposit_i32, { "Q", "0", "Q" } }, + { INDEX_op_extract_i32, { "r", "r" } }, + { INDEX_op_sextract_i32, { "r", "r" } }, + { INDEX_op_movcond_i32, { "r", "r", "ri", "r", "0" } }, { INDEX_op_mulu2_i32, { "a", "d", "a", "r" } },
@@ -2265,6 +2302,7 @@ static const TCGTargetOpDef x86_op_defs[] = { { INDEX_op_extu_i32_i64, { "r", "r" } }, { INDEX_op_deposit_i64, { "Q", "0", "Q" } }, + { INDEX_op_extract_i64, { "r", "r" } }, { INDEX_op_movcond_i64, { "r", "r", "re", "r", "0" } }, { INDEX_op_mulu2_i64, { "a", "d", "a", "r" } },
Signature · 1 line
2.7.4
PATCH v3 8/18 tcg/mips: Implement field extraction opcodes
In reply to Richard Henderson--- tcg/mips/tcg-target.h | 2 +- tcg/mips/tcg-target.inc.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
tcg/mips/tcg-target.h +1 -1
@@ -123,7 +123,7 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_HAS_bswap16_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_bswap32_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_deposit_i32 use_mips32r2_instructions -#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_extract_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_ext8s_i32 use_mips32r2_instructions#define TCG_TARGET_HAS_ext16s_i32 use_mips32r2_instructions
tcg/mips/tcg-target.inc.c +4 -0
@@ -1637,6 +1637,9 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,case INDEX_op_deposit_i32:tcg_out_opc_bf (s,OPC_INS , a0, a2, args[3 ] + args[4 ] -1 , args[3 ]);break ; +case INDEX_op_extract_i32: +tcg_out_opc_bf (s,OPC_EXT , a0, a1, a2 + args[3 ] -1 , a2); +break ;case INDEX_op_brcond_i32:tcg_out_brcond (s, a2, a0, a1,arg_label (args[3 ]));
@@ -1736,6 +1739,7 @@ static const TCGTargetOpDef mips_op_defs[] = { { INDEX_op_ext16s_i32, { "r", "rZ" } }, { INDEX_op_deposit_i32, { "r", "0", "rZ" } }, + { INDEX_op_extract_i32, { "r", "r" } }, { INDEX_op_brcond_i32, { "rZ", "rZ" } }, #if use_mips32r6_instructions
Signature · 1 line
2.7.4
PATCH v3 9/18 tcg/ppc: Implement field extraction opcodes
In reply to Richard Henderson--- tcg/ppc/tcg-target.h | 4 ++-- tcg/ppc/tcg-target.inc.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-)
tcg/ppc/tcg-target.h +2 -2
@@ -69,7 +69,7 @@ typedef enum {#define TCG_TARGET_HAS_nand_i32 1#define TCG_TARGET_HAS_nor_i32 1#define TCG_TARGET_HAS_deposit_i32 1 -#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_extract_i32 1#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_mulu2_i32 0
@@ -102,7 +102,7 @@ typedef enum {#define TCG_TARGET_HAS_nand_i64 1#define TCG_TARGET_HAS_nor_i64 1#define TCG_TARGET_HAS_deposit_i64 1 -#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_extract_i64 1#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1
tcg/ppc/tcg-target.inc.c +10 -0
@@ -2396,6 +2396,14 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, }break ; +case INDEX_op_extract_i32: +tcg_out_rlw (s,RLWINM , args[0 ], args[1 ], +32 - args[2 ],32 - args[3 ],31 ); +break ; +case INDEX_op_extract_i64: +tcg_out_rld (s,RLDICL , args[0 ], args[1 ],64 - args[2 ],64 - args[3 ]); +break ; +case INDEX_op_movcond_i32:tcg_out_movcond (s,TCG_TYPE_I32 , args[5 ], args[0 ], args[1 ], args[2 ], args[3 ], args[4 ], const_args[2 ]);
@@ -2530,6 +2538,7 @@ static const TCGTargetOpDef ppc_op_defs[] = { { INDEX_op_movcond_i32, { "r", "r", "ri", "rZ", "rZ" } }, { INDEX_op_deposit_i32, { "r", "0", "rZ" } }, + { INDEX_op_extract_i32, { "r", "r" } }, { INDEX_op_muluh_i32, { "r", "r", "r" } }, { INDEX_op_mulsh_i32, { "r", "r", "r" } },
@@ -2585,6 +2594,7 @@ static const TCGTargetOpDef ppc_op_defs[] = { { INDEX_op_movcond_i64, { "r", "r", "ri", "rZ", "rZ" } }, { INDEX_op_deposit_i64, { "r", "0", "rZ" } }, + { INDEX_op_extract_i64, { "r", "r" } }, { INDEX_op_mulsh_i64, { "r", "r", "r" } }, { INDEX_op_muluh_i64, { "r", "r", "r" } },
Signature · 1 line
2.7.4
PATCH v3 10/18 tcg/s390: Expose host facilities to tcg-target.h
In reply to Richard HendersonThis lets us expose facilities to TCG_TARGET_HAS_* defines directly, rather than hiding behind function calls.
--- tcg/s390/tcg-target.h | 126 ++++++++++++++++++++++++---------------------- tcg/s390/tcg-target.inc.c | 74 +++++++++++---------------- 2 files changed, 96 insertions(+), 104 deletions(-)
tcg/s390/tcg-target.h +67 -59
@@ -49,67 +49,75 @@ typedef enum TCGReg {#define TCG_TARGET_NB_REGS 16 -/* optional instructions */ -#define TCG_TARGET_HAS_div2_i32 1 -#define TCG_TARGET_HAS_rot_i32 1 -#define TCG_TARGET_HAS_ext8s_i32 1 -#define TCG_TARGET_HAS_ext16s_i32 1 -#define TCG_TARGET_HAS_ext8u_i32 1 -#define TCG_TARGET_HAS_ext16u_i32 1 -#define TCG_TARGET_HAS_bswap16_i32 1 -#define TCG_TARGET_HAS_bswap32_i32 1 -#define TCG_TARGET_HAS_not_i32 0 -#define TCG_TARGET_HAS_neg_i32 1 -#define TCG_TARGET_HAS_andc_i32 0 -#define TCG_TARGET_HAS_orc_i32 0 -#define TCG_TARGET_HAS_eqv_i32 0 -#define TCG_TARGET_HAS_nand_i32 0 -#define TCG_TARGET_HAS_nor_i32 0 -#define TCG_TARGET_HAS_deposit_i32 1 -#define TCG_TARGET_HAS_extract_i32 0 -#define TCG_TARGET_HAS_sextract_i32 0 -#define TCG_TARGET_HAS_movcond_i32 1 -#define TCG_TARGET_HAS_add2_i32 1 -#define TCG_TARGET_HAS_sub2_i32 1 -#define TCG_TARGET_HAS_mulu2_i32 0 -#define TCG_TARGET_HAS_muls2_i32 0 -#define TCG_TARGET_HAS_muluh_i32 0 -#define TCG_TARGET_HAS_mulsh_i32 0 -#define TCG_TARGET_HAS_extrl_i64_i32 0 -#define TCG_TARGET_HAS_extrh_i64_i32 0 +/* A list of relevant facilities used by this translator. Some of these +are required for proper operation, and these are checked at startup. */ + +#define FACILITY_ZARCH_ACTIVE (1ULL << (63 - 2)) +#define FACILITY_LONG_DISP (1ULL << (63 - 18)) +#define FACILITY_EXT_IMM (1ULL << (63 - 21)) +#define FACILITY_GEN_INST_EXT (1ULL << (63 - 34)) +#define FACILITY_LOAD_ON_COND (1ULL << (63 - 45)) +#define FACILITY_FAST_BCR_SER FACILITY_LOAD_ON_COND -#define TCG_TARGET_HAS_div2_i64 1 -#define TCG_TARGET_HAS_rot_i64 1 -#define TCG_TARGET_HAS_ext8s_i64 1 -#define TCG_TARGET_HAS_ext16s_i64 1 -#define TCG_TARGET_HAS_ext32s_i64 1 -#define TCG_TARGET_HAS_ext8u_i64 1 -#define TCG_TARGET_HAS_ext16u_i64 1 -#define TCG_TARGET_HAS_ext32u_i64 1 -#define TCG_TARGET_HAS_bswap16_i64 1 -#define TCG_TARGET_HAS_bswap32_i64 1 -#define TCG_TARGET_HAS_bswap64_i64 1 -#define TCG_TARGET_HAS_not_i64 0 -#define TCG_TARGET_HAS_neg_i64 1 -#define TCG_TARGET_HAS_andc_i64 0 -#define TCG_TARGET_HAS_orc_i64 0 -#define TCG_TARGET_HAS_eqv_i64 0 -#define TCG_TARGET_HAS_nand_i64 0 -#define TCG_TARGET_HAS_nor_i64 0 -#define TCG_TARGET_HAS_deposit_i64 1 -#define TCG_TARGET_HAS_extract_i64 0 -#define TCG_TARGET_HAS_sextract_i64 0 -#define TCG_TARGET_HAS_movcond_i64 1 -#define TCG_TARGET_HAS_add2_i64 1 -#define TCG_TARGET_HAS_sub2_i64 1 -#define TCG_TARGET_HAS_mulu2_i64 1 -#define TCG_TARGET_HAS_muls2_i64 0 -#define TCG_TARGET_HAS_muluh_i64 0 -#define TCG_TARGET_HAS_mulsh_i64 0 +extern uint64_t s390_facilities; + +/* optional instructions */ +#define TCG_TARGET_HAS_div2_i32 1 +#define TCG_TARGET_HAS_rot_i32 1 +#define TCG_TARGET_HAS_ext8s_i32 1 +#define TCG_TARGET_HAS_ext16s_i32 1 +#define TCG_TARGET_HAS_ext8u_i32 1 +#define TCG_TARGET_HAS_ext16u_i32 1 +#define TCG_TARGET_HAS_bswap16_i32 1 +#define TCG_TARGET_HAS_bswap32_i32 1 +#define TCG_TARGET_HAS_not_i32 0 +#define TCG_TARGET_HAS_neg_i32 1 +#define TCG_TARGET_HAS_andc_i32 0 +#define TCG_TARGET_HAS_orc_i32 0 +#define TCG_TARGET_HAS_eqv_i32 0 +#define TCG_TARGET_HAS_nand_i32 0 +#define TCG_TARGET_HAS_nor_i32 0 +#define TCG_TARGET_HAS_deposit_i32 (s390_facilities & FACILITY_GEN_INST_EXT) +#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_sextract_i32 0 +#define TCG_TARGET_HAS_movcond_i32 1 +#define TCG_TARGET_HAS_add2_i32 1 +#define TCG_TARGET_HAS_sub2_i32 1 +#define TCG_TARGET_HAS_mulu2_i32 0 +#define TCG_TARGET_HAS_muls2_i32 0 +#define TCG_TARGET_HAS_muluh_i32 0 +#define TCG_TARGET_HAS_mulsh_i32 0 +#define TCG_TARGET_HAS_extrl_i64_i32 0 +#define TCG_TARGET_HAS_extrh_i64_i32 0 -extern bool tcg_target_deposit_valid (int ofs,int len); -#define TCG_TARGET_deposit_i32_valid tcg_target_deposit_valid -#define TCG_TARGET_deposit_i64_valid tcg_target_deposit_valid +#define TCG_TARGET_HAS_div2_i64 1 +#define TCG_TARGET_HAS_rot_i64 1 +#define TCG_TARGET_HAS_ext8s_i64 1 +#define TCG_TARGET_HAS_ext16s_i64 1 +#define TCG_TARGET_HAS_ext32s_i64 1 +#define TCG_TARGET_HAS_ext8u_i64 1 +#define TCG_TARGET_HAS_ext16u_i64 1 +#define TCG_TARGET_HAS_ext32u_i64 1 +#define TCG_TARGET_HAS_bswap16_i64 1 +#define TCG_TARGET_HAS_bswap32_i64 1 +#define TCG_TARGET_HAS_bswap64_i64 1 +#define TCG_TARGET_HAS_not_i64 0 +#define TCG_TARGET_HAS_neg_i64 1 +#define TCG_TARGET_HAS_andc_i64 0 +#define TCG_TARGET_HAS_orc_i64 0 +#define TCG_TARGET_HAS_eqv_i64 0 +#define TCG_TARGET_HAS_nand_i64 0 +#define TCG_TARGET_HAS_nor_i64 0 +#define TCG_TARGET_HAS_deposit_i64 (s390_facilities & FACILITY_GEN_INST_EXT) +#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_sextract_i64 0 +#define TCG_TARGET_HAS_movcond_i64 1 +#define TCG_TARGET_HAS_add2_i64 1 +#define TCG_TARGET_HAS_sub2_i64 1 +#define TCG_TARGET_HAS_mulu2_i64 1 +#define TCG_TARGET_HAS_muls2_i64 0 +#define TCG_TARGET_HAS_muluh_i64 0 +#define TCG_TARGET_HAS_mulsh_i64 0/* used for function call generation */ #define TCG_REG_CALL_STACK TCG_REG_R15
tcg/s390/tcg-target.inc.c +29 -45
254 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 11/18 tcg/s390: Implement field extraction opcodes
In reply to Richard Henderson--- tcg/s390/tcg-target.h | 4 ++-- tcg/s390/tcg-target.inc.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-)
tcg/s390/tcg-target.h +2 -2
@@ -78,7 +78,7 @@ extern uint64_t s390_facilities;#define TCG_TARGET_HAS_nand_i32 0#define TCG_TARGET_HAS_nor_i32 0#define TCG_TARGET_HAS_deposit_i32 (s390_facilities & FACILITY_GEN_INST_EXT) -#define TCG_TARGET_HAS_extract_i32 0 +#define TCG_TARGET_HAS_extract_i32 (s390_facilities & FACILITY_GEN_INST_EXT)#define TCG_TARGET_HAS_sextract_i32 0#define TCG_TARGET_HAS_movcond_i32 1#define TCG_TARGET_HAS_add2_i32 1
@@ -109,7 +109,7 @@ extern uint64_t s390_facilities;#define TCG_TARGET_HAS_nand_i64 0#define TCG_TARGET_HAS_nor_i64 0#define TCG_TARGET_HAS_deposit_i64 (s390_facilities & FACILITY_GEN_INST_EXT) -#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_extract_i64 (s390_facilities & FACILITY_GEN_INST_EXT)#define TCG_TARGET_HAS_sextract_i64 0#define TCG_TARGET_HAS_movcond_i64 1#define TCG_TARGET_HAS_add2_i64 1
tcg/s390/tcg-target.inc.c +11 -0
@@ -1247,6 +1247,12 @@ static void tgen_deposit(TCGContext *s, TCGReg dest, TCGReg src,tcg_out_risbg (s, dest, src, msb, lsb, ofs,0 ); } +static void tgen_extract (TCGContext *s,TCGReg dest,TCGReg src, +int ofs,int len) +{ +tcg_out_risbg (s, dest, src,64 - len,63 ,64 - ofs,1 ); +} +static void tgen_gotoi (TCGContext *s,int cc,tcg_insn_unit *dest) {ptrdiff_t off = dest - s->code_ptr;
@@ -2153,6 +2159,9 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, OP_32_64(deposit):tgen_deposit (s ,args [0 ],args [2 ],args [3 ],args [4 ]);break ; + OP_32_64(extract): +tgen_extract (s ,args [0 ],args [1 ],args [2 ],args [3 ]); +break ;case INDEX_op_mb:/* The host memory model is quite strong, we simply need to
@@ -2222,6 +2231,7 @@ static const TCGTargetOpDef s390_op_defs[] = { { INDEX_op_setcond_i32, { "r", "r", "rC" } }, { INDEX_op_movcond_i32, { "r", "r", "rC", "r", "0" } }, { INDEX_op_deposit_i32, { "r", "0", "r" } }, + { INDEX_op_extract_i32, { "r", "r" } }, { INDEX_op_qemu_ld_i32, { "r", "L" } }, { INDEX_op_qemu_ld_i64, { "r", "L" } },
@@ -2283,6 +2293,7 @@ static const TCGTargetOpDef s390_op_defs[] = { { INDEX_op_setcond_i64, { "r", "r", "rC" } }, { INDEX_op_movcond_i64, { "r", "r", "rC", "r", "0" } }, { INDEX_op_deposit_i64, { "r", "0", "r" } }, + { INDEX_op_extract_i64, { "r", "r" } }, { INDEX_op_mb, { } }, { -1 },
Signature · 1 line
2.7.4
PATCH v3 12/18 tcg/s390: Support deposit into zero
In reply to Richard HendersonSince we can no longer use matching constraints, this does mean we must handle that data movement by hand.
--- tcg/s390/tcg-target.inc.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
tcg/s390/tcg-target.inc.c +26 -4
@@ -43,6 +43,7 @@#define TCG_CT_CONST_XORI 0x400#define TCG_CT_CONST_CMPI 0x800#define TCG_CT_CONST_ADLI 0x1000 +#define TCG_CT_CONST_ZERO 0x2000/* Several places within the instruction set 0 means "no register" rather than TCG_REG_R0. */
@@ -404,6 +405,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)case 'C' : ct->ct |=TCG_CT_CONST_CMPI ;break ; +case 'Z' : + ct->ct |=TCG_CT_CONST_ZERO ; +break ;default :return -1 ; }
@@ -543,6 +547,8 @@ static int tcg_target_const_match(tcg_target_long val, TCGType type,return tcg_match_xori (type, val); }else if (ct &TCG_CT_CONST_CMPI ) {return tcg_match_cmpi (type, val); + }else if (ct &TCG_CT_CONST_ZERO ) { +return val ==0 ; }return 0 ;
@@ -1240,11 +1246,11 @@ static void tgen_movcond(TCGContext *s, TCGType type, TCGCond c, TCGReg dest, }static void tgen_deposit (TCGContext *s,TCGReg dest,TCGReg src, -int ofs,int len) +int ofs,int len,int z) {int lsb = (63 - ofs);int msb = lsb - (len -1 ); -tcg_out_risbg (s, dest, src, msb, lsb, ofs,0 ); +tcg_out_risbg (s, dest, src, msb, lsb, ofs, z); } static void tgen_extract(TCGContext *s, TCGReg dest, TCGReg src,
@@ -2157,8 +2163,24 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,break ; OP_32_64(deposit): -tgen_deposit (s ,args [0 ],args [2 ],args [3 ],args [4 ]); + a0 = args[0 ], a1 = args[1 ], a2 = args[2 ]; +if (const_args[1 ]) { +tgen_deposit (s, a0, a2, args[3 ], args[4 ],1 ); + }else { +/* Since we can't support "0Z" as a constraint, we allow a1 in +any register. Fix things up as if a matching constraint. */ +if (a0 != a1) { +TCGType type = (opc == INDEX_op_deposit_i64); +if (a0 == a2) { +tcg_out_mov (s, type,TCG_TMP0 , a2); + a2 =TCG_TMP0 ; + } +tcg_out_mov (s, type, a0, a1); + } +tgen_deposit (s, a0, a2, args[3 ], args[4 ],0 ); + }break ; + OP_32_64(extract):tgen_extract (s ,args [0 ],args [1 ],args [2 ],args [3 ]);break ;
@@ -2230,7 +2252,7 @@ static const TCGTargetOpDef s390_op_defs[] = { { INDEX_op_brcond_i32, { "r", "rC" } }, { INDEX_op_setcond_i32, { "r", "r", "rC" } }, { INDEX_op_movcond_i32, { "r", "r", "rC", "r", "0" } }, - { INDEX_op_deposit_i32, { "r", "0", "r" } }, + { INDEX_op_deposit_i32, { "r", "rZ", "r" } }, { INDEX_op_extract_i32, { "r", "r" } }, { INDEX_op_qemu_ld_i32, { "r", "L" } },
Signature · 1 line
2.7.4
PATCH v3 13/18 target-alpha: Use deposit and extract ops
In reply to Richard Henderson--- target-alpha/translate.c | 67 ++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 25 deletions(-)
target-alpha/translate.c +42 -25
@@ -949,7 +949,13 @@ static void gen_ext_h(DisasContext *ctx, TCGv vc, TCGv va, int rb, bool islit, uint8_t lit, uint8_t byte_mask) {if (islit) { -tcg_gen_shli_i64 (vc, va, (64 - lit *8 ) &0x3f ); +int pos = (64 - lit *8 ) &0x3f ; +int len =cto32 (byte_mask) *8 ; +if (pos < len) { +tcg_gen_deposit_z_i64 (vc, va, pos, len - pos); + }else { +tcg_gen_movi_i64 (vc,0 ); + } }else {TCGv tmp =tcg_temp_new ();tcg_gen_shli_i64 (tmp,load_gpr (ctx, rb),3 );
@@ -966,38 +972,44 @@ static void gen_ext_l(DisasContext *ctx, TCGv vc, TCGv va, int rb, bool islit, uint8_t lit, uint8_t byte_mask) {if (islit) { -tcg_gen_shri_i64 (vc, va, (lit &7 ) *8 ); +int pos = (lit &7 ) *8 ; +int len =cto32 (byte_mask) *8 ; +if (pos + len >=64 ) { + len =64 - pos; + } +tcg_gen_extract_i64 (vc, va, pos, len); }else {TCGv tmp =tcg_temp_new ();tcg_gen_andi_i64 (tmp,load_gpr (ctx, rb),7 );tcg_gen_shli_i64 (tmp, tmp,3 );tcg_gen_shr_i64 (vc, va, tmp);tcg_temp_free (tmp); +gen_zapnoti (vc, vc, byte_mask); } -gen_zapnoti (vc, vc, byte_mask); }/* INSWH, INSLH, INSQH */ static void gen_ins_h (DisasContext *ctx,TCGv vc,TCGv va,int rb,bool islit,uint8_t lit,uint8_t byte_mask) { -TCGv tmp =tcg_temp_new (); - -/* The instruction description has us left-shift the byte mask and extract -bits <15:8> and apply that zap at the end. This is equivalent to simply -performing the zap first and shifting afterward. */ -gen_zapnoti (tmp, va, byte_mask); -if (islit) { - lit &=7 ; -if (unlikely (lit ==0 )) { -tcg_gen_movi_i64 (vc,0 ); +int pos =64 - (lit &7 ) *8 ; +int len =cto32 (byte_mask) *8 ; +if (pos < len) { +tcg_gen_extract_i64 (vc, va, pos, len - pos); }else { -tcg_gen_shri_i64 (vc, tmp,64 - lit *8 ); +tcg_gen_movi_i64 (vc,0 ); } }else { +TCGv tmp =tcg_temp_new ();TCGv shift =tcg_temp_new (); +/* The instruction description has us left-shift the byte mask +and extract bits <15:8> and apply that zap at the end. This +is equivalent to simply performing the zap first and shifting +afterward. */ +gen_zapnoti (tmp, va, byte_mask); +/* If (B & 7) == 0, we need to shift by 64 and leave a zero. Do this portably by splitting the shift into two parts: shift_count-1 and 1. Arrange for the -1 by using ones-complement instead of
@@ -1010,32 +1022,37 @@ static void gen_ins_h(DisasContext *ctx, TCGv vc, TCGv va, int rb, bool islit,tcg_gen_shr_i64 (vc, tmp, shift);tcg_gen_shri_i64 (vc, vc,1 );tcg_temp_free (shift); +tcg_temp_free (tmp); } -tcg_temp_free (tmp); }/* INSBL, INSWL, INSLL, INSQL */ static void gen_ins_l (DisasContext *ctx,TCGv vc,TCGv va,int rb,bool islit,uint8_t lit,uint8_t byte_mask) { -TCGv tmp =tcg_temp_new (); - -/* The instruction description has us left-shift the byte mask -the same number of byte slots as the data and apply the zap -at the end. This is equivalent to simply performing the zap -first and shifting afterward. */ -gen_zapnoti (tmp, va, byte_mask); -if (islit) { -tcg_gen_shli_i64 (vc, tmp, (lit &7 ) *8 ); +int pos = (lit &7 ) *8 ; +int len =cto32 (byte_mask) *8 ; +if (pos + len >64 ) { + len =64 - pos; + } +tcg_gen_deposit_z_i64 (vc, va, pos, len); }else { +TCGv tmp =tcg_temp_new ();TCGv shift =tcg_temp_new (); + +/* The instruction description has us left-shift the byte mask +and extract bits <15:8> and apply that zap at the end. This +is equivalent to simply performing the zap first and shifting +afterward. */ +gen_zapnoti (tmp, va, byte_mask); +tcg_gen_andi_i64 (shift,load_gpr (ctx, rb),7 );tcg_gen_shli_i64 (shift, shift,3 );tcg_gen_shl_i64 (vc, tmp, shift);tcg_temp_free (shift); +tcg_temp_free (tmp); } -tcg_temp_free (tmp); }/* MSKWH, MSKLH, MSKQH */
Signature · 1 line
2.7.4
PATCH v3 14/18 target-arm: Use new deposit and extract ops
In reply to Richard HendersonUse the new primitives for UBFX and SBFX.
--- target-arm/translate-a64.c | 79 +++++++++++++++------------------------------- target-arm/translate.c | 37 +++++----------------- 2 files changed, 34 insertions(+), 82 deletions(-)
target-arm/translate-a64.c +26 -53
@@ -3219,67 +3219,40 @@ static void disas_bitfield(DisasContext *s, uint32_t insn)low 32-bits anyway. */ tcg_tmp =read_cpu_reg (s, rn,1 ); -/* Recognize the common aliases. */ -if (opc ==0 ) {/* SBFM */ -if (ri ==0 ) { -if (si ==7 ) {/* SXTB */ -tcg_gen_ext8s_i64 (tcg_rd, tcg_tmp); - goto done; - }else if (si ==15 ) {/* SXTH */ -tcg_gen_ext16s_i64 (tcg_rd, tcg_tmp); - goto done; - }else if (si ==31 ) {/* SXTW */ -tcg_gen_ext32s_i64 (tcg_rd, tcg_tmp); - goto done; - } - } -if (si ==63 || (si ==31 && ri <= si)) {/* ASR */ -if (si ==31 ) { -tcg_gen_ext32s_i64 (tcg_tmp, tcg_tmp); - } -tcg_gen_sari_i64 (tcg_rd, tcg_tmp, ri); +/* Recognize simple(r) extractions. */ +if (ri <= si) { +int len = (si - ri) +1 ; +if (opc ==0 ) {/* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */ +tcg_gen_sextract_i64 (tcg_rd, tcg_tmp, ri, len); goto done; - } - }else if (opc ==2 ) {/* UBFM */ -if (ri ==0 ) {/* UXTB, UXTH, plus non-canonical AND */ -tcg_gen_andi_i64 (tcg_rd, tcg_tmp,bitmask64 (si +1 )); -return ; - } -if (si ==63 || (si ==31 && ri <= si)) {/* LSR */ -if (si ==31 ) { -tcg_gen_ext32u_i64 (tcg_tmp, tcg_tmp); - } -tcg_gen_shri_i64 (tcg_rd, tcg_tmp, ri); + }else if (opc ==2 ) {/* UBFM: UBFX, LSR, UXTB, UXTH */ +tcg_gen_extract_i64 (tcg_rd, tcg_tmp, ri, len);return ; } -if (si +1 == ri && si != bitsize -1 ) {/* LSL */ -int shift = bitsize -1 - si; -tcg_gen_shli_i64 (tcg_rd, tcg_tmp, shift); - goto done; - } } -if (opc !=1 ) {/* SBFM or UBFM */ -tcg_gen_movi_i64 (tcg_rd,0 ); - } +/* Do the bit move operation. Note that above we handled ri <= si, +Wd<s-r:0> = Wn<s:r>, via tcg_gen_*extract_i64. Now we handle +the ri > si case, Wd<32+s-r,32-r> = Wn<s:0>, via deposit. */ + pos = (bitsize - ri) & (bitsize -1 ); + len = si +1 ; -/* do the bit move operation */ -if (si >= ri) { -/* Wd<s-r:0> = Wn<s:r> */ -tcg_gen_shri_i64 (tcg_tmp, tcg_tmp, ri); - pos =0 ; - len = (si - ri) +1 ; - }else { -/* Wd<32+s-r,32-r> = Wn<s:0> */ - pos = bitsize - ri; - len = si +1 ; +if (opc ==0 && len < ri) { +/* SBFM: sign extend the destination field from len to fill +the balance of the word. Let the deposit below insert all +of those sign bits. */ +tcg_gen_sextract_i64 (tcg_tmp, tcg_tmp,0 , len); + len = ri; } -tcg_gen_deposit_i64 (tcg_rd, tcg_rd, tcg_tmp, pos, len); - -if (opc ==0 ) {/* SBFM - sign extend the destination field */ -tcg_gen_shli_i64 (tcg_rd, tcg_rd,64 - (pos + len)); -tcg_gen_sari_i64 (tcg_rd, tcg_rd,64 - (pos + len)); +if (opc ==1 ) {/* BFM */ +tcg_gen_deposit_i64 (tcg_rd, tcg_rd, tcg_tmp, pos, len); + }else { +/* SBFM or UBFM: We start with zero, and we haven't modified +any bits outside bitsize, therefore the zero-extension +below is unneeded. */ +tcg_gen_deposit_z_i64 (tcg_rd, tcg_tmp, pos, len); +return ; } done:
target-arm/translate.c +8 -29
@@ -288,29 +288,6 @@ static void gen_revsh(TCGv_i32 var)tcg_gen_ext16s_i32 (var, var); } -/* Unsigned bitfield extract. */ -static void gen_ubfx (TCGv_i32 var,int shift,uint32_t mask) -{ -if (shift) -tcg_gen_shri_i32 (var, var, shift); -tcg_gen_andi_i32 (var, var, mask); -} - -/* Signed bitfield extract. */ -static void gen_sbfx (TCGv_i32 var,int shift,int width) -{ -uint32_t signbit; - -if (shift) -tcg_gen_sari_i32 (var, var, shift); -if (shift + width <32 ) { - signbit =1u << (width -1 ); -tcg_gen_andi_i32 (var, var, (1u << width) -1 ); -tcg_gen_xori_i32 (var, var, signbit); -tcg_gen_subi_i32 (var, var, signbit); - } -} -/* Return (b << 32) + a. Mark inputs as dead */ static TCGv_i64 gen_addq_msw (TCGv_i64 a,TCGv_i32 b) {
@@ -9178,9 +9155,9 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) goto illegal_op;if (i <32 ) {if (op1 &0x20 ) { -gen_ubfx (tmp, shift, (1u << i) -1 ); +tcg_gen_extract_i32 (tmp, tmp, shift, i); }else { -gen_sbfx (tmp, shift, i); +tcg_gen_sextract_i32 (tmp, tmp, shift, i); } }store_reg (s, rd, tmp);
@@ -10497,15 +10474,17 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw imm++;if (shift + imm >32 ) goto illegal_op; -if (imm <32 ) -gen_sbfx (tmp, shift, imm); +if (imm <32 ) { +tcg_gen_sextract_i32 (tmp, tmp, shift, imm); + }break ;case 6 :/* Unsigned bitfield extract. */ imm++;if (shift + imm >32 ) goto illegal_op; -if (imm <32 ) -gen_ubfx (tmp, shift, (1u << imm) -1 ); +if (imm <32 ) { +tcg_gen_extract_i32 (tmp, tmp, shift, imm); + }break ;case 3 :/* Bitfield insert/clear. */ if (imm < shift)
Signature · 1 line
2.7.4
PATCH v3 15/18 target-i386: Use new deposit and extract ops
In reply to Richard HendersonA couple of places where it was easy to identify a right-shift followed by an extract or and-with-immediate, and the obvious sign-extract from a high byte register.
--- target-i386/translate.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
target-i386/translate.c +23 -22
@@ -383,8 +383,7 @@ static void gen_op_mov_reg_v(TCGMemOp ot, int reg, TCGv t0)static inline void gen_op_mov_v_reg (TCGMemOp ot,TCGv t0,int reg) {if (ot ==MO_8 &&byte_reg_is_xH (reg)) { -tcg_gen_shri_tl (t0, cpu_regs[reg -4 ],8 ); -tcg_gen_ext8u_tl (t0, t0); +tcg_gen_extract_tl (t0, cpu_regs[reg -4 ],8 ,8 ); }else {tcg_gen_mov_tl (t0, cpu_regs[reg]); }
@@ -3756,8 +3755,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,/* Extract the LEN into a mask. Lengths larger than operand size get all ones. */ -tcg_gen_shri_tl (cpu_A0, cpu_regs[s->vex_v],8 ); -tcg_gen_ext8u_tl (cpu_A0, cpu_A0); +tcg_gen_extract_tl (cpu_A0, cpu_regs[s->vex_v],8 ,8 );tcg_gen_movcond_tl (TCG_COND_LEU , cpu_A0, cpu_A0, bound, cpu_A0, bound);tcg_temp_free (bound);
@@ -3908,9 +3906,8 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,gen_compute_eflags (s); } carry_in = cpu_tmp0; -tcg_gen_shri_tl (carry_in, cpu_cc_src, -ctz32 (b ==0x1f6 ?CC_C :CC_O )); -tcg_gen_andi_tl (carry_in, carry_in,1 ); +tcg_gen_extract_tl (carry_in, cpu_cc_src, +ctz32 (b ==0x1f6 ?CC_C :CC_O ),1 ); }switch (ot) {
@@ -5435,21 +5432,25 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, rm = (modrm &7 ) |REX_B (s);if (mod ==3 ) { -gen_op_mov_v_reg (ot, cpu_T0, rm); -switch (s_ot) { -case MO_UB : -tcg_gen_ext8u_tl (cpu_T0, cpu_T0); -break ; -case MO_SB : -tcg_gen_ext8s_tl (cpu_T0, cpu_T0); -break ; -case MO_UW : -tcg_gen_ext16u_tl (cpu_T0, cpu_T0); -break ; -default : -case MO_SW : -tcg_gen_ext16s_tl (cpu_T0, cpu_T0); -break ; +if (s_ot ==MO_SB &&byte_reg_is_xH (rm)) { +tcg_gen_sextract_tl (cpu_T0, cpu_regs[rm -4 ],8 ,8 ); + }else { +gen_op_mov_v_reg (ot, cpu_T0, rm); +switch (s_ot) { +case MO_UB : +tcg_gen_ext8u_tl (cpu_T0, cpu_T0); +break ; +case MO_SB : +tcg_gen_ext8s_tl (cpu_T0, cpu_T0); +break ; +case MO_UW : +tcg_gen_ext16u_tl (cpu_T0, cpu_T0); +break ; +default : +case MO_SW : +tcg_gen_ext16s_tl (cpu_T0, cpu_T0); +break ; + } }gen_op_mov_reg_v (d_ot, reg, cpu_T0); }else {
Signature · 1 line
2.7.4
PATCH v3 16/18 target-mips: Use the new extract op
In reply to Richard HendersonUse extract for EXT and DEXT.
--- target-mips/translate.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
target-mips/translate.c +5 -7
@@ -4484,11 +4484,12 @@ static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,if (lsb + msb >31 ) { goto fail; } -tcg_gen_shri_tl (t0, t1, lsb);if (msb !=31 ) { -tcg_gen_andi_tl (t0, t0, (1U << (msb +1 )) -1 ); +tcg_gen_extract_tl (t0, t1, lsb, msb +1 ); }else { -tcg_gen_ext32s_tl (t0, t0); +/* The two checks together imply that lsb == 0, +so this is a simple sign-extension. */ +tcg_gen_ext32s_tl (t0, t1); }break ;#if defined(TARGET_MIPS64 )
@@ -4503,10 +4504,7 @@ static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,if (lsb + msb >63 ) { goto fail; } -tcg_gen_shri_tl (t0, t1, lsb); -if (msb !=63 ) { -tcg_gen_andi_tl (t0, t0, (1ULL << (msb +1 )) -1 ); - } +tcg_gen_extract_tl (t0, t1, lsb, msb +1 );break ;#endif case OPC_INS :
Signature · 1 line
2.7.4
PATCH v3 17/18 target-ppc: Use the new deposit and extract ops
In reply to Richard HendersonUse the new primitives for RDWINM and RLDICL.
--- target-ppc/translate.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
target-ppc/translate.c +19 -16
@@ -1975,16 +1975,16 @@ static void gen_rlwinm(DisasContext *ctx) {TCGv t_ra = cpu_gpr[rA (ctx->opcode)];TCGv t_rs = cpu_gpr[rS (ctx->opcode)]; -uint32_t sh =SH (ctx->opcode); -uint32_t mb =MB (ctx->opcode); -uint32_t me =ME (ctx->opcode); - -if (mb ==0 && me == (31 - sh)) { -tcg_gen_shli_tl (t_ra, t_rs, sh); -tcg_gen_ext32u_tl (t_ra, t_ra); - }else if (sh !=0 && me ==31 && sh == (32 - mb)) { -tcg_gen_ext32u_tl (t_ra, t_rs); -tcg_gen_shri_tl (t_ra, t_ra, mb); +int sh =SH (ctx->opcode); +int mb =MB (ctx->opcode); +int me =ME (ctx->opcode); +int len = me - mb +1 ; +int rsh = (32 - sh) &31 ; + +if (sh !=0 && len >0 && me == (31 - sh)) { +tcg_gen_deposit_z_tl (t_ra, t_rs, sh, len); + }else if (me ==31 && rsh + len <=32 ) { +tcg_gen_extract_tl (t_ra, t_rs, rsh, len); }else {target_ulong mask;#if defined(TARGET_PPC64 )
@@ -1992,8 +1992,9 @@ static void gen_rlwinm(DisasContext *ctx) me +=32 ;#endif mask =MASK (mb, me); - -if (mask <=0xffffffffu ) { +if (sh ==0 ) { +tcg_gen_andi_tl (t_ra, t_rs, mask); + }else if (mask <=0xffffffffu ) {TCGv_i32 t0 =tcg_temp_new_i32 ();tcg_gen_trunc_tl_i32 (t0, t_rs);tcg_gen_rotli_i32 (t0, t0, sh);
@@ -2096,11 +2097,13 @@ static void gen_rldinm(DisasContext *ctx, int mb, int me, int sh) {TCGv t_ra = cpu_gpr[rA (ctx->opcode)];TCGv t_rs = cpu_gpr[rS (ctx->opcode)]; +int len = me - mb +1 ; +int rsh = (64 - sh) &63 ; -if (sh !=0 && mb ==0 && me == (63 - sh)) { -tcg_gen_shli_tl (t_ra, t_rs, sh); - }else if (sh !=0 && me ==63 && sh == (64 - mb)) { -tcg_gen_shri_tl (t_ra, t_rs, mb); +if (sh !=0 && len >0 && me == (63 - sh)) { +tcg_gen_deposit_z_tl (t_ra, t_rs, sh, len); + }else if (me ==63 && rsh + len <=64 ) { +tcg_gen_extract_tl (t_ra, t_rs, rsh, len); }else {tcg_gen_rotli_tl (t_ra, t_rs, sh);tcg_gen_andi_tl (t_ra, t_ra,MASK (mb, me));
Signature · 1 line
2.7.4
PATCH v3 18/18 target-s390x: Use the new deposit and extract ops
In reply to Richard HendersonUse the new primitives for RISBG.
--- target-s390x/translate.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
target-s390x/translate.c +22 -12
@@ -3134,20 +3134,26 @@ static ExitStatus op_risbg(DisasContext *s, DisasOps *o) } } -/* In some cases we can implement this with deposit, which can be more -efficient on some hosts. */ -if (~mask == imask && i3 <= i4) { -if (s->fields->op2 ==0x5d ) { - i3 +=32 , i4 +=32 ; - } + len = i4 - i3 +1 ; + pos =63 - i4; + rot = i5 &63 ; +if (s->fields->op2 ==0x5d ) { + pos +=32 ; + } + +/* In some cases we can implement this with extract. */ +if (imask ==0 && pos ==0 && len >0 && rot + len <=64 ) { +tcg_gen_extract_i64 (o->out, o->in2, rot, len); +return NO_EXIT ; + } + +/* In some cases we can implement this with deposit. */ +if (len >0 && (imask ==0 || ~mask == imask)) {/* Note that we rotate the bits to be inserted to the lsb, not to the position as described in the PoO. */ - len = i4 - i3 +1 ; - pos =63 - i4; - rot = (i5 - pos) &63 ; + rot = (rot - pos) &63 ; }else { - pos = len =-1 ; - rot = i5 &63 ; + pos =-1 ; }/* Rotate the input as necessary. */
@@ -3155,7 +3161,11 @@ static ExitStatus op_risbg(DisasContext *s, DisasOps *o)/* Insert the selected bits into the output. */ if (pos >=0 ) { -tcg_gen_deposit_i64 (o->out, o->out, o->in2, pos, len); +if (imask ==0 ) { +tcg_gen_deposit_z_i64 (o->out, o->in2, pos, len); + }else { +tcg_gen_deposit_i64 (o->out, o->out, o->in2, pos, len); + } }else if (imask ==0 ) {tcg_gen_andi_i64 (o->out, o->in2, mask); }else {
Signature · 1 line
2.7.4
Your series seems to have some coding style problems. See output below for more information:
Hi,
Your series seems to have some coding style problems. See output below for more information:
Type: series
Subject: [Qemu-devel] [patch v3 00/18] tcg field extract primitives
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
5f8de8d target-s390x: Use the new deposit and extract ops 5d887cd target-ppc: Use the new deposit and extract ops 823629a target-mips: Use the new extract op b1df231 target-i386: Use new deposit and extract ops 4fcc1ad target-arm: Use new deposit and extract ops 38aa933 target-alpha: Use deposit and extract ops 935116b tcg/s390: Support deposit into zero bc2ecb0 tcg/s390: Implement field extraction opcodes 34f18c5 tcg/s390: Expose host facilities to tcg-target.h 830033c tcg/ppc: Implement field extraction opcodes 7b20c32 tcg/mips: Implement field extraction opcodes 8e69031 tcg/i386: Implement field extraction opcodes a10576c tcg/arm: Implement field extraction opcodes ce7e87e tcg/arm: Move isa detection to tcg-target.h ae30586 tcg/aarch64: Implement field extraction opcodes fbb4fe9 tcg: Add deposit_z expander
4745d42 tcg: Minor adjustments to deposit expanders e29bca5 tcg: Add field extraction primitives
=== OUTPUT BEGIN ===
Checking PATCH 1/18: tcg: Add field extraction primitives...
ERROR: spaces required around that ':' (ctx:VxE) #139: FILE: tcg/optimize.c:881:
+ CASE_OP_32_64(extract):
^
ERROR: spaces required around that ':' (ctx:VxE)
#145: FILE: tcg/optimize.c:887:
+ CASE_OP_32_64(sextract):
^
ERROR: spaces required around that ':' (ctx:VxE)
#159: FILE: tcg/optimize.c:1064:
+ CASE_OP_32_64(extract):
^
ERROR: spaces required around that ':' (ctx:VxE)
#167: FILE: tcg/optimize.c:1072:
+ CASE_OP_32_64(sextract):
^
ERROR: space prohibited after that '&&' (ctx:ExW)
#271: FILE: tcg/tcg-op.c:582:
+ && TCG_TARGET_extract_i32_valid(ofs, len)) {
^ERROR: space prohibited after that '&&' (ctx:ExW)
#334: FILE: tcg/tcg-op.c:645:
+ && TCG_TARGET_extract_i32_valid(ofs, len)) {
^ERROR: space prohibited after that '&&' (ctx:ExW)
#420: FILE: tcg/tcg-op.c:1799:
+ && TCG_TARGET_extract_i64_valid(ofs, len)) {
^ERROR: space prohibited after that '&&' (ctx:ExW)
#526: FILE: tcg/tcg-op.c:1905:
+ && TCG_TARGET_extract_i64_valid(ofs, len)) {
^total: 8 errors, 0 warnings, 599 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 2/18: tcg: Minor adjustments to deposit expanders... Checking PATCH 3/18: tcg: Add deposit_z expander...
ERROR: space prohibited after that '&&' (ctx:ExW)
#33: FILE: tcg/tcg-op.c:577:
+ && TCG_TARGET_deposit_i32_valid(ofs, len)) {
^ERROR: space prohibited after that '&&' (ctx:ExW)
#98: FILE: tcg/tcg-op.c:1836:
+ && TCG_TARGET_deposit_i64_valid(ofs, len)) {
^total: 2 errors, 0 warnings, 185 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 4/18: tcg/aarch64: Implement field extraction opcodes... Checking PATCH 5/18: tcg/arm: Move isa detection to tcg-target.h...
WARNING: architecture specific defines should be avoided #19: FILE: tcg/arm/tcg-target.h:30:
+#ifndef __ARM_ARCH
WARNING: architecture specific defines should be avoided #20: FILE: tcg/arm/tcg-target.h:31:
+# if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
WARNING: architecture specific defines should be avoided #39: FILE: tcg/arm/tcg-target.h:50:
+#if defined(__ARM_ARCH_5T__) \
total: 0 errors, 3 warnings, 107 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 6/18: tcg/arm: Implement field extraction opcodes... Checking PATCH 7/18: tcg/i386: Implement field extraction opcodes... Checking PATCH 8/18: tcg/mips: Implement field extraction opcodes... Checking PATCH 9/18: tcg/ppc: Implement field extraction opcodes... Checking PATCH 10/18: tcg/s390: Expose host facilities to tcg-target.h... Checking PATCH 11/18: tcg/s390: Implement field extraction opcodes...
ERROR: spaces required around that ':' (ctx:VxE)
#52: FILE: tcg/s390/tcg-target.inc.c:2162:
+ OP_32_64(extract):
^
total: 1 errors, 0 warnings, 51 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 12/18: tcg/s390: Support deposit into zero... Checking PATCH 13/18: target-alpha: Use deposit and extract ops... Checking PATCH 14/18: target-arm: Use new deposit and extract ops... Checking PATCH 15/18: target-i386: Use new deposit and extract ops... Checking PATCH 16/18: target-mips: Use the new extract op... Checking PATCH 17/18: target-ppc: Use the new deposit and extract ops... Checking PATCH 18/18: target-s390x: Use the new deposit and extract ops... === OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]