Skip to content

Commit

Permalink
Naming improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
akashlevy committed Nov 21, 2024
1 parent f855b39 commit 52a1493
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 65 deletions.
104 changes: 52 additions & 52 deletions kernel/ff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ FfData::FfData(FfInitVals *initvals, Cell *cell_) : FfData(cell_->module, initva
}

FfData FfData::slice(const std::vector<int> &bits) {
FfData res(module, initvals, NEW_ID2); // SILIMATE: Improve the naming
FfData res(module, initvals, NEW_ID4); // SILIMATE: Improve the naming
res.sig_clk = sig_clk;
res.sig_ce = sig_ce;
res.sig_aload = sig_aload;
Expand Down Expand Up @@ -400,21 +400,21 @@ void FfData::aload_to_sr() {
pol_clr = false;
pol_set = true;
if (pol_aload) {
sig_clr = module->Mux(NEW_ID2_SUFFIX("clr"), Const(State::S1, width), sig_ad, sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_set = module->Mux(NEW_ID2_SUFFIX("set"), Const(State::S0, width), sig_ad, sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_clr = module->Mux(NEW_ID4_SUFFIX("clr"), Const(State::S1, width), sig_ad, sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_set = module->Mux(NEW_ID4_SUFFIX("set"), Const(State::S0, width), sig_ad, sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_clr = module->Mux(NEW_ID2_SUFFIX("clr"), sig_ad, Const(State::S1, width), sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_set = module->Mux(NEW_ID2_SUFFIX("set"), sig_ad, Const(State::S0, width), sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_clr = module->Mux(NEW_ID4_SUFFIX("clr"), sig_ad, Const(State::S1, width), sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_set = module->Mux(NEW_ID4_SUFFIX("set"), sig_ad, Const(State::S0, width), sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
} else {
pol_clr = pol_aload;
pol_set = pol_aload;
if (pol_aload) {
sig_clr = module->AndnotGate(NEW_ID2_SUFFIX("clr"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_set = module->AndGate(NEW_ID2_SUFFIX("set"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_clr = module->AndnotGate(NEW_ID4_SUFFIX("clr"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_set = module->AndGate(NEW_ID4_SUFFIX("set"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_clr = module->OrGate(NEW_ID2_SUFFIX("clr"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_set = module->OrnotGate(NEW_ID2_SUFFIX("set"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_clr = module->OrGate(NEW_ID4_SUFFIX("clr"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_set = module->OrnotGate(NEW_ID4_SUFFIX("set"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
}
}
Expand All @@ -427,31 +427,31 @@ void FfData::convert_ce_over_srst(bool val) {
if (!is_fine) {
if (pol_ce) {
if (pol_srst) {
sig_ce = module->Or(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->Or(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->Or(NEW_ID2_SUFFIX("ce"), sig_ce, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_ce = module->Or(NEW_ID4_SUFFIX("ce"), sig_ce, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
} else {
if (pol_srst) {
SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->And(NEW_ID2_SUFFIX("ce"), sig_ce, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_ce = module->And(NEW_ID4_SUFFIX("ce"), sig_ce, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_ce = module->And(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->And(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
}
} else {
if (pol_ce) {
if (pol_srst) {
sig_ce = module->OrGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->OrGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_ce = module->OrnotGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->OrnotGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
} else {
if (pol_srst) {
sig_ce = module->AndnotGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->AndnotGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_ce = module->AndGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ce = module->AndGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
}
}
Expand All @@ -460,31 +460,31 @@ void FfData::convert_ce_over_srst(bool val) {
if (!is_fine) {
if (pol_srst) {
if (pol_ce) {
sig_srst = cell->module->And(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->And(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->And(NEW_ID2_SUFFIX("srst"), sig_srst, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_srst = cell->module->And(NEW_ID4_SUFFIX("srst"), sig_srst, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
} else {
if (pol_ce) {
SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->Or(NEW_ID2_SUFFIX("srst"), sig_srst, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
sig_srst = cell->module->Or(NEW_ID4_SUFFIX("srst"), sig_srst, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_srst = cell->module->Or(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->Or(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
}
} else {
if (pol_srst) {
if (pol_ce) {
sig_srst = cell->module->AndGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->AndGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_srst = cell->module->AndnotGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->AndnotGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
} else {
if (pol_ce) {
sig_srst = cell->module->OrnotGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->OrnotGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
sig_srst = cell->module->OrGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_srst = cell->module->OrGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
}
}
Expand All @@ -501,14 +501,14 @@ void FfData::unmap_ce() {

if (!is_fine) {
if (pol_ce)
sig_d = module->Mux(NEW_ID2_SUFFIX("d"), sig_q, sig_d, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->Mux(NEW_ID4_SUFFIX("d"), sig_q, sig_d, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
else
sig_d = module->Mux(NEW_ID2_SUFFIX("d"), sig_d, sig_q, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->Mux(NEW_ID4_SUFFIX("d"), sig_d, sig_q, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
if (pol_ce)
sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), sig_q, sig_d, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), sig_q, sig_d, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
else
sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), sig_d, sig_q, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), sig_d, sig_q, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
has_ce = false;
}
Expand All @@ -521,14 +521,14 @@ void FfData::unmap_srst() {

if (!is_fine) {
if (pol_srst)
sig_d = module->Mux(NEW_ID2_SUFFIX("d"), sig_d, val_srst, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->Mux(NEW_ID4_SUFFIX("d"), sig_d, val_srst, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
else
sig_d = module->Mux(NEW_ID2_SUFFIX("d"), val_srst, sig_d, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->Mux(NEW_ID4_SUFFIX("d"), val_srst, sig_d, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
if (pol_srst)
sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), sig_d, val_srst[0], sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), sig_d, val_srst[0], sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
else
sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), val_srst[0], sig_d, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), val_srst[0], sig_d, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
has_srst = false;
}
Expand Down Expand Up @@ -701,7 +701,7 @@ void FfData::flip_bits(const pool<int> &bits) {

flip_rst_bits(bits);

Wire *new_q = module->addWire(NEW_ID2_SUFFIX("new_q"), width); // SILIMATE: Improve the naming
Wire *new_q = module->addWire(NEW_ID4_SUFFIX("new_q"), width); // SILIMATE: Improve the naming

if (has_sr && cell) {
log_warning("Flipping D/Q/init and inserting priority fixup to legalize %s.%s [%s].\n", log_id(module->name), log_id(cell->name), log_id(cell->type));
Expand All @@ -713,15 +713,15 @@ void FfData::flip_bits(const pool<int> &bits) {
SigSpec new_sig_clr;
if (pol_set) {
if (pol_clr) {
new_sig_clr = module->AndnotGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming
new_sig_clr = module->AndnotGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
new_sig_clr = module->AndGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming
new_sig_clr = module->AndGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
} else {
if (pol_clr) {
new_sig_clr = module->OrGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming
new_sig_clr = module->OrGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
} else {
new_sig_clr = module->OrnotGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming
new_sig_clr = module->OrnotGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
}
pol_set = pol_clr;
Expand All @@ -730,28 +730,28 @@ void FfData::flip_bits(const pool<int> &bits) {
sig_clr = new_sig_clr;
}
if (has_clk || has_gclk)
sig_d = module->NotGate(NEW_ID2_SUFFIX("d"), sig_d, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->NotGate(NEW_ID4_SUFFIX("d"), sig_d, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
if (has_aload)
sig_ad = module->NotGate(NEW_ID2_SUFFIX("ad"), sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming
module->addNotGate(NEW_ID2_SUFFIX("not"), new_q, sig_q, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ad = module->NotGate(NEW_ID4_SUFFIX("ad"), sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
module->addNotGate(NEW_ID4_SUFFIX("not"), new_q, sig_q, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
else
{
if (has_sr) {
SigSpec not_clr;
if (!pol_clr) {
not_clr = sig_clr;
sig_clr = module->Not(NEW_ID2_SUFFIX("clr"), sig_clr, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_clr = module->Not(NEW_ID4_SUFFIX("clr"), sig_clr, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
pol_clr = true;
} else {
not_clr = module->Not(NEW_ID2_SUFFIX("not_clr"), sig_clr, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
not_clr = module->Not(NEW_ID4_SUFFIX("not_clr"), sig_clr, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}
if (!pol_set) {
sig_set = module->Not(NEW_ID2_SUFFIX("set"), sig_set, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_set = module->Not(NEW_ID4_SUFFIX("set"), sig_set, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
pol_set = true;
}

SigSpec masked_set = module->And(NEW_ID2_SUFFIX("masked_set"), sig_set, not_clr, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
SigSpec masked_set = module->And(NEW_ID4_SUFFIX("masked_set"), sig_set, not_clr, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
for (auto bit: bits) {
sig_set[bit] = sig_clr[bit];
sig_clr[bit] = masked_set[bit];
Expand All @@ -763,10 +763,10 @@ void FfData::flip_bits(const pool<int> &bits) {
mask.bits()[bit] = State::S1;

if (has_clk || has_gclk)
sig_d = module->Xor(NEW_ID2_SUFFIX("d"), sig_d, mask, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_d = module->Xor(NEW_ID4_SUFFIX("d"), sig_d, mask, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
if (has_aload)
sig_ad = module->Xor(NEW_ID2_SUFFIX("ad"), sig_ad, mask, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
module->addXor(NEW_ID2_SUFFIX("xor"), new_q, mask, sig_q, false, cell->get_src_attribute()); // SILIMATE: Improve the naming
sig_ad = module->Xor(NEW_ID4_SUFFIX("ad"), sig_ad, mask, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
module->addXor(NEW_ID4_SUFFIX("xor"), new_q, mask, sig_q, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming
}

sig_q = new_q;
Expand Down
22 changes: 10 additions & 12 deletions kernel/yosys_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,16 @@ RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std:
YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
#define NEW_ID_SUFFIX(suffix) \
YOSYS_NAMESPACE_PREFIX new_id_suffix(__FILE__, __LINE__, __FUNCTION__, suffix)
#define NEW_ID2 \
module->uniquify(cell->name.str())
#define NEW_ID2_SUFFIX(suffix) \
module->uniquify(cell->name.str() + "_" + suffix)
#define NEW_ID3 \
module->uniquify(cell_name.str())
#define NEW_ID3_SUFFIX(suffix) \
module->uniquify(cell_name.str() + "_" + suffix)
#define NEW_MEM_ID_SUFFIX(suffix) \
mem.mem ? module->uniquify(mem.mem->name.str() + "_" + suffix) : module->uniquify(string("\\mem_") + suffix)
#define NEW_ABC_ID \
module->uniquify(IdString("\\boolopt"))

#define UNQ_SUFFIX "_ix" + std::to_string(autoidx++)
#define NEW_ID2 IdString(cell->name.str() + UNQ_SUFFIX)
#define NEW_ID2_SUFFIX(suffix) IdString(cell->name.str() + "_" + suffix + UNQ_SUFFIX)
#define NEW_ID3 IdString(cell_name.str() + UNQ_SUFFIX)
#define NEW_ID3_SUFFIX(suffix) IdString(cell_name.str() + "_" + suffix + UNQ_SUFFIX)
#define NEW_ID4 IdString(name.str() + UNQ_SUFFIX)
#define NEW_ID4_SUFFIX(suffix) IdString(name.str() + "_" + suffix + UNQ_SUFFIX)
#define NEW_MEM_ID_SUFFIX(suffix) mem.mem ? module->uniquify(mem.mem->name.str() + "_" + suffix) : module->uniquify(string("\\mem_") + suffix)
#define NEW_ABC_ID module->uniquify(IdString("\\boolopt"))

// Create a statically allocated IdString object, using for example ID::A or ID($add).
//
Expand Down
2 changes: 1 addition & 1 deletion passes/techmap/techmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void apply_prefix(IdString prefix, IdString &id)
if (id[0] == '\\')
id = stringf("%s.%s", prefix.c_str(), id.c_str()+1);
else
id = stringf("$techmap%s.%s", prefix.c_str(), id.c_str());
id = stringf("\\%s.%s", prefix.c_str(), id.c_str());
}

void apply_prefix(IdString prefix, RTLIL::SigSpec &sig, RTLIL::Module *module)
Expand Down

0 comments on commit 52a1493

Please sign in to comment.