# zipcpu/dblclockfft architecture

> Architecture diagram of the GitHub repository zipcpu/dblclockfft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zipcpu/dblclockfft
- Repository: https://github.com/zipcpu/dblclockfft

## Overview

1. This repository is a configurable FFT IP generator, not a single fixed design. The central flow is: a C++ command-line generator builds an FFT configuration, emits Verilog RTL for that configuration, and the generated core is then exercised by C++ tests, RTL testbenches, and formal proofs.

2. The `sw/` directory is the code-generation layer. `fftgen.cpp` is the main entry point, supported by reusable builders and helpers such as `bldstage.cpp`, `butterfly.cpp`, `bitreverse.cpp`, `rounding.cpp`, and `softmpy.cpp`. These components assemble the FFT architecture from parameters like transform direction, precision, twiddle width, and output bit ordering.

3. The generator is designed to produce different pipeline behaviors. The README describes two major operating styles: a two-samples-per-clock mode and a one-sample-per-clock mode with configurable input spacing. That choice affects the butterfly implementation and how many multiplies are used per FFT stage.

4. The `rtl/` directory contains the Verilog implementation of the core building blocks. `fftmain.v` and `ifftmain.v` are the top-level forward/inverse FFT wrappers, while `fftstage.v`, `qtrstage.v`, and `laststage.v` represent the staged pipeline structure. This is the datapath that the generator instantiates.

5. The low-level RTL blocks map directly to arithmetic and permutation functions in the FFT. `butterfly.v`, `hwbfly.v`, `bimpy.v`, and `longbimpy.v` cover multiply-accumulate and butterfly math; `bitreverse.v` handles output ordering; `convround.v` handles rounding/conversion; and `windowfn.v` suggests optional preprocessing or windowing support.

6. The `bench/cpp/` subtree is the software verification and benchmarking environment. It contains C++ testbenches for individual blocks and full designs such as `fft_tb.cpp`, `ifft_tb.cpp`, `butterfly_tb.cpp`, `fftstage_tb.cpp`, `laststage_tb.cpp`, `mpy_tb.cpp`, and `bitreverse_tb.cpp`. These act as the golden-model side of the verification flow.

7. The C++ bench code also includes small support utilities and plotting hooks. `twoc.cpp/.h` appear to provide numeric/two’s-complement helpers, and the `.m` files indicate MATLAB/Octave scripts used to inspect or plot simulation output. This makes the software bench a numerical reference layer, not just a compile test.

8. The `bench/rtl/` directory holds a hardware testbench for the Verilog side. The presence of `ifft_tb.v` indicates direct RTL simulation of the inverse FFT path, likely used to confirm the generated core behaves correctly in a hardware-like environment.

9. The `bench/formal/` directory is the formal-verification layer. The `.sby` files show the design is checked with SymbiYosys, and the `abs_*.v` files provide abstract models/specifications for blocks like multipliers. This layer focuses on proving local correctness of modules such as `bimpy`, `butterfly`, `fftstage`, `hwbfly`, `laststage`, `qtrstage`, and `windowfn`.

10. The `doc/` tree contains the published specification and licensing material. `spec.pdf` and its source under `doc/src/` document the architecture and expected behavior, which is important because this project is intended as generated IP with a defined external contract.

11. The repo is organized around a clear boundary between generation and implementation. The software generator defines the FFT instance, the RTL directory defines reusable hardware blocks, and the bench/formal trees validate those blocks against numerical expectations and formal properties.

12. A key architectural constraint is that the core does not include overflow protection. That means the caller or integrator must choose precision conservatively, and this assumption affects how the generated core is parameterized and validated.

13. Overall, this repository is best diagrammed as a configurable FFT toolchain: parameterized C++ generation on one side, a composable Verilog pipeline in the middle, and three validation paths around it—C++ reference simulation, RTL simulation, and formal proof.

