Queue in SystemVerilog

  • Queue in System Verilog is a variable-size, ordered collection of homogeneous objects.
  • Queue is similar to one-dimensional unpacked array that grows and shrinks automatically.
  • Queues can be manipulated using the indexing, concatenation, slicing operator and equality operators.
  • In queue 0 represents the first, and $ representing the last entries.

Queue Operators

0  : Used to represents the first element of queue
$  : Used to represents the last element of queue
{} : Used along with first and last operator to add/delete elements.

Queue Declaration

bit[3:0] data[$];

where:

bit[3:0]   -> data_type
data         -> name of the queue
$               -> Represents the last element of queue

Queues methods

MethodDescription
delete()It deletes the item at the specified index position.
insert()It inserts the given item at the specified index position.
size()It returns the number of items in the queue. If the queue is empty, it returns as 0.
push_front()It inserts the given element at the front of the queue.
push_back()It inserts the given element at the end of the queue.
pop_front()It removes and returns the first element of the queue.
pop_back()It removes and returns the last element of the queue.

Queue can be bounded or unbounded

bounded queue – queue with the number of entries limited or queue size specified

unbounded queue – queue with unlimited entries or queue size not specified

Advantage of Queue

  • Queue can have variable length, including a length of zero.
  • Queue will perform both Last In First Out (LIFO) and First In First Out (FIFO) behavior.
  • Queue will have support to adding and removing elements anywhere.

Queue Examples