Part of Curriculum: Memory and FIFO Design (Module 9: Asynchronous Pointer Cross-Domain Synchronization)
View Full Roadmap →
Level 4 Hard ★ Flagship #36 50 pts ✓ Solved

Asynchronous FIFO Pointer Synchronization — Multi-Clock Design

Clock Domain Crossing (CDC) · cdc, industry-rtl, arbiters, clock-domain-crossing, hard, async-fifo

Convert a 4-bit write pointer to Gray code in clk_wr, synchronize it across clock domains into clk_rd using a 2-flop synchronizer, and generate a safe rd_empty flag.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
wr_ptr_bin[3:0]rd_ptr_gray[3:0]rd_empty>clkrst_nASYNCHRONOUS FIFO PODIGITAL HARDWARE BLOCK
⚡ Timing & Synthesizability Constraints

Timing Contract: Dual clock domains: `clk_wr` and `clk_rd` are completely asynchronous with independent phases and frequencies.

RTL Constraints: Passing RTL simulation does NOT prove absence of metastability in physical silicon.

Objective: Understand the Clifford Cummings asynchronous FIFO pointer crossing technique, MTBF safety, and conservative flag generation.

Prerequisites: Two-flop synchronizers, Gray code counters, FIFO full/empty detection.
NameDirWidthDescription
clk_wrinput1Write domain clock
wr_rst_ninput1Write domain active-low reset
wr_ptr_bininput4Binary write pointer in wr domain
clk_rdinput1Read domain clock
rd_rst_ninput1Read domain active-low reset
rd_ptr_grayinput4Current Gray read pointer in rd domain
rd_emptyoutput1Safe empty flag in read clock domain
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
In write domain, convert binary pointer to Gray code and register it: `wr_gray_reg <= wr_ptr_bin ^ (wr_ptr_bin >> 1);`.
Hint 2: Implementation Architecture & Approach
Pass `wr_gray_reg` through two `clk_rd` flip-flops (`sync_q1`, `sync_q2`).
Hint 3: Edge Cases, Timing & Verilog Syntax
Generate `rd_empty = (sync_q2 == rd_ptr_gray);`.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module(
  input        clk_wr,
  input        wr_rst_n,
  input  [3:0] wr_ptr_bin,
  input        clk_rd,
  input        rd_rst_n,
  input  [3:0] rd_ptr_gray,
  output       rd_empty
);
  // Step 1: Register Gray code in write clock domain
  reg [3:0] wr_gray_reg;
  always @(posedge clk_wr or negedge wr_rst_n) begin
    if (!wr_rst_n)
      wr_gray_reg <= 4'b0000;
    else
      wr_gray_reg <= wr_ptr_bin ^ (wr_ptr_bin >> 1);
  end

  // Step 2: 2-Flop synchronizer into read clock domain
  (* ASYNC_REG = "TRUE" *) reg [3:0] sync_q1;
  (* ASYNC_REG = "TRUE" *) reg [3:0] sync_q2;
  always @(posedge clk_rd or negedge rd_rst_n) begin
    if (!rd_rst_n) begin
      sync_q1 <= 4'b0000;
      sync_q2 <= 4'b0000;
    end else begin
      sync_q1 <= wr_gray_reg;
      sync_q2 <= sync_q1;
    end
  end

  // Step 3: Compare synchronized Gray write pointer with current Gray read pointer
  assign rd_empty = (sync_q2 == rd_ptr_gray);
endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 4 · Clock Domain Crossing (CDC)

What You Will Learn

By solving Asynchronous FIFO Pointer Synchronization — Multi-Clock Design, you will acquire core industry skills:

  • Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
  • Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
  • Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
  • Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.

Problem Statement & Requirements

Convert a 4-bit write pointer to Gray code in clk_wr, synchronize it across clock domains into clk_rd using a 2-flop synchronizer, and generate a safe rd_empty flag.

Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.

