Re: [tip:locking/core] locking/atomics: Simplify the op definitions in atomic.h some more

From: Peter Zijlstra
Date: Tue May 15 2018 - 13:41:43 EST


On Tue, May 15, 2018 at 04:43:33PM +0100, Mark Rutland wrote:
> I put together the following while trying to avoid bash magic (i.e the
> arrays, and keeping the option of naming the params. My local copy of
> dash seems happy with it.

Very nice; clearly your sh foo is stronger than mine ;-)

> I *think* the table can encode enough info to generate atomic-long.h,
> atomic-instrumented.h, and the atomic.h ordering fallbacks. I'll need to
> flesh out the table and check that we don't end up clashing with
> some of the regular fallbacks.

Yes, details details ;-)

> # name meta args...
> #
> # Where meta contains a string of:
> # * B - bool: returns bool, fully ordered
> # * V - void: returns void, fully ordered

void retuns are relaxed

> # * I - int: returns base type, all orderings
> # * R - return: returns base type, all orderings
> # * F - fetch: returns base type, all orderings
> # * T - try: returns bool, all orderings

Little more verbose than mine, I think we can get there with X and XB
instead of I and T, but whatever :-)

> # Where args contains list of type[:name], where type is:
> # * v - pointer to atomic base type (atomic or atomic64)
> # * i - base type (int or long)
> # * I - pointer to base type (int or long)
> #
> add VRF i v
> sub VRF i v
> inc VRF v
> dec VRF v
> or VF i v
> and VF i v
> andnot VF i v
> xor VF i v
> xchg I v i
> cmpxchg I v i:old i:new
> try_cmpxchg T v I:old i:new
> add_and_test B i v
> sub_and_test B i v
> dec_and_test B v
> inc_and_test B v

Cute, that [:name].