summaryrefslogtreecommitdiff
path: root/verilator_lib/sim.cc
blob: 3ca8f673bae13141f819eff97cabd9eb4a2fa0ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
}