Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 18 May 2015 22:12:38 -0400
From: Rich Felker <>
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 ( " %1, @%0 ; bf %l[fail]" : :
	"r"(p), "z"(v) : "memory" : fail );
	return 1;
	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:

        .align 2
        synco ; @r4, r0
        cmp/eq  r0,r5
        bf      .L4
        mov     r6,r0
#APP r0, @r4 ; bf .L2
        mov     r5,r0
        .align 1
        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.


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.