Kyrylo Tkachov <ktkac...@nvidia.com> writes: > Hi Spencer, > >> On 28 Jul 2025, at 16:25, Spencer Abson <spencer.ab...@arm.com> wrote: >> >> Streaming-compatible functions can be compiled without SME enabled, but need >> to use "SMSTART SM" and "SMSTOP SM" to temporarily switch into the streaming >> mode of a callee. These switches are conditional on the current mode being >> opposite to the target mode, so no SME instructions are executed if SME is >> not >> available. >> >> However, in GAS, "SMSTART SM" and "SMSTOP SM" always require +sme. A call >> from a streaming-compatible function, compiled without SME enabled, to a non >> -streaming function will be rejected as: > > I guess this is an argument for allowing SMTART/SMSTOP in gas unconditionally? > Though it would need to be consistent with LLVM and we’d still need a > workaround for older binutils, so okay...
I'm not sure it would be appropriate to allow SMSTART and SMSTOP without SME. Although the instructions are used in streaming-compatible functions, their use is guarded by a runtime test that streaming mode is active (and thus SME is available). In that sense, they are really being used in blocks of SME-specific code that are embedded in a function that is PSTATE.SM-agnostic overall. If we needed to do other SME things besides SMSTART and SMSTOP then it might make sense to add SME to the assembler architecture extensions (aarch64_set_asm_isa_flags). But that would also remove some sanity checking of inline asms, and I suppose of GCC's own code. .inst seems more robust. >> Error: selected processor does not support `smstop sm'.. >> >> To work around this, we make use of the .inst directive to insert the literal >> encodings of "SMSTART SM" and "SMSTOP SM". >> >> gcc/ChangeLog: >> PR target/121028 >> * config/aarch64/aarch64-sme.md (aarch64_smstart_sm): Use the .inst >> directive if !TARGET_SME. >> (aarch64_smstop_sm): Likewise. >> >> gcc/testsuite/ChangeLog: >> PR target/121028 >> * gcc.target/aarch64/sme/call_sm_switch_1.c: Tell check-function >> -bodies not to ignore .inst directives, and replace the test for >> "smstart sm" with one for it's encoding. >> * gcc.target/aarch64/sme/call_sm_switch_11.c: Likewise. >> * gcc.target/aarch64/sme/pr121028.c: New test. >> --- >> gcc/config/aarch64/aarch64-sme.md | 12 ++++- >> .../gcc.target/aarch64/sme/call_sm_switch_1.c | 4 +- >> .../aarch64/sme/call_sm_switch_11.c | 5 +- >> .../gcc.target/aarch64/sme/pr121028.c | 46 +++++++++++++++++++ >> 4 files changed, 61 insertions(+), 6 deletions(-) >> create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/pr121028.c >> >> diff --git a/gcc/config/aarch64/aarch64-sme.md >> b/gcc/config/aarch64/aarch64-sme.md >> index 6b3f4390943..5264bf75c0b 100644 >> --- a/gcc/config/aarch64/aarch64-sme.md >> +++ b/gcc/config/aarch64/aarch64-sme.md >> @@ -62,6 +62,10 @@ >> ;; (b) they are sometimes used conditionally, particularly in streaming- >> ;; compatible code. >> ;; >> +;; To prevent the latter from upsetting the assembler, we emit the literal >> +;; encodings of "SMSTART SM" and "SMSTOP SM" when compiling without >> +;; TARGET_SME. >> +;; >> ;; ========================================================================= >> >> ;; ------------------------------------------------------------------------- >> @@ -161,7 +165,9 @@ >> (clobber (reg:VNx16BI P14_REGNUM)) >> (clobber (reg:VNx16BI P15_REGNUM))] >> "" >> - "smstart\tsm" >> + { >> + return TARGET_SME ? "smstart\tsm" : ".inst 0xd503437f"; >> + } > > Usually when we emit such .inst directives we also emit the mnemonic as an > assembly comment to aid human assembly debugging. Yeah, agreed that we should have a comment ("// smstart sm", etc.). > Ok by me with these changes, but maybe Richard is best-placed to comment on > the SME parts. LGTM too with that change. Thanks, Richard