"Design an asynchronous FIFO" is the clock-domain-crossing question. It shows up in RTL, verification and SoC interviews because one small design tests everything: metastability, synchronizers, Gray code, and full/empty logic. Here's the version interviewers expect, and the follow-ups that trip people up.

Why you can't just synchronize a binary pointer

The writer runs on wclk and the reader on rclk. Each side needs to see the other side's pointer to compute full and empty. The obvious idea is to pass the binary pointer through a two-flop synchronizer.

The problem: a binary counter can change many bits at once (0111 to 1000 flips all four). If the receiving clock samples in the middle of that transition, each bit resolves independently, and you can capture a value that was never on the bus, like 1111. Now the FIFO thinks it's somewhere it never was.

The fix: Gray code

In Gray code, consecutive values differ in exactly one bit. If the receiving side samples during a transition, that one bit resolves to either the old or the new value, so you always get a pointer that's either the previous or the current one. Both are safe, just possibly one step stale.

Converting binary to Gray is one line:

assign gray = bin ^ (bin >> 1); 

The structure

  • Dual-port memory: written on wclk, read on rclk.
  • Each side keeps a binary pointer (for addressing) and a Gray pointer (for crossing).
  • Each Gray pointer crosses into the other domain through a two-flop synchronizer.
  • Pointers are one bit wider than the address, so you can tell full from empty when the addresses match.
// write side, ADDR = log2(depth) logic [ADDR:0] wbin, wgray, rgray_w1, rgray_w2; always_ff @(posedge wclk or negedge wrst_n) if (!wrst_n) {rgray_w2, rgray_w1} <= '0; else {rgray_w2, rgray_w1} <= {rgray_w1, rgray}; // 2-flop sync 

Empty and full

  • Empty (read side): the read Gray pointer equals the synchronized write Gray pointer.
  • Full (write side): the write Gray pointer equals the synchronized read Gray pointer with its top two bits inverted. That's the Gray-code version of "same address, wrapped one more time."
assign full = (wgray_next == {~rgray_w2[ADDR:ADDR-1], rgray_w2[ADDR-2:0]}); 

The top-two-bits trick is the detail that separates good answers from great ones. Be ready to explain it with a 4-entry example.

Why it's safe even though the pointers are stale

The synchronized pointer is always a cycle or two old. That means:

  • The writer might think the FIFO is full when a slot just freed up.
  • The reader might think it's empty when data just arrived.

Both errors are pessimistic: you stall a cycle or two, but you never overflow or read garbage. Interviewers love asking "is the stale pointer a bug?" The answer is no, and this is why.

Follow-ups to expect

  • "Why two flops?" One flop can stay metastable; two give it a full cycle to resolve, which pushes the failure rate (MTBF) to an acceptable level. Very fast clocks may need three.
  • "Can the depth be any number?" Not with this design. Gray code wraps cleanly only for powers of two.
  • "What constraints does this need?" The synchronizer paths are false paths for normal timing, but the Gray bus needs a max-delay or skew constraint so its bits don't arrive in different cycles.
  • "How do you verify it?" Random clock ratios, bursts that fill and drain completely, and assertions that you never write when full or read when empty.

How to answer in an interview

Draw the two domains, explain why binary pointers break, switch to Gray code with two-flop synchronizers, add the extra pointer bit, and derive full and empty. Then point out that stale pointers only make the flags pessimistic.

More problems like this

The RTL Design Interview Problem Pack covers the async FIFO at block level, plus the pieces it's built from (two-flop and pulse synchronizers, Gray code, a synchronous FIFO), among 20 problems in total. Sixteen of them come with synthesizable SystemVerilog solutions. For memory-side interviews, there's a free one-page DDR5 timing cheat sheet.

This article was generated with AI from the author's study notes.