xref: /aosp_15_r20/external/compiler-rt/lib/builtins/arm/sync-ops.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot /*===-- sync-ops.h - --===//
2*7c3d14c8STreehugger Robot  *
3*7c3d14c8STreehugger Robot  *                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot  *
5*7c3d14c8STreehugger Robot  * This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot  * Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot  *
8*7c3d14c8STreehugger Robot  *===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot  *
10*7c3d14c8STreehugger Robot  * This file implements outline macros for the __sync_fetch_and_*
11*7c3d14c8STreehugger Robot  * operations. Different instantiations will generate appropriate assembly for
12*7c3d14c8STreehugger Robot  * ARM and Thumb-2 versions of the functions.
13*7c3d14c8STreehugger Robot  *
14*7c3d14c8STreehugger Robot  *===----------------------------------------------------------------------===*/
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot #include "../assembly.h"
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot #define SYNC_OP_4(op) \
19*7c3d14c8STreehugger Robot         .p2align 2 ; \
20*7c3d14c8STreehugger Robot         .thumb ; \
21*7c3d14c8STreehugger Robot         .syntax unified ; \
22*7c3d14c8STreehugger Robot         DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_ ## op) \
23*7c3d14c8STreehugger Robot         dmb ; \
24*7c3d14c8STreehugger Robot         mov r12, r0 ; \
25*7c3d14c8STreehugger Robot         LOCAL_LABEL(tryatomic_ ## op): \
26*7c3d14c8STreehugger Robot         ldrex r0, [r12] ; \
27*7c3d14c8STreehugger Robot         op(r2, r0, r1) ; \
28*7c3d14c8STreehugger Robot         strex r3, r2, [r12] ; \
29*7c3d14c8STreehugger Robot         cmp r3, #0 ; \
30*7c3d14c8STreehugger Robot         bne LOCAL_LABEL(tryatomic_ ## op) ; \
31*7c3d14c8STreehugger Robot         dmb ; \
32*7c3d14c8STreehugger Robot         bx lr
33*7c3d14c8STreehugger Robot 
34*7c3d14c8STreehugger Robot #define SYNC_OP_8(op) \
35*7c3d14c8STreehugger Robot         .p2align 2 ; \
36*7c3d14c8STreehugger Robot         .thumb ; \
37*7c3d14c8STreehugger Robot         .syntax unified ; \
38*7c3d14c8STreehugger Robot         DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_ ## op) \
39*7c3d14c8STreehugger Robot         push {r4, r5, r6, lr} ; \
40*7c3d14c8STreehugger Robot         dmb ; \
41*7c3d14c8STreehugger Robot         mov r12, r0 ; \
42*7c3d14c8STreehugger Robot         LOCAL_LABEL(tryatomic_ ## op): \
43*7c3d14c8STreehugger Robot         ldrexd r0, r1, [r12] ; \
44*7c3d14c8STreehugger Robot         op(r4, r5, r0, r1, r2, r3) ; \
45*7c3d14c8STreehugger Robot         strexd r6, r4, r5, [r12] ; \
46*7c3d14c8STreehugger Robot         cmp r6, #0 ; \
47*7c3d14c8STreehugger Robot         bne LOCAL_LABEL(tryatomic_ ## op) ; \
48*7c3d14c8STreehugger Robot         dmb ; \
49*7c3d14c8STreehugger Robot         pop {r4, r5, r6, pc}
50*7c3d14c8STreehugger Robot 
51*7c3d14c8STreehugger Robot #define MINMAX_4(rD, rN, rM, cmp_kind) \
52*7c3d14c8STreehugger Robot         cmp rN, rM ; \
53*7c3d14c8STreehugger Robot         mov rD, rM ; \
54*7c3d14c8STreehugger Robot         it cmp_kind ; \
55*7c3d14c8STreehugger Robot         mov##cmp_kind rD, rN
56*7c3d14c8STreehugger Robot 
57*7c3d14c8STreehugger Robot #define MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, cmp_kind) \
58*7c3d14c8STreehugger Robot         cmp rN_LO, rM_LO ; \
59*7c3d14c8STreehugger Robot         sbcs rN_HI, rM_HI ; \
60*7c3d14c8STreehugger Robot         mov rD_LO, rM_LO ; \
61*7c3d14c8STreehugger Robot         mov rD_HI, rM_HI ; \
62*7c3d14c8STreehugger Robot         itt cmp_kind ; \
63*7c3d14c8STreehugger Robot         mov##cmp_kind rD_LO, rN_LO ; \
64*7c3d14c8STreehugger Robot         mov##cmp_kind rD_HI, rN_HI
65