Selaa lähdekoodia

test if __sync_* GCC built-in are available

Cédric Augonnet 16 vuotta sitten
vanhempi
commit
446f18f835
4 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 14 0
      acinclude.m4
  2. 2 0
      configure.ac
  3. 4 0
      include/starpu-util.h
  4. 2 0
      include/starpu_config.h.in

+ 14 - 0
acinclude.m4

@@ -0,0 +1,14 @@
+dnl This test is taken from libgfortran
+
+dnl Check whether the target supports __sync_*_compare_and_swap.
+AC_DEFUN([STARPU_CHECK_SYNC_BUILTINS], [
+  AC_CACHE_CHECK([whether the target supports __sync_*_compare_and_swap],
+		 ac_cv_have_sync_builtins, [
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([int foo, bar;],
+			[bar = __sync_val_compare_and_swap(&foo, 0, 1);])],
+			[ac_cv_have_sync_builtins=yes],
+			[ac_cv_have_sync_builtins=no])])
+  if test $ac_cv_have_sync_builtins = yes; then
+    AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
+	      [Define to 1 if the target supports __sync_*_compare_and_swap])
+  fi])

+ 2 - 0
configure.ac

@@ -57,6 +57,8 @@ if test x$have_posix_memalign = xyes; then
 	AC_DEFINE(HAVE_POSIX_MEMALIGN,[],[posix_memalign is available])
 fi
 
+# This defines HAVE_SYNC_BUILTINS
+STARPU_CHECK_SYNC_BUILTINS
 
 ###############################################################################
 #                                                                             #

+ 4 - 0
include/starpu-util.h

@@ -30,8 +30,12 @@
 #define STARPU_UNLIKELY(expr)          (__builtin_expect(!!(expr),0))
 #define STARPU_LIKELY(expr)            (__builtin_expect(!!(expr),1))
 
+#ifdef HAVE_SYNC_BUILTINS
 #define STARPU_ATOMIC_ADD(ptr, value)  (__sync_fetch_and_add ((ptr), (value)) + (value))
 #define STARPU_ATOMIC_OR(ptr, value)  (__sync_fetch_and_or ((ptr), (value)))
+#else
+#error __sync_fetch_and_add is not available
+#endif
 
 #define STARPU_SUCCESS	0
 #define STARPU_TRYAGAIN	1

+ 2 - 0
include/starpu_config.h.in

@@ -19,4 +19,6 @@
 
 #undef HAVE_POSIX_MEMALIGN
 
+#undef HAVE_SYNC_BUILTINS
+
 #endif