summaryrefslogtreecommitdiff
path: root/verilator_lib/sim.cc
diff options
context:
space:
mode:
authorMartin Stensgård <mastensg@mastensg.net>2025-05-02 20:52:27 +0200
committerMartin Stensgård <mastensg@mastensg.net>2025-05-02 20:52:27 +0200
commitcb019a43f55e08aa4c12573270a32213c823e1cb (patch)
tree7bb17c0dde760db6493894e17c19befe5cb5c3e2 /verilator_lib/sim.cc
parent0e422ec41b33216b12d8a98612d1b4b3cd84b3a7 (diff)
verilator_lib: wrap verilog module in c++ library in c++ executable
Diffstat (limited to 'verilator_lib/sim.cc')
-rw-r--r--verilator_lib/sim.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/verilator_lib/sim.cc b/verilator_lib/sim.cc
new file mode 100644
index 0000000..3ca8f67
--- /dev/null
+++ b/verilator_lib/sim.cc
@@ -0,0 +1,36 @@
+#include <cstdint>
+#include <cstdio>
+
+#include "Vmul.h"
+#include "verilated.h"
+
+enum { MAX = 10000 };
+
+int
+sim(void)
+{
+ VerilatedContext *cp = new VerilatedContext;
+
+ Vmul *top = new Vmul{cp};
+ top->clk = 0;
+
+ int numclks = 0;
+ for (int x = 0; x < MAX; ++x) {
+ for (int y = 0; y < MAX; ++y) {
+ top->x = x;
+ top->y = y;
+ top->clk = 1;
+ top->eval();
+
+ int p = top->p;
+ if (p != (uint32_t)(x * y))
+ printf("%4d * %4d = %4d\n", x, y, p);
+
+ top->clk = 0;
+ top->eval();
+ ++numclks;
+ }
+ }
+ fprintf(stderr, "%d clock cycles\n", numclks);
+ return 0;
+}