Skip to content

Replace production phase extractor with slope-linear Q512 tables#68

Merged
falseywinchnet merged 1 commit into
mainfrom
zgi5lb-main/refactor-bfft-phase-path-with-slope-linear-extraction
Jun 27, 2026
Merged

Replace production phase extractor with slope-linear Q512 tables#68
falseywinchnet merged 1 commit into
mainfrom
zgi5lb-main/refactor-bfft-phase-path-with-slope-linear-extraction

Conversation

@falseywinchnet

Copy link
Copy Markdown
Owner

Motivation

  • Replace machine-dependent tree/vec phase paths with a scalar-friendly, cache-resident slope-linear first-octant extractor (Q=512) specialized for float and double to improve portability and L1 residency.
  • Generate all hot-table constants offline at high precision with mpmath and embed them as aligned, constexpr data to avoid runtime trig calls and range-dependent behavior.
  • Keep the inverse sin/cos table path intact and NaN-safe while ensuring forward mag/phase conversion is dense and sequential over standard bin order.
  • Add correctness and benchmark infrastructure to validate accuracy and performance of the new slope-linear paths.

Description

  • Added a small generic table type and specializations in src/detail/generated/bruun_phase_slope_tables.hpp for bruun_phase_slope_tables<float,128,512> and bruun_phase_slope_tables<double,256,512> with alignas(64) constants and a std::uint8_t slope_to_leaf[513] map.
  • Implemented bruun_phase_slope_leaf and a generic bruun_phase_first_octant_slope_linear<T,Leaves,Q> function plus type-specific wrappers bruun_phase_first_octant and bruun_phase_first_octant_f32 and float overloads of bruun_fused_madd/bruun_fused_msub in src/detail/bruun_kernel.hpp.
  • Replaced tree/vec production first-octant and pair/SIMD wrappers on the hot path so bruun_phase_atan2_mag / bruun_phase_atan2_mag_f32 now use the slope-linear tables and quadrant repair; the forward mag/phase conversion loop was kept sequential over standard-order bins in convert_standard_complex_to_mag_phase.
  • Added tools/gen_phase_slope_tables.py (mpmath, 100 dps) to regenerate tables, updated examples/atan2_benchmark.cpp labels to the new slope paths, added examples/audio_magphase_roundtrip_benchmark.cpp, and added a dense slope accuracy test check_slope_phase_accuracy in tests/correctness.cpp plus a relaxed mag/phase tolerance in tests/api_c.c to match the double target.

Testing

  • Built the project with cmake -S . -B build && cmake --build build -j and the build completed successfully.
  • Ran unit/regression tests with ctest --test-dir build --output-on-failure and all tests passed (reported 2 tests in the CI run: correctness and api_c).
  • Executed the phase benchmark ./build/atan_vectoring_network_experiment 4194304 which produced: bfft slope256 linear double: 0.260033 s, 16.130 Mphase/s, bfft slope128 linear float: 0.283724 s, 14.783 Mphase/s, and bfft table sincos: 0.146617 s, 28.607 Mpair/s.
  • Executed the audio round-trip benchmark ./build/audio_magphase_roundtrip_benchmark 2048 4096 which produced split timings and accuracy metrics including magphase fwd+inv 0.594445 s, MSE 1.2865420194109656e-20, SNR 193.138900 dB, and max_abs 2.043787084016202e-10.

Codex Task

@falseywinchnet falseywinchnet merged commit 02b1a34 into main Jun 27, 2026
4 checks passed
@falseywinchnet falseywinchnet deleted the zgi5lb-main/refactor-bfft-phase-path-with-slope-linear-extraction branch June 27, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant