RTL Design / Module 7: Datapath & Memory Systems
Lesson 7.3

Async FIFO overview — Gray pointers

When writer and reader live on different clocks, a sync FIFO's shared pointers break. The async FIFO is the standard bridge — and its secret weapon is Gray-coded pointers crossed through synchronizers. This lesson is the overview; the CDC course covers the deep dive.

Definition

An async FIFO stores data in a dual-port RAM. Write logic runs on wr_clk; read logic on rd_clk. Pointers cross domains as Gray codes through 2+ flop synchronizers so full/empty flags are safe (conservative).

1

Why you need an async FIFO

Real chips have multiple clock domains: CPU core, DDR controller, PCIe PHY, sensor interface. You cannot share a sync FIFO pointer across unrelated clocks — metastability and multi-bit coherency destroy count and compare logic.

🔀

Clock domain crossing

Producer and consumer operate asynchronously. Data must be buffered safely between domains.

📊

Rate matching

Burst writer (e.g. DMA) vs steady reader (processor). FIFO absorbs bursts without dropping beats.

🛡️

Metastability shield

Only control pointers cross — data stays in RAM written on wr_clk, read on rd_clk.

Analogy

Two people on different schedules pass notes through a locked mailbox. Each has their own key (clock). They never reach in at the same time — they only check a flag ("mail waiting") that the other side updates safely with a delay.

2

Architecture — dual clock, Gray crossing

Async FIFO dual clock architecture

Each side computes full/empty using its local pointer and the synchronized remote pointer. Data never crosses — only Gray pointers do.

3

Binary vs Gray — why Gray wins at CDC

Binary vs Gray pointer crossing

At count 7→8, binary flips 4 bits. Gray flips exactly 1 bit. A 2-flop synchronizer on Gray may sample old or new value — never an impossible state.

CountBinaryGrayBits changed
0000000—
10010011
20100111
30110101
41001101
51011111
61101011
71111001
4

Gray pointer conversion RTL

gray_ptr.v
// Binary ↔ Gray for async FIFO pointers
function automatic [PTR_W:0] bin2gray(input [PTR_W:0] bin);
  bin2gray = bin ^ (bin >> 1);
endfunction

function automatic [PTR_W:0] gray2bin(input [PTR_W:0] gray);
  integer i;
  gray2bin[PTR_W] = gray[PTR_W];
  for (i = PTR_W-1; i >= 0; i = i - 1)
    gray2bin[i] = gray2bin[i+1] ^ gray[i];
endfunction

// Cross wr_gray to rd_clk domain (2-flop synchronizer)
reg [PTR_W:0] rd_sync_wr_gray_q1, rd_sync_wr_gray_q2;
always @(posedge rd_clk or negedge rd_rst_n) begin
  if (!rd_rst_n) begin
    rd_sync_wr_gray_q1 <= {(PTR_W+1){1'b0}};
    rd_sync_wr_gray_q2 <= {(PTR_W+1){1'b0}};
  end else begin
    rd_sync_wr_gray_q1 <= wr_gray;
    rd_sync_wr_gray_q2 <= rd_sync_wr_gray_q1;
  end
end
Trap

Never synchronize a binary multi-bit pointer directly. Never use the synchronized pointer for RAM addressing — only for full/empty comparison. RAM access uses the local binary pointer.

5

Conservative full/empty

Because synchronized pointers lag reality, flags must be conservative:

  • wr-side full: may assert early (thinks FIFO is fuller than reality) → safe: writer pauses sooner, never overflows
  • rd-side empty: may assert early (thinks FIFO is emptier than reality) → safe: reader waits longer, never underflows
async_fifo_flags.v
// Write side: full when wr_gray == {~rd_gray_sync[MSB], rd_gray_sync[MSB-1:0]}
assign wr_full  = (wr_gray == {~rd_gray_sync[PTR_W], rd_gray_sync[PTR_W-1:0]});
// Read side: empty when rd_gray == wr_gray_sync
assign rd_empty = (rd_gray == wr_gray_sync);

Go deeper: Full CDC methodology — metastability MTBF, synchronizer chains, pulse crossing, and formal CDC signoff — is covered in the EcrioniX CDC course. Also see Premium course index for related material.

📘

CDC course topics

2-flop vs 3-flop sync, MTBF calculation, pulse synchronizers, and structural CDC lint rules.

🔬

Formal CDC

Tools check for unsynchronized crossings, reconvergence, and glitch-prone paths before tapeout.

🏭

Vendor FIFO IP

Xilinx FIFO Generator, Intel SC FIFO — parameterized, timing-closed, use in production flows.

6

Do / don't checklist

✅ Do❌ Don't
Gray-encode pointers before CDCSync binary pointers for full/empty
Use 2+ flop synchronizers per Gray busAssume synchronized ptr is cycle-accurate
Reset both domains independentlyCross async reset without synchronizer
Use dual-port RAM (true dual-port or 2R1W)Read/write same addr same cycle blindly
Document conservative flag latencyBuild full custom async FIFO without review
Use vendor FIFO IP when possibleCross data buses without handshake/FIFO
  • Verify empty flag on rd_clk — no read when count could be 0
  • Verify full flag on wr_clk — no write when count could be DEPTH
  • Simulate with different wr_clk and rd_clk frequencies (faster/slower each way)
  • Run CDC structural checks if your flow supports them
7

Simulation strategy for async FIFOs

CDC bugs hide in corner cases. Your testbench should vary clock ratios and phase:

  • wr_clk faster: fill FIFO until wr_full, verify no write corruption
  • rd_clk faster: drain until rd_empty, verify no read garbage
  • Reset sequencing: assert wr_rst and rd_rst independently; FIFO must recover empty
  • Near-simultaneous full/empty: rapid toggle of both enables — flags stay conservative

Typical wr_clk=100MHz, rd_clk=66MHz fill-then-drain pattern:
fill phase → full → drain → empty

async_fifo_tb_sketch.v
// Clock generators — different periods
initial wr_clk = 0; always #5  wr_clk = ~wr_clk;  // 100 MHz
initial rd_clk = 0; always #7.5 rd_clk = ~rd_clk;  // ~67 MHz

task fill_to_full;
  integer i;
  begin
    for (i = 0; i < DEPTH; i = i + 1) begin
      @(posedge wr_clk);
      wr_en = 1; wdata = i[7:0];
    end
    @(posedge wr_clk); wr_en = 0;
    if (!wr_full) $display("FAIL: not full after %0d writes", DEPTH);
  end
endtask
8

When to build vs buy

Interview angle

"Would you design an async FIFO from scratch?" — For learning and small FPGAs, yes — understand Gray pointers and conservative flags. For production ASICs, use characterized vendor IP or a team-reviewed library cell. Your value is knowing why it works and how to verify it.

▶ Explore FIFO patterns in simulator

🎯 What to remember

  • Async FIFO bridges different clocks — data stays in dual-port RAM; pointers cross as Gray codes.
  • Gray changes 1 bit per step → synchronizer sees old or new value, never garbage.
  • Full/empty flags are conservative due to sync delay — that's a feature, not a bug.
  • Deep CDC topics live in the CDC course — this lesson is the RTL designer's map.
Advertisement