mirror of
https://github.com/YosysHQ/yosys.git
synced 2026-10-08 02:52:53 +02:00
#6130 fixed arith_tree so that a chain link narrower than its consumer is left out of the tree, and added an equivalence regression for the exact failing shape. Cover what that test does not: structural checks that the narrow link survives as its own cell, on both the raw $add path and the alumacc $alu path, and a mixed case where a wider chain consuming the truncated link as a leaf still folds and stays equivalent. Signed-off-by: Daniel M'BOUYOU <[email protected]>
212 lines
3.8 KiB
Plaintext
212 lines
3.8 KiB
Plaintext
read_verilog <<EOT
|
|
module equiv_add3(
|
|
input [3:0] a, b, c,
|
|
output [3:0] y
|
|
);
|
|
assign y = a + b + c;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 1 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_add4(
|
|
input [3:0] a, b, c, d,
|
|
output [3:0] y
|
|
);
|
|
assign y = a + b + c + d;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 2 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_add5(
|
|
input [3:0] a, b, c, d, e,
|
|
output [3:0] y
|
|
);
|
|
assign y = a + b + c + d + e;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 3 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_add8(
|
|
input [3:0] a, b, c, d, e, f, g, h,
|
|
output [3:0] y
|
|
);
|
|
assign y = a + b + c + d + e + f + g + h;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 6 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_signed(
|
|
input signed [3:0] a, b, c, d,
|
|
output signed [5:0] y
|
|
);
|
|
assign y = a + b + c + d;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 2 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_mixed(
|
|
input [1:0] a,
|
|
input [3:0] b,
|
|
input [5:0] c,
|
|
output [5:0] y
|
|
);
|
|
assign y = a + b + c;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 1 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_sub_3op(
|
|
input [3:0] a, b, c,
|
|
output [3:0] y
|
|
);
|
|
assign y = a - b + c;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 2 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_sub_mixed(
|
|
input [3:0] a, b, c, d,
|
|
output [3:0] y
|
|
);
|
|
assign y = a + b - c + d;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-min 1 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_sub_all(
|
|
input [3:0] a, b, c, d,
|
|
output [3:0] y
|
|
);
|
|
assign y = a - b - c - d;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-min 1 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_sub_signed(
|
|
input signed [3:0] a, b, c, d,
|
|
output signed [5:0] y
|
|
);
|
|
assign y = a + b - c - d;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-count 3 t:$fa
|
|
select -assert-count 1 t:$add
|
|
design -reset
|
|
|
|
read_verilog <<EOT
|
|
module equiv_double_neg(
|
|
input [3:0] a, b, c,
|
|
output [4:0] y
|
|
);
|
|
wire [3:0] ab = a - b;
|
|
assign y = c - ab;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -reset
|
|
|
|
# A chain link that is narrower than the cell consuming it truncates its own
|
|
# result, and that truncation is observable in the wider consumer. Flattening
|
|
# the chain must not recover the carry the narrower link discarded.
|
|
read_verilog <<EOT
|
|
module equiv_narrow_intermediate(
|
|
input [7:0] a, b, c,
|
|
output [8:0] y
|
|
);
|
|
wire [7:0] t = a + b;
|
|
assign y = t + c;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -reset
|
|
|
|
# Only the truncating link must be excluded: with a truncated t entering the
|
|
# wider (t+c+d) chain as a leaf, the wide part still folds into a tree and the
|
|
# whole result stays equivalent.
|
|
read_verilog <<EOT
|
|
module equiv_trunc_mixed(
|
|
input [7:0] a, b, c, d,
|
|
output [9:0] y
|
|
);
|
|
wire [7:0] t = a + b;
|
|
assign y = t + c + d;
|
|
endmodule
|
|
EOT
|
|
hierarchy -auto-top
|
|
proc
|
|
equiv_opt -assert arith_tree
|
|
design -load postopt
|
|
select -assert-min 1 t:$fa
|
|
design -reset
|