CDC Course / Module 4: Asynchronous FIFO Design
Lesson 4.2

The Asynchronous FIFO Architecture

Everything in this module culminates here. An asynchronous FIFO allows one clock domain to stream data in, and a completely asynchronous domain to pull data out—safely, continuously, and without a per-word handshake bottleneck. It is constructed entirely from primitives you have already mastered: a true dual-port RAM, two Gray-coded counters, and a pair of dual-flop synchronizers. This lesson assembles them into the exact, silicon-proven architecture deployed in modern SoCs, derived rigorously and verified against a tape-out grade model.

1

The Core Engineering Problem

Strip away the RAM array for a moment. An Async FIFO is fundamentally an exercise in pointer management. You have a Write Pointer tracking the next empty memory slot, and a Read Pointer tracking the next unread slot. Crossing clock domains securely boils down to answering two critical questions, computed simultaneously across asynchronous boundaries:

Domain A (Writer) must ask:
"Has the reader consumed enough data to free up space?" If the writer overtakes the reader, unread data is destructively overwritten. This is the FULL condition.
Domain B (Reader) must ask:
"Has the writer actually committed new data here?" If the reader overtakes the writer, garbage data is consumed. This is the EMPTY condition.

Answering these questions requires each domain to continuously evaluate its own pointer against a synchronized copy of the remote domain's pointer. Because pointers are multi-bit counters, relying on standard binary encoding would guarantee fatal combinational glitches. This is why Gray Code (Lesson 4.1) is not an optional optimization—it is the foundational mechanism that guarantees structural integrity.

2

The Industry-Standard Architecture

Observe the elegant symmetry: two mirror-image logic cones, a shared dual-port memory core, and two entirely independent synchronizer paths. The data itself never crosses a synchronizer; only the Gray-coded pointers traverse the boundary.

WRITE CLOCK DOMAIN (clk_a) READ CLOCK DOMAIN (clk_b) DUAL-PORT RAM Depth: 2^N × Width: M wdata[M-1:0] → waddr[N-1:0] → wr_en · clk_a → → rdata[M-1:0] ← raddr[N-1:0] ← rd_en · clk_b Binary W-Pointer wptr_bin [N:0] BIN → GRAY b ^ (b >> 1) wptr_gray REG [N:0] FULL COMPARATOR wptr_gray == {~rptr_s[N:N-1], rptr_s[N-2:0]} R-PTR 2FF SYNC FF1 FF2 Binary R-Pointer rptr_bin [N:0] BIN → GRAY b ^ (b >> 1) rptr_gray REG [N:0] EMPTY COMPARATOR rptr_gray == wptr_s W-PTR 2FF SYNC FF1 FF2 wptr_gray rptr_gray FULL EMPTY
Industry-Standard CDC Async FIFO Architecture. The write/read addresses natively drive the Dual-Port RAM. The complete (N+1)-bit Gray pointers securely traverse the asynchronous clock boundaries via dual-flop synchronizers to independently generate pessimistic FULL and EMPTY flags.

Physical Isolation: Notice what absolutely does not cross the clock domain boundary: the massive, multi-bit data bus. The data payload safely waits inside the dual-port RAM. The only signals that ever experience asynchronous crossings are the two N+1 bit Gray-coded pointers.

3

The N+1 Bit Paradigm: Resolving Ambiguity

If a FIFO is \(2^N\) deep, you might assume an N-bit pointer is sufficient. It is not. If the writer completes exactly one lap around the memory array, its N-bit address rolls over back to 0—becoming numerically identical to a reader that hasn't moved. An N-bit pointer cannot distinguish between a memory array that is completely empty and one that is catastrophically full.

The architectural solution is to append a Virtual MSB. Both pointers are instantiated as N+1 bits wide. The lower N bits map directly to the physical RAM address, natively wrapping via natural binary overflow. The extra MSB tracks the "lap count."

The Pointer State Matrix

Equal Address Bits + Equal MSB = Pointers are at the exact same physical and virtual state. FIFO is EMPTY.

Equal Address Bits + Opposite MSB = Writer has lapped the reader exactly once. FIFO is FULL.

4

Synthesizing the FULL Condition

Because we are operating strictly in the Gray-code domain (to prevent multi-bit synchronization failures), checking if the writer has "lapped" the reader requires translating the N+1 binary logic into Gray space. The industry standard comparator inverts the top two bits of the synchronized read pointer:

