Skip to content

Commit

Permalink
Create nicer gates (Buffer/Not) when reading blif files
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloquinte committed Jan 24, 2024
1 parent 2a54b1c commit 9940d01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/io/blif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,24 @@ fn build_network(
_ => return Err(format!("Invalid cube: {}", s)),
};
polarities.push(pol);
if pol {
cube_gates.push(Gate::andn(&deps));
let g = if pol {
if deps.len() == 0 {

Check warning on line 172 in src/io/blif.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

length comparison to zero

warning: length comparison to zero --> src/io/blif.rs:172:20 | 172 | if deps.len() == 0 { | ^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `deps.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default

Check warning on line 172 in src/io/blif.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

length comparison to zero

warning: length comparison to zero --> src/io/blif.rs:172:20 | 172 | if deps.len() == 0 { | ^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `deps.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default
Gate::Buf(Signal::one())
} else if deps.len() == 1 {
Gate::Buf(deps[0])
} else {
Gate::andn(&deps)
}
} else {
cube_gates.push(Gate::Nary(deps.into(), NaryType::Nand));
}
if deps.len() == 0 {

Check warning on line 180 in src/io/blif.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

length comparison to zero

warning: length comparison to zero --> src/io/blif.rs:180:20 | 180 | if deps.len() == 0 { | ^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `deps.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero

Check warning on line 180 in src/io/blif.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

length comparison to zero

warning: length comparison to zero --> src/io/blif.rs:180:20 | 180 | if deps.len() == 0 { | ^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `deps.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
Gate::Buf(Signal::zero())
} else if deps.len() == 1 {
Gate::Buf(!deps[0])
} else {
Gate::Nary(deps.into(), NaryType::Nand)
}
};

Check warning on line 187 in src/io/blif.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

this `else { if .. }` block can be collapsed

warning: this `else { if .. }` block can be collapsed --> src/io/blif.rs:179:20 | 179 | } else { | ____________________^ 180 | | if deps.len() == 0 { 181 | | Gate::Buf(Signal::zero()) 182 | | } else if deps.len() == 1 { ... | 186 | | } 187 | | }; | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if = note: `#[warn(clippy::collapsible_else_if)]` on by default help: collapse nested if block | 179 ~ } else if deps.len() == 0 { 180 + Gate::Buf(Signal::zero()) 181 + } else if deps.len() == 1 { 182 + Gate::Buf(!deps[0]) 183 + } else { 184 + Gate::Nary(deps.into(), NaryType::Nand) 185 ~ }; |

Check warning on line 187 in src/io/blif.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

this `else { if .. }` block can be collapsed

warning: this `else { if .. }` block can be collapsed --> src/io/blif.rs:179:20 | 179 | } else { | ____________________^ 180 | | if deps.len() == 0 { 181 | | Gate::Buf(Signal::zero()) 182 | | } else if deps.len() == 1 { ... | 186 | | } 187 | | }; | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if = note: `#[warn(clippy::collapsible_else_if)]` on by default help: collapse nested if block | 179 ~ } else if deps.len() == 0 { 180 + Gate::Buf(Signal::zero()) 181 + } else if deps.len() == 1 { 182 + Gate::Buf(!deps[0]) 183 + } else { 184 + Gate::Nary(deps.into(), NaryType::Nand) 185 ~ }; |
cube_gates.push(g);
}
if cube_gates.is_empty() {
ret.replace(gate, Gate::Buf(Signal::zero()));
Expand Down
11 changes: 7 additions & 4 deletions src/network/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ pub fn stats(a: &Network) -> NetworkStats {
Ternary(_, TernaryType::Mux) => ret.nb_mux += 1,
Ternary(_, TernaryType::Maj) => ret.nb_maj += 1,
Buf(s) => {
if s.is_inverted() {
ret.nb_not += 1;
} else {
ret.nb_buf += 1;
if !s.is_constant() {
// Do not count buffered constants that may be created for I/O
if s.is_inverted() {
ret.nb_not += 1;
} else {
ret.nb_buf += 1;
}
}
}
Dff([_, en, res]) => {
Expand Down

0 comments on commit 9940d01

Please sign in to comment.