Main entry points: [`rtl/fftstage.v`](https://github.com/zipcpu/dblclockfft/blob/master/rtl/fftstage.v) (FFT Stage), [`sw/bldstage.cpp`](https://github.com/zipcpu/dblclockfft/blob/master/sw/bldstage.cpp) (Stage Builder), [`sw/fftgen.cpp`](https://github.com/zipcpu/dblclockfft/blob/master/sw/fftgen.cpp) (FFT Gen), [`rtl/butterfly.v`](https://github.com/zipcpu/dblclockfft/blob/master/rtl/butterfly.v) (Butterfly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gen["Generator"]
  node_fftgen["FFT Gen<br/>C++ CLI generator<br/>[fftgen.cpp]"]
  node_bldstage["Stage Builder<br/>C++ stage assembly<br/>[bldstage.cpp]"]
  node_butterfly_sw["Butterfly Build<br/>C++ datapath model<br/>[butterfly.cpp]"]
  node_bitreverse_sw["Order Build<br/>C++ ordering model<br/>[bitreverse.cpp]"]
  node_rounding_sw["Rounding Build<br/>C++ quantization model<br/>[rounding.cpp]"]
  node_softmpy["Soft Multiply<br/>C++ arithmetic helper<br/>[softmpy.cpp]"]
end

subgraph group_rtl["RTL Core"]
  node_fftmain["FFT Top<br/>Verilog wrapper<br/>[fftmain.v]"]
  node_ifftmain["IFFT Top<br/>Verilog wrapper<br/>[ifftmain.v]"]
  node_fftstage["FFT Stage<br/>Verilog pipeline<br/>[fftstage.v]"]
  node_qtrstage["Quarter Stage<br/>Verilog pipeline<br/>[qtrstage.v]"]
  node_laststage["Last Stage<br/>Verilog pipeline<br/>[laststage.v]"]
  node_butterfly_rtl["Butterfly<br/>Verilog arithmetic<br/>[butterfly.v]"]
  node_hwbfly["HW Butterfly<br/>Verilog arithmetic<br/>[hwbfly.v]"]
  node_bimpy["Bimpy<br/>Verilog multiplier<br/>[bimpy.v]"]
  node_longbimpy["Long Bimpy<br/>Verilog multiplier<br/>[longbimpy.v]"]
  node_bitreverse_rtl["Bit Reverse<br/>Verilog permutation<br/>[bitreverse.v]"]
  node_convround["Conv Round<br/>Verilog conversion<br/>[convround.v]"]
  node_windowfn["Window Fn<br/>Verilog preproc<br/>[windowfn.v]"]
end

subgraph group_bench["Verification"]
  node_cppbench["C++ Benc​h<br/>software verification"]
  node_rtlbench["RTL Bench<br/>hardware testbench<br/>[ifft_tb.v]"]
  node_formalbench["Formal Suite<br/>formal verification"]
end

subgraph group_doc["Docs"]
  node_specdoc["Spec<br/>documentation<br/>[spec.pdf]"]
end

node_fftgen -->|"builds"| node_bldstage
node_bldstage -->|"configures"| node_butterfly_sw
node_bldstage -->|"orders"| node_bitreverse_sw
node_bldstage -->|"quantizes"| node_rounding_sw
node_bldstage -->|"uses"| node_softmpy
node_fftgen -->|"emits"| node_fftmain
node_fftgen -->|"emits"| node_ifftmain
node_fftmain -->|"instantiates"| node_fftstage
node_ifftmain -->|"instantiates"| node_fftstage
node_fftstage -->|"includes"| node_qtrstage
node_fftstage -->|"terminates"| node_laststage
node_fftstage -->|"computes"| node_butterfly_rtl
node_butterfly_rtl -->|"specializes"| node_hwbfly
node_butterfly_rtl -->|"multiplies"| node_bimpy
node_bimpy -->|"widens"| node_longbimpy
node_fftstage -->|"permutes"| node_bitreverse_rtl
node_fftstage -->|"rounds"| node_convround
node_fftmain -.->|"optionally preprocesses"| node_windowfn
node_cppbench -->|"verifies"| node_fftgen
node_cppbench -->|"models"| node_butterfly_rtl
node_cppbench -->|"models"| node_bitreverse_rtl
node_rtlbench -->|"simulates"| node_ifftmain
node_formalbench -->|"proves"| node_bimpy
node_formalbench -->|"proves"| node_butterfly_rtl
node_formalbench -->|"proves"| node_fftstage
node_formalbench -->|"proves"| node_windowfn
node_specdoc -.->|"defines"| node_fftgen
node_specdoc -.->|"describes"| node_fftmain

click node_fftgen "https://github.com/zipcpu/dblclockfft/blob/master/sw/fftgen.cpp"
click node_bldstage "https://github.com/zipcpu/dblclockfft/blob/master/sw/bldstage.cpp"
click node_butterfly_sw "https://github.com/zipcpu/dblclockfft/blob/master/sw/butterfly.cpp"
click node_bitreverse_sw "https://github.com/zipcpu/dblclockfft/blob/master/sw/bitreverse.cpp"
click node_rounding_sw "https://github.com/zipcpu/dblclockfft/blob/master/sw/rounding.cpp"
click node_softmpy "https://github.com/zipcpu/dblclockfft/blob/master/sw/softmpy.cpp"
click node_fftmain "https://github.com/zipcpu/dblclockfft/blob/master/rtl/fftmain.v"
click node_ifftmain "https://github.com/zipcpu/dblclockfft/blob/master/rtl/ifftmain.v"
click node_fftstage "https://github.com/zipcpu/dblclockfft/blob/master/rtl/fftstage.v"
click node_qtrstage "https://github.com/zipcpu/dblclockfft/blob/master/rtl/qtrstage.v"
click node_laststage "https://github.com/zipcpu/dblclockfft/blob/master/rtl/laststage.v"
click node_butterfly_rtl "https://github.com/zipcpu/dblclockfft/blob/master/rtl/butterfly.v"
click node_hwbfly "https://github.com/zipcpu/dblclockfft/blob/master/rtl/hwbfly.v"
click node_bimpy "https://github.com/zipcpu/dblclockfft/blob/master/rtl/bimpy.v"
click node_longbimpy "https://github.com/zipcpu/dblclockfft/blob/master/rtl/longbimpy.v"
click node_bitreverse_rtl "https://github.com/zipcpu/dblclockfft/blob/master/rtl/bitreverse.v"
click node_convround "https://github.com/zipcpu/dblclockfft/blob/master/rtl/convround.v"
click node_windowfn "https://github.com/zipcpu/dblclockfft/blob/master/rtl/windowfn.v"
click node_cppbench "https://github.com/zipcpu/dblclockfft/tree/master/bench/cpp"
click node_rtlbench "https://github.com/zipcpu/dblclockfft/blob/master/bench/rtl/ifft_tb.v"
click node_formalbench "https://github.com/zipcpu/dblclockfft/tree/master/bench/formal"
click node_specdoc "https://github.com/zipcpu/dblclockfft/blob/master/doc/spec.pdf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_fftgen,node_bldstage,node_butterfly_sw,node_bitreverse_sw,node_rounding_sw,node_softmpy toneBlue
class node_fftmain,node_ifftmain,node_fftstage,node_qtrstage,node_laststage,node_butterfly_rtl,node_hwbfly,node_bimpy,node_longbimpy,node_bitreverse_rtl,node_convround,node_windowfn toneAmber
class node_cppbench,node_rtlbench,node_formalbench toneMint
class node_specdoc toneRose
```

## Components

### Generator

C++ FFT IP generation layer

- [FFT Gen](https://github.com/zipcpu/dblclockfft/blob/master/sw/fftgen.cpp): C++ CLI generator · Main entry point that builds a parameterized FFT instance and emits Verilog. · `sw/fftgen.cpp`
- [Stage Builder](https://github.com/zipcpu/dblclockfft/blob/master/sw/bldstage.cpp): C++ stage assembly · Assembles pipeline stages from FFT parameters and operating mode. · `sw/bldstage.cpp`
- [Butterfly Build](https://github.com/zipcpu/dblclockfft/blob/master/sw/butterfly.cpp): C++ datapath model · Build-time logic for butterfly structure and pipeline behavior. · `sw/butterfly.cpp`
- [Order Build](https://github.com/zipcpu/dblclockfft/blob/master/sw/bitreverse.cpp): C++ ordering model · Build-time configuration for bit-reversal and output ordering. · `sw/bitreverse.cpp`
- [Rounding Build](https://github.com/zipcpu/dblclockfft/blob/master/sw/rounding.cpp): C++ quantization model · Build-time control for rounding and numeric conversion behavior. · `sw/rounding.cpp`
- [Soft Multiply](https://github.com/zipcpu/dblclockfft/blob/master/sw/softmpy.cpp): C++ arithmetic helper · Software-side multiply helper used by the generator and numerical modeling. · `sw/softmpy.cpp`

### RTL Core

Reusable Verilog datapath and wrappers

- [FFT Top](https://github.com/zipcpu/dblclockfft/blob/master/rtl/fftmain.v): Verilog wrapper · Forward FFT top-level wrapper around the staged core. · `rtl/fftmain.v`
- [IFFT Top](https://github.com/zipcpu/dblclockfft/blob/master/rtl/ifftmain.v): Verilog wrapper · Inverse FFT top-level wrapper around the staged core. · `rtl/ifftmain.v`
- [FFT Stage](https://github.com/zipcpu/dblclockfft/blob/master/rtl/fftstage.v): Verilog pipeline · Main staged pipeline element used by the generated core. · `rtl/fftstage.v`
- [Quarter Stage](https://github.com/zipcpu/dblclockfft/blob/master/rtl/qtrstage.v): Verilog pipeline · Specialized stage used in the FFT pipeline structure. · `rtl/qtrstage.v`
- [Last Stage](https://github.com/zipcpu/dblclockfft/blob/master/rtl/laststage.v): Verilog pipeline · Terminal pipeline stage for the generated transform. · `rtl/laststage.v`
- [Butterfly](https://github.com/zipcpu/dblclockfft/blob/master/rtl/butterfly.v): Verilog arithmetic · Butterfly datapath with multiply-accumulate behavior. · `rtl/butterfly.v`
- [HW Butterfly](https://github.com/zipcpu/dblclockfft/blob/master/rtl/hwbfly.v): Verilog arithmetic · Hardware butterfly variant used in the core datapath. · `rtl/hwbfly.v`
- [Bimpy](https://github.com/zipcpu/dblclockfft/blob/master/rtl/bimpy.v): Verilog multiplier · Multiplier block used by butterfly and FFT arithmetic. · `rtl/bimpy.v`
- [Long Bimpy](https://github.com/zipcpu/dblclockfft/blob/master/rtl/longbimpy.v): Verilog multiplier · Wider multiplier variant for higher precision arithmetic. · `rtl/longbimpy.v`
- [Bit Reverse](https://github.com/zipcpu/dblclockfft/blob/master/rtl/bitreverse.v): Verilog permutation · Output ordering/permutation block used by the generated core. · `rtl/bitreverse.v`
- [Conv Round](https://github.com/zipcpu/dblclockfft/blob/master/rtl/convround.v): Verilog conversion · Rounding and conversion logic for fixed-point results. · `rtl/convround.v`
- [Window Fn](https://github.com/zipcpu/dblclockfft/blob/master/rtl/windowfn.v): Verilog preproc · Optional preprocessing or windowing function block. · `rtl/windowfn.v`

### Verification

C++ simulation, RTL simulation, and formal checks

- [C++ Benc​h](https://github.com/zipcpu/dblclockfft/tree/master/bench/cpp): software verification · Reference-model and benchmark environment for generated FFT designs. · `bench/cpp`
- [RTL Bench](https://github.com/zipcpu/dblclockfft/blob/master/bench/rtl/ifft_tb.v): hardware testbench · Verilog simulation environment for exercising the inverse FFT path. · `bench/rtl/ifft_tb.v`
- [Formal Suite](https://github.com/zipcpu/dblclockfft/tree/master/bench/formal): formal verification · SymbiYosys proofs and abstract models for core RTL blocks. · `bench/formal`

### Docs

Specification and licensing material

- [Spec](https://github.com/zipcpu/dblclockfft/blob/master/doc/spec.pdf): documentation · Published specification and source documentation for the generated IP contract. · `doc/spec.pdf`

## Connections

- FFT Gen → Stage Builder: builds · Generator delegates stage assembly to reusable builders.
- Stage Builder → Butterfly Build: configures · Stage builder selects butterfly structure and operating mode.
- Stage Builder → Order Build: orders · Build logic determines output ordering behavior.
- Stage Builder → Rounding Build: quantizes · Build logic sets rounding and conversion policy.
- Stage Builder → Soft Multiply: uses · Generator relies on arithmetic helpers for modeling and emission.
- FFT Gen → FFT Top: emits · The generator produces the forward FFT wrapper and core configuration.
- FFT Gen → IFFT Top: emits · The generator produces the inverse FFT wrapper and core configuration.
- FFT Top → FFT Stage: instantiates · Top-level forward design is built from staged pipeline blocks.
- IFFT Top → FFT Stage: instantiates · Top-level inverse design is built from staged pipeline blocks.
- FFT Stage → Quarter Stage: includes · Pipeline structure includes specialized quarter-stage logic.
- FFT Stage → Last Stage: terminates · Pipeline structure ends with the last-stage block.
- FFT Stage → Butterfly: computes · Stage datapath is centered on butterfly arithmetic.
- Butterfly → HW Butterfly: specializes · Hardware butterfly variant supports the core math path.
- Butterfly → Bimpy: multiplies · Butterfly arithmetic depends on multiplier blocks.
- Bimpy → Long Bimpy: widens · Long multiplier variant covers higher-width arithmetic cases.
- FFT Stage → Bit Reverse: permutes · Stage/output flow uses bit-reversal ordering when required.
- FFT Stage → Conv Round: rounds · Stage output passes through fixed-point rounding/conversion.
- FFT Top → Window Fn: optionally preprocesses · Forward path can include windowing or preprocessing.
- C++ Benc​h → FFT Gen: verifies · Software benches exercise generated configurations against numerical references.
- C++ Benc​h → Butterfly: models · C++ testbenches cover individual arithmetic blocks and full FFTs.
- C++ Benc​h → Bit Reverse: models · C++ tests check permutation and ordering behavior.
- RTL Bench → IFFT Top: simulates · RTL testbench runs direct hardware simulation of the inverse FFT path.
- Formal Suite → Bimpy: proves · Formal proofs cover multiplier correctness using abstractions.
- Formal Suite → Butterfly: proves · Formal suite checks butterfly-level arithmetic properties.
- Formal Suite → FFT Stage: proves · Formal suite checks staged pipeline behavior.
- Formal Suite → Window Fn: proves · Formal suite includes optional preprocessing/windowing properties.
- Spec → FFT Gen: defines · Documentation specifies the configurable generator contract and assumptions.
- Spec → FFT Top: describes · Spec documents the expected externally visible FFT/IP behavior.
