MathUtils: speed up Chebyshev field eval via FMA-grouped Clenshaw#15491
Open
ktf wants to merge 1 commit into
Open
MathUtils: speed up Chebyshev field eval via FMA-grouped Clenshaw#15491ktf wants to merge 1 commit into
ktf wants to merge 1 commit into
Conversation
shahor02
previously approved these changes
Jun 5, 2026
Collaborator
shahor02
left a comment
There was a problem hiding this comment.
Now Claude should rewrite the Numerical Recipes textbook!
Collaborator
|
But the formatting should be fixed. |
The Clenshaw recurrence in Chebyshev3DCalc::chebyshevEvaluation1D dominates magnetic-field evaluation in track extrapolation/fitting (~32% of the muon-qa process). The expression `array[i] + x2*b1 - b2` parses as a dependent multiply->add->subtract chain on the loop-carried b1 (~10 cyc), which the compiler cannot shorten under FP rules. Regroup as fma(x2, b1, array[i] - b2): the same value, but array[i]-b2 no longer depends on the just-updated b1, collapsing the carried chain to a single FMA latency (~4 cyc). Tail return gets fma(-x, b1, b0). Validated against the previous kernel (20M random evals): max abs diff 4.6e-5, mean 2.7e-7 (~2 ULP) -> field-equivalent to within the map's own ~1e-5 precision. Adds testChebyshev3D (reproduces a known function to 1.4e-6; overload cross-checks exact).
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.
The Clenshaw recurrence in Chebyshev3DCalc::chebyshevEvaluation1D
dominates magnetic-field evaluation in track extrapolation/fitting
(~32% of the muon-qa process). The expression
array[i] + x2*b1 - b2parses as a dependent multiply->add->subtract chain on the loop-carried
b1 (~10 cyc), which the compiler cannot shorten under FP rules.
Regroup as fma(x2, b1, array[i] - b2): the same value, but array[i]-b2
no longer depends on the just-updated b1, collapsing the carried chain
to a single FMA latency (~4 cyc). Tail return gets fma(-x, b1, b0).
Validated against the previous kernel (20M random evals): max abs diff
4.6e-5, mean 2.7e-7 (~2 ULP) -> field-equivalent to within the map's own
~1e-5 precision. Adds testChebyshev3D (reproduces a known function to
1.4e-6; overload cross-checks exact).