title: what's the difference between gcc __sync_bool_compare_and_swap and cmpxchg?
body: <p>to use cas, gcc provides some useful functions such as<br>
  __sync_bool_compare_and_swap  </p>
  
  <p>but we can also use asm code like cmpxchg  </p>
  
  <pre><code>bool  ret;
  __asm__ __volatile__(
      "lock cmpxchg16b %1;\n"
      "sete %0;\n"
      :"=m"(ret),"+m" (*(volatile pointer_t *) (addr))
      :"a" (old_value.ptr), "d" (old_value.tag), "b" (new_value.ptr), "c" (new_value.tag));
  return ret;
  </code></pre>
  
  <p>I have grep the source code of gcc 4.6.3, and found that __sync_bool_compare_and_swap is implemented use   </p>
  
  <pre><code>typedef int (__kernel_cmpxchg_t) (int oldval, int newval, int *ptr); 
  #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
  </code></pre>
  
  <p>it seems that 0xffff0fc0 is the adress of some kernel helper functions  </p>
  
  <p>but in gcc 4.1.2 , there is no such codes like __kernel_cmpxchg_t, and I can't find the implementation of __sync_bool_compare_and_swap.  </p>
  
  <p>so what's the difference between __sync_bool_compare_and_swap and cmpxchg?  </p>
  
  <p>is __sync_bool_compare_and_swap implemented by cmpxchg?  </p>
  
  <p>and with kernel helper function __kernel_cmpxchg_t, is it implementd by cmpxchg?  </p>
  
  <p>thanks!</p>