Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

build: quit guessing about intrinsics, check specifics #1626

Merged
merged 1 commit into from

5 participants

@theuni
Owner

Should be safe across the board unless I typo'd.

Quick darwin test would be appreciated before merging.

@ghost

sign-offs for relevant platforms please.

@Memphiz
Owner

osx:

macbook:xbmc-memphiz memphis$ grep HAS_BUILTIN xbmc/config.h
#define HAS_BUILTIN_SYNC_ADD_AND_FETCH 1
#define HAS_BUILTIN_SYNC_SUB_AND_FETCH 1
#define HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP 1

ios:

macbook:xbmc-ios memphis$ grep HAS_BUILTIN xbmc/config.h
#define HAS_BUILTIN_SYNC_ADD_AND_FETCH 1
#define HAS_BUILTIN_SYNC_SUB_AND_FETCH 1
#define HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP 1

and compiles on both

signed-off for osx/ios/atv2

@huceke
Collaborator

signed-off for RaspberryPI

@theuni
Owner

Fixed include, should be fine for win32 now. Thanks @wsoltys

@MartijnKaijser

Win32 builds ok

@Fneufneu
Collaborator

On amd64 FreeBSD with base gcc 4.2 and clang

#define HAS_BUILTIN_SYNC_ADD_AND_FETCH 1
#define HAS_BUILTIN_SYNC_SUB_AND_FETCH 1
#define HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP 1

and compile fine.

@ghost

squash and inject cory.

@theuni theuni merged commit acae170 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 16, 2012
  1. build: quit guessing about intrinsics, check specifics

    Cory Fields authored
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.