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