From bd6594522aa61000023546bd6c43459af4590dba Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 5 Oct 2012 21:41:19 +0400 Subject: [PATCH] Generalize compare_double_and_swap_double using double_compare_and_swap * src/atomic_ops/generalize.h (AO_compare_double_and_swap_double, AO_compare_double_and_swap_double_full): New inline function (move code from gcc/arm.h and msftc/x86.h) based on the corresponding double_compare_and_swap (only if AO_HAVE_DOUBLE_PTR_STORAGE and AO_HAVE_double_compare_and_swap[_full] defined but not AO_HAVE_compare_double_and_swap_double[_full]). * src/atomic_ops/generalize.h (AO_HAVE_compare_double_and_swap_double, AO_HAVE_compare_double_and_swap_double_full): New macro (moved from gcc/arm.h and msftc/x86.h, respectively). * src/atomic_ops/sysdeps/gcc/arm.h (AO_compare_double_and_swap_double): Remove definition from this file; remove TODO item. * src/atomic_ops/sysdeps/msftc/x86.h (AO_compare_double_and_swap_double_full): Likewise. --- src/atomic_ops/generalize.h | 38 ++++++++++++++++++++++++++++++ src/atomic_ops/sysdeps/gcc/arm.h | 17 ------------- src/atomic_ops/sysdeps/msftc/x86.h | 18 -------------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/atomic_ops/generalize.h b/src/atomic_ops/generalize.h index 8878ff4..bb72c7b 100644 --- a/src/atomic_ops/generalize.h +++ b/src/atomic_ops/generalize.h @@ -1283,6 +1283,44 @@ #include "generalize-small.h" +/* Compare_double_and_swap_double based on double_compare_and_swap. */ +#ifdef AO_HAVE_DOUBLE_PTR_STORAGE +# if defined(AO_HAVE_double_compare_and_swap) \ + && !defined(AO_HAVE_compare_double_and_swap_double) + AO_INLINE int + AO_compare_double_and_swap_double(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2) + { + AO_double_t old_w; + AO_double_t new_w; + old_w.AO_val1 = old_val1; + old_w.AO_val2 = old_val2; + new_w.AO_val1 = new_val1; + new_w.AO_val2 = new_val2; + return AO_double_compare_and_swap(addr, old_w, new_w); + } +# define AO_HAVE_compare_double_and_swap_double +# endif +# if defined(AO_HAVE_double_compare_and_swap_full) \ + && !defined(AO_HAVE_compare_double_and_swap_double_full) + AO_INLINE int + AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2) + { + AO_double_t old_w; + AO_double_t new_w; + old_w.AO_val1 = old_val1; + old_w.AO_val2 = old_val2; + new_w.AO_val1 = new_val1; + new_w.AO_val2 = new_val2; + return AO_double_compare_and_swap_full(addr, old_w, new_w); + } +# define AO_HAVE_compare_double_and_swap_double_full +# endif +#endif /* AO_HAVE_DOUBLE_PTR_STORAGE */ + /* Compare_double_and_swap_double */ #if defined(AO_HAVE_compare_double_and_swap_double) \ && defined(AO_HAVE_nop_full) \ diff --git a/src/atomic_ops/sysdeps/gcc/arm.h b/src/atomic_ops/sysdeps/gcc/arm.h index 844bb3d..b994bbb 100644 --- a/src/atomic_ops/sysdeps/gcc/arm.h +++ b/src/atomic_ops/sysdeps/gcc/arm.h @@ -339,23 +339,6 @@ AO_fetch_compare_and_swap(volatile AO_t *addr, AO_t old_val, AO_t new_val) return !result; /* if succeded, return 1 else 0 */ } # define AO_HAVE_double_compare_and_swap - - /* TODO: Move to generalize.h. */ - AO_INLINE int - AO_compare_double_and_swap_double(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2) - { - AO_double_t old_w; - AO_double_t new_w; - - old_w.AO_val1 = old_val1; - old_w.AO_val2 = old_val2; - new_w.AO_val1 = new_val1; - new_w.AO_val2 = new_val2; - return AO_double_compare_and_swap(addr, old_w, new_w); - } -# define AO_HAVE_compare_double_and_swap_double #endif /* AO_ARM_HAVE_LDREXD */ #else diff --git a/src/atomic_ops/sysdeps/msftc/x86.h b/src/atomic_ops/sysdeps/msftc/x86.h index 10e5229..897bd8b 100644 --- a/src/atomic_ops/sysdeps/msftc/x86.h +++ b/src/atomic_ops/sysdeps/msftc/x86.h @@ -102,24 +102,6 @@ AO_test_and_set_full(volatile AO_TS_t *addr) old_val.AO_whole) == old_val.AO_whole; } # define AO_HAVE_double_compare_and_swap_full - - /* TODO: Move to generalize.h. */ - AO_INLINE int - AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2) - { - AO_double_t old_w; - AO_double_t new_w; - - old_w.AO_val1 = old_val1; - old_w.AO_val2 = old_val2; - new_w.AO_val1 = new_val1; - new_w.AO_val2 = new_val2; - return AO_double_compare_and_swap_full(addr, old_w, new_w); - } -# define AO_HAVE_compare_double_and_swap_double_full - #endif /* AO_ASSUME_VISTA */ #define AO_T_IS_INT -- 2.40.0