Skip to content

bench: spectral-analysis perf spike (window asm ladder + pipeline profile)#82

Open
tfcollins wants to merge 15 commits into
mainfrom
bench/bh-window-asm
Open

bench: spectral-analysis perf spike (window asm ladder + pipeline profile)#82
tfcollins wants to merge 15 commits into
mainfrom
bench/bh-window-asm

Conversation

@tfcollins

Copy link
Copy Markdown
Collaborator

Summary

Exploratory, self-contained performance spike under bench/ (no src/ changes) investigating how fast genalyzer's spectral-analysis math can go, down to hand-tuned AVX-256 assembly. Two pieces:

  1. Blackman-Harris window optimization ladder (bench/bh_window_bench.cpp, bench/bh_window_asm.S): T0 baseline (std::cos ×3/sample) → T1 no-transcendentals (phasor recurrence) → T2 AVX-256 intrinsics → T3 hand-tuned asm → T4 multithreaded. Each tier verified vs T0 (max-abs-err < 1e-9).
  2. Real-pipeline profile (bench/profile/): stage breakdown of the actual fft() path.

Findings

  • Window: the ~8–10× single-core speedup comes entirely from killing the transcendentals (T0→T1). SIMD (T2) and hand-tuned assembly (T3) add essentially nothing — once the data-independent window is precomputed, the apply loop is memory-bandwidth-bound. Multicore (T4) only wins at large nfft+navg.
  • Pipeline profile (the bigger result): with averaging (navg>1), reduce_and_scale — the per-bin std::arg(atan2) + std::polar(sincos) stage — is 47–68% of the entire transform, 1.5–4.6× the FFT itself. Since analysis consumes mean-square magnitude and only reads phase at a handful of tone bins, most of those navg×nfft atan2 calls appear to be wasted work. This is the next optimization target.

Build/run: bench/build.sh && bench/bh_window_bench. Details in bench/README.md, bench/profile/PROFILE.md, and the spec/plan/session-state docs under docs/superpowers/.

Test Plan

  • All tier correctness gates pass (anchor + per-tier vs T0, incl. renorm-coverage)
  • No src/ modifications (profiling instrumentation was temporary, reverted)
  • Reviewer sanity-check of the AVX-256 asm kernel and profiling methodology

Note: throwaway research spike for measurement/learning, not intended as production code.

tfcollins added 15 commits June 19, 2026 20:36
Adds bh_window_t4 which precomputes the Blackman-Harris window once on
the calling thread then dispatches the asm apply kernel across NTHREADS=6
worker threads.  Two partition strategies are used: row-partitioning when
navg >= 6, and sample-range partitioning otherwise.  Also fixes a subtle
TLS capture bug: thread_local statics are not captured by [&] in lambdas
(each thread resolves them via its own TLS slot), so sw.data() is
snapshotted into a plain pointer before threads are spawned.
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