Skip to content

Commit

Permalink
Merge pull request YosysHQ#2326 from YosysHQ/mwk/peeopt-muldiv-sign
Browse files Browse the repository at this point in the history
peepopt.muldiv: Add a signedness check.
  • Loading branch information
clairexen authored Aug 20, 2020
2 parents 1cdb533 + e89cc9c commit 16bb3fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion passes/pmgen/peepopt_muldiv.pmg
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
pattern muldiv

state <SigSpec> t x y
state <bool> is_signed

match mul
select mul->type == $mul
select GetSize(port(mul, \A)) + GetSize(port(mul, \B)) <= GetSize(port(mul, \Y))
endmatch

code t x y
code t x y is_signed
t = port(mul, \Y);
x = port(mul, \A);
y = port(mul, \B);
is_signed = param(mul, \A_SIGNED).as_bool();
branch;
std::swap(x, y);
endcode
Expand All @@ -19,6 +21,7 @@ match div
select div->type.in($div)
index <SigSpec> port(div, \A) === t
index <SigSpec> port(div, \B) === x
filter param(div, \A_SIGNED).as_bool() == is_signed
endmatch

code
Expand Down
12 changes: 12 additions & 0 deletions tests/opt/bug2318.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
read_verilog <<EOT
module t(input [3:0] A, input [3:0] B, output signed [3:0] Y);

wire [7:0] P = A * B;
wire signed [7:0] SP = P;
wire signed [3:0] SB = B;
assign Y = SP / SB;

endmodule
EOT

equiv_opt -assert peepopt

0 comments on commit 16bb3fc

Please sign in to comment.