Part of Curriculum: Memory and FIFO Design (Module 3: Synchronous FIFO Fundamentals)
View Full Roadmap →
Level 3 Hard ★ Flagship #25 50 pts ✓ Solved

Synchronous FIFO — FIFO Architecture

Queues & Buffers · memory, fifo, protocols, apb, uart, hard, synchronous-fifo

Design an 8-entry by 8-bit synchronous First-In First-Out (FIFO) buffer with write enable (wr_en), read enable (rd_en), full, and empty flags.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
wr_endin[7:0]rd_endout[7:0]fullempty>clkrst_nSYNCHRONOUS FIFODIGITAL HARDWARE BLOCK
⚡ Timing & Synthesizability Constraints

Timing Contract: Single clock domain. Write commits on `posedge clk` when `wr_en && !full`. Read updates on `posedge clk` when `rd_en && !empty`.

RTL Constraints: FIFO depth = 8 words. Simultaneous push and pop when non-empty must succeed without losing data.

Objective: Master circular buffer pointer management, simultaneous read/write arbitration, and flag generation.

Prerequisites: Synchronous RAM, binary counters, FIFO full/empty logic.
NameDirWidthDescription
clkinput1Master clock
areset_ninput1Active-low asynchronous reset
wr_eninput1Write (push) enable
dininput88-bit input data
rd_eninput1Read (pop) enable
doutoutput88-bit output data
fulloutput1FIFO full flag
emptyoutput1FIFO empty flag
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Maintain an explicit occupancy counter `count[3:0]` ranging from 0 to 8.
Hint 2: Implementation Architecture & Approach
`full = (count == 8)` and `empty = (count == 0)`.
Hint 3: Edge Cases, Timing & Verilog Syntax
When both `write_valid` and `read_valid` assert in the same cycle, data is simultaneously written and read, so `count` remains 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(
  input        clk,
  input        areset_n,
  input        wr_en,
  input  [7:0] din,
  input        rd_en,
  output reg [7:0] dout,
  output       full,
  output       empty
);
  reg [7:0] mem [0:7];
  reg [2:0] wr_ptr;
  reg [2:0] rd_ptr;
  reg [3:0] count;

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

  wire write_valid = wr_en && !full;
  wire read_valid  = rd_en && !empty;

  always @(posedge clk or negedge areset_n) begin
    if (!areset_n) begin
      wr_ptr <= 3'd0;
      rd_ptr <= 3'd0;
      count  <= 4'd0;
      dout   <= 8'd0;
    end else begin
      if (write_valid) begin
        mem[wr_ptr] <= din;
        wr_ptr      <= wr_ptr + 1'b1;
      end
      if (read_valid) begin
        dout   <= mem[rd_ptr];
        rd_ptr <= rd_ptr + 1'b1;
      end

      case ({write_valid, read_valid})
        2'b10: count <= count + 1'b1;
        2'b01: count <= count - 1'b1;
        default: count <= count; // 00 or 11 (simultaneous read/write maintains occupancy)
      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 3 · Queues & Buffers

What You Will Learn

By solving Synchronous FIFO — FIFO Architecture, 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 an 8-entry by 8-bit synchronous First-In First-Out (FIFO) buffer with write enable (wr_en), read enable (rd_en), full, and empty flags.

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: Master circular buffer pointer management, simultaneous read/write arbitration, and flag generation.

Prerequisites: Synchronous RAM, binary counters, FIFO full/empty logic.

Port List & Interface Timing

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

NameDirWidthDescription
clkinput1Master clock
areset_ninput1Active-low asynchronous reset
wr_eninput1Write (push) enable
dininput88-bit input data
rd_eninput1Read (pop) enable
doutoutput88-bit output data
fulloutput1FIFO full flag
emptyoutput1FIFO empty flag

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Single clock domain. Write commits on `posedge clk` when `wr_en && !full`. Read updates on `posedge clk` when `rd_en && !empty`.

Synthesis Constraints: FIFO depth = 8 words. Simultaneous push and pop when non-empty must succeed without losing data.

Architectural Deep Dive & Implementation Walkthrough

A synchronous FIFO acts as an elastic pipeline buffer between modules on the same clock. Write and read pointers wrap around circularly through memory addresses $0 \dots 7$. An occupancy counter tracks buffer fullness, preventing write overflows when full and read underflows when empty.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Allowing write pointer to advance when FIFO is full, corrupting previously queued unread data.', 'Failing to handle simultaneous read and write, causing the occupancy counter to drift away from actual pointer distance.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

Synchronous FIFOs are fundamental building blocks in DMA controllers, packet network switches, and processor load/store queues.

Starter RTL Code

module top_module(
  input        clk,
  input        areset_n,
  input        wr_en,
  input  [7:0] din,
  input        rd_en,
  output reg [7:0] dout,
  output       full,
  output       empty
);

  // 8-entry by 8-bit Synchronous FIFO

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input        clk,
  input        areset_n,
  input        wr_en,
  input  [7:0] din,
  input        rd_en,
  output reg [7:0] dout,
  output       full,
  output       empty
);
  reg [7:0] mem [0:7];
  reg [2:0] wr_ptr;
  reg [2:0] rd_ptr;
  reg [3:0] count;

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

  wire write_valid = wr_en && !full;
  wire read_valid  = rd_en && !empty;

  always @(posedge clk or negedge areset_n) begin
    if (!areset_n) begin
      wr_ptr <= 3'd0;
      rd_ptr <= 3'd0;
      count  <= 4'd0;
      dout   <= 8'd0;
    end else begin
      if (write_valid) begin
        mem[wr_ptr] <= din;
        wr_ptr      <= wr_ptr + 1'b1;
      end
      if (read_valid) begin
        dout   <= mem[rd_ptr];
        rd_ptr <= rd_ptr + 1'b1;
      end

      case ({write_valid, read_valid})
        2'b10: count <= count + 1'b1;
        2'b01: count <= count - 1'b1;
        default: count <= count; // 00 or 11 (simultaneous read/write maintains occupancy)
      endcase
    end
  end
endmodule

Related RTL Problems in Level 3

Frequently Asked Questions

What does Synchronous FIFO — FIFO Architecture require?

Design an 8-entry by 8-bit synchronous First-In First-Out (FIFO) buffer with write enable (wr_en), read enable (rd_en), full, and empty flags. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: memory, fifo, protocols, apb, uart, hard, synchronous-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 Synchronous FIFO — FIFO Architecture to assess real-world synthesizability and race-condition awareness.