all about vlsi DV
1. Introduction
After arrays, beginners usually ask:
How do I handle data that keeps coming and going?
How do I model FIFO behavior?
This is where queues come in.
Queues are one of the most practical and intuitive data structures in System Verilog, especially in verification.
They appear frequently in interviews because they test whether you understand data flow, not just syntax.
2. What Is a Queue in System Verilog?
(Featured Snippet Target)
A queue in System Verilog is a variable-sized, ordered collection that supports FIFO (First-In-First-Out) behavior, allowing elements to be added and removed dynamically.
In simple words:
-
Data goes in
-
Data comes out
-
Order is preserved
3. Alice & Bob Setup (Memorize This)
-
Alice produces data
-
Bob consumes data
-
Data arrives over time
-
Data must be processed in order
Alice and Bob agree on one rule:
“Whoever comes first, gets served first.”
That rule is FIFO.
4. Why Queues Exist (Real-Life Motivation)
Imagine Alice sending Bob packets:
-
Alice does not know how fast Bob will consume
-
Bob does not know how fast Alice will produce
-
Data must not be lost
-
Order must be maintained
Using:
-
Fixed-size arrays → too rigid
-
Dynamic arrays → resizing is manual and messy
Queues solve this naturally.
5. Queue Basics — One Line Syntax
int q[$]; // a queue of integers
That $ means:
“Size changes automatically.”
No allocation.
No deallocation.
Just push and pop.
6. Alice Pushes, Bob Pops (Core Idea)
Mental Picture (Remember This)
-
Alice stands at one end
-
Bob stands at the other end
-
Alice pushes items in
-
Bob pulls items out
That’s a queue.
Runnable Example — Simple FIFO Queue
module queue_basic_example;
int q[$];
initial begin
// Alice pushes data
q.push_back(10);
q.push_back(20);
q.push_back(30);
// Bob pops data
$display("Bob gets %0d", q.pop_front());
$display("Bob gets %0d", q.pop_front());
$display("Bob gets %0d", q.pop_front());
end
endmodule
Output order:
10
20
30
FIFO preserved.
7. Common Queue Operations (Keep It Minimal)
You only need to remember four operations:
q.push_back(x); // Alice adds at the end
q.push_front(x); // Alice adds at the front
q.pop_front(); // Bob removes from front
q.pop_back(); // Bob removes from back
But for FIFO, the golden rule is:
push_back + pop_front
8. Queue vs Dynamic Array (Very Important)
Mental Difference
-
Dynamic array → “I decide size, then fill”
-
Queue → “I keep adding and removing”
Dynamic arrays are static after allocation.
Queues are alive and flowing.
Runnable Comparison Example
module queue_vs_dynamic;
int dyn[];
int q[$];
initial begin
dyn = new[2];
dyn[0] = 1;
dyn[1] = 2;
q.push_back(1);
q.push_back(2);
// Queue can grow easily
q.push_back(3);
$display("Dynamic size=%0d", dyn.size());
$display("Queue size=%0d", q.size());
end
endmodule
9. Queue Size and Safety
Before Bob pops, he should check:
if (q.size() > 0)
q.pop_front();
Because:
-
Empty queue pop = runtime error
SystemVerilog does not auto-protect you
10. Where Queues Are Used (Concrete Examples)
Queues are used to model:
-
FIFOs
-
Scoreboards
-
Pending transactions
-
Expected vs actual data streams
Any place where order matters.
11. Common Beginner Mistakes
-
Using queues in RTL (not synthesizable)
-
Forgetting FIFO rule (mixing push/pop ends)
-
Popping empty queues
Overthinking instead of using built-in methods
12. Interview Perspective (What They Test)
Interviewers usually ask:
-
“Difference between queue and dynamic array?”
-
“How do you implement FIFO in System Verilog?”
-
“Are queues synthesizable?”
Strong One-Line Answers
-
Queue = variable-sized FIFO
-
Dynamic array = fixed after allocation
Queues are for verification, not RTL
13. One Sentence to Remember (Interview Gold)
Queues model flowing data where order matters and size changes dynamically.
If you remember this, you’ll never confuse them again.
14. Knowledge Check
-
Why are queues better than dynamic arrays for FIFOs?
-
Which operations implement FIFO?
Why shouldn’t queues be used in RTL?
15. What’s Next
Now Alice and Bob can store and move data.
Next, they need to group related data together.
👉 Next Article:
Structures & Unions in System Verilog
This will finally let Alice send one meaningful object, not loose values.