full = (wptr_gray == { ~rptr_gray_sync[N:N-1], rptr_gray_sync[N-2:0] })
N = physical address width; pointers are N+1 bits wide

Why invert the top two bits? This is a mathematical property of reflected binary code. When a binary counter overflows its MSB (e.g., from 011... to 100...), the corresponding Gray code mirrors across the axis, causing the top two bits to differ from the previous lap, while all lower bits remain identical.

Verification Matrix: Depth-4 FIFO (N=2), 4 writes, 0 reads
wptr_bin100 (Decimal 4 — Writer has completed one lap)
wptr_gray110  (= 100 ^ 010)
rptr_bin000 (Nothing read yet)
rptr_gray_sync000
~rptr_gray_sync[2:1]11  (Invert the top two bits)
Comparator RHS110  (Recombined with LSB)
Conclusion110 == 110 → FULL Asserted ✓
LAP 1 (wptr_bin MSB = 1) LAP 0 (rptr_bin MSB = 0) The Gray Reflection Principle Lap 0 Binary: 000 → Gray: 000 Lap 1 Binary: 100 → Gray: 110 Inverting top 2 bits of Lap 0 (~00[1:0]) = 11 Result: 110. This definitively isolates the FULL state without decoding.
Visualizing the Gray code reflection. Inverting the top two bits of the read pointer allows a direct mathematical equality check against a write pointer that is exactly one lap ahead.
5

Synthesizing the EMPTY Condition

Deriving EMPTY is computationally trivial. Because the read pointer can only ever chase the write pointer and never overtake it, "caught up" simply means the two Gray pointers are identical.

empty = (rptr_gray == wptr_gray_sync)
Direct equality. No inversion required.

The asymmetry between the FULL and EMPTY logic is a deliberate artifact of the architecture. FULL must distinguish "lapped by one" from "exactly caught up," while EMPTY only needs to confirm exact synchronization.

6

Alternative: Decode-Then-Compare

A frequent architectural debate revolves around why we compare Gray vectors directly instead of utilizing a GRAY2BIN module (Lesson 4.1) to decode the synchronized pointer back into binary, and then performing standard arithmetic.

Decoding is mathematically valid, but it carries a severe penalty in physical implementation.

Timing Closure Failure: A GRAY2BIN converter is structurally a cascaded chain of XOR gates. The combinational delay grows linearly with the pointer width. Placing this deep logic cone directly in the path of the FULL or EMPTY flag generation—which are typically the most critical timing paths in a memory interface—is an anti-pattern that causes routing congestion and timing violations at high frequencies.

Direct-Gray comparison (the logic used in Sections 4 and 5) requires only a bitwise equality check and two inverters. It maps instantly to a single stage of LUTs in an FPGA or a minimal delay gate path in an ASIC, ensuring robust timing closure.

7

The Golden Rule: Register Before Crossing

If you analyze the synthesizable Verilog provided below, you will observe a subtle but absolute requirement: wptr_gray and rptr_gray are flip-flops, not combinational wires. The Gray value is calculated combinationally, but it is explicitly clocked into a register before traversing the clock domain boundary.

⚠️NEVER CROSS A COMBINATIONAL SIGNAL
If a Gray pointer is driven directly by combinational logic (e.g., an XOR gate) across the boundary, differential routing delays between the source bits will cause the signal to glitch. If the receiving synchronizer samples the wire during a multi-bit glitch (e.g., transitioning from 010 to 110 via a transient 111), the destination domain will latch an illegal pointer state. Registering the Gray output isolates the synchronizer from combinational hazards, guaranteeing a clean, single-bit transition.
8

The Philosophy of Pessimistic Flags

A rigorous CDC architecture does not strive for "real-time" accuracy. Because the pointers must traverse dual-flop synchronizers, the status flags inherently evaluate a delayed snapshot of the remote domain (lagging by at least two clock cycles).

  • FULL is Pessimistic: The writer sees a delayed version of the read pointer. The FIFO might have freed up space, but the writer won't know it yet. Thus, it asserts FULL slightly longer than strictly necessary.
  • EMPTY is Pessimistic: The reader sees a delayed version of the write pointer. The FIFO might have new data, but the reader won't know it yet. Thus, it asserts EMPTY slightly longer than strictly necessary.

Sacrificing Throughput for Integrity

This pessimism is not a flaw; it is the cornerstone of CDC reliability. The flags err on the side of caution. A write is never allowed to overtake a slow reader, and a reader is never allowed to underflow a slow writer. Trading a microscopic fraction of bandwidth for a mathematically airtight guarantee against data corruption is the hallmark of professional hardware design.

