]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/config/cpu/sparc/atomicity.h
Move from CPP to CXX.
[thirdparty/gcc.git] / libstdc++-v3 / config / cpu / sparc / atomicity.h
CommitLineData
750db234 1// Low-level functions for atomic operations: Sparc version -*- C++ -*-
a29456b5 2
750db234 3// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
a29456b5
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction. Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License. This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
b2dad0e3 29
3d7c150e
BK
30#ifndef _GLIBCXX_ATOMICITY_H
31#define _GLIBCXX_ATOMICITY_H 1
b2dad0e3 32
750db234
JJ
33#ifdef __arch64__
34
35typedef long _Atomic_word;
36
37static inline _Atomic_word
38__attribute__ ((__unused__))
39__exchange_and_add (volatile _Atomic_word *__mem, int __val)
40{
41 _Atomic_word __tmp1, __tmp2;
42
43 __asm__ __volatile__("1: ldx [%2], %0\n\t"
44 " add %0, %3, %1\n\t"
45 " casx [%2], %0, %1\n\t"
46 " sub %0, %1, %0\n\t"
47 " brnz,pn %0, 1b\n\t"
48 " nop"
49 : "=&r" (__tmp1), "=&r" (__tmp2)
50 : "r" (__mem), "r" (__val)
51 : "memory");
52 return __tmp2;
53}
54
55static inline void
56__attribute__ ((__unused__))
57__atomic_add (volatile _Atomic_word* __mem, int __val)
58{
59 _Atomic_word __tmp1, __tmp2;
60
61 __asm__ __volatile__("1: ldx [%2], %0\n\t"
62 " add %0, %3, %1\n\t"
63 " casx [%2], %0, %1\n\t"
64 " sub %0, %1, %0\n\t"
65 " brnz,pn %0, 1b\n\t"
66 " nop"
67 : "=&r" (__tmp1), "=&r" (__tmp2)
68 : "r" (__mem), "r" (__val)
69 : "memory");
70}
71
72#else /* __arch32__ */
73
f17d6c73 74typedef int _Atomic_word;
b2dad0e3 75
7814a308
NM
76template <int __inst>
77struct __Atomicity_lock
78{
79 static unsigned char _S_atomicity_lock;
80};
81
82template <int __inst>
83unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0;
84
813df022
LR
85template unsigned char __Atomicity_lock<0>::_S_atomicity_lock;
86
b2dad0e3 87static int
7e0ec38b 88__attribute__ ((__unused__))
f17d6c73 89__exchange_and_add (volatile _Atomic_word* __mem, int __val)
b2dad0e3 90{
f17d6c73 91 _Atomic_word __result, __tmp;
b2dad0e3
BK
92
93 __asm__ __volatile__("1: ldstub [%1], %0\n\t"
94 " cmp %0, 0\n\t"
95 " bne 1b\n\t"
96 " nop"
f17d6c73 97 : "=&r" (__tmp)
7814a308 98 : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
b2dad0e3 99 : "memory");
f17d6c73
NM
100 __result = *__mem;
101 *__mem += __val;
b2dad0e3
BK
102 __asm__ __volatile__("stb %%g0, [%0]"
103 : /* no outputs */
7814a308 104 : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
b2dad0e3 105 : "memory");
f17d6c73 106 return __result;
b2dad0e3
BK
107}
108
109static void
7e0ec38b 110__attribute__ ((__unused__))
f17d6c73 111__atomic_add (volatile _Atomic_word* __mem, int __val)
b2dad0e3 112{
f17d6c73 113 _Atomic_word __tmp;
b2dad0e3
BK
114
115 __asm__ __volatile__("1: ldstub [%1], %0\n\t"
116 " cmp %0, 0\n\t"
117 " bne 1b\n\t"
118 " nop"
f17d6c73 119 : "=&r" (__tmp)
7814a308 120 : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
b2dad0e3 121 : "memory");
f17d6c73 122 *__mem += __val;
b2dad0e3
BK
123 __asm__ __volatile__("stb %%g0, [%0]"
124 : /* no outputs */
7814a308 125 : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
b2dad0e3
BK
126 : "memory");
127}
128
750db234
JJ
129#endif /* __arch32__ */
130
b2dad0e3 131#endif /* atomicity.h */