All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Alrae <leon.alrae@imgtec.com>
To: Richard Henderson <rth@twiddle.net>
Cc: qemu-devel@nongnu.org, aurelien@aurel32.net
Subject: Re: [Qemu-devel] [PATCH 2/2] target-mips: reimplement SC instruction and use cmpxchg
Date: Mon, 19 Sep 2016 12:35:58 +0100	[thread overview]
Message-ID: <20160919113557.GA3262@hhmipssw201.hh.imgtec.org> (raw)
In-Reply-To: <50da89d8-bc60-13f8-47fc-f69b40c13b58@twiddle.net>

On Fri, Sep 16, 2016 at 09:48:51AM -0700, Richard Henderson wrote:
> On 09/15/2016 01:44 AM, Leon Alrae wrote:
> > /* Store conditional */
> >+static void gen_st_cond(DisasContext *ctx, int rt, int base, int offset,
> >+                        int size)
> > {
> >+    TCGv addr, t0, val;
> >+    TCGLabel *l1 = gen_new_label();
> >+    TCGLabel *l2 = gen_new_label();
> >+    TCGLabel *done = gen_new_label();
> >
> >-#ifdef CONFIG_USER_ONLY
> >     t0 = tcg_temp_local_new();
> >+    addr = tcg_temp_local_new();
> >+    /* check the alignment of the address */
> >+    gen_base_offset_addr(ctx, addr, base, offset);
> >+    tcg_gen_andi_tl(t0, addr, size - 1);
> 
> You shouldn't have to test the alignment here, as the alignment
> should have been tested during the load-locked, and the (aligned)
> address will be compared.

This is to satisfy the requirement that unaligned SC generates Address
Error exception. But I agree that in practice this doesn't seem
particularly useful since LL will do that.

> 
> 
> >+    /* compare the address against that of the preceeding LL */
> >+    tcg_gen_brcond_tl(TCG_COND_EQ, addr, cpu_lladdr, l2);
> >+    tcg_gen_movi_tl(t0, 0);
> >+    tcg_gen_br(done);
> ...
> >+#ifdef TARGET_MIPS64
> >+    case 8: /* SCD */
> >+        tcg_gen_atomic_cmpxchg_i64(t0, addr, cpu_llval, val,
> >+                                   ctx->mem_idx, MO_TEQ);
> >         break;
> > #endif
> >-    case OPC_SC:
> >-    case R6_OPC_SC:
> >-        op_st_sc(t1, t0, rt, ctx);
> >+    case 4: /* SC */
> >+        {
> >+            TCGv_i32 val32 = tcg_temp_new_i32();
> >+            TCGv_i32 llval32 = tcg_temp_new_i32();
> >+            TCGv_i32 old32 = tcg_temp_new_i32();
> >+            tcg_gen_trunc_tl_i32(val32, val);
> >+            tcg_gen_trunc_tl_i32(llval32, cpu_llval);
> >+
> >+            tcg_gen_atomic_cmpxchg_i32(old32, addr, llval32, val32,
> >+                                       ctx->mem_idx, MO_TESL);
> >+            tcg_gen_ext_i32_tl(t0, old32);
> 
> You can use tcg_gen_atomic_cmpxchg_tl so that you do not need to do
> all of this truncation yourself.  Which means that if you replace
> the size parameter with a TCGMemOp parameter (MO_TEQ vs MO_TESL) you
> can make all this code common.

Ah, yes.

> 
> Further, local temporaries are less than ideal and should be avoided
> if possible.  Using them results in an extra store into the local
> stack frame.
> 
> We can avoid this for addr by noting that once you have compared
> addr to cpu_lladdr, you can free addr and use cpu_lladdr in the
> actual cmpxchg.

Ok. I'll correct in v2.

Thanks,
Leon

  reply	other threads:[~2016-09-19 11:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-15  8:44 [Qemu-devel] [PATCH 0/2] target-mips: rework conditional stores for mttcg Leon Alrae
2016-09-15  8:44 ` [Qemu-devel] [PATCH 1/2] target-mips: compare virtual addresses in LL/SC sequence Leon Alrae
2016-09-15  8:44 ` [Qemu-devel] [PATCH 2/2] target-mips: reimplement SC instruction and use cmpxchg Leon Alrae
2016-09-16 16:48   ` Richard Henderson
2016-09-19 11:35     ` Leon Alrae [this message]
2016-09-21  8:07 [Qemu-devel] [PATCH 0/2] target-mips: rework conditional stores for mttcg Leon Alrae
2016-09-21  8:07 ` [Qemu-devel] [PATCH 2/2] target-mips: reimplement SC instruction and use cmpxchg Leon Alrae
2016-09-21 20:16   ` Richard Henderson
2016-09-27  7:02     ` Leon Alrae

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=20160919113557.GA3262@hhmipssw201.hh.imgtec.org \
    --to=leon.alrae@imgtec.com \
    --cc=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.