[xbuild] Rename method to make it more consistent.
[mono.git] / mono / io-layer / hppa_atomic.S
1 /*
2     Copyright (c) 2003 Bernie Solomon <bernard@ugsolutions.com>
3     
4     Permission is hereby granted, free of charge, to any person obtaining
5     a copy of this software and associated documentation files (the
6     "Software"), to deal in the Software without restriction, including
7     without limitation the rights to use, copy, modify, merge, publish,
8     distribute, sublicense, and/or sell copies of the Software, and to
9     permit persons to whom the Software is furnished to do so, subject to
10     the following conditions:
11     
12     The above copyright notice and this permission notice shall be
13     included in all copies or substantial portions of the Software.
14     
15     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19     LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20     OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23
24
25     Implementation of "atomic" operations for HPPA. Currently (Oct 9th 2003)
26     only implemented for 64 bit compiles. There is only one atomic
27     instruction LDCW which is used to implement spinlocks. There are
28     16 locks which are selected by taking 4 bits out of the address of
29     the relevant variable to try to avoid too much contention
30     for a single lock.
31 */
32 #include "config.h"
33
34 #ifdef __LP64__
35 #if SIZEOF_VOID_P != 8
36 #error "__LP64__ state and SIZEOF_VOID_P don't match!!"
37 #endif
38 #define EXPORT_ARGS ,NO_RELOCATION,LONG_RETURN
39 #define CALLINFO_ARGS ,ARGS_SAVED,ORDERING_AWARE
40 #define RETURN  bve,n (%rp)
41 #define LDPTR   ldd
42 #define STPTR   std
43 #else
44 #if SIZEOF_VOID_P != 4
45 #error "__LP64__ state and SIZEOF_VOID_P don't match!!"
46 #endif
47 #define CALLINFO_ARGS
48 #define EXPORT_ARGS
49 #define RETURN  bv,n (%rp)
50 #define LDPTR   ldw
51 #define STPTR   stw
52 #endif
53         .code
54
55  .label InterlockedIncrement
56         .EXPORT InterlockedIncrement,ENTRY,PRIV_LEV=3 EXPORT_ARGS
57         .PROC
58         .CALLINFO FRAME=0 CALLINFO_ARGS
59         .ENTRY
60 #ifdef PIC
61         ADDIL   LT%locks,%r19
62         LDPTR   RT%locks(%r1),%r31
63 #else
64         ADDIL   L%locks-$global$,%dp
65         LDO     R%locks-$global$(%r1),%r31
66 #endif
67         EXTRU   %arg0,28,4,%r28
68         ZDEP    %r28,27,28,%r29
69         ADD,L   %r29,%r31,%r31
70  .label atomictest$1
71         LDCW    0(%r31),%r29
72         CMPB,<> %r0,%r29,gotlock$1
73         NOP
74  .label spin$1
75         LDW     0(%r31),%r29
76         CMPB,=  %r29,%r0,spin$1
77         NOP
78         B,N     atomictest$1
79  .label gotlock$1
80         LDW     0(%arg0),%ret0
81         LDI     1,%r29
82         LDO     1(%ret0),%ret0
83         STW     %ret0,0(%arg0)
84         STW     %r29,0(%r31)
85         .EXIT
86         RETURN
87         .PROCEND
88
89  .label InterlockedDecrement
90         .EXPORT InterlockedDecrement,ENTRY,PRIV_LEV=3 EXPORT_ARGS
91         .PROC
92         .CALLINFO FRAME=0 CALLINFO_ARGS
93         .ENTRY
94 #ifdef PIC
95         ADDIL   LT%locks,%r19
96         LDPTR   RT%locks(%r1),%r31
97 #else
98         ADDIL   L%locks-$global$,%dp
99         LDO     R%locks-$global$(%r1),%r31
100 #endif
101         EXTRU   %arg0,28,4,%r28
102         ZDEP    %r28,27,28,%r29
103         ADD,L   %r29,%r31,%r31
104  .label atomictest$2
105         LDCW    0(%r31),%r29
106         CMPB,<> %r0,%r29,gotlock$2
107         NOP
108  .label spin$2
109         LDW     0(%r31),%r29
110         CMPB,=  %r29,%r0,spin$2
111         NOP
112         B,N     atomictest$2
113  .label gotlock$2
114         LDW     0(%arg0),%ret0
115         LDI     1,%r29
116         LDO     -1(%ret0),%ret0
117         STW     %ret0,0(%arg0)
118         STW     %r29,0(%r31)
119         .EXIT
120         RETURN
121         .PROCEND
122
123  .label InterlockedExchange
124         .EXPORT InterlockedExchange,ENTRY,PRIV_LEV=3 EXPORT_ARGS
125         .PROC
126         .CALLINFO FRAME=0 CALLINFO_ARGS
127         .ENTRY
128 #ifdef PIC
129         ADDIL   LT%locks,%r19
130         LDPTR   RT%locks(%r1),%r31
131 #else
132         ADDIL   L%locks-$global$,%dp
133         LDO     R%locks-$global$(%r1),%r31
134 #endif
135         EXTRU   %arg0,28,4,%r28
136         ZDEP    %r28,27,28,%r29
137         ADD,L   %r29,%r31,%r31
138  .label atomictest$3
139         LDCW    0(%r31),%r29
140         CMPB,<> %r0,%r29,gotlock$3
141         NOP
142  .label spin$3
143         LDW     0(%r31),%r29
144         CMPB,=  %r29,%r0,spin$3
145         NOP
146         B,N     atomictest$3
147  .label gotlock$3
148         LDW     0(%arg0),%ret0
149         STW     %arg1,0(%arg0)
150         LDI     1,%r29
151         STW     %r29,0(%r31)
152         .EXIT
153         RETURN
154         .PROCEND
155
156  .label InterlockedExchangePointer
157         .EXPORT InterlockedExchangePointer,ENTRY,PRIV_LEV=3 EXPORT_ARGS
158         .PROC
159         .CALLINFO FRAME=0 CALLINFO_ARGS
160         .ENTRY
161 #ifdef PIC
162         ADDIL   LT%locks,%r19
163         LDPTR   RT%locks(%r1),%r31
164 #else
165         ADDIL   L%locks-$global$,%dp
166         LDO     R%locks-$global$(%r1),%r31
167 #endif
168         EXTRU   %arg0,28,4,%r28
169         ZDEP    %r28,27,28,%r29
170         ADD,L   %r29,%r31,%r31
171  .label atomictest$4
172         LDCW    0(%r31),%r29
173         CMPB,<> %r0,%r29,gotlock$4
174         NOP
175  .label spin$4
176         LDW     0(%r31),%r29
177         CMPB,=  %r29,%r0,spin$4
178         NOP
179         B,N     atomictest$4
180  .label gotlock$4
181         LDPTR   0(%arg0),%ret0
182         STPTR   %arg1,0(%arg0)
183         LDI     1,%r29
184         STW     %r29,0(%r31)
185         .EXIT
186         RETURN
187         .PROCEND
188
189  .label InterlockedCompareExchange
190         .EXPORT InterlockedCompareExchange,ENTRY,PRIV_LEV=3 EXPORT_ARGS
191         .PROC
192         .CALLINFO FRAME=0 CALLINFO_ARGS
193         .ENTRY
194 #ifdef PIC
195         ADDIL   LT%locks,%r19
196         LDPTR   RT%locks(%r1),%r31
197 #else
198         ADDIL   L%locks-$global$,%dp
199         LDO     R%locks-$global$(%r1),%r31
200 #endif
201         EXTRU   %arg0,28,4,%r28
202         ZDEP    %r28,27,28,%r29
203         ADD,L   %r29,%r31,%r31
204  .label atomictest$5
205         LDCW    0(%r31),%r29
206         CMPB,<> %r0,%r29,gotlock$5
207         NOP
208  .label spin$5
209         LDW     0(%r31),%r29
210         CMPB,=  %r29,%r0,spin$5
211         NOP
212         B,N     atomictest$5
213  .label gotlock$5
214         LDW     0(%arg0),%ret0
215         sub,<>  %ret0,%r24,%r0
216         STW     %arg1,0(%arg0)          /* not done if %ret0 <> %r24 */
217         LDI     1,%r29
218         STW     %r29,0(%r31)
219         .EXIT
220         RETURN
221         .PROCEND
222
223  .label InterlockedCompareExchangePointer
224         .EXPORT InterlockedCompareExchangePointer,ENTRY,PRIV_LEV=3 EXPORT_ARGS
225         .PROC
226         .CALLINFO FRAME=0 CALLINFO_ARGS
227         .ENTRY
228 #ifdef PIC
229         ADDIL   LT%locks,%r19
230         LDPTR   RT%locks(%r1),%r31
231 #else
232         ADDIL   L%locks-$global$,%dp
233         LDO     R%locks-$global$(%r1),%r31
234 #endif
235         EXTRU   %arg0,28,4,%r28
236         ZDEP    %r28,27,28,%r29
237         ADD,L   %r29,%r31,%r31
238  .label atomictest$6
239         LDCW    0(%r31),%r29
240         CMPB,<> %r0,%r29,gotlock$6
241         NOP
242  .label spin$6
243         LDW     0(%r31),%r29
244         CMPB,=  %r29,%r0,spin$6
245         NOP
246         B,N     atomictest$6
247  .label gotlock$6
248         LDPTR   0(%arg0),%ret0
249         sub,<>  %ret0,%r24,%r0
250         STPTR   %arg1,0(%arg0)
251         LDI     1,%r29
252         STW     %r29,0(%r31)
253         .EXIT
254         RETURN
255         .PROCEND
256
257
258         .data
259  .label locks
260         .ALIGN  16
261         .STRING "\x00\x00\x00\x01"
262         .ALIGN  16
263         .STRING "\x00\x00\x00\x01"
264         .ALIGN  16
265         .STRING "\x00\x00\x00\x01"
266         .ALIGN  16
267         .STRING "\x00\x00\x00\x01"
268         .ALIGN  16
269         .STRING "\x00\x00\x00\x01"
270         .ALIGN  16
271         .STRING "\x00\x00\x00\x01"
272         .ALIGN  16
273         .STRING "\x00\x00\x00\x01"
274         .ALIGN  16
275         .STRING "\x00\x00\x00\x01"
276         .ALIGN  16
277         .STRING "\x00\x00\x00\x01"
278         .ALIGN  16
279         .STRING "\x00\x00\x00\x01"
280         .ALIGN  16
281         .STRING "\x00\x00\x00\x01"
282         .ALIGN  16
283         .STRING "\x00\x00\x00\x01"
284         .ALIGN  16
285         .STRING "\x00\x00\x00\x01"
286         .ALIGN  16
287         .STRING "\x00\x00\x00\x01"
288         .ALIGN  16
289         .STRING "\x00\x00\x00\x01"
290         .ALIGN  16
291         .STRING "\x00\x00\x00\x01"
292         .IMPORT $global$,DATA
293         .END