Skip to content

Commit c1b692e

Browse files
jroelofswangxiang090105
authored andcommitted
fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
llvm/llvm-project#75635 (comment) ``` /b/s/w/ir/x/w/llvm_build/./bin/clang --target=aarch64-unknown-linux-gnu --sysroot=/b/s/w/ir/x/w/cipd/linux -DHAS_ASM_LSE -DVISIBILITY_HIDDEN --target=aarch64-unknown-linux-gnu -O2 -g -DNDEBUG -fno-lto -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -DCOMPILER_RT_HAS_FLOAT16 -MD -MT CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -MF CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o.d -o CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -c /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c In file included from /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c:43: /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/sysauxv.inc:5:41: error: use of undeclared identifier 'HWCAP_ATOMICS' 5 | __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0; | ^ 1 error generated. ```
1 parent e3cead5 commit c1b692e

File tree

3 files changed

+184
-179
lines changed

3 files changed

+184
-179
lines changed

compiler-rt/lib/builtins/cpu_model/aarch64.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ _Bool __aarch64_have_lse_atomics
3434
__attribute__((visibility("hidden"), nocommon)) = false;
3535

3636
#if defined(__FreeBSD__)
37+
#include "aarch64/hwcap.inc"
3738
#include "aarch64/lse_atomics/freebsd.inc"
3839
#elif defined(__Fuchsia__)
40+
#include "aarch64/hwcap.inc"
3941
#include "aarch64/lse_atomics/fuchsia.inc"
4042
#elif defined(__ANDROID__)
43+
#include "aarch64/hwcap.inc"
4144
#include "aarch64/lse_atomics/android.inc"
4245
#elif __has_include(<sys/auxv.h>)
46+
#include "aarch64/hwcap.inc"
4347
#include "aarch64/lse_atomics/sysauxv.inc"
4448
#else
4549
// When unimplemented, we leave __aarch64_have_lse_atomics initialized to false.

compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -3,186 +3,7 @@
33
#define HAVE_SYS_AUXV_H
44
#endif
55

6-
#if __has_include(<sys/hwcap.h>)
7-
#include <sys/hwcap.h>
8-
#define HAVE_SYS_HWCAP_H
9-
#endif
10-
11-
#ifndef _IFUNC_ARG_HWCAP
12-
#define _IFUNC_ARG_HWCAP (1ULL << 62)
13-
#endif
14-
#ifndef AT_HWCAP
15-
#define AT_HWCAP 16
16-
#endif
17-
#ifndef HWCAP_CPUID
18-
#define HWCAP_CPUID (1 << 11)
19-
#endif
20-
#ifndef HWCAP_FP
21-
#define HWCAP_FP (1 << 0)
22-
#endif
23-
#ifndef HWCAP_ASIMD
24-
#define HWCAP_ASIMD (1 << 1)
25-
#endif
26-
#ifndef HWCAP_AES
27-
#define HWCAP_AES (1 << 3)
28-
#endif
29-
#ifndef HWCAP_PMULL
30-
#define HWCAP_PMULL (1 << 4)
31-
#endif
32-
#ifndef HWCAP_SHA1
33-
#define HWCAP_SHA1 (1 << 5)
34-
#endif
35-
#ifndef HWCAP_SHA2
36-
#define HWCAP_SHA2 (1 << 6)
37-
#endif
38-
#ifndef HWCAP_CRC32
39-
#define HWCAP_CRC32 (1 << 7)
40-
#endif
41-
#ifndef HWCAP_ATOMICS
42-
#define HWCAP_ATOMICS (1 << 8)
43-
#endif
44-
#ifndef HWCAP_FPHP
45-
#define HWCAP_FPHP (1 << 9)
46-
#endif
47-
#ifndef HWCAP_ASIMDHP
48-
#define HWCAP_ASIMDHP (1 << 10)
49-
#endif
50-
#ifndef HWCAP_ASIMDRDM
51-
#define HWCAP_ASIMDRDM (1 << 12)
52-
#endif
53-
#ifndef HWCAP_JSCVT
54-
#define HWCAP_JSCVT (1 << 13)
55-
#endif
56-
#ifndef HWCAP_FCMA
57-
#define HWCAP_FCMA (1 << 14)
58-
#endif
59-
#ifndef HWCAP_LRCPC
60-
#define HWCAP_LRCPC (1 << 15)
61-
#endif
62-
#ifndef HWCAP_DCPOP
63-
#define HWCAP_DCPOP (1 << 16)
64-
#endif
65-
#ifndef HWCAP_SHA3
66-
#define HWCAP_SHA3 (1 << 17)
67-
#endif
68-
#ifndef HWCAP_SM3
69-
#define HWCAP_SM3 (1 << 18)
70-
#endif
71-
#ifndef HWCAP_SM4
72-
#define HWCAP_SM4 (1 << 19)
73-
#endif
74-
#ifndef HWCAP_ASIMDDP
75-
#define HWCAP_ASIMDDP (1 << 20)
76-
#endif
77-
#ifndef HWCAP_SHA512
78-
#define HWCAP_SHA512 (1 << 21)
79-
#endif
80-
#ifndef HWCAP_SVE
81-
#define HWCAP_SVE (1 << 22)
82-
#endif
83-
#ifndef HWCAP_ASIMDFHM
84-
#define HWCAP_ASIMDFHM (1 << 23)
85-
#endif
86-
#ifndef HWCAP_DIT
87-
#define HWCAP_DIT (1 << 24)
88-
#endif
89-
#ifndef HWCAP_ILRCPC
90-
#define HWCAP_ILRCPC (1 << 26)
91-
#endif
92-
#ifndef HWCAP_FLAGM
93-
#define HWCAP_FLAGM (1 << 27)
94-
#endif
95-
#ifndef HWCAP_SSBS
96-
#define HWCAP_SSBS (1 << 28)
97-
#endif
98-
#ifndef HWCAP_SB
99-
#define HWCAP_SB (1 << 29)
100-
#endif
1016

102-
#ifndef AT_HWCAP2
103-
#define AT_HWCAP2 26
104-
#endif
105-
#ifndef HWCAP2_DCPODP
106-
#define HWCAP2_DCPODP (1 << 0)
107-
#endif
108-
#ifndef HWCAP2_SVE2
109-
#define HWCAP2_SVE2 (1 << 1)
110-
#endif
111-
#ifndef HWCAP2_SVEAES
112-
#define HWCAP2_SVEAES (1 << 2)
113-
#endif
114-
#ifndef HWCAP2_SVEPMULL
115-
#define HWCAP2_SVEPMULL (1 << 3)
116-
#endif
117-
#ifndef HWCAP2_SVEBITPERM
118-
#define HWCAP2_SVEBITPERM (1 << 4)
119-
#endif
120-
#ifndef HWCAP2_SVESHA3
121-
#define HWCAP2_SVESHA3 (1 << 5)
122-
#endif
123-
#ifndef HWCAP2_SVESM4
124-
#define HWCAP2_SVESM4 (1 << 6)
125-
#endif
126-
#ifndef HWCAP2_FLAGM2
127-
#define HWCAP2_FLAGM2 (1 << 7)
128-
#endif
129-
#ifndef HWCAP2_FRINT
130-
#define HWCAP2_FRINT (1 << 8)
131-
#endif
132-
#ifndef HWCAP2_SVEI8MM
133-
#define HWCAP2_SVEI8MM (1 << 9)
134-
#endif
135-
#ifndef HWCAP2_SVEF32MM
136-
#define HWCAP2_SVEF32MM (1 << 10)
137-
#endif
138-
#ifndef HWCAP2_SVEF64MM
139-
#define HWCAP2_SVEF64MM (1 << 11)
140-
#endif
141-
#ifndef HWCAP2_SVEBF16
142-
#define HWCAP2_SVEBF16 (1 << 12)
143-
#endif
144-
#ifndef HWCAP2_I8MM
145-
#define HWCAP2_I8MM (1 << 13)
146-
#endif
147-
#ifndef HWCAP2_BF16
148-
#define HWCAP2_BF16 (1 << 14)
149-
#endif
150-
#ifndef HWCAP2_DGH
151-
#define HWCAP2_DGH (1 << 15)
152-
#endif
153-
#ifndef HWCAP2_RNG
154-
#define HWCAP2_RNG (1 << 16)
155-
#endif
156-
#ifndef HWCAP2_BTI
157-
#define HWCAP2_BTI (1 << 17)
158-
#endif
159-
#ifndef HWCAP2_MTE
160-
#define HWCAP2_MTE (1 << 18)
161-
#endif
162-
#ifndef HWCAP2_RPRES
163-
#define HWCAP2_RPRES (1 << 21)
164-
#endif
165-
#ifndef HWCAP2_MTE3
166-
#define HWCAP2_MTE3 (1 << 22)
167-
#endif
168-
#ifndef HWCAP2_SME
169-
#define HWCAP2_SME (1 << 23)
170-
#endif
171-
#ifndef HWCAP2_SME_I16I64
172-
#define HWCAP2_SME_I16I64 (1 << 24)
173-
#endif
174-
#ifndef HWCAP2_SME_F64F64
175-
#define HWCAP2_SME_F64F64 (1 << 25)
176-
#endif
177-
#ifndef HWCAP2_WFXT
178-
#define HWCAP2_WFXT (1UL << 31)
179-
#endif
180-
#ifndef HWCAP2_EBF16
181-
#define HWCAP2_EBF16 (1ULL << 32)
182-
#endif
183-
#ifndef HWCAP2_SVE_EBF16
184-
#define HWCAP2_SVE_EBF16 (1ULL << 33)
185-
#endif
1867

1878
static void __init_cpu_features_constructor(unsigned long hwcap,
1889
const __ifunc_arg_t *arg) {
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#if __has_include(<sys/hwcap.h>)
2+
#include <sys/hwcap.h>
3+
#define HAVE_SYS_HWCAP_H
4+
#endif
5+
6+
#ifndef _IFUNC_ARG_HWCAP
7+
#define _IFUNC_ARG_HWCAP (1ULL << 62)
8+
#endif
9+
#ifndef AT_HWCAP
10+
#define AT_HWCAP 16
11+
#endif
12+
#ifndef HWCAP_CPUID
13+
#define HWCAP_CPUID (1 << 11)
14+
#endif
15+
#ifndef HWCAP_FP
16+
#define HWCAP_FP (1 << 0)
17+
#endif
18+
#ifndef HWCAP_ASIMD
19+
#define HWCAP_ASIMD (1 << 1)
20+
#endif
21+
#ifndef HWCAP_AES
22+
#define HWCAP_AES (1 << 3)
23+
#endif
24+
#ifndef HWCAP_PMULL
25+
#define HWCAP_PMULL (1 << 4)
26+
#endif
27+
#ifndef HWCAP_SHA1
28+
#define HWCAP_SHA1 (1 << 5)
29+
#endif
30+
#ifndef HWCAP_SHA2
31+
#define HWCAP_SHA2 (1 << 6)
32+
#endif
33+
#ifndef HWCAP_CRC32
34+
#define HWCAP_CRC32 (1 << 7)
35+
#endif
36+
#ifndef HWCAP_ATOMICS
37+
#define HWCAP_ATOMICS (1 << 8)
38+
#endif
39+
#ifndef HWCAP_FPHP
40+
#define HWCAP_FPHP (1 << 9)
41+
#endif
42+
#ifndef HWCAP_ASIMDHP
43+
#define HWCAP_ASIMDHP (1 << 10)
44+
#endif
45+
#ifndef HWCAP_ASIMDRDM
46+
#define HWCAP_ASIMDRDM (1 << 12)
47+
#endif
48+
#ifndef HWCAP_JSCVT
49+
#define HWCAP_JSCVT (1 << 13)
50+
#endif
51+
#ifndef HWCAP_FCMA
52+
#define HWCAP_FCMA (1 << 14)
53+
#endif
54+
#ifndef HWCAP_LRCPC
55+
#define HWCAP_LRCPC (1 << 15)
56+
#endif
57+
#ifndef HWCAP_DCPOP
58+
#define HWCAP_DCPOP (1 << 16)
59+
#endif
60+
#ifndef HWCAP_SHA3
61+
#define HWCAP_SHA3 (1 << 17)
62+
#endif
63+
#ifndef HWCAP_SM3
64+
#define HWCAP_SM3 (1 << 18)
65+
#endif
66+
#ifndef HWCAP_SM4
67+
#define HWCAP_SM4 (1 << 19)
68+
#endif
69+
#ifndef HWCAP_ASIMDDP
70+
#define HWCAP_ASIMDDP (1 << 20)
71+
#endif
72+
#ifndef HWCAP_SHA512
73+
#define HWCAP_SHA512 (1 << 21)
74+
#endif
75+
#ifndef HWCAP_SVE
76+
#define HWCAP_SVE (1 << 22)
77+
#endif
78+
#ifndef HWCAP_ASIMDFHM
79+
#define HWCAP_ASIMDFHM (1 << 23)
80+
#endif
81+
#ifndef HWCAP_DIT
82+
#define HWCAP_DIT (1 << 24)
83+
#endif
84+
#ifndef HWCAP_ILRCPC
85+
#define HWCAP_ILRCPC (1 << 26)
86+
#endif
87+
#ifndef HWCAP_FLAGM
88+
#define HWCAP_FLAGM (1 << 27)
89+
#endif
90+
#ifndef HWCAP_SSBS
91+
#define HWCAP_SSBS (1 << 28)
92+
#endif
93+
#ifndef HWCAP_SB
94+
#define HWCAP_SB (1 << 29)
95+
#endif
96+
97+
#ifndef AT_HWCAP2
98+
#define AT_HWCAP2 26
99+
#endif
100+
#ifndef HWCAP2_DCPODP
101+
#define HWCAP2_DCPODP (1 << 0)
102+
#endif
103+
#ifndef HWCAP2_SVE2
104+
#define HWCAP2_SVE2 (1 << 1)
105+
#endif
106+
#ifndef HWCAP2_SVEAES
107+
#define HWCAP2_SVEAES (1 << 2)
108+
#endif
109+
#ifndef HWCAP2_SVEPMULL
110+
#define HWCAP2_SVEPMULL (1 << 3)
111+
#endif
112+
#ifndef HWCAP2_SVEBITPERM
113+
#define HWCAP2_SVEBITPERM (1 << 4)
114+
#endif
115+
#ifndef HWCAP2_SVESHA3
116+
#define HWCAP2_SVESHA3 (1 << 5)
117+
#endif
118+
#ifndef HWCAP2_SVESM4
119+
#define HWCAP2_SVESM4 (1 << 6)
120+
#endif
121+
#ifndef HWCAP2_FLAGM2
122+
#define HWCAP2_FLAGM2 (1 << 7)
123+
#endif
124+
#ifndef HWCAP2_FRINT
125+
#define HWCAP2_FRINT (1 << 8)
126+
#endif
127+
#ifndef HWCAP2_SVEI8MM
128+
#define HWCAP2_SVEI8MM (1 << 9)
129+
#endif
130+
#ifndef HWCAP2_SVEF32MM
131+
#define HWCAP2_SVEF32MM (1 << 10)
132+
#endif
133+
#ifndef HWCAP2_SVEF64MM
134+
#define HWCAP2_SVEF64MM (1 << 11)
135+
#endif
136+
#ifndef HWCAP2_SVEBF16
137+
#define HWCAP2_SVEBF16 (1 << 12)
138+
#endif
139+
#ifndef HWCAP2_I8MM
140+
#define HWCAP2_I8MM (1 << 13)
141+
#endif
142+
#ifndef HWCAP2_BF16
143+
#define HWCAP2_BF16 (1 << 14)
144+
#endif
145+
#ifndef HWCAP2_DGH
146+
#define HWCAP2_DGH (1 << 15)
147+
#endif
148+
#ifndef HWCAP2_RNG
149+
#define HWCAP2_RNG (1 << 16)
150+
#endif
151+
#ifndef HWCAP2_BTI
152+
#define HWCAP2_BTI (1 << 17)
153+
#endif
154+
#ifndef HWCAP2_MTE
155+
#define HWCAP2_MTE (1 << 18)
156+
#endif
157+
#ifndef HWCAP2_RPRES
158+
#define HWCAP2_RPRES (1 << 21)
159+
#endif
160+
#ifndef HWCAP2_MTE3
161+
#define HWCAP2_MTE3 (1 << 22)
162+
#endif
163+
#ifndef HWCAP2_SME
164+
#define HWCAP2_SME (1 << 23)
165+
#endif
166+
#ifndef HWCAP2_SME_I16I64
167+
#define HWCAP2_SME_I16I64 (1 << 24)
168+
#endif
169+
#ifndef HWCAP2_SME_F64F64
170+
#define HWCAP2_SME_F64F64 (1 << 25)
171+
#endif
172+
#ifndef HWCAP2_WFXT
173+
#define HWCAP2_WFXT (1UL << 31)
174+
#endif
175+
#ifndef HWCAP2_EBF16
176+
#define HWCAP2_EBF16 (1ULL << 32)
177+
#endif
178+
#ifndef HWCAP2_SVE_EBF16
179+
#define HWCAP2_SVE_EBF16 (1ULL << 33)
180+
#endif

0 commit comments

Comments
 (0)