Module 7: Advanced RTL Design Techniques · 7.2 Arithmetic Circuits in RTL

Pipelining a Wide Adder

Module 5 introduced the fundamental concepts of pipelining. Pipelines trade latency for increased throughput by inserting register boundaries between combinational logic stages. A common application involves splitting a 64-bit adder when its carry chain cannot achieve timing closure within a single clock cycle.

In wide adders, carry propagation ripples through long gate paths. Rather than redesigning the basic adder architecture, engineers segment the carry chain across multiple pipeline stages. This technique cuts the critical path length in half, allowing the circuit to achieve higher operating frequencies.

Incorrect Carry-Chain Segmentation

A common mistake involves registering operand inputs without preserving the intermediate carry-out bit:

// Defective implementation: fails to propagate the intermediate carry bit across clock cycles
always @(posedge clk) begin
    a_hi_reg <= a[63:32];
    b_hi_reg <= b[63:32];
    sum_lo   <= a[31:0] + b[31:0];   // Lower half calculated in stage 1
end

always @(posedge clk) begin
    sum_hi <= a_hi_reg + b_hi_reg;   // Upper half calculated in stage 2 without carry-in
end

The upper adder stage requires the carry-out generated by the lower adder stage. Because the code fails to register this intermediate carry bit, the upper half calculates incorrect sums whenever the lower 32 bits generate a carry.

Correct Carry-Chain Pipeline Architecture

A functional pipelined adder registers the intermediate carry bit alongside the lower sum bits:

`timescale 1ns / 1ps
`default_nettype none

module pipelined_adder_64 (
    input  wire        clk,
    input  wire [63:0] a, b,
    output reg  [63:0] sum,
    output reg         cout
);
    // Stage 1 registers: calculate lower 32 bits and capture intermediate carry
    reg [31:0]  sum_lo_reg;
    reg         carry_reg;
    reg [63:32] a_hi_reg, b_hi_reg;

    always @(posedge clk) begin
        {carry_reg, sum_lo_reg} <= a[31:0] + b[31:0];
        a_hi_reg <= a[63:32];
        b_hi_reg <= b[63:32];
    end

    // Stage 2 registers: calculate upper 32 bits using registered carry-in
    always @(posedge clk) begin
        {cout, sum[63:32]} <= a_hi_reg + b_hi_reg + carry_reg;
        sum[31:0]          <= sum_lo_reg;   // Propagate lower sum to maintain temporal alignment
    end
endmodule

The register carry_reg captures the lower carry-out bit. On the subsequent clock edge, stage 2 uses carry_reg as the carry-in for the upper 32-bit addition. The lower sum bits pass through register sum_lo_reg to ensure that both halves of the 64-bit result align at the output:

Pipelined adder: the carry crosses the register boundary with the lower sum
Figure 1: Pipelined adder with the carry registered between stages

Timing and Latency Analysis

Each pipeline stage evaluates only 32 bits of carry logic instead of 64 bits. Reducing the carry-chain length shortens propagation delay significantly. This reduction creates timing margin, enabling higher clock frequencies at the expense of one clock cycle of latency.

Designers can extend this pattern to divide a 64-bit adder into four 16-bit pipeline stages. High-performance processors use this technique to achieve gigahertz clock speeds.

Verification Exercise

Extend the 2-stage adder into a 4-stage pipeline containing four 16-bit adders. Verify that input operands traverse all four stages and produce correct outputs four clock cycles later.

View Solution
`timescale 1ns / 1ps
`default_nettype none

module pipelined_adder_64_4stage (
    input  wire        clk,
    input  wire [63:0] a, b,
    output reg  [63:0] sum,
    output reg         cout
);
    // Stage 1 pipeline registers
    reg [15:0] s1_sum0;            reg s1_c;
    reg [47:0] s1_a_rest, s1_b_rest;

    // Stage 2 pipeline registers
    reg [31:0] s2_sum;             reg s2_c;
    reg [31:0] s2_a_rest, s2_b_rest;

    // Stage 3 pipeline registers
    reg [47:0] s3_sum;             reg s3_c;
    reg [15:0] s3_a_rest, s3_b_rest;

    always @(posedge clk) begin
        // Stage 1: bits [15:0]
        {s1_c, s1_sum0} <= a[15:0] + b[15:0];
        s1_a_rest <= a[63:16]; s1_b_rest <= b[63:16];

        // Stage 2: bits [31:16]
        {s2_c, s2_sum[31:16]} <= s1_a_rest[15:0] + s1_b_rest[15:0] + s1_c;
        s2_sum[15:0] <= s1_sum0;
        s2_a_rest <= s1_a_rest[47:16]; s2_b_rest <= s1_b_rest[47:16];

        // Stage 3: bits [47:32]
        {s3_c, s3_sum[47:32]} <= s2_a_rest[15:0] + s2_b_rest[15:0] + s2_c;
        s3_sum[31:0] <= s2_sum;
        s3_a_rest <= s2_a_rest[31:16]; s3_b_rest <= s2_b_rest[31:16];

        // Stage 4: bits [63:48]
        {cout, sum[63:48]} <= s3_a_rest + s3_b_rest + s3_c;
        sum[47:0] <= s3_sum;
    end
endmodule

Applying test stimulus a = 64'hFFFF_FFFF_FFFF_FFFF and b = 64'h0000_0000_0000_0001 forces a carry transition across all four stages. The output generates sum = 64'h0 with cout = 1 exactly 4 clock cycles later.

Pipelining wide adders requires registering both intermediate data slices and carry-out bits. The next article applies these pipelining methods to hardware multipliers.

← Saturating Arithmetic Pipelining a Multiplier →