SystemVerilog queues


#1

SystemVerilog queues cheatsheet

Example code on EDA Playground:
https://www.edaplayground.com/x/3Qwh

Initialize queue

  logic [7:0] q[$] = {1,2,3,4,5};

Size of queue

$display("q size", q.size());

Push into queue

  q.push_front(10);
  q.push_back(11);

Pop from queue

  a = q.pop_front();
  a = q.pop_back();

Insert and delete

  q.insert(2, 'd20);
  q.delete(3);

Function to print queue contents in a single line

  function void print_queue(string tag, logic[7:0] q[$]);
    foreach (q[i]) $sformat(tag, "%s %0d", tag, q[i]);   
    $display(tag);
  endfunction