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