Re: [PATCH] asm-generic/atomic: Add try_cmpxchg() fallbacks

From: Will Deacon
Date: Thu Feb 20 2020 - 05:39:42 EST


On Thu, Feb 20, 2020 at 11:37:27AM +0100, Peter Zijlstra wrote:
> On Thu, Feb 20, 2020 at 10:30:45AM +0000, Will Deacon wrote:
> > On Tue, Feb 18, 2020 at 03:27:00PM +0100, Peter Zijlstra wrote:
> > > diff --git a/scripts/atomic/gen-atomic-fallback.sh b/scripts/atomic/gen-atomic-fallback.sh
> > > index b6c6f5d306a7..3c9be8d550e0 100755
> > > --- a/scripts/atomic/gen-atomic-fallback.sh
> > > +++ b/scripts/atomic/gen-atomic-fallback.sh
> > > @@ -140,6 +140,32 @@ cat <<EOF
> > > EOF
> > > }
> > >
> > > +gen_try_cmpxchg_fallback()
> > > +{
> > > + local order="$1"; shift;
> > > +
> > > +cat <<EOF
> > > +#ifndef try_cmpxchg${order}
> > > +#define try_cmpxchg${order}(_ptr, _oldp, _new) \\
> > > +({ \\
> > > + typeof(*ptr) ___r, ___o = *(_oldp); \\
> > > + ___r = cmpxchg${order}((_ptr), ___o, (_new)); \\
> > > + if (unlikely(___r != ___o)) \\
> > > + *(_old) = ___r; \\
> >
> > This doesn't compile because _old isn't declared. Probably best to avoid
> > evaluating _oldp twice though.
>
> Compiler had already spotted that, I'll make it something like:
>
> typeof(*ptr) *___op = (_oldp), ___o = *___op;
>
> ...
>
> *___op = ___r;
>
> Which avoids the double eval.

Cool, you can stick my Ack on the patch with that change.

Will