mirror of
https://github.com/YosysHQ/yosys
synced 2026-05-03 08:55:15 +00:00
Invert.
This commit is contained in:
parent
42c309347b
commit
4bbffecf98
1 changed files with 16 additions and 9 deletions
|
|
@ -91,7 +91,8 @@ struct AluInfo {
|
||||||
return GetSize(bi) == 1 && bi[0] == State::S0 && GetSize(ci) == 1 && ci[0] == State::S0;
|
return GetSize(bi) == 1 && bi[0] == State::S0 && GetSize(ci) == 1 && ci[0] == State::S0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A cell is chainable if it's a plain add/sub with unused carries.
|
// Chainable cells are adds/subs with no carry usage, connected chainable
|
||||||
|
// cells form chains that can be replaced with CSA trees.
|
||||||
bool is_chainable(Cell* cell)
|
bool is_chainable(Cell* cell)
|
||||||
{
|
{
|
||||||
if (!(is_add(cell) || is_subtract(cell)))
|
if (!(is_add(cell) || is_subtract(cell)))
|
||||||
|
|
@ -138,7 +139,7 @@ struct Rewriter
|
||||||
return consumer;
|
return consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find cells that consumes another cell's output.
|
// Find cells that consume another cell's output.
|
||||||
dict<Cell*, Cell*> find_parents(const pool<Cell*>& candidates)
|
dict<Cell*, Cell*> find_parents(const pool<Cell*>& candidates)
|
||||||
{
|
{
|
||||||
dict<Cell*, Cell*> parent_of;
|
dict<Cell*, Cell*> parent_of;
|
||||||
|
|
@ -151,6 +152,17 @@ struct Rewriter
|
||||||
return parent_of;
|
return parent_of;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<dict<Cell*, pool<Cell*>>, pool<Cell*>> invert_parent_map(const dict<Cell*, Cell*>& parent_of)
|
||||||
|
{
|
||||||
|
dict<Cell*, pool<Cell*>> children_of;
|
||||||
|
pool<Cell*> has_parent;
|
||||||
|
for (auto& [child, parent] : parent_of) {
|
||||||
|
children_of[parent].insert(child);
|
||||||
|
has_parent.insert(child);
|
||||||
|
}
|
||||||
|
return {children_of, has_parent};
|
||||||
|
}
|
||||||
|
|
||||||
pool<Cell*> collect_chain(Cell* root, const dict<Cell*, pool<Cell*>>& children_of)
|
pool<Cell*> collect_chain(Cell* root, const dict<Cell*, pool<Cell*>>& children_of)
|
||||||
{
|
{
|
||||||
pool<Cell*> chain;
|
pool<Cell*> chain;
|
||||||
|
|
@ -376,6 +388,7 @@ struct Rewriter
|
||||||
extended.push_back(s);
|
extended.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add correction for negated operands (-x = ~x + 1 so 1 per negation)
|
||||||
if (neg_compensation > 0)
|
if (neg_compensation > 0)
|
||||||
extended.push_back(SigSpec(neg_compensation, width));
|
extended.push_back(SigSpec(neg_compensation, width));
|
||||||
|
|
||||||
|
|
@ -402,13 +415,7 @@ struct Rewriter
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto parent_of = find_parents(candidates);
|
auto parent_of = find_parents(candidates);
|
||||||
|
auto [children_of, has_parent] = invert_parent_map(parent_of);
|
||||||
dict<Cell*, pool<Cell*>> children_of;
|
|
||||||
pool<Cell*> has_parent;
|
|
||||||
for (auto& [child, parent] : parent_of) {
|
|
||||||
children_of[parent].insert(child);
|
|
||||||
has_parent.insert(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
pool<Cell*> processed;
|
pool<Cell*> processed;
|
||||||
for (auto root : candidates) {
|
for (auto root : candidates) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue