]> granicus.if.org Git - libatomic_ops/commitdiff
Merge branch 'ao_t_is_int-fix' into master
authorIvan Maidanski <ivmai@mail.ru>
Tue, 29 Nov 2011 18:41:13 +0000 (22:41 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 29 Nov 2011 18:41:13 +0000 (22:41 +0400)
1  2 
src/atomic_ops.h
src/atomic_ops/sysdeps/gcc/hexagon.h
src/atomic_ops/sysdeps/gcc/ia64.h
src/atomic_ops/sysdeps/gcc/m68k.h
src/atomic_ops/sysdeps/gcc/mips.h
src/atomic_ops/sysdeps/gcc/powerpc.h
src/atomic_ops/sysdeps/gcc/x86.h
src/atomic_ops/sysdeps/hpc/ia64.h
src/atomic_ops/sysdeps/sunc/x86.h

Simple merge
index 6d25797d8a1e032f08398d9500cc90351731835a,b89905bbd104a3721453cb47d50b808d98ca369d..38d73f94965cc6d2f4a4126656ff4e9e8ec6339a
@@@ -68,53 -68,28 +68,53 @@@ AO_test_and_set(volatile AO_TS_t *addr
  }
  #define AO_HAVE_test_and_set
  
 -AO_INLINE int
 -AO_compare_and_swap(volatile AO_t *addr, AO_t old, AO_t new_val)
 +#ifndef AO_GENERALIZE_ASM_BOOL_CAS
 +  AO_INLINE int
 +  AO_compare_and_swap(volatile AO_t *addr, AO_t old, AO_t new_val)
 +  {
 +    AO_t __oldval;
 +    int result = 0;
 +    __asm__ __volatile__(
 +      "1:\n"
 +      "  %0 = memw_locked(%3);\n"       /* load and reserve             */
 +      "  {\n"
 +      "    p2 = cmp.eq(%0,%4);\n"       /* if load is not equal to      */
 +      "    if (!p2.new) jump:nt 2f; \n" /* old, fail                    */
 +      "  }\n"
 +      "  memw_locked(%3,p1) = %5;\n"    /* else store conditional       */
 +      "  if (!p1) jump 1b;\n"           /* retry if lost reservation    */
 +      "  %1 = #1\n"                     /* success, result = 1          */
 +      "2:\n"
 +      : "=&r" (__oldval), "+r" (result), "+m"(*addr)
 +      : "r" (addr), "r" (old), "r" (new_val)
 +      : "p1", "p2", "memory"
 +    );
 +    return result;
 +  }
 +# define AO_HAVE_compare_and_swap
 +#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
 +
 +AO_INLINE AO_t
 +AO_fetch_compare_and_swap(volatile AO_t *addr, AO_t old_val, AO_t new_val)
  {
    AO_t __oldval;
 -  int result = 0;
 +
    __asm__ __volatile__(
       "1:\n"
 -     "  %0 = memw_locked(%3);\n"        /* load and reserve            */
 +     "  %0 = memw_locked(%2);\n"        /* load and reserve            */
       "  {\n"
 -     "    p2 = cmp.eq(%0,%4);\n"        /* if load is not equal to     */
 -     "    if (!p2.new) jump:nt 2f; \n"  /* old, fail                   */
 +     "    p2 = cmp.eq(%0,%3);\n"        /* if load is not equal to     */
 +     "    if (!p2.new) jump:nt 2f; \n"  /* old_val, fail               */
       "  }\n"
 -     "  memw_locked(%3,p1) = %5;\n"     /* else store conditional      */
 +     "  memw_locked(%2,p1) = %4;\n"     /* else store conditional      */
       "  if (!p1) jump 1b;\n"            /* retry if lost reservation   */
 -     "  %1 = #1\n"                      /* success, result = 1         */
       "2:\n"
 -     : "=&r" (__oldval), "+r" (result), "+m"(*addr)
 -     : "r" (addr), "r" (old), "r" (new_val)
 +     : "=&r" (__oldval), "+m"(*addr)
 +     : "r" (addr), "r" (old_val), "r" (new_val)
       : "p1", "p2", "memory"
    );
 -  return result;
 +  return __oldval;
  }
 -#define AO_HAVE_compare_and_swap
 +#define AO_HAVE_fetch_compare_and_swap
  
- #include "../ao_t_is_int.h"
+ #define AO_T_IS_INT
Simple merge
index a00afe7000ddd08f48191ad366d59f5687ee281e,73838f6837c8a5c55095721232e2a6e98636ad2c..c065304dc25b8c9cee0eb8279eac6ae09153afc8
@@@ -63,6 -63,4 +63,6 @@@ AO_compare_and_swap_full(volatile AO_t 
  }
  #define AO_HAVE_compare_and_swap_full
  
- #include "../ao_t_is_int.h"
 +/* FIXME: implement AO_fetch_compare_and_swap */
 +
+ #define AO_T_IS_INT
index 9adfe21256dd029e3ea1aea644c66843aea5fcd2,670e30e5c8a189044083f809c6fc926751939c48..1e1ad979f438fa6e861702cbe33f8f5cc3b8eb03
@@@ -66,37 -66,13 +66,13 @@@ AO_compare_and_swap(volatile AO_t *addr
  }
  #define AO_HAVE_compare_and_swap
  
- /* FIXME: I think the implementations below should be automatically     */
- /* generated if we omit them.  - HB                                     */
- AO_INLINE int
- AO_compare_and_swap_acquire(volatile AO_t *addr, AO_t old, AO_t new_val) {
-   int result = AO_compare_and_swap(addr, old, new_val);
-   AO_nop_full();
-   return result;
- }
- #define AO_HAVE_compare_and_swap_acquire
- AO_INLINE int
- AO_compare_and_swap_release(volatile AO_t *addr, AO_t old, AO_t new_val) {
-   AO_nop_full();
-   return AO_compare_and_swap(addr, old, new_val);
- }
- #define AO_HAVE_compare_and_swap_release
- AO_INLINE int
- AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val) {
-   int result;
-   AO_nop_full();
-   result = AO_compare_and_swap(addr, old, new_val);
-   AO_nop_full();
-   return result;
- }
- #define AO_HAVE_compare_and_swap_full
+ /* CAS primitives with acquire, release and full semantics are  */
+ /* generated automatically (and AO_int_... primitives are       */
+ /* defined properly after the first generalization pass).       */
  
 -/*
 - * FIXME: We should also implement fetch_and_add and or primitives
 - * directly.
 - */
 +/* FIXME: implement AO_fetch_compare_and_swap */
 +
 +/* FIXME: We should also implement AO_fetch_and_add, AO_and, AO_or,     */
 +/* AO_xor primitives directly.                                          */
  
