Basics of systemverilog Queue

  • Well what’s a queue? A First In First Out data structure. Coming to system verilog, here comes the basic properties of Queues.
    • The size of queue will be infinite by default. (Well until your simulator or your machine crashes)
    • A fixed size queue.
  • In any case the simulator will manage the modifications to this queue. May it be any additions or deletions of elements or updations to its elements.
  • Now how do you declare a queue in system verilog. The syntax is not too complicated yet.
    • Unbounded or an infinite queue.
      • <data-type> <queue_identifier>[$]
      • Eg: int id_que[$];
      • This will create a queue of name id_queue which can hold integer objects. Now int can be replaced by data type of your own choice
    • Bounded or a finite queue.
      • In this case if you don’t want to waste space and you know your queue does not need more than N number of elements you can use bounded queues.
      • <data-type> <queue_identifier>[$:<size>]
      • Eg: int id_que[$:9]; //This stores 10 elements
      • This will create a queue of size (size+1). it can store (size+1) elements in it.
  • Now having been declared and you have to make use of it.
  • Tasks/Functions for queue:
    • size():
      • id_que.size(): will return the number of elements present in the queue at the time when this is called.
    • insert():
      • id_que.insert(10, 1001); This will insert 1001 into queue at index 10.
    • delete()
      • id_que.delete(10): This will delete 10th element in the queue.
    • push_back()
      • id_que.push_back(VALUE) : This will append VALUE at the end of the queue. The pushed value is the tail or last element in the queue.
    • push_front()
      • id_que.push_front(VALUE): This will prepend VALUE at the beginning of the queue. The pushed value is the head or first element in the queue.
    • pop_back():
      • int a = id_queue.pop_back(): This will remove last element or tail from the queue and returns the value stored.
    • pop_front()
      • int b = id_que.pop_front(): This will remove the first element or the head from the queue and returns the value stored in first lement.
  • Trivia:
  • what happens when you pop from empty queue?
  • what happens from when you push when queue is full?
  • what happens if you push a wrong data type?
  • what happens if you pop and assign to a wrong data type?
  • Some practice:
  • How do you implement mailbox functionality by using only queue and its methods
venkatesh.amvrao Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *