#codegen #proc-macro #fft #simd

macro oxifft-codegen

Procedural macro crate for OxiFFT codelet generation

4 releases

new 0.1.3 Feb 12, 2026
0.1.2 Jan 26, 2026
0.1.1 Jan 15, 2026
0.1.0 Jan 12, 2026

#107 in #fft

49 downloads per month
Used in 3 crates (via oxifft)

Apache-2.0

46KB
965 lines

oxifft-codegen

Procedural macro crate for OxiFFT codelet generation.

Overview

This crate replaces FFTW's OCaml-based genfft code generator with Rust procedural macros. It generates highly optimized FFT kernels (codelets) at compile time.

Features

  • Compile-time code generation: Zero runtime overhead
  • Optimized kernels: Common subexpression elimination, strength reduction
  • Multiple sizes: Support for sizes 2, 4, 8, 16, 32, 64
  • Twiddle variants: Both non-twiddle (base case) and twiddle codelets
  • SIMD-aware: Can generate SIMD-specific code patterns

Codelet Types

Non-Twiddle Codelets (notw)

Base case FFT kernels that don't require twiddle factors. Used at the leaves of the FFT recursion.

use oxifft_codegen::gen_notw_codelet;

// Generates codelet_notw_8 function
gen_notw_codelet!(8);

Twiddle Codelets

FFT kernels that apply twiddle factors as part of the Cooley-Tukey recursion.

use oxifft_codegen::gen_twiddle_codelet;

// Generates codelet_twiddle_4 function
gen_twiddle_codelet!(4);

SIMD Codelets

Architecture-specific SIMD-optimized kernels.

use oxifft_codegen::gen_simd_codelet;

// Generates SIMD-optimized size-8 codelet
gen_simd_codelet!(8);

Code Generation Strategy

The codelet generator follows FFTW's approach:

  1. Symbolic representation: Build a DAG of FFT operations
  2. Optimization passes:
    • Common subexpression elimination (CSE)
    • Strength reduction (replace multiplications with additions where possible)
    • Dead code elimination
  3. Code emission: Generate Rust code with optimal instruction ordering

Supported Sizes

Size Non-Twiddle Twiddle SIMD
2 Planned
4 Planned
8 Planned
16 Planned Planned
32 Planned Planned
64 Planned Planned

Implementation Notes

  • Uses proc-macro2, quote, and syn for macro implementation
  • Generated code is generic over the Float trait (f32/f64)
  • Follows FFTW's codelet naming conventions for compatibility

License

Same as the parent OxiFFT project.

Dependencies

~125–510KB
~12K SLoC