qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Richard Henderson <rth@twiddle.net>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/7] tcg: Split out subroutines from do_constant_folding_cond
Date: Mon, 1 Oct 2012 20:46:12 +0200	[thread overview]
Message-ID: <20121001184612.GC4623@ohm.aurel32.net> (raw)
In-Reply-To: <1348766397-20731-6-git-send-email-rth@twiddle.net>

On Thu, Sep 27, 2012 at 10:19:55AM -0700, Richard Henderson wrote:
> We can re-use these for implementing double-word folding.
> 
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  tcg/optimize.c | 146 ++++++++++++++++++++++++++++++++-------------------------
>  1 file changed, 81 insertions(+), 65 deletions(-)
> 
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index c972e4f..c1881fa 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -292,6 +292,82 @@ static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y)
>      return res;
>  }
>  
> +static bool do_constant_folding_cond_32(uint32_t x, uint32_t y, TCGCond c)
> +{
> +    switch (c) {
> +    case TCG_COND_EQ:
> +        return x == y;
> +    case TCG_COND_NE:
> +        return x != y;
> +    case TCG_COND_LT:
> +        return (int32_t)x < (int32_t)y;
> +    case TCG_COND_GE:
> +        return (int32_t)x >= (int32_t)y;
> +    case TCG_COND_LE:
> +        return (int32_t)x <= (int32_t)y;
> +    case TCG_COND_GT:
> +        return (int32_t)x > (int32_t)y;
> +    case TCG_COND_LTU:
> +        return x < y;
> +    case TCG_COND_GEU:
> +        return x >= y;
> +    case TCG_COND_LEU:
> +        return x <= y;
> +    case TCG_COND_GTU:
> +        return x > y;
> +    default:
> +        tcg_abort();
> +    }
> +}
> +
> +static bool do_constant_folding_cond_64(uint64_t x, uint64_t y, TCGCond c)
> +{
> +    switch (c) {
> +    case TCG_COND_EQ:
> +        return x == y;
> +    case TCG_COND_NE:
> +        return x != y;
> +    case TCG_COND_LT:
> +        return (int64_t)x < (int64_t)y;
> +    case TCG_COND_GE:
> +        return (int64_t)x >= (int64_t)y;
> +    case TCG_COND_LE:
> +        return (int64_t)x <= (int64_t)y;
> +    case TCG_COND_GT:
> +        return (int64_t)x > (int64_t)y;
> +    case TCG_COND_LTU:
> +        return x < y;
> +    case TCG_COND_GEU:
> +        return x >= y;
> +    case TCG_COND_LEU:
> +        return x <= y;
> +    case TCG_COND_GTU:
> +        return x > y;
> +    default:
> +        tcg_abort();
> +    }
> +}
> +
> +static bool do_constant_folding_cond_eq(TCGCond c)
> +{
> +    switch (c) {
> +    case TCG_COND_GT:
> +    case TCG_COND_LTU:
> +    case TCG_COND_LT:
> +    case TCG_COND_GTU:
> +    case TCG_COND_NE:
> +        return 0;
> +    case TCG_COND_GE:
> +    case TCG_COND_GEU:
> +    case TCG_COND_LE:
> +    case TCG_COND_LEU:
> +    case TCG_COND_EQ:
> +        return 1;
> +    default:
> +        tcg_abort();
> +    }
> +}
> +
>  /* Return 2 if the condition can't be simplified, and the result
>     of the condition (0 or 1) if it can */
>  static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
> @@ -300,69 +376,14 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
>      if (temps[x].state == TCG_TEMP_CONST && temps[y].state == TCG_TEMP_CONST) {
>          switch (op_bits(op)) {
>          case 32:
> -            switch (c) {
> -            case TCG_COND_EQ:
> -                return (uint32_t)temps[x].val == (uint32_t)temps[y].val;
> -            case TCG_COND_NE:
> -                return (uint32_t)temps[x].val != (uint32_t)temps[y].val;
> -            case TCG_COND_LT:
> -                return (int32_t)temps[x].val < (int32_t)temps[y].val;
> -            case TCG_COND_GE:
> -                return (int32_t)temps[x].val >= (int32_t)temps[y].val;
> -            case TCG_COND_LE:
> -                return (int32_t)temps[x].val <= (int32_t)temps[y].val;
> -            case TCG_COND_GT:
> -                return (int32_t)temps[x].val > (int32_t)temps[y].val;
> -            case TCG_COND_LTU:
> -                return (uint32_t)temps[x].val < (uint32_t)temps[y].val;
> -            case TCG_COND_GEU:
> -                return (uint32_t)temps[x].val >= (uint32_t)temps[y].val;
> -            case TCG_COND_LEU:
> -                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;
> -            }
> -            break;
> +            return do_constant_folding_cond_32(temps[x].val, temps[y].val, c);
>          case 64:
> -            switch (c) {
> -            case TCG_COND_EQ:
> -                return (uint64_t)temps[x].val == (uint64_t)temps[y].val;
> -            case TCG_COND_NE:
> -                return (uint64_t)temps[x].val != (uint64_t)temps[y].val;
> -            case TCG_COND_LT:
> -                return (int64_t)temps[x].val < (int64_t)temps[y].val;
> -            case TCG_COND_GE:
> -                return (int64_t)temps[x].val >= (int64_t)temps[y].val;
> -            case TCG_COND_LE:
> -                return (int64_t)temps[x].val <= (int64_t)temps[y].val;
> -            case TCG_COND_GT:
> -                return (int64_t)temps[x].val > (int64_t)temps[y].val;
> -            case TCG_COND_LTU:
> -                return (uint64_t)temps[x].val < (uint64_t)temps[y].val;
> -            case TCG_COND_GEU:
> -                return (uint64_t)temps[x].val >= (uint64_t)temps[y].val;
> -            case TCG_COND_LEU:
> -                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;
> -            }
> -            break;
> +            return do_constant_folding_cond_64(temps[x].val, temps[y].val, c);
> +        default:
> +            tcg_abort();
>          }
>      } else if (temps_are_copies(x, y)) {
> -        switch (c) {
> -        case TCG_COND_GT:
> -        case TCG_COND_LTU:
> -        case TCG_COND_LT:
> -        case TCG_COND_GTU:
> -        case TCG_COND_NE:
> -            return 0;
> -        case TCG_COND_GE:
> -        case TCG_COND_GEU:
> -        case TCG_COND_LE:
> -        case TCG_COND_LEU:
> -        case TCG_COND_EQ:
> -            return 1;
> -        }
> +        return do_constant_folding_cond_eq(c);
>      } else if (temps[y].state == TCG_TEMP_CONST && temps[y].val == 0) {
>          switch (c) {
>          case TCG_COND_LTU:
> @@ -375,11 +396,6 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
>      } else {
>          return 2;
>      }
> -
> -    fprintf(stderr,
> -            "Unrecognized bitness %d or condition %d in "
> -            "do_constant_folding_cond.\n", op_bits(op), c);
> -    tcg_abort();
>  }
>  
>  static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2)

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>


