diff mbox series

[v2,02/22] tcg/i386: Move constraint type check to tcg_target_const_match

Message ID 20210115210456.1053477-3-richard.henderson@linaro.org
State Superseded
Headers show
Series tcg: backend constraints cleanup | expand

Commit Message

Richard Henderson Jan. 15, 2021, 9:04 p.m. UTC
Rather than check the type when filling in the constraint,
check it when matching the constant.  This removes the only
use of the type argument to target_parse_constraint.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 tcg/i386/tcg-target.c.inc | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

-- 
2.25.1

Comments

Peter Maydell Jan. 19, 2021, 2:27 p.m. UTC | #1
On Fri, 15 Jan 2021 at 21:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>

> Rather than check the type when filling in the constraint,

> check it when matching the constant.  This removes the only

> use of the type argument to target_parse_constraint.

>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  tcg/i386/tcg-target.c.inc | 28 +++++++++++++++++-----------

>  1 file changed, 17 insertions(+), 11 deletions(-)

>

> diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc

> index 050f3cb0b1..74637f654a 100644

> --- a/tcg/i386/tcg-target.c.inc

> +++ b/tcg/i386/tcg-target.c.inc

> @@ -263,13 +263,13 @@ static const char *target_parse_constraint(TCGArgConstraint *ct,

>          break;

>

>      case 'e':

> -        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_S32);

> +        ct->ct |= TCG_CT_CONST_S32;

>          break;

>      case 'Z':

> -        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_U32);

> +        ct->ct |= TCG_CT_CONST_U32;

>          break;

>      case 'I':

> -        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_I32);

> +        ct->ct |= TCG_CT_CONST_I32;

>          break;

>

>      default:

> @@ -286,14 +286,20 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type,

>      if (ct & TCG_CT_CONST) {

>          return 1;

>      }

> -    if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) {

> -        return 1;

> -    }

> -    if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) {

> -        return 1;

> -    }

> -    if ((ct & TCG_CT_CONST_I32) && ~val == (int32_t)~val) {

> -        return 1;

> +    if (TCG_TARGET_REG_BITS == 32 || type == TCG_TYPE_I32) {


Where does the TCG_TARGET_REG_BITS check come from? We weren't
testing that in the old code in target_parse_constraint() that
I can see.

> +        if (ct & (TCG_CT_CONST_S32 | TCG_CT_CONST_U32 | TCG_CT_CONST_I32)) {

> +            return 1;

> +        }

> +    } else {

> +        if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) {

> +            return 1;

> +        }

> +        if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) {

> +            return 1;

> +        }

> +        if ((ct & TCG_CT_CONST_I32) && ~val == (int32_t)~val) {

> +            return 1;

> +        }

>      }

>      if ((ct & TCG_CT_CONST_WSZ) && val == (type == TCG_TYPE_I32 ? 32 : 64)) {

>          return 1;


thanks
-- PMM
Richard Henderson Jan. 19, 2021, 7:19 p.m. UTC | #2
On 1/19/21 4:27 AM, Peter Maydell wrote:
> On Fri, 15 Jan 2021 at 21:14, Richard Henderson

> <richard.henderson@linaro.org> wrote:

>>

>> Rather than check the type when filling in the constraint,

>> check it when matching the constant.  This removes the only

>> use of the type argument to target_parse_constraint.

>>

>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

>> ---

>>  tcg/i386/tcg-target.c.inc | 28 +++++++++++++++++-----------

>>  1 file changed, 17 insertions(+), 11 deletions(-)

>>

>> diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc

>> index 050f3cb0b1..74637f654a 100644

>> --- a/tcg/i386/tcg-target.c.inc

>> +++ b/tcg/i386/tcg-target.c.inc

>> @@ -263,13 +263,13 @@ static const char *target_parse_constraint(TCGArgConstraint *ct,

>>          break;

>>

>>      case 'e':

>> -        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_S32);

>> +        ct->ct |= TCG_CT_CONST_S32;

>>          break;

>>      case 'Z':

>> -        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_U32);

>> +        ct->ct |= TCG_CT_CONST_U32;

>>          break;

>>      case 'I':

>> -        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_I32);

>> +        ct->ct |= TCG_CT_CONST_I32;

>>          break;

>>

>>      default:

>> @@ -286,14 +286,20 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type,

>>      if (ct & TCG_CT_CONST) {

>>          return 1;

>>      }

>> -    if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) {

>> -        return 1;

>> -    }

>> -    if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) {

>> -        return 1;

>> -    }

>> -    if ((ct & TCG_CT_CONST_I32) && ~val == (int32_t)~val) {

>> -        return 1;

>> +    if (TCG_TARGET_REG_BITS == 32 || type == TCG_TYPE_I32) {

> 

> Where does the TCG_TARGET_REG_BITS check come from? We weren't

> testing that in the old code in target_parse_constraint() that

> I can see.


Premature optimization and a separate change.
Dropped.


r~

> 

>> +        if (ct & (TCG_CT_CONST_S32 | TCG_CT_CONST_U32 | TCG_CT_CONST_I32)) {

>> +            return 1;

>> +        }

>> +    } else {

>> +        if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) {

>> +            return 1;

>> +        }

>> +        if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) {

>> +            return 1;

>> +        }

>> +        if ((ct & TCG_CT_CONST_I32) && ~val == (int32_t)~val) {

>> +            return 1;

>> +        }

>>      }

>>      if ((ct & TCG_CT_CONST_WSZ) && val == (type == TCG_TYPE_I32 ? 32 : 64)) {

>>          return 1;

> 

> thanks

> -- PMM

>
diff mbox series

Patch

diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
index 050f3cb0b1..74637f654a 100644
--- a/tcg/i386/tcg-target.c.inc
+++ b/tcg/i386/tcg-target.c.inc
@@ -263,13 +263,13 @@  static const char *target_parse_constraint(TCGArgConstraint *ct,
         break;
 
     case 'e':
-        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_S32);
+        ct->ct |= TCG_CT_CONST_S32;
         break;
     case 'Z':
-        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_U32);
+        ct->ct |= TCG_CT_CONST_U32;
         break;
     case 'I':
-        ct->ct |= (type == TCG_TYPE_I32 ? TCG_CT_CONST : TCG_CT_CONST_I32);
+        ct->ct |= TCG_CT_CONST_I32;
         break;
 
     default:
@@ -286,14 +286,20 @@  static inline int tcg_target_const_match(tcg_target_long val, TCGType type,
     if (ct & TCG_CT_CONST) {
         return 1;
     }
-    if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) {
-        return 1;
-    }
-    if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) {
-        return 1;
-    }
-    if ((ct & TCG_CT_CONST_I32) && ~val == (int32_t)~val) {
-        return 1;
+    if (TCG_TARGET_REG_BITS == 32 || type == TCG_TYPE_I32) {
+        if (ct & (TCG_CT_CONST_S32 | TCG_CT_CONST_U32 | TCG_CT_CONST_I32)) {
+            return 1;
+        }
+    } else {
+        if ((ct & TCG_CT_CONST_S32) && val == (int32_t)val) {
+            return 1;
+        }
+        if ((ct & TCG_CT_CONST_U32) && val == (uint32_t)val) {
+            return 1;
+        }
+        if ((ct & TCG_CT_CONST_I32) && ~val == (int32_t)~val) {
+            return 1;
+        }
     }
     if ((ct & TCG_CT_CONST_WSZ) && val == (type == TCG_TYPE_I32 ? 32 : 64)) {
         return 1;