Debian Codegraph @

libgcc/config/aarch64/__aarch64_have_sme.c

raw
1 /* Initializer for SME support.
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
24
25 #include "auto-target.h"
26
27 #ifndef inhibit_libc
28 /* For libc feature test macros. */
29 # include <unistd.h>
30 #endif
31
32 #if __ARM_FEATURE_SME
33 /* Avoid runtime SME detection if libgcc is built with SME. */
34 # define HAVE_SME_CONST const
35 # define HAVE_SME_VALUE 1
36 #elif HAVE___GETAUXVAL
37 /* SME access detection on Linux. */
38 # define HAVE_SME_CONST
39 # define HAVE_SME_VALUE 0
40 # define HAVE_SME_CTOR sme_accessible ()
41
42 # define AT_HWCAP2 26
43 # define HWCAP2_SME (1 << 23)
44 unsigned long int __getauxval (unsigned long int);
45
46 static _Bool
47 sme_accessible (void)
48 {
49 unsigned long hwcap2 = __getauxval (AT_HWCAP2);
50 return (hwcap2 & HWCAP2_SME) != 0;
51 }
52 #elif __LIBC___AARCH64_SME_ACCESSIBLE
53 /* Alternative SME access detection. */
54 # define HAVE_SME_CONST
55 # define HAVE_SME_VALUE 0
56 # define HAVE_SME_CTOR __aarch64_sme_accessible ()
57 _Bool __aarch64_sme_accessible (void);
58 #else
59 # define HAVE_SME_CONST const
60 # define HAVE_SME_VALUE 0
61 #endif
62
63 /* Define the symbol gating SME support in libgcc. */
64 HAVE_SME_CONST _Bool __aarch64_have_sme
65 __attribute__((visibility("hidden"), nocommon)) = HAVE_SME_VALUE;
66
67 #ifdef HAVE_SME_CTOR
68 /* Use a higher priority to ensure it runs before user constructors
69 with priority 100. */
70 static void __attribute__((constructor (90)))
71 init_have_sme (void)
72 {
73 __aarch64_have_sme = HAVE_SME_CTOR;
74 }
75 #endif