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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
//arm lock helper
//there is 2 part: read and write
// write return 0 on success, 1 on fail (value has been changed)
.text
.align 4
.extern cpuext
.global arm64_lock_read_b
.global arm64_lock_write_b
.global arm64_lock_read_h
.global arm64_lock_write_h
.global arm64_lock_read_d
.global arm64_lock_write_d
.global arm64_lock_read_dd
.global arm64_lock_write_dd
.global arm64_lock_read_dq
.global arm64_lock_write_dq
.global arm64_lock_xchg_dd
.global arm64_lock_xchg_d
.global arm64_lock_xchg_h
.global arm64_lock_xchg_b
.global arm64_lock_storeifnull
.global arm64_lock_storeifnull_d
.global arm64_lock_storeifref
.global arm64_lock_storeifref2
.global arm64_lock_storeifref_d
.global arm64_lock_storeifref2_d
.global arm64_lock_decifnot0b
.global arm64_lock_storeb
.global arm64_lock_incif0
.global arm64_lock_decifnot0
.global arm64_lock_store
.global arm64_lock_store_dd
.global arm64_lock_get_b
.global arm64_lock_get_d
.global arm64_lock_get_dd
.global arm64_crc
arm64_lock_read_b:
dmb ish
// address is x0, return is x0
ldaxrb w0, [x0]
ret
arm64_lock_write_b:
// address is x0, value is x1, return is x0
mov x2, x0
stlxrb w0, w1, [x2]
dmb ish
ret
arm64_lock_read_h:
dmb ish
// address is x0, return is x0
ldaxrh w0, [x0]
ret
arm64_lock_write_h:
// address is x0, value is x1, return is x0
mov x2, x0
stlxrh w0, w1, [x2]
dmb ish
ret
arm64_lock_read_d:
dmb ish
// address is x0, return is x0
ldaxr w0, [x0]
ret
arm64_lock_write_d:
// address is x0, value is w1, return is x0
mov x2, x0
stlxr w0, w1, [x2]
dmb ish
ret
arm64_lock_read_dd:
dmb ish
// address is x0, return is x0
ldaxr x0, [x0]
ret
arm64_lock_write_dd:
// address is x0, value is x1, return is x0
mov x2, x0
stlxr w0, x1, [x2]
dmb ish
ret
arm64_lock_read_dq:
dmb ish
// address is r2, return is r0, r1
ldaxp x4, x3, [x2]
str x4, [x0]
str x3, [x1]
ret
arm64_lock_write_dq:
// address is r2, value is r0, r1, return is r0
// r0 needs to be aligned
stlxp w3, x0, x1, [x2]
mov w0, w3
dmb ish
ret
arm64_lock_xchg_dd:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_xchg_dd
dmb ish
arm64_lock_xchg_dd_0:
// address is x0, value is x1, return old value in x0
ldaxr x2, [x0]
stlxr w3, x1, [x0]
cbnz w3, arm64_lock_xchg_dd_0
mov x0, x2
ret
arm64_atomic_xchg_dd:
dmb ish
// address is x0, value is x1, return old value in x0
swpal x1, x0, [x0]
ret
arm64_lock_xchg_d:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_xchg_d
dmb ish
arm64_lock_xchg_d_0:
// address is x0, value is x1, return old value in x0
ldaxr w2, [x0]
stlxr w3, w1, [x0]
cbnz w3, arm64_lock_xchg_d_0
mov w0, w2
ret
arm64_atomic_xchg_d:
dmb ish
// address is x0, value is x1, return old value in x0
swpal w1, w0, [x0]
ret
arm64_lock_xchg_h:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_xchg_h
dmb ish
arm64_lock_xchg_h_0:
// address is x0, value is x1, return old value in x0
ldaxrh w2, [x0]
stlxrh w3, w1, [x0]
cbnz w3, arm64_lock_xchg_h_0
mov w0, w2
ret
arm64_atomic_xchg_h:
dmb ish
// address is x0, value is x1, return old value in x0
swpalh w1, w0, [x0]
ret
arm64_lock_xchg_b:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_xchg_b
dmb ish
arm64_lock_xchg_b_0:
// address is x0, value is x1, return old value in x0
ldaxrb w2, [x0]
stlxrb w3, w1, [x0]
cbnz w3, arm64_lock_xchg_b_0
mov w0, w2
ret
arm64_atomic_xchg_b:
dmb ish
// address is x0, value is x1, return old value in x0
swpalb w1, w0, [x0]
ret
arm64_lock_storeifnull:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_storeifnull
dmb ish
1:
// address is x0, value is x1, x1 store to x0 only if [x0] is 0. return old [x0] value
ldaxr x2, [x0]
cbnz x2, 2f
stlxr w3, x1, [x0]
cbnz w3, 1b
2:
mov x0, x2
ret
arm64_atomic_storeifnull:
dmb ish
// address is x0, value is x1, x1 store to x0 only if [x0] is 0. return old [x0] value
mov x2, xzr
casal x2, x1, [x0]
mov x0, x2
ret
arm64_lock_storeifnull_d:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_storeifnull_d
dmb ish
1:
// address is x0, value is w1, w1 store to x0 only if [x0] is 0. return old [x0] value
ldaxr w2, [x0]
cbnz w2, 2f
stlxr w3, w1, [x0]
cbnz w3, 1b
2:
dmb ish
mov w0, w2
ret
arm64_atomic_storeifnull_d:
dmb ish
// address is x0, value is w1, w1 store to x0 only if [x0] is 0. return old [x0] value
mov x2, xzr
casal w2, w1, [x0]
mov w0, w2
ret
arm64_lock_storeifref:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_storeifref
dmb ish
1:
// address is x0, value is x1, x1 store to x0 only if [x0] is x2. return new [x0] value (so x1 or old value)
ldaxr x3, [x0]
cmp x2, x3
bne 2f
stlxr w4, x1, [x0]
cbnz w4, 1b
mov x0, x1
ret
2:
mov x0, x3
ret
arm64_atomic_storeifref:
dmb ish
// address is x0, value is x1, x1 store to x0 only if [x0] is x2. return new [x0] value (so x1 or old value)
mov x3, x2
casal x2, x1, [x0]
cmp x2, x3
mov x0, x1
ret
2:
mov x0, x3
ret
arm64_lock_storeifref_d:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_storeifref_d
dmb ish
1:
// address is x0, value is w1, w1 store to x0 only if [x0] is w2. return new [x0] value (so x1 or old value)
ldaxr w3, [x0]
cmp w2, w3
bne 2f
stlxr w4, w1, [x0]
cbnz w4, 1b
mov w0, w1
ret
2:
mov w0, w3
ret
arm64_atomic_storeifref_d:
dmb ish
// address is x0, value is w1, w1 store to x0 only if [x0] is w2. return new [x0] value (so w1 or old value)
mov w3, w2
casal w2, w1, [x0]
cmp w2, w3
mov w0, w1
ret
2:
mov w0, w3
ret
arm64_lock_storeifref2_d:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_storeifref2_d
dmb ish
1:
// address is x0, value is w1, w1 store to x0 only if [x0] is w2. return old [x0] value
ldaxr w3, [x0]
cmp w2, w3
bne 2f
stlxr w4, w1, [x0]
cbnz w4, 1b
2:
mov w0, w3
ret
arm64_atomic_storeifref2_d:
dmb ish
// address is x0, value is w1, w1 store to x0 only if [x0] is w2. return old [x0] value
casal w2, w1, [x0]
mov w0, w2
ret
arm64_lock_storeifref2:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_storeifref2
dmb ish
1:
// address is x0, value is x1, x1 store to x0 only if [x0] is x2. return old [x0] value
ldaxr x3, [x0]
cmp x2, x3
bne 2f
stlxr w4, x1, [x0]
cbnz w4, 1b
2:
mov x0, x3
ret
arm64_atomic_storeifref2:
dmb ish
// address is x0, value is x1, x1 store to x0 only if [x0] is x2. return old [x0] value
casal x2, x1, [x0]
mov x0, x2
ret
arm64_lock_decifnot0b:
dmb ish
1:
ldaxrb w1, [x0]
cmp w1, #0
beq 2f
sub w1, w1, #1
stlxrb w2, w1, [x0]
cbnz w2, 1b
2:
ret
arm64_lock_storeb:
strb w1, [x0]
dmb ish
ret
arm64_lock_decifnot0:
dmb ish
1:
ldaxr w1, [x0]
cmp w1, #0
beq 2f
sub w3, w1, #1
stlxr w2, w3, [x0]
cbnz w2, 1b
2:
mov w0, w1
ret
arm64_lock_incif0:
adrp x3, cpuext
add x3, x3, #:lo12:cpuext
ldr w3, [x3]
tbnz w3, #0, arm64_atomic_incif0
dmb ish
1:
ldaxr w1, [x0]
cmp w1, #0
bne 2f
add w3, w1, #1
stlxr w2, w3, [x0]
cbnz w2, 1b
2:
mov w0, w1
ret
arm64_atomic_incif0:
mov w1, #1
dmb ish
swpal w1, wzr, [x0]
mov w0, w1
ret
arm64_lock_store:
str w1, [x0]
dmb ish
ret
arm64_lock_store_dd:
str x1, [x0]
dmb ish
ret
arm64_lock_get_b:
ldaxrb w0, [x0]
ret
arm64_lock_get_d:
ldaxr w0, [x0]
ret
arm64_lock_get_dd:
ldaxr x0, [x0]
ret
arm64_crc:
//x0 is address, w1 is len
mov x2, x0 // address is x2 now
mov w0, wzr // crc is w0
1:
cmp w1, #8
blo 2f
ldr x3, [x2], #8
crc32x w0, w0, x3
subs w1, w1, #8
bne 1b
2:
cbz w1, 4f
3:
ldrb w3, [x2], #1
crc32b w0, w0, w3
subs w1, w1, #1
bne 3b
4:
ret
|