Skip to content
Snippets Groups Projects
Commit e3a01e02 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Fixed the atomic min/max/add for floats that were incorrectly pushed earlier.

parent ff8cb4a0
No related branches found
No related tags found
Loading
...@@ -35,39 +35,48 @@ ...@@ -35,39 +35,48 @@
#define atomic_swap(v, n) __sync_lock_test_and_set(v, n) #define atomic_swap(v, n) __sync_lock_test_and_set(v, n)
/** /**
* @param Atomic min operation on floats. * @brief Atomic min operation on floats.
*/ */
__attribute__((always_inline)) INLINE void atomic_min_f(float const* x, __attribute__((always_inline)) INLINE void atomic_min_f(volatile float* x,
float y) { float y) {
int done = 0; float test, new;
while (!done) { float old = *x;
const float val = *x; do {
done = __sync_bool_compare_and_swap((int*)x, val, min(val, y)); test = old;
} new = min(old, y);
if (new == old) return;
old = atomic_cas((int*)x, test, new);
} while (test != old);
} }
/** /**
* @param Atomic max operation on floats. * @brief Atomic max operation on floats.
*/ */
__attribute__((always_inline)) INLINE void atomic_max_f(float const* x, __attribute__((always_inline)) INLINE void atomic_max_f(volatile float* x,
float y) { float y) {
int done = 0; float test, new;
while (!done) { float old = *x;
const float val = *x; do {
done = __sync_bool_compare_and_swap((int*)x, val, max(val, y)); test = old;
} new = max(old, y);
if (new == old) return;
old = atomic_cas((int*)x, test, new);
} while (test != old);
} }
/** /**
* @param Atomic add operation on floats. * @brief Atomic add operation on floats.
*/ */
__attribute__((always_inline)) INLINE void atomic_add_f(float const* x, __attribute__((always_inline)) INLINE void atomic_add_f(volatile float* x,
float y) { float y) {
int done = 0; float test, new;
while (!done) { float old = *x;
const float val = *x; do {
done = __sync_bool_compare_and_swap((int*)x, val, val + y); test = old;
} new = old + y;
if (new == old) return;
old = atomic_cas((int*)x, test, new);
} while (test != old);
} }
#endif /* SWIFT_ATOMIC_H */ #endif /* SWIFT_ATOMIC_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment