3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-01-04 10:08:47 +00:00

Merge pull request #3516 from dehekkendekrekker/subcircuit_fix

Fixes #3515
This commit is contained in:
KrystalDelusion 2025-11-29 12:51:15 +13:00 committed by GitHub
commit 34fa8a4ff7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 1 deletions

View file

@ -912,6 +912,10 @@ class SubCircuit::SolverWorker
bool pruneEnumerationMatrix(std::vector<std::set<int>> &enumerationMatrix, const GraphData &needle, const GraphData &haystack, int &nextRow, bool allowOverlap)
{
bool didSomething = true;
// Map of j:[i where j is used]
std::map<int, std::set<int>> usedNodes;
while (didSomething)
{
nextRow = -1;
@ -923,13 +927,23 @@ class SubCircuit::SolverWorker
didSomething = true;
else if (!allowOverlap && haystack.usedNodes[j])
didSomething = true;
else
else {
newRow.insert(j);
usedNodes[j].insert(i); // Store the needle index by haystack node index
}
}
// This indicates there are no available haystack nodes to assign to the needle
if (newRow.size() == 0)
return false;
// If there are multiple needles assigned to the haystack node, the solution is invalid
if (newRow.size() == 1 && usedNodes[*newRow.begin()].size() > 1)
return false;
if (newRow.size() >= 2 && (nextRow < 0 || needle.adjMatrix.at(nextRow).size() < needle.adjMatrix.at(i).size()))
nextRow = i;
enumerationMatrix[i].swap(newRow);
}
}

26
tests/various/bug3515.v Normal file
View file

@ -0,0 +1,26 @@
// Triple AND GATE
module mod_74x08_3 (
input A_1,
input B_1,
input A_2,
input B_2,
input A_3,
input B_3,
output Y_1,
output Y_2,
output Y_3);
assign Y_1 = A_1 & B_1;
assign Y_2 = A_2 & B_2;
assign Y_3 = A_3 & B_3;
endmodule
// OR GATE
module mod_74x32_1 (
input A_1,
input B_1,
output Y_1);
assign Y_1 = A_1 | B_1;
endmodule

31
tests/various/bug3515.ys Normal file
View file

@ -0,0 +1,31 @@
# base case is able to map
read_verilog << EOF
module and_x3 (
input a, b, c, d,
output reg y
);
assign y = (a&b)&(c&d);
endmodule
EOF
hierarchy -top and_x3
opt
extract -map ./bug3515.v
select -assert-count 1 t:mod_74x08_3
# more needles than haystacks; not able to map
design -reset
read_verilog << EOF
module mod_and_or (
input a, b, c, d,
output reg y
);
assign y = (a&b)|(c&d);
endmodule
EOF
hierarchy -top mod_and_or
opt
extract -map ./bug3515.v
select -assert-count 2 t:$and