Skip to content

Commit f874811

Browse files
authored
Fix netlist rewrite (#219)
1 parent f9515f2 commit f874811

File tree

4 files changed

+92
-11
lines changed

4 files changed

+92
-11
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ toml = "0.9.11"
4646
thiserror = { version = "2.0.16" }
4747
sv-parser = "0.13.4"
4848
ctrlc = "3.5.1"
49-
safety-net = { version = "0.5.4", features = ["graph"] }
49+
safety-net = { version = "0.5.5", features = ["graph"] }
5050
good_lp = { version = "1.14.2", optional = true }
51-
nl-compiler = { version = "0.1.14" }
51+
nl-compiler = { version = "0.1.15" }
5252

5353
[lints.clippy]
5454
manual_range_contains = "allow"

src/netlist.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,11 @@ impl<I: Instantiable + LogicFunc<L>, L: CircuitLang + LogicCell<I>> LogicMapping
552552
drop(self);
553553
drop(mapping);
554554

555-
let mut new_roots = Vec::new();
555+
let mut new_roots = HashSet::new();
556556

557557
for (old, new) in root_pairs {
558558
if old == new {
559-
new_roots.push(new);
559+
new_roots.insert(new);
560560
continue;
561561
}
562562

@@ -566,14 +566,14 @@ impl<I: Instantiable + LogicFunc<L>, L: CircuitLang + LogicCell<I>> LogicMapping
566566
}
567567

568568
netlist.replace_net_uses(old, &new)?;
569-
new_roots.push(new);
569+
new_roots.insert(new);
570570
}
571571

572-
netlist.clean()?;
572+
netlist.retain(&mut new_roots)?;
573573

574574
netlist.rename_nets(|_, i| format_id!("__{i}__"))?;
575575

576-
Ok(new_roots)
576+
Ok(new_roots.into_iter().collect())
577577
}
578578
}
579579

tests/driver/rewrite_bug.v

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// RUN: eqmap_fpga %s --assert-sat --no-retime -k 4 | FileCheck %s
2+
3+
module rewrite_bug (
4+
clk,
5+
rst,
6+
a,
7+
y
8+
);
9+
wire _0_;
10+
input a;
11+
wire a;
12+
input clk;
13+
wire clk;
14+
wire p;
15+
wire q;
16+
input rst;
17+
wire rst;
18+
output y;
19+
wire y;
20+
LUT2 #(
21+
.INIT(4'h5)
22+
) _1_ (
23+
.I0(q),
24+
.I1(p),
25+
.O (_0_)
26+
);
27+
FDRE #(
28+
.INIT(1'hx)
29+
) _2_ (
30+
.C (clk),
31+
.CE(1'h1),
32+
.D (a),
33+
.Q (q),
34+
.R (rst)
35+
);
36+
FDRE #(
37+
.INIT(1'hx)
38+
) _3_ (
39+
.C (clk),
40+
.CE(1'h1),
41+
.D (q),
42+
.Q (p),
43+
.R (1'h0)
44+
);
45+
FDRE #(
46+
.INIT(1'hx)
47+
) _4_ (
48+
.C (clk),
49+
.CE(1'h1),
50+
.D (_0_),
51+
.Q (y),
52+
.R (rst)
53+
);
54+
55+
// CHECK: FDRE #(
56+
// CHECK: .INIT(1'bx)
57+
// CHECK: ) __4__ (
58+
// CHECK: .D(a),
59+
// CHECK: .C(clk),
60+
// CHECK: .CE(1'b1),
61+
// CHECK: .R(rst),
62+
// CHECK: .Q(__0__)
63+
// CHECK: );
64+
// CHECK: FDRE #(
65+
// CHECK: .INIT(1'bx)
66+
// CHECK: ) __5__ (
67+
// CHECK: .D(__3__),
68+
// CHECK: .C(clk),
69+
// CHECK: .CE(1'b1),
70+
// CHECK: .R(rst),
71+
// CHECK: .Q(__1__)
72+
// CHECK: );
73+
// CHECK: LUT1 #(
74+
// CHECK: .INIT(2'b01)
75+
// CHECK: ) __7__ (
76+
// CHECK: .I0(__0__),
77+
// CHECK: .O(__3__)
78+
// CHECK: );
79+
// CHECK: assign y = __1__;
80+
81+
endmodule

0 commit comments

Comments
 (0)