Blame sysdeps/ia64/atomic-machine.h

Packit 6c4009
/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <ia64intrin.h>
Packit 6c4009
Packit 6c4009
typedef int8_t atomic8_t;
Packit 6c4009
typedef uint8_t uatomic8_t;
Packit 6c4009
typedef int_fast8_t atomic_fast8_t;
Packit 6c4009
typedef uint_fast8_t uatomic_fast8_t;
Packit 6c4009
Packit 6c4009
typedef int16_t atomic16_t;
Packit 6c4009
typedef uint16_t uatomic16_t;
Packit 6c4009
typedef int_fast16_t atomic_fast16_t;
Packit 6c4009
typedef uint_fast16_t uatomic_fast16_t;
Packit 6c4009
Packit 6c4009
typedef int32_t atomic32_t;
Packit 6c4009
typedef uint32_t uatomic32_t;
Packit 6c4009
typedef int_fast32_t atomic_fast32_t;
Packit 6c4009
typedef uint_fast32_t uatomic_fast32_t;
Packit 6c4009
Packit 6c4009
typedef int64_t atomic64_t;
Packit 6c4009
typedef uint64_t uatomic64_t;
Packit 6c4009
typedef int_fast64_t atomic_fast64_t;
Packit 6c4009
typedef uint_fast64_t uatomic_fast64_t;
Packit 6c4009
Packit 6c4009
typedef intptr_t atomicptr_t;
Packit 6c4009
typedef uintptr_t uatomicptr_t;
Packit 6c4009
typedef intmax_t atomic_max_t;
Packit 6c4009
typedef uintmax_t uatomic_max_t;
Packit 6c4009
Packit 6c4009
#define __HAVE_64B_ATOMICS 1
Packit 6c4009
#define USE_ATOMIC_COMPILER_BUILTINS 0
Packit 6c4009
Packit 6c4009
/* XXX Is this actually correct?  */
Packit 6c4009
#define ATOMIC_EXCHANGE_USES_CAS 0
Packit 6c4009
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
Packit 6c4009
  (abort (), 0)
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \
Packit 6c4009
  (abort (), 0)
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
Packit 6c4009
  (!__sync_bool_compare_and_swap ((mem), (int) (long) (oldval), \
Packit 6c4009
				  (int) (long) (newval)))
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
Packit 6c4009
  (!__sync_bool_compare_and_swap ((mem), (long) (oldval), \
Packit 6c4009
				  (long) (newval)))
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
Packit 6c4009
  (abort (), (__typeof (*mem)) 0)
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
Packit 6c4009
  (abort (), (__typeof (*mem)) 0)
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
Packit 6c4009
  __sync_val_compare_and_swap ((mem), (int) (long) (oldval), \
Packit 6c4009
			       (int) (long) (newval))
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
Packit 6c4009
  __sync_val_compare_and_swap ((mem), (long) (oldval), (long) (newval))
Packit 6c4009
Packit 6c4009
/* Atomically store newval and return the old value.  */
Packit 6c4009
#define atomic_exchange_acq(mem, value) \
Packit 6c4009
  __sync_lock_test_and_set (mem, value)
Packit 6c4009
Packit 6c4009
#define atomic_exchange_rel(mem, value) \
Packit 6c4009
  (__sync_synchronize (), __sync_lock_test_and_set (mem, value))
Packit 6c4009
Packit 6c4009
#define atomic_exchange_and_add(mem, value) \
Packit 6c4009
  __sync_fetch_and_add ((mem), (value))
Packit 6c4009
Packit 6c4009
#define atomic_decrement_if_positive(mem) \
Packit 6c4009
  ({ __typeof (*mem) __oldval, __val;					      \
Packit 6c4009
     __typeof (mem) __memp = (mem);					      \
Packit 6c4009
									      \
Packit 6c4009
     __val = (*__memp);							      \
Packit 6c4009
     do									      \
Packit 6c4009
       {								      \
Packit 6c4009
	 __oldval = __val;						      \
Packit 6c4009
	 if (__builtin_expect (__val <= 0, 0))				      \
Packit 6c4009
	   break;							      \
Packit 6c4009
	 __val = atomic_compare_and_exchange_val_acq (__memp,	__oldval - 1, \
Packit 6c4009
						      __oldval);	      \
Packit 6c4009
       }								      \
Packit 6c4009
     while (__builtin_expect (__val != __oldval, 0));			      \
Packit 6c4009
     __oldval; })
Packit 6c4009
Packit 6c4009
#define atomic_bit_test_set(mem, bit) \
Packit 6c4009
  ({ __typeof (*mem) __oldval, __val;					      \
Packit 6c4009
     __typeof (mem) __memp = (mem);					      \
Packit 6c4009
     __typeof (*mem) __mask = ((__typeof (*mem)) 1 << (bit));		      \
Packit 6c4009
									      \
Packit 6c4009
     __val = (*__memp);							      \
Packit 6c4009
     do									      \
Packit 6c4009
       {								      \
Packit 6c4009
	 __oldval = __val;						      \
Packit 6c4009
	 __val = atomic_compare_and_exchange_val_acq (__memp,		      \
Packit 6c4009
						      __oldval | __mask,      \
Packit 6c4009
						      __oldval);	      \
Packit 6c4009
       }								      \
Packit 6c4009
     while (__builtin_expect (__val != __oldval, 0));			      \
Packit 6c4009
     __oldval & __mask; })
Packit 6c4009
Packit 6c4009
#define atomic_full_barrier() __sync_synchronize ()