]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/config/cpu/arm/atomicity.h
libstdc++-v3: New directory.
[thirdparty/gcc.git] / libstdc++-v3 / config / cpu / arm / atomicity.h
1 /* Low-level functions for atomic operations. ARM version.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #ifndef _ATOMICITY_H
21 #define _ATOMICITY_H 1
22
23 #ifdef _GLIBCPP_HAVE_INTTYPES_H
24 #include <inttypes.h>
25 #else
26 typedef unsigned int uint32_t;
27 typedef int int32_t;
28 #endif
29
30 static inline int
31 __attribute__ ((unused))
32 exchange_and_add (volatile uint32_t *mem, int val)
33 {
34 int tmp, tmp2, result;
35 __asm__ ("\
36 0: ldr %0,[%3]
37 add %1,%0,%4
38 swp %2,%1,[%3]
39 cmp %0,%2
40 swpne %1,%2,[%3]
41 bne 0b
42 " : "=&r"(result), "=&r"(tmp), "=&r"(tmp2) : "r" (mem), "r"(val) : "cc", "memory");
43 return result;
44 }
45
46 static inline void
47 __attribute__ ((unused))
48 atomic_add (volatile uint32_t *mem, int val)
49 {
50 int tmp, tmp2, tmp3;
51 __asm__ ("\
52 0: ldr %0,[%3]
53 add %1,%0,%4
54 swp %2,%1,[%3]
55 cmp %0,%2
56 swpne %1,%2,[%3]
57 bne 0b
58 " : "=&r"(tmp), "=&r"(tmp2), "=&r"(tmp3) : "r" (mem), "r"(val) : "cc", "memory");
59 }
60
61 static inline int
62 __attribute__ ((unused))
63 compare_and_swap (volatile long int *p, long int oldval, long int newval)
64 {
65 int result, tmp;
66 __asm__ ("\
67 0: ldr %1,[%2]
68 mov %0,#0
69 cmp %1,%4
70 bne 1f
71 swp %0,%3,[%2]
72 cmp %1,%0
73 swpne %1,%0,[%2]
74 bne 0b
75 mov %0,#1
76 1:
77 " : "=&r"(result), "=&r"(tmp) : "r" (p), "r" (newval), "r" (oldval) : "cc", "memory");
78 }
79
80 static inline long int
81 __attribute__ ((unused))
82 always_swap (volatile long int *p, long int newval)
83 {
84 long int result;
85 __asm__ ("\
86 swp %0,%2,[%1]
87 " : "=&r"(result) : "r"(p), "r"(newval) : "memory");
88 return result;
89 }
90
91 static inline int
92 __attribute__ ((unused))
93 test_and_set (volatile long int *p, long int newval)
94 {
95 int result, tmp, tmp2, tmp3;
96 __asm__ ("\
97 0: ldr %0,[%2]
98 cmp %0,#0
99 bne 1f
100 swp %1,%3,[%2]
101 cmp %0,%1
102 swpne %0,%1,[%2]
103 bne 0b
104 1:
105 " : "=&r"(result), "=r" (tmp) : "r"(p), "r"(newval) : "cc", "memory");
106 return result;
107 }
108
109 #endif /* atomicity.h */