/*
 * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* XSIZE_fetch_compare_and_swap */
#if defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
    && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire)
  AO_INLINE XCTYPE
  AO_XSIZE_fetch_compare_and_swap_acquire(volatile XCTYPE *addr,
                                          XCTYPE old_val, XCTYPE new_val)
  {
    XCTYPE result = AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val);
    AO_nop_full();
    return result;
  }
# define AO_HAVE_XSIZE_fetch_compare_and_swap_acquire
#endif
#if defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
    && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_release)
# define AO_XSIZE_fetch_compare_and_swap_release(addr, old_val, new_val) \
                (AO_nop_full(), \
                 AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val))
# define AO_HAVE_XSIZE_fetch_compare_and_swap_release
#endif
#if defined(AO_HAVE_XSIZE_fetch_compare_and_swap_full)
# if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_release)
#   define AO_XSIZE_fetch_compare_and_swap_release(addr, old_val, new_val) \
                AO_XSIZE_fetch_compare_and_swap_full(addr, old_val, new_val)
#   define AO_HAVE_XSIZE_fetch_compare_and_swap_release
# endif
# if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire)
#   define AO_XSIZE_fetch_compare_and_swap_acquire(addr, old_val, new_val) \
                AO_XSIZE_fetch_compare_and_swap_full(addr, old_val, new_val)
#   define AO_HAVE_XSIZE_fetch_compare_and_swap_acquire
# endif
# if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_write)
#   define AO_XSIZE_fetch_compare_and_swap_write(addr, old_val, new_val) \
                AO_XSIZE_fetch_compare_and_swap_full(addr, old_val, new_val)
#   define AO_HAVE_XSIZE_fetch_compare_and_swap_write
# endif
# if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_read)
#   define AO_XSIZE_fetch_compare_and_swap_read(addr, old_val, new_val) \
                AO_XSIZE_fetch_compare_and_swap_full(addr, old_val, new_val)
#   define AO_HAVE_XSIZE_fetch_compare_and_swap_read
# endif
#endif /* AO_HAVE_XSIZE_fetch_compare_and_swap_full */

