mirror of https://github.com/YosysHQ/yosys.git
Merge branch 'xc7dsp' of github.com:YosysHQ/yosys into xc7dsp
This commit is contained in:
commit
20b7120d66
|
@ -92,20 +92,25 @@ module \$__mul_gen (A, B, Y);
|
||||||
genvar i;
|
genvar i;
|
||||||
generate
|
generate
|
||||||
if (A_WIDTH > `DSP_A_MAXWIDTH) begin
|
if (A_WIDTH > `DSP_A_MAXWIDTH) begin
|
||||||
localparam n_floored = A_WIDTH/`DSP_A_MAXWIDTH;
|
`ifdef DSP_A_SIGNEDONLY
|
||||||
localparam n = n_floored + (n_floored*`DSP_A_MAXWIDTH < A_WIDTH ? 1 : 0);
|
localparam sign_headroom = 1;
|
||||||
|
`else
|
||||||
|
localparam sign_headroom = 0;
|
||||||
|
`endif
|
||||||
|
localparam n_floored = A_WIDTH/(`DSP_A_MAXWIDTH - sign_headroom);
|
||||||
|
localparam n = n_floored + (n_floored*(`DSP_A_MAXWIDTH - sign_headroom) < A_WIDTH ? 1 : 0);
|
||||||
wire [`DSP_A_MAXWIDTH+B_WIDTH-1:0] partial [n-1:1];
|
wire [`DSP_A_MAXWIDTH+B_WIDTH-1:0] partial [n-1:1];
|
||||||
wire [Y_WIDTH-1:0] partial_sum [n-2:0];
|
wire [Y_WIDTH-1:0] partial_sum [n-2:0];
|
||||||
localparam int_yw = `MIN(Y_WIDTH, B_WIDTH+`DSP_A_MAXWIDTH);
|
localparam int_yw = `MIN(Y_WIDTH, B_WIDTH+`DSP_A_MAXWIDTH);
|
||||||
|
|
||||||
\$__mul_gen #(
|
\$__mul_gen #(
|
||||||
.A_SIGNED(A_SIGNED),
|
.A_SIGNED(0),
|
||||||
.B_SIGNED(B_SIGNED),
|
.B_SIGNED(B_SIGNED),
|
||||||
.A_WIDTH(`DSP_A_MAXWIDTH),
|
.A_WIDTH(`DSP_A_MAXWIDTH),
|
||||||
.B_WIDTH(B_WIDTH),
|
.B_WIDTH(B_WIDTH),
|
||||||
.Y_WIDTH(int_yw)
|
.Y_WIDTH(int_yw)
|
||||||
) mul_slice_first (
|
) mul_slice_first (
|
||||||
.A(A[`DSP_A_MAXWIDTH-1:0]),
|
.A({{sign_headroom{1'b0}}, A[`DSP_A_MAXWIDTH-sign_headroom-1:0]}),
|
||||||
.B(B),
|
.B(B),
|
||||||
.Y(partial_sum[0][int_yw-1:0])
|
.Y(partial_sum[0][int_yw-1:0])
|
||||||
);
|
);
|
||||||
|
@ -114,73 +119,78 @@ module \$__mul_gen (A, B, Y);
|
||||||
|
|
||||||
for (i = 1; i < n-1; i=i+1) begin:slice
|
for (i = 1; i < n-1; i=i+1) begin:slice
|
||||||
\$__mul_gen #(
|
\$__mul_gen #(
|
||||||
.A_SIGNED(A_SIGNED),
|
.A_SIGNED(0),
|
||||||
.B_SIGNED(B_SIGNED),
|
.B_SIGNED(B_SIGNED),
|
||||||
.A_WIDTH(`DSP_A_MAXWIDTH),
|
.A_WIDTH(`DSP_A_MAXWIDTH),
|
||||||
.B_WIDTH(B_WIDTH),
|
.B_WIDTH(B_WIDTH),
|
||||||
.Y_WIDTH(int_yw)
|
.Y_WIDTH(int_yw)
|
||||||
) mul_slice (
|
) mul_slice (
|
||||||
.A(A[(i+1)*`DSP_A_MAXWIDTH-1:i*`DSP_A_MAXWIDTH]),
|
.A({{sign_headroom{1'b0}}, A[(i+1)*(`DSP_A_MAXWIDTH-sign_headroom)-1:i*(`DSP_A_MAXWIDTH-sign_headroom)]}),
|
||||||
.B(B),
|
.B(B),
|
||||||
.Y(partial[i][int_yw-1:0])
|
.Y(partial[i][int_yw-1:0])
|
||||||
);
|
);
|
||||||
//assign partial_sum[i] = (partial[i] << i*`DSP_A_MAXWIDTH) + partial_sum[i-1];
|
//assign partial_sum[i] = (partial[i] << i*`DSP_A_MAXWIDTH) + partial_sum[i-1];
|
||||||
assign partial_sum[i] = {
|
assign partial_sum[i] = {
|
||||||
partial[i][int_yw-1:0]
|
partial[i][int_yw-1:0]
|
||||||
+ partial_sum[i-1][Y_WIDTH-1:(i*`DSP_A_MAXWIDTH)],
|
+ partial_sum[i-1][Y_WIDTH-1:(i*(`DSP_A_MAXWIDTH-sign_headroom))],
|
||||||
partial_sum[i-1][(i*`DSP_A_MAXWIDTH)-1:0]
|
partial_sum[i-1][(i*(`DSP_A_MAXWIDTH-sign_headroom))-1:0]
|
||||||
};
|
};
|
||||||
end
|
end
|
||||||
|
|
||||||
\$__mul_gen #(
|
\$__mul_gen #(
|
||||||
.A_SIGNED(A_SIGNED),
|
.A_SIGNED(A_SIGNED),
|
||||||
.B_SIGNED(B_SIGNED),
|
.B_SIGNED(B_SIGNED),
|
||||||
.A_WIDTH(A_WIDTH-(n-1)*`DSP_A_MAXWIDTH),
|
.A_WIDTH(A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom)),
|
||||||
.B_WIDTH(B_WIDTH),
|
.B_WIDTH(B_WIDTH),
|
||||||
.Y_WIDTH(`MIN(Y_WIDTH, A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH)),
|
.Y_WIDTH(`MIN(Y_WIDTH, A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom)+B_WIDTH)),
|
||||||
) mul_slice_last (
|
) mul_slice_last (
|
||||||
.A(A[A_WIDTH-1:(n-1)*`DSP_A_MAXWIDTH]),
|
.A(A[A_WIDTH-1:(n-1)*(`DSP_A_MAXWIDTH-sign_headroom)]),
|
||||||
.B(B),
|
.B(B),
|
||||||
.Y(partial[n-1][`MIN(Y_WIDTH, A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH)-1:0])
|
.Y(partial[n-1][`MIN(Y_WIDTH, A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom)+B_WIDTH)-1:0])
|
||||||
);
|
);
|
||||||
//assign Y = (partial[n-1] << (n-1)*`DSP_A_MAXWIDTH) + partial_sum[n-2];
|
//assign Y = (partial[n-1] << (n-1)*`DSP_A_MAXWIDTH) + partial_sum[n-2];
|
||||||
assign Y = {
|
assign Y = {
|
||||||
partial[n-1][`MIN(Y_WIDTH, A_WIDTH-(n-1)*`DSP_A_MAXWIDTH+B_WIDTH):0]
|
partial[n-1][`MIN(Y_WIDTH, A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom)+B_WIDTH):0]
|
||||||
+ partial_sum[n-2][Y_WIDTH-1:((n-1)*`DSP_A_MAXWIDTH)],
|
+ partial_sum[n-2][Y_WIDTH-1:((n-1)*(`DSP_A_MAXWIDTH-sign_headroom))],
|
||||||
partial_sum[n-2][((n-1)*`DSP_A_MAXWIDTH)-1:0]
|
partial_sum[n-2][((n-1)*(`DSP_A_MAXWIDTH-sign_headroom))-1:0]
|
||||||
};
|
};
|
||||||
end
|
end
|
||||||
else if (B_WIDTH > `DSP_B_MAXWIDTH) begin
|
else if (B_WIDTH > `DSP_B_MAXWIDTH) begin
|
||||||
localparam n_floored = B_WIDTH/`DSP_B_MAXWIDTH;
|
`ifdef DSP_B_SIGNEDONLY
|
||||||
localparam n = n_floored + (n_floored*`DSP_B_MAXWIDTH < B_WIDTH ? 1 : 0);
|
localparam sign_headroom = 1;
|
||||||
|
`else
|
||||||
|
localparam sign_headroom = 0;
|
||||||
|
`endif
|
||||||
|
localparam n_floored = B_WIDTH/(`DSP_B_MAXWIDTH - sign_headroom);
|
||||||
|
localparam n = n_floored + (n_floored*(`DSP_B_MAXWIDTH - sign_headroom) < B_WIDTH ? 1 : 0);
|
||||||
wire [A_WIDTH+`DSP_B_MAXWIDTH-1:0] partial [n-1:1];
|
wire [A_WIDTH+`DSP_B_MAXWIDTH-1:0] partial [n-1:1];
|
||||||
wire [Y_WIDTH-1:0] partial_sum [n-2:0];
|
wire [Y_WIDTH-1:0] partial_sum [n-2:0];
|
||||||
localparam int_yw = `MIN(Y_WIDTH, A_WIDTH+`DSP_B_MAXWIDTH);
|
localparam int_yw = `MIN(Y_WIDTH, A_WIDTH+`DSP_B_MAXWIDTH);
|
||||||
|
|
||||||
\$__mul_gen #(
|
\$__mul_gen #(
|
||||||
.A_SIGNED(A_SIGNED),
|
.A_SIGNED(A_SIGNED),
|
||||||
.B_SIGNED(B_SIGNED),
|
.B_SIGNED(0),
|
||||||
.A_WIDTH(A_WIDTH),
|
.A_WIDTH(A_WIDTH),
|
||||||
.B_WIDTH(`DSP_B_MAXWIDTH),
|
.B_WIDTH(`DSP_B_MAXWIDTH),
|
||||||
.Y_WIDTH(int_yw)
|
.Y_WIDTH(int_yw)
|
||||||
) mul_first (
|
) mul_first (
|
||||||
.A(A),
|
.A(A),
|
||||||
.B(B[`DSP_B_MAXWIDTH-1:0]),
|
.B({{sign_headroom{1'b0}}, B[(`DSP_B_MAXWIDTH - sign_headroom)-1:0]}),
|
||||||
.Y(partial_sum[0][int_yw-1:0])
|
.Y(partial_sum[0][int_yw-1:0])
|
||||||
);
|
);
|
||||||
if (Y_WIDTH > int_yw)
|
if (Y_WIDTH > int_yw)
|
||||||
assign partial_sum[0][Y_WIDTH-1:A_WIDTH+`DSP_B_MAXWIDTH]=0;
|
assign partial_sum[0][Y_WIDTH-1:int_yw]=0;
|
||||||
|
|
||||||
for (i = 1; i < n-1; i=i+1) begin:slice
|
for (i = 1; i < n-1; i=i+1) begin:slice
|
||||||
\$__mul_gen #(
|
\$__mul_gen #(
|
||||||
.A_SIGNED(A_SIGNED),
|
.A_SIGNED(A_SIGNED),
|
||||||
.B_SIGNED(B_SIGNED),
|
.B_SIGNED(0),
|
||||||
.A_WIDTH(A_WIDTH),
|
.A_WIDTH(A_WIDTH),
|
||||||
.B_WIDTH(`DSP_B_MAXWIDTH),
|
.B_WIDTH(`DSP_B_MAXWIDTH),
|
||||||
.Y_WIDTH(int_yw)
|
.Y_WIDTH(int_yw)
|
||||||
) mul (
|
) mul (
|
||||||
.A(A),
|
.A(A),
|
||||||
.B(B[(i+1)*`DSP_B_MAXWIDTH-1:i*`DSP_B_MAXWIDTH]),
|
.B({{sign_headroom{1'b0}}, B[(i+1)*(`DSP_B_MAXWIDTH - sign_headroom)-1:i*(`DSP_B_MAXWIDTH - sign_headroom)]}),
|
||||||
.Y(partial[i][int_yw-1:0])
|
.Y(partial[i][int_yw-1:0])
|
||||||
);
|
);
|
||||||
//assign partial_sum[i] = (partial[i] << i*`DSP_B_MAXWIDTH) + partial_sum[i-1];
|
//assign partial_sum[i] = (partial[i] << i*`DSP_B_MAXWIDTH) + partial_sum[i-1];
|
||||||
|
@ -191,8 +201,8 @@ module \$__mul_gen (A, B, Y);
|
||||||
// partial_sum[i-1][A_WIDTH+((i-1)*`DSP_B_MAXWIDTH):0]
|
// partial_sum[i-1][A_WIDTH+((i-1)*`DSP_B_MAXWIDTH):0]
|
||||||
assign partial_sum[i] = {
|
assign partial_sum[i] = {
|
||||||
partial[i][int_yw-1:0]
|
partial[i][int_yw-1:0]
|
||||||
+ partial_sum[i-1][Y_WIDTH-1:(i*`DSP_B_MAXWIDTH)],
|
+ partial_sum[i-1][Y_WIDTH-1:(i*(`DSP_B_MAXWIDTH - sign_headroom))],
|
||||||
partial_sum[i-1][(i*`DSP_B_MAXWIDTH)-1:0]
|
partial_sum[i-1][(i*(`DSP_B_MAXWIDTH - sign_headroom))-1:0]
|
||||||
};
|
};
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -200,12 +210,12 @@ module \$__mul_gen (A, B, Y);
|
||||||
.A_SIGNED(A_SIGNED),
|
.A_SIGNED(A_SIGNED),
|
||||||
.B_SIGNED(B_SIGNED),
|
.B_SIGNED(B_SIGNED),
|
||||||
.A_WIDTH(A_WIDTH),
|
.A_WIDTH(A_WIDTH),
|
||||||
.B_WIDTH(B_WIDTH-(n-1)*`DSP_B_MAXWIDTH),
|
.B_WIDTH(B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH - sign_headroom)),
|
||||||
.Y_WIDTH(`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH))
|
.Y_WIDTH(`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH - sign_headroom)))
|
||||||
) mul_last (
|
) mul_last (
|
||||||
.A(A),
|
.A(A),
|
||||||
.B(B[B_WIDTH-1:(n-1)*`DSP_B_MAXWIDTH]),
|
.B(B[B_WIDTH-1:(n-1)*(`DSP_B_MAXWIDTH - sign_headroom)]),
|
||||||
.Y(partial[n-1][`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH)-1:0])
|
.Y(partial[n-1][`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH - sign_headroom))-1:0])
|
||||||
);
|
);
|
||||||
// AMD: this came comment out -- looks closer to right answer
|
// AMD: this came comment out -- looks closer to right answer
|
||||||
//assign Y = (partial[n-1] << (n-1)*`DSP_B_MAXWIDTH) + partial_sum[n-2];
|
//assign Y = (partial[n-1] << (n-1)*`DSP_B_MAXWIDTH) + partial_sum[n-2];
|
||||||
|
@ -215,9 +225,9 @@ module \$__mul_gen (A, B, Y);
|
||||||
// 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)],
|
// 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)],
|
||||||
// partial_sum[n-2][A_WIDTH+((n-2)*`DSP_B_MAXWIDTH):0]
|
// partial_sum[n-2][A_WIDTH+((n-2)*`DSP_B_MAXWIDTH):0]
|
||||||
assign Y = {
|
assign Y = {
|
||||||
partial[n-1][`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*`DSP_B_MAXWIDTH)-1:0]
|
partial[n-1][`MIN(Y_WIDTH, A_WIDTH+B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH - sign_headroom))-1:0]
|
||||||
+ partial_sum[n-2][Y_WIDTH-1:((n-1)*`DSP_B_MAXWIDTH)],
|
+ partial_sum[n-2][Y_WIDTH-1:((n-1)*(`DSP_B_MAXWIDTH - sign_headroom))],
|
||||||
partial_sum[n-2][((n-1)*`DSP_B_MAXWIDTH)-1:0]
|
partial_sum[n-2][((n-1)*(`DSP_B_MAXWIDTH - sign_headroom))-1:0]
|
||||||
};
|
};
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
|
Loading…
Reference in New Issue