Patchwork [13/14] i386: optimize setbe

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 6, 2012, 12:30 p.m.
Message ID <1349526621-13939-14-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/189696/
State New
Headers show

Comments

Paolo Bonzini - Oct. 6, 2012, 12:30 p.m.
This is looking at EFLAGS, but it can do so more efficiently with
setcond.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target-i386/translate.c | 7 +++----
 1 file modificato, 3 inserzioni(+), 4 rimozioni(-)
Blue Swirl - Oct. 7, 2012, 7:43 p.m.
On Sat, Oct 6, 2012 at 12:30 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> This is looking at EFLAGS, but it can do so more efficiently with
> setcond.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Blue Swirl <blauwirbel@gmail.com>

> ---
>  target-i386/translate.c | 7 +++----
>  1 file modificato, 3 inserzioni(+), 4 rimozioni(-)
>
> diff --git a/target-i386/translate.c b/target-i386/translate.c
> index fb44839..342b9ec 100644
> --- a/target-i386/translate.c
> +++ b/target-i386/translate.c
> @@ -1031,10 +1031,9 @@ static inline void gen_setcc_slow(DisasContext *s, int jcc_op, TCGv reg, bool in
>          return;
>      case JCC_BE:
>          gen_compute_eflags(s);
> -        tcg_gen_shri_tl(reg, cpu_cc_src, 6);
> -        tcg_gen_or_tl(reg, reg, cpu_cc_src);
> -        tcg_gen_andi_tl(reg, reg, 1);
> -        break;
> +        tcg_gen_andi_tl(reg, cpu_cc_src, 0x41);

Symbolic names for the flags would be nice.

> +        tcg_gen_setcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, reg, reg, 0);
> +        return;
>      case JCC_S:
>          gen_compute_eflags_s(s, reg, inv);
>          return;
> --
> 1.7.12.1
>
>
>
Richard Henderson - Oct. 9, 2012, 8:13 p.m.
On 10/06/2012 05:30 AM, Paolo Bonzini wrote:
>          gen_compute_eflags(s);
> -        tcg_gen_shri_tl(reg, cpu_cc_src, 6);
> -        tcg_gen_or_tl(reg, reg, cpu_cc_src);
> -        tcg_gen_andi_tl(reg, reg, 1);
> -        break;
> +        tcg_gen_andi_tl(reg, cpu_cc_src, 0x41);
> +        tcg_gen_setcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, reg, reg, 0);
> +        return;

This one's questionable.  Whether it's an improvement really depends
on the host cpu isa.  It's probably more of a benefit if we can avoid
the setcond completely.  See the comments for the next patch.

That said, the patch produces correct code.

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~

Patch

diff --git a/target-i386/translate.c b/target-i386/translate.c
index fb44839..342b9ec 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -1031,10 +1031,9 @@  static inline void gen_setcc_slow(DisasContext *s, int jcc_op, TCGv reg, bool in
         return;
     case JCC_BE:
         gen_compute_eflags(s);
-        tcg_gen_shri_tl(reg, cpu_cc_src, 6);
-        tcg_gen_or_tl(reg, reg, cpu_cc_src);
-        tcg_gen_andi_tl(reg, reg, 1);
-        break;
+        tcg_gen_andi_tl(reg, cpu_cc_src, 0x41);
+        tcg_gen_setcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, reg, reg, 0);
+        return;
     case JCC_S:
         gen_compute_eflags_s(s, reg, inv);
         return;