#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_release)
# define AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val) \
            AO_XSIZE_fetch_compare_and_swap_release(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap
#endif
#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire)
# define AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val) \
            AO_XSIZE_fetch_compare_and_swap_acquire(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap
#endif
#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_write)
# define AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val) \
                AO_XSIZE_fetch_compare_and_swap_write(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap
#endif
#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_read)
# define AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val) \
                AO_XSIZE_fetch_compare_and_swap_read(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap
#endif

#if defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire) \
    && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_full)
# define AO_XSIZE_fetch_compare_and_swap_full(addr, old_val, new_val) \
            (AO_nop_full(), \
             AO_XSIZE_fetch_compare_and_swap_acquire(addr, old_val, new_val))
# define AO_HAVE_XSIZE_fetch_compare_and_swap_full
#endif

#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_release_write) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_write)
# define AO_XSIZE_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
                AO_XSIZE_fetch_compare_and_swap_write(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap_release_write
#endif
#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_release_write) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_release)
# define AO_XSIZE_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
            AO_XSIZE_fetch_compare_and_swap_release(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap_release_write
#endif
#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire_read) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_read)
# define AO_XSIZE_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
                AO_XSIZE_fetch_compare_and_swap_read(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap_acquire_read
#endif
#if !defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire_read) \
    && defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire)
# define AO_XSIZE_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
            AO_XSIZE_fetch_compare_and_swap_acquire(addr, old_val, new_val)
# define AO_HAVE_XSIZE_fetch_compare_and_swap_acquire_read
#endif

#ifdef AO_NO_DD_ORDERING
# if defined(AO_HAVE_XSIZE_fetch_compare_and_swap_acquire_read)
#   define AO_XSIZE_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
        AO_XSIZE_fetch_compare_and_swap_acquire_read(addr, old_val, new_val)
#   define AO_HAVE_XSIZE_fetch_compare_and_swap_dd_acquire_read
# endif
#else
# if defined(AO_HAVE_XSIZE_fetch_compare_and_swap)
#   define AO_XSIZE_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
                AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val)
#   define AO_HAVE_XSIZE_fetch_compare_and_swap_dd_acquire_read
# endif
#endif /* !AO_NO_DD_ORDERING */

/* XSIZE_compare_and_swap */
#if defined(AO_HAVE_XSIZE_compare_and_swap) && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_compare_and_swap_acquire)
  AO_INLINE int
  AO_XSIZE_compare_and_swap_acquire(volatile XCTYPE *addr, XCTYPE old,
                                    XCTYPE new_val)
  {
    int result = AO_XSIZE_compare_and_swap(addr, old, new_val);
    AO_nop_full();
    return result;
  }
# define AO_HAVE_XSIZE_compare_and_swap_acquire
#endif
#if defined(AO_HAVE_XSIZE_compare_and_swap) && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_compare_and_swap_release)
# define AO_XSIZE_compare_and_swap_release(addr, old, new_val) \
                (AO_nop_full(), AO_XSIZE_compare_and_swap(addr, old, new_val))
# define AO_HAVE_XSIZE_compare_and_swap_release
#endif
#if defined(AO_HAVE_XSIZE_compare_and_swap_full)
# if !defined(AO_HAVE_XSIZE_compare_and_swap_release)
#   define AO_XSIZE_compare_and_swap_release(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_full(addr, old, new_val)
#   define AO_HAVE_XSIZE_compare_and_swap_release
# endif
# if !defined(AO_HAVE_XSIZE_compare_and_swap_acquire)
#   define AO_XSIZE_compare_and_swap_acquire(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_full(addr, old, new_val)
#   define AO_HAVE_XSIZE_compare_and_swap_acquire
# endif
# if !defined(AO_HAVE_XSIZE_compare_and_swap_write)
#   define AO_XSIZE_compare_and_swap_write(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_full(addr, old, new_val)
#   define AO_HAVE_XSIZE_compare_and_swap_write
# endif
# if !defined(AO_HAVE_XSIZE_compare_and_swap_read)
#   define AO_XSIZE_compare_and_swap_read(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_full(addr, old, new_val)
#   define AO_HAVE_XSIZE_compare_and_swap_read
# endif
#endif /* AO_HAVE_XSIZE_compare_and_swap_full */

#if !defined(AO_HAVE_XSIZE_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_release)
# define AO_XSIZE_compare_and_swap(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_release(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap
#endif
#if !defined(AO_HAVE_XSIZE_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_acquire)
# define AO_XSIZE_compare_and_swap(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_acquire(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap
#endif
#if !defined(AO_HAVE_XSIZE_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_write)
# define AO_XSIZE_compare_and_swap(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_write(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap
#endif
#if !defined(AO_HAVE_XSIZE_compare_and_swap) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_read)
# define AO_XSIZE_compare_and_swap(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_read(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_acquire) \
    && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_compare_and_swap_full)
# define AO_XSIZE_compare_and_swap_full(addr, old, new_val) \
                (AO_nop_full(), \
                 AO_XSIZE_compare_and_swap_acquire(addr, old, new_val))
# define AO_HAVE_XSIZE_compare_and_swap_full
#endif

#if !defined(AO_HAVE_XSIZE_compare_and_swap_release_write) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_write)
# define AO_XSIZE_compare_and_swap_release_write(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_write(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap_release_write
#endif
#if !defined(AO_HAVE_XSIZE_compare_and_swap_release_write) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_release)
# define AO_XSIZE_compare_and_swap_release_write(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_release(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap_release_write
#endif
#if !defined(AO_HAVE_XSIZE_compare_and_swap_acquire_read) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_read)
# define AO_XSIZE_compare_and_swap_acquire_read(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_read(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap_acquire_read
#endif
#if !defined(AO_HAVE_XSIZE_compare_and_swap_acquire_read) \
    && defined(AO_HAVE_XSIZE_compare_and_swap_acquire)
# define AO_XSIZE_compare_and_swap_acquire_read(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_acquire(addr, old, new_val)
# define AO_HAVE_XSIZE_compare_and_swap_acquire_read
#endif

#ifdef AO_NO_DD_ORDERING
# if defined(AO_HAVE_XSIZE_compare_and_swap_acquire_read)
#   define AO_XSIZE_compare_and_swap_dd_acquire_read(addr, old, new_val) \
                AO_XSIZE_compare_and_swap_acquire_read(addr, old, new_val)
#   define AO_HAVE_XSIZE_compare_and_swap_dd_acquire_read
# endif
#else
# if defined(AO_HAVE_XSIZE_compare_and_swap)
#   define AO_XSIZE_compare_and_swap_dd_acquire_read(addr, old, new_val) \
                AO_XSIZE_compare_and_swap(addr, old, new_val)
#   define AO_HAVE_XSIZE_compare_and_swap_dd_acquire_read
# endif
#endif /* !AO_NO_DD_ORDERING */

/* XSIZE_load */
#if defined(AO_HAVE_XSIZE_load_full) && !defined(AO_HAVE_XSIZE_load_acquire)
# define AO_XSIZE_load_acquire(addr) AO_XSIZE_load_full(addr)
# define AO_HAVE_XSIZE_load_acquire
#endif

#if defined(AO_HAVE_XSIZE_load_acquire) && !defined(AO_HAVE_XSIZE_load)
# define AO_XSIZE_load(addr) AO_XSIZE_load_acquire(addr)
# define AO_HAVE_XSIZE_load
#endif

#if defined(AO_HAVE_XSIZE_load_full) && !defined(AO_HAVE_XSIZE_load_read)
# define AO_XSIZE_load_read(addr) AO_XSIZE_load_full(addr)
# define AO_HAVE_XSIZE_load_read
#endif

#if !defined(AO_HAVE_XSIZE_load_acquire_read) \
    && defined(AO_HAVE_XSIZE_load_acquire)
# define AO_XSIZE_load_acquire_read(addr) AO_XSIZE_load_acquire(addr)
# define AO_HAVE_XSIZE_load_acquire_read
#endif

#if defined(AO_HAVE_XSIZE_load) && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_load_acquire)
  AO_INLINE XCTYPE
  AO_XSIZE_load_acquire(const volatile XCTYPE *addr)
  {
    XCTYPE result = AO_XSIZE_load(addr);

    /* Acquire barrier would be useless, since the load could be delayed    */
    /* beyond it.                                                           */
    AO_nop_full();
    return result;
  }
# define AO_HAVE_XSIZE_load_acquire
#endif

#if defined(AO_HAVE_XSIZE_load) && defined(AO_HAVE_nop_read) \
    && !defined(AO_HAVE_XSIZE_load_read)
  AO_INLINE XCTYPE
  AO_XSIZE_load_read(const volatile XCTYPE *addr)
  {
    XCTYPE result = AO_XSIZE_load(addr);

    AO_nop_read();
    return result;
  }
# define AO_HAVE_XSIZE_load_read
#endif

#if defined(AO_HAVE_XSIZE_load_acquire) && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_load_full)
# define AO_XSIZE_load_full(addr) (AO_nop_full(), AO_XSIZE_load_acquire(addr))
# define AO_HAVE_XSIZE_load_full
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_read) \
    && !defined(AO_HAVE_XSIZE_load_read)
# define AO_XSIZE_CAS_BASED_LOAD_READ
  AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE XCTYPE
  AO_XSIZE_load_read(const volatile XCTYPE *addr)
  {
    XCTYPE result;

    do {
      result = *(const XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap_read(
                                                (volatile XCTYPE *)addr,
                                                result, result)));
    return result;
  }
# define AO_HAVE_XSIZE_load_read
#endif

#if !defined(AO_HAVE_XSIZE_load_acquire_read) \
    && defined(AO_HAVE_XSIZE_load_read)
# define AO_XSIZE_load_acquire_read(addr) AO_XSIZE_load_read(addr)
# define AO_HAVE_XSIZE_load_acquire_read
#endif

#if defined(AO_HAVE_XSIZE_load_acquire_read) && !defined(AO_HAVE_XSIZE_load) \
    && (!defined(AO_XSIZE_CAS_BASED_LOAD_READ) \
        || !defined(AO_HAVE_XSIZE_compare_and_swap))
# define AO_XSIZE_load(addr) AO_XSIZE_load_acquire_read(addr)
# define AO_HAVE_XSIZE_load
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_full) \
    && !defined(AO_HAVE_XSIZE_load_full)
  AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE XCTYPE
  AO_XSIZE_load_full(const volatile XCTYPE *addr)
  {
    XCTYPE result;

    do {
      result = *(const XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap_full(
                                                (volatile XCTYPE *)addr,
                                                result, result)));
    return result;
  }
# define AO_HAVE_XSIZE_load_full
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_acquire) \
    && !defined(AO_HAVE_XSIZE_load_acquire)
  AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE XCTYPE
  AO_XSIZE_load_acquire(const volatile XCTYPE *addr)
  {
    XCTYPE result;

    do {
      result = *(const XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap_acquire(
                                                (volatile XCTYPE *)addr,
                                                result, result)));
    return result;
  }
