1
/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2
This file is part of the GNU C Library.
4
The GNU C Library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
The GNU C Library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public
15
License along with the GNU C Library. If not, see
16
<http://www.gnu.org/licenses/>. */
21
typedef int8_t atomic8_t;
22
typedef uint8_t uatomic8_t;
23
typedef int_fast8_t atomic_fast8_t;
24
typedef uint_fast8_t uatomic_fast8_t;
26
typedef int32_t atomic32_t;
27
typedef uint32_t uatomic32_t;
28
typedef int_fast32_t atomic_fast32_t;
29
typedef uint_fast32_t uatomic_fast32_t;
31
typedef intptr_t atomicptr_t;
32
typedef uintptr_t uatomicptr_t;
33
typedef intmax_t atomic_max_t;
34
typedef uintmax_t uatomic_max_t;
36
void __arm_link_error (void);
38
/* Use the atomic builtins provided by GCC in case the backend provides
39
a pattern to do this efficiently. */
41
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
42
#define atomic_full_barrier() __sync_synchronize ()
43
#elif defined __thumb2__
44
#define atomic_full_barrier() \
45
__asm__ __volatile__ \
46
("movw\tip, #0x0fa0\n\t" \
47
"movt\tip, #0xffff\n\t" \
49
: : : "ip", "lr", "cc", "memory");
51
#define atomic_full_barrier() \
52
__asm__ __volatile__ \
53
("mov\tip, #0xffff0fff\n\t" \
55
"add\tpc, ip, #(0xffff0fa0 - 0xffff0fff)" \
56
: : : "ip", "lr", "cc", "memory");
59
/* Atomic compare and exchange. This sequence relies on the kernel to
60
provide a compare and exchange operation which is atomic on the
61
current architecture, either via cleverness on pre-ARMv6 or via
62
ldrex / strex on ARMv6. */
64
#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
65
({ __arm_link_error (); oldval; })
67
#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
68
({ __arm_link_error (); oldval; })
70
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
71
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
72
__sync_val_compare_and_swap ((mem), (oldval), (newval))
74
/* It doesn't matter what register is used for a_oldval2, but we must
75
specify one to work around GCC PR rtl-optimization/21223. Otherwise
76
it may cause a_oldval or a_tmp to be moved to a different register. */
78
#elif defined __thumb2__
79
/* Thumb-2 has ldrex/strex. However it does not have barrier instructions,
80
so we still need to use the kernel helper. */
81
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
82
({ register __typeof (oldval) a_oldval asm ("r0"); \
83
register __typeof (oldval) a_newval asm ("r1") = (newval); \
84
register __typeof (mem) a_ptr asm ("r2") = (mem); \
85
register __typeof (oldval) a_tmp asm ("r3"); \
86
register __typeof (oldval) a_oldval2 asm ("r4") = (oldval); \
87
__asm__ __volatile__ \
88
("0:\tldr\t%[tmp],[%[ptr]]\n\t" \
89
"cmp\t%[tmp], %[old2]\n\t" \
91
"mov\t%[old], %[old2]\n\t" \
92
"movw\t%[tmp], #0x0fc0\n\t" \
93
"movt\t%[tmp], #0xffff\n\t" \
96
"mov\t%[tmp], %[old2]\n\t" \
98
: [old] "=&r" (a_oldval), [tmp] "=&r" (a_tmp) \
99
: [new] "r" (a_newval), [ptr] "r" (a_ptr), \
100
[old2] "r" (a_oldval2) \
101
: "ip", "lr", "cc", "memory"); \
104
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
105
({ register __typeof (oldval) a_oldval asm ("r0"); \
106
register __typeof (oldval) a_newval asm ("r1") = (newval); \
107
register __typeof (mem) a_ptr asm ("r2") = (mem); \
108
register __typeof (oldval) a_tmp asm ("r3"); \
109
register __typeof (oldval) a_oldval2 asm ("r4") = (oldval); \
110
__asm__ __volatile__ \
111
("0:\tldr\t%[tmp],[%[ptr]]\n\t" \
112
"cmp\t%[tmp], %[old2]\n\t" \
114
"mov\t%[old], %[old2]\n\t" \
115
"mov\t%[tmp], #0xffff0fff\n\t" \
117
"add\tpc, %[tmp], #(0xffff0fc0 - 0xffff0fff)\n\t" \
119
"mov\t%[tmp], %[old2]\n\t" \
121
: [old] "=&r" (a_oldval), [tmp] "=&r" (a_tmp) \
122
: [new] "r" (a_newval), [ptr] "r" (a_ptr), \
123
[old2] "r" (a_oldval2) \
124
: "ip", "lr", "cc", "memory"); \
128
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
129
({ __arm_link_error (); oldval; })