Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proc_dff: bit-granularity optimizations and refactoring #4781

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
35 changes: 23 additions & 12 deletions passes/opt/opt_dff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "passes/techmap/simplemap.h"
#include <stdio.h>
#include <stdlib.h>
#include <optional>

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
Expand Down Expand Up @@ -95,6 +96,18 @@ struct OptDffWorker

}

// If this bit sigmaps to a bit driven by a mux ouput bit that only drives this
// bit, returns that mux otherwise nullopt
std::optional<cell_int_t> mergeable_mux(SigBit bit) {
sigmap.apply(bit);
auto it = bit2mux.find(bit);

if (it == bit2mux.end() || bitusers[bit] != 1)
return std::nullopt;

return it->second;
}

State combine_const(State a, State b) {
if (a == State::Sx && !opt.keepdc)
return b;
Expand Down Expand Up @@ -591,13 +604,12 @@ struct OptDffWorker
State reset_val = State::Sx;
if (ff.has_srst)
reset_val = ff.val_srst[i];
while (bit2mux.count(ff.sig_d[i]) && bitusers[ff.sig_d[i]] == 1) {
cell_int_t mbit = bit2mux.at(ff.sig_d[i]);
if (GetSize(mbit.first->getPort(ID::S)) != 1)
while (const auto mbit = mergeable_mux(ff.sig_d[i])) {
if (GetSize(mbit->first->getPort(ID::S)) != 1)
break;
SigBit s = mbit.first->getPort(ID::S);
SigBit a = mbit.first->getPort(ID::A)[mbit.second];
SigBit b = mbit.first->getPort(ID::B)[mbit.second];
SigBit s = mbit->first->getPort(ID::S);
SigBit a = mbit->first->getPort(ID::A)[mbit->second];
SigBit b = mbit->first->getPort(ID::B)[mbit->second];
// Workaround for funny memory WE pattern.
if ((a == State::S0 || a == State::S1) && (b == State::S0 || b == State::S1))
break;
Expand Down Expand Up @@ -668,13 +680,12 @@ struct OptDffWorker
for (int i = 0 ; i < ff.width; i++) {
// First, eat up as many simple muxes as possible.
ctrls_t enables;
while (bit2mux.count(ff.sig_d[i]) && bitusers[ff.sig_d[i]] == 1) {
cell_int_t mbit = bit2mux.at(ff.sig_d[i]);
if (GetSize(mbit.first->getPort(ID::S)) != 1)
while (const auto mbit = mergeable_mux(ff.sig_d[i])) {
if (GetSize(mbit->first->getPort(ID::S)) != 1)
break;
SigBit s = mbit.first->getPort(ID::S);
SigBit a = mbit.first->getPort(ID::A)[mbit.second];
SigBit b = mbit.first->getPort(ID::B)[mbit.second];
SigBit s = mbit->first->getPort(ID::S);
SigBit a = mbit->first->getPort(ID::A)[mbit->second];
SigBit b = mbit->first->getPort(ID::B)[mbit->second];
if (a == ff.sig_q[i]) {
enables.insert(ctrl_t(s, true));
ff.sig_d[i] = b;
Expand Down
Loading
Loading