Verilator Simulation
Purpose
Guide Verilator-specific simulation workflows for SystemVerilog designs, from static lint analysis through simulation execution, waveform debugging, coverage closure, and C++ co-simulation integration.
Scope Constraints
Reviews RTL source, testbenches, and Makefile/build infrastructure. Does not execute Verilator or modify design files. Does not cover commercial simulators (VCS, Questa) or UVM testbench architecture — hand off to verification-methodology for those.
Inputs
- RTL design files (SystemVerilog)
- Testbench files (directed or constrained-random)
- Build infrastructure (Makefile, scripts)
- Existing Verilator warnings or simulation logs, if any
- Coverage targets or gaps to investigate
Input Sanitization
No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.
Procedure
Progress Checklist
Step 1: Lint Analysis
- Review design files with
--lint-only -Wall --timing -sv flags.
- Prioritize warnings by security impact: WIDTHTRUNC/WIDTHEXPAND (data corruption), CASEINCOMPLETE (FSM holes), UNOPTFLAT (combinational loops).
- Identify justified suppressions using
/* verilator lint_off WARNING */ pragmas.
- Separate design lint (strict,
-Wall) from testbench lint (relaxed, -Wno-STMTDLY -Wno-INITIALDLY).
- Flag any CMPCONST warnings on range checks — these often mask always-true/always-false comparisons.
Step 2: Simulation Setup
- Verify
--binary --timing -sv --assert as baseline flags.
- Confirm
--assert is present — without it, all SVA assertions are silently ignored.
- Check
--x-assign unique --x-initial unique for uninitialized register randomization.
- Verify file ordering: design files before testbench files, correct
--top-module.
- Recommend
-j 0 for parallel C++ compilation and --Mdir for separate build directories when running multiple configurations.
Step 3: Trace and Waveform Debugging
- Recommend
--trace-fst --trace-structs over --trace (VCD) — FST is ~10x smaller and preserves struct field names.
- Verify testbench includes
$dumpfile/$dumpvars or $test$plusargs("DUMP_VCD") conditional dump.
- Identify selective tracing with
/* verilator tracing_off */ pragmas for large designs.
- For security-critical paths, identify key signals to watch: tag bits, FSM state, handshake pairs, reservation state.
- Note GTKWave (
brew install --cask gtkwave) as the standard FST/VCD viewer.
Step 4: Coverage-Driven Verification
- Enable with
--coverage flag (line + toggle coverage).
- Post-process with
verilator_coverage --annotate <dir> coverage.dat for annotated source.
- Identify coverage holes in security-critical paths: FSM transitions, error handling branches, tag-bit toggle.
- Merge coverage across multiple simulation runs for regression.
- Note: Verilator does not support SystemVerilog covergroups — functional coverage requires post-processing or assertion-based coverage.
Step 5: C++ Co-Simulation
- For DPI-C integration: use
--cc mode, bind C functions via import "DPI-C" in SystemVerilog.
- For custom C++ wrappers: include
verilated.h, instantiate Vtop, step with eval().
- Enable tracing in C++ with
Verilated::traceEverOn(true) before model construction.
- Reference model integration: compare DUT outputs against C++ golden model each cycle.
- Debug with
VL_PRINTF and Verilated::debug(level).
Step 6: Limitations and Workarounds
- No full UVM support — use directed + constrained-random testbenches in pure SystemVerilog.
- Limited SVA — only subset of concurrent assertions supported;
assert property basic forms work, complex sequences may not.
- Two-state by default — use
--x-assign unique to catch X-propagation bugs that 2-state hides.
--timing required for #delay and timescale — without it, clock generation fails.
--bbox-unsup blackboxes unsupported constructs instead of erroring (use cautiously).
Compaction resilience: If context was lost, re-read the Inputs section for the design under review, check the Progress Checklist, then resume from the earliest incomplete step.
Output Format
Verilator Workflow Review
| Check Area |
Status |
Findings |
Actions |
| Lint (design) |
... |
... |
... |
| Lint (testbench) |
... |
... |
... |
| Simulation flags |
... |
... |
... |
| Assertions enabled |
... |
... |
... |
| Trace configuration |
... |
... |
... |
| Coverage setup |
... |
... |
... |
| X-safety |
... |
... |
... |
Handoff
- Hand off to verification-methodology for UVM testbench architecture or commercial simulator flows.
- Hand off to chip-design-flow for synthesis constraints or RTL coding style review.
- Hand off to soc-integration for SoC-level multi-block simulation coordination.
- Hand off to forge/rtl-security-review for security-focused RTL analysis beyond simulation.
Quality Checks
Evolution Notes
1---2name: verilator-simulation3description: Use when planning or reviewing Verilator-based simulation workflows for SystemVerilog designs. Covers lint analysis, simulation setup, trace/waveform debugging, coverage-driven verification, and C++ co-simulation. Do not use for commercial EDA tools (use verification-methodology) or RTL design flow (use chip-design-flow).4---56# Verilator Simulation78## Purpose910Guide Verilator-specific simulation workflows for SystemVerilog designs, from static lint analysis through simulation execution, waveform debugging, coverage closure, and C++ co-simulation integration.1112## Scope Constraints1314Reviews RTL source, testbenches, and Makefile/build infrastructure. Does not execute Verilator or modify design files. Does not cover commercial simulators (VCS, Questa) or UVM testbench architecture — hand off to verification-methodology for those.1516## Inputs1718- RTL design files (SystemVerilog)19- Testbench files (directed or constrained-random)20- Build infrastructure (Makefile, scripts)21- Existing Verilator warnings or simulation logs, if any22- Coverage targets or gaps to investigate2324## Input Sanitization2526No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.2728## Procedure2930### Progress Checklist31- [ ] Step 1: Lint analysis32- [ ] Step 2: Simulation setup33- [ ] Step 3: Trace and waveform debugging34- [ ] Step 4: Coverage-driven verification35- [ ] Step 5: C++ co-simulation36- [ ] Step 6: Limitations and workarounds3738### Step 1: Lint Analysis3940- Review design files with `--lint-only -Wall --timing -sv` flags.41- Prioritize warnings by security impact: WIDTHTRUNC/WIDTHEXPAND (data corruption), CASEINCOMPLETE (FSM holes), UNOPTFLAT (combinational loops).42- Identify justified suppressions using `/* verilator lint_off WARNING */` pragmas.43- Separate design lint (strict, `-Wall`) from testbench lint (relaxed, `-Wno-STMTDLY -Wno-INITIALDLY`).44- Flag any CMPCONST warnings on range checks — these often mask always-true/always-false comparisons.4546### Step 2: Simulation Setup4748- Verify `--binary --timing -sv --assert` as baseline flags.49- Confirm `--assert` is present — without it, all SVA assertions are silently ignored.50- Check `--x-assign unique --x-initial unique` for uninitialized register randomization.51- Verify file ordering: design files before testbench files, correct `--top-module`.52- Recommend `-j 0` for parallel C++ compilation and `--Mdir` for separate build directories when running multiple configurations.5354### Step 3: Trace and Waveform Debugging5556- Recommend `--trace-fst --trace-structs` over `--trace` (VCD) — FST is ~10x smaller and preserves struct field names.57- Verify testbench includes `$dumpfile`/`$dumpvars` or `$test$plusargs("DUMP_VCD")` conditional dump.58- Identify selective tracing with `/* verilator tracing_off */` pragmas for large designs.59- For security-critical paths, identify key signals to watch: tag bits, FSM state, handshake pairs, reservation state.60- Note GTKWave (`brew install --cask gtkwave`) as the standard FST/VCD viewer.6162### Step 4: Coverage-Driven Verification6364- Enable with `--coverage` flag (line + toggle coverage).65- Post-process with `verilator_coverage --annotate <dir> coverage.dat` for annotated source.66- Identify coverage holes in security-critical paths: FSM transitions, error handling branches, tag-bit toggle.67- Merge coverage across multiple simulation runs for regression.68- Note: Verilator does not support SystemVerilog covergroups — functional coverage requires post-processing or assertion-based coverage.6970### Step 5: C++ Co-Simulation7172- For DPI-C integration: use `--cc` mode, bind C functions via `import "DPI-C"` in SystemVerilog.73- For custom C++ wrappers: include `verilated.h`, instantiate `Vtop`, step with `eval()`.74- Enable tracing in C++ with `Verilated::traceEverOn(true)` before model construction.75- Reference model integration: compare DUT outputs against C++ golden model each cycle.76- Debug with `VL_PRINTF` and `Verilated::debug(level)`.7778### Step 6: Limitations and Workarounds7980- No full UVM support — use directed + constrained-random testbenches in pure SystemVerilog.81- Limited SVA — only subset of concurrent assertions supported; `assert property` basic forms work, complex sequences may not.82- Two-state by default — use `--x-assign unique` to catch X-propagation bugs that 2-state hides.83- `--timing` required for `#delay` and `timescale` — without it, clock generation fails.84- `--bbox-unsup` blackboxes unsupported constructs instead of erroring (use cautiously).8586> **Compaction resilience**: If context was lost, re-read the Inputs section for the design under review, check the Progress Checklist, then resume from the earliest incomplete step.8788## Output Format8990### Verilator Workflow Review9192| Check Area | Status | Findings | Actions |93|-----------|--------|----------|---------|94| Lint (design) | ... | ... | ... |95| Lint (testbench) | ... | ... | ... |96| Simulation flags | ... | ... | ... |97| Assertions enabled | ... | ... | ... |98| Trace configuration | ... | ... | ... |99| Coverage setup | ... | ... | ... |100| X-safety | ... | ... | ... |101102## Handoff103104- Hand off to verification-methodology for UVM testbench architecture or commercial simulator flows.105- Hand off to chip-design-flow for synthesis constraints or RTL coding style review.106- Hand off to soc-integration for SoC-level multi-block simulation coordination.107- Hand off to forge/rtl-security-review for security-focused RTL analysis beyond simulation.108109## Quality Checks110111- [ ] Design files lint-clean with `-Wall` (no unsuppressed warnings)112- [ ] `--assert` flag present in all simulation targets113- [ ] `--x-assign unique` used for X-safety114- [ ] Trace configuration verified (FST preferred, conditional dump in testbench)115- [ ] Coverage targets defined and collection enabled116- [ ] Security-critical signal paths identified for waveform inspection117- [ ] Limitations documented and workarounds in place118119## Evolution Notes120<!-- Observations appended after each use -->