fix: emit ARM ARM by-element operand form for NEON FMLA/FMLS - #30
Open
mohitt31 wants to merge 1 commit into
Open
fix: emit ARM ARM by-element operand form for NEON FMLA/FMLS#30mohitt31 wants to merge 1 commit into
mohitt31 wants to merge 1 commit into
Conversation
The NEON backend printed the by-element FMLA/FMLS multiplicand with the
full arrangement specifier, e.g.
fmla v11.2d, v1.2d, v3.2d[0]
The ARM ARM gives this instruction as
FMLA <Vd>.<T>, <Vn>.<T>, <Vm>.<Ts>[<index>]
i.e. the third operand carries the element type, not the arrangement, so
it has to be written "v3.d[0]". GNU as accepts the redundant form, which
is why this has gone unnoticed, but the LLVM integrated assembler rejects
it with "invalid operand for instruction". That makes every NEON kernel
fail to assemble under clang, including the documented
HOST_ARCH=apple-m1/m2/m3/m4 builds of SeisSol on macOS.
Emit the element-type form instead. This is a pure syntax change; the
encoded instruction is the same.
Verified with tests/unit_test.py arm128:
- gcc 13.3 / GNU as 2.42 (aarch64): 630/630 before and after
- clang: does not assemble before; 630/630 after (with
-ffp-contract=off; with contraction enabled one single-precision
case differs by ~1e-6 relative, which is the C reference being
fused, not the generated kernel)
Contains AI-generated content. (model: Opus 5)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this fixes
The NEON backend prints the by-element FMLA/FMLS multiplicand with the full
arrangement specifier:
The ARM ARM gives the instruction as
so the third operand carries the element type, not the arrangement, and has to
be written
v3.d[0].GNU as accepts the redundant form, which is why this has gone unnoticed. The
LLVM integrated assembler rejects it:
It affects
.2d(double) and.4s(single) alike, and reproduces on both Appleclang 21 and Homebrew clang 22.
Why it matters
Every NEON kernel fails to assemble under clang, so
HOST_ARCH=apple-m1/m2/m3/m4builds of SeisSol do not compile on macOS — theconfiguration SeisSol's own build docs recommend for Macs.
SeisSol/SeisSol#963added macOS and M1/M2 support in 2023; this is part of why it has regressed.
The change
One file,
pypspamm/codegen/architectures/arm/inlineprinter.py: a smalllaneOperand()helper that convertsv3.2dtov3.d, used only on theby-element path in
visitFma. It is a pure syntax change; the encodedinstruction is identical.
Testing
tests/unit_test.py arm128, which checks the generated kernels against areference:
So there is no regression under GNU as and clang is unblocked.
One note on the clang column: with FMA contraction left at the default, one
single-precision case differs by ~1.2e-6 relative. That is the C reference in
the test being contracted by the compiler, not the generated kernel —
-ffp-contract=offgives 630/630. The unchanged gcc column confirms the kernelsthemselves are not affected.
AI tools used
Contains AI-generated content. (model: Opus 5)