]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2011-2015 Free Software Foundation, Inc. |
63d143a2 CM |
2 | This file is part of the GNU C Library. |
3 | Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. | |
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 | |
ab84e3ff PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
63d143a2 CM |
18 | |
19 | #ifndef _BITS_ATOMIC_H | |
20 | #define _BITS_ATOMIC_H 1 | |
21 | ||
22 | #include <asm/unistd.h> | |
23 | ||
1ea339b6 TR |
24 | #define __HAVE_64B_ATOMICS 0 |
25 | #define USE_ATOMIC_COMPILER_BUILTINS 0 | |
26 | ||
63d143a2 CM |
27 | /* 32-bit integer compare-and-exchange. */ |
28 | static __inline __attribute__ ((always_inline)) | |
29 | int __atomic_cmpxchg_32 (volatile int *mem, int newval, int oldval) | |
30 | { | |
31 | int result; | |
32 | __asm__ __volatile__ ("swint1" | |
33 | : "=R00" (result), "=m" (*mem) | |
34 | : "R10" (__NR_FAST_cmpxchg), "R00" (mem), | |
35 | "R01" (oldval), "R02" (newval), "m" (*mem) | |
36 | : "r20", "r21", "r22", "r23", "r24", | |
37 | "r25", "r26", "r27", "r28", "r29", "memory"); | |
38 | return result; | |
39 | } | |
40 | ||
41 | #define atomic_compare_and_exchange_val_acq(mem, n, o) \ | |
42 | ((__typeof (*(mem))) \ | |
43 | ((sizeof (*(mem)) == 4) ? \ | |
44 | __atomic_cmpxchg_32 ((int *) (mem), (int) (n), (int) (o)) : \ | |
45 | __atomic_error_bad_argument_size())) | |
46 | ||
47 | /* Atomically compute: | |
48 | int old = *ptr; | |
49 | *ptr = (old & mask) + addend; | |
50 | return old; */ | |
51 | ||
52 | static __inline __attribute__ ((always_inline)) | |
53 | int __atomic_update_32 (volatile int *mem, int mask, int addend) | |
54 | { | |
55 | int result; | |
56 | __asm__ __volatile__ ("swint1" | |
57 | : "=R00" (result), "=m" (*mem) | |
58 | : "R10" (__NR_FAST_atomic_update), "R00" (mem), | |
59 | "R01" (mask), "R02" (addend), "m" (*mem) | |
60 | : "r20", "r21", "r22", "r23", "r24", | |
61 | "r25", "r26", "r27", "r28", "r29", "memory"); | |
62 | return result; | |
63 | } | |
64 | ||
65 | /* Size-checked verson of __atomic_update_32. */ | |
66 | #define __atomic_update(mem, mask, addend) \ | |
67 | ((__typeof (*(mem))) \ | |
68 | ((sizeof (*(mem)) == 4) ? \ | |
69 | __atomic_update_32 ((int *) (mem), (int) (mask), (int) (addend)) : \ | |
70 | __atomic_error_bad_argument_size ())) | |
71 | ||
72 | #define atomic_exchange_acq(mem, newvalue) \ | |
73 | __atomic_update ((mem), 0, (newvalue)) | |
74 | #define atomic_exchange_and_add(mem, value) \ | |
75 | __atomic_update ((mem), -1, (value)) | |
76 | #define atomic_and_val(mem, mask) \ | |
77 | __atomic_update ((mem), (mask), 0) | |
78 | #define atomic_or_val(mem, mask) \ | |
79 | ({ __typeof (mask) __att1_v = (mask); \ | |
80 | __atomic_update ((mem), ~__att1_v, __att1_v); }) | |
81 | ||
82 | #include <sysdeps/tile/bits/atomic.h> | |
83 | ||
84 | #endif /* bits/atomic.h */ |