Design an FPGA pipeline by splitting a calculation into registered stages and understand the difference between throughput and latency.
A pipeline divides a calculation into stages separated by registers. Several data items then advance simultaneously, with each stage processing a different sample.
Separate latency from throughput
Notion
Meaning
Latency
Time between one input and its output
Throughput
Number of results produced per unit of time
Without a pipeline, one item crosses the entire logic path before capture. With four stages, it passes through four calculations in sequence. Once the pipeline is full, a result can emerge every cycle if the circuit accepts new data every cycle.
Registers generally add cycle latency, but shorten combinational paths and may permit a higher frequency. Time per sample depends on both the number of cycles and their duration.
Balance the stages
The period must cover the slowest stage and register delays. Ignoring clock skew and uncertainty gives this simplified relation:
Tclk >= Tmax_stage + Tsetup + Tcq
Tcq is the clock-to-output delay; Tsetup is the stability requirement before capture. A very deep pipeline can lose its benefit when those costs dominate logic delay. Registers also consume area.
If one stage takes 40 ns and the others 15 ns, the first still limits frequency. Reorganize the logic to bring stage delays closer together.
Keep operands from the same sample
Here is a multiplication followed by an addition without an intermediate register:
The next version separates the operations across two cycles:
P_PIPE : process(i_clk)begin if rising_edge(i_clk) then if i_rst = '1' then r_mul <= (others => '0'); r_c <= (others => '0'); o_y <= (others => '0'); else r_mul <= unsigned(i_a) * unsigned(i_b); r_c <= resize(unsigned(i_c), r_c'length); o_y <= std_logic_vector(r_mul + r_c); end if; end if;end process P_PIPE;
r_mul stores the product. r_c, an unsigned register of the same width, delays i_c by one cycle. The addition therefore uses the product and third operand from the same sample.
All signals associated with a data item must follow this delay. In the testbench, compare the output with inputs from the appropriate cycle and check the intended latency.