Skip to content

Commit e436cc0

Browse files
authored
Merge pull request #4779 from YosysHQ/emil/han-carlson-adder
Add a Han-Carlson option for `$lcu` mapping
2 parents 6f3376c + 3ebc714 commit e436cc0

File tree

8 files changed

+120
-3
lines changed

8 files changed

+120
-3
lines changed

techlibs/common/Makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ $(eval $(call add_share_file,share,techlibs/common/abc9_unmap.v))
3636
$(eval $(call add_share_file,share,techlibs/common/cmp2lcu.v))
3737
$(eval $(call add_share_file,share,techlibs/common/cmp2softlogic.v))
3838
$(eval $(call add_share_file,share/choices,techlibs/common/choices/kogge-stone.v))
39+
$(eval $(call add_share_file,share/choices,techlibs/common/choices/han-carlson.v))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
(* techmap_celltype = "$lcu" *)
2+
module _80_lcu_han_carlson (P, G, CI, CO);
3+
parameter WIDTH = 2;
4+
5+
(* force_downto *)
6+
input [WIDTH-1:0] P, G;
7+
input CI;
8+
9+
(* force_downto *)
10+
output [WIDTH-1:0] CO;
11+
12+
integer i, j;
13+
(* force_downto *)
14+
reg [WIDTH-1:0] p, g;
15+
16+
always @* begin
17+
i = 0;
18+
p = P;
19+
g = G;
20+
21+
// in almost all cases CI will be constant zero
22+
g[0] = g[0] | (p[0] & CI);
23+
if (i < $clog2(WIDTH)) begin
24+
25+
// First layer: BK
26+
for (j = WIDTH - 1; j >= 0; j = j - 1) begin
27+
if (j % 2 == 1) begin
28+
g[j] = g[j] | p[j] & g[j - 1];
29+
p[j] = p[j] & p[j - 1];
30+
end
31+
end
32+
33+
// Inner (log(WIDTH) - 1) layers: KS
34+
for (i = 1; i < $clog2(WIDTH); i = i + 1) begin
35+
for (j = WIDTH - 1; j >= 2**i; j = j - 1) begin
36+
if (j % 2 == 1) begin
37+
g[j] = g[j] | p[j] & g[j - 2**i];
38+
p[j] = p[j] & p[j - 2**i];
39+
end
40+
end
41+
end
42+
43+
// Last layer: BK
44+
if (i < ($clog2(WIDTH) + 1)) begin
45+
for (j = WIDTH - 1; j >= 0; j = j - 1) begin
46+
if ((j % 2 == 0) && (j > 0)) begin
47+
g[j] = g[j] | p[j] & g[j - 1];
48+
p[j] = p[j] & p[j - 1];
49+
end
50+
end
51+
end
52+
53+
end
54+
end
55+
56+
assign CO = g;
57+
endmodule

tests/gen-tests-makefile.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ generate_ys_test() {
2020
generate_target "$ys_file" "\"$YOSYS_BASEDIR/yosys\" -ql ${ys_file%.*}.log $yosys_args_ $ys_file"
2121
}
2222

23+
# $ generate_tcl_test tcl_file [yosys_args]
24+
generate_tcl_test() {
25+
tcl_file=$1
26+
yosys_args_=${2:-}
27+
generate_target "$tcl_file" "\"$YOSYS_BASEDIR/yosys\" -ql ${tcl_file%.*}.log $yosys_args_ $tcl_file"
28+
}
29+
2330
# $ generate_bash_test bash_file
2431
generate_bash_test() {
2532
bash_file=$1
@@ -29,6 +36,7 @@ generate_bash_test() {
2936
# $ generate_tests [-y|--yosys-scripts] [-s|--prove-sv] [-b|--bash] [-a|--yosys-args yosys_args]
3037
generate_tests() {
3138
do_ys=false
39+
do_tcl=false
3240
do_sv=false
3341
do_sh=false
3442
yosys_args=""
@@ -40,6 +48,10 @@ generate_tests() {
4048
do_ys=true
4149
shift
4250
;;
51+
-t|--tcl-scripts)
52+
do_tcl=true
53+
shift
54+
;;
4355
-s|--prove-sv)
4456
do_sv=true
4557
shift
@@ -59,7 +71,7 @@ generate_tests() {
5971
esac
6072
done
6173

62-
if [[ ! ( $do_ys = true || $do_sv = true || $do_sh = true ) ]]; then
74+
if [[ ! ( $do_ys = true || $do_tcl = true || $do_sv = true || $do_sh = true ) ]]; then
6375
echo >&2 "Error: No file types selected"
6476
exit 1
6577
fi
@@ -72,6 +84,11 @@ generate_tests() {
7284
generate_ys_test "$x" "$yosys_args"
7385
done
7486
fi;
87+
if [[ $do_tcl = true ]]; then
88+
for x in *.tcl; do
89+
generate_tcl_test "$x" "$yosys_args"
90+
done
91+
fi;
7592
if [[ $do_sv = true ]]; then
7693
for x in *.sv; do
7794
if [ ! -f "${x%.sv}.ys" ]; then

tests/techmap/han-carlson.tcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
yosys -import
2+
3+
read_verilog +/choices/han-carlson.v
4+
read_verilog -icells lcu_refined.v
5+
design -save init
6+
7+
for {set i 1} {$i <= 16} {incr i} {
8+
design -load init
9+
chparam -set WIDTH $i
10+
yosys proc
11+
opt_clean
12+
equiv_make lcu _80_lcu_han_carlson equiv
13+
equiv_simple equiv
14+
equiv_status -assert equiv
15+
}

tests/techmap/kogge-stone.tcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
yosys -import
2+
3+
read_verilog +/choices/kogge-stone.v
4+
read_verilog -icells lcu_refined.v
5+
design -save init
6+
7+
for {set i 1} {$i <= 16} {incr i} {
8+
design -load init
9+
chparam -set WIDTH $i
10+
yosys proc
11+
opt_clean
12+
equiv_make lcu _80_lcu_kogge_stone equiv
13+
equiv_simple equiv
14+
equiv_status -assert equiv
15+
}

tests/techmap/kogge-stone.ys

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/techmap/lcu_refined.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module lcu (P, G, CI, CO);
2+
parameter WIDTH = 2;
3+
4+
input [WIDTH-1:0] P, G;
5+
input CI;
6+
7+
output [WIDTH-1:0] CO;
8+
9+
reg [WIDTH-1:0] p, g;
10+
11+
\$lcu #(.WIDTH(WIDTH)) impl (.P(P), .G(G), .CI(CI), .CO(CO));
12+
13+
endmodule

tests/techmap/run-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
set -eu
33
source ../gen-tests-makefile.sh
4-
run_tests --yosys-scripts --bash --yosys-args "-e 'select out of bounds'"
4+
run_tests --yosys-scripts --tcl-scripts --bash --yosys-args "-e 'select out of bounds'"

0 commit comments

Comments
 (0)