]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/hppa/atomic-machine.h
2302c1fe124abcc45faca1e40576b3adde4718ae
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / hppa / atomic-machine.h
1 /* Copyright (C) 2003-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2005.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <stdint.h> /* Required for type definitions e.g. uint8_t. */
20
21 #ifndef _ATOMIC_MACHINE_H
22 #define _ATOMIC_MACHINE_H 1
23
24 typedef int8_t atomic8_t;
25 typedef uint8_t uatomic8_t;
26 typedef int_fast8_t atomic_fast8_t;
27 typedef uint_fast8_t uatomic_fast8_t;
28
29 typedef int32_t atomic32_t;
30 typedef uint32_t uatomic32_t;
31 typedef int_fast32_t atomic_fast32_t;
32 typedef uint_fast32_t uatomic_fast32_t;
33
34 typedef intptr_t atomicptr_t;
35 typedef uintptr_t uatomicptr_t;
36 typedef intmax_t atomic_max_t;
37 typedef uintmax_t uatomic_max_t;
38
39 #define __HAVE_64B_ATOMICS 0
40 #define USE_ATOMIC_COMPILER_BUILTINS 0
41
42 /* XXX Is this actually correct? */
43 #define ATOMIC_EXCHANGE_USES_CAS 1
44
45 /* prev = *addr;
46 if (prev == old)
47 *addr = new;
48 return prev; */
49
50 /* Use the kernel atomic light weight syscalls on hppa. */
51 #define _LWS "0xb0"
52 #define _LWS_CAS "0"
53 /* Note r31 is the link register. */
54 #define _LWS_CLOBBER "r1", "r23", "r22", "r20", "r31", "memory"
55 /* String constant for -EAGAIN. */
56 #define _ASM_EAGAIN "-11"
57 /* String constant for -EDEADLOCK. */
58 #define _ASM_EDEADLOCK "-45"
59
60 /* The only basic operation needed is compare and exchange. The mem
61 pointer must be word aligned. We no longer loop on deadlock. */
62 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
63 ({ \
64 register long lws_errno asm("r21"); \
65 register unsigned long lws_ret asm("r28"); \
66 register unsigned long lws_mem asm("r26") = (unsigned long)(mem); \
67 register unsigned long lws_old asm("r25") = (unsigned long)(oldval);\
68 register unsigned long lws_new asm("r24") = (unsigned long)(newval);\
69 __asm__ __volatile__( \
70 "0: \n\t" \
71 "ble " _LWS "(%%sr2, %%r0) \n\t" \
72 "ldi " _LWS_CAS ", %%r20 \n\t" \
73 "cmpiclr,<> " _ASM_EAGAIN ", %%r21, %%r0\n\t" \
74 "b,n 0b \n\t" \
75 "cmpclr,= %%r0, %%r21, %%r0 \n\t" \
76 "iitlbp %%r0,(%%sr0, %%r0) \n\t" \
77 : "=r" (lws_ret), "=r" (lws_errno) \
78 : "r" (lws_mem), "r" (lws_old), "r" (lws_new) \
79 : _LWS_CLOBBER \
80 ); \
81 \
82 (__typeof (oldval)) lws_ret; \
83 })
84
85 #define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
86 ({ \
87 __typeof__ (*mem) ret; \
88 ret = atomic_compare_and_exchange_val_acq(mem, newval, oldval); \
89 /* Return 1 if it was already acquired. */ \
90 (ret != oldval); \
91 })
92
93 #endif
94 /* _ATOMIC_MACHINE_H */