From 6c78bd36372b0f38ea18cacf60996778448fe48e Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Thu, 28 Nov 2024 15:13:51 +0100 Subject: [PATCH] techmap: add a Han-Carlson option for `$lcu` mapping --- techlibs/common/Makefile.inc | 1 + techlibs/common/choices/han-carlson.v | 57 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 techlibs/common/choices/han-carlson.v diff --git a/techlibs/common/Makefile.inc b/techlibs/common/Makefile.inc index fa5c2a825..cb67d6329 100644 --- a/techlibs/common/Makefile.inc +++ b/techlibs/common/Makefile.inc @@ -36,3 +36,4 @@ $(eval $(call add_share_file,share,techlibs/common/abc9_unmap.v)) $(eval $(call add_share_file,share,techlibs/common/cmp2lcu.v)) $(eval $(call add_share_file,share,techlibs/common/cmp2softlogic.v)) $(eval $(call add_share_file,share/choices,techlibs/common/choices/kogge-stone.v)) +$(eval $(call add_share_file,share/choices,techlibs/common/choices/han-carlson.v)) diff --git a/techlibs/common/choices/han-carlson.v b/techlibs/common/choices/han-carlson.v new file mode 100644 index 000000000..4c93c6f7e --- /dev/null +++ b/techlibs/common/choices/han-carlson.v @@ -0,0 +1,57 @@ +(* techmap_celltype = "$lcu" *) +module _85_lcu_han_carlson (P, G, CI, CO); + parameter WIDTH = 2; + + (* force_downto *) + input [WIDTH-1:0] P, G; + input CI; + + (* force_downto *) + output [WIDTH-1:0] CO; + + integer i, j; + (* force_downto *) + reg [WIDTH-1:0] p, g; + + always @* begin + i = 0; + p = P; + g = G; + + // in almost all cases CI will be constant zero + g[0] = g[0] | (p[0] & CI); + if (i < $clog2(WIDTH)) begin + + // First layer: BK + for (j = WIDTH - 1; j >= 0; j = j - 1) begin + if (j % 2 == 1) begin + g[j] = g[j] | p[j] & g[j - 1]; + p[j] = p[j] & p[j - 1]; + end + end + + // Inner (log(WIDTH) - 1) layers: KS + for (i = 1; i < $clog2(WIDTH); i = i + 1) begin + for (j = WIDTH - 1; j >= 2**i; j = j - 1) begin + if (j % 2 == 1) begin + g[j] = g[j] | p[j] & g[j - 2**i]; + p[j] = p[j] & p[j - 2**i]; + end + end + end + + // Last layer: BK + if (i < ($clog2(WIDTH) + 1)) begin + for (j = WIDTH - 1; j >= 0; j = j - 1) begin + if ((j % 2 == 0) && (j > 0)) begin + g[j] = g[j] | p[j] & g[j - 1]; + p[j] = p[j] & p[j - 1]; + end + end + end + + end + end + + assign CO = g; +endmodule