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 DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_ ## op) \ 22 dmb ; \ 23 mov r12, r0 ; \ 24 LOCAL_LABEL(tryatomic_ ## op): \ 25 ldrex r0, [r12] ; \ 26 op(r2, r0, r1) ; \ 27 strex r3, r2, [r12] ; \ 28 cbnz r3, LOCAL_LABEL(tryatomic_ ## op) ; \ 29 dmb ; \ 30 bx lr 31 32 #define SYNC_OP_8(op) \ 33 .p2align 2 ; \ 34 .thumb ; \ 35 DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_ ## op) \ 36 push {r4, r5, r6, lr} ; \ 37 dmb ; \ 38 mov r12, r0 ; \ 39 LOCAL_LABEL(tryatomic_ ## op): \ 40 ldrexd r0, r1, [r12] ; \ 41 op(r4, r5, r0, r1, r2, r3) ; \ 42 strexd r6, r4, r5, [r12] ; \ 43 cbnz r6, LOCAL_LABEL(tryatomic_ ## op) ; \ 44 dmb ; \ 45 pop {r4, r5, r6, pc} 46 47 #define MINMAX_4(rD, rN, rM, cmp_kind) \ 48 cmp rN, rM ; \ 49 mov rD, rM ; \ 50 it cmp_kind ; \ 51 mov##cmp_kind rD, rN 52 53 #define MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, cmp_kind) \ 54 cmp rN_LO, rM_LO ; \ 55 sbcs rN_HI, rM_HI ; \ 56 mov rD_LO, rM_LO ; \ 57 mov rD_HI, rM_HI ; \ 58 itt cmp_kind ; \ 59 mov##cmp_kind rD_LO, rN_LO ; \ 60 mov##cmp_kind rD_HI, rN_HI 61