Skip to content

Commit 0153254

Browse files
committed
Add init of uninitialized regs
1 parent b2007fe commit 0153254

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

src/synth_rapidsilicon.cc

+59-3
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ struct SynthRapidSiliconPass : public ScriptPass {
254254
log(" -post_cleanup <0|1|2>\n");
255255
log(" Performs a post synthesis netlist cleanup. '0' value means post cleanup is OFF. '1' means post cleanup is ON and '2' is ON in debug mode.\n");
256256
log("\n");
257+
log(" -init_registers <0|1|2>\n");
258+
log(" Force initialization of uninitialized registers. '0' value means initialize with '0', '1' means initialize with '1' and '2' means leave it uninitialized. By default '0' is used.\n");
259+
log("\n");
257260
log(" -new_iobuf_map <0|1|2|3|4>\n");
258261
log(" Performs a new approach to map IO buffers. '0' value means mapping is OFF. '1' means new mapping is ON (hard coded version) and '2' is ON in debug mode. 3 is the new generic approach, 4 generic with debug info\n");
259262
log("\n");
@@ -402,6 +405,7 @@ struct SynthRapidSiliconPass : public ScriptPass {
402405
bool cec;
403406
bool sec;
404407
int post_cleanup;
408+
int init_regs;
405409
int new_iobuf_map;
406410
string gated_clock_strategy;
407411
bool gated_clock_conversion_logic;
@@ -481,6 +485,7 @@ struct SynthRapidSiliconPass : public ScriptPass {
481485
no_flatten = false;
482486
no_iobuf= false;
483487
post_cleanup= 0;
488+
init_regs= 0;
484489
new_iobuf_map= 0;
485490
gated_clock_strategy= "";
486491
gated_clock_conversion_logic=false;
@@ -693,6 +698,10 @@ struct SynthRapidSiliconPass : public ScriptPass {
693698
if (args[argidx] == "-post_cleanup" && argidx + 1 < args.size()) {
694699
post_cleanup = stoi(args[++argidx]);
695700
continue;
701+
}
702+
if (args[argidx] == "-init_registers" && argidx + 1 < args.size()) {
703+
init_regs = stoi(args[++argidx]);
704+
continue;
696705
}
697706
if (args[argidx] == "-new_iobuf_map" && argidx + 1 < args.size()) {
698707
new_iobuf_map = stoi(args[++argidx]);
@@ -827,6 +836,9 @@ struct SynthRapidSiliconPass : public ScriptPass {
827836
if (post_cleanup < 0 && post_cleanup > 2) {
828837
log_cmd_error("Invalid post cleanup value: '%i'\n", post_cleanup);
829838
}
839+
if (init_regs < 0 && init_regs > 2) {
840+
log_cmd_error("Invalid init regs value: '%i'\n", init_regs);
841+
}
830842
if (new_iobuf_map < 0 && new_iobuf_map > 4) {
831843
log_cmd_error("Invalid new iobuf map value: '%i'\n", new_iobuf_map);
832844
}
@@ -2007,6 +2019,36 @@ struct SynthRapidSiliconPass : public ScriptPass {
20072019
log(" [%.2f sec.]\n", ftotalTime);
20082020
}
20092021

2022+
void initRegisters (RTLIL::State init)
2023+
{
2024+
for (auto module : _design->selected_modules()) {
2025+
2026+
SigMap sigmap(module);
2027+
FfInitVals initvals(&sigmap, module);
2028+
2029+
for (auto cell : module->selected_cells()) {
2030+
2031+
if (!RTLIL::builtin_ff_cell_types().count(cell->type)) {
2032+
continue;
2033+
}
2034+
2035+
FfData ff(&initvals, cell);
2036+
2037+
log("FF init value for cell %s (%s): %s = %s\n", log_id(cell), log_id(cell->type),
2038+
log_signal(ff.sig_q), log_signal(ff.val_init));
2039+
2040+
pool<int> bits;
2041+
for (int i = 0; i < ff.width; i++) {
2042+
if ((ff.val_init.bits[i] != State::S1) && (ff.val_init.bits[i] != State::S0)) {
2043+
ff.val_init.bits[i] = init;
2044+
}
2045+
}
2046+
ff.emit();
2047+
}
2048+
}
2049+
2050+
}
2051+
20102052
void reportCarryChains() {
20112053

20122054
dict<RTLIL::SigSpec, Cell*> ci2cell; // from the 'ci' net gives the corresponding carry adder cell
@@ -5589,13 +5631,13 @@ static void show_sig(const RTLIL::SigSpec &sig)
55895631
}
55905632
continue;
55915633
}
5592-
if (portName == RTLIL::escape_id("FAST_CLK")) {
5634+
if (portName == RTLIL::escape_id("FAST_CLK")) {
55935635

55945636
if (sig == actual) {
55955637
return true;
55965638
}
5597-
continue;
5598-
}
5639+
continue;
5640+
}
55995641
}
56005642
}
56015643

@@ -8232,6 +8274,20 @@ void collect_clocks (RTLIL::Module* module,
82328274

82338275
run("stat");
82348276

8277+
// We need to initialize uninitialized registers otherwise we may see
8278+
// unexpected strong DFF optimizations like in EDA-3136 or EDA-3177 where
8279+
// the design is almost empty at the end.
8280+
//
8281+
if (init_regs == 0) {
8282+
8283+
initRegisters(State::S0); // by default we use '0' value
8284+
8285+
} else if (init_regs == 1) {
8286+
8287+
initRegisters(State::S1);
8288+
}
8289+
8290+
82358291
top_run_opt(1 /* nodffe */, 0 /* sat */, 1 /* force nosdff */, 1, 12, 0);
82368292

82378293
if (fsm_encoding == Encoding::BINARY)

0 commit comments

Comments
 (0)