Objective: Understand the Clifford Cummings asynchronous FIFO pointer crossing technique, MTBF safety, and conservative flag generation.

Prerequisites: Two-flop synchronizers, Gray code counters, FIFO full/empty detection.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

NameDirWidthDescription
clk_wrinput1Write domain clock
wr_rst_ninput1Write domain active-low reset
wr_ptr_bininput4Binary write pointer in wr domain
clk_rdinput1Read domain clock
rd_rst_ninput1Read domain active-low reset
rd_ptr_grayinput4Current Gray read pointer in rd domain
rd_emptyoutput1Safe empty flag in read clock domain

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Dual clock domains: `clk_wr` and `clk_rd` are completely asynchronous with independent phases and frequencies.

Synthesis Constraints: Passing RTL simulation does NOT prove absence of metastability in physical silicon.

Architectural Deep Dive & Implementation Walkthrough

Because Gray code transitions only one bit at a time, asynchronous sampling by `clk_rd` can only sample either the old pointer value or the newly updated pointer value — never an erroneous intermediate value. The empty flag is conservative: synchronization latency can delay clearing `empty`, but will NEVER falsely indicate non-empty when the buffer is empty, guaranteeing zero underflows.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Synchronizing binary pointers directly without Gray coding: multi-bit skew causes catastrophic FIFO data corruption.', 'Assuming that passing functional simulation proves CDC safety: RTL simulators do not model analog metastability.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

CRITICAL CDC NOTE: Functional simulation only confirms algorithmic logic. True CDC robustness requires static CDC analysis tools to verify clock domains and ensure proper `set_max_delay` constraints between the Gray register and the first synchronizer flop.

Starter RTL Code

module top_module(
  input        clk_wr,
  input        wr_rst_n,
  input  [3:0] wr_ptr_bin,
  input        clk_rd,
  input        rd_rst_n,
  input  [3:0] rd_ptr_gray,
  output       rd_empty
);

  // Synchronize Gray write pointer into read domain and generate rd_empty

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input        clk_wr,
  input        wr_rst_n,
  input  [3:0] wr_ptr_bin,
  input        clk_rd,
  input        rd_rst_n,
  input  [3:0] rd_ptr_gray,
  output       rd_empty
);
  // Step 1: Register Gray code in write clock domain
  reg [3:0] wr_gray_reg;
  always @(posedge clk_wr or negedge wr_rst_n) begin
    if (!wr_rst_n)
      wr_gray_reg <= 4'b0000;
    else
      wr_gray_reg <= wr_ptr_bin ^ (wr_ptr_bin >> 1);
  end

  // Step 2: 2-Flop synchronizer into read clock domain
  (* ASYNC_REG = "TRUE" *) reg [3:0] sync_q1;
  (* ASYNC_REG = "TRUE" *) reg [3:0] sync_q2;
  always @(posedge clk_rd or negedge rd_rst_n) begin
    if (!rd_rst_n) begin
      sync_q1 <= 4'b0000;
      sync_q2 <= 4'b0000;
    end else begin
      sync_q1 <= wr_gray_reg;
      sync_q2 <= sync_q1;
    end
  end

  // Step 3: Compare synchronized Gray write pointer with current Gray read pointer
  assign rd_empty = (sync_q2 == rd_ptr_gray);
endmodule

Related RTL Problems in Level 4

Frequently Asked Questions

What does Asynchronous FIFO Pointer Synchronization — Multi-Clock Design require?

Convert a 4-bit write pointer to Gray code in clk_wr, synchronize it across clock domains into clk_rd using a 2-flop synchronizer, and generate a safe rd_empty flag. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: cdc, industry-rtl, arbiters, clock-domain-crossing, hard, async-fifo. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.

How is my solution graded?

A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.

How does this challenge help with semiconductor interviews?

Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of Asynchronous FIFO Pointer Synchronization — Multi-Clock Design to assess real-world synthesizability and race-condition awareness.