Skip to content

Commit 8e9859d

Browse files
committed
feat: change vcd format to fst format to improve sim speed
1 parent caf7e1b commit 8e9859d

File tree

3 files changed

+64
-43
lines changed

3 files changed

+64
-43
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ DRAMsim3
1212
dramsim3.json
1313
dramsim3.txt
1414
dramsim3epoch.json
15-
*.vcd
15+
*.vcd
16+
*.wave

rtl/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ SOC_VSRC_INCLPATH += -I$(ROOT_PATH)/ysyxSoC/ysyx/peripheral/spi/rtl
4040
SOC_CSRC_INCLPATH += -I$(SOC_CSRC_HOME)
4141
SOC_CSRC_INCLPATH += -I$(SOC_CSRC_LIB_HOME)
4242

43-
SOC_CXXFLAGS += -std=c++11 -static -Wall $(SOC_CSRC_INCLPATH)
43+
# if want to ouput vcd wave, replace '-DDUMP_WAVE_FST' to '-DDUMP_WAVE_VCD',
44+
# replace '--trace-fst' to '--trace'
45+
SOC_CXXFLAGS += -std=c++11 -static -Wall $(SOC_CSRC_INCLPATH) -DDUMP_WAVE_FST
4446
SOC_FLAGS += --cc --exe --top-module $(SOC_VSRC_TOP)
4547
SOC_FLAGS += --x-assign unique -O3 -CFLAGS "$(SOC_CXXFLAGS)"
46-
SOC_FLAGS += --trace --assert --stats-vars --output-split 30000 --output-split-cfuncs 30000
47-
SOC_FLAGS += --timescale "1ns/1ns" -Wno-fatal --trace
48+
SOC_FLAGS += --trace-fst --assert --stats-vars --output-split 30000 --output-split-cfuncs 30000
49+
SOC_FLAGS += --timescale "1ns/1ns" -Wno-fatal
4850
SOC_FLAGS += -o $(BUILD_DIR)/soc/emu
4951
SOC_FLAGS += -Mdir $(BUILD_DIR)/soc/emu-compile
5052
SOC_FLAGS += $(SOC_VSRC_INCLPATH) $(SOC_CXXFILES) $(SOC_VXXFILES)
@@ -239,7 +241,7 @@ socLintCheck: socNameCheck
239241
$(MAKE) -C $(YSYXSOC_HOME)/lint/ lint-unused
240242
@echo -e "\033[1;32mlint-unused check done\033[0m"
241243

242-
socPrevBuild:
244+
socPrevBuild: diffAllBuild socTopModify
243245
# FIXME: if only need to moidfy core, commit it
244246
# @cp $(YSYXSOC_HOME)/soc/ysyxSoCFull.v $(BUILD_DIR)/soc
245247
@sed -i s/ysyx_000000/ysyx_210324/g $(BUILD_DIR)/soc/ysyxSoCFull.v

rtl/tc_l2/src/main/csrc/emu.h

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#include <unistd.h>
22
#include <getopt.h>
33

4+
#ifdef DUMP_WAVE_VCD
45
#include <verilated_vcd_c.h>
6+
#elif DUMP_WAVE_FST
7+
#include <verilated_fst_c.h>
8+
#endif
59
#include <verilated.h>
610
#include <VysyxSoCFull.h>
711

@@ -26,47 +30,53 @@ class Emulator
2630
flash_init(args.image);
2731

2832
printf("Initializing and resetting DUT ...\n");
29-
dut_ptr = new VysyxSoCFull;
30-
dut_ptr->reset = 1;
33+
dutPtr = new VysyxSoCFull;
34+
dutPtr->reset = 1;
3135
for (int i = 0; i < 10; i++)
3236
{
33-
dut_ptr->clock = 0;
34-
dut_ptr->eval();
35-
dut_ptr->clock = 1;
36-
dut_ptr->eval();
37+
dutPtr->clock = 0;
38+
dutPtr->eval();
39+
dutPtr->clock = 1;
40+
dutPtr->eval();
3741
}
38-
dut_ptr->clock = 0;
39-
dut_ptr->reset = 0;
40-
dut_ptr->eval();
42+
dutPtr->clock = 0;
43+
dutPtr->reset = 0;
44+
dutPtr->eval();
4145

