|
@@ -322,20 +322,20 @@ extern "C"
|
|
STARPU_ABORT(); }}
|
|
STARPU_ABORT(); }}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-/* Note: do not use starpu_cmpxchg / starpu_xchg / starpu_cmpxchgl /
|
|
|
|
- * starpu_xchgl / starpu_cmpxchg64 / starpu_xchg64, which only
|
|
|
|
|
|
+/* Note: do not use _starpu_cmpxchg / _starpu_xchg / _starpu_cmpxchgl /
|
|
|
|
+ * _starpu_xchgl / _starpu_cmpxchg64 / _starpu_xchg64, which only
|
|
* assembly-hand-written fallbacks used when building with an old gcc.
|
|
* assembly-hand-written fallbacks used when building with an old gcc.
|
|
- * Rather use STARPU_VAL_COMPARE_AND_SWAP available on all platforms with a
|
|
|
|
- * recent-enough gcc */
|
|
|
|
|
|
+ * Rather use STARPU_VAL_COMPARE_AND_SWAP and STARPU_VAL_EXCHANGE available on
|
|
|
|
+ * all platforms with a recent-enough gcc */
|
|
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
-static __starpu_inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned old, unsigned next)
|
|
|
|
|
|
+static __starpu_inline unsigned _starpu_cmpxchg(unsigned *ptr, unsigned old, unsigned next)
|
|
{
|
|
{
|
|
__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
return old;
|
|
return old;
|
|
}
|
|
}
|
|
#define STARPU_HAVE_CMPXCHG
|
|
#define STARPU_HAVE_CMPXCHG
|
|
-static __starpu_inline unsigned starpu_xchg(unsigned *ptr, unsigned next)
|
|
|
|
|
|
+static __starpu_inline unsigned _starpu_xchg(unsigned *ptr, unsigned next)
|
|
{
|
|
{
|
|
/* Note: xchg is always locked already */
|
|
/* Note: xchg is always locked already */
|
|
__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
@@ -343,13 +343,13 @@ static __starpu_inline unsigned starpu_xchg(unsigned *ptr, unsigned next)
|
|
}
|
|
}
|
|
#define STARPU_HAVE_XCHG
|
|
#define STARPU_HAVE_XCHG
|
|
|
|
|
|
-static __starpu_inline uint32_t starpu_cmpxchg32(uint32_t *ptr, uint32_t old, uint32_t next)
|
|
|
|
|
|
+static __starpu_inline uint32_t _starpu_cmpxchg32(uint32_t *ptr, uint32_t old, uint32_t next)
|
|
{
|
|
{
|
|
__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
return old;
|
|
return old;
|
|
}
|
|
}
|
|
#define STARPU_HAVE_CMPXCHG32
|
|
#define STARPU_HAVE_CMPXCHG32
|
|
-static __starpu_inline uint32_t starpu_xchg32(uint32_t *ptr, uint32_t next)
|
|
|
|
|
|
+static __starpu_inline uint32_t _starpu_xchg32(uint32_t *ptr, uint32_t next)
|
|
{
|
|
{
|
|
/* Note: xchg is always locked already */
|
|
/* Note: xchg is always locked already */
|
|
__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
@@ -358,13 +358,13 @@ static __starpu_inline uint32_t starpu_xchg32(uint32_t *ptr, uint32_t next)
|
|
#define STARPU_HAVE_XCHG32
|
|
#define STARPU_HAVE_XCHG32
|
|
|
|
|
|
#if defined(__i386__)
|
|
#if defined(__i386__)
|
|
-static __starpu_inline unsigned long starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
|
|
|
|
|
|
+static __starpu_inline unsigned long _starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
|
|
{
|
|
{
|
|
__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
return old;
|
|
return old;
|
|
}
|
|
}
|
|
#define STARPU_HAVE_CMPXCHGL
|
|
#define STARPU_HAVE_CMPXCHGL
|
|
-static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned long next)
|
|
|
|
|
|
+static __starpu_inline unsigned long _starpu_xchgl(unsigned long *ptr, unsigned long next)
|
|
{
|
|
{
|
|
/* Note: xchg is always locked already */
|
|
/* Note: xchg is always locked already */
|
|
__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
@@ -374,13 +374,13 @@ static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned l
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
#if defined(__x86_64__)
|
|
-static __starpu_inline unsigned long starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
|
|
|
|
|
|
+static __starpu_inline unsigned long _starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
|
|
{
|
|
{
|
|
__asm__ __volatile__("lock cmpxchgq %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
__asm__ __volatile__("lock cmpxchgq %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
return old;
|
|
return old;
|
|
}
|
|
}
|
|
#define STARPU_HAVE_CMPXCHGL
|
|
#define STARPU_HAVE_CMPXCHGL
|
|
-static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned long next)
|
|
|
|
|
|
+static __starpu_inline unsigned long _starpu_xchgl(unsigned long *ptr, unsigned long next)
|
|
{
|
|
{
|
|
/* Note: xchg is always locked already */
|
|
/* Note: xchg is always locked already */
|
|
__asm__ __volatile__("xchgq %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
__asm__ __volatile__("xchgq %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
@@ -390,7 +390,7 @@ static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned l
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#if defined(__i386__)
|
|
#if defined(__i386__)
|
|
-static __starpu_inline uint64_t starpu_cmpxchg64(uint64_t *ptr, uint64_t old, uint64_t next)
|
|
|
|
|
|
+static __starpu_inline uint64_t _starpu_cmpxchg64(uint64_t *ptr, uint64_t old, uint64_t next)
|
|
{
|
|
{
|
|
uint32_t next_hi = next >> 32;
|
|
uint32_t next_hi = next >> 32;
|
|
uint32_t next_lo = next & 0xfffffffful;
|
|
uint32_t next_lo = next & 0xfffffffful;
|
|
@@ -401,13 +401,13 @@ static __starpu_inline uint64_t starpu_cmpxchg64(uint64_t *ptr, uint64_t old, ui
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
#if defined(__x86_64__)
|
|
-static __starpu_inline uint64_t starpu_cmpxchg64(uint64_t *ptr, uint64_t old, uint64_t next)
|
|
|
|
|
|
+static __starpu_inline uint64_t _starpu_cmpxchg64(uint64_t *ptr, uint64_t old, uint64_t next)
|
|
{
|
|
{
|
|
__asm__ __volatile__("lock cmpxchgq %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
__asm__ __volatile__("lock cmpxchgq %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
|
|
return old;
|
|
return old;
|
|
}
|
|
}
|
|
#define STARPU_HAVE_CMPXCHG64
|
|
#define STARPU_HAVE_CMPXCHG64
|
|
-static __starpu_inline uint64_t starpu_xchg64(uint64_t *ptr, uint64_t next)
|
|
|
|
|
|
+static __starpu_inline uint64_t _starpu_xchg64(uint64_t *ptr, uint64_t next)
|
|
{
|
|
{
|
|
/* Note: xchg is always locked already */
|
|
/* Note: xchg is always locked already */
|
|
__asm__ __volatile__("xchgq %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
__asm__ __volatile__("xchgq %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
|
|
@@ -426,7 +426,7 @@ static __starpu_inline unsigned starpu_atomic_##name(unsigned *ptr, unsigned val
|
|
{ \
|
|
{ \
|
|
old = *ptr; \
|
|
old = *ptr; \
|
|
next = expr; \
|
|
next = expr; \
|
|
- if (starpu_cmpxchg(ptr, old, next) == old) \
|
|
|
|
|
|
+ if (_starpu_cmpxchg(ptr, old, next) == old) \
|
|
break; \
|
|
break; \
|
|
}; \
|
|
}; \
|
|
return expr; \
|
|
return expr; \
|
|
@@ -439,7 +439,7 @@ static __starpu_inline unsigned long starpu_atomic_##name##l(unsigned long *ptr,
|
|
{ \
|
|
{ \
|
|
old = *ptr; \
|
|
old = *ptr; \
|
|
next = expr; \
|
|
next = expr; \
|
|
- if (starpu_cmpxchgl(ptr, old, next) == old) \
|
|
|
|
|
|
+ if (_starpu_cmpxchgl(ptr, old, next) == old) \
|
|
break; \
|
|
break; \
|
|
}; \
|
|
}; \
|
|
return expr; \
|
|
return expr; \
|
|
@@ -452,7 +452,7 @@ static __starpu_inline uint64_t starpu_atomic_##name##64(uint64_t *ptr, uint64_t
|
|
{ \
|
|
{ \
|
|
old = *ptr; \
|
|
old = *ptr; \
|
|
next = expr; \
|
|
next = expr; \
|
|
- if (starpu_cmpxchg64(ptr, old, next) == old) \
|
|
|
|
|
|
+ if (_starpu_cmpxchg64(ptr, old, next) == old) \
|
|
break; \
|
|
break; \
|
|
}; \
|
|
}; \
|
|
return expr; \
|
|
return expr; \
|
|
@@ -503,13 +503,13 @@ STARPU_ATOMIC_SOMETHING64(or, old | value)
|
|
#define STARPU_BOOL_COMPARE_AND_SWAP64(ptr, old, value) STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value)
|
|
#define STARPU_BOOL_COMPARE_AND_SWAP64(ptr, old, value) STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value)
|
|
#else
|
|
#else
|
|
#ifdef STARPU_HAVE_CMPXCHG
|
|
#ifdef STARPU_HAVE_CMPXCHG
|
|
-#define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)) == (old))
|
|
|
|
|
|
+#define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (_starpu_cmpxchg((ptr), (old), (value)) == (old))
|
|
#endif
|
|
#endif
|
|
#ifdef STARPU_HAVE_CMPXCHG32
|
|
#ifdef STARPU_HAVE_CMPXCHG32
|
|
-#define STARPU_BOOL_COMPARE_AND_SWAP32(ptr, old, value) (starpu_cmpxchg32((ptr), (old), (value)) == (old))
|
|
|
|
|
|
+#define STARPU_BOOL_COMPARE_AND_SWAP32(ptr, old, value) (_starpu_cmpxchg32((ptr), (old), (value)) == (old))
|
|
#endif
|
|
#endif
|
|
#ifdef STARPU_HAVE_CMPXCHG64
|
|
#ifdef STARPU_HAVE_CMPXCHG64
|
|
-#define STARPU_BOOL_COMPARE_AND_SWAP64(ptr, old, value) (starpu_cmpxchg64((ptr), (old), (value)) == (old))
|
|
|
|
|
|
+#define STARPU_BOOL_COMPARE_AND_SWAP64(ptr, old, value) (_starpu_cmpxchg64((ptr), (old), (value)) == (old))
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -519,13 +519,33 @@ STARPU_ATOMIC_SOMETHING64(or, old | value)
|
|
#define STARPU_VAL_COMPARE_AND_SWAP64(ptr, old, value) STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value)
|
|
#define STARPU_VAL_COMPARE_AND_SWAP64(ptr, old, value) STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value)
|
|
#else
|
|
#else
|
|
#ifdef STARPU_HAVE_CMPXCHG
|
|
#ifdef STARPU_HAVE_CMPXCHG
|
|
-#define STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)))
|
|
|
|
|
|
+#define STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value) (_starpu_cmpxchg((ptr), (old), (value)))
|
|
#endif
|
|
#endif
|
|
#ifdef STARPU_HAVE_CMPXCHG32
|
|
#ifdef STARPU_HAVE_CMPXCHG32
|
|
-#define STARPU_VAL_COMPARE_AND_SWAP32(ptr, old, value) (starpu_cmpxchg32((ptr), (old), (value)))
|
|
|
|
|
|
+#define STARPU_VAL_COMPARE_AND_SWAP32(ptr, old, value) (_starpu_cmpxchg32((ptr), (old), (value)))
|
|
#endif
|
|
#endif
|
|
#ifdef STARPU_HAVE_CMPXCHG64
|
|
#ifdef STARPU_HAVE_CMPXCHG64
|
|
-#define STARPU_VAL_COMPARE_AND_SWAP64(ptr, old, value) (starpu_cmpxchg64((ptr), (old), (value)))
|
|
|
|
|
|
+#define STARPU_VAL_COMPARE_AND_SWAP64(ptr, old, value) (_starpu_cmpxchg64((ptr), (old), (value)))
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#ifdef STARPU_HAVE_ATOMIC_EXCHANGE_N
|
|
|
|
+#define STARPU_VAL_EXCHANGE(ptr, value) (__atomic_exchange_n((ptr), (value), __ATOMIC_SEQ_CST))
|
|
|
|
+#define STARPU_VAL_EXCHANGEL(ptr, value) STARPU_VAL_EXCHANGE((ptr) (value))
|
|
|
|
+#define STARPU_VAL_EXCHANGE32(ptr, value) STARPU_VAL_EXCHANGE((ptr) (value))
|
|
|
|
+#define STARPU_VAL_EXCHANGE64(ptr, value) STARPU_VAL_EXCHANGE((ptr) (value))
|
|
|
|
+#else
|
|
|
|
+#ifdef STARPU_HAVE_XCHG
|
|
|
|
+#define STARPU_VAL_EXCHANGE(ptr, value) (_starpu_xchg((ptr), (value)))
|
|
|
|
+#endif
|
|
|
|
+#ifdef STARPU_HAVE_XCHGL
|
|
|
|
+#define STARPU_VAL_EXCHANGEL(ptr, value) (_starpu_xchgl((ptr), (value)))
|
|
|
|
+#endif
|
|
|
|
+#ifdef STARPU_HAVE_XCHG32
|
|
|
|
+#define STARPU_VAL_EXCHANGE32(ptr, value) (_starpu_xchg32((ptr), (value)))
|
|
|
|
+#endif
|
|
|
|
+#ifdef STARPU_HAVE_XCHG64
|
|
|
|
+#define STARPU_VAL_EXCHANGE64(ptr, value) (_starpu_xchg64((ptr), (value)))
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -534,8 +554,8 @@ STARPU_ATOMIC_SOMETHING64(or, old | value)
|
|
#define STARPU_TEST_AND_SET(ptr, value) (__sync_lock_test_and_set ((ptr), (value)))
|
|
#define STARPU_TEST_AND_SET(ptr, value) (__sync_lock_test_and_set ((ptr), (value)))
|
|
#define STARPU_RELEASE(ptr) (__sync_lock_release ((ptr)))
|
|
#define STARPU_RELEASE(ptr) (__sync_lock_release ((ptr)))
|
|
#elif defined(STARPU_HAVE_XCHG)
|
|
#elif defined(STARPU_HAVE_XCHG)
|
|
-#define STARPU_TEST_AND_SET(ptr, value) (starpu_xchg((ptr), (value)))
|
|
|
|
-#define STARPU_RELEASE(ptr) (starpu_xchg((ptr), 0))
|
|
|
|
|
|
+#define STARPU_TEST_AND_SET(ptr, value) (_starpu_xchg((ptr), (value)))
|
|
|
|
+#define STARPU_RELEASE(ptr) (_starpu_xchg((ptr), 0))
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef STARPU_HAVE_SYNC_SYNCHRONIZE
|
|
#ifdef STARPU_HAVE_SYNC_SYNCHRONIZE
|