-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Compiler-rt] Add AArch64 routines for __arm_agnostic("sme_za_state") #120059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12e1815
[Compiler-rt] Add AArch64 routines for __arm_agnostic("sme_za_state")
sdesmalen-arm 88e7dc4
Address comments
sdesmalen-arm aaecb05
Address more comments
sdesmalen-arm 7b50c7a
Further simplification
sdesmalen-arm c0dc2a4
Further simplification
sdesmalen-arm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
|
|
||
| .set FEAT_SVE_BIT, 30 | ||
| .set FEAT_SME_BIT, 42 | ||
| .set FEAT_SME2_BIT, 57 | ||
| .set FEAT_SME2_MASK, 1 << 57 | ||
| .set SVCR_PSTATE_SM_BIT, 0 | ||
|
|
||
| #if !defined(__APPLE__) | ||
|
|
@@ -22,7 +24,7 @@ | |
| #define CPU_FEATS_SYMBOL_OFFSET SYMBOL_NAME(__aarch64_cpu_features)@pageoff | ||
| #endif | ||
|
|
||
| .arch armv9-a+sme | ||
| .arch armv9-a+sme2 | ||
|
|
||
| // Utility function which calls a system's abort() routine. Because the function | ||
| // is streaming-compatible it should disable streaming-SVE mode before calling | ||
|
|
@@ -204,6 +206,163 @@ DEFINE_COMPILERRT_FUNCTION(__arm_get_current_vg) | |
| ret | ||
| END_COMPILERRT_FUNCTION(__arm_get_current_vg) | ||
|
|
||
| DEFINE_COMPILERRT_FUNCTION(__arm_sme_state_size) | ||
| .variant_pcs __arm_sme_state_size | ||
| BTI_C | ||
|
|
||
| // Test if SME is available and ZA state is 'active'. | ||
| adrp x16, CPU_FEATS_SYMBOL | ||
| ldr x16, [x16, CPU_FEATS_SYMBOL_OFFSET] | ||
| tbz x16, #FEAT_SME_BIT, 0f | ||
| mrs x16, SVCR | ||
| tbz x16, #1, 0f | ||
| mrs x16, TPIDR2_EL0 | ||
| cbnz x16, 0f | ||
sdesmalen-arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Size = HAS_FEAT_SME2 ? 96 : 32 | ||
sdesmalen-arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| adrp x16, CPU_FEATS_SYMBOL | ||
| ldr x16, [x16, CPU_FEATS_SYMBOL_OFFSET] | ||
| tst x16, #FEAT_SME2_MASK | ||
| mov w17, #32 | ||
| mov w16, #96 | ||
| csel x16, x17, x16, eq | ||
|
|
||
| // Size = Size + (SVLB * SVLB) | ||
| rdsvl x17, #1 | ||
| madd x0, x17, x17, x16 | ||
| ret | ||
|
|
||
| 0: | ||
| // Default case, 16 bytes is minimum (to encode VALID bit, multiple of 16 bytes) | ||
| mov w0, #16 | ||
| ret | ||
| END_COMPILERRT_FUNCTION(__arm_sme_state_size) | ||
|
|
||
| DEFINE_COMPILERRT_FUNCTION(__arm_sme_save) | ||
| .variant_pcs __arm_sme_save | ||
| BTI_C | ||
|
|
||
| // Clear internal state bits | ||
| stp xzr, xzr, [x0] | ||
|
|
||
| // If PTR is not 16-byte aligned, abort. | ||
| tst x0, #0xF | ||
| b.ne 3f | ||
sdesmalen-arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // If SME is not available, PSTATE.ZA = 0 or TPIDR2_EL0 != 0, return. | ||
| adrp x16, CPU_FEATS_SYMBOL | ||
| ldr x16, [x16, CPU_FEATS_SYMBOL_OFFSET] | ||
| tbz x16, #FEAT_SME_BIT, 2f | ||
| mrs x16, SVCR | ||
| tbz x16, #1, 2f | ||
| mrs x16, TPIDR2_EL0 | ||
| cbnz x16, 2f | ||
|
|
||
| # ZA or ZT0 need saving, we can now set internal VALID bit to 1 | ||
| mov w16, #1 | ||
| str x16, [x0] | ||
sdesmalen-arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| adrp x16, CPU_FEATS_SYMBOL | ||
| ldr x16, [x16, CPU_FEATS_SYMBOL_OFFSET] | ||
| tbz x16, #FEAT_SME2_BIT, 0f | ||
|
|
||
| // Store ZT0 and ZA | ||
| add x16, x0, #32 | ||
| str zt0, [x16] | ||
| add x18, x0, #96 | ||
| b 1f | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 0: | ||
| // Has SME only | ||
| add x18, x0, #32 | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1: | ||
| // Set up lazy-save (x18 = pointer to buffer) | ||
| rdsvl x17, #1 | ||
| str x18, [x0, #16]! | ||
| strh w17, [x0, #8] | ||
| stur wzr, [x0, #10] | ||
| strh wzr, [x0, #14] | ||
|
||
| msr TPIDR2_EL0, x0 | ||
| ret | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 2: | ||
| // Do nothing | ||
| ret | ||
|
|
||
| 3: | ||
| b SYMBOL_NAME(do_abort) | ||
| END_COMPILERRT_FUNCTION(__arm_sme_save) | ||
|
|
||
| DEFINE_COMPILERRT_FUNCTION(__arm_sme_restore) | ||
| .cfi_startproc | ||
| .variant_pcs __arm_sme_save | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| BTI_C | ||
|
|
||
| stp x29, x30, [sp, #-16]! | ||
| .cfi_def_cfa_offset 16 | ||
| mov x29, sp | ||
| .cfi_def_cfa w29, 16 | ||
| .cfi_offset w30, -8 | ||
| .cfi_offset w29, -16 | ||
|
|
||
| // If PTR is not 16-byte aligned, abort. | ||
| tst x0, #0xF | ||
| b.ne 3f | ||
|
|
||
| // If the VALID bit is 0, return early. | ||
| ldr x16, [x0] | ||
| tbz x16, #0, 2f | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // If SME is not available, abort. | ||
| adrp x16, CPU_FEATS_SYMBOL | ||
| ldr x16, [x16, CPU_FEATS_SYMBOL_OFFSET] | ||
| tbz x16, #FEAT_SME_BIT, 3f | ||
|
|
||
| // If TPIDR2_EL0 != nullptr, no lazy-save was committed, try to reload zt0. | ||
| mrs x16, TPIDR2_EL0 | ||
| cbnz x16, 0f | ||
|
|
||
| // If TPIDR2_EL0 == nullptr and PSTATE.ZA = 1 (<=> ZA state is 'active'), | ||
| // abort. | ||
| mrs x16, SVCR | ||
| tbnz x16, #1, 3f | ||
|
|
||
| // Restore za. | ||
| smstart za | ||
| mov x16, x0 | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| add x0, x0, #16 | ||
| bl __arm_tpidr2_restore | ||
| mov x0, x16 | ||
| msr TPIDR2_EL0, xzr | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 0: | ||
| smstart za | ||
|
|
||
| 1: | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Check if zt0 needs restoring. | ||
| adrp x16, CPU_FEATS_SYMBOL | ||
| ldr x16, [x16, CPU_FEATS_SYMBOL_OFFSET] | ||
| tbz x16, #FEAT_SME2_BIT, 2f | ||
|
|
||
| // Restore zt0. | ||
| add x16, x0, #32 | ||
| ldr zt0, [x16] | ||
|
|
||
| 2: | ||
| // Do nothing | ||
| .cfi_def_cfa wsp, 16 | ||
| ldp x29, x30, [sp], #16 | ||
| .cfi_def_cfa_offset 0 | ||
| .cfi_restore w30 | ||
| .cfi_restore w29 | ||
| ret | ||
|
|
||
| 3: | ||
| b SYMBOL_NAME(do_abort) | ||
| .cfi_endproc | ||
| END_COMPILERRT_FUNCTION(__arm_sme_restore) | ||
|
|
||
| NO_EXEC_STACK_DIRECTIVE | ||
|
|
||
| // GNU property note for BTI and PAC | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.