1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
// bool cas(uint32 *ptr, uint32 old, uint32 new)
// Atomically:
// if(*ptr == old){
// *ptr = new;
// return 1;
// } else
// return 0;
TEXT ·Cas(SB), NOSPLIT, $0-17
MOVV ptr+0(FP), R4
MOVW old+8(FP), R5
MOVW new+12(FP), R6
DBAR
cas_again:
MOVV R6, R7
LL (R4), R8
BNE R5, R8, cas_fail
SC R7, (R4)
BEQ R7, cas_again
MOVV $1, R4
MOVB R4, ret+16(FP)
DBAR
RET
cas_fail:
MOVV $0, R4
JMP -4(PC)
// bool cas64(uint64 *ptr, uint64 old, uint64 new)
// Atomically:
// if(*ptr == old){
// *ptr = new;
// return 1;
// } else {
// return 0;
// }
TEXT ·Cas64(SB), NOSPLIT, $0-25
MOVV ptr+0(FP), R4
MOVV old+8(FP), R5
MOVV new+16(FP), R6
DBAR
cas64_again:
MOVV R6, R7
LLV (R4), R8
BNE R5, R8, cas64_fail
SCV R7, (R4)
BEQ R7, cas64_again
MOVV $1, R4
MOVB R4, ret+24(FP)
DBAR
RET
cas64_fail:
MOVV $0, R4
JMP -4(PC)
TEXT ·Casuintptr(SB), NOSPLIT, $0-25
JMP ·Cas64(SB)
TEXT ·CasRel(SB), NOSPLIT, $0-17
JMP ·Cas(SB)
TEXT ·Loaduintptr(SB), NOSPLIT|NOFRAME, $0-16
JMP ·Load64(SB)
TEXT ·Loaduint(SB), NOSPLIT|NOFRAME, $0-16
JMP ·Load64(SB)
TEXT ·Storeuintptr(SB), NOSPLIT, $0-16
JMP ·Store64(SB)
TEXT ·Xadduintptr(SB), NOSPLIT, $0-24
JMP ·Xadd64(SB)
TEXT ·Loadint64(SB), NOSPLIT, $0-16
JMP ·Load64(SB)
TEXT ·Xaddint64(SB), NOSPLIT, $0-24
JMP ·Xadd64(SB)
// bool casp(void **val, void *old, void *new)
// Atomically:
// if(*val == old){
// *val = new;
// return 1;
// } else
// return 0;
TEXT ·Casp1(SB), NOSPLIT, $0-25
JMP ·Cas64(SB)
// uint32 xadd(uint32 volatile *ptr, int32 delta)
// Atomically:
// *val += delta;
// return *val;
TEXT ·Xadd(SB), NOSPLIT, $0-20
MOVV ptr+0(FP), R4
MOVW delta+8(FP), R5
DBAR
LL (R4), R6
ADDU R6, R5, R7
MOVV R7, R6
SC R7, (R4)
BEQ R7, -4(PC)
MOVW R6, ret+16(FP)
DBAR
RET
TEXT ·Xadd64(SB), NOSPLIT, $0-24
MOVV ptr+0(FP), R4
MOVV delta+8(FP), R5
DBAR
LLV (R4), R6
ADDVU R6, R5, R7
MOVV R7, R6
SCV R7, (R4)
BEQ R7, -4(PC)
MOVV R6, ret+16(FP)
DBAR
RET
TEXT ·Xchg(SB), NOSPLIT, $0-20
MOVV ptr+0(FP), R4
MOVW new+8(FP), R5
DBAR
MOVV R5, R6
LL (R4), R7
SC R6, (R4)
BEQ R6, -3(PC)
MOVW R7, ret+16(FP)
DBAR
RET
TEXT ·Xchg64(SB), NOSPLIT, $0-24
MOVV ptr+0(FP), R4
MOVV new+8(FP), R5
DBAR
MOVV R5, R6
LLV (R4), R7
SCV R6, (R4)
BEQ R6, -3(PC)
MOVV R7, ret+16(FP)
DBAR
RET
TEXT ·Xchguintptr(SB), NOSPLIT, $0-24
JMP ·Xchg64(SB)
TEXT ·StorepNoWB(SB), NOSPLIT, $0-16
JMP ·Store64(SB)
TEXT ·StoreRel(SB), NOSPLIT, $0-12
JMP ·Store(SB)
TEXT ·StoreRel64(SB), NOSPLIT, $0-16
JMP ·Store64(SB)
TEXT ·StoreReluintptr(SB), NOSPLIT, $0-16
JMP ·Store64(SB)
TEXT ·Store(SB), NOSPLIT, $0-12
MOVV ptr+0(FP), R4
MOVW val+8(FP), R5
DBAR
MOVW R5, 0(R4)
DBAR
RET
TEXT ·Store8(SB), NOSPLIT, $0-9
MOVV ptr+0(FP), R4
MOVB val+8(FP), R5
DBAR
MOVB R5, 0(R4)
DBAR
RET
TEXT ·Store64(SB), NOSPLIT, $0-16
MOVV ptr+0(FP), R4
MOVV val+8(FP), R5
DBAR
MOVV R5, 0(R4)
DBAR
RET
// void Or8(byte volatile*, byte);
TEXT ·Or8(SB), NOSPLIT, $0-9
MOVV ptr+0(FP), R4
MOVBU val+8(FP), R5
// Align ptr down to 4 bytes so we can use 32-bit load/store.
MOVV $~3, R6
AND R4, R6
// R7 = ((ptr & 3) * 8)
AND $3, R4, R7
SLLV $3, R7
// Shift val for aligned ptr. R5 = val << R4
SLLV R7, R5
DBAR
LL (R6), R7
OR R5, R7
SC R7, (R6)
BEQ R7, -4(PC)
DBAR
RET
// void And8(byte volatile*, byte);
TEXT ·And8(SB), NOSPLIT, $0-9
MOVV ptr+0(FP), R4
MOVBU val+8(FP), R5
// Align ptr down to 4 bytes so we can use 32-bit load/store.
MOVV $~3, R6
AND R4, R6
// R7 = ((ptr & 3) * 8)
AND $3, R4, R7
SLLV $3, R7
// Shift val for aligned ptr. R5 = val << R7 | ^(0xFF << R7)
MOVV $0xFF, R8
SLLV R7, R5
SLLV R7, R8
NOR R0, R8
OR R8, R5
DBAR
LL (R6), R7
AND R5, R7
SC R7, (R6)
BEQ R7, -4(PC)
DBAR
RET
// func Or(addr *uint32, v uint32)
TEXT ·Or(SB), NOSPLIT, $0-12
MOVV ptr+0(FP), R4
MOVW val+8(FP), R5
DBAR
LL (R4), R6
OR R5, R6
SC R6, (R4)
BEQ R6, -4(PC)
DBAR
RET
// func And(addr *uint32, v uint32)
TEXT ·And(SB), NOSPLIT, $0-12
MOVV ptr+0(FP), R4
MOVW val+8(FP), R5
DBAR
LL (R4), R6
AND R5, R6
SC R6, (R4)
BEQ R6, -4(PC)
DBAR
RET
// uint32 runtime∕internal∕atomic·Load(uint32 volatile* ptr)
TEXT ·Load(SB),NOSPLIT|NOFRAME,$0-12
MOVV ptr+0(FP), R19
DBAR
MOVWU 0(R19), R19
DBAR
MOVW R19, ret+8(FP)
RET
// uint8 runtime∕internal∕atomic·Load8(uint8 volatile* ptr)
TEXT ·Load8(SB),NOSPLIT|NOFRAME,$0-9
MOVV ptr+0(FP), R19
DBAR
MOVBU 0(R19), R19
DBAR
MOVB R19, ret+8(FP)
RET
// uint64 runtime∕internal∕atomic·Load64(uint64 volatile* ptr)
TEXT ·Load64(SB),NOSPLIT|NOFRAME,$0-16
MOVV ptr+0(FP), R19
DBAR
MOVV 0(R19), R19
DBAR
MOVV R19, ret+8(FP)
RET
// void *runtime∕internal∕atomic·Loadp(void *volatile *ptr)
TEXT ·Loadp(SB),NOSPLIT|NOFRAME,$0-16
MOVV ptr+0(FP), R19
DBAR
MOVV 0(R19), R19
DBAR
MOVV R19, ret+8(FP)
RET
// uint32 runtime∕internal∕atomic·LoadAcq(uint32 volatile* ptr)
TEXT ·LoadAcq(SB),NOSPLIT|NOFRAME,$0-12
JMP ·Load(SB)
// uint64 ·LoadAcq64(uint64 volatile* ptr)
TEXT ·LoadAcq64(SB),NOSPLIT|NOFRAME,$0-16
JMP ·Load64(SB)
// uintptr ·LoadAcquintptr(uintptr volatile* ptr)
TEXT ·LoadAcquintptr(SB),NOSPLIT|NOFRAME,$0-16
JMP ·Load64(SB)
|