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