Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

build: quit guessing about intrinsics, check specifics

  • Loading branch information...
commit c3adf6738cb94764d0fbccdd3c08b20788a5218c 1 parent 937ace2
Cory Fields authored
Showing with 37 additions and 17 deletions.
  1. +31 −0 configure.in
  2. +6 −17 xbmc/threads/Atomics.cpp
View
31 configure.in
@@ -811,6 +811,37 @@ AC_CHECK_FUNCS([atexit dup2 fdatasync floor fs_stat_dev ftime ftruncate getcwd g
AC_CHECK_SIZEOF([int])
AC_CHECK_SIZEOF([size_t])
+# Check for intrinsics
+AC_MSG_CHECKING([for __sync_add_and_fetch(temp, 1)])
+AC_TRY_COMPILE([],[long* temp=0; __sync_add_and_fetch(temp, 1);],
+ [have_builtin_sync_add_and_fetch=yes],
+ [have_builtin_sync_add_and_fetch=no])
+AC_MSG_RESULT($have_builtin_sync_add_and_fetch)
+if test "x$have_builtin_sync_add_and_fetch" = "xyes"; then
+ AC_DEFINE(HAS_BUILTIN_SYNC_ADD_AND_FETCH, 1,
+ [Define to 1 if your compiler supports the __sync_add_and_fetch() intrinsic.])
+fi
+
+AC_MSG_CHECKING([for __sync_sub_and_fetch(temp, 1)])
+AC_TRY_COMPILE([],[long* temp=0; __sync_sub_and_fetch(temp, 1);],
+ [have_builtin_sync_sub_and_fetch=yes],
+ [have_builtin_sync_sub_and_fetch=no])
+AC_MSG_RESULT($have_builtin_sync_sub_and_fetch)
+if test "x$have_builtin_sync_sub_and_fetch" = "xyes"; then
+ AC_DEFINE(HAS_BUILTIN_SYNC_SUB_AND_FETCH, 1,
+ [Define to 1 if your compiler supports the __sync_sub_and_fetch() intrinsic.])
+fi
+
+AC_MSG_CHECKING([for __sync_val_compare_and_swap(temp, 1, 1)])
+AC_TRY_COMPILE([],[long *temp = 0; __sync_val_compare_and_swap(temp, 1, 1);],
+ [have_builtin_sync_val_compare_and_swap=yes],
+ [have_builtin_sync_val_compare_and_swap=no])
+AC_MSG_RESULT($have_builtin_sync_val_compare_and_swap)
+if test "x$have_builtin_sync_val_compare_and_swap" = "xyes"; then
+ AC_DEFINE(HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP, 1,
+ [Define to 1 if your compiler supports the __sync_val_compare_and_swap() intrinsic.])
+fi
+
# Add top source directory for all builds so we can use config.h
INCLUDES="$INCLUDES -I\$(abs_top_srcdir)"
View
23 xbmc/threads/Atomics.cpp
@@ -19,25 +19,14 @@
*/
#include "Atomics.h"
-
-// the only safe way to be absolutly sure that
-// gcc intrinsics are present when using an unknown GCC
-#if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
- #define HAS_GCC_INTRINSICS
-#elif defined(TARGET_DARWIN)
- // safe under darwin gcc-4.2, llvm-gcc-4.2 and clang
- #define HAS_GCC_INTRINSICS
-#elif defined(TARGET_FREEBSD)
- // safe under freebsd gcc-4.2 and clang
- #define HAS_GCC_INTRINSICS
-#endif
+#include "system.h"
///////////////////////////////////////////////////////////////////////////
// 32-bit atomic compare-and-swap
// Returns previous value of *pAddr
///////////////////////////////////////////////////////////////////////////
long cas(volatile long *pAddr, long expectedVal, long swapVal)
{
-#if defined(HAS_GCC_INTRINSICS)
+#if defined(HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP)
return(__sync_val_compare_and_swap(pAddr, expectedVal, swapVal));
#elif defined(__ppc__) || defined(__powerpc__) // PowerPC
unsigned int prev;
@@ -159,7 +148,7 @@ long long cas2(volatile long long* pAddr, long long expectedVal, long long swapV
///////////////////////////////////////////////////////////////////////////
long AtomicIncrement(volatile long* pAddr)
{
-#if defined(HAS_GCC_INTRINSICS)
+#if defined(HAS_BUILTIN_SYNC_ADD_AND_FETCH)
return __sync_add_and_fetch(pAddr, 1);
#elif defined(__ppc__) || defined(__powerpc__) // PowerPC
@@ -237,7 +226,7 @@ long AtomicIncrement(volatile long* pAddr)
///////////////////////////////////////////////////////////////////////////
long AtomicAdd(volatile long* pAddr, long amount)
{
-#if defined(HAS_GCC_INTRINSICS)
+#if defined(HAS_BUILTIN_SYNC_ADD_AND_FETCH)
return __sync_add_and_fetch(pAddr, amount);
#elif defined(__ppc__) || defined(__powerpc__) // PowerPC
@@ -315,7 +304,7 @@ long AtomicAdd(volatile long* pAddr, long amount)
///////////////////////////////////////////////////////////////////////////
long AtomicDecrement(volatile long* pAddr)
{
-#if defined(HAS_GCC_INTRINSICS)
+#if defined(HAS_BUILTIN_SYNC_SUB_AND_FETCH)
return __sync_sub_and_fetch(pAddr, 1);
#elif defined(__ppc__) || defined(__powerpc__) // PowerPC
@@ -393,7 +382,7 @@ long AtomicDecrement(volatile long* pAddr)
///////////////////////////////////////////////////////////////////////////
long AtomicSubtract(volatile long* pAddr, long amount)
{
-#if defined(HAS_GCC_INTRINSICS)
+#if defined(HAS_BUILTIN_SYNC_SUB_AND_FETCH)
return __sync_sub_and_fetch(pAddr, amount);
#elif defined(__ppc__) || defined(__powerpc__) // PowerPC
Please sign in to comment.
Something went wrong with that request. Please try again.