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 7/7] tcg: Streamline movcond_i64 using movcond_i32
Date: Fri, 21 Sep 2012 23:23:20 +0200	[thread overview]
Message-ID: <20120921212320.GJ4457@ohm.aurel32.net> (raw)
In-Reply-To: <1348247620-12734-8-git-send-email-rth@twiddle.net>

On Fri, Sep 21, 2012 at 10:13:40AM -0700, Richard Henderson wrote:
> When movcond_i32 is available we can further reduce the generated
> op count from 12 to 6, and the generated code size on i686 from
> 88 to 74 bytes.
> 
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  tcg/tcg-op.h | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h
> index 3e375ea..0145a09 100644
> --- a/tcg/tcg-op.h
> +++ b/tcg/tcg-op.h
> @@ -2147,16 +2147,24 @@ static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
>          tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
>                           TCGV_LOW(c1), TCGV_HIGH(c1),
>                           TCGV_LOW(c2), TCGV_HIGH(c2), cond);
> -        tcg_gen_neg_i32(t0, t0);
>  
> -        tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
> -        tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
> -        tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
> +        if (TCG_TARGET_HAS_movcond_i32) {
> +            tcg_gen_movi_i32(t1, 0);
> +            tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
> +                                TCGV_LOW(v1), TCGV_LOW(v2));
> +            tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
> +                                TCGV_HIGH(v1), TCGV_HIGH(v2));
> +        } else {
> +            tcg_gen_neg_i32(t0, t0);
>  
> -        tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
> -        tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
> -        tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
> +            tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
> +            tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
> +            tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
>  
> +            tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
> +            tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
> +            tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
> +        }
>          tcg_temp_free_i32(t0);
>          tcg_temp_free_i32(t1);
>      } else {

At some point I tried to think how to implement movcond_i64 for 
MIPS directly in the backend. I just tried your patch, and I got
this kind of code:

| 0x2bb2ae58:  sltu       at,zero,s4
| 0x2bb2ae5c:  sltu       t0,zero,s3
| 0x2bb2ae60:  or s3,at,t0
| 0x2bb2ae64:  movz       s1,s5,s3
| 0x2bb2ae68:  movz       s2,s6,s3
|
| (in some cases some constants/globals loading appear in the middle, but
| that's not due to movcond).

It's basically the kind of code I would have written. It's clearly
better to implement it directly in TCG.

Now I wonder if it wouldn't be better to write brcond2 as setcond2 +
brcond. And even setcond2 as a pair of setcond in TCG, which would allow
some optimizations in case both high parts are zero.

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

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

  reply	other threads:[~2012-09-21 21:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21 17:13 [Qemu-devel] [PATCH v2 0/7] tcg: movcond Richard Henderson
2012-09-21 17:13 ` [Qemu-devel] [PATCH 1/7] tcg: Introduce movcond Richard Henderson
2012-09-21 17:13 ` [Qemu-devel] [PATCH 2/7] target-alpha: Use movcond Richard Henderson
2012-09-21 17:13 ` [Qemu-devel] [PATCH 3/7] tcg-i386: Implement movcond Richard Henderson
2012-09-24 21:37   ` Alex Barcelo
2012-09-24 21:54     ` Richard Henderson
2012-09-25 22:48       ` Aurelien Jarno
2012-09-21 17:13 ` [Qemu-devel] [PATCH 4/7] tcg: Optimize movcond for constant comparisons Richard Henderson
2012-09-21 17:13 ` [Qemu-devel] [PATCH 5/7] tcg: Optimize two-address commutative operations Richard Henderson
2012-09-21 17:13 ` [Qemu-devel] [PATCH 6/7] tcg: Streamline movcond_i64 using 32-bit arithmetic Richard Henderson
2012-09-21 21:15   ` Aurelien Jarno
2012-09-22 18:11   ` Aurelien Jarno
2012-09-21 17:13 ` [Qemu-devel] [PATCH 7/7] tcg: Streamline movcond_i64 using movcond_i32 Richard Henderson
2012-09-21 21:23   ` Aurelien Jarno [this message]
2012-09-21 22:27     ` Richard Henderson
2012-09-22  9:30       ` Aurelien Jarno
2012-09-21 18:14 ` [Qemu-devel] [PATCH v2 0/7] tcg: movcond Aurelien Jarno
2012-09-21 20:10 ` [Qemu-devel] [PATCH v2 0/7] tcg: movcond (ppc32 version) malc
2012-09-21 22:21   ` Richard Henderson
2012-09-21 22:34     ` malc
2012-09-22 14:38   ` Blue Swirl

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=20120921212320.GJ4457@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).