Re: locking/atomic: Introduce atomic_try_cmpxchg()
From: Linus Torvalds
Date: Sat Mar 25 2017 - 14:34:39 EST
On Sat, Mar 25, 2017 at 11:28 AM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hmm. Sad. The label approach looked like it would match the semantics
> of cmpxchg perfectly, but it's not as optimal as it superficially
> would have seemed.
Oh, I just noticed that at least your other one didn't mark "success"
as being likely.
That changed code generation a lot for me for the loops, where gcc
would assume that the loop was likely to be taken, which in turn means
that gcc lays out the loop with a backwards branch. Which is denser,
but also likely slower, since most x86 chips predict backwards
branches taken.
So that might be one difference. Although the size differences in the
last case are so small that it might also just be random noise.
Linus