File: sync-ops.h

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (67 lines) | stat: -rw-r--r-- 3,778 bytes parent folder | download | duplicates (17)
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
//===-- sync-ops.h - --===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements outline macros for the __sync_fetch_and_*
// operations. Different instantiations will generate appropriate assembly for
// ARM and Thumb-2 versions of the functions.
//
//===----------------------------------------------------------------------===//

#include "../assembly.h"

#if __ARM_ARCH >= 7
#define DMB dmb
#elif __ARM_ARCH >= 6
#define DMB mcr p15, #0, r0, c7, c10, #5
#else
#error DMB is only supported on ARMv6+
#endif

#define SYNC_OP_4(op)                                                          \
  .p2align 2;                                                                  \
  .syntax unified;                                                             \
  DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op)                            \
  DMB;                                                                         \
  mov r12, r0;                                                                 \
  LOCAL_LABEL(tryatomic_##op) : ldrex r0, [r12];                               \
  op(r2, r0, r1);                                                              \
  strex r3, r2, [r12];                                                         \
  cmp r3, #0;                                                                  \
  bne LOCAL_LABEL(tryatomic_##op);                                             \
  DMB;                                                                         \
  bx lr

#define SYNC_OP_8(op)                                                          \
  .p2align 2;                                                                  \
  .syntax unified;                                                             \
  DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op)                            \
  push {r4, r5, r6, lr};                                                       \
  DMB;                                                                         \
  mov r12, r0;                                                                 \
  LOCAL_LABEL(tryatomic_##op) : ldrexd r0, r1, [r12];                          \
  op(r4, r5, r0, r1, r2, r3);                                                  \
  strexd r6, r4, r5, [r12];                                                    \
  cmp r6, #0;                                                                  \
  bne LOCAL_LABEL(tryatomic_##op);                                             \
  DMB;                                                                         \
  pop { r4, r5, r6, pc }

#define MINMAX_4(rD, rN, rM, cmp_kind)                                         \
  cmp rN, rM;                                                                  \
  mov rD, rM;                                                                  \
  it cmp_kind;                                                                 \
  mov##cmp_kind rD, rN

#define MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, cmp_kind)           \
  cmp rN_LO, rM_LO;                                                            \
  sbcs rN_HI, rM_HI;                                                           \
  mov rD_LO, rM_LO;                                                            \
  mov rD_HI, rM_HI;                                                            \
  itt cmp_kind;                                                                \
  mov##cmp_kind rD_LO, rN_LO;                                                  \
  mov##cmp_kind rD_HI, rN_HI