For signed multipliers, compute sign bit separately...

This commit is contained in:
Eddie Hung 2019-07-31 15:45:41 -07:00
parent e4a638c292
commit 60c4887d15
1 changed files with 42 additions and 23 deletions

View File

@ -54,8 +54,22 @@ module \$mul (A, B, Y);
generate generate
if (A_SIGNED != B_SIGNED || A_WIDTH <= 1 || B_WIDTH <= 1) if (A_SIGNED != B_SIGNED || A_WIDTH <= 1 || B_WIDTH <= 1)
wire _TECHMAP_FAIL_ = 1; wire _TECHMAP_FAIL_ = 1;
// NB: A_SIGNED == B_SIGNED == 0 from here // NB: A_SIGNED == B_SIGNED from here
else if (A_WIDTH >= B_WIDTH) else if (A_WIDTH < B_WIDTH)
\$mul #(
.A_SIGNED(B_SIGNED),
.B_SIGNED(A_SIGNED),
.A_WIDTH(B_WIDTH),
.B_WIDTH(A_WIDTH),
.Y_WIDTH(Y_WIDTH)
) _TECHMAP_REPLACE_ (
.A(B),
.B(A),
.Y(Y)
);
else if (A_SIGNED && (A_WIDTH > `DSP_A_MAXWIDTH || B_WIDTH > `DSP_B_MAXWIDTH)) begin
wire _;
assign Y[Y_WIDTH-1] = A[A_WIDTH-1] ^ B[B_WIDTH-1];
\$__mul #( \$__mul #(
.A_SIGNED(A_SIGNED), .A_SIGNED(A_SIGNED),
.B_SIGNED(B_SIGNED), .B_SIGNED(B_SIGNED),
@ -65,18 +79,19 @@ module \$mul (A, B, Y);
) _TECHMAP_REPLACE_ ( ) _TECHMAP_REPLACE_ (
.A(A), .A(A),
.B(B), .B(B),
.Y(Y) .Y({_,Y[Y_WIDTH-2:0]})
); );
end
else else
\$__mul #( \$__mul #(
.A_SIGNED(B_SIGNED), .A_SIGNED(A_SIGNED),
.B_SIGNED(A_SIGNED), .B_SIGNED(B_SIGNED),
.A_WIDTH(B_WIDTH), .A_WIDTH(A_WIDTH),
.B_WIDTH(A_WIDTH), .B_WIDTH(B_WIDTH),
.Y_WIDTH(Y_WIDTH) .Y_WIDTH(Y_WIDTH)
) _TECHMAP_REPLACE_ ( ) _TECHMAP_REPLACE_ (
.A(B), .A(A),
.B(A), .B(B),
.Y(Y) .Y(Y)
); );
endgenerate endgenerate
@ -209,23 +224,27 @@ module \$__mul (A, B, Y);
.B({{sign_headroom{1'b0}}, B[i*(`DSP_B_MAXWIDTH-sign_headroom) +: `DSP_B_MAXWIDTH-sign_headroom]}), .B({{sign_headroom{1'b0}}, B[i*(`DSP_B_MAXWIDTH-sign_headroom) +: `DSP_B_MAXWIDTH-sign_headroom]}),
.Y(partial[i]) .Y(partial[i])
); );
// TODO: Currently a 'cascade' approach to summing the partial // TODO: Currently a 'cascade' approach to summing the partial
// products is taken here, but a more efficient 'binary // products is taken here, but a more efficient 'binary
// reduction' approach also exists... // reduction' approach also exists...
assign partial_sum[i] = (partial[i] << i*(`DSP_B_MAXWIDTH-sign_headroom)) + partial_sum[i-1]; assign partial_sum[i] = (partial[i] << i*(`DSP_B_MAXWIDTH-sign_headroom)) + partial_sum[i-1];
end end
\$__mul #( localparam last_B_WIDTH = B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH-sign_headroom);
.A_SIGNED(A_SIGNED), if (A_SIGNED && B_SIGNED && last_B_WIDTH == 1)
.B_SIGNED(B_SIGNED), assign last_partial = 0;
.A_WIDTH(A_WIDTH), else
.B_WIDTH(B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH-sign_headroom)), \$__mul #(
.Y_WIDTH(last_Y_WIDTH) .A_SIGNED(A_SIGNED),
) mul_last ( .B_SIGNED(B_SIGNED),
.A(A), .A_WIDTH(A_WIDTH),
.B(B[B_WIDTH-1 : (n-1)*(`DSP_B_MAXWIDTH-sign_headroom)]), .B_WIDTH(last_B_WIDTH),
.Y(last_partial) .Y_WIDTH(last_Y_WIDTH)
); ) mul_last (
.A(A),
.B(B[B_WIDTH-1 -: last_B_WIDTH]),
.Y(last_partial)
);
assign partial_sum[n-1] = (last_partial << (n-1)*(`DSP_B_MAXWIDTH-sign_headroom)) + partial_sum[n-2]; assign partial_sum[n-1] = (last_partial << (n-1)*(`DSP_B_MAXWIDTH-sign_headroom)) + partial_sum[n-2];
assign Y = partial_sum[n-1]; assign Y = partial_sum[n-1];
end end