boehm-gc: revert all CACAO-specific modifications; this is now an exact copy of the...
[cacao.git] / src / mm / boehm-gc / libatomic_ops-1.2 / src / atomic_ops / sysdeps / gcc / sparc.h
index 4850855d651dacbd14de391405f747edc169a693..5ee7a9051ea4da7a8036cdc5afdebf6a7a617630 100644 (file)
@@ -29,7 +29,7 @@
 
 AO_INLINE AO_TS_VAL_t
 AO_test_and_set_full(volatile AO_TS_t *addr) {
-  int oldval;
+   AO_TS_VAL_t oldval;
 
    __asm__ __volatile__("ldstub %1,%0"
                        : "=r"(oldval), "=m"(*addr)
@@ -39,6 +39,32 @@ AO_test_and_set_full(volatile AO_TS_t *addr) {
 
 #define AO_HAVE_test_and_set_full
 
+#ifndef AO_NO_SPARC_V9
+/* Returns nonzero if the comparison succeeded. */
+AO_INLINE int
+AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val) {
+  char ret;
+  __asm__ __volatile__ ("membar #StoreLoad | #LoadLoad\n\t"
+#                      if defined(__arch64__)
+                         "casx [%2],%0,%1\n\t"
+#                      else
+                         "cas [%2],%0,%1\n\t" /* 32-bit version */
+#                      endif
+                       "membar #StoreLoad | #StoreStore\n\t"
+                       "cmp %0,%1\n\t"
+                       "be,a 0f\n\t"
+                       "mov 1,%0\n\t"/* one insn after branch always executed */
+                       "clr %0\n\t"
+                       "0:\n\t"
+                       : "=r" (ret), "+r" (new_val)
+                       : "r" (addr), "0" (old)
+                       : "memory", "cc");
+  return (int)ret;
+}
+
+#define AO_HAVE_compare_and_swap_full
+#endif /* AO_NO_SPARC_V9 */
+
 /* FIXME: This needs to be extended for SPARC v8 and v9.       */
 /* SPARC V8 also has swap.  V9 has CAS.                                */
 /* There are barriers like membar #LoadStore.                  */