Use minimum sized width wires
authorEddie Hung <eddie@fpgeh.com>
Mon, 22 Jul 2019 20:01:26 +0000 (13:01 -0700)
committerEddie Hung <eddie@fpgeh.com>
Mon, 22 Jul 2019 20:01:26 +0000 (13:01 -0700)
techlibs/common/mul2dsp.v

index 8b1ddefbf80170ece42ea67f4e49e5b226cf563e..cf9eeff6f528c0d495c210b3fc73c2b0537b5a68 100644 (file)
@@ -88,12 +88,15 @@ module \$__mul (A, B, Y);
                else if (A_WIDTH > `DSP_A_MAXWIDTH) begin\r
                        localparam n = (A_WIDTH+`DSP_A_MAXWIDTH-sign_headroom-1) / (`DSP_A_MAXWIDTH-sign_headroom);\r
                        localparam partial_Y_WIDTH = `MIN(Y_WIDTH, B_WIDTH+`DSP_A_MAXWIDTH);\r
+                       localparam last_Y_WIDTH = `MIN(partial_Y_WIDTH, B_WIDTH+A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom));\r
                        if (A_SIGNED && B_SIGNED) begin\r
-                               wire signed [partial_Y_WIDTH-1:0] partial [n-1:0];\r
+                               wire signed [partial_Y_WIDTH-1:0] partial [n-2:0];\r
+                               wire signed [last_Y_WIDTH-1:0] last_partial;\r
                                wire signed [Y_WIDTH-1:0] partial_sum [n-1:0];\r
                        end\r
                        else begin\r
                                wire [partial_Y_WIDTH-1:0] partial [n-1:0];\r
+                               wire [last_Y_WIDTH-1:0] last_partial;\r
                                wire [Y_WIDTH-1:0] partial_sum [n-1:0];\r
                        end\r
 \r
@@ -130,24 +133,27 @@ module \$__mul (A, B, Y);
                                .B_SIGNED(B_SIGNED),\r
                                .A_WIDTH(A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom)),\r
                                .B_WIDTH(B_WIDTH),\r
-                               .Y_WIDTH(partial_Y_WIDTH)\r
+                               .Y_WIDTH(last_Y_WIDTH)\r
                        ) mul_slice_last (\r
                                .A(A[A_WIDTH-1 : (n-1)*(`DSP_A_MAXWIDTH-sign_headroom)]),\r
                                .B(B),\r
-                               .Y(partial[n-1])\r
+                               .Y(last_partial)\r
                        );\r
-                       assign partial_sum[n-1] = (partial[n-1] << (n-1)*(`DSP_A_MAXWIDTH-sign_headroom)) + partial_sum[n-2];\r
+                       assign partial_sum[n-1] = (last_partial << (n-1)*(`DSP_A_MAXWIDTH-sign_headroom)) + partial_sum[n-2];\r
                        assign Y = partial_sum[n-1];\r
                end\r
                else if (B_WIDTH > `DSP_B_MAXWIDTH) begin\r
                        localparam n = (B_WIDTH+`DSP_B_MAXWIDTH-sign_headroom-1) / (`DSP_B_MAXWIDTH-sign_headroom);\r
                        localparam partial_Y_WIDTH = `MIN(Y_WIDTH, A_WIDTH+`DSP_B_MAXWIDTH);\r
+                       localparam last_Y_WIDTH = `MIN(partial_Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH-sign_headroom));\r
                        if (A_SIGNED && B_SIGNED) begin\r
-                               wire signed [partial_Y_WIDTH-1:0] partial [n-1:0];\r
+                               wire signed [partial_Y_WIDTH-1:0] partial [n-2:0];\r
+                               wire signed [last_Y_WIDTH-1:0] last_partial;\r
                                wire signed [Y_WIDTH-1:0] partial_sum [n-1:0];\r
                        end\r
                        else begin\r
                                wire [partial_Y_WIDTH-1:0] partial [n-1:0];\r
+                               wire [last_Y_WIDTH-1:0] last_partial;\r
                                wire [Y_WIDTH-1:0] partial_sum [n-1:0];\r
                        end\r
 \r
@@ -188,9 +194,9 @@ module \$__mul (A, B, Y);
                        ) mul_last (\r
                                .A(A),\r
                                .B(B[B_WIDTH-1 : (n-1)*(`DSP_B_MAXWIDTH-sign_headroom)]),\r
-                               .Y(partial[n-1])\r
+                               .Y(last_partial)\r
                        );\r
-                       assign partial_sum[n-1] = (partial[n-1] << (n-1)*(`DSP_B_MAXWIDTH-sign_headroom)) + partial_sum[n-2];\r
+                       assign partial_sum[n-1] = (last_partial << (n-1)*(`DSP_B_MAXWIDTH-sign_headroom)) + partial_sum[n-2];\r
                        assign Y = partial_sum[n-1];\r
                end\r
                else begin \r