TDEB Top Bar

Trending
Semiconductor Industry News — The Digital Electronics Blog
Follow Us

TDEB Masthead

The Semiconductor Hub

Semiconductors.  Chips and Systems.  Innovation.

Indexed by leading Search Engines, AI and referenced by Engineers worldwide 500+ Articles 10M+ Pageviews 30+ Reports 50+ Citations

Verilog2C++: Translating Verilog Designs into C++ Classes

mg
by
0
Share Facebook X LinkedIn WhatsApp Email

Verilog2C++ is a Verilog-to-C++ translation program: it turns a Verilog design into a C++ class, using a cycle-accurate representation of each net and register. Its project page claims it is about 10 times faster than other commercial simulators, but it has only simple functions.

What it does

A normal Verilog simulator reads your design and interprets it, or compiles it into an internal form, and then runs an event-driven scheduler that reacts to every signal change. Verilog2C++ takes a different route. It converts the design once into ordinary C++ source: a header and an implementation file for the top module. You then compile that C++ with a standard compiler, write your test bench in C++, and run the result as a normal program.

Because the generated model only evaluates logic on clock edges, rather than tracking every change in between, it can run much faster than an event-driven simulator for synchronous designs.

Why translate Verilog to C++?

  • Speed: long regression runs, firmware bring-up or architecture studies need many millions of cycles.
  • Integration: a C++ model can be linked into a software simulator, an instruction-set model or a test program.
  • Cost: the translator and the C++ compiler are free, so no simulator license is needed for each run.

Where it falls short

The trade-off is coverage of the language. Verilog2C++ handles a subset of Verilog with two-state values only and no initial or task statements, so it cannot show X propagation or timing behavior. For a full-featured, actively maintained open-source tool of the same kind, look at Verilator (see below).

Deep dive: the numbers and details

This part holds the tool's stated features and limits, how cycle-based translation works, and a comparison with Verilator. Skip it if the overview is all you need.

Stated features and limits

From the Verilog2C++ project page:

ItemDetail
Input languageIEEE 1364-2001 (Verilog-2001); SystemVerilog listed as a future plan
Simulation styleStatic scheduling, cycle-based
Value systemTwo-state only (0 and 1)
Not supportedSystem tasks, initial statements, task statements; no simulation kernel included
Command inputsFile name, top module, optional clock and reset ports with edge (posedge or negedge), and a dumpvars option
OutputA .hh header and .cc file for the top module; optional VCD waveform dump for GTKWave
Test benchWritten by hand in C++
Tested platformThe author's own early-2000s Linux system (kernel 2.4.18, gcc 3.2)

The "about 10 times faster" claim comes from the project page itself. Its benchmark section is empty, so treat the figure as the author's estimate, not a measured result.

How cycle-based translation works

An event-driven simulator keeps a queue of events and re-evaluates any process whose inputs change, possibly many times per clock cycle. A cycle-based translator, in general, instead:

  1. Finds all registers clocked by each named clock edge.
  2. Sorts the combinational logic between registers into a fixed order (static scheduling), so each expression is evaluated exactly once per cycle, after its inputs.
  3. Emits a C++ function, typically one per clock edge, that computes all next-state values and then updates every register together, which mimics nonblocking assignment.

In a typical cycle-based translator, each net and register becomes a C++ member variable sized to the nearest machine word, so a 32-bit Verilog register is one native integer and an AND of two buses is one machine instruction.

Worked example: a counter

module cnt (input clk, input rst, output reg [7:0] q);
  always @(posedge clk)
    if (rst) q <= 8'd0;
    else     q <= q + 8'd1;
endmodule

A cycle-based translation of this becomes, in spirit, a C++ class with a member q and a method called once per rising clock edge that computes next_q = rst ? 0 : (q + 1) & 0xFF and then assigns q = next_q. The test bench is a C++ loop that sets rst, calls the clock method, and checks q. There is no event queue and no delta cycles, which is where the speed comes from. (This sketch shows the idea; it is not the tool's literal output.)

Verilog2C++ compared with Verilator

AspectVerilog2C++Verilator
InputVerilog-2001 subsetVerilog and SystemVerilog
OutputC++ classC++ or SystemC, single- or multithreaded
Unknown and high-impedance valuesTwo-state onlyX and Z handled only in limited contexts
Speed claimAbout 10x commercial simulators (unbenchmarked)Over 10x standalone SystemC and about 100x Icarus Verilog on one thread; 2 to 10x more with multithreading
License and maintenanceNot stated; single authorLGPL v3 or Artistic License 2.0; community project under CHIPS Alliance with over 700 contributors

Verilator figures are from the Verilator project page.

When to use a cycle-based C++ model

  • Use it for long functional runs, software co-simulation and performance models of synchronous RTL.
  • Keep an event-driven, four-state simulator for reset and X-propagation checks, gate-level simulation with timing, and designs with latches or multiple asynchronous clocks.

Interview angle

A common verification interview question is "What is the difference between event-driven and cycle-based simulation?" A good answer: an event-driven simulator re-evaluates logic whenever an input changes and models delays and four-state values; a cycle-based simulator or translator evaluates each piece of logic once per clock edge in a fixed order, which is much faster for synchronous designs but blind to timing, glitches and X values. Tools such as Verilog2C++ and Verilator are examples of the second kind.

Common mistakes

  • Assuming a two-state model will reveal uninitialized registers; it will quietly start them at 0.
  • Relying on initial blocks for memory loading, which Verilog2C++ does not support.
  • Treating a clean C++ run as proof of timing correctness; cycle-based models know nothing about delays.
Share Facebook X LinkedIn WhatsApp Email

Post a Comment

0 Comments

Your comments will be moderated before it appears here.

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!