sme-abi-init.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  2. // See https://llvm.org/LICENSE.txt for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. __attribute__((visibility("hidden"), nocommon))
  5. _Bool __aarch64_has_sme_and_tpidr2_el0;
  6. // We have multiple ways to check that the function has SME, depending on our
  7. // target.
  8. // * For Linux we can use __getauxval().
  9. // * For newlib we can use __aarch64_sme_accessible().
  10. #if defined(__linux__)
  11. #ifndef AT_HWCAP2
  12. #define AT_HWCAP2 26
  13. #endif
  14. #ifndef HWCAP2_SME
  15. #define HWCAP2_SME (1 << 23)
  16. #endif
  17. extern unsigned long int __getauxval (unsigned long int);
  18. static _Bool has_sme(void) {
  19. return __getauxval(AT_HWCAP2) & HWCAP2_SME;
  20. }
  21. #else // defined(__linux__)
  22. #if defined(COMPILER_RT_SHARED_LIB)
  23. __attribute__((weak))
  24. #endif
  25. extern _Bool __aarch64_sme_accessible(void);
  26. static _Bool has_sme(void) {
  27. #if defined(COMPILER_RT_SHARED_LIB)
  28. if (!__aarch64_sme_accessible)
  29. return 0;
  30. #endif
  31. return __aarch64_sme_accessible();
  32. }
  33. #endif // defined(__linux__)
  34. #if __GNUC__ >= 9
  35. #pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
  36. #endif
  37. __attribute__((constructor(90)))
  38. static void init_aarch64_has_sme(void) {
  39. __aarch64_has_sme_and_tpidr2_el0 = has_sme();
  40. }