EE / ECE students
Final-year and master's students preparing for VLSI internships and campus placements in design or verification.
Software engineers
Developers moving into hardware who want the foundations explained from first principles.
QA & test engineers
Test automation people heading into design verification — the same stimulus-and-check mindset applied to silicon.
FPGA & embedded engineers
Engineers who write some HDL already and want the rules and habits that verification teams expect.
RTL designers
Designers who want to move to verification and think like the person checking their code.
Career returners
Engineers refreshing fundamentals before interviews after time away from hands-on work.
Prerequisites
| You need | Level | Where to get it |
|---|---|---|
| Verilog modules, always blocks, = vs <= | Comfortable | Area 02 |
| A first testbench (driver, monitor, check) | Have written one | Area 02 · Module 4 |
| Any programming language | Helpful: arrays, functions | — |
Where this area sits in the chip flow — and the roles that use it
| Role | How you use this area on the job | Typical first title |
|---|---|---|
| Design verification (DV) | Write scoreboards with queues, coverage counters with associative arrays, parallel stimulus with fork | DV Engineer / Verification Engineer I |
| RTL design | Use enums and packed structs in RTL; read testbench code when debugging | ASIC Design Engineer / RTL Engineer |
| FPGA | Write SystemVerilog testbenches for FPGA blocks | FPGA Engineer |
| DFT | Build pattern lists and expected-response tables | DFT Engineer |
| Post-silicon validation | Write directed tests and models that mirror silicon tests | Validation Engineer |
- Choose between bit, logic, int and integer and avoid hiding X.
- Use typedef, enum, packed and unpacked structs.
- Pick the right container: fixed, dynamic, queue or associative.
- Use array methods instead of hand-written loops.
- Write automatic functions and tasks with ref and default arguments.
- Run parallel threads with fork/join variants and stop them safely.
- Connect threads with mailboxes and guard resources with semaphores.
- Check a FIFO with a queue model and find its overflow bug.
| Tool | What it does | Used in this area for | Cost |
|---|---|---|---|
| Verilator (5.x) | Fast simulator that compiles Verilog/SystemVerilog to C++; also a strict linter | Every example and the lab (make) | Free |
Icarus Verilog iverilog + vvp | Event-driven Verilog simulator: compiles, then runs | Not for this area: no associative arrays, limited SystemVerilog | Free |
| GTKWave or Surfer | Waveform viewers for .vcd / .fst dumps | Watching the FIFO's flags | Free |
| VS Code + Verilog extension | Editor with syntax highlighting and lint on save | Writing code | Free |
| EDA Playground | Browser-based simulators, including commercial ones, after a free sign-up | Commercial simulators with full SystemVerilog support | Free |
| make and git | Run builds with one command; track your changes | Lab Makefile; saving your work | Free |
Commercial simulators you will meet at work
| Simulator | Vendor | Notes |
|---|---|---|
| VCS | Synopsys | Widely used for SystemVerilog/UVM regressions |
| Xcelium | Cadence | Successor of Incisive / NC-Sim |
| Questa | Siemens EDA | Successor of ModelSim; starter editions ship with FPGA tools |
Verilator 5 supports the features in this area (queues, associative arrays, classes, fork/join with --timing). Commercial simulators support the full IEEE 1800 standard.
Recommended: WSL 2 (Ubuntu inside Windows). You get the same commands as Linux and as most companies' compute farms.
- Turn on WSL and install UbuntuOpen PowerShell as Administrator, run the command, then restart.
wsl --install
After the restart an Ubuntu window opens: choose a user name and password. - Install the toolsIn the Ubuntu window:
sudo apt update sudo apt install -y iverilog verilator gtkwave make git
- Install VS Code and connect it to WSLInstall VS Code from code.visualstudio.com, add the WSL extension, then type
code .in Ubuntu to open the current folder. - Add Verilog supportInstall the Verilog-HDL/SystemVerilog/Bluespec SystemVerilog extension (publisher mshr-h).
- Check it works
iverilog -V | head -1 verilator --version
Install the native Icarus Verilog for Windows build (installer from bleyer.org/icarus, which also bundles GTKWave) and tick "Add executable folder to the user PATH". Use EDA Playground for Verilator.
- Install Apple's command-line tools
xcode-select --install
- Install HomebrewFollow the one-line command on brew.sh, then reopen Terminal.
- Install the simulators
brew install icarus-verilog verilator make git
- Install a waveform viewerDownload Surfer from surfer-project.org (native on Apple silicon), or try
brew install --cask gtkwave. - EditorInstall VS Code and the Verilog-HDL/SystemVerilog/Bluespec SystemVerilog extension.
- Check it works
iverilog -V | head -1 verilator --version
- Ubuntu / Debian
sudo apt update sudo apt install -y iverilog verilator gtkwave make git
- Fedora
sudo dnf install -y iverilog verilator gtkwave make git
- Arch
sudo pacman -S iverilog verilator gtkwave make git
- Check the versions
iverilog -V | head -1 # 11 or newer verilator --version # 5.x recommended
- Open EDA PlaygroundGo to edaplayground.com and create a free account (simulation needs a login).
- Paste the codeDesign on the right, testbench on the left.
- Choose a simulatorUnder Tools & Simulators pick a SystemVerilog-capable simulator (one of the commercial ones listed); tick Open EPWave after run for waveforms.
- RunPress Run; the log shows your
$displayoutput.
Queues, classes, mailboxes and fork timing need Verilator 5.0 or newer with --timing. Ubuntu 24.04 and current Homebrew ship 5.x; check with verilator --version. On an older system, use EDA Playground or build Verilator from source (verilator.org → Installation). Icarus Verilog does not support associative arrays or most class features.
- Make a folder and a file called
first.svmodule first; int q[$]; // queue int hits[string]; // associative array int x; initial begin q.push_back(10); q.push_back(20); q.push_front(5); $display("queue size = %0d, front = %0d, back = %0d", q.size(), q[0], q[$]); x = q.pop_front(); $display("popped %0d, size now %0d", x, q.size()); hits["read"]++; hits["read"]++; hits["write"]++; foreach (hits[k]) $display("hits[%s] = %0d", k, hits[k]); fork begin #10 $display("[%0t] slow thread done", $time); end begin #3 $display("[%0t] fast thread done", $time); end join_any $display("[%0t] join_any returned", $time); disable fork; $finish; end endmodule
- Compile it
verilator --binary --timing first.sv
- Run it
./obj_dir/Vfirst
Expected output:queue size = 3, front = 5, back = 20 popped 5, size now 2 hits[read] = 2 hits[write] = 1 [3] fast thread done [3] join_any returned - first.sv:18: Verilog $finish
- What to notice
join_anyreturned at time 3, when the fast thread finished;disable forkkilled the slow one, so its message never prints. Associative keys print in sorted order.
| Session | Do this | Time |
|---|---|---|
| Day 1 | Install Verilator 5 · first run · Module 1 (types, enum, struct) | 3 h |
| Day 2 | Module 2 (containers); queue playground; rewrite a loop with array methods | 3 h |
| Day 3 | Module 3 (functions, tasks, automatic, ref) | 2 h |
| Day 4 | Module 4 (fork variants, events, semaphores, mailboxes) | 3 h |
| Day 5 | Lab: complete the queue model, find the FIFO bug · area test | 3 h |
Start from zero
New to this? Work through these steps first, in order. Already comfortable? Skim them and jump to the reference below.
Why SystemVerilog
SystemVerilog is Verilog plus a lot of extra features for writing testbenches: better types, containers, classes, threads and random stimulus.
The same car as before, with a full toolbox in the boot.
Everything you wrote in Area 02 still works. You now add tools that make testbenches shorter and safer.
.sv.Every verification job description asks for it — UVM in later areas is built on it.
Two-state and four-state types
logic can hold 0, 1, X and Z. bit can hold only 0 and 1 — any X or Z becomes 0.A camera that records everything (logic) versus one that turns every blurry photo into a black frame (bit).
logic [3:0] a = 4'b1x0z;→ a shows1x0z.bit [3:0] b = 4'b1x0z;→ b shows1000: the X and Z were silently turned into 0.
logic, integer) and two-state (bit, int, byte).Use logic for anything connected to the DUT, so X bugs stay visible. Use int/bit for counters inside the testbench.
bit [3:0] x = 4'b1z1x; What does x hold?
Z and X become 0 → 1010.
Integer types at a glance
SystemVerilog has ready-made integer types of different widths, some signed.
Boxes of standard sizes: small, medium, large.
| Type | Bits | States | Signed |
|---|---|---|---|
bit | 1 | 2 | no |
byte | 8 | 2 | yes |
shortint | 16 | 2 | yes |
int | 32 | 2 | yes |
longint | 64 | 2 | yes |
logic | 1 | 4 | no |
integer | 32 | 4 | yes |
A byte holding 200 reads as −56 — a classic surprise when you store data bytes in it. Use bit [7:0] for raw data.
typedef and enum: names instead of numbers
typedef gives a type a name. enum gives a list of values names, and can print them.Naming the dial positions on a washing machine instead of numbering them.
typedef enum logic [1:0] {IDLE, BUSY, DONE} state_t; state_t s = BUSY; $display("%s", s.name()); // prints BUSY s = s.next(); // DONE
name(), next(), first()).Logs that say “state = BUSY” are far faster to debug than “state = 1”.
struct: group related fields
A struct bundles several fields under one name.
A form with boxes for name, age and city — one form, many fields.
typedef struct packed { logic [3:0] kind; logic [3:0] len; } hdr_t; hdr_t h = 8'h52; // packed: kind = 5, len = 2 — the fields are just bit slices
Packet headers and register layouts are natural structs — your checks read h.len instead of bus[3:0].
Strings and formatted messages
string holds text of any length; $sformatf builds text like $display but returns it.Filling in a message template: “Packet %0d had length %0d”.
string msg = $sformatf("pkt %0d len %0d", id, len); $display(msg); // pkt 7 len 12
Clear, consistent error messages are half of debugging.
Going further: the reference
The same ideas at the next level: precise definitions, tables, rules and interview questions.
Key definitions
- Four-state type
- Each bit can be 0, 1, X or Z:
logic,integer,reg,wire. - Two-state type
- Each bit is only 0 or 1:
bit,byte,int,longint. Faster; X becomes 0. - typedef
- Gives a new name to a type so it can be reused:
typedef logic [7:0] byte_t; - enum
- A type whose values are named constants;
.name()prints the label. - Packed struct
- Fields laid out as one contiguous bit vector — can be sliced and assigned to bits.
- Unpacked struct
- A record of fields that may include strings, queues or class handles; not a bit vector.
- Cast
- Converting a value to another type:
op_e'(2),int'(x),$cast. - string
- A dynamic text type with methods:
len,toupper,substr, comparison with==.
Two-state and four-state types
| Type | States | Width | Signed | Use for |
|---|---|---|---|---|
logic | 4 | 1 (or as declared) | no | DUT signals; anything that can be X |
bit | 2 | 1 | no | Testbench data, flags |
byte | 2 | 8 | yes | Byte streams, characters |
shortint / int / longint | 2 | 16 / 32 / 64 | yes | Counters, loop variables, models |
integer | 4 | 32 | yes | Legacy Verilog code |
time | 4 | 64 | no | Simulation time |
logic, check for unknowns, then convert.typedef and enum
typedef enum logic [1:0] {READ = 2'b00, WRITE = 2'b01, IDLE = 2'b11} op_e; op_e op = WRITE; $display("%s", op.name()); // WRITE op = op.next(); // IDLE op = op_e'(0); // explicit cast needed from an integer
| Enum method | Returns |
|---|---|
.name() | The label as a string |
.first() / .last() | First / last declared value |
.next() / .prev() | Neighbouring value (wraps) |
.num() | How many values |
struct and union
typedef struct packed { logic [3:0] id; logic [7:0] addr; logic [31:0] data; } bus_req_t; bus_req_t req = '{id: 4'h3, addr: 8'h10, data: 32'hCAFE_F00D};
Strings
| Code | Result |
|---|---|
string s = "axi"; | declare |
s = {s, "_lite"}; | "axi_lite" |
s.len() | 8 |
s.toupper() | "AXI_LITE" |
s.substr(0, 2) | "axi" |
$sformatf("addr=%0h", a) | formatted string — the workhorse for messages |
Assigning DUT outputs to bit or int · assigning an integer to an enum without a cast · expecting %p to print in decimal · putting a queue inside a packed struct (not allowed).
Interview corner
Q. Difference between logic and bit? A. logic is four-state, bit two-state; X/Z become 0 in a bit.
Q. Packed vs unpacked struct? A. Packed is a contiguous bit vector usable in expressions; unpacked is a record that can hold dynamic types.
Key takeaways
- Use
logicfor anything that touches the DUT, two-state types for testbench maths. - Enums give names in logs and waves, and catch illegal values at compile time.
- Packed structs are bit vectors with field names.
Start from zero
New to this? Work through these steps first, in order. Already comfortable? Skim them and jump to the reference below.
Fixed arrays
A fixed array has a set number of elements decided when you write the code.
An egg box with exactly 12 slots.
int scores[4] = '{10, 20, 30, 40}; foreach (scores[i]) $display(i, scores[i]);
Fine for things with a known count, like 4 channels or 8 registers.
Dynamic arrays
A dynamic array's size is chosen while the test runs, with new[n].
Setting out chairs once you know how many guests came.
byte payload[]; payload = new[len]; // len decided at run time
Packet payloads have random lengths — dynamic arrays fit them exactly.
Queues: first in, first out
A queue is a list you add to and take from at either end. Most often: add at the back, remove from the front.
A line at a shop counter: the first person in is the first served.
int q[$]; with push_back, pop_front, size().A queue is the perfect model of a FIFO — exactly what Lab 03 uses as its reference.
Start with q = {}. push_back(4), push_back(7), pop_front(), push_back(1). What is q?
After pushes: {4, 7}. pop_front removes 4 → {7}. push_back(1) → {7, 1}.
Associative arrays: look up by key
An associative array stores values under keys you choose, and only uses memory for keys you actually write.
A phone book: look up by name; empty pages take no space.
bit [31:0] mem [bit [31:0]]; // key = address mem[32'h1000_0000] = 32'hCAFE; if (mem.exists(addr)) data = mem[addr];
exists(), num(), delete().Modelling a 4 GB memory with only the addresses the test touched — a daily scoreboard trick.
Array methods do the loops for you
Arrays and queues have built-in methods to sum, search and sort.
A spreadsheet's SUM and FILTER buttons instead of adding by hand.
int a[] = '{3, 9, 4, 12};a.sum()→ 28a.find(x) with (x > 5)→ {9, 12}a.sort()→ {3, 4, 9, 12}
with clause.Coverage of “which packet lengths did we send” and checksum checks become one line.
Choosing the right container
Pick by how you use the data.
Egg box, folding chairs, shop line, phone book.
| Need | Use |
|---|---|
| Known, fixed count | fixed array |
| Size known at run time, then fixed | dynamic array |
| Add/remove at the ends (FIFO, expected-results list) | queue |
| Sparse, look up by key (memory, counters per ID) | associative array |
The right container makes a scoreboard ten lines instead of fifty.
Going further: the reference
The same ideas at the next level: precise definitions, tables, rules and interview questions.
Key definitions
- Fixed-size array
- Size set in the declaration:
int a[8]. - Dynamic array
- Declared with
[], sized at run time withnew[n]. - Queue
- Declared with
[$]; grows and shrinks at both ends. - Associative array
- Indexed by any key type; stores only the entries written.
- Array method
- Built-in operation such as
sum(),find,sort(). withclause- An expression applied to each
itemin methods likefind.
Try it: queue playground
Queue operations
| Call | Effect | Starting from '{1, 2, 3} |
|---|---|---|
q.push_back(4) | Add at the back | 1 2 3 4 |
q.push_front(0) | Add at the front | 0 1 2 3 |
x = q.pop_front() | Remove and return the first | x = 1, q = 2 3 |
x = q.pop_back() | Remove and return the last | x = 3, q = 1 2 |
q.insert(1, 9) | Insert at index | 1 9 2 3 |
q.delete(0) | Delete at index | 2 3 |
q.size(), q[$] | Length; last element | 3; 3 |
Associative arrays
bit [31:0] mem [bit [31:0]]; // sparse 4 GB memory model mem[32'h1000] = 32'hDEAD_BEEF; if (mem.exists(32'h2000)) ... foreach (mem[addr]) $display("%h: %h", addr, mem[addr]); int hits[string]; hits["read"]++; // counters by name
| Method | Does |
|---|---|
exists(k) | 1 if key present |
delete(k) / delete() | Remove one / all |
num() / size() | Number of entries |
first(k), next(k), last(k), prev(k) | Walk keys in order |
Array methods worth memorising
| Method | Returns | Example |
|---|---|---|
sum(), product() | a value | payload.sum() |
min(), max(), unique() | a queue | q.max() |
find with (item > 3) | queue of matches | q.find with (item > 3) |
find_index with (...) | queue of indexes | q.find_index with (item == 0) |
sort(), rsort(), reverse(), shuffle() | reorders in place | q.sort() |
Reading a missing associative key returns the default value (0) and, on most simulators, a warning. In a memory model always check exists() first, or decide deliberately what an unwritten address returns.
Indexing past the end of a queue (returns default, no error on many tools) · forgetting new[n] before using a dynamic array · iterating a queue while popping from it · using an associative array where order matters without first/next.
Interview corner
Q. Which container models a FIFO's expected data? A. A queue: push_back on write, pop_front on read.
Q. Why an associative array for a memory model? A. Only written addresses consume storage — a 4 GB space with a few hundred entries.
Key takeaways
- Queue = FIFO model; associative = sparse memory or counters.
- Dynamic arrays need
new[n]. - Array methods replace hand-written loops for sums, searches and sorts.
Start from zero
New to this? Work through these steps first, in order. Already comfortable? Skim them and jump to the reference below.
Function or task?
A function calculates and returns a value in zero simulation time. A task can wait — for a clock edge or a delay.
A function is a calculator: instant answer. A task is an errand: it takes time.
function int parity(bit [7:0] b); return ^b; endfunction task wait_cycles(int n); repeat (n) @(posedge clk); endtask
Reference models are functions; drivers and monitors are tasks.
Passing arguments: copy or link
By default an argument is copied in. With ref the routine works on the caller's own variable.
Emailing a copy of a document versus sharing a link to the original.
function void clear(ref int q[$]); q.delete(); endfunction // empties the caller's queue
Directions input, output, inout, ref, and const ref (link, read-only).
const ref avoids copying big arrays; plain ref lets a task see values change while it waits.automatic versus static
An automatic routine gives every call its own local variables. A static one shares a single set between all calls.
Everyone getting their own notepad (automatic) versus everyone writing on one whiteboard (static).
- Two threads call the same static task at once.
- Both write the same local variable — one overwrites the other.
- Make it
automaticand each call has its own copy ✓
Testbenches run many threads; static locals create bugs that appear only sometimes.
Loops and jumps
SystemVerilog has for, foreach, repeat, while, and break/continue.
Walking down a row of lockers, skipping the empty ones and stopping at the first full one.
foreach (q[i]) begin if (q[i] == 0) continue; // skip zeros if (q[i] < 0) break; // stop at a negative total += q[i]; end
Off-by-one loop bounds are a common testbench bug; foreach removes them.
For q = {2, 0, 5, -1, 7}, what is total after the loop above?
2 + (skip 0) + 5, then −1 stops the loop → 7.
Going further: the reference
The same ideas at the next level: precise definitions, tables, rules and interview questions.
Key definitions
- Function
- Returns a value (or
void) and may not consume simulation time. - Task
- May consume time (
@,#,wait); returns results through output arguments. - automatic
- Each call gets its own copy of local variables — required for recursion and parallel calls.
- static
- One shared copy of local variables for all calls — the default inside modules.
refargument- Passed by reference: no copy, and the routine sees changes made elsewhere.
const ref- By reference but read-only: speed of
refwithout the risk.
| function | task | |
|---|---|---|
| Consumes time | no | yes |
| Returns | a value or void | via output/ref |
| Can call | functions | functions and tasks |
| Typical use | parity, models, formatting | drive, wait, sample |
function automatic int parity(input bit [31:0] v); return ^v; endfunction task automatic drive(ref logic [7:0] bus, input byte val, input int cycles = 1); bus = val; repeat (cycles) @(posedge clk); endtask drive(.bus(d), .val(8'h5A)); // named arguments; cycles uses its default
Why every testbench routine is automatic
Loops and jumps
| Construct | Example |
|---|---|
foreach | foreach (arr[i]) sum += arr[i]; · 2-D: foreach (m[i, j]) |
for | for (int i = 0; i < n; i++) |
repeat | repeat (8) @(posedge clk); |
while / do … while | while (!done) @(posedge clk); |
break / continue / return | Leave a loop / skip to next / leave a routine |
Omitting automatic on testbench tasks · calling a task from a function (compile error) · passing large arrays by value in hot loops · relying on ref in a static task.
Interview corner
Q. Can a function call a task? A. No — a function can't consume time, and a task might.
Q. What does ref give you? A. Pass by reference: no copy and the callee sees live changes; const ref makes it read-only.
Key takeaways
- Functions compute, tasks take time.
- Write
automaticon every testbench routine. - Use
const reffor large read-only arguments.
Start from zero
New to this? Work through these steps first, in order. Already comfortable? Skim them and jump to the reference below.
Doing several things at once
A testbench must drive inputs, watch outputs and check results at the same time. Each of those runs as a separate thread.
Cooks in a kitchen: one chops, one stirs, one plates — all at once.
A driver thread sends packets while a monitor thread collects outputs and a checker thread compares them.
Every UVM component you'll write later runs in its own thread.
fork … join, join_any, join_none
fork starts several threads. The ending decides when the parent continues.Waiting for all your friends to arrive (join), for the first one (join_any), or not waiting at all (join_none).
Timeouts are written as “fork the test and a timer, join_any” — whichever finishes first wins.
Threads of #5, #15 and #40 inside fork … join_any, started at time 0. When does the parent continue?
When the first one finishes: at 5 ns.
Events: a doorbell between threads
One thread triggers an event; others waiting for it wake up.
A doorbell: someone presses it, everyone listening reacts.
event done; initial begin #50 -> done; end // ring initial begin @(done); $display("woke at %0t", $time); end
->, wait @ or wait(e.triggered).Simple synchronisation: “start checking once reset has finished”.
Semaphores: one key for a shared room
A semaphore holds a number of keys. A thread takes a key before using a shared resource and gives it back afterwards.
One key to a meeting room: whoever holds it uses the room; others wait.
semaphore bus_key = new(1); bus_key.get(); drive_bus(); bus_key.put();
get, put, try_get.Stops two drivers from driving the same bus at once.
Mailboxes: a postbox between components
A mailbox passes data from one thread to another, in order. get waits if it's empty.
A postbox: the sender drops letters in; the receiver collects them one by one, oldest first.
mailbox #(int) mb = new(); initial repeat (3) mb.put($urandom_range(1, 9)); // generator initial forever begin int v; mb.get(v); drive(v); end // driver
put, get, try_get, bounded size.This generator → driver hand-off is the same idea as UVM's sequencer and driver.
Putting it together: a FIFO checked by a queue
To check a FIFO, keep a queue as the model: push on every write the FIFO accepts, pop and compare on every read.
Keeping your own list of what you put into a locker, and checking each item as it comes out.
- Write 5 → model {5}. Write 8 → model {5, 8}.
- Read → FIFO gives 5; model pops 5 ✓.
- FIFO full and a write is attempted → the FIFO must not accept it, so the model must not push.
A scoreboard with a queue model.
Lab 03's planted bug writes when the FIFO is full — the queue model is what exposes it.
Going further: the reference
The same ideas at the next level: precise definitions, tables, rules and interview questions.
Key definitions
- Thread / process
- An independent flow of execution;
initial,alwaysandforkbranches are threads. - fork … join
- Start several threads; the parent waits for all of them.
- join_any / join_none
- Parent continues after the first child finishes / immediately.
- disable fork
- Kill all child threads still running from the current thread.
- event
- A named trigger:
-> efires it,@ewaits for it. - semaphore
- A bucket of keys that limits how many threads use a resource.
- mailbox
- A thread-safe FIFO for passing messages (transactions) between threads.
Try it: fork variants
fork begin wait (done); end begin repeat (1000) @(posedge clk); $error("timeout"); end join_any disable fork; // stop whichever is still running for (int i = 0; i < 4; i++) begin automatic int k = i; // capture the loop variable! fork drive_port(k); join_none end wait fork; // wait for every spawned child
Without automatic int k = i; every join_none thread starts after the loop has finished and sees i == 4.
Events, semaphores, mailboxes
| Primitive | Create | Key calls |
|---|---|---|
| event | event e; | -> e; · @e; · wait (e.triggered); |
| semaphore | semaphore s = new(1); | s.get(1) · s.put(1) · s.try_get(1) |
| mailbox | mailbox #(packet) m = new(); | put · get (blocks) · try_get · peek · num |
The lab: a FIFO checked by a queue
push_back; accepted read → pop_front and compare; flags checked against model.size() every cycle.Forgetting disable fork after a watchdog (threads leak into later tests) · @e missing an event that fired in the same time step (use wait (e.triggered)) · unbounded mailboxes hiding a stuck consumer.
Interview corner
Q. join_any + disable fork vs join_none + wait fork? A. The first waits for the first finisher then kills the rest; the second starts everything and later waits for all to finish.
Q. Mailbox vs queue? A. A mailbox is thread-safe and get blocks until data arrives; a queue is just storage.
Key takeaways
joinwaits for all,join_anyfor one,join_nonefor none.- Capture loop variables before forking.
- Mailboxes connect generator to driver; semaphores guard shared resources.
A DUT output is X and you assign it to bit b. What is b?
Which container models a sparse 4 GB memory?
What does q.pop_front() return for '{5, 7, 9}?
Can a function contain @(posedge clk)?
Why must testbench tasks be automatic?
After fork … join_any, how do you stop the remaining threads?
disable fork;What does mailbox.get() do when the mailbox is empty?
In the FIFO lab, what must full equal every cycle?
model.size() == DEPTH.Explain the four SystemVerilog array types and when to use each.
What's the difference between == and === on logic?
== returns X when any bit is X/Z; === compares X and Z literally and returns 0 or 1.Why might a test pass on one simulator and fail on another?
How do you implement a timeout in a testbench?
join_any, then disable fork; report an error if the delay won.What is a semaphore used for in a testbench?
How do you pass a large array to a task efficiently and safely?
const ref.What does wait fork wait for?
Enum assigned an out-of-range integer — what happens?
.name() returns an empty string.| You see | Why | Fix |
|---|---|---|
Unsupported: associative array (Icarus) | Icarus has limited SystemVerilog support | Use Verilator 5 (make) or EDA Playground |
Verilator: Need --timing | Delays and fork timing need the timing option | Compile with verilator --binary --timing |
| All forked threads print the same index | Loop variable not captured | automatic int k = i; before fork |
| Simulation hangs at the end | A thread waits on an empty mailbox or an event that never fires | Add a watchdog; check producer counts |
Lab says FAIL: nothing was checked | Model TODOs still empty | Complete TODO 1–4 in tb_sync_fifo.sv |
| Resource | Why read it |
|---|---|
| IEEE 1800 SystemVerilog standard — data types, arrays and processes chapters | Definitive behaviour of every feature on this page |
| Chris Spear & Greg Tumbush, SystemVerilog for Verification | The standard text for testbench SystemVerilog |
| Stuart Sutherland, Simon Davidmann, Peter Flake, SystemVerilog for Design | Types, structs and enums from the design side |
Verilator manual — SystemVerilog support and --timing | What the free simulator supports |
Lab 03 · Queue-checked FIFO
You get sync_fifo.v (depth 8, one planted bug), tb_sync_fifo.sv with biased random push/pop traffic and an empty reference model, and a Makefile for Verilator.
- Run
make: with the model empty it reportsFAIL: nothing was checked. - TODO 1–2: check
fullandemptyagainstmodel.size(); on an accepted read pop the expected value and compare with!==. - TODO 3–4: push accepted writes; count operations in an associative array.
- Run again: the first error points at the bug — note what traffic was happening. Fix the RTL and re-run.
Done when you see PASS: … reads checked, 2000 cycles.