42-
if (args.dump_wave)
46+
if (args.dumpWave)
4347
{
48+
#ifdef DUMP_WAVE_VCD
49+
wavePtr = new VerilatedVcdC;
50+
#elif DUMP_WAVE_FST
51+
wavePtr = new VerilatedFstC;
52+
#endif
4453
Verilated::traceEverOn(true);
45-
printf("`dump-wave` enabled, waves will be written to \"soc.vcd\".\n");
46-
fp = new VerilatedVcdC;
47-
dut_ptr->trace(fp, 1);
48-
fp->open("soc.vcd");
49-
fp->dump(0);
54+
printf("`dump-wave` enabled, waves will be written to \"soc.wave\".\n");
55+
dutPtr->trace(wavePtr, 1);
56+
wavePtr->open("soc.wave");
57+
wavePtr->dump(0);
5058
}
5159
}
5260
~Emulator()
5361
{
54-
if (args.dump_wave)
62+
if (args.dumpWave)
5563
{
56-
fp->close();
57-
delete fp;
64+
wavePtr->close();
65+
delete wavePtr;
5866
}
5967
}
6068

6169
void step()
6270
{
63-
dut_ptr->clock = 1;
64-
dut_ptr->eval();
71+
dutPtr->clock = 1;
72+
dutPtr->eval();
6573
cycle++;
66-
if (args.dump_wave && args.dump_begin <= cycle && cycle <= args.dump_end)
67-
fp->dump((vluint64_t)cycle);
68-
dut_ptr->clock = 0;
69-
dut_ptr->eval();
74+
if (args.dumpWave && args.dumpBegin <= cycle && cycle <= args.dumpEnd)
75+
{
76+
wavePtr->dump((vluint64_t)cycle);
77+
}
78+
dutPtr->clock = 0;
79+
dutPtr->eval();
7080
}
7181

7282
unsigned long long get_cycle()
@@ -77,7 +87,6 @@ class Emulator
7787
private:
7888
void parseArgs(int argc, char *argv[])
7989
{
80-
8190
int long_index;
8291
const struct option long_options[] = {
8392
{"dump-wave", 0, NULL, 0},
@@ -97,7 +106,7 @@ class Emulator
97106
switch (long_index)
98107
{
99108
case 0:
100-
args.dump_wave = true;
109+
args.dumpWave = true;
101110
continue;
102111
}
103112
// fall through
@@ -108,10 +117,10 @@ class Emulator
108117
args.image = optarg;
109118
break;
110119
case 'b':
111-
args.dump_begin = atoll(optarg);
120+
args.dumpBegin = atoll(optarg);
112121
break;
113122
case 'e':
114-
args.dump_end = atoll(optarg);
123+
args.dumpEnd = atoll(optarg);
115124
break;
116125
}
117126
}
@@ -123,24 +132,33 @@ class Emulator
123132
{
124133
printf("Usage: %s [OPTION...]\n", file);
125134
printf("\n");
126-
printf(" -i, --image=FILE run with this image file\n");
127-
printf(" --dump-wave dump waveform when log is enabled\n");
128-
printf(" -b, --log-begin=NUM display log from NUM th cycle\n");
129-
printf(" -e, --log-end=NUM stop display log at NUM th cycle\n");
130-
printf(" -h, --help print program help info\n");
135+
printf(" -i, --image=FILE run with this image file\n");
136+
printf(" --dump-wave dump vcd(fst) format waveform when log is enabled.\n");
137+
printf(" recommand use fst format, becuase fst format wave\n");
138+
printf(" file is much smaller than vcd format. You need to\n");
139+
printf(" change compiler option in Makefile to switch format.\n");
140+
printf(" -b, --log-begin=NUM display log from NUM th cycle\n");
141+
printf(" -e, --log-end=NUM stop display log at NUM th cycle\n");
142+
printf(" -h, --help print program help info\n");
131143
printf("\n");
132144
}
133145

134146
unsigned long long cycle = 0;
135147

136148
struct Args
137149
{
138-
bool dump_wave = false;
139-
unsigned long dump_begin = 0;
140-
unsigned long dump_end = -1;
150+
bool dumpWave = false;
151+
unsigned long dumpBegin = 0;
152+
unsigned long dumpEnd = -1;
141153
const char *image = nullptr;
142154
} args;
143155

144-
VysyxSoCFull *dut_ptr = nullptr;
145-
VerilatedVcdC *fp = nullptr;
156+
VysyxSoCFull *dutPtr = nullptr;
157+
158+
#ifdef DUMP_WAVE_VCD
159+
VerilatedVcdC *wavePtr = nullptr;
160+
#elif DUMP_WAVE_FST
161+
VerilatedFstC *wavePtr = nullptr;
162+
#endif
163+
146164
};

0 commit comments

Comments
 (0)