Skip to content

arm64: read the SME2 vector length only after the FEAT_SME2 test - #6153

Open
tesch1 wants to merge 1 commit into
OpenMathLib:developfrom
tesch1:sme2-rdsvl
Open

tesch1 wants to merge 1 commit into
OpenMathLib:developfrom
tesch1:sme2-rdsvl

Conversation

@tesch1

@tesch1 tesch1 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6150.

Before: s2_usable() computed sme2 && svcntsw() == 16. Clang treats svcntsw() as free of side effects and if-converts the expression, so RDSVL runs before the FEAT_SME2 result is tested. On a CPU without SME, RDSVL is undefined (SIGILL). This affects a static TARGET=VORTEXM4 build run on such a CPU, on the first call that reaches s2_usable(); DYNAMIC_ARCH builds select VORTEXM4 only with SME. Not tested on M1-M3 hardware.

After: the vector length is read by a noinline function with volatile inline asm, called only when FEAT_SME2 is present. Disassembly of sme_sgemm_kernel.o (Apple clang 21): sysctlbyname, cbz on the FEAT_SME2 value, then bl _s2_svl_lanes; the other RDSVL instructions are after smstart sm.

@0tomhoyt found this problem and wrote the fix in #6142 (bf16 SBGEMM); this PR takes the same approach, so that the fix can go in on its own, ahead of #6142.

Tested on M4 Pro: make with the BLAS/CBLAS tests and utest (144/144, 1564/1564).

AI assistance

AI coding tools (Claude Code) helped to prepare this PR. The change was reviewed and tested as described above.

svcntsw() has no side effects for clang, which if-converted the
expression and ran RDSVL before the FEAT_SME2 result was tested.
On a CPU without SME that is SIGILL. A noinline function with
volatile inline asm keeps RDSVL behind the test.

Fixes OpenMathLib#6150

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VORTEXM4: s2_usable() runs RDSVL before the SME2 check (SIGILL without SME)

1 participant