1 //===-- sync-ops.h - --===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements outline macros for the __sync_fetch_and_*
10 // operations. Different instantiations will generate appropriate assembly for
11 // ARM and Thumb-2 versions of the functions.
13 //===----------------------------------------------------------------------===//
15 #include "../assembly.h"
20 #define DMB mcr p15, #0, r0, c7, c10, #5
22 #error DMB is only supported on ARMv6+
25 #define SYNC_OP_4(op) \
28 DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op) \
31 LOCAL_LABEL(tryatomic_##op) : ldrex r0, [r12]; \
33 strex r3, r2, [r12]; \
35 bne LOCAL_LABEL(tryatomic_##op); \
39 #define SYNC_OP_8(op) \
42 DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op) \
43 push {r4, r5, r6, lr}; \
46 LOCAL_LABEL(tryatomic_##op) : ldrexd r0, r1, [r12]; \
47 op(r4, r5, r0, r1, r2, r3); \
48 strexd r6, r4, r5, [r12]; \
50 bne LOCAL_LABEL(tryatomic_##op); \
52 pop { r4, r5, r6, pc }
54 #define MINMAX_4(rD, rN, rM, cmp_kind) \
60 #define MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, cmp_kind) \
66 mov##cmp_kind rD_LO, rN_LO; \
67 mov##cmp_kind rD_HI, rN_HI