implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / libatomic_ops / src / atomic_ops / sysdeps / msftc / x86.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 /* If AO_ASSUME_WINDOWS98 is defined, we assume Windows 98 or newer.    */
24 /* If AO_ASSUME_VISTA is defined, we assume Windows Server 2003, Vista  */
25 /* or later.                                                            */
26
27 #include "../all_aligned_atomic_load_store.h"
28
29 /* Real X86 implementations, except for some old WinChips, appear       */
30 /* to enforce ordering between memory operations, EXCEPT that a later   */
31 /* read can pass earlier writes, presumably due to the visible          */
32 /* presence of store buffers.                                           */
33 /* We ignore both the WinChips, and the fact that the official specs    */
34 /* seem to be much weaker (and arguably too weak to be usable).         */
35
36 #include "../ordered_except_wr.h"
37
38 #include "../test_and_set_t_is_char.h"
39
40 #ifndef AO_USE_INTERLOCKED_INTRINSICS
41   /* _Interlocked primitives (Inc, Dec, Xchg, Add) are always available */
42 # define AO_USE_INTERLOCKED_INTRINSICS
43 #endif
44 #include "common32_defs.h"
45
46 /* As far as we can tell, the lfence and sfence instructions are not    */
47 /* currently needed or useful for cached memory accesses.               */
48
49 /* Unfortunately mfence doesn't exist everywhere.               */
50 /* IsProcessorFeaturePresent(PF_COMPARE_EXCHANGE128) is         */
51 /* probably a conservative test for it?                         */
52
53 #if defined(AO_USE_PENTIUM4_INSTRS)
54
55 AO_INLINE void
56 AO_nop_full(void)
57 {
58   __asm { mfence }
59 }
60 #define AO_HAVE_nop_full
61
62 #else
63
64 /* We could use the cpuid instruction.  But that seems to be slower     */
65 /* than the default implementation based on test_and_set_full.  Thus    */
66 /* we omit that bit of misinformation here.                             */
67
68 #endif
69
70 AO_INLINE AO_TS_VAL_t
71 AO_test_and_set_full(volatile AO_TS_t *addr)
72 {
73     __asm
74     {
75         mov     eax,0xff                ; /* AO_TS_SET */
76         mov     ebx,addr                ;
77         xchg    byte ptr [ebx],al       ;
78     }
79     /* Ignore possible "missing return value" warning here. */
80 }
81 #define AO_HAVE_test_and_set_full
82
83 #ifdef _WIN64
84 #  error wrong architecture
85 #endif
86
87 #ifdef AO_ASSUME_VISTA
88
89 /* NEC LE-IT: whenever we run on a pentium class machine we have that
90  * certain function */
91
92 #include "../standard_ao_double_t.h"
93 #pragma intrinsic (_InterlockedCompareExchange64)
94 /* Returns nonzero if the comparison succeeded. */
95 AO_INLINE int
96 AO_compare_double_and_swap_double_full(volatile AO_double_t *addr,
97                                        AO_t old_val1, AO_t old_val2,
98                                        AO_t new_val1, AO_t new_val2)
99 {
100     __int64 oldv = (__int64)old_val1 | ((__int64)old_val2 << 32);
101     __int64 newv = (__int64)new_val1 | ((__int64)new_val2 << 32);
102     return _InterlockedCompareExchange64((__int64 volatile *)addr,
103                                        newv, oldv) == oldv;
104 }
105 #define AO_HAVE_compare_double_and_swap_double_full
106
107 #ifdef __cplusplus
108 AO_INLINE int
109 AO_double_compare_and_swap_full(volatile AO_double_t *addr,
110                                 AO_double_t old_val, AO_double_t new_val)
111 {
112     return _InterlockedCompareExchange64((__int64 volatile *)addr,
113                 new_val.AO_whole, old_val.AO_whole) == old_val.AO_whole;
114 }
115 #define AO_HAVE_double_compare_and_swap_full
116 #endif /* __cplusplus */
117
118 #endif /* AO_ASSUME_VISTA */
119
120 #include "../ao_t_is_int.h"