# define AO_HAVE_XSIZE_load_acquire
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap) && !defined(AO_HAVE_XSIZE_load)
  AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE XCTYPE
  AO_XSIZE_load(const volatile XCTYPE *addr)
  {
    XCTYPE result;

    do {
      result = *(const XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap(
                                                (volatile XCTYPE *)addr,
                                                result, result)));
    return result;
  }
# define AO_HAVE_XSIZE_load
#endif

#ifdef AO_NO_DD_ORDERING
# if defined(AO_HAVE_XSIZE_load_acquire_read)
#   define AO_XSIZE_load_dd_acquire_read(addr) \
                                AO_XSIZE_load_acquire_read(addr)
#   define AO_HAVE_XSIZE_load_dd_acquire_read
# endif
#else
# if defined(AO_HAVE_XSIZE_load)
#   define AO_XSIZE_load_dd_acquire_read(addr) AO_XSIZE_load(addr)
#   define AO_HAVE_XSIZE_load_dd_acquire_read
# endif
#endif /* !AO_NO_DD_ORDERING */

/* XSIZE_store */
#if defined(AO_HAVE_XSIZE_store_full) && !defined(AO_HAVE_XSIZE_store_release)
# define AO_XSIZE_store_release(addr, val) AO_XSIZE_store_full(addr, val)
# define AO_HAVE_XSIZE_store_release
#endif

