Skip to content

Introduce basic Verilator support - #48

Draft
kulp wants to merge 4 commits into
developfrom
verilator
Draft

Introduce basic Verilator support#48
kulp wants to merge 4 commits into
developfrom
verilator

Conversation

@kulp

@kulp kulp commented Aug 6, 2020

Copy link
Copy Markdown
Owner

Running on Verilator may or may not give tenyr an obvous immediate advantage, but given how quickly its generated C++ code can run, it seems a reasonable way to introduce a cycle-accurate simulator alternative to the (time-agnostic) functional simulator that is tsim.

With a long-running Fibonacci (argument 30), the Verilated vsim as of 981425b is about 7x slower than tsim.

diff --git a/ex/fib.tas b/ex/fib.tas
index ed3fbf6a..e17c5654 100644
--- a/ex/fib.tas
+++ b/ex/fib.tas
@@ -4,7 +4,7 @@
 #  C is the (so far only) argument register
 #  N is the relative-jump temp register

-.set ARGUMENT, 10
+.set ARGUMENT, 30

 _start:
     o <- ((1 << 13) - 1)    # sets up base/stack pointer
$ time ./build/src/tsim build/ex/fib.texe
./build/src/tsim build/ex/fib.texe  2.88s user 0.00s system 99% cpu 2.884 total

$ time ./build/hw/verilator/vsim build/ex/fib.texe
./build/hw/verilator/vsim build/ex/fib.texe  19.13s user 0.10s system 99% cpu 19.276 total

@kulp kulp added this to the v1.1 milestone Aug 6, 2020
@codecov

This comment has been minimized.

@kulp

This comment was marked as outdated.

@kulp
kulp force-pushed the verilator branch 2 times, most recently from af3d1e5 to c02c591 Compare July 7, 2026 01:12
@kulp
kulp force-pushed the verilator branch 3 times, most recently from 08dc350 to e88bd15 Compare August 15, 2026 19:36
kulp added 4 commits August 15, 2026 14:45
This belongs with commit f1517c0.
Add the `-DVERILATOR` option (disabled by default) and wire the Verilator
simulator into the CMake build conditionally.
Introduce the Verilator-based simulator that runs tenyr code through
the Verilog implementation. The simulator:

- provides serial text output via simserial.v
- supports -v verbosity levels matching tsim (0-4)
- shares disassembly and register dump code with tsim via asm.c
- loads .texe (obj) binary format

The main simulation loop includes proper halt detection:
- Checks for $finish instruction (0xffffffff) at the S0 state boundary
  using a two-phase finish_pending flag, letting the instruction execute
  through S3 so its data memory access is traced before halting
- Checks the core halt signal (err_i | rty_i) at every cycle
- Updates prev_state after halt checks so the S6->S0 transition is
  detected correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant