|
|
Message-ID: <20150519021238.GE17573@brightrain.aerifal.cx>
Date: Mon, 18 May 2015 22:12:38 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] inline llsc atomics when compiling for sh4a
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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.