Skip to content

[fft] AVX2 Shoup butterflies with runtime dispatch - #65

Open
devin-ai-integration[bot] wants to merge 3 commits into
masterfrom
devin/1785103226-simd-ntt
Open

[fft] AVX2 Shoup butterflies with runtime dispatch#65
devin-ai-integration[bot] wants to merge 3 commits into
masterfrom
devin/1785103226-simd-ntt

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Vectorizes the hot NTT loops for 32-bit prime moduli using Shoup multiplication (precomputed quotients w' = floor(w·2^32 / MOD) stored alongside rt/inv_rt), avoiding Montgomery form entirely: data stays in the normal residue representation, lazily in [0, 2·MOD) between passes and normalized back to [0, MOD) on a transform's final pass — outputs are bit-identical to the scalar path.

New AVX2 kernels in fft_core (gated by ntt_simd<num>, true for modnum<MOD> with MOD < 2^30 on x86):

  • forward_simd / inverse_simd: butterflies at k >= 8 are 8-wide (mul_shoup = mulhi32 + 2 mullo, lazy_reduce = min_epu32(x, x - lim)); the k < 8 tail stays scalar Shoup.
  • scale_simd: constant-multiply, used by fft_engine::finish's 1/n scale for assign ops (finish_linear regains an assign fast-path so the cut fixup doesn't force the scalar cut_op route).
  • twiddle_simd: the b[i] = coeffs[i] * rt[n+i] pass in extend.

The kernels carry [[gnu::target("avx2")]] and are selected at runtime via __builtin_cpu_supports("avx2"), so no special compile flags are needed and non-x86 / non-AVX2 / other value types (goldilocks, cnum, dynamic modnum) keep the existing scalar loops untouched.

Measured (g++ -O2, no arch flags, N=2^18): isolated butterflies ~0.58 → ~0.20 ns/weighted-op (~2.8×); end-to-end multipoint eval 325 → ~233 ms (−29%), interpolation 455 → ~337 ms (−26%). Remaining scalar hot loops are the variable×variable pointwise mul/mul2 passes, which Shoup can't cover (they'd need Montgomery-domain transforms).

Link to Devin session: https://app.devin.ai/sessions/44c622b53d88445c9431863199c4fe7b
Requested by: @ecnerwala


Open in Devin Review (Beta)

Co-Authored-By: Andrew He <he.andrew.mail@gmail.com>
@ecnerwala ecnerwala self-assigned this Jul 26, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown

GCC Code Coverage Report

📂 Overall coverage

Metric Coverage
Lines 🟡 7595/9420 (80.6%)
Functions 🟡 987/1106 (89.2%)
Branches 🟡 6177/7925 (77.9%)

@beta-devin-ai-integration beta-devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review (Beta)

devin-ai-integration Bot and others added 2 commits July 27, 2026 02:29
Co-Authored-By: Andrew He <he.andrew.mail@gmail.com>
Co-Authored-By: Andrew He <he.andrew.mail@gmail.com>
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.

1 participant