[fft] Add fused graeffe engine primitive - #87
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Andrew He <he.andrew.mail@gmail.com>
devin-ai-integration
Bot
force-pushed
the
devin/1786977962-fused-graeffe
branch
from
August 17, 2026 16:47
c6d77ef to
095004b
Compare
GCC Code Coverage Report📂 Overall coverage
|
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.
Summary
Adds
E::graeffe(t, n) -> productto the engine contract: the size-n/2 even half ofA(x) * A(-x)(one Graeffe/root-squaring step), semanticallydownsample(mul(t, negate_arg(t, n), n), n/2, false)but fused so engines can skip materializing the negated transform, the full-size pointwise product, and the separate downsample pass.The fusion exploits that the product takes the same value
A(w) A(-w)at the paired entries2u, 2u+1(which holdAat+-win the bit-reversed convention):ntt:p[u] = t[2u] * t[2u+1]— one mult per output, no halving, noinv_rttwist.real: eachA(w) A(-w)is already a plain spectrum value of the halved (real) result, so the pass computes(x + w y)(x - w y)per packed entry and repacks adjacent pairs with oneretangleper output (mul'sretangledegenerates sincep0 == p1).split: inlines the negate shuffle (b[i] = t[i^1]) and the even-half average intomul_impl's conjugate-symmetry unpacking pass.crtdelegates per prime; the algebra wrappers (matrix/trunc/*_stable) use the generic composition, which stays correct for the non-commutative case (the fused single-product form assumes commutativity).Call sites switched:
packed_bivariate::advance(the ps_compose Graeffe loop;negate_argis still computed there since the caller needs the transform ofQ(-x, y)) and theQ <- even part of Q(x) Q(-x)update inkth_term_of_rational_function. This saves O(n) work per level/iteration — a constant-factor win on the lower-order pointwise passes, not on the n log^2 n transform term.New
graeffeTEMPLATE_TEST_CASE covers all base engines at n = 2, 16, 64 against the slow product's even coefficients mod x^n - 1 (121 tests pass).Link to Devin session: https://app.devin.ai/sessions/7d41aa62f31e4620807608a6e6afcc94
Requested by: @ecnerwala