}
#define AO_HAVE_char_store_release
-AO_INLINE unsigned/**/char
-AO_char_fetch_compare_and_swap(volatile unsigned/**/char *addr,
- unsigned/**/char old_val, unsigned/**/char new_val)
-{
- return __sync_val_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
-}
-#define AO_HAVE_char_fetch_compare_and_swap
-
-/* TODO: Add CAS _acquire/release/full primitives. */
-
-#ifndef AO_GENERALIZE_ASM_BOOL_CAS
- AO_INLINE int
- AO_char_compare_and_swap(volatile unsigned/**/char *addr,
- unsigned/**/char old_val, unsigned/**/char new_val)
+#ifdef AO_GCC_HAVE_char_SYNC_CAS
+ AO_INLINE unsigned/**/char
+ AO_char_fetch_compare_and_swap(volatile unsigned/**/char *addr,
+ unsigned/**/char old_val, unsigned/**/char new_val)
{
- return __sync_bool_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
+ return __sync_val_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
}
-# define AO_HAVE_char_compare_and_swap
-#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+# define AO_HAVE_char_fetch_compare_and_swap
+
+ /* TODO: Add CAS _acquire/release/full primitives. */
+
+# ifndef AO_GENERALIZE_ASM_BOOL_CAS
+ AO_INLINE int
+ AO_char_compare_and_swap(volatile unsigned/**/char *addr,
+ unsigned/**/char old_val, unsigned/**/char new_val)
+ {
+ return __sync_bool_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
+ }
+# define AO_HAVE_char_compare_and_swap
+# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+#endif /* AO_GCC_HAVE_char_SYNC_CAS */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
}
#define AO_HAVE_short_store_release
-AO_INLINE unsigned/**/short
-AO_short_fetch_compare_and_swap(volatile unsigned/**/short *addr,
- unsigned/**/short old_val, unsigned/**/short new_val)
-{
- return __sync_val_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
-}
-#define AO_HAVE_short_fetch_compare_and_swap
-
-/* TODO: Add CAS _acquire/release/full primitives. */
-
-#ifndef AO_GENERALIZE_ASM_BOOL_CAS
- AO_INLINE int
- AO_short_compare_and_swap(volatile unsigned/**/short *addr,
- unsigned/**/short old_val, unsigned/**/short new_val)
+#ifdef AO_GCC_HAVE_short_SYNC_CAS
+ AO_INLINE unsigned/**/short
+ AO_short_fetch_compare_and_swap(volatile unsigned/**/short *addr,
+ unsigned/**/short old_val, unsigned/**/short new_val)
{
- return __sync_bool_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
+ return __sync_val_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
}
-# define AO_HAVE_short_compare_and_swap
-#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+# define AO_HAVE_short_fetch_compare_and_swap
+
+ /* TODO: Add CAS _acquire/release/full primitives. */
+
+# ifndef AO_GENERALIZE_ASM_BOOL_CAS
+ AO_INLINE int
+ AO_short_compare_and_swap(volatile unsigned/**/short *addr,
+ unsigned/**/short old_val, unsigned/**/short new_val)
+ {
+ return __sync_bool_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
+ }
+# define AO_HAVE_short_compare_and_swap
+# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+#endif /* AO_GCC_HAVE_short_SYNC_CAS */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
}
#define AO_HAVE_int_store_release
-AO_INLINE unsigned
-AO_int_fetch_compare_and_swap(volatile unsigned *addr,
- unsigned old_val, unsigned new_val)
-{
- return __sync_val_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
-}
-#define AO_HAVE_int_fetch_compare_and_swap
-
-/* TODO: Add CAS _acquire/release/full primitives. */
-
-#ifndef AO_GENERALIZE_ASM_BOOL_CAS
- AO_INLINE int
- AO_int_compare_and_swap(volatile unsigned *addr,
- unsigned old_val, unsigned new_val)
+#ifdef AO_GCC_HAVE_int_SYNC_CAS
+ AO_INLINE unsigned
+ AO_int_fetch_compare_and_swap(volatile unsigned *addr,
+ unsigned old_val, unsigned new_val)
{
- return __sync_bool_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
+ return __sync_val_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
}
-# define AO_HAVE_int_compare_and_swap
-#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+# define AO_HAVE_int_fetch_compare_and_swap
+
+ /* TODO: Add CAS _acquire/release/full primitives. */
+
+# ifndef AO_GENERALIZE_ASM_BOOL_CAS
+ AO_INLINE int
+ AO_int_compare_and_swap(volatile unsigned *addr,
+ unsigned old_val, unsigned new_val)
+ {
+ return __sync_bool_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
+ }
+# define AO_HAVE_int_compare_and_swap
+# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+#endif /* AO_GCC_HAVE_int_SYNC_CAS */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
}
#define AO_HAVE_store_release
-AO_INLINE AO_t
-AO_fetch_compare_and_swap(volatile AO_t *addr,
- AO_t old_val, AO_t new_val)
-{
- return __sync_val_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
-}
-#define AO_HAVE_fetch_compare_and_swap
-
-/* TODO: Add CAS _acquire/release/full primitives. */
-
-#ifndef AO_GENERALIZE_ASM_BOOL_CAS
- AO_INLINE int
- AO_compare_and_swap(volatile AO_t *addr,
- AO_t old_val, AO_t new_val)
+#ifdef AO_GCC_HAVE_SYNC_CAS
+ AO_INLINE AO_t
+ AO_fetch_compare_and_swap(volatile AO_t *addr,
+ AO_t old_val, AO_t new_val)
{
- return __sync_bool_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
+ return __sync_val_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
}
-# define AO_HAVE_compare_and_swap
-#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+# define AO_HAVE_fetch_compare_and_swap
+
+ /* TODO: Add CAS _acquire/release/full primitives. */
+
+# ifndef AO_GENERALIZE_ASM_BOOL_CAS
+ AO_INLINE int
+ AO_compare_and_swap(volatile AO_t *addr,
+ AO_t old_val, AO_t new_val)
+ {
+ return __sync_bool_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
+ }
+# define AO_HAVE_compare_and_swap
+# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+#endif /* AO_GCC_HAVE_SYNC_CAS */
}
#define AO_HAVE_XSIZE_store_release
-AO_INLINE XCTYPE
-AO_XSIZE_fetch_compare_and_swap(volatile XCTYPE *addr,
- XCTYPE old_val, XCTYPE new_val)
-{
- return __sync_val_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
-}
-#define AO_HAVE_XSIZE_fetch_compare_and_swap
-
-/* TODO: Add CAS _acquire/release/full primitives. */
-
-#ifndef AO_GENERALIZE_ASM_BOOL_CAS
- AO_INLINE int
- AO_XSIZE_compare_and_swap(volatile XCTYPE *addr,
- XCTYPE old_val, XCTYPE new_val)
+#ifdef AO_GCC_HAVE_XSIZE_SYNC_CAS
+ AO_INLINE XCTYPE
+ AO_XSIZE_fetch_compare_and_swap(volatile XCTYPE *addr,
+ XCTYPE old_val, XCTYPE new_val)
{
- return __sync_bool_compare_and_swap(addr, old_val, new_val
- /* empty protection list */);
+ return __sync_val_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
}
-# define AO_HAVE_XSIZE_compare_and_swap
-#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+# define AO_HAVE_XSIZE_fetch_compare_and_swap
+
+ /* TODO: Add CAS _acquire/release/full primitives. */
+
+# ifndef AO_GENERALIZE_ASM_BOOL_CAS
+ AO_INLINE int
+ AO_XSIZE_compare_and_swap(volatile XCTYPE *addr,
+ XCTYPE old_val, XCTYPE new_val)
+ {
+ return __sync_bool_compare_and_swap(addr, old_val, new_val
+ /* empty protection list */);
+ }
+# define AO_HAVE_XSIZE_compare_and_swap
+# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+#endif /* AO_GCC_HAVE_XSIZE_SYNC_CAS */
/* For the details, see GNU Manual, chapter 6.52 (Built-in functions */
/* for memory model aware atomic operations). */
+#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) \
+ || defined(AO_GCC_FORCE_HAVE_CAS)
+# define AO_GCC_HAVE_char_SYNC_CAS
+#endif
+
+#if (__SIZEOF_SHORT__ == 2 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)) \
+ || defined(AO_GCC_FORCE_HAVE_CAS)
+# define AO_GCC_HAVE_short_SYNC_CAS
+#endif
+
+#if (__SIZEOF_INT__ == 4 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)) \
+ || (__SIZEOF_INT__ == 8 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) \
+ || defined(AO_GCC_FORCE_HAVE_CAS)
+# define AO_GCC_HAVE_int_SYNC_CAS
+#endif
+
+#if (__SIZEOF_SIZE_T__ == 4 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)) \
+ || (__SIZEOF_SIZE_T__ == 8 \
+ && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) \
+ || defined(AO_GCC_FORCE_HAVE_CAS)
+# define AO_GCC_HAVE_SYNC_CAS
+#endif
+
#ifdef AO_UNIPROCESSOR
/* If only a single processor (core) is used, AO_UNIPROCESSOR could */
/* be defined by the client to avoid unnecessary memory barrier. */
# define AO_HAVE_double_store_release
# endif
+# if (__SIZEOF_SIZE_T__ == 4 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) \
+ || (__SIZEOF_SIZE_T__ == 8 /* half of AO_double_t */ \
+ && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16))
+# define AO_GCC_HAVE_double_SYNC_CAS
+# endif
+
+#endif /* AO_HAVE_DOUBLE_PTR_STORAGE */
+
+#ifdef AO_GCC_HAVE_double_SYNC_CAS
# ifndef AO_HAVE_double_compare_and_swap
AO_INLINE int
AO_double_compare_and_swap(volatile AO_double_t *addr,
# endif
/* TODO: Add double CAS _acquire/release/full primitives. */
-#endif /* AO_HAVE_DOUBLE_PTR_STORAGE */
+#endif /* AO_GCC_HAVE_double_SYNC_CAS */