
inline long compare_exchange(long* v, const long c, const long n) {
long r;
#ifdef __arch64__
// UltraSparc 64-bit variant
__asm__ __volatile__("casx [%2], %3, %0 \t\n" \ " \t\n" : "=&r"(r), "=m"(*v) : "r"(v), "r"(c), "0"(n), "m"(*v) :); #else
// Legacy 32-bit variant
__asm__ __volatile__("cas [%2], %3, %0 \t\n" \ " \t\n" : "=&r"(r), "=m"(*v) : "r"(v), "r"(c), "0"(n), "m"(*v) :);
Here's my version: inline uint32_t compareAndSwap(uint32_t * dest_, uint32_t compare_, uint32_t swap_) { __asm__ __volatile__("cas %0, %1, %2 \n\t" : "+m" (*dest_), "+r" (compare_) : "r" (swap_) : ); return compare_; } inline uint64_t compareAndSwap(uint64_t * dest_, uint64_t compare_, uint64_t swap_) { __asm__ __volatile__("casx %0, %1, %2 \n\t" : "+m" (*dest_), "+r" (compare_) : "r" (swap_) : ); return compare_; } I also have these intrinsics for the Sunpro compiler. The only problem is that with Sunpro, these have to come in a separate .il file, which has to be included on the compile line at the same time as the .cpp being compiled. Tom