|
@@ -29,6 +29,39 @@ extern "C"
|
|
|
{
|
|
|
#endif
|
|
|
|
|
|
+/* Return true (non-zero) if GCC version MAJ.MIN or later is being used
|
|
|
+ * (macro taken from glibc.) */
|
|
|
+#if defined __GNUC__ && defined __GNUC_MINOR__
|
|
|
+# define STARPU_GNUC_PREREQ(maj, min) \
|
|
|
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
|
|
+#else
|
|
|
+# define STARPU_GNUC_PREREQ(maj, min) 0
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifdef __GNUC__
|
|
|
+# define STARPU_UNLIKELY(expr) (__builtin_expect(!!(expr),0))
|
|
|
+# define STARPU_LIKELY(expr) (__builtin_expect(!!(expr),1))
|
|
|
+# define STARPU_ATTRIBUTE_UNUSED __attribute__((unused))
|
|
|
+# define STARPU_ATTRIBUTE_INTERNAL __attribute__ ((visibility ("internal")))
|
|
|
+#else
|
|
|
+# define STARPU_UNLIKELY(expr) (expr)
|
|
|
+# define STARPU_LIKELY(expr) (expr)
|
|
|
+# define STARPU_ATTRIBUTE_UNUSED
|
|
|
+# define STARPU_ATTRIBUTE_INTERNAL
|
|
|
+#endif
|
|
|
+
|
|
|
+#if STARPU_GNUC_PREREQ(3, 1) && !defined(BUILDING_STARPU) && !defined(STARPU_USE_DEPRECATED_API)
|
|
|
+#define STARPU_DEPRECATED __attribute__((__deprecated__))
|
|
|
+#else
|
|
|
+#define STARPU_DEPRECATED
|
|
|
+#endif /* __GNUC__ */
|
|
|
+
|
|
|
+#if STARPU_GNUC_PREREQ(3,3)
|
|
|
+#define STARPU_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
|
|
|
+#else
|
|
|
+#define STARPU_WARN_UNUSED_RESULT
|
|
|
+#endif /* __GNUC__ */
|
|
|
+
|
|
|
#define STARPU_POISON_PTR ((void *)0xdeadbeef)
|
|
|
|
|
|
#define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
|
|
@@ -39,11 +72,11 @@ extern "C"
|
|
|
#define STARPU_ASSERT_MSG(x, msg) do { (void) (x);} while(0)
|
|
|
#else
|
|
|
# if defined(__CUDACC__) && defined(STARPU_HAVE_WINDOWS)
|
|
|
-# define STARPU_ASSERT(x) do { if (!(x)) *(int*)NULL = 0; } while(0)
|
|
|
-# define STARPU_ASSERT_MSG(x, msg) do { if (!(x)) { fprintf(stderr, "[starpu][%s][assert failure] %s\n", __func__, msg); *(int*)NULL = 0; }} while(0)
|
|
|
+# define STARPU_ASSERT(x) do { if (STARPU_UNLIKELY(!(x))) *(int*)NULL = 0; } while(0)
|
|
|
+# define STARPU_ASSERT_MSG(x, msg) do { if (STARPU_UNLIKELY(!(x))) { fprintf(stderr, "[starpu][%s][assert failure] %s\n", __func__, msg); *(int*)NULL = 0; }} while(0)
|
|
|
# else
|
|
|
# define STARPU_ASSERT(x) assert(x)
|
|
|
-# define STARPU_ASSERT_MSG(x, msg) do { if (!(x)) { fprintf(stderr, "[starpu][%s][assert failure] %s\n", __func__, msg); } ; assert(x); } while(0)
|
|
|
+# define STARPU_ASSERT_MSG(x, msg) do { if (STARPU_UNLIKELY(!(x))) { fprintf(stderr, "[starpu][%s][assert failure] %s\n", __func__, msg); } ; assert(x); } while(0)
|
|
|
|
|
|
# endif
|
|
|
#endif
|
|
@@ -54,56 +87,23 @@ extern "C"
|
|
|
} while(0)
|
|
|
|
|
|
#if defined(STARPU_HAVE_STRERROR_R)
|
|
|
-# define STARPU_CHECK_RETURN_VALUE(err, message) {if (err != 0) { \
|
|
|
+# define STARPU_CHECK_RETURN_VALUE(err, message) {if (STARPU_UNLIKELY(err != 0)) { \
|
|
|
char xmessage[256]; strerror_r(-err, xmessage, 256); \
|
|
|
fprintf(stderr, "StarPU function <%s> returned unexpected value: <%d:%s>\n", message, err, xmessage); \
|
|
|
STARPU_ABORT(); }}
|
|
|
-# define STARPU_CHECK_RETURN_VALUE_IS(err, value, message) {if (err != value) { \
|
|
|
+# define STARPU_CHECK_RETURN_VALUE_IS(err, value, message) {if (STARPU_UNLIKELY(err != value)) { \
|
|
|
char xmessage[256]; strerror_r(-err, xmessage, 256); \
|
|
|
fprintf(stderr, "StarPU function <%s> returned unexpected value: <%d:%s>\n", message, err, xmessage); \
|
|
|
STARPU_ABORT(); }}
|
|
|
#else
|
|
|
-# define STARPU_CHECK_RETURN_VALUE(err, message) {if (err != 0) { \
|
|
|
+# define STARPU_CHECK_RETURN_VALUE(err, message) {if (STARPU_UNLIKELY(err != 0)) { \
|
|
|
fprintf(stderr, "StarPU function <%s> returned unexpected value: <%d>\n", message, err); \
|
|
|
STARPU_ABORT(); }}
|
|
|
-# define STARPU_CHECK_RETURN_VALUE_IS(err, value, message) {if (err != value) { \
|
|
|
+# define STARPU_CHECK_RETURN_VALUE_IS(err, value, message) {if (STARPU_UNLIKELY(err != value)) { \
|
|
|
fprintf(stderr, "StarPU function <%s> returned unexpected value: <%d>\n", message, err); \
|
|
|
STARPU_ABORT(); }}
|
|
|
#endif /* STARPU_HAVE_STRERROR_R */
|
|
|
|
|
|
-/* Return true (non-zero) if GCC version MAJ.MIN or later is being used
|
|
|
- * (macro taken from glibc.) */
|
|
|
-#if defined __GNUC__ && defined __GNUC_MINOR__
|
|
|
-# define STARPU_GNUC_PREREQ(maj, min) \
|
|
|
- ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
|
|
-#else
|
|
|
-# define STARPU_GNUC_PREREQ(maj, min) 0
|
|
|
-#endif
|
|
|
-
|
|
|
-#ifdef __GNUC__
|
|
|
-# define STARPU_UNLIKELY(expr) (__builtin_expect(!!(expr),0))
|
|
|
-# define STARPU_LIKELY(expr) (__builtin_expect(!!(expr),1))
|
|
|
-# define STARPU_ATTRIBUTE_UNUSED __attribute__((unused))
|
|
|
-# define STARPU_ATTRIBUTE_INTERNAL __attribute__ ((visibility ("internal")))
|
|
|
-#else
|
|
|
-# define STARPU_UNLIKELY(expr) (expr)
|
|
|
-# define STARPU_LIKELY(expr) (expr)
|
|
|
-# define STARPU_ATTRIBUTE_UNUSED
|
|
|
-# define STARPU_ATTRIBUTE_INTERNAL
|
|
|
-#endif
|
|
|
-
|
|
|
-#if STARPU_GNUC_PREREQ(3, 1) && !defined(BUILDING_STARPU) && !defined(STARPU_USE_DEPRECATED_API)
|
|
|
-#define STARPU_DEPRECATED __attribute__((__deprecated__))
|
|
|
-#else
|
|
|
-#define STARPU_DEPRECATED
|
|
|
-#endif /* __GNUC__ */
|
|
|
-
|
|
|
-#if STARPU_GNUC_PREREQ(3,3)
|
|
|
-#define STARPU_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
|
|
|
-#else
|
|
|
-#define STARPU_WARN_UNUSED_RESULT
|
|
|
-#endif /* __GNUC__ */
|
|
|
-
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
|
|
static __inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned old, unsigned next)
|
|
@@ -172,6 +172,17 @@ STARPU_ATOMIC_SOMETHING(or, old | value)
|
|
|
#define STARPU_SYNCHRONIZE() __asm__ __volatile__("sync" ::: "memory")
|
|
|
#endif
|
|
|
|
|
|
+#if defined(__i386__)
|
|
|
+#define STARPU_RMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
|
|
|
+#define STARPU_WMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
|
|
|
+#elif defined(__x86_64__)
|
|
|
+#define STARPU_RMB() __asm__ __volatile__("lfence" ::: "memory")
|
|
|
+#define STARPU_WMB() __asm__ __volatile__("sfence" ::: "memory")
|
|
|
+#elif defined(__ppc__) || defined(__ppc64__)
|
|
|
+#define STARPU_RMB() __asm__ __volatile__("sync" ::: "memory")
|
|
|
+#define STARPU_WMB() __asm__ __volatile__("sync" ::: "memory")
|
|
|
+#endif
|
|
|
+
|
|
|
#ifdef __cplusplus
|
|
|
}
|
|
|
#endif
|