Skip to content

Table-based sin/cos approximation and residue-linear traversal + unrolling for mag/phase paths#63

Merged
falseywinchnet merged 1 commit into
mainfrom
ntj3qh-main/replace-sin/cos-with-approximation-in-kernel
Jun 26, 2026
Merged

Table-based sin/cos approximation and residue-linear traversal + unrolling for mag/phase paths#63
falseywinchnet merged 1 commit into
mainfrom
ntj3qh-main/replace-sin/cos-with-approximation-in-kernel

Conversation

@falseywinchnet

Copy link
Copy Markdown
Owner

Motivation

  • Reduce expensive sin/cos calls in inverse mag/phase hot loops and improve cache locality and throughput for forward/inverse mag-phase transforms.
  • Provide a fast fallback that preserves correct behavior for out-of-range phase inputs while enabling a fast path for phases in [0, 2*pi).
  • Improve performance by traversing Bruun residues in linear/native order and applying small-loop unrolling in the inverse hot path.

Description

  • Added #include <array> and new types bruun_sincos_sample and templated bruun_sincos_table<K> to precompute a power-of-two sin/cos lookup table.
  • Implemented bruun_table256_poly3_sincos and bruun_table256_poly3_sincos_f32 which perform a table lookup plus a cubic polynomial correction for remainder, and fall back to std::sin/std::cos for out-of-range phases.
  • Rewrote forward mag/phase paths to traverse residues in native linear order using IDX (improving streaming reads) and removed redundant phase-normalization code now handled by bruun_phase_atan2_mag.
  • Replaced direct std::sin/std::cos calls in inverse_mag_phase and inverse_mag_phase_f32 with the table-based approximations, and added 4-element loop unrolling to compute sin/cos for multiple bins per iteration.

Testing

  • Built the library and ran the full unit test suite; all unit tests completed successfully.
  • Ran the mag/phase correctness tests comparing round-trip forward/inverse; results matched baseline behavior.
  • Executed performance microbenchmarks for mag/phase inverse and forward hot paths; observed expected throughput improvements (benchmark runs succeeded).

Codex Task

@falseywinchnet falseywinchnet merged commit 827a30c into main Jun 26, 2026
4 checks passed
@falseywinchnet falseywinchnet deleted the ntj3qh-main/replace-sin/cos-with-approximation-in-kernel 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