implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / libatomic_ops / src / atomic_ops / sysdeps / msftc / arm.h
1 /*
2  * Copyright (c) 2003 Hewlett-Packard Development Company, L.P.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 #include "../read_ordered.h"
24
25 #ifndef AO_ASSUME_WINDOWS98
26   /* CAS is always available */
27 # define AO_ASSUME_WINDOWS98
28 #endif
29 #include "common32_defs.h"
30 /* FIXME: Do _InterlockedOps really have a full memory barrier?         */
31 /* (MSDN WinCE docs say nothing about it.)                              */
32
33 #if _M_ARM >= 6
34 /* ARMv6 is the first architecture providing support for simple LL/SC.  */
35
36 #include "../standard_ao_double_t.h"
37
38 /* If only a single processor is used, we can define AO_UNIPROCESSOR    */
39 /* and do not need to access CP15 for ensuring a DMB at all.            */
40 #ifdef AO_UNIPROCESSOR
41   AO_INLINE void AO_nop_full(void) {}
42 # define AO_HAVE_nop_full
43 #else
44 /* AO_nop_full() is emulated using AO_test_and_set_full().              */
45 #endif
46
47 #include "../test_and_set_t_is_ao_t.h"
48 /* AO_test_and_set() is emulated using CAS.                             */
49
50 AO_INLINE AO_t
51 AO_load(const volatile AO_t *addr)
52 {
53   /* Cast away the volatile in case it adds fence semantics */
54   return (*(const AO_t *)addr);
55 }
56 #define AO_HAVE_load
57
58 AO_INLINE void
59 AO_store_full(volatile AO_t *addr, AO_t value)
60 {
61   /* Emulate atomic store using CAS.    */
62   AO_t old = AO_load(addr);
63   AO_t current;
64 # ifdef AO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE
65     while ((current = (AO_t)_InterlockedCompareExchange(
66                                 (PVOID AO_INTERLOCKED_VOLATILE *)addr,
67                                 (PVOID)value, (PVOID)old)) != old)
68       old = current;
69 # else
70     while ((current = (AO_t)_InterlockedCompareExchange(
71                                 (LONG AO_INTERLOCKED_VOLATILE *)addr,
72                                 (LONG)value, (LONG)old)) != old)
73       old = current;
74 # endif
75 }
76 #define AO_HAVE_store_full
77
78 /* FIXME: implement AO_compare_double_and_swap_double() */
79
80 #else /* _M_ARM < 6 */
81
82 /* Some slide set, if it has been red correctly, claims that Loads      */
83 /* followed by either a Load or a Store are ordered, but nothing        */
84 /* else is. It appears that SWP is the only simple memory barrier.      */
85 #include "../all_atomic_load_store.h"
86
87 #include "../test_and_set_t_is_ao_t.h"
88 /* AO_test_and_set_full() is emulated using CAS.                        */
89
90 #endif /* _M_ARM < 6 */