RTL Problems / Level 3 · Queues & Buffers
What You Will Learn
By solving FIFO Almost-Full Logic — Threshold Calculation, 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
Generate an almost_full flag for a 16-entry FIFO that asserts whenever occupancy is greater than or equal to ALMOST_FULL_THRESHOLD (default 12).
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.
Prerequisites: FIFO occupancy counters, threshold comparison.
Port List & Interface Timing
The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:
| Name | Dir | Width | Description |
|---|---|---|---|
clk | input | 1 | Clock signal |
areset_n | input | 1 | Active-low reset |
wr_valid | input | 1 | Valid write beat committed |
rd_valid | input | 1 | Valid read beat committed |
occupancy | output | 5 | Current word occupancy (0 to 16) |
almost_full | output | 1 | Asserted when occupancy >= 12 |
full | output | 1 | Asserted when occupancy == 16 |
Timing Constraints & Synthesizable RTL Rules
Timing Contract: Flag evaluates synchronously on `posedge clk`. Asserts when `occupancy >= ALMOST_FULL_THRESHOLD`.
Synthesis Constraints: FIFO capacity = 16. Threshold parameter `ALMOST_FULL_THRESHOLD = 12`.
Architectural Deep Dive & Implementation Walkthrough
Common RTL Designer Pitfalls
['Sizing `occupancy` to only 4 bits for a 16-entry FIFO: 4 bits can only count from 0 to 15, causing overflow at 16.', 'Using strict equality `occupancy == 12` instead of `>= 12`.']
Silicon & Hardware Engineering Notes
Configurable almost-full thresholds are standard features of hard FIFO macros in AMD/Xilinx UltraScale+ and Intel Agilex FPGAs.
Starter RTL Code
module top_module #(
parameter ALMOST_FULL_THRESHOLD = 12
)(
input clk,
input areset_n,
input wr_valid,
input rd_valid,
output reg [4:0] occupancy,
output almost_full,
output full
);
// FIFO watermark tracking and almost_full threshold logic
endmodule
Verified Reference Solution
🔒 Reveal Verified Reference RTL Solution
module top_module #(
parameter ALMOST_FULL_THRESHOLD = 12
)(
input clk,
input areset_n,
input wr_valid,
input rd_valid,
output reg [4:0] occupancy,
output almost_full,
output full
);
always @(posedge clk or negedge areset_n) begin
if (!areset_n) begin
occupancy <= 5'd0;
end else begin
case ({wr_valid, rd_valid})
2'b10: occupancy <= occupancy + 1'b1;
2'b01: occupancy <= occupancy - 1'b1;
default: occupancy <= occupancy;
endcase
end
end
assign full = (occupancy == 5'd16);
assign almost_full = (occupancy >= ALMOST_FULL_THRESHOLD);
endmodule
Related RTL Problems in Level 3
- Synchronous RAM — Memory Read/Write — Design a 16-word by 8-bit synchronous RAM (16x8) with synchronous write and synchronous read.
- Single-Port RAM with Write Enable — Memory Control — Implement a 32-word x 8-bit single-port synchronous RAM with read-first (read-during-write) behavior.
- Synchronous FIFO — FIFO Architecture — 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.
Connected EcrioniX Learning Resources
Accelerate your VLSI engineering knowledge with these curated learning materials:
Progress through step-by-step verified modules from fundamentals to advanced silicon design.
Benchmark your hardware knowledge across 10 semiconductor domains and receive study roadmaps.
Explore foundational circuit theory, waveform timing, and physical hardware implementation.
Frequently Asked Questions
What does FIFO Almost-Full Logic — Threshold Calculation require?
Generate an almost_full flag for a 16-entry FIFO that asserts whenever occupancy is greater than or equal to ALMOST_FULL_THRESHOLD (default 12). 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, fifo-thresholds. 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 FIFO Almost-Full Logic — Threshold Calculation to assess real-world synthesizability and race-condition awareness.