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
23extern unsigned long int __getauxval (unsigned long int);
24
25static _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
34extern _Bool __aarch64_sme_accessible(void);
35
36static _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)))
50static void init_aarch64_has_sme(void) {
51 __aarch64_has_sme_and_tpidr2_el0 = has_sme();
52}
53

source code of compiler-rt/lib/builtins/aarch64/sme-abi-init.c