title: Does clang support a double-word-compare-and-exchange operation?
body: <p>I have been reading through and coding up examples from Anthony Williams' book <a href="http://www.manning.com/williams/" rel="nofollow">Concurrency in Practice</a> and needed to enable double-word-compare-and-exchange for gcc4.8 using <code>-mcx16</code> so that a struct containing a pointer an int could be manipulated in a lock-free atomic manner.</p>
  
  <p>Does Clang (any version) support double-word-compare-and-exchange on x64?</p>
  
  <p>The following code gives linking errors in GCC4.8 and Clang 3.3 without extra compiler options:</p>
  
  <pre><code>#include &lt;atomic&gt;
  #include &lt;thread&gt;
  
  struct ReferenceCountedPointer
  {
    int referenceCount;
    void* data;
  };
  
  int main()
  {
    std::atomic&lt;ReferenceCountedPointer&gt; arcp;
    ReferenceCountedPointer rcp;
  
    arcp.compare_exchange_weak(rcp, rcp);
  
    return 0;
  }
  </code></pre>
  
  <p>The above program is pointless but illustrates the linking errors I see.</p>
  
  <p>Compilation commands I used for Clang and GCC are:</p>
  
  <p>Clang 3.3:</p>
  
  <pre><code>clang++-mp-3.3 -std=c++11 -stdlib=libc++ CX16.cpp -o CX16
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
  "___atomic_compare_exchange", referenced from:
    _main in CX16-plVSvq.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <p>GCC4.8:</p>
  
  <pre><code>g++-mp-4.8 -std=c++11 CX16.cpp -o CX16
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
  "___atomic_compare_exchange_16", referenced from:
    std::atomic&lt;ReferenceCountedPointer&gt;::compare_exchange_weak(ReferenceCountedPointer&amp;,        ReferenceCountedPointer, std::memory_order, std::memory_order) in ccOjp95s.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>