- #include "../ao_t_is_int.h"
+ #define AO_T_IS_INT
Simple merge
Simple merge
index 866ea5983065a0e149f0acb5f8b020a625ccdb3b,a4d384e58e14242978d147aaa13ce3fe70f2aab8..ab0e0e9f2051de06ce320d5552f180f7656c3ac4
@@@ -81,73 -81,84 +81,73 @@@ AO_fetch_and_sub1_release (volatile AO_
  }
  #define AO_HAVE_fetch_and_sub1_release
  
 -AO_INLINE int
 -AO_compare_and_swap_acquire(volatile AO_t *addr,
 -                             AO_t old, AO_t new_val)
 +AO_INLINE AO_t
 +AO_fetch_compare_and_swap_acquire(volatile AO_t *addr, AO_t old_val,
 +                                  AO_t new_val)
  {
 -  AO_t oldval;
 -
 -  _Asm_mov_to_ar(_AREG_CCV, old, _DOWN_MEM_FENCE);
 -  oldval = _Asm_cmpxchg(AO_T_SIZE, _SEM_ACQ, addr,
 -                        new_val, _LDHINT_NONE, _DOWN_MEM_FENCE);
 -  return (oldval == old);
 +  _Asm_mov_to_ar(_AREG_CCV, old_val, _DOWN_MEM_FENCE);
 +  return _Asm_cmpxchg(AO_T_SIZE, _SEM_ACQ, addr,
 +                      new_val, _LDHINT_NONE, _DOWN_MEM_FENCE);
  }
 -#define AO_HAVE_compare_and_swap_acquire
 +#define AO_HAVE_fetch_compare_and_swap_acquire
  
 -AO_INLINE int
 -AO_compare_and_swap_release(volatile AO_t *addr,
 -                             AO_t old, AO_t new_val)
 +AO_INLINE AO_t
 +AO_fetch_compare_and_swap_release(volatile AO_t *addr, AO_t old_val,
 +                                  AO_t new_val)
  {
 -  AO_t oldval;
 -  _Asm_mov_to_ar(_AREG_CCV, old, _UP_MEM_FENCE);
 -  oldval = _Asm_cmpxchg(AO_T_SIZE, _SEM_REL, addr,
 -                        new_val, _LDHINT_NONE, _UP_MEM_FENCE);
 -  /* Hopefully the compiler knows not to reorder the above two? */
 -  return (oldval == old);
 +  _Asm_mov_to_ar(_AREG_CCV, old_val, _UP_MEM_FENCE);
 +  return _Asm_cmpxchg(AO_T_SIZE, _SEM_REL, addr,
 +                      new_val, _LDHINT_NONE, _UP_MEM_FENCE);
 +
  }
 -#define AO_HAVE_compare_and_swap_release
 +#define AO_HAVE_fetch_compare_and_swap_release
  
 -AO_INLINE int
 -AO_char_compare_and_swap_acquire(volatile unsigned char *addr,
 -                                 unsigned char old, unsigned char new_val)
 +AO_INLINE unsigned char
 +AO_char_fetch_compare_and_swap_acquire(volatile unsigned char *addr,
 +                                unsigned char old_val, unsigned char new_val)
  {
 -  unsigned char oldval;
 +  _Asm_mov_to_ar(_AREG_CCV, old_val, _DOWN_MEM_FENCE);
 +  return _Asm_cmpxchg(_SZ_B, _SEM_ACQ, addr,
 +                      new_val, _LDHINT_NONE, _DOWN_MEM_FENCE);
  
 -  _Asm_mov_to_ar(_AREG_CCV, old, _DOWN_MEM_FENCE);
 -  oldval = _Asm_cmpxchg(_SZ_B, _SEM_ACQ, addr,
 -                        new_val, _LDHINT_NONE, _DOWN_MEM_FENCE);
 -  return (oldval == old);
  }
 -#define AO_HAVE_char_compare_and_swap_acquire
 +#define AO_HAVE_char_fetch_compare_and_swap_acquire
  
 -AO_INLINE int
 -AO_char_compare_and_swap_release(volatile unsigned char *addr,
 -                                 unsigned char old, unsigned char new_val)
 +AO_INLINE unsigned char
 +AO_char_fetch_compare_and_swap_release(volatile unsigned char *addr,
 +                                unsigned char old_val, unsigned char new_val)
  {
 -  unsigned char oldval;
 -  _Asm_mov_to_ar(_AREG_CCV, old, _UP_MEM_FENCE);
 -  oldval = _Asm_cmpxchg(_SZ_B, _SEM_REL, addr,
 -                        new_val, _LDHINT_NONE, _UP_MEM_FENCE);
 -  /* Hopefully the compiler knows not to reorder the above two? */
 -  return (oldval == old);
 +  _Asm_mov_to_ar(_AREG_CCV, old_val, _UP_MEM_FENCE);
 +  return _Asm_cmpxchg(_SZ_B, _SEM_REL, addr,
 +                      new_val, _LDHINT_NONE, _UP_MEM_FENCE);
 +
  }
 -#define AO_HAVE_char_compare_and_swap_release
 +#define AO_HAVE_char_fetch_compare_and_swap_release
  
 -AO_INLINE int
 -AO_short_compare_and_swap_acquire(volatile unsigned short *addr,
 -                                 unsigned short old, unsigned short new_val)
 +AO_INLINE unsigned short
 +AO_short_fetch_compare_and_swap_acquire(volatile unsigned short *addr,
 +                                        unsigned short old_val,
 +                                        unsigned short new_val)
  {
 -  unsigned short oldval;
 +  _Asm_mov_to_ar(_AREG_CCV, old_val, _DOWN_MEM_FENCE);
 +  return _Asm_cmpxchg(_SZ_B, _SEM_ACQ, addr,
 +                      new_val, _LDHINT_NONE, _DOWN_MEM_FENCE);
  
 -  _Asm_mov_to_ar(_AREG_CCV, old, _DOWN_MEM_FENCE);
 -  oldval = _Asm_cmpxchg(_SZ_B, _SEM_ACQ, addr,
 -                        new_val, _LDHINT_NONE, _DOWN_MEM_FENCE);
 -  return (oldval == old);
  }
 -#define AO_HAVE_short_compare_and_swap_acquire
 +#define AO_HAVE_short_fetch_compare_and_swap_acquire
  
 -AO_INLINE int
 -AO_short_compare_and_swap_release(volatile unsigned short *addr,
 -                                 unsigned short old, unsigned short new_val)
 +AO_INLINE unsigned short
 +AO_short_fetch_compare_and_swap_release(volatile unsigned short *addr,
 +                                        unsigned short old_val,
 +                                        unsigned short new_val)
  {
 -  unsigned short oldval;
 -  _Asm_mov_to_ar(_AREG_CCV, old, _UP_MEM_FENCE);
 -  oldval = _Asm_cmpxchg(_SZ_B, _SEM_REL, addr,
 -                        new_val, _LDHINT_NONE, _UP_MEM_FENCE);
 -  /* Hopefully the compiler knows not to reorder the above two? */
 -  return (oldval == old);
 +  _Asm_mov_to_ar(_AREG_CCV, old_val, _UP_MEM_FENCE);
 +  return _Asm_cmpxchg(_SZ_B, _SEM_REL, addr,
 +                      new_val, _LDHINT_NONE, _UP_MEM_FENCE);
 +
  }
 -#define AO_HAVE_short_compare_and_swap_release
 +#define AO_HAVE_short_fetch_compare_and_swap_release
  
  #ifndef __LP64__
- # include "../ao_t_is_int.h"
+ # define AO_T_IS_INT
  #endif
Simple merge