mirror of
https://github.com/YosysHQ/yosys
synced 2026-03-23 04:49:15 +00:00
Add chain tests and tighten synthesis assertions for csa.
This commit is contained in:
parent
a7fcfc18fa
commit
1f097a937f
21 changed files with 230 additions and 16 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// edge case for carry shifting
|
||||
// Edge case for carry shifting
|
||||
|
||||
module add_1bit(
|
||||
input a, b, c,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
read_verilog add_1bit.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
equiv_opt csa_tree
|
||||
design -load postopt
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Test bit correctness
|
||||
|
||||
read_verilog equiv_narrow.v
|
||||
hierarchy -top equiv_add3
|
||||
proc; opt_clean
|
||||
|
|
|
|||
8
tests/csa_tree/csa_tree_sub_2op_neg.ys
Normal file
8
tests/csa_tree/csa_tree_sub_2op_neg.ys
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
read_verilog sub_2op_neg.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-none t:$fa
|
||||
select -assert-count 1 t:$sub
|
||||
11
tests/csa_tree/csa_tree_sub_3op.ys
Normal file
11
tests/csa_tree/csa_tree_sub_3op.ys
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Test minimal sub chain
|
||||
|
||||
read_verilog sub_3op.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
select -assert-none t:$sub
|
||||
9
tests/csa_tree/csa_tree_sub_5op.ys
Normal file
9
tests/csa_tree/csa_tree_sub_5op.ys
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
read_verilog sub_5op.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-min 2 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
select -assert-none t:$sub
|
||||
9
tests/csa_tree/csa_tree_sub_all.ys
Normal file
9
tests/csa_tree/csa_tree_sub_all.ys
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
read_verilog sub_all.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
select -assert-none t:$sub
|
||||
41
tests/csa_tree/csa_tree_sub_equiv.ys
Normal file
41
tests/csa_tree/csa_tree_sub_equiv.ys
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Test equiv_opt on narrow sub designs
|
||||
|
||||
read_verilog equiv_sub_narrow.v
|
||||
hierarchy -top equiv_sub_mixed
|
||||
proc; opt_clean
|
||||
equiv_opt csa_tree
|
||||
design -load postopt
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
design -reset
|
||||
log "equiv_sub_mixed: ok"
|
||||
|
||||
read_verilog equiv_sub_narrow.v
|
||||
hierarchy -top equiv_sub_all
|
||||
proc; opt_clean
|
||||
equiv_opt csa_tree
|
||||
design -load postopt
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
design -reset
|
||||
log "equiv_sub_all: ok"
|
||||
|
||||
read_verilog equiv_sub_narrow.v
|
||||
hierarchy -top equiv_sub_3op
|
||||
proc; opt_clean
|
||||
equiv_opt csa_tree
|
||||
design -load postopt
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
design -reset
|
||||
log "equiv_sub_3op: ok"
|
||||
|
||||
read_verilog equiv_sub_narrow.v
|
||||
hierarchy -top equiv_sub_signed
|
||||
proc; opt_clean
|
||||
equiv_opt csa_tree
|
||||
design -load postopt
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
design -reset
|
||||
log "equiv_sub_signed: ok"
|
||||
11
tests/csa_tree/csa_tree_sub_mixed.ys
Normal file
11
tests/csa_tree/csa_tree_sub_mixed.ys
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Test mixed csa chain
|
||||
|
||||
read_verilog sub_mixed.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
select -assert-none t:$sub
|
||||
9
tests/csa_tree/csa_tree_sub_signed.ys
Normal file
9
tests/csa_tree/csa_tree_sub_signed.ys
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
read_verilog sub_signed.v
|
||||
hierarchy -auto-top
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
stat
|
||||
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
select -assert-none t:$sub
|
||||
38
tests/csa_tree/csa_tree_sub_sim.ys
Normal file
38
tests/csa_tree/csa_tree_sub_sim.ys
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
read_verilog sub_mixed.v
|
||||
hierarchy -top sub_mixed
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
opt_clean
|
||||
|
||||
# 10 + 20 - 5 + 3 = 28
|
||||
sat -set a 10 -set b 20 -set c 5 -set d 3 -prove y 28
|
||||
|
||||
# 0 + 0 - 0 + 0 = 0
|
||||
sat -set a 0 -set b 0 -set c 0 -set d 0 -prove y 0
|
||||
|
||||
# 100 + 50 - 30 + 10 = 130
|
||||
sat -set a 100 -set b 50 -set c 30 -set d 10 -prove y 130
|
||||
|
||||
# 1 + 1 - 255 + 1 = 4
|
||||
sat -set a 1 -set b 1 -set c 255 -set d 1 -prove y 4
|
||||
|
||||
log "sub_mixed vectors: ok"
|
||||
|
||||
design -reset
|
||||
|
||||
read_verilog sub_all.v
|
||||
hierarchy -top sub_all
|
||||
proc; opt_clean
|
||||
csa_tree
|
||||
opt_clean
|
||||
|
||||
# 100 - 10 - 20 - 30 = 40
|
||||
sat -set a 100 -set b 10 -set c 20 -set d 30 -prove y 40
|
||||
|
||||
# 0 - 0 - 0 - 0 = 0
|
||||
sat -set a 0 -set b 0 -set c 0 -set d 0 -prove y 0
|
||||
|
||||
# 255 - 1 - 1 - 1 = 252
|
||||
sat -set a 255 -set b 1 -set c 1 -set d 1 -prove y 252
|
||||
|
||||
log "sub_all vectors: ok"
|
||||
|
|
@ -1,17 +1,20 @@
|
|||
# ABC synthesis comparison: with vs without csa_tree
|
||||
|
||||
# Baseline: no csa_tree
|
||||
read_verilog abc_bench_add8.v
|
||||
hierarchy -top abc_bench_add8
|
||||
proc; opt
|
||||
|
||||
# Baseline synth
|
||||
techmap
|
||||
abc -g AND,OR,XOR
|
||||
opt_clean
|
||||
stat
|
||||
design -save baseline
|
||||
|
||||
# Baseline is typically 238 gates — assert it's above 235
|
||||
select -assert-min 236 t:$_AND_ t:$_OR_ t:$_XOR_ %u
|
||||
|
||||
design -reset
|
||||
|
||||
# With csa_tree
|
||||
design -reset
|
||||
read_verilog abc_bench_add8.v
|
||||
hierarchy -top abc_bench_add8
|
||||
proc; opt
|
||||
|
|
@ -21,25 +24,36 @@ abc -g AND,OR,XOR
|
|||
opt_clean
|
||||
stat
|
||||
|
||||
select -assert-max 250 t:$_AND_ t:$_OR_ t:$_XOR_ t:$_NOT_ %u
|
||||
design -save csa_result
|
||||
# CSA was giving ~232 gates, assert rough equality
|
||||
select -assert-max 235 t:$_AND_ t:$_OR_ t:$_XOR_ %u
|
||||
|
||||
# Depth comparison via ABC
|
||||
design -reset
|
||||
|
||||
# Depth-optimal: baseline
|
||||
read_verilog abc_bench_add8.v
|
||||
hierarchy -top abc_bench_add8
|
||||
proc; opt
|
||||
techmap
|
||||
abc -D 1
|
||||
opt_clean
|
||||
stat
|
||||
log "baseline depth mapping complete"
|
||||
|
||||
# Baseline depth-optimal is ~243 cells
|
||||
select -assert-min 240 t:$_AND_ t:$_NAND_ t:$_OR_ t:$_NOR_ t:$_XOR_ t:$_XNOR_ t:$_NOT_ %u
|
||||
|
||||
design -reset
|
||||
|
||||
# Depth-optimal: with csa_tree
|
||||
read_verilog abc_bench_add8.v
|
||||
hierarchy -top abc_bench_add8
|
||||
proc; opt
|
||||
csa_tree
|
||||
techmap
|
||||
abc -D 1
|
||||
opt_clean
|
||||
stat
|
||||
log "CSA depth mapping complete"
|
||||
|
||||
# CSA depth-optimal is ~232 cells, must be under baseline
|
||||
select -assert-max 236 t:$_AND_ t:$_NAND_ t:$_OR_ t:$_NOR_ t:$_XOR_ t:$_XNOR_ t:$_NOT_ %u
|
||||
|
||||
log "CSA depth and gate count: ok"
|
||||
|
|
|
|||
|
|
@ -5,5 +5,4 @@ equiv_opt csa_tree
|
|||
design -load postopt
|
||||
|
||||
select -assert-min 2 t:$fa
|
||||
select -assert-count 2 t:$add
|
||||
|
||||
select -assert-count 2 t:$add
|
||||
|
|
@ -5,5 +5,4 @@ equiv_opt csa_tree
|
|||
design -load postopt
|
||||
|
||||
select -assert-min 1 t:$fa
|
||||
select -assert-count 1 t:$add
|
||||
|
||||
select -assert-count 1 t:$add
|
||||
27
tests/csa_tree/equiv_sub_narrow.v
Normal file
27
tests/csa_tree/equiv_sub_narrow.v
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
module equiv_sub_mixed(
|
||||
input [3:0] a, b, c, d,
|
||||
output [3:0] y
|
||||
);
|
||||
assign y = a + b - c + d;
|
||||
endmodule
|
||||
|
||||
module equiv_sub_all(
|
||||
input [3:0] a, b, c, d,
|
||||
output [3:0] y
|
||||
);
|
||||
assign y = a - b - c - d;
|
||||
endmodule
|
||||
|
||||
module equiv_sub_3op(
|
||||
input [3:0] a, b, c,
|
||||
output [3:0] y
|
||||
);
|
||||
assign y = a - b + c;
|
||||
endmodule
|
||||
|
||||
module equiv_sub_signed(
|
||||
input signed [3:0] a, b, c, d,
|
||||
output signed [5:0] y
|
||||
);
|
||||
assign y = a + b - c - d;
|
||||
endmodule
|
||||
6
tests/csa_tree/sub_2op_neg.v
Normal file
6
tests/csa_tree/sub_2op_neg.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module sub_2op_neg(
|
||||
input [7:0] a, b,
|
||||
output [7:0] y
|
||||
);
|
||||
assign y = a - b;
|
||||
endmodule
|
||||
6
tests/csa_tree/sub_3op.v
Normal file
6
tests/csa_tree/sub_3op.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module sub_3op(
|
||||
input [7:0] a, b, c,
|
||||
output [7:0] y
|
||||
);
|
||||
assign y = a - b + c;
|
||||
endmodule
|
||||
6
tests/csa_tree/sub_5op.v
Normal file
6
tests/csa_tree/sub_5op.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module sub_5op(
|
||||
input [11:0] a, b, c, d, e,
|
||||
output [11:0] y
|
||||
);
|
||||
assign y = a - b + c - d + e;
|
||||
endmodule
|
||||
6
tests/csa_tree/sub_all.v
Normal file
6
tests/csa_tree/sub_all.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module sub_all(
|
||||
input [7:0] a, b, c, d,
|
||||
output [7:0] y
|
||||
);
|
||||
assign y = a - b - c - d;
|
||||
endmodule
|
||||
6
tests/csa_tree/sub_mixed.v
Normal file
6
tests/csa_tree/sub_mixed.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module sub_mixed(
|
||||
input [7:0] a, b, c, d,
|
||||
output [7:0] y
|
||||
);
|
||||
assign y = a + b - c + d;
|
||||
endmodule
|
||||
6
tests/csa_tree/sub_signed.v
Normal file
6
tests/csa_tree/sub_signed.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module sub_signed(
|
||||
input signed [7:0] a, b, c, d,
|
||||
output signed [9:0] y
|
||||
);
|
||||
assign y = a + b - c - d;
|
||||
endmodule
|
||||
Loading…
Add table
Add a link
Reference in a new issue