Blame sysdeps/unix/sysv/linux/hppa/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
   Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2005.
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> /*  Required for type definitions e.g. uint8_t.  */
Packit 6c4009
Packit 6c4009
#ifndef _ATOMIC_MACHINE_H
Packit 6c4009
#define _ATOMIC_MACHINE_H	1
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 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 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 0
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
/* prev = *addr;
Packit 6c4009
   if (prev == old)
Packit 6c4009
     *addr = new;
Packit 6c4009
   return prev; */
Packit 6c4009
Packit 6c4009
/* Use the kernel atomic light weight syscalls on hppa.  */
Packit 6c4009
#define _LWS "0xb0"
Packit 6c4009
#define _LWS_CAS "0"
Packit 6c4009
/* Note r31 is the link register.  */
Packit 6c4009
#define _LWS_CLOBBER "r1", "r23", "r22", "r20", "r31", "memory"
Packit 6c4009
/* String constant for -EAGAIN.  */
Packit 6c4009
#define _ASM_EAGAIN "-11"
Packit 6c4009
/* String constant for -EDEADLOCK.  */
Packit 6c4009
#define _ASM_EDEADLOCK "-45"
Packit 6c4009
Packit 6c4009
/* The only basic operation needed is compare and exchange.  The mem
Packit 6c4009
   pointer must be word aligned.  We no longer loop on deadlock.  */
Packit 6c4009
#define atomic_compare_and_exchange_val_acq(mem, newval, oldval)	\
Packit 6c4009
  ({									\
Packit 6c4009
     register long lws_errno asm("r21");				\
Packit 6c4009
     register unsigned long lws_ret asm("r28");				\
Packit 6c4009
     register unsigned long lws_mem asm("r26") = (unsigned long)(mem);	\
Packit 6c4009
     register unsigned long lws_old asm("r25") = (unsigned long)(oldval);\
Packit 6c4009
     register unsigned long lws_new asm("r24") = (unsigned long)(newval);\
Packit 6c4009
     __asm__ __volatile__(						\
Packit 6c4009
	"0:					\n\t"			\
Packit 6c4009
	"ble	" _LWS "(%%sr2, %%r0)		\n\t"			\
Packit 6c4009
	"ldi	" _LWS_CAS ", %%r20		\n\t"			\
Packit 6c4009
	"cmpiclr,<> " _ASM_EAGAIN ", %%r21, %%r0\n\t"			\
Packit 6c4009
	"b,n 0b					\n\t"			\
Packit 6c4009
	"cmpclr,= %%r0, %%r21, %%r0		\n\t"			\
Packit 6c4009
	"iitlbp %%r0,(%%sr0, %%r0)		\n\t"			\
Packit 6c4009
	: "=r" (lws_ret), "=r" (lws_errno)				\
Packit 6c4009
	: "r" (lws_mem), "r" (lws_old), "r" (lws_new)			\
Packit 6c4009
	: _LWS_CLOBBER							\
Packit 6c4009
     );									\
Packit 6c4009
									\
Packit 6c4009
     (__typeof (oldval)) lws_ret;					\
Packit 6c4009
   })
Packit 6c4009
Packit 6c4009
#define atomic_compare_and_exchange_bool_acq(mem, newval, oldval)	\
Packit 6c4009
  ({									\
Packit 6c4009
     __typeof__ (*mem) ret;						\
Packit 6c4009
     ret = atomic_compare_and_exchange_val_acq(mem, newval, oldval);	\
Packit 6c4009
     /* Return 1 if it was already acquired.  */			\
Packit 6c4009
     (ret != oldval);							\
Packit 6c4009
   })
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
/* _ATOMIC_MACHINE_H */