aarch64.c 2.5 KB

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