localparam n = n_floored + (n_floored*`DSP_A_MAXWIDTH < A_WIDTH ? 1 : 0);\r
wire [`DSP_A_MAXWIDTH+B_WIDTH-1:0] partial [n-1:1];\r
wire [Y_WIDTH-1:0] partial_sum [n-2:0];\r
+ localparam int_yw = `MIN(Y_WIDTH, B_WIDTH+`DSP_A_MAXWIDTH);\r
\r
\$__mul_gen #(\r
.A_SIGNED(A_SIGNED),\r
.B_SIGNED(B_SIGNED),\r
.A_WIDTH(`DSP_A_MAXWIDTH),\r
.B_WIDTH(B_WIDTH),\r
- .Y_WIDTH(B_WIDTH+`DSP_A_MAXWIDTH)\r
+ .Y_WIDTH(int_yw)\r
) mul_slice_first (\r
.A(A[`DSP_A_MAXWIDTH-1:0]),\r
.B(B),\r
- .Y(partial_sum[0][B_WIDTH+`DSP_A_MAXWIDTH-1:0])\r
+ .Y(partial_sum[0][int_yw-1:0])\r
);\r
- assign partial_sum[0][Y_WIDTH-1:B_WIDTH+`DSP_A_MAXWIDTH]=0;\r
+ if (Y_WIDTH > int_yw)\r
+ assign partial_sum[0][Y_WIDTH-1:int_yw]=0;\r
\r
for (i = 1; i < n-1; i=i+1) begin:slice\r
\$__mul_gen #(\r
.B_SIGNED(B_SIGNED),\r
.A_WIDTH(`DSP_A_MAXWIDTH),\r
.B_WIDTH(B_WIDTH),\r
- .Y_WIDTH(B_WIDTH+`DSP_A_MAXWIDTH)\r
+ .Y_WIDTH(int_yw)\r
) mul_slice (\r
.A(A[(i+1)*`DSP_A_MAXWIDTH-1:i*`DSP_A_MAXWIDTH]),\r
.B(B),\r
- .Y(partial[i][B_WIDTH+`DSP_A_MAXWIDTH-1:0])\r
+ .Y(partial[i][int_yw-1:0])\r
);\r
//assign partial_sum[i] = (partial[i] << i*`DSP_A_MAXWIDTH) + partial_sum[i-1];\r
assign partial_sum[i] = {\r
- partial[i][B_WIDTH+`DSP_A_MAXWIDTH-1:0]\r
+ partial[i][int_yw-1:0]\r
+ partial_sum[i-1][Y_WIDTH-1:(i*`DSP_A_MAXWIDTH)],\r
partial_sum[i-1][(i*`DSP_A_MAXWIDTH)-1:0]\r
};\r
.B_SIGNED(B_SIGNED),\r
.A_WIDTH(A_WIDTH-(n-1)*`DSP_A_MAXWIDTH),\r
.B_WIDTH(B_WIDTH),\r
- .Y_WIDTH(A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH),\r
+ .Y_WIDTH(`MIN(Y_WIDTH, A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH)),\r
) mul_slice_last (\r
.A(A[A_WIDTH-1:(n-1)*`DSP_A_MAXWIDTH]),\r
.B(B),\r
- .Y(partial[n-1][A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH-1:0])\r
+ .Y(partial[n-1][`MIN(Y_WIDTH, A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH)-1:0])\r
);\r
//assign Y = (partial[n-1] << (n-1)*`DSP_A_MAXWIDTH) + partial_sum[n-2];\r
assign Y = {\r
- partial[n-1][A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH:0]\r
+ partial[n-1][`MIN(Y_WIDTH, A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH):0]\r
+ partial_sum[n-2][Y_WIDTH-1:((n-1)*`DSP_A_MAXWIDTH)],\r
partial_sum[n-2][((n-1)*`DSP_A_MAXWIDTH)-1:0]\r
};\r
localparam n = n_floored + (n_floored*`DSP_B_MAXWIDTH < B_WIDTH ? 1 : 0);\r
wire [A_WIDTH+`DSP_B_MAXWIDTH-1:0] partial [n-1:1];\r
wire [Y_WIDTH-1:0] partial_sum [n-2:0];\r
+ localparam int_yw = `MIN(Y_WIDTH, A_WIDTH+`DSP_B_MAXWIDTH);\r
\r
\$__mul_gen #(\r
.A_SIGNED(A_SIGNED),\r
.B_SIGNED(B_SIGNED),\r
.A_WIDTH(A_WIDTH),\r
.B_WIDTH(`DSP_B_MAXWIDTH),\r
- .Y_WIDTH(A_WIDTH+`DSP_B_MAXWIDTH)\r
+ .Y_WIDTH(int_yw)\r
) mul_first (\r
.A(A),\r
.B(B[`DSP_B_MAXWIDTH-1:0]),\r
- .Y(partial_sum[0][A_WIDTH+`DSP_B_MAXWIDTH-1:0])\r
+ .Y(partial_sum[0][int_yw-1:0])\r
);\r
- assign partial_sum[0][Y_WIDTH-1:A_WIDTH+`DSP_B_MAXWIDTH]=0;\r
+ if (Y_WIDTH > int_yw)\r
+ assign partial_sum[0][Y_WIDTH-1:A_WIDTH+`DSP_B_MAXWIDTH]=0;\r
\r
for (i = 1; i < n-1; i=i+1) begin:slice\r
\$__mul_gen #(\r
.B_SIGNED(B_SIGNED),\r
.A_WIDTH(A_WIDTH),\r
.B_WIDTH(`DSP_B_MAXWIDTH),\r
- .Y_WIDTH(A_WIDTH+`DSP_B_MAXWIDTH)\r
+ .Y_WIDTH(int_yw)\r
) mul (\r
.A(A),\r
.B(B[(i+1)*`DSP_B_MAXWIDTH-1:i*`DSP_B_MAXWIDTH]),\r
- .Y(partial[i][A_WIDTH+`DSP_B_MAXWIDTH-1:0])\r
+ .Y(partial[i][int_yw-1:0])\r
);\r
//assign partial_sum[i] = (partial[i] << i*`DSP_B_MAXWIDTH) + partial_sum[i-1];\r
// was:\r
// partial[i][`DSP_B_MAXWIDTH-1:0] + partial_sum[i-1][A_WIDTH+(i*`DSP_B_MAXWIDTH)-1:A_WIDTH+((i-1)*`DSP_B_MAXWIDTH)],\r
// partial_sum[i-1][A_WIDTH+((i-1)*`DSP_B_MAXWIDTH):0]\r
assign partial_sum[i] = {\r
- partial[i][A_WIDTH+`DSP_B_MAXWIDTH-1:0]\r
+ partial[i][int_yw-1:0]\r
+ partial_sum[i-1][Y_WIDTH-1:(i*`DSP_B_MAXWIDTH)],\r
partial_sum[i-1][(i*`DSP_B_MAXWIDTH)-1:0] \r
};\r
.B_SIGNED(B_SIGNED),\r
.A_WIDTH(A_WIDTH),\r
.B_WIDTH(B_WIDTH-(n-1)*`DSP_B_MAXWIDTH),\r
- .Y_WIDTH(A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH)\r
+ .Y_WIDTH(`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH))\r
) mul_last (\r
.A(A),\r
.B(B[B_WIDTH-1:(n-1)*`DSP_B_MAXWIDTH]),\r
- .Y(partial[n-1][A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH-1:0])\r
+ .Y(partial[n-1][`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH)-1:0])\r
);\r
// AMD: this came comment out -- looks closer to right answer\r
//assign Y = (partial[n-1] << (n-1)*`DSP_B_MAXWIDTH) + partial_sum[n-2];\r
// partial[n-1][`DSP_B_MAXWIDTH-1:0] + partial_sum[n-2][A_WIDTH+((n-1)*`DSP_B_MAXWIDTH)-1:A_WIDTH+((n-2)*`DSP_B_MAXWIDTH)],\r
// partial_sum[n-2][A_WIDTH+((n-2)*`DSP_B_MAXWIDTH):0]\r
assign Y = {\r
- partial[n-1][A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH-1:0]\r
+ partial[n-1][`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH)-1:0]\r
+ partial_sum[n-2][Y_WIDTH-1:((n-1)*`DSP_B_MAXWIDTH)],\r
partial_sum[n-2][((n-1)*`DSP_B_MAXWIDTH)-1:0]\r
};\r