#if defined(AO_HAVE_XSIZE_store_release) && !defined(AO_HAVE_XSIZE_store)
# define AO_XSIZE_store(addr, val) AO_XSIZE_store_release(addr, val)
# define AO_HAVE_XSIZE_store
#endif

#if defined(AO_HAVE_XSIZE_store_full) && !defined(AO_HAVE_XSIZE_store_write)
# define AO_XSIZE_store_write(addr, val) AO_XSIZE_store_full(addr, val)
# define AO_HAVE_XSIZE_store_write
#endif

#if defined(AO_HAVE_XSIZE_store_release) \
    && !defined(AO_HAVE_XSIZE_store_release_write)
# define AO_XSIZE_store_release_write(addr, val) \
                                AO_XSIZE_store_release(addr, val)
# define AO_HAVE_XSIZE_store_release_write
#endif

#if defined(AO_HAVE_XSIZE_store_write) && !defined(AO_HAVE_XSIZE_store)
# define AO_XSIZE_store(addr, val) AO_XSIZE_store_write(addr, val)
# define AO_HAVE_XSIZE_store
#endif

#if defined(AO_HAVE_XSIZE_store) && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_store_release)
# define AO_XSIZE_store_release(addr, val) \
                                (AO_nop_full(), AO_XSIZE_store(addr, val))
# define AO_HAVE_XSIZE_store_release
#endif

#if defined(AO_HAVE_XSIZE_store) && defined(AO_HAVE_nop_write) \
    && !defined(AO_HAVE_XSIZE_store_write)
# define AO_XSIZE_store_write(addr, val) \
                                (AO_nop_write(), AO_XSIZE_store(addr, val))
# define AO_HAVE_XSIZE_store_write
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_write) \
    && !defined(AO_HAVE_XSIZE_store_write)
  AO_ATTR_NO_SANITIZE_MEMORY AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE void
  AO_XSIZE_store_write(volatile XCTYPE *addr, XCTYPE new_val)
  {
    XCTYPE old_val;

    do {
      old_val = *(XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap_write(addr, old_val,
                                                              new_val)));
  }
# define AO_HAVE_XSIZE_store_write
#endif

#if defined(AO_HAVE_XSIZE_store_write) \
    && !defined(AO_HAVE_XSIZE_store_release_write)
# define AO_XSIZE_store_release_write(addr, val) \
                                AO_XSIZE_store_write(addr, val)
# define AO_HAVE_XSIZE_store_release_write
#endif

#if defined(AO_HAVE_XSIZE_store_release) && defined(AO_HAVE_nop_full) \
    && !defined(AO_HAVE_XSIZE_store_full)
# define AO_XSIZE_store_full(addr, val) \
                                (AO_XSIZE_store_release(addr, val), \
                                 AO_nop_full())
# define AO_HAVE_XSIZE_store_full
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap) && !defined(AO_HAVE_XSIZE_store)
  AO_ATTR_NO_SANITIZE_MEMORY AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE void
  AO_XSIZE_store(volatile XCTYPE *addr, XCTYPE new_val)
  {
    XCTYPE old_val;

    do {
      old_val = *(XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap(addr,
                                                        old_val, new_val)));
  }
# define AO_HAVE_XSIZE_store
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_release) \
    && !defined(AO_HAVE_XSIZE_store_release)
  AO_ATTR_NO_SANITIZE_MEMORY AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE void
  AO_XSIZE_store_release(volatile XCTYPE *addr, XCTYPE new_val)
  {
    XCTYPE old_val;

    do {
      old_val = *(XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap_release(addr, old_val,
                                                                new_val)));
  }
# define AO_HAVE_XSIZE_store_release
#endif

#if defined(AO_HAVE_XSIZE_compare_and_swap_full) \
    && !defined(AO_HAVE_XSIZE_store_full)
  AO_ATTR_NO_SANITIZE_MEMORY AO_ATTR_NO_SANITIZE_THREAD
  AO_INLINE void
  AO_XSIZE_store_full(volatile XCTYPE *addr, XCTYPE new_val)
  {
    XCTYPE old_val;

    do {
      old_val = *(XCTYPE *)addr;
    } while (AO_EXPECT_FALSE(!AO_XSIZE_compare_and_swap_full(addr, old_val,
                                                             new_val)));
  }
# define AO_HAVE_XSIZE_store_full
#endif
