qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Sandiford <rdsandiford@googlemail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [4545] Switch MIPS movf/movt to TCG.
Date: Sat, 24 May 2008 11:53:37 +0100	[thread overview]
Message-ID: <87fxs86ki6.fsf@firetop.home> (raw)
In-Reply-To: <E1Jzbet-0001cv-UL@cvs.savannah.gnu.org> (Thiemo Seufer's message of "Fri\, 23 May 2008 18\:06\:27 +0000")

Hi Thiemo,

Thiemo Seufer <ths@networkno.de> writes:
> Modified: trunk/target-mips/translate.c
> ===================================================================
> --- trunk/target-mips/translate.c	2008-05-23 17:33:39 UTC (rev 4544)
> +++ trunk/target-mips/translate.c	2008-05-23 18:06:27 UTC (rev 4545)
> @@ -5450,19 +5450,33 @@
>  
>  static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
>  {
> +    TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
> +    TCGv r_tmp = new_tmp();
> +    TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
> +    TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
> +    int l1 = gen_new_label();
>      uint32_t ccbit;
> +    TCGCond cond;
>  
> -    gen_load_gpr(cpu_T[0], rd);
> -    gen_load_gpr(cpu_T[1], rs);
> -    if (cc) {
> +    if (cc)
>          ccbit = 1 << (24 + cc);
> -    } else
> +    else
>          ccbit = 1 << 23;
> -    if (!tf)
> -        gen_op_movf(ccbit);
> +    if (tf)
> +        cond = TCG_COND_NE;
>      else
> -        gen_op_movt(ccbit);
> -    gen_store_gpr(cpu_T[0], rd);
> +        cond = TCG_COND_EQ;
> +
> +    gen_load_gpr(t0, rd);
> +    gen_load_gpr(t1, rs);
> +    tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
> +    tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
> +    tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
> +    tcg_gen_brcond_i32(cond, r_tmp, tcg_const_i32(0), l1);
> +    tcg_gen_mov_tl(t0, t1);
> +    gen_set_label(l1);
> +    dead_tmp(r_tmp);
> +    gen_store_gpr(t0, rd);
>  }
>  
>  #define GEN_MOVCF(fmt)                                                \

Looks like there's a couple of problems here:

  - T0 and T1 outlive the first basic block, so the GPR loads get
    deleted as dead.

  - This a branch-over-move, so the condition is reversed.
    It should be TCG_COND_EQ (to zero) for MOVT and
    TCG_COND_NE (to zero) for MOVF.

The patch below seems to work for me.

(Style elsewhere in translate.c seemed to be to use C blocks to
emphasise the lifetimes of temporaries, so I did the same here.
Hope that's OK.)

Richard

Index: qemu/target-mips/translate.c
===================================================================
--- qemu.orig/target-mips/translate.c	2008-05-24 11:12:56.000000000 +0100
+++ qemu/target-mips/translate.c	2008-05-24 11:45:16.000000000 +0100
@@ -5664,10 +5664,6 @@ static void gen_cp1 (DisasContext *ctx, 
 
 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
 {
-    TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
-    TCGv r_tmp = new_tmp();
-    TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
-    TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
     int l1 = gen_new_label();
     uint32_t ccbit;
     TCGCond cond;
@@ -5677,20 +5673,26 @@ static void gen_movci (DisasContext *ctx
     else
         ccbit = 1 << 23;
     if (tf)
-        cond = TCG_COND_NE;
-    else
         cond = TCG_COND_EQ;
+    else
+        cond = TCG_COND_NE;
+
+    gen_load_gpr(cpu_T[0], rd);
+    gen_load_gpr(cpu_T[1], rs);
+    {
+        TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
+        TCGv r_tmp = new_tmp();
+
+        tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
+        tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
+        tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
+        tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
+        dead_tmp(r_tmp);
+    }
+    tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
 
-    gen_load_gpr(t0, rd);
-    gen_load_gpr(t1, rs);
-    tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
-    tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
-    tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
-    tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
-    tcg_gen_mov_tl(t0, t1);
     gen_set_label(l1);
-    dead_tmp(r_tmp);
-    gen_store_gpr(t0, rd);
+    gen_store_gpr(cpu_T[0], rd);
 }
 
 #define GEN_MOVCF(fmt)                                                \

      reply	other threads:[~2008-05-24 10:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-23 18:06 [Qemu-devel] [4545] Switch MIPS movf/movt to TCG Thiemo Seufer
2008-05-24 10:53 ` Richard Sandiford [this message]

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=87fxs86ki6.fsf@firetop.home \
    --to=rdsandiford@googlemail.com \
    --cc=qemu-devel@nongnu.org \
    /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).