mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] inline llsc atomics when compiling for sh4a
Date: Mon, 18 May 2015 22:12:38 -0400	[thread overview]
Message-ID: <20150519021238.GE17573@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150519003045.GC17573@brightrain.aerifal.cx>

On Mon, May 18, 2015 at 08:30:45PM -0400, Rich Felker wrote:
> [...]
> static inline int __sh_cas_llsc(volatile int *p, int t, int s)
> {
> 	do old = llsc_start(p);
> 	while (!llsc_end(p, old==t ? s : old));
> 	return old;
> }
> 
> This version is structurally analogous to the non-CAS atomics, but
> perhaps more costly in the old!=t case.
> 
> Anyway at this point I don't see an efficient way do to the
> conditional, so it's mostly a theoretical topic at this point.

I have a partial solution but it's utterly hideous:

static inline int llsc_end(volatile int *p, int v)
{
	__asm__ __volatile__ goto ( "mov.co %1, @%0 ; bf %l[fail]" : :
	"r"(p), "z"(v) : "memory" : fail );
	return 1;
fail:
	return 0;
}

This doesn't eliminate the branch in the asm, but it does allow gcc to
eliminate the branch outside the asm. The resulting code is:

a_cas:
        .align 2
.L2:
#APP
        synco ; mov.li @r4, r0
#NO_APP
        cmp/eq  r0,r5
        bf      .L4
        mov     r6,r0
#APP
        mov.co r0, @r4 ; bf .L2
#NO_APP
.L6:
        rts
        mov     r5,r0
        .align 1
.L4:
        bra     .L6
        mov     r0,r5

Of course asm goto is utterly hideous, so I don't propose actually
using this. I doubt any of the non-GCC compilers we support would
accept it.

Rich


  reply	other threads:[~2015-05-19  2:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-17 18:55 Bobby Bingham
2015-05-18  2:34 ` Rich Felker
2015-05-18  4:28   ` Rich Felker
2015-05-18 22:56   ` Bobby Bingham
2015-05-19  0:30     ` Rich Felker
2015-05-19  2:12       ` Rich Felker [this message]
2015-05-19  4:52     ` Rich Felker

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=20150519021238.GE17573@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).