yosys/tests/silimate/opt_expand.ys

262 lines
4.2 KiB
Plaintext

log -header "Simple positive case"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
output wire x
);
wire m;
assign m = a | b;
assign x = m & c;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 2 t:$and
select -assert-count 1 t:$or
design -reset
log -pop
log -header "No intermediate wire: (a | b) & c"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
output wire x
);
assign x = (a | b) & c;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 2 t:$and
select -assert-count 1 t:$or
design -reset
log -pop
log -header "No intermediate wire flipped: c & (a | b)"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
output wire x
);
assign x = c & (a | b);
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 2 t:$and
select -assert-count 1 t:$or
design -reset
log -pop
log -header "Fanout from intermediate wire"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
output wire m,
output wire x
);
assign m = a | b;
assign x = c & m;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 1 t:$and
select -assert-count 1 t:$or
design -reset
log -pop
log -header "Nested AND gate: ((a & b) | c) & d"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
input wire d,
output wire x
);
assign x = ((a & b) | c) & d;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 3 t:$and
select -assert-count 1 t:$or
design -reset
log -pop
log -header "Nested OR gate: ((a | b) | c) & d"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
input wire d,
output wire x
);
assign x = ((a | b) | c) & d;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 3 t:$and
select -assert-count 2 t:$or
design -reset
log -pop
log -header "With inverter: (~a | b) & c"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
output wire x
);
assign x = (~a | b) & c;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 2 t:$and
select -assert-count 1 t:$or
design -reset
log -pop
log -header "Deeper nesting: ((a | b) & (c | d)) & e"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
input wire d,
input wire e,
output wire x
);
assign x = ((a | b) & (c | d)) & e;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 4 t:$and
select -assert-count 2 t:$or
design -reset
log -pop
log -header "More inputs and nesting: ((a | b | c) & (d | e)) & f"
log -push
design -reset
read_verilog <<EOF
module top (
input wire a,
input wire b,
input wire c,
input wire d,
input wire e,
input wire f,
output wire x
);
assign x = ((a | b | c) & (d | e)) & f;
endmodule
EOF
check -assert
# Check equivalence after opt_expand
equiv_opt -assert opt_expand
# Check final design has correct number of gates
design -load postopt
select -assert-count 4 t:$and
select -assert-count 3 t:$or
design -reset
log -pop