first tests for opt_expand

This commit is contained in:
William Zhu 2025-03-27 12:31:37 -07:00
parent 3d13f7aae2
commit cc4c9c4eba
3 changed files with 232 additions and 0 deletions

View File

@ -946,6 +946,7 @@ SH_TEST_DIRS += tests/blif
SH_TEST_DIRS += tests/memfile
SH_TEST_DIRS += tests/fmt
# SH_TEST_DIRS += tests/cxxrtl
SH_TEST_DIRS += tests/silimate
ifeq ($(ENABLE_FUNCTIONAL_TESTS),1)
SH_TEST_DIRS += tests/functional
endif

View File

@ -0,0 +1,225 @@
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
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
equiv_opt -assert opt_expand
design -load postopt
select -assert-count 4 t:$and
select -assert-count 3 t:$or
design -reset
log -pop

6
tests/silimate/run-test.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
for x in *.ys; do
echo "Running $x.."
../../yosys -ql ${x%.ys}.log $x
done