-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

  reply	other threads:[~2012-10-01 18:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-27 17:19 [Qemu-devel] [PATCH 0/7] Double-word tcg/optimize improvements Richard Henderson
2012-09-27 17:19 ` [Qemu-devel] [PATCH 1/7] tcg: Split out swap_commutative as a subroutine Richard Henderson
2012-09-27 21:45   ` Aurelien Jarno
2012-09-27 17:19 ` [Qemu-devel] [PATCH 2/7] tcg: Optimize add2 + sub2 Richard Henderson
2012-09-27 23:20   ` Aurelien Jarno
2012-09-27 23:28     ` Richard Henderson
2012-10-01 17:46       ` Aurelien Jarno
2012-10-01 18:41         ` Richard Henderson
2012-09-30  7:04   ` Blue Swirl
2012-10-01 18:36     ` Richard Henderson
2012-09-27 17:19 ` [Qemu-devel] [PATCH 3/7] tcg: Swap commutative double-word comparisons Richard Henderson
2012-09-27 23:22   ` Aurelien Jarno
2012-09-27 17:19 ` [Qemu-devel] [PATCH 4/7] tcg: Optimize double-word comparisons against zero Richard Henderson
2012-10-01 18:43   ` Aurelien Jarno
2012-10-01 18:47     ` Richard Henderson
2012-09-27 17:19 ` [Qemu-devel] [PATCH 5/7] tcg: Split out subroutines from do_constant_folding_cond Richard Henderson
2012-10-01 18:46   ` Aurelien Jarno [this message]
2012-09-27 17:19 ` [Qemu-devel] [PATCH 6/7] tcg: Tidy brcond optimization Richard Henderson
2012-10-01 18:48   ` Aurelien Jarno
2012-09-27 17:19 ` [Qemu-devel] [PATCH 7/7] tcg: Do constant folding on double-word comparisons Richard Henderson
2012-10-01 18:50   ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121001184612.GC4623@ohm.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).