Skip to content

Commit

Permalink
Merge pull request #2 from alainmarcel/new_peepopts
Browse files Browse the repository at this point in the history
Fix code review issue
  • Loading branch information
akashlevy authored Dec 18, 2024
2 parents f9ae66d + 2979232 commit 6c5d7cc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions passes/pmgen/peepopt_muldiv_c.pmg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ match div
// Check that b_const and c_const is constant
filter b_const.is_fully_const()
filter port(div, \B).is_fully_const()
index <SigSpec> remove_bottom_padding(port(div, \A)) === mul_y
endmatch

code
Expand Down
7 changes: 7 additions & 0 deletions passes/pmgen/pmgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ def process_pmgfile(f, filename):
print(" }", file=f)
print("", file=f)

print(" SigSpec remove_bottom_padding(SigSpec sig) {", file=f)
print(" int i = 0;", file=f)
print(" for (; i < sig.size() - 1 && sig[i] == State::S0; i++) {} ", file=f)
print(" return sig.extract(i, sig.size() - i);", file=f)
print(" }", file=f)
print("", file=f)

print(" void blacklist(Cell *cell) {", file=f)
print(" if (cell != nullptr && blacklist_cells.insert(cell).second) {", file=f)
print(" auto ptr = rollback_cache.find(cell);", file=f)
Expand Down
38 changes: 38 additions & 0 deletions tests/peepopt/multdiv_c.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
log -header "Test simple positive case"
log -push
design -reset
read_verilog <<EOF
module muldiv_const_ok (
input wire [31:0] a,
output wire [63:0] y
);
assign y = (a * 5140) / (257 * 2);
endmodule
EOF
check -assert
equiv_opt -assert peepopt ;;;
design -load postopt
select -assert-any t:$mul # assert mult

log -pop
log -header "Test negative case where div is kept"
log -push
design -reset
read_verilog <<EOF
module muldiv_const_ko (
input wire signed [31:0] a,
output wire signed [63:0] y,
output wire probe
);
wire [44:0] tmp = (a * 5140);
assign probe = tmp[44];

assign y = tmp[43:0] / (257 * 2);
endmodule
EOF
check -assert
equiv_opt -assert peepopt ;;;
design -load postopt
select -assert-any t:$div # assert div

log -pop

0 comments on commit 6c5d7cc

Please sign in to comment.