TCGCond improvements
cover TCGCond improvements
The second patch comes from the target-s390 patch set I've been working on. The first patch has been split out from that. The third patch provides tcg_high_cond globally, as the 32-bit sparc port suffers from the same bug that afflicted hppa.
Richard Henderson (3):
tcg: Add is_unsigned_cond
tcg: Add TCG_COND_NEVER, TCG_COND_ALWAYS
tcg: Add tcg_high_cond
tcg/arm/tcg-target.c | 2 +- tcg/hppa/tcg-target.c | 19 ++---------- tcg/i386/tcg-target.c | 2 +- tcg/optimize.c | 6 ++++ tcg/ppc/tcg-target.c | 2 +- tcg/ppc64/tcg-target.c | 2 +- tcg/s390/tcg-target.c | 6 ++-- tcg/sparc/tcg-target.c | 2 +- tcg/tcg-op.h | 82 ++++++++++++++++++++++++++++++++++++++------------ tcg/tcg.c | 2 ++ tcg/tcg.h | 57 +++++++++++++++++++++++++++-------- 11 files changed, 126 insertions(+), 56 deletions(-)
Signature · 1 line
1.7.11.4
PATCH 1/3 tcg: Add is_unsigned_cond
Before we rearrange the TCG_COND enumeration, add a predicate for the (single) use of comparisons vs TCGCond.
--- tcg/s390/tcg-target.c | 2 +- tcg/tcg.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
tcg/s390/tcg-target.c +1 -1
@@ -1113,7 +1113,7 @@ static void tgen64_xori(TCGContext *s, TCGReg dest, tcg_target_ulong val)static int tgen_cmp (TCGContext *s,TCGType type,TCGCond c,TCGReg r1,TCGArg c2,int c2const) { -bool is_unsigned = (c >TCG_COND_GT ); +bool is_unsigned =is_unsigned_cond (c);if (c2const) {if (c2 ==0 ) {if (type ==TCG_TYPE_I32 ) {
tcg/tcg.h +5 -0
@@ -298,6 +298,11 @@ static inline TCGCond tcg_unsigned_cond(TCGCond c)return (c >=TCG_COND_LT && c <=TCG_COND_GT ? c +4 : c); } +static inline bool is_unsigned_cond (TCGCond c) +{ +return c >=TCG_COND_LTU ; +} +#define TEMP_VAL_DEAD 0#define TEMP_VAL_REG 1#define TEMP_VAL_MEM 2
Signature · 1 line
1.7.11.4
PATCH 2/3 tcg: Add TCG_COND_NEVER, TCG_COND_ALWAYS
In reply to Richard HendersonThere are several cases that can be handled easier inside both translators and code generators if we have out-of-band values for conditions. It's easy enough to handle ALWAYS and NEVER in the natural way inside the tcg middle-end.
--- tcg/arm/tcg-target.c | 2 +- tcg/hppa/tcg-target.c | 2 +- tcg/i386/tcg-target.c | 2 +- tcg/optimize.c | 6 ++++ tcg/ppc/tcg-target.c | 2 +- tcg/ppc64/tcg-target.c | 2 +- tcg/s390/tcg-target.c | 4 +-- tcg/sparc/tcg-target.c | 2 +- tcg/tcg-op.h | 82 ++++++++++++++++++++++++++++++++++++++------------ tcg/tcg.c | 2 ++ tcg/tcg.h | 37 ++++++++++++++--------- 11 files changed, 102 insertions(+), 41 deletions(-)
tcg/arm/tcg-target.c +1 -1
@@ -335,7 +335,7 @@ enum arm_cond_code_e { COND_AL = 0xe, }; -static const uint8_t tcg_cond_to_arm_cond[10 ] = { +static const uint8_t tcg_cond_to_arm_cond[] = { [TCG_COND_EQ ] =COND_EQ , [TCG_COND_NE ] =COND_NE , [TCG_COND_LT ] =COND_LT ,
tcg/hppa/tcg-target.c +1 -1
@@ -732,7 +732,7 @@ static void tcg_out_branch(TCGContext *s, int label_index, int nul) } } -static const uint8_t tcg_cond_to_cmp_cond[10 ] = +static const uint8_t tcg_cond_to_cmp_cond[] = { [TCG_COND_EQ ] =COND_EQ , [TCG_COND_NE ] =COND_EQ |COND_FALSE ,
tcg/i386/tcg-target.c +1 -1
@@ -338,7 +338,7 @@ static inline int tcg_target_const_match(tcg_target_long val,#define JCC_JLE 0xe#define JCC_JG 0xf -static const uint8_t tcg_cond_to_jcc[10 ] = { +static const uint8_t tcg_cond_to_jcc[] = { [TCG_COND_EQ ] =JCC_JE , [TCG_COND_NE ] =JCC_JNE , [TCG_COND_LT ] =JCC_JL ,
tcg/optimize.c +6 -0
@@ -321,6 +321,8 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,return (uint32_t )temps[x].val <= (uint32_t )temps[y].val;case TCG_COND_GTU :return (uint32_t )temps[x].val > (uint32_t )temps[y].val; +default : +break ; }break ;case 64 :
@@ -345,6 +347,8 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,return (uint64_t )temps[x].val <= (uint64_t )temps[y].val;case TCG_COND_GTU :return (uint64_t )temps[x].val > (uint64_t )temps[y].val; +default : +break ; }break ; }
@@ -362,6 +366,8 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,case TCG_COND_LEU :case TCG_COND_EQ :return 1 ; +default : +break ; } }else if (temps[y].state ==TCG_TEMP_CONST && temps[y].val ==0 ) {switch (c) {
tcg/ppc/tcg-target.c +1 -1
@@ -437,7 +437,7 @@ enum {CR_SO }; -static const uint32_t tcg_to_bc[10 ] = { +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/ppc64/tcg-target.c +1 -1
@@ -418,7 +418,7 @@ enum {CR_SO }; -static const uint32_t tcg_to_bc[10 ] = { +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/s390/tcg-target.c +2 -2
@@ -268,7 +268,7 @@ static const int tcg_target_call_oarg_regs[] = {#define S390_CC_ALWAYS 15/* Condition codes that result from a COMPARE and COMPARE LOGICAL. */ -static const uint8_t tcg_cond_to_s390_cond[10 ] = { +static const uint8_t tcg_cond_to_s390_cond[] = { [TCG_COND_EQ ] =S390_CC_EQ , [TCG_COND_NE ] =S390_CC_NE , [TCG_COND_LT ] =S390_CC_LT ,
@@ -284,7 +284,7 @@ static const uint8_t tcg_cond_to_s390_cond[10] = {/* 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[10 ] = { +static const uint8_t tcg_cond_to_ltr_cond[] = { [TCG_COND_EQ ] =S390_CC_EQ , [TCG_COND_NE ] =S390_CC_NE , [TCG_COND_LT ] =S390_CC_LT ,
tcg/sparc/tcg-target.c +1 -1
@@ -512,7 +512,7 @@ static void tcg_out_branch_i64(TCGContext *s, int opc, int label_index) }#endif -static const uint8_t tcg_cond_to_bcond[10 ] = { +static const uint8_t tcg_cond_to_bcond[] = { [TCG_COND_EQ ] =COND_E , [TCG_COND_NE ] =COND_NE , [TCG_COND_LT ] =COND_L ,
tcg/tcg-op.h +63 -19
131 lines not on this page · raw message
tcg/tcg.c +2 -0
@@ -860,6 +860,8 @@ static TCGHelperInfo *tcg_find_helper(TCGContext *s, tcg_target_ulong val)static const char *const cond_name[] = { + [TCG_COND_NEVER ] ="never" , + [TCG_COND_ALWAYS ] ="always" , [TCG_COND_EQ ] ="eq" , [TCG_COND_NE ] ="ne" , [TCG_COND_LT ] ="lt" ,
tcg/tcg.h +23 -14
@@ -266,18 +266,28 @@ typedef int TCGv_i64;#define TCG_CALL_DUMMY_TCGV MAKE_TCGV_I32(-1)#define TCG_CALL_DUMMY_ARG ((TCGArg)(-1)) +/* Conditions. Note that these are layed out for easy manipulation by +the the functions below: +bit 0 is used for inverting; +bit 1 is signed, +bit 2 is unsigned, +bit 3 is used with bit 0 for swapping signed/unsigned. */ typedef enum { -TCG_COND_EQ , -TCG_COND_NE , -TCG_COND_LT , -TCG_COND_GE , -TCG_COND_LE , -TCG_COND_GT , +/* non-signed */ +TCG_COND_NEVER =0 |0 |0 |0 , +TCG_COND_ALWAYS =0 |0 |0 |1 , +TCG_COND_EQ =8 |0 |0 |0 , +TCG_COND_NE =8 |0 |0 |1 , +/* signed */ +TCG_COND_LT =0 |0 |2 |0 , +TCG_COND_GE =0 |0 |2 |1 , +TCG_COND_LE =8 |0 |2 |0 , +TCG_COND_GT =8 |0 |2 |1 ,/* unsigned */ -TCG_COND_LTU , -TCG_COND_GEU , -TCG_COND_LEU , -TCG_COND_GTU , +TCG_COND_LTU =0 |4 |0 |0 , +TCG_COND_GEU =0 |4 |0 |1 , +TCG_COND_LEU =8 |4 |0 |0 , +TCG_COND_GTU =8 |4 |0 |1 , }TCGCond ;/* Invert the sense of the comparison. */
@@ -289,18 +299,17 @@ static inline TCGCond tcg_invert_cond(TCGCond c)/* Swap the operands in a comparison. */ static inline TCGCond tcg_swap_cond (TCGCond c) { -int mask = (c <TCG_COND_LT ?0 : c <TCG_COND_LTU ?7 :15 ); -return (TCGCond)(c ^ mask); +return c &6 ? (TCGCond)(c ^9 ) : c; }static inline TCGCond tcg_unsigned_cond (TCGCond c) { -return (c >=TCG_COND_LT && c <=TCG_COND_GT ? c +4 : c); +return c &2 ? (TCGCond)(c ^6 ) : c; }static inline bool is_unsigned_cond (TCGCond c) { -return c >=TCG_COND_LTU ; +return (c &4 ) !=0 ; }#define TEMP_VAL_DEAD 0
Signature · 1 line
1.7.11.4
PATCH 3/3 tcg: Add tcg_high_cond
In reply to Richard HendersonThe table that was recently added for hppa is generally usable. And with the renumbering of the TCG_COND constants it's not too difficult to compute rather than have a table.
--- tcg/hppa/tcg-target.c | 17 ++--------------- tcg/tcg.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-)
tcg/hppa/tcg-target.c +2 -15
@@ -814,19 +814,6 @@ static void tcg_out_comclr(TCGContext *s, int cond, TCGArg ret,tcg_out32 (s, op); } -static TCGCond const tcg_high_cond[] = { - [TCG_COND_EQ ] =TCG_COND_EQ , - [TCG_COND_NE ] =TCG_COND_NE , - [TCG_COND_LT ] =TCG_COND_LT , - [TCG_COND_LE ] =TCG_COND_LT , - [TCG_COND_GT ] =TCG_COND_GT , - [TCG_COND_GE ] =TCG_COND_GT , - [TCG_COND_LTU ] =TCG_COND_LTU , - [TCG_COND_LEU ] =TCG_COND_LTU , - [TCG_COND_GTU ] =TCG_COND_GTU , - [TCG_COND_GEU ] =TCG_COND_GTU -}; -static void tcg_out_brcond2 (TCGContext *s,int cond,TCGArg al,TCGArg ah,TCGArg bl,int blconst,TCGArg bh,int bhconst,int label_index)
@@ -841,7 +828,7 @@ static void tcg_out_brcond2(TCGContext *s, int cond, TCGArg al, TCGArg ah,tcg_out_brcond (s,TCG_COND_NE , ah, bh, bhconst, label_index);break ;default : -tcg_out_brcond (s, tcg_high_cond[cond], ah, bh, bhconst, label_index); +tcg_out_brcond (s,tcg_high_cond (cond), ah, bh, bhconst, label_index);tcg_out_comclr (s,TCG_COND_NE ,TCG_REG_R0 , ah, bh, bhconst);tcg_out_brcond (s,tcg_unsigned_cond (cond), al, bl, blconst, label_index);
@@ -894,7 +881,7 @@ static void tcg_out_setcond2(TCGContext *s, int cond, TCGArg ret,tcg_out_setcond (s,tcg_unsigned_cond (cond), scratch, al, bl, blconst);tcg_out_comclr (s,TCG_COND_EQ ,TCG_REG_R0 , ah, bh, bhconst);tcg_out_movi (s,TCG_TYPE_I32 , scratch,0 ); -tcg_out_comclr (s,tcg_invert_cond (tcg_high_cond[cond]), +tcg_out_comclr (s,tcg_invert_cond (tcg_high_cond (cond)),TCG_REG_R0 , ah, bh, bhconst);tcg_out_movi (s,TCG_TYPE_I32 , scratch,1 );break ;
tcg/tcg.h +17 -0
@@ -302,16 +302,33 @@ static inline TCGCond tcg_swap_cond(TCGCond c)return c &6 ? (TCGCond)(c ^9 ) : c; } +/* Create an "unsigned" version of a "signed" comparison. */ static inline TCGCond tcg_unsigned_cond (TCGCond c) {return c &2 ? (TCGCond)(c ^6 ) : c; } +/* Must a comparison be considered unsigned? */ static inline bool is_unsigned_cond (TCGCond c) {return (c &4 ) !=0 ; } +/* Create a "high" version of a double-word comparison. +This removes equality from a LTE or GTE comparison. */ +static inline TCGCond tcg_high_cond (TCGCond c) +{ +switch (c) { +case TCG_COND_GE : +case TCG_COND_LE : +case TCG_COND_GEU : +case TCG_COND_LEU : +return (TCGCond)(c ^8 ); +default : +return c; + } +} +#define TEMP_VAL_DEAD 0#define TEMP_VAL_REG 1#define TEMP_VAL_MEM 2
Signature · 1 line
1.7.11.4
Ping.
r~
Quoted 23 lines · Richard Henderson
The second patch comes from the target-s390 patch set I've been working on. The first patch has been split out from that. The third patch provides
tcg_high_condglobally, as the 32-bit sparc port suffers from the same bug that afflicted hppa.Richard Henderson (3):
tcg: Addis_unsigned_cond
tcg: AddTCG_COND_NEVER,TCG_COND_ALWAYS
tcg: Addtcg_high_condtcg/arm/tcg-target.c | 2 +- tcg/hppa/tcg-target.c | 19 ++---------- tcg/i386/tcg-target.c | 2 +- tcg/optimize.c | 6 ++++ tcg/ppc/tcg-target.c | 2 +- tcg/ppc64/tcg-target.c | 2 +- tcg/s390/tcg-target.c | 6 ++-- tcg/sparc/tcg-target.c | 2 +- tcg/tcg-op.h | 82 ++++++++++++++++++++++++++++++++++++++------------ tcg/tcg.c | 2 ++ tcg/tcg.h | 57 +++++++++++++++++++++++++++-------- 11 files changed, 126 insertions(+), 56 deletions(-)
Quoted 10 lines · Richard Henderson
The second patch comes from the target-s390 patch set I've been working on. The first patch has been split out from that. The third patch provides
tcg_high_condglobally, as the 32-bit sparc port suffers from the same bug that afflicted hppa.Richard Henderson (3):
tcg: Addis_unsigned_cond
tcg: AddTCG_COND_NEVER,TCG_COND_ALWAYS
tcg: Addtcg_high_cond
Quoted 13 lines
tcg/arm/tcg-target.c | 2 +- tcg/hppa/tcg-target.c | 19 ++---------- tcg/i386/tcg-target.c | 2 +- tcg/optimize.c | 6 ++++ tcg/ppc/tcg-target.c | 2 +- tcg/ppc64/tcg-target.c | 2 +- tcg/s390/tcg-target.c | 6 ++-- tcg/sparc/tcg-target.c | 2 +- tcg/tcg-op.h | 82 ++++++++++++++++++++++++++++++++++++++------------ tcg/tcg.c | 2 ++ tcg/tcg.h | 57 +++++++++++++++++++++++++++-------- 11 files changed, 126 insertions(+), 56 deletions(-)
Thanks, all applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net