Part of Curriculum: Memory and FIFO Design (Module 7: Parameterized Full-Bandwidth Synchronous FIFO)
View Full Roadmap →
Level 8 Expert ★ Advanced #54 50 pts ✓ Solved

Parameterized Synchronous FIFO with Simultaneous Read/Write

Advanced RTL & Protocol Design · advanced-rtl, fifo-and-buffer-architecture, systemverilog, asic, fpga

Design a parameterized synchronous FIFO supporting simultaneous read and write operations without underflow or overflow hazards.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
wr_enrd_enfullcount[3:0]>clkrst_nPARAMETERIZED SYNCHRRAM / STORAGE ARRAY
⚡ Timing & Synthesizability Constraints

Timing Contract: Clocked on rising edge of clk with active-low rst_n. Write updates on posedge clk when wr_en && !full (or wr_en && rd_en when full). Read data presents registered or cut-through.

RTL Constraints: No underflow or memory corruption. Parameterized DATA_WIDTH and DEPTH. Synthesizable Verilog-2001.

Objective: Implement a parameterizable single-clock FIFO (default DATA_WIDTH=32, DEPTH=8). Support circular read and write pointer mechanics, simultaneous push and pop when full (preserving contents), accurate count tracking, and overflow/underflow protection.

Prerequisites: Synchronous FIFO architectures, circular buffers, pointer arithmetic, Verilog parameters.
PortDirWidthDescription
clk, rst_ninput1Clock and active-low synchronous reset
wr_en, wr_data[31:0]input1, 32Push enable strobe and incoming data
rd_en, rd_data[31:0]in/out1, 32Pop enable strobe and outgoing read data
full, emptyoutput1, 1Status flags for full and empty capacity
count[3:0]output4Current entry count (0 to 8)
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Maintain a separate count register to simplify full and empty generation.
Hint 2: Implementation Architecture & Approach
When the FIFO is full, a write should only be permitted if a read is simultaneously occurring (valid_wr = wr_en && (!full || rd_en)).
Hint 3: Edge Cases, Timing & Verilog Syntax
Handle simultaneous read and write (push && pop) in the count case statement so count stays unchanged.
🔒 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 #(
  parameter DATA_WIDTH = 32,
  parameter DEPTH      = 8
)(
  input  wire                  clk,
  input  wire                  rst_n,
  input  wire                  wr_en,
  input  wire [DATA_WIDTH-1:0] wr_data,
  input  wire                  rd_en,
  output reg  [DATA_WIDTH-1:0] rd_data,
  output wire                  full,
  output wire                  empty,
  output reg  [3:0]            count
);

  reg [DATA_WIDTH-1:0] mem [0:DEPTH-1];
  reg [2:0] wr_ptr, rd_ptr;

  assign full  = (count == DEPTH);
  assign empty = (count == 4'd0);

  wire valid_wr = wr_en && (!full || rd_en);
  wire valid_rd = rd_en && !empty;

  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      wr_ptr  <= 3'd0;
      rd_ptr  <= 3'd0;
      count   <= 4'd0;
      rd_data <= {DATA_WIDTH{1'b0}};
    end else begin
      if (valid_wr) begin
        mem[wr_ptr] <= wr_data;
        wr_ptr      <= (wr_ptr + 3'd1) % DEPTH;
      end

      if (valid_rd) begin
        rd_data <= mem[rd_ptr];
        rd_ptr  <= (rd_ptr + 3'd1) % DEPTH;
      end

      case ({valid_wr, valid_rd})
        2'b10: count <= count + 4'd1;
        2'b01: count <= count - 4'd1;
        default: ; // 2'b00 or 2'b11 -> hold count
      endcase
    end
  end

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 8 · Advanced RTL & Protocol Design

What You Will Learn

By solving Parameterized Synchronous FIFO with Simultaneous Read/Write, 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

Design a parameterized synchronous FIFO supporting simultaneous read and write operations without underflow or overflow hazards.

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: Implement a parameterizable single-clock FIFO (default DATA_WIDTH=32, DEPTH=8). Support circular read and write pointer mechanics, simultaneous push and pop when full (preserving contents), accurate count tracking, and overflow/underflow protection.

Prerequisites: Synchronous FIFO architectures, circular buffers, pointer arithmetic, Verilog parameters.

Port List & Interface Timing

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

PortDirWidthDescription
clk, rst_ninput1Clock and active-low synchronous reset
wr_en, wr_data[31:0]input1, 32Push enable strobe and incoming data
rd_en, rd_data[31:0]in/out1, 32Pop enable strobe and outgoing read data
full, emptyoutput1, 1Status flags for full and empty capacity
count[3:0]output4Current entry count (0 to 8)

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Clocked on rising edge of clk with active-low rst_n. Write updates on posedge clk when wr_en && !full (or wr_en && rd_en when full). Read data presents registered or cut-through.

Synthesis Constraints: No underflow or memory corruption. Parameterized DATA_WIDTH and DEPTH. Synthesizable Verilog-2001.

Architectural Deep Dive & Implementation Walkthrough

Single-Clock FIFO Architecture

Synchronous FIFOs decouple data rate mismatches between modules running in the same clock domain.

Corner-Case Handling

  • Simultaneous Read/Write when Full: A well-designed FIFO allows a write when full if a read is concurrently popping an entry. The write overwrites the slot being freed, maintaining count = DEPTH without dropping data.
  • Underflow Protection: If rd_en is asserted when empty = 1, read pointer advancement must be suppressed.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

Allowing count to overflow beyond DEPTH or underflow below 0 on invalid enable strobes.

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

For small depths (DEPTH <= 32), synthesize to distributed flip-flops; for larger depths (DEPTH >= 64), infer block RAMs (BRAMs).

Starter RTL Code

module top_module #(
  parameter DATA_WIDTH = 32,
  parameter DEPTH      = 8
)(
  input  wire                  clk,
  input  wire                  rst_n,
  input  wire                  wr_en,
  input  wire [DATA_WIDTH-1:0] wr_data,
  input  wire                  rd_en,
  output reg  [DATA_WIDTH-1:0] rd_data,
  output wire                  full,
  output wire                  empty,
  output reg  [3:0]            count
);

  // Implement parameterized synchronous FIFO:
  // 1. circular write and read pointers.
  // 2. count tracks number of valid items in FIFO (0 to DEPTH).

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module #(
  parameter DATA_WIDTH = 32,
  parameter DEPTH      = 8
)(
  input  wire                  clk,
  input  wire                  rst_n,
  input  wire                  wr_en,
  input  wire [DATA_WIDTH-1:0] wr_data,
  input  wire                  rd_en,
  output reg  [DATA_WIDTH-1:0] rd_data,
  output wire                  full,
  output wire                  empty,
  output reg  [3:0]            count
);

  reg [DATA_WIDTH-1:0] mem [0:DEPTH-1];
  reg [2:0] wr_ptr, rd_ptr;

  assign full  = (count == DEPTH);
  assign empty = (count == 4'd0);

  wire valid_wr = wr_en && (!full || rd_en);
  wire valid_rd = rd_en && !empty;

  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      wr_ptr  <= 3'd0;
      rd_ptr  <= 3'd0;
      count   <= 4'd0;
      rd_data <= {DATA_WIDTH{1'b0}};
    end else begin
      if (valid_wr) begin
        mem[wr_ptr] <= wr_data;
        wr_ptr      <= (wr_ptr + 3'd1) % DEPTH;
      end

      if (valid_rd) begin
        rd_data <= mem[rd_ptr];
        rd_ptr  <= (rd_ptr + 3'd1) % DEPTH;
      end

      case ({valid_wr, valid_rd})
        2'b10: count <= count + 4'd1;
        2'b01: count <= count - 4'd1;
        default: ; // 2'b00 or 2'b11 -> hold count
      endcase
    end
  end

endmodule

Related RTL Problems in Level 8

  • Watchdog Timer — A timeout that fires unless it keeps getting "kicked" — the safety-net circuit that resets a hung system when its heartbeat stops arriving.
  • Fixed-Priority Arbiter — Grant exactly one of four requesters at a time, always favoring the highest-index request when several arrive together.
  • CRC-4 Generator — Compute the 4-bit CRC remainder of an 8-bit message using the CRC-4 (poly x⁴+x+1) bit-serial algorithm, entirely in combinational logic.

Frequently Asked Questions

What does Parameterized Synchronous FIFO with Simultaneous Read/Write require?

Design a parameterized synchronous FIFO supporting simultaneous read and write operations without underflow or overflow hazards. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: advanced-rtl, fifo-and-buffer-architecture, systemverilog, asic, fpga. 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 Parameterized Synchronous FIFO with Simultaneous Read/Write to assess real-world synthesizability and race-condition awareness.