public inbox for linux-sh@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Mundt <lethal@linux-sh.org>
To: linux-sh@vger.kernel.org
Subject: Re: Mutex fast-path implementation sh4a
Date: Thu, 20 Nov 2008 04:43:34 +0000	[thread overview]
Message-ID: <20081120044334.GA28447@linux-sh.org> (raw)
In-Reply-To: <49241338.1010405@yahoo.it>

On Wed, Nov 19, 2008 at 02:23:04PM +0100, michael wrote:
> Hi,
> 
> I'm not an expert of sh4 assembler instruction on gcc, but I figure out 
> how to implement
> the fastpath_lock and trylock, and I obtain this code:
> 
> static inline void
> __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
> {
>        int __res;
> 
>        __asm__ __volatile__ (
> 
>                "movli.l        @%1, %0 \n\t"
>                "dt             %0      \n\t"
>                "movco.l        %0, @%1 \n\t"
>                : "=&z" (__res)
>                : "r" (&(count)->counter)
>                : "t" );
> 
>        if (unlikely(__res != count->counter))
>                fail_fn(count);
> }
> 
The assembly looks fine, but you probably want to change the __res test
to something like:

	if (unlikely(__res != 0))
		fail_fn(count);

Given that you already have the counter value implemented there. This
will save you an additional memory access due to the fact the atomic
counter is volatile.

When you are implementing this, you should also include the comment from
ARM, as the single-pass atomic sequence without looping semantics aren't
entirely obvious without it.

> The retval function is very quite similar to this one. I don't find 
> documentation about sh assembler,
> can someone point me out to documentation?

What sort of documentation are you looking for? A good start is the SH-4A
software manual, which you can find the pdf for from any SH-4A part
specification download. If you are particularly concerned about inline
assembly, then you need to look at the GCC manual for SH-specific
information. Anything else you can feel free to ask on the list.

  reply	other threads:[~2008-11-20  4:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-19 13:23 Mutex fast-path implementation sh4a michael
2008-11-20  4:43 ` Paul Mundt [this message]
2008-11-20 17:18 ` Michael Trimarchi

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=20081120044334.GA28447@linux-sh.org \
    --to=lethal@linux-sh.org \
    --cc=linux-sh@vger.kernel.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