3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-21 05:13:40 +00:00
This commit is contained in:
Alain Dargelas 2025-02-26 16:51:39 -08:00
parent 6a26b2db55
commit ecd2ac4302

View file

@ -84,7 +84,6 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec, std::
std::cout << "max_output_per_buffer: " << max_output_per_buffer << "\n";
std::vector<RTLIL::SigSpec> buffer_outputs;
std::vector<RTLIL::Cell *> buffers;
std::cout << "HERE1\n" << std::flush;
std::cout << "CELL: " << cell->name.c_str() << "\n" << std::flush;
RTLIL::SigSpec cellOutSig;
for (auto &conn : cell->connections()) {
@ -95,7 +94,6 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec, std::
break;
}
}
std::cout << "HERE2\n" << std::flush;
for (int i = 0; i < num_buffers; ++i) {
RTLIL::Cell *buffer = module->addCell(NEW_ID2_SUFFIX("fbuf"), ID($buf)); // Assuming BUF is defined
RTLIL::SigSpec buffer_output = module->addWire(NEW_ID2_SUFFIX("fbuf"));
@ -104,9 +102,7 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec, std::
buffer_outputs.push_back(buffer_output);
buffers.push_back(buffer);
}
std::cout << "Lookup\n" << std::flush;
std::set<Cell *> cells = sig2CellsInFanout[cellOutSig];
std::cout << "Lookup OK\n" << std::flush;
int indexCurrentBuffer = 0;
int indexFanout = 0;
std::map<Cell *, int> bufferActualFanout;
@ -115,7 +111,10 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec, std::
IdString portName = conn.first;
RTLIL::SigSpec actual = conn.second;
if (c->input(portName)) {
if (actual.is_chunk()) {
if (sigmap(actual) == cellOutSig) {
std::cout << "vector size: " << buffer_outputs.size() << std::endl;
std::cout << "index : " << indexCurrentBuffer << std::endl;
c->setPort(portName, buffer_outputs[indexCurrentBuffer]);
sig2CellsInFanout[sigmap(buffer_outputs[indexCurrentBuffer])].insert(c);
indexFanout++;
@ -124,6 +123,35 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec, std::
indexFanout = 0;
indexCurrentBuffer++;
}
break;
}
} else {
bool match = false;
for (SigChunk chunk : actual.chunks()) {
if (sigmap(SigSpec(chunk)) == cellOutSig) {
match = true;
break;
}
}
if (match) {
std::vector<RTLIL::SigChunk> newChunks;
for (SigChunk chunk : actual.chunks()) {
if (sigmap(SigSpec(chunk)) == cellOutSig) {
newChunks.push_back(buffer_outputs[indexCurrentBuffer].as_wire());
} else {
newChunks.push_back(chunk);
}
}
c->setPort(portName, newChunks);
sig2CellsInFanout[sigmap(buffer_outputs[indexCurrentBuffer])].insert(c);
indexFanout++;
bufferActualFanout[buffers[indexCurrentBuffer]] = indexFanout;
if (indexFanout >= max_output_per_buffer) {
indexFanout = 0;
indexCurrentBuffer++;
}
break;
}
}
}
}
@ -132,6 +160,7 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict<RTLIL::SigSpec, std::
// Recursively fix the fanout of the newly created buffers
for (std::map<Cell *, int>::iterator itr = bufferActualFanout.begin(); itr != bufferActualFanout.end(); itr++) {
if (itr->second == 1) {
// Remove newly created buffers with a fanout of 1
std::cout << "Buffer of 1" << std::endl;
for (Cell *c : cells) {
for (auto &conn : c->connections()) {
@ -234,7 +263,7 @@ struct AnnotateCellFanout : public ScriptPass {
break;
}
extra_args(args, argidx, design);
if (limit < 2) {
if ((limit != -1) && (limit < 2)) {
log_error("Fanout cannot be limited to less than 2\n");
return;
}