[LLVMdev] compare and swap
andrewl at lenharth.org
Thu Feb 21 11:34:19 CST 2008
On 2/21/08, Torvald Riegel <torvald at se.inf.tu-dresden.de> wrote:
> why is the intrinsic name not CAS? And having another version that returns
> just a bool might be better in some cases ( 1. does CAS return the value on
> all architectures? 2. you can just jump based on a flag and don't need to
> compare it again). Just my 2 cents though ...
I was going from chandler's docs, but it could be renamed trivially
(and I almost did at several points).
1) yes, but on some it may be easier to have a bool version than others.
2.a) to get the bool, the x86 (and some others) backend would have to
generate the compare instruction anyway, so you don't save anything by
having a bool version.
2.b) in the case of a load locked store conditional based backend, the
bool version would save a compare if the store conditional has the
typical returns success or failure semantics.
So, yes, a CAS that returned bool could be useful. However, it is
pretty easy to pattern match
CAS -> Compare
in those backends that can save the compare by testing the result of
the store conditional.
More information about the LLVMdev