Re: [PATCH v3 09/25] openrisc: add optimized atomic operations

From: Peter Zijlstra
Date: Wed Feb 22 2017 - 06:27:57 EST


On Wed, Feb 22, 2017 at 04:11:38AM +0900, Stafford Horne wrote:
> +#define atomic_add_return atomic_add_return
> +#define atomic_sub_return atomic_sub_return
> +#define atomic_fetch_add atomic_fetch_add
> +#define atomic_fetch_sub atomic_fetch_sub
> +#define atomic_fetch_and atomic_fetch_and
> +#define atomic_fetch_or atomic_fetch_or
> +#define atomic_fetch_xor atomic_fetch_xor
> +#define atomic_and atomic_and
> +#define atomic_or atomic_or
> +#define atomic_xor atomic_xor
> +

It would be good to also implement __atomic_add_unless().

Something like so, if I got your asm right..

static inline int __atomic_add_unless(atomic_t *v, int a, int u)
{
int old, tmp;

__asm__ __volatile__(
"1: l.lwa %0, 0(%2) \n"
" l.sfeq %0, %4 \n"
" l.bf 2f \n"
" l.nop \n"
" l.add %1, %0, %3 \n"
" l.swa 0(%2), %1 \n"
" l.bnf 1b \n"
"2: l.nop \n"
: "=&r"(old), "=&r" (tmp)
: "r"(&v->counter), "r"(a), "r"(u)
: "cc", "memory");

return old;
}