Home / Learn Verilog / Queues and Dynamic Arrays

Queues and Dynamic Arrays

Flexible containers for testbenches.

The short versionFlexible containers for testbenches.

Theory in plain words

Scoreboard queuepush expectedqueuepop and compare
Scoreboard queue

What it is

A queue int q[$] grows and shrinks; push_back, pop_front, size() are the main methods.

Why it matters

Scoreboards store expected values in queues.

Mechanically speaking

Testbench-only.

Shows up in

  • Everyday RTL design
  • FPGA and ASIC projects
  • Testbenches and debugging

Try it

A queue by handVerilog: edit and run

Queues do this for you.

SystemVerilog queue
int q[$];\ninitial begin\n  q.push_back(11); q.push_back(22);\n  $display("%0d", q.pop_front());   // 11\n  $display("size %0d", q.size());     // 1\nend
Careful:This simulator runs the core of SystemVerilog (logic, always_ff, always_comb, enum, typedef, int, loops with int, break/continue, inside, immediate assert). Features shown only in the grey code box need a full simulator (Icarus -g2012, Verilator, Questa, VCS, Xcelium).

Check yourself

1. Queue pop_front returns...