Watch a live 8-deep FIFO fill and drain, verified against the same golden model used to prove this design. 👇

🧪

Interactive Lab: FIFO Fill / Drain Simulator

An 8-deep FIFO (N=3) with independent write and read clocks. A producer fills it until FULL asserts, then a consumer drains it until EMPTY asserts, repeating — so occupancy sweeps cleanly between 0 and 8. WR_DATA and RD_DATA show the actual values moving through; watch the same sequence reappear on RD_DATA. Green dots are successful attempts; red dots are attempts blocked by FULL/EMPTY. Change the clock periods to see how the frequency ratio reshapes the fill/drain slopes and the synchronizer latency on the flags.

Writes: —
Reads: —
Overflow / Underflow: —

Try it yourself — copy this into our Verilog simulator and check the waveform. 👇

async_fifo.v
module async_fifo #(
    parameter DATA_WIDTH = 8,
    parameter ADDR_WIDTH = 3            // FIFO depth = 2**ADDR_WIDTH
) (
    // Write domain
    input  wire                  clk_a,
    input  wire                  rst_a_n,
    input  wire                  wr_en,
    input  wire [DATA_WIDTH-1:0] wr_data,
    output wire                  full,

    // Read domain
    input  wire                  clk_b,
    input  wire                  rst_b_n,
    input  wire                  rd_en,
    output reg  [DATA_WIDTH-1:0] rd_data,
    output wire                  empty
);

    localparam DEPTH = 1 << ADDR_WIDTH;

    // ---- Shared dual-port memory ----
    reg [DATA_WIDTH-1:0] mem [0:DEPTH-1];

    wire wr_now = wr_en && !full;
    always @(posedge clk_a) begin
        if (wr_now) mem[wptr_bin[ADDR_WIDTH-1:0]] <= wr_data;
    end

    wire rd_now = rd_en && !empty;
    always @(posedge clk_b or negedge rst_b_n) begin
        if (!rst_b_n)      rd_data <= {DATA_WIDTH{1'b0}};
        else if (rd_now)   rd_data <= mem[rptr_bin[ADDR_WIDTH-1:0]];
    end

    // ---- Write domain: Binary counter & registered Gray pointer ----
    reg  [ADDR_WIDTH:0] wptr_bin;
    reg  [ADDR_WIDTH:0] wptr_gray;
    wire [ADDR_WIDTH:0] wptr_bin_next  = wptr_bin + wr_now;
    wire [ADDR_WIDTH:0] wptr_gray_next = wptr_bin_next ^ (wptr_bin_next >> 1);

    always @(posedge clk_a or negedge rst_a_n) begin
        if (!rst_a_n) begin
            wptr_bin  <= {(ADDR_WIDTH+1){1'b0}};
            wptr_gray <= {(ADDR_WIDTH+1){1'b0}};
        end else begin
            wptr_bin  <= wptr_bin_next;
            wptr_gray <= wptr_gray_next; // CRITICAL: Gray pointer must be registered before crossing domains to avoid combinational glitches
        end
    end

    // ---- Read domain: Binary counter & registered Gray pointer ----
    reg  [ADDR_WIDTH:0] rptr_bin;
    reg  [ADDR_WIDTH:0] rptr_gray;
    wire [ADDR_WIDTH:0] rptr_bin_next  = rptr_bin + rd_now;
    wire [ADDR_WIDTH:0] rptr_gray_next = rptr_bin_next ^ (rptr_bin_next >> 1);

    always @(posedge clk_b or negedge rst_b_n) begin
        if (!rst_b_n) begin
            rptr_bin  <= {(ADDR_WIDTH+1){1'b0}};
            rptr_gray <= {(ADDR_WIDTH+1){1'b0}};
        end else begin
            rptr_bin  <= rptr_bin_next;
            rptr_gray <= rptr_gray_next; // CRITICAL: Register before crossing
        end
    end

    // ---- Synchronize rptr_gray into the write domain (feeds FULL) ----
    (* ASYNC_REG = "TRUE" *) reg [ADDR_WIDTH:0] rptr_gray_sync1, rptr_gray_sync2;
    always @(posedge clk_a or negedge rst_a_n) begin
        if (!rst_a_n) begin
            rptr_gray_sync1 <= {(ADDR_WIDTH+1){1'b0}};
            rptr_gray_sync2 <= {(ADDR_WIDTH+1){1'b0}};
        end else begin
            rptr_gray_sync1 <= rptr_gray;
            rptr_gray_sync2 <= rptr_gray_sync1;
        end
    end

    // ---- Synchronize wptr_gray into the read domain (feeds EMPTY) ----
    (* ASYNC_REG = "TRUE" *) reg [ADDR_WIDTH:0] wptr_gray_sync1, wptr_gray_sync2;
    always @(posedge clk_b or negedge rst_b_n) begin
        if (!rst_b_n) begin
            wptr_gray_sync1 <= {(ADDR_WIDTH+1){1'b0}};
            wptr_gray_sync2 <= {(ADDR_WIDTH+1){1'b0}};
        end else begin
            wptr_gray_sync1 <= wptr_gray;
            wptr_gray_sync2 <= wptr_gray_sync1;
        end
    end

    // ---- FULL: write has lapped the synchronized read pointer by one cycle ----
    assign full = (wptr_gray == {~rptr_gray_sync2[ADDR_WIDTH:ADDR_WIDTH-1],
                                   rptr_gray_sync2[ADDR_WIDTH-2:0]});

    // ---- EMPTY: read pointer has caught up to the synchronized write pointer ----
    assign empty = (rptr_gray == wptr_gray_sync2);

endmodule
tb_async_fifo.v
`timescale 1ns/1ps
module tb_async_fifo;

    localparam DATA_WIDTH = 8;
    localparam ADDR_WIDTH = 3;

    reg clk_a = 0, clk_b = 0;
    reg rst_a_n = 0, rst_b_n = 0;
    reg wr_en = 0, rd_en = 0;
    reg [DATA_WIDTH-1:0] wr_data = 0;
    wire full, empty;
    wire [DATA_WIDTH-1:0] rd_data;

    always #5   clk_a = ~clk_a;   // 100 MHz write clock
    always #3.5 clk_b = ~clk_b;   // ~143 MHz read clock

    async_fifo #(.DATA_WIDTH(DATA_WIDTH), .ADDR_WIDTH(ADDR_WIDTH)) dut (
        .clk_a(clk_a), .rst_a_n(rst_a_n), .wr_en(wr_en), .wr_data(wr_data), .full(full),
        .clk_b(clk_b), .rst_b_n(rst_b_n), .rd_en(rd_en), .rd_data(rd_data), .empty(empty)
    );

    initial begin
        $dumpfile("async_fifo.vcd");
        $dumpvars(0, tb_async_fifo);
        #20 rst_a_n = 1; rst_b_n = 1;
    end

    // Write side: push 12 values, backing off whenever FULL
    integer i;
    initial begin
        wr_en = 0;
        @(posedge rst_a_n);
        for (i = 0; i < 12; i = i + 1) begin
            @(posedge clk_a);
            while (full) @(posedge clk_a);
            #1 wr_en = 1; wr_data = i;
            @(posedge clk_a);
            #1 wr_en = 0;
        end
    end

    // Read side: pop everything, backing off whenever EMPTY, checking order
    integer expected;
    initial begin
        rd_en = 0;
        expected = 0;
        @(posedge rst_b_n);
        while (expected < 12) begin
            @(posedge clk_b);
            while (empty) @(posedge clk_b);
            #1 rd_en = 1;
            @(posedge clk_b);
            #1 rd_en = 0;
            if (rd_data !== expected)
                $display("MISMATCH at time %0t: expected %0d, got %0d", $time, expected, rd_data);
            else
                $display("OK at time %0t: read %0d", $time, rd_data);
            expected = expected + 1;
        end
        #20 $finish;
    end

endmodule

🎯 What to remember

  • An async FIFO is a shared dual-port RAM plus two binary counters (write/read pointers), each Gray-coded and synchronized into the other domain to generate FULL and EMPTY.
  • Pointers are N+1 bits wide for an N-bit address — the extra top bit tracks how many times each pointer has lapped the RAM, which is exactly what distinguishes "full" from "empty" when the address bits alone are identical.
  • FULL compares the write pointer against the synchronized read pointer with its top two bits inverted. EMPTY is a direct equality — no inversion needed.
  • Both flags are always safely late, never early — a small, deliberate throughput cost in exchange for a mathematically guaranteed absence of overflow or underflow.
  • The actual data (wr_data/rd_data) never crosses domains — only the two Gray-coded pointers do.
Advertisement