mirror of
https://github.com/YosysHQ/yosys
synced 2026-07-21 06:35:49 +00:00
Add muxmode pass and tests
This commit is contained in:
parent
dacd882383
commit
161ff0fa3f
7 changed files with 653 additions and 2 deletions
77
tests/silimate/muxinvprop.ys
Normal file
77
tests/silimate/muxinvprop.ys
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
log -header "Simple positive case with 4-long mux chain and 1 inverted component"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire [3:0] s,
|
||||
input wire [3:0] b,
|
||||
input wire a,
|
||||
output wire y
|
||||
);
|
||||
assign y = s[0] ? b[0] : (s[1] ? b[1] : ~(s[2] ? b[2] : (s[3] ? b[3] : a)));
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 4 t:$mux
|
||||
select -assert-count 3 t:$not
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple negative case with 4-long mux chain and 1 inverted fo2 component"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire [3:0] s,
|
||||
input wire [3:0] b,
|
||||
input wire a,
|
||||
output wire y,
|
||||
output wire y2
|
||||
);
|
||||
wire m;
|
||||
assign m = s[2] ? b[2] : (s[3] ? b[3] : a);
|
||||
assign y2 = m;
|
||||
assign y = s[0] ? b[0] : (s[1] ? b[1] : ~m);
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 4 t:$mux
|
||||
select -assert-count 1 t:$not
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
362
tests/silimate/muxmode.ys
Normal file
362
tests/silimate/muxmode.ys
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
log -header "Simple positive case with AND"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire s1,
|
||||
input wire s2,
|
||||
input wire a,
|
||||
input wire b,
|
||||
input wire c,
|
||||
input wire d,
|
||||
output wire x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = m1 & c;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 3 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple positive case with AND (order reversed)"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire s1,
|
||||
input wire s2,
|
||||
input wire a,
|
||||
input wire b,
|
||||
input wire c,
|
||||
input wire d,
|
||||
output wire x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = c & m1;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 3 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple positive case with OR"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire s1,
|
||||
input wire s2,
|
||||
input wire a,
|
||||
input wire b,
|
||||
input wire c,
|
||||
input wire d,
|
||||
output wire x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = m1 | c;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 3 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple positive case with OR (order reversed)"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire s1,
|
||||
input wire s2,
|
||||
input wire a,
|
||||
input wire b,
|
||||
input wire c,
|
||||
input wire d,
|
||||
output wire x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = c | m1;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 3 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
log -header "Simple negative case with multi-bit AND"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire [1:0] s1,
|
||||
input wire [1:0] s2,
|
||||
input wire [1:0] a,
|
||||
input wire [1:0] b,
|
||||
input wire [1:0] c,
|
||||
input wire [1:0] d,
|
||||
output wire [1:0] x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = m1 & c;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 1 t:$and
|
||||
select -assert-count 2 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple negative case with multi-bit AND (order reversed)"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire [1:0] s1,
|
||||
input wire [1:0] s2,
|
||||
input wire [1:0] a,
|
||||
input wire [1:0] b,
|
||||
input wire [1:0] c,
|
||||
input wire [1:0] d,
|
||||
output wire [1:0] x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = c & m1;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 1 t:$and
|
||||
select -assert-count 2 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple negative case with OR"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire [1:0] s1,
|
||||
input wire [1:0] s2,
|
||||
input wire [1:0] a,
|
||||
input wire [1:0] b,
|
||||
input wire [1:0] c,
|
||||
input wire [1:0] d,
|
||||
output wire [1:0] x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = m1 | c;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 1 t:$or
|
||||
select -assert-count 2 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
|
||||
|
||||
|
||||
log -header "Simple negative case with multi-bit OR (order reversed)"
|
||||
log -push
|
||||
design -reset
|
||||
read_verilog <<EOF
|
||||
module top (
|
||||
input wire [1:0] s1,
|
||||
input wire [1:0] s2,
|
||||
input wire [1:0] a,
|
||||
input wire [1:0] b,
|
||||
input wire [1:0] c,
|
||||
input wire [1:0] d,
|
||||
output wire [1:0] x
|
||||
);
|
||||
wire m1, m2;
|
||||
|
||||
assign m1 = s1 ? b : a;
|
||||
assign m2 = c | m1;
|
||||
assign x = s2 ? m2 : d;
|
||||
endmodule
|
||||
EOF
|
||||
check -assert
|
||||
|
||||
# # Show pre
|
||||
# autoname
|
||||
# write_json pre.json
|
||||
# exec -- netlistsvg pre.json -o pre.svg
|
||||
|
||||
# Check equivalence after muxmode
|
||||
equiv_opt -assert muxmode
|
||||
|
||||
# Check final design has correct number of gates
|
||||
design -load postopt
|
||||
select -assert-count 1 t:$or
|
||||
select -assert-count 2 t:$mux
|
||||
|
||||
# # Show post
|
||||
# autoname
|
||||
# write_json post.json
|
||||
# exec -- netlistsvg post.json -o post.svg
|
||||
|
||||
design -reset
|
||||
log -pop
|
||||
Loading…
Add table
Add a link
Reference in a new issue