Skip to content

Add FMA rewrites and fused d4 inverse codelets#36

Merged
falseywinchnet merged 1 commit into
mainfrom
inverse-fma-and-d4-fusion
Jun 21, 2026
Merged

Add FMA rewrites and fused d4 inverse codelets#36
falseywinchnet merged 1 commit into
mainfrom
inverse-fma-and-d4-fusion

Conversation

@falseywinchnet

Copy link
Copy Markdown
Owner

Summary

  • Rewrote all inverse twiddle recombinations to use MADD/MSUB instead of ADD(MUL,MUL), matching the forward path's FMA usage (NEON: 8→38 FMAs)
  • Added codelet_d4_inv_f32 (SSE2/NEON) fusing two d3_inv + norm_q_inv(q=8), keeping intermediates in registers instead of store/reload through the data array
  • Added codelet_d4_inv (AVX2+FMA) — same fusion for double-precision using __m256d intrinsics
  • Wired both into the recursive path and the schedule runner

Assembly impact

  • NEON: 1162→961 total instructions
  • SSE2: 1535→1286 total instructions
  • AVX2 d4 fusion: 2212 instructions, 55 FMAs, 330 spill/reloads (expected for 16 YMM registers)

Test plan

  • make test passes (correctness ok, c api ok, backend=neon-128)
  • Cross-compile SSE2 clean (--target=x86_64-apple-darwin -msse2 -mno-avx)
  • Cross-compile AVX2+FMA clean (--target=x86_64-apple-darwin -mavx2 -mfma)

🤖 Generated with Claude Code

Inverse twiddle recombinations used ADD(MUL,MUL) instead of MADD/MSUB,
missing FMA opportunities on every ISA. Fixed in norm_q_inv, norm2_inv_fused,
and codelet_d3_tw_res_inv for both f32 (V4F) and double (V2) paths.
NEON FMA count in the inverse schedule runner went from 8 to 38.

Added codelet_d4_inv_f32 (SSE2/NEON) and codelet_d4_inv (AVX2+FMA) that
fuse two d3_inv leaves with the q=8 norm_q_inv butterfly, keeping all
intermediate values in registers instead of storing/reloading 32 elements
through the data array. Wired into both the recursive path and the
schedule runner for both precisions.

Assembly impact: NEON total instructions 1162→961, SSE2 1535→1286.
AVX2 double d4 fusion: 2212 instructions, 55 FMAs, 330 spill/reloads
(expected for 16 YMM registers; spills hit L1 stack).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@falseywinchnet falseywinchnet merged commit fd42bca into main Jun 21, 2026
4 checks passed
@falseywinchnet falseywinchnet deleted the inverse-fma-and-d4-fusion branch June 21, 2026 09:30
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