What you practice
Queues (2.2). Use push_back() and pop_front() to manage dynamic data buffers with queues. It is in Dynamic Data Types — Part 2 · Verification & OOP of the SystemVerilog Masterclass. Software-side verification: dynamic data structures, classes, and the first UVM master keys.
The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.
What you will learn
Today you will learn how to use SystemVerilog queues for dynamic buffer management by implementing push_back() and pop_front() operations in a testbench.
Learning objectives
- Declare and initialize a queue using
int q[$]. - Use
push_back()to append elements to the end of the queue. - Use
pop_front()to remove and retrieve elements from the front of the queue. - Verify queue behavior with
$displayand size checks.
Theory
Queues in SystemVerilog are dynamic arrays that support efficient insertion and removal at both ends. They are declared with type q[$] and provide built-in methods like push_back(), pop_front(), push_front(), and pop_back(). The size() method returns the current number of elements.
| Method | Operation |
|---|---|
push_back() | Append element to the end |
pop_front() | Remove and return first element |
size() | Return current number of elements |
Queues grow and shrink automatically — ideal for FIFOs, packet buffers, and task scheduling.
Practice
- Open this chapter in RtlStudio — files appear automatically in Explore.
- Open
student/tb/tb.svfrom the Explore tree. - Replace
q.__TODO__(i * 10)with the correct method call to push elements onto the queue. - Replace
q.__TODO__()with the correct method call to pop elements from the queue. - Run Simulation from the sidebar and check the Log panel for
INFO:messages. - Confirm the final
INFO: PASSline appears after all elements are popped.
Summary
You practiced implementing FIFO behavior using SystemVerilog queues by inserting elements with push_back() and removing them with pop_front(). This demonstrated how queues provide efficient, dynamic buffer management for verification and OOP tasks. Queues are especially valuable for modeling streaming data, transaction logs, and testbench stimulus generation.
Run it in the Verilog IDE
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.
The lesson is done when the simulation matches Queues. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.