hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame sysdeps/sparc/sparc64/atomic-machine.h

Packit 6c4009
/* Atomic operations.  sparc64 version.
Packit 6c4009
   Copyright (C) 2003-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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
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 1
Packit 6c4009
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
({									      \
Packit 6c4009
  __typeof (*(mem)) __acev_tmp;						      \
Packit 6c4009
  __typeof (mem) __acev_mem = (mem);					      \
Packit 6c4009
  if (__builtin_constant_p (oldval) && (oldval) == 0)			      \
Packit 6c4009
    __asm __volatile ("cas [%3], %%g0, %0"				      \
Packit 6c4009
		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
Packit 6c4009
		      : "m" (*__acev_mem), "r" (__acev_mem),		      \
Packit 6c4009
		        "0" (newval) : "memory");			      \
Packit 6c4009
  else									      \
Packit 6c4009
    __asm __volatile ("cas [%4], %2, %0"				      \
Packit 6c4009
		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
Packit 6c4009
		      : "r" (oldval), "m" (*__acev_mem), "r" (__acev_mem),    \
Packit 6c4009
		        "0" (newval) : "memory");			      \
Packit 6c4009
  __acev_tmp; })
Packit 6c4009
Packit 6c4009
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
Packit 6c4009
({									      \
Packit 6c4009
  __typeof (*(mem)) __acev_tmp;						      \
Packit 6c4009
  __typeof (mem) __acev_mem = (mem);					      \
Packit 6c4009
  if (__builtin_constant_p (oldval) && (oldval) == 0)			      \
Packit 6c4009
    __asm __volatile ("casx [%3], %%g0, %0"				      \
Packit 6c4009
		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
Packit 6c4009
		      : "m" (*__acev_mem), "r" (__acev_mem),		      \
Packit 6c4009
		        "0" ((long) (newval)) : "memory");		      \
Packit 6c4009
  else									      \
Packit 6c4009
    __asm __volatile ("casx [%4], %2, %0"				      \
Packit 6c4009
		      : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
Packit 6c4009
		      : "r" ((long) (oldval)), "m" (*__acev_mem),	      \
Packit 6c4009
		        "r" (__acev_mem), "0" ((long) (newval)) : "memory");  \
Packit 6c4009
  __acev_tmp; })
Packit 6c4009
Packit 6c4009
#define atomic_exchange_acq(mem, newvalue) \
Packit 6c4009
  ({ __typeof (*(mem)) __oldval, __val;					      \
Packit 6c4009
     __typeof (mem) __memp = (mem);					      \
Packit 6c4009
     __typeof (*(mem)) __value = (newvalue);				      \
Packit 6c4009
									      \
Packit 6c4009
     if (sizeof (*(mem)) == 4)						      \
Packit 6c4009
       __asm ("swap %0, %1"						      \
Packit 6c4009
	      : "=m" (*__memp), "=r" (__oldval)				      \
Packit 6c4009
	      : "m" (*__memp), "1" (__value) : "memory");		      \
Packit 6c4009
     else								      \
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, __value,    \
Packit 6c4009
							  __oldval);	      \
Packit 6c4009
	   }								      \
Packit 6c4009
         while (__builtin_expect (__val != __oldval, 0));		      \
Packit 6c4009
       }								      \
Packit 6c4009
     __oldval; })
Packit 6c4009
Packit 6c4009
#define atomic_compare_and_exchange_val_24_acq(mem, newval, oldval) \
Packit 6c4009
  atomic_compare_and_exchange_val_acq (mem, newval, oldval)
Packit 6c4009
Packit 6c4009
#define atomic_exchange_24_rel(mem, newval) \
Packit 6c4009
  atomic_exchange_rel (mem, newval)
Packit 6c4009
Packit 6c4009
#define atomic_full_barrier() \
Packit 6c4009
  __asm __volatile ("membar #LoadLoad | #LoadStore"			      \
Packit 6c4009
			  " | #StoreLoad | #StoreStore" : : : "memory")
Packit 6c4009
#define atomic_read_barrier() \
Packit 6c4009
  __asm __volatile ("membar #LoadLoad | #LoadStore" : : : "memory")
Packit 6c4009
#define atomic_write_barrier() \
Packit 6c4009
  __asm __volatile ("membar #LoadStore | #StoreStore" : : : "memory")
Packit 6c4009
Packit 6c4009
extern void __cpu_relax (void);
Packit 6c4009
#define atomic_spin_nop() __cpu_relax ()