Verilator open-source SystemVerilog simulator and lint system
Go to file
Geza Lore 0af3cb9dc0 VlWide4AB prototype for 4-state data
Based on top of #7642. And as discussed in #7193, experiments.

This patch contains 2 parts.

---

The important part:

In the runtime, it introduces `VlWide4AB`, which is is intended to be the
representation of 4-state signals with 32-bit A/B words interleaved
(each 2x32-bit word is an `EData[2] array`, as I'm a bit paranoid about
strict aliasing issues, but could be made a struct with care).
`VlWide4AB` contains `.abits()` and `.bbits()` methods, which yields a
proxy class that through implict constructors can be passed directly to
the existing runtime functions that expect a `WDataInP`/`WDataOutP`.
Whether the `WData*` handle is for a `VlWide` (contiguous), or
`VlWide4AB` is encoded in the spare LSB of the pointer held in the
`WData*` handle. Indexing, arithmetic on the handle considers the
stride, so as long as the runtime only accesses wide state through
`WData*` handles, the routines work for both the 2-state and
4-state-interleaved formats (and the same could be done for
4-state-non-interleaved, or other exotic encodings if necessary.

Example to clarify, though I would recommend a `make test-diff` with
this patch:

```c++
  // This works just like before
  VlWide<10> a2, b2, c2;
  VL_MUL_W(10, a2, b2, c2);

  // This also works
  VlWide4AB<10> a4, b4, c4;
  VL_MUL_W(10, a4.abits(), b4.abits(), c4.abits());

  // But this would also work no problem - note mixed strides/parts:
  VL_MUL_W(10, a2, b4.abits(), c4.bbits());
```

That is, the runtime needs minimal changes. Places where a wide is
accessed without a `WData*` handle or where `WData*::datap()` is called
to get to the raw pointer will need to be fixed. (I will post a separate
patch to add a type-safe template based `scanf` implementation which will
also just work afterwards).

Regarding performance, the encoding is fairly efficient, so impact
should be small, but also most things should be V3Expanded anyway.
If there are performance issues with some, we can always add explicit
variants for those, but I would expect most time to be in the generated
code after V3Expand.

To add runtime functions that take VlWide4AB directly, one would cerate
a `WData4*` handle analogous to `WData`, then can pass the `VlWide4AB`
dierctly without `.abits()`, `.bbits()`. Tracing for example will need
this.

---

The unimportant part:

I hacked up V3Emit and friends to emit `VlWide4AB` for all wide data,
currently always using the `bbits()`, just to test this out. It passes
~94% of the test suite. You can largely ignore this demonstration hack.

---

Continuing the discussion from
https://github.com/verilator/verilator/pull/7193#issuecomment-4444858411
the runtime with the above architecture will work to do 2-state
arithmetic with minimal changes. Verilator internally will do no 4-state
arithmetic after V3Forustate (which needs to run early), which coverts
all 4-state arithmetic into 2-state over abits/bbits like it
currently does.

I came to the conclusion agreeing with Wilson that we will need an
explicit `AstABits`/`AstBBits` LValue type to represent the reference
over aggregate data types (e.g. unpacked arrays of queues of classes
that have associative arrays of 4-state values as members). With the
above runtime, the Emit rule for `AstABits` is simply to print
`.abits()`, and similarly for `AstBBits`, simply print `.bbits()`.

However, we should special case `AstNodeVarRef`, to contain an enum
value, to represent the reference directly when dealing with simple
variable references. (These are the ones that we can optimize
aggressively throughout the compiler). That is, add this to
`AstNodeVarRef`:

```c++
  enum class VarPart : uint8_t {
     WHOLE, // References whole variable, e.g. for `x = y`
     ABITS, // References A bits, e.g `x = p.abits() | q.bbits()`
     BBITS, // References B bits
  };

  class AstNodeVarRef {
        ...
        VarPart m_part
        ...

        VarPart part() const { return m_part; }
        // Encoded reference if needed for map keys - can be other than
        // uintptr_t, but we have a few spare bottom bits in the ptr.
        uintptr_t varpart() const {
          return reinterpret_cast<uintptr_t>(m_varp) | m_part;
        }
  };
```

`AstVarRef(AstVar, VarPart::ABITS)` is then semantically equivalent to
`AstABits(AstVarRef(AstVar, VarPart::WHOLE))`.

(We could special case other LValue nodes if it helps with the
internals, and we will probably want to do e.g. `AstWordSel`, but on the
first try it's probably enoughto have the generic `Ast{A,B}Bits` +
VarRef special.)

Rules to encode in V3Broken:

- After V3FourState, only LValue expressions can have a 4-state type
- `AstABits`/`AstBBits` (and `AstNodeVarRef` with non WHOLE flag) can only
  be applied to a 4-state packed type.
- `AstABits`/`AstBBits (and `AstNodeVarRef` with non WHOLE flag) has a
  2-state type matching it's operand (same width)
2026-05-22 20:07:14 +01:00
.devcontainer Tests: Untabify some tests. 2024-09-01 21:12:37 -04:00
.github CI: Bump actions/create-github-app-token in the everything group (#7611) 2026-05-18 20:48:53 -04:00
LICENSES Commentary: Changes update 2026-05-12 09:52:18 -04:00
bin Fix internal error on consecutive repetition with N > 256 (#7552) (#7603) 2026-05-17 21:54:10 -04:00
ci Tests: Switch VCD/FST compare to wavediff (#7426) 2026-04-21 13:53:53 -04:00
docs Support busses with mix of pullup/pulldown (#7632) 2026-05-21 14:45:40 -04:00
examples Add SPDX copyright identifiers, and get 'reuse' clean. No functional change. 2026-01-26 20:24:34 -05:00
include VlWide4AB prototype for 4-state data 2026-05-22 20:07:14 +01:00
nodist Support streaming on queues (#7597) 2026-05-20 19:14:02 -04:00
src VlWide4AB prototype for 4-state data 2026-05-22 20:07:14 +01:00
test_regress Fix erroneous implicit conversions of VlWide (#7642) 2026-05-22 20:05:08 +01:00
.bake.toml Add SPDX copyright identifiers, and get 'reuse' clean. No functional change. 2026-01-26 20:24:34 -05:00
.clang-format Fix header order botched by clang-format in recent commit. 2023-10-18 06:37:46 -04:00
.clang-tidy Support vpi_put/vpi_get forcing of signals (#5933) (#6704). 2026-01-10 03:48:46 -05:00
.codacy.yml CI: Avoid duplicate action runs on dependabot 2025-09-03 18:54:27 -04:00
.codecov.yml Add SPDX copyright identifiers, and get 'reuse' clean. No functional change. 2026-01-26 20:24:34 -05:00
.gitattributes Commentary: Convert Changes to RST format 2021-03-14 14:12:58 -04:00
.gitignore Add 'make venv' target (#6775) 2025-12-14 11:18:32 +00:00
.pre-commit-hooks.yaml Add Docker pre-commit hook (#5238) (#5452) 2024-09-23 07:37:24 -04:00
.style.yapf Internals: Add .style.yapf 2024-08-26 21:53:36 -04:00
CITATION.cff Internals: Format CITATION.cff as proper YAML 2025-12-20 22:19:15 -05:00
CMakeLists.txt Support new FST writer API (#6871) (#6992) 2026-05-12 07:39:43 -04:00
CPPLINT.cfg Internals: Add cpplint control file and related cleanups 2022-01-09 16:49:38 -05:00
Changes Commentary: Changes update 2026-05-19 21:40:08 -04:00
LICENSE Add back LICENSE file due to (f4pga/actions#49) 2026-02-02 19:34:10 -05:00
Makefile.in Support new FST writer API (#6871) (#6992) 2026-05-12 07:39:43 -04:00
README.rst Add SPDX copyright identifiers, and get 'reuse' clean. No functional change. 2026-01-26 20:24:34 -05:00
REUSE.toml Commentary: Changes update 2026-05-12 09:52:18 -04:00
configure.ac devel release 2026-04-26 01:58:27 -04:00
install-sh Internals: Avoid using <tab> in the middle of lines (#3913) 2023-01-29 22:39:22 -05:00
python-dev-requirements.txt Add SPDX copyright identifiers, and get 'reuse' clean. No functional change. 2026-01-26 20:24:34 -05:00
verilator-config-version.cmake.in Add SPDX copyright identifiers, and get 'reuse' clean. No functional change. 2026-01-26 20:24:34 -05:00
verilator-config.cmake.in Support new FST writer API (#6871) (#6992) 2026-05-12 07:39:43 -04:00
verilator.pc.in Fix default pkgconfig version to have no spaces (#2308) 2020-05-05 08:46:24 -04:00

README.rst

.. Github doesn't render images unless absolute URL
.. Do not know of a conditional tag, "only: github" nor "github display" works
.. SPDX-FileCopyrightText: 2003-2026 Wilson Snyder
.. SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0

|badge1| |badge2| |badge3| |badge4| |badge5| |badge7| |badge8|

.. |badge1| image:: https://img.shields.io/badge/Website-Verilator.org-181717.svg
   :target: https://verilator.org
.. |badge2| image:: https://img.shields.io/badge/License-LGPL%20v3-blue.svg
   :target: https://www.gnu.org/licenses/lgpl-3.0
.. |badge3| image:: https://img.shields.io/badge/License-Artistic%202.0-0298c3.svg
   :target: https://opensource.org/licenses/Artistic-2.0
.. |badge4| image:: https://repology.org/badge/tiny-repos/verilator.svg?header=distro%20packages
   :target: https://repology.org/project/verilator/versions
.. |badge5| image:: https://img.shields.io/docker/pulls/verilator/verilator
   :target: https://hub.docker.com/r/verilator/verilator
.. |badge7| image:: https://github.com/verilator/verilator/workflows/build/badge.svg
   :target: https://github.com/verilator/verilator/actions?query=workflow%3Abuild
.. |badge8| image:: https://img.shields.io/github/actions/workflow/status/verilator/verilator/rtlmeter.yml?branch=master&event=schedule&label=benchmarks
   :target: https://verilator.github.io/verilator-rtlmeter-results


Welcome to Verilator
====================

.. list-table::

   * - **Welcome to Verilator, the fastest Verilog/SystemVerilog simulator.**
        * Accepts Verilog or SystemVerilog
        * Performs lint code-quality checks
        * Compiles into multithreaded C++, or SystemC
        * Creates JSON to front-end your own tools
     - |Logo|
   * - |verilator multithreaded performance|
     - **Fast**
        * Outperforms many closed-source commercial simulators
        * Single- and multithreaded output models
   * - **Widely Used**
        * Wide industry and academic deployment
        * Out-of-the-box support from Arm and RISC-V vendor IP
        * Over 700 contributors
     - |verilator usage|
   * - |verilator community|
     - **Community Driven & Openly Licensed**
        * Guided by the `CHIPS Alliance`_ and `Linux Foundation`_
        * Open, and free as in both speech and beer
        * More simulation for your verification budget
   * - **Commercial Support Available**
        * Commercial support contracts
        * Design support contracts
        * Enhancement contracts
     - |verilator support|


What Verilator Does
===================

Verilator is invoked with parameters similar to GCC or Synopsys's VCS. It
"Verilates" the specified Verilog or SystemVerilog code by reading it,
performing lint checks, and optionally inserting assertion checks and
coverage-analysis points. It outputs single- or multithreaded .cpp and .h
files, the "Verilated" code.

Verilator can automatically generate a simulator executable (using
``--binary``), or users can write their own C++/SystemC wrapper to
instantiate the model. The resulting Verilated executable performs the
design simulation. Verilator also supports linking Verilator-generated
libraries, optionally encrypted, into other simulators.

Verilator supports all design constructs, most verification constructs,
intra-assignment delays (e.g, `#10`), and events. Tristate-bus (`z`) and
unknowns (`x`) are handled in limited contexts, in a special manor for
performance. It currently may not be the best choice if you are expecting a
full-featured replacement for a closed-source Verilog simulator, performing
SDF annotation, or mixed-signal simulation. However, if you are looking for
a path to migrate SystemVerilog to C++/SystemC, or want high-speed
simulation, Verilator is the tool for you.


Performance
===========

Verilator does not directly translate Verilog HDL to C++ or SystemC.
Rather, Verilator compiles your code into a much faster optimized and
optionally thread-partitioned model, which is in turn wrapped inside a
C++/SystemC module. The results are a compiled Verilog model that executes
even on a single thread over 10x faster than standalone SystemC, and on a
single thread is about 100 times faster than interpreted Verilog simulators
such as `Icarus Verilog`_. Another 2-10x speedup might be gained from
multithreading (yielding 200-1000x total over interpreted simulators).

Verilator has typically similar or better performance versus closed-source
Verilog simulators (e.g., Aldec Riviera-Pro, Cadence Incisive/NC-Verilog,
Mentor ModelSim/Questa, Synopsys VCS, VTOC, and Pragmatic CVer/CVC). But,
Verilator is open-sourced, so you can spend on computes rather than
licenses. Thus, Verilator gives you the best simulation cycles/dollar.


Installation & Documentation
============================

For more information:

- `Verilator installation and package directory structure
  <https://verilator.org/install>`_

- `Verilator manual (HTML) <https://verilator.org/verilator_doc.html>`_, or
  `Verilator manual (PDF) <https://verilator.org/verilator_doc.pdf>`_

- `Subscribe to Verilator announcements
  <https://github.com/verilator/verilator-announce>`_

- `Verilator forum <https://verilator.org/forum>`_

- `Verilator issues <https://verilator.org/issues>`_


Support
=======

Verilator is a community project, guided by the `CHIPS Alliance`_ under the
`Linux Foundation`_.

We appreciate and welcome your contributions in whatever form; please see
`Contributing to Verilator
<https://github.com/verilator/verilator/blob/master/docs/CONTRIBUTING.rst>`_.
Thanks to our `Contributors and Sponsors
<https://verilator.org/guide/latest/contributors.html>`_.

Verilator also supports and encourages commercial support models and
organizations; please see `Verilator Commercial Support
<https://verilator.org/verilator_commercial_support>`_.


Related Projects
================

- `Cocotb <https://www.cocotb.org/>`_ - A coroutine-based cosimulation
  library for writing testbenches in Python which officially supports
  Verilator.

- `GTKwave <https://gtkwave.sourceforge.net/>`_ - Waveform viewer for
  Verilator traces.

- `Icarus Verilog`_ - Icarus is a highly-featured interpreted Verilog
  simulator. If Verilator does not support your needs, perhaps Icarus may.

- `Surfer <https://surfer-project.org/>`_ - Web or offline waveform viewer
  for Verilator traces.


Open License
============

Verilator is Copyright 2003-2026 by Wilson Snyder. (Report bugs to
`Verilator Issues <https://verilator.org/issues>`_.)

Verilator is free software; you can redistribute it and/or modify it under
the terms of either the GNU Lesser General Public License Version 3 or the
Perl Artistic License Version 2.0. See the documentation for more details.

.. _chips alliance: https://chipsalliance.org
.. _icarus verilog: https://steveicarus.github.io/iverilog
.. _linux foundation: https://www.linuxfoundation.org
.. |Logo| image:: https://www.veripool.org/img/verilator_256_200_min.png
.. |verilator multithreaded performance| image:: https://www.veripool.org/img/verilator_multithreaded_performance_bg-min.png
.. |verilator usage| image:: https://www.veripool.org/img/verilator_usage_400x200-min.png
.. |verilator community| image:: https://www.veripool.org/img/verilator_community_400x125-min.png
.. |verilator support| image:: https://www.veripool.org/img/verilator_support_400x125-min.png