implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / libatomic_ops / src / atomic_ops / sysdeps / gcc / sparc.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 /* FIXME.  Very incomplete.  No support for sparc64.    */
19 /* Non-ancient SPARCs provide compare-and-swap (casa).  */
20 /* We should make that available.                       */
21
22 #include "../all_atomic_load_store.h"
23
24 /* Real SPARC code uses TSO:                            */
25 #include "../ordered_except_wr.h"
26
27 /* Test_and_set location is just a byte.                */
28 #include "../test_and_set_t_is_char.h"
29
30 AO_INLINE AO_TS_VAL_t
31 AO_test_and_set_full(volatile AO_TS_t *addr) {
32    AO_TS_VAL_t oldval;
33
34    __asm__ __volatile__("ldstub %1,%0"
35                         : "=r"(oldval), "=m"(*addr)
36                         : "m"(*addr) : "memory");
37    return oldval;
38 }
39 #define AO_HAVE_test_and_set_full
40
41 #ifndef AO_NO_SPARC_V9
42 /* Returns nonzero if the comparison succeeded. */
43 AO_INLINE int
44 AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val) {
45   char ret;
46   __asm__ __volatile__ ("membar #StoreLoad | #LoadLoad\n\t"
47 #                       if defined(__arch64__)
48                           "casx [%2],%0,%1\n\t"
49 #                       else
50                           "cas [%2],%0,%1\n\t" /* 32-bit version */
51 #                       endif
52                         "membar #StoreLoad | #StoreStore\n\t"
53                         "cmp %0,%1\n\t"
54                         "be,a 0f\n\t"
55                         "mov 1,%0\n\t"/* one insn after branch always executed */
56                         "clr %0\n\t"
57                         "0:\n\t"
58                         : "=r" (ret), "+r" (new_val)
59                         : "r" (addr), "0" (old)
60                         : "memory", "cc");
61   return (int)ret;
62 }
63 #define AO_HAVE_compare_and_swap_full
64 #endif /* !AO_NO_SPARC_V9 */
65
66 /* FIXME: This needs to be extended for SPARC v8 and v9.        */
67 /* SPARC V8 also has swap.  V9 has CAS.                         */
68 /* There are barriers like membar #LoadStore.                   */
69 /* CASA (32-bit) and CASXA(64-bit) instructions were            */
70 /* added in V9.                                                 */