Skip to content

Commit 5a0d73b

Browse files
[compiler-rt][AArch64] NFCI: Simplify __arm_get_current_vg. (#119210)
This patch simplifies the code in two different ways: * When SVE is available, return `cntd` directly to avoid the need for bitfield insert. * When SME is available, check the PSTATE.SM bit of `SVCR` directly rather than calling `__arm_sme_state`.
1 parent 444e53f commit 5a0d73b

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

compiler-rt/lib/builtins/aarch64/sme-abi.S

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "../assembly.h"
1010

11+
.set FEAT_SVE_BIT, 30
12+
.set SVCR_PSTATE_SM_BIT, 0
1113

1214
#if !defined(__APPLE__)
1315
#define TPIDR2_SYMBOL SYMBOL_NAME(__aarch64_has_sme_and_tpidr2_el0)
@@ -188,39 +190,20 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_get_current_vg)
188190
.variant_pcs __arm_get_current_vg
189191
BTI_C
190192

191-
stp x29, x30, [sp, #-16]!
192-
.cfi_def_cfa_offset 16
193-
mov x29, sp
194-
.cfi_def_cfa w29, 16
195-
.cfi_offset w30, -8
196-
.cfi_offset w29, -16
197193
adrp x17, CPU_FEATS_SYMBOL
198194
ldr w17, [x17, CPU_FEATS_SYMBOL_OFFSET]
199-
tbnz w17, #30, 0f
200-
adrp x16, TPIDR2_SYMBOL
201-
ldrb w16, [x16, TPIDR2_SYMBOL_OFFSET]
202-
cbz w16, 1f
195+
tbnz w17, #FEAT_SVE_BIT, 1f
196+
adrp x17, TPIDR2_SYMBOL
197+
ldrb w17, [x17, TPIDR2_SYMBOL_OFFSET]
198+
cbz x17, 2f
203199
0:
204-
mov x18, x1
205-
bl __arm_sme_state
206-
mov x1, x18
207-
and x17, x17, #0x40000000
208-
bfxil x17, x0, #0, #1
209-
cbz x17, 1f
200+
mrs x17, SVCR
201+
tbz x17, #SVCR_PSTATE_SM_BIT, 2f
202+
1:
210203
cntd x0
211-
.cfi_def_cfa wsp, 16
212-
ldp x29, x30, [sp], #16
213-
.cfi_def_cfa_offset 0
214-
.cfi_restore w30
215-
.cfi_restore w29
216204
ret
217-
1:
205+
2:
218206
mov x0, xzr
219-
.cfi_def_cfa wsp, 16
220-
ldp x29, x30, [sp], #16
221-
.cfi_def_cfa_offset 0
222-
.cfi_restore w30
223-
.cfi_restore w29
224207
ret
225208
END_COMPILERRT_OUTLINE_FUNCTION(__arm_get_current_vg)
226209

0 commit comments

Comments
 (0)