From: Nick Piggin <npiggin@suse.de>
To: Joel Schopp <jschopp@austin.ibm.com>
Cc: Nick Piggin <npiggin@suse.de>, Linus Torvalds <torvalds@osdl.org>,
Andrew Morton <akpm@osdl.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [patch 2/2] powerpc: native atomic_add_unless
Date: Thu, 19 Jan 2006 15:04:29 +0100 [thread overview]
Message-ID: <20060119140429.GC958@wotan.suse.de> (raw)
In-Reply-To: <43CEAD95.5010601@austin.ibm.com>
On Wed, Jan 18, 2006 at 03:05:25PM -0600, Joel Schopp wrote:
> >>Why use a separate register here? Why not reuse %0 instead of using %1?
> >>Registers are valuable.
> >>
> >You still need to get the output (t) because you need to return
> >whether the operation met with the "unless" case or not. If there is
> >a better way to do this then I'd like to know.
>
> I was thinking something like this would do:
>
> static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
> {
> int t;
>
> __asm__ __volatile__ (
> LWSYNC_ON_SMP
> "1: lwarx %0,0,%1 # atomic_add_unless\n\
> cmpw %0,%3 \n\
> beq- 2f \n\
> add %0,%2,%0 \n"
> PPC405_ERR77(0,%1)
> " stwcx. %0,0,%1 \n\
> bne- 1b \n"
> ISYNC_ON_SMP
> "subf %0,%2,%0 \n\
> 2:"
> : "=&r" (t)
> : "r" (&v->counter), "r" (a), "r" (u)
> : "cc", "memory");
>
> return likely(t != u);
> }
>
Oh yes, for some reason I thought that wouldn't work in all cases,
but I think that's nice. Thanks!
> Though if I could figure out how to get gcc to do it I'd much rather do
> something like this (which won't compile but I think illustrates the
> concept):
>
> static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
> {
> int t;
>
> __asm__ __volatile__ (
> LWSYNC_ON_SMP
> "1: lwarx %0,0,%1 # atomic_add_unless\n\
> cmpw %0,%3 \n\
> beq- 3f \n\
> add %0,%2,%0 \n"
> PPC405_ERR77(0,%1)
> " stwcx. %0,0,%1 \n\
> bne- 1b \n"
> ISYNC_ON_SMP
> 2:"
> : "=&r" (t)
> : "r" (&v->counter), "r" (a), "r" (u)
> : "cc", "memory");
>
> return 1;
> 3:
> return 0;
> }
next prev parent reply other threads:[~2006-01-19 14:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-18 6:36 [patch 1/2] atomic_add_unless sadness Nick Piggin
2006-01-18 6:39 ` [patch 2/2] powerpc: native atomic_add_unless Nick Piggin
2006-01-18 17:11 ` Joel Schopp
2006-01-18 17:28 ` Nick Piggin
2006-01-18 21:05 ` Joel Schopp
2006-01-19 14:04 ` Nick Piggin [this message]
2006-01-18 16:48 ` [patch 1/2] atomic_add_unless sadness Linus Torvalds
2006-01-18 17:10 ` Nick Piggin
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=20060119140429.GC958@wotan.suse.de \
--to=npiggin@suse.de \
--cc=akpm@osdl.org \
--cc=jschopp@austin.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.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 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.