implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / libatomic_ops / src / atomic_ops / sysdeps / gcc / mips.h
1 /*
2  * Copyright (c) 2005,2007  Thiemo Seufer <ths@networkno.de>
3  *
4  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
6  *
7  * Permission is hereby granted to use or copy this program
8  * for any purpose,  provided the above notices are retained on all copies.
9  * Permission to modify the code and to distribute modified code is granted,
10  * provided the above notices are retained, and a notice that the code was
11  * modified is included with the above copyright notice.
12  */
13
14 /*
15  * FIXME:  This should probably make finer distinctions.  SGI MIPS is
16  * much more strongly ordered, and in fact closer to sequentially
17  * consistent.  This is really aimed at modern embedded implementations.
18  * It looks to me like this assumes a 32-bit ABI.  -HB
19  */
20
21 #include "../all_aligned_atomic_load_store.h"
22 #include "../acquire_release_volatile.h"
23 #include "../test_and_set_t_is_ao_t.h"
24 #include "../standard_ao_double_t.h"
25
26 /* Data dependence does not imply read ordering.  */
27 #define AO_NO_DD_ORDERING
28
29 AO_INLINE void
30 AO_nop_full(void)
31 {
32   __asm__ __volatile__(
33       "       .set push           \n"
34       "       .set mips2          \n"
35       "       .set noreorder      \n"
36       "       .set nomacro        \n"
37       "       sync                \n"
38       "       .set pop              "
39       : : : "memory");
40 }
41 #define AO_HAVE_nop_full
42
43 AO_INLINE int
44 AO_compare_and_swap(volatile AO_t *addr, AO_t old, AO_t new_val)
45 {
46   register int was_equal = 0;
47   register int temp;
48
49   __asm__ __volatile__(
50       "       .set push           \n"
51       "       .set mips2          \n"
52       "       .set noreorder      \n"
53       "       .set nomacro        \n"
54       "1:     ll      %0, %1      \n"
55       "       bne     %0, %4, 2f  \n"
56       "        move   %0, %3      \n"
57       "       sc      %0, %1      \n"
58       "       .set pop            \n"
59       "       beqz    %0, 1b      \n"
60       "       li      %2, 1       \n"
61       "2:                           "
62       : "=&r" (temp), "+R" (*addr), "+r" (was_equal)
63       : "r" (new_val), "r" (old)
64       : "memory");
65   return was_equal;
66 }
67 #define AO_HAVE_compare_and_swap
68
69 /* FIXME: I think the implementations below should be automatically     */
70 /* generated if we omit them.  - HB                                     */
71
72 AO_INLINE int
73 AO_compare_and_swap_acquire(volatile AO_t *addr, AO_t old, AO_t new_val) {
74   int result = AO_compare_and_swap(addr, old, new_val);
75   AO_nop_full();
76   return result;
77 }
78 #define AO_HAVE_compare_and_swap_acquire
79
80 AO_INLINE int
81 AO_compare_and_swap_release(volatile AO_t *addr, AO_t old, AO_t new_val) {
82   AO_nop_full();
83   return AO_compare_and_swap(addr, old, new_val);
84 }
85 #define AO_HAVE_compare_and_swap_release
86
87 AO_INLINE int
88 AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val) {
89   int result;
90   AO_nop_full();
91   result = AO_compare_and_swap(addr, old, new_val);
92   AO_nop_full();
93   return result;
94 }
95 #define AO_HAVE_compare_and_swap_full
96
97 /*
98  * FIXME: We should also implement fetch_and_add and or primitives
99  * directly.
100  */
101
102 #include "../ao_t_is_int.h"