Imported and merged Boehm GC 7.0
[cacao.git] / src / mm / boehm-gc / libatomic_ops-1.2 / src / atomic_ops / sysdeps / gcc / arm.h
1 /* 
2  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
3  * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
4  * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved.
5  *
6  *
7  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
9  *
10  * Permission is hereby granted to use or copy this program
11  * for any purpose,  provided the above notices are retained on all copies.
12  * Permission to modify the code and to distribute modified code is granted,
13  * provided the above notices are retained, and a notice that the code was
14  * modified is included with the above copyright notice.
15  *
16  */
17
18 /* There exist multiprocessor SoC ARM processors, so this matters.      */
19 /* This needs to be augmented for later ARM (e.g. V7) procesors.        */
20
21 /* I found a slide set that, if I read it correctly, claims that        */
22 /* Loads followed by either a Load or Store are ordered, but nothing    */
23 /* else is.                                                             */
24 /* It appears that SWP is the only simple memory barrier.               */
25 #include "../all_atomic_load_store.h"
26
27 #include "../read_ordered.h"
28
29 #include "../test_and_set_t_is_ao_t.h" /* Probably suboptimal */
30
31
32 AO_INLINE AO_TS_VAL_t
33 AO_test_and_set_full(volatile AO_TS_t *addr) {
34   AO_TS_VAL_t oldval;
35   /* SWP on ARM is very similar to XCHG on x86.                 */
36   /* The first operand is the result, the second the value      */
37   /* to be stored.  Both registers must be different from addr. */
38   /* Make the address operand an early clobber output so it     */
39   /* doesn't overlap with the other operands.  The early clobber*/
40   /* on oldval is neccessary to prevent the compiler allocating */
41   /* them to the same register if they are both unused.         */
42   __asm__ __volatile__("swp %0, %2, [%3]"
43                         : "=&r"(oldval), "=&r"(addr)
44                         : "r"(1), "1"(addr)
45                         : "memory");
46   return oldval;
47 }
48
49 #define AO_HAVE_test_and_set_full
50
51
52