PAPI 7.1.0.0
Loading...
Searching...
No Matches
gcc/sparc.h
Go to the documentation of this file.
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/* TODO: Very incomplete; Add support for sparc64. */
19/* Non-ancient SPARCs provide compare-and-swap (casa). */
20
21#include "../all_atomic_load_store.h"
22
23/* Real SPARC code uses TSO: */
24#include "../ordered_except_wr.h"
25
26/* Test_and_set location is just a byte. */
27#include "../test_and_set_t_is_char.h"
28
31 AO_TS_VAL_t oldval;
32
33 __asm__ __volatile__("ldstub %1,%0"
34 : "=r"(oldval), "=m"(*addr)
35 : "m"(*addr) : "memory");
36 return oldval;
37}
38#define AO_HAVE_test_and_set_full
39
40#ifndef AO_NO_SPARC_V9
41
42# ifndef AO_GENERALIZE_ASM_BOOL_CAS
43/* Returns nonzero if the comparison succeeded. */
44AO_INLINE int
45AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val) {
46 AO_t ret;
47 __asm__ __volatile__ ("membar #StoreLoad | #LoadLoad\n\t"
48# if defined(__arch64__)
49 "casx [%2],%0,%1\n\t"
50# else
51 "cas [%2],%0,%1\n\t" /* 32-bit version */
52# endif
53 "membar #StoreLoad | #StoreStore\n\t"
54 "cmp %0,%1\n\t"
55 "be,a 0f\n\t"
56 "mov 1,%0\n\t"/* one insn after branch always executed */
57 "clr %0\n\t"
58 "0:\n\t"
59 : "=r" (ret), "+r" (new_val)
60 : "r" (addr), "0" (old)
61 : "memory", "cc");
62 return (int)ret;
63}
64# define AO_HAVE_compare_and_swap_full
65# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
66
68AO_fetch_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val) {
69 __asm__ __volatile__ ("membar #StoreLoad | #LoadLoad\n\t"
70# if defined(__arch64__)
71 "casx [%1],%2,%0\n\t"
72# else
73 "cas [%1],%2,%0\n\t" /* 32-bit version */
74# endif
75 "membar #StoreLoad | #StoreStore\n\t"
76 : "+r" (new_val)
77 : "r" (addr), "r" (old)
78 : "memory");
79 return new_val;
80}
81#define AO_HAVE_fetch_compare_and_swap_full
82
83#endif /* !AO_NO_SPARC_V9 */
84
85/* TODO: Extend this for SPARC v8 and v9 (V8 also has swap, V9 has CAS, */
86/* there are barriers like membar #LoadStore, CASA (32-bit) and */
87/* CASXA (64-bit) instructions added in V9). */
#define AO_t
Definition: atomic_ops.h:156
#define AO_INLINE
Definition: atomic_ops.h:186
#define AO_fetch_compare_and_swap_full(addr, old, newval)
Definition: emul_cas.h:61
#define AO_TS_t
Definition: gcc/hppa.h:39
#define AO_TS_VAL_t
Definition: gcc/hppa.h:44
AO_INLINE int AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val)
Definition: gcc/sparc.h:45
AO_INLINE AO_TS_VAL_t AO_test_and_set_full(volatile AO_TS_t *addr)
Definition: gcc/sparc.h:30