[cfe-commits] Patch for review/integration: __sync_swap()

Chandler Carruth chandlerc at google.com
Fri Apr 8 20:35:00 PDT 2011


On Fri, Apr 8, 2011 at 7:38 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Fri, Apr 8, 2011 at 6:09 PM, Dave Zarzycki <zarzycki at apple.com> wrote:
> > Background:
> >
> > The __sync_*() atomic intrinsics do not directly expose the fundamental
> atomic swap operation that many processors support. One can indirectly get
> at the instruction by using __sync_lock_test_and_set(), but the
> documentation for that intrinsic does not promise to be an atomic swap on
> all architectures or even be a full barrier like the other __sync_*()
> intrinsics. This patch fixes this oversight:
>
> It's not really an oversight; the __sync_ intrinsics were invented by
> Intel for Itanium, and the Itanium xchg instruction isn't a full
> barrier.  I don't see any harm in adding this anyway, although I'm not
> really an expert in lock-free algorithms.


While I don't see anything directly problematic with this, I think it might
be better to instead look toward adding a complete set of builtins through
which both the C++11 and C1X atomic libraries can be implemented. Until
those are added, it's not clear to me what value this intrinsic adds over
inline asm. Typically the advantage is portability, but that doesn't seem
likely to be achieved at this point for any of the __sync_* functions, and
much more likely to be achieved through C1X and C++11 standard libraries...

Just my 2 cents.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110408/6035ad2d/attachment.html>


More information about the cfe-commits mailing list