xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/aarch64/sme-abi-init.c (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
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 
5 __attribute__((visibility("hidden"), nocommon))
6 _Bool __aarch64_has_sme_and_tpidr2_el0;
7 
8 // We have multiple ways to check that the function has SME, depending on our
9 // target.
10 // * For Linux we can use __getauxval().
11 // * For newlib we can use __aarch64_sme_accessible().
12 
13 #if defined(__linux__)
14 
15 #ifndef AT_HWCAP2
16 #define AT_HWCAP2 26
17 #endif
18 
19 #ifndef HWCAP2_SME
20 #define HWCAP2_SME (1 << 23)
21 #endif
22 
23 extern unsigned long int __getauxval (unsigned long int);
24 
25 static _Bool has_sme(void) {
26   return __getauxval(AT_HWCAP2) & HWCAP2_SME;
27 }
28 
29 #else  // defined(__linux__)
30 
31 #if defined(COMPILER_RT_SHARED_LIB)
32 __attribute__((weak))
33 #endif
34 extern _Bool __aarch64_sme_accessible(void);
35 
36 static _Bool has_sme(void)  {
37 #if defined(COMPILER_RT_SHARED_LIB)
38   if (!__aarch64_sme_accessible)
39     return 0;
40 #endif
41   return __aarch64_sme_accessible();
42 }
43 
44 #endif // defined(__linux__)
45 
46 #if __GNUC__ >= 9
47 #pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
48 #endif
49 __attribute__((constructor(90)))
50 static void init_aarch64_has_sme(void) {
51   __aarch64_has_sme_and_tpidr2_el0 = has_sme();
52 }
53