1 | //===-- cpu_model/aarch64.c - Support for __cpu_model builtin ----*- C -*-===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file is based on LLVM's lib/Support/Host.cpp. |
10 | // It implements __aarch64_have_lse_atomics, __aarch64_cpu_features for |
11 | // AArch64. |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #include "aarch64.h" |
16 | |
17 | #if !defined(__aarch64__) && !defined(__arm64__) && !defined(_M_ARM64) && \ |
18 | !defined(__arm64ec__) && !defined(_M_ARM64EC) |
19 | #error This file is intended only for aarch64-based targets |
20 | #endif |
21 | |
22 | #if __has_include(<sys/ifunc.h>) |
23 | #include <sys/ifunc.h> |
24 | #else |
25 | typedef struct __ifunc_arg_t { |
26 | unsigned long _size; |
27 | unsigned long _hwcap; |
28 | unsigned long _hwcap2; |
29 | } __ifunc_arg_t; |
30 | #endif // __has_include(<sys/ifunc.h>) |
31 | |
32 | // LSE support detection for out-of-line atomics |
33 | // using HWCAP and Auxiliary vector |
34 | _Bool __aarch64_have_lse_atomics |
35 | __attribute__((visibility("hidden" ), nocommon)) = false; |
36 | |
37 | #if defined(__FreeBSD__) |
38 | // clang-format off: should not reorder sys/auxv.h alphabetically |
39 | #include <sys/auxv.h> |
40 | // clang-format on |
41 | #include "aarch64/hwcap.inc" |
42 | #include "aarch64/lse_atomics/freebsd.inc" |
43 | #elif defined(__Fuchsia__) |
44 | #include "aarch64/hwcap.inc" |
45 | #include "aarch64/lse_atomics/fuchsia.inc" |
46 | #elif defined(__ANDROID__) |
47 | #include "aarch64/hwcap.inc" |
48 | #include "aarch64/lse_atomics/android.inc" |
49 | #elif defined(__linux__) && __has_include(<sys/auxv.h>) |
50 | #include "aarch64/hwcap.inc" |
51 | #include "aarch64/lse_atomics/getauxval.inc" |
52 | #elif defined(_WIN32) |
53 | #include "aarch64/lse_atomics/windows.inc" |
54 | #else |
55 | // When unimplemented, we leave __aarch64_have_lse_atomics initialized to false. |
56 | #endif |
57 | |
58 | #if !defined(DISABLE_AARCH64_FMV) |
59 | |
60 | // Architecture features used |
61 | // in Function Multi Versioning |
62 | struct { |
63 | unsigned long long features; |
64 | // As features grows new fields could be added |
65 | } __aarch64_cpu_features __attribute__((visibility("hidden" ), nocommon)); |
66 | |
67 | // The formatter wants to re-order these includes, but doing so is incorrect: |
68 | // clang-format off |
69 | #if defined(__APPLE__) |
70 | #include "aarch64/fmv/apple.inc" |
71 | #elif defined(__FreeBSD__) |
72 | #include "aarch64/fmv/mrs.inc" |
73 | #include "aarch64/fmv/freebsd.inc" |
74 | #elif defined(__Fuchsia__) |
75 | #include "aarch64/fmv/fuchsia.inc" |
76 | #elif defined(__ANDROID__) |
77 | #include "aarch64/fmv/mrs.inc" |
78 | #include "aarch64/fmv/android.inc" |
79 | #elif defined(__linux__) && __has_include(<sys/auxv.h>) |
80 | #include "aarch64/fmv/mrs.inc" |
81 | #include "aarch64/fmv/getauxval.inc" |
82 | #elif defined(_WIN32) |
83 | #include "aarch64/fmv/windows.inc" |
84 | #elif defined(ENABLE_BAREMETAL_AARCH64_FMV) |
85 | #include "aarch64/fmv/baremetal.inc" |
86 | #else |
87 | #include "aarch64/fmv/unimplemented.inc" |
88 | #endif |
89 | // clang-format on |
90 | |
91 | #endif // !defined(DISABLE_AARCH64_FMV) |
92 | |