*/\r
\r
`ifndef DSP_A_MAXWIDTH\r
-$error("Macro DSP_A_MAXWIDTH must be defined");\r
+$fatal(1, "Macro DSP_A_MAXWIDTH must be defined");\r
`endif\r
`ifndef DSP_B_MAXWIDTH\r
-$error("Macro DSP_B_MAXWIDTH must be defined");\r
+$fatal(1, "Macro DSP_B_MAXWIDTH must be defined");\r
+`endif\r
+`ifndef DSP_B_MAXWIDTH\r
+$fatal(1, "Macro DSP_B_MAXWIDTH must be defined");\r
+`endif\r
+`ifndef DSP_A_MAXWIDTH_PARTIAL\r
+`define DSP_A_MAXWIDTH_PARTIAL `DSP_A_MAXWIDTH\r
+`endif\r
+`ifndef DSP_B_MAXWIDTH_PARTIAL\r
+`define DSP_B_MAXWIDTH_PARTIAL `DSP_B_MAXWIDTH\r
`endif\r
\r
`ifndef DSP_NAME\r
-$error("Macro DSP_NAME must be defined");\r
+$fatal(1, "Macro DSP_NAME must be defined");\r
`endif\r
\r
`define MAX(a,b) (a > b ? a : b)\r
`define MIN(a,b) (a < b ? a : b)\r
\r
-module \$mul (A, B, Y); \r
+(* techmap_celltype = "$mul $__mul" *)\r
+module _80_mul (A, B, Y);\r
parameter A_SIGNED = 0;\r
parameter B_SIGNED = 0;\r
parameter A_WIDTH = 1;\r
input [B_WIDTH-1:0] B;\r
output [Y_WIDTH-1:0] Y;\r
\r
+ parameter _TECHMAP_CELLTYPE_ = "";\r
+\r
generate\r
- if (A_SIGNED != B_SIGNED)\r
+ if (0) begin end\r
+`ifdef DSP_A_MINWIDTH\r
+ else if (A_WIDTH < `DSP_A_MINWIDTH)\r
+ wire _TECHMAP_FAIL_ = 1;\r
+`endif\r
+`ifdef DSP_B_MINWIDTH\r
+ else if (B_WIDTH < `DSP_B_MINWIDTH)\r
+ wire _TECHMAP_FAIL_ = 1;\r
+`endif\r
+`ifdef DSP_Y_MINWIDTH\r
+ else if (Y_WIDTH < `DSP_Y_MINWIDTH)\r
+ wire _TECHMAP_FAIL_ = 1;\r
+`endif\r
+ else if (_TECHMAP_CELLTYPE_ == "$mul" && A_SIGNED != B_SIGNED)\r
wire _TECHMAP_FAIL_ = 1;\r
- // NB: A_SIGNED == B_SIGNED from here\r
`ifdef DSP_SIGNEDONLY\r
- else if (!A_SIGNED)\r
+ else if (_TECHMAP_CELLTYPE_ == "$mul" && !A_SIGNED)\r
\$mul #(\r
.A_SIGNED(1),\r
.B_SIGNED(1),\r
.B(A),\r
.Y(Y)\r
);\r
- else\r
- \$__mul #(\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(A),\r
- .B(B),\r
- .Y(Y)\r
- );\r
- endgenerate\r
-endmodule\r
-\r
-module \$__mul (A, B, Y);\r
- parameter A_SIGNED = 0;\r
- parameter B_SIGNED = 0;\r
- parameter A_WIDTH = 1;\r
- parameter B_WIDTH = 1;\r
- parameter Y_WIDTH = 1;\r
-\r
- input [A_WIDTH-1:0] A;\r
- input [B_WIDTH-1:0] B;\r
- output [Y_WIDTH-1:0] Y;\r
-\r
- wire [1023:0] _TECHMAP_DO_ = "proc; clean";\r
+ else begin\r
+ wire [1023:0] _TECHMAP_DO_ = "proc; clean";\r
\r
`ifdef DSP_SIGNEDONLY\r
- localparam sign_headroom = 1;\r
+ localparam sign_headroom = 1;\r
`else\r
- localparam sign_headroom = 0;\r
+ localparam sign_headroom = 0;\r
`endif\r
\r
- genvar i;\r
- generate\r
- if (0) begin end\r
-`ifdef DSP_A_MINWIDTH\r
- else if (A_WIDTH < `DSP_A_MINWIDTH)\r
- wire _TECHMAP_FAIL_ = 1;\r
-`endif\r
-`ifdef DSP_B_MINWIDTH\r
- else if (B_WIDTH < `DSP_B_MINWIDTH)\r
- wire _TECHMAP_FAIL_ = 1;\r
-`endif\r
-`ifdef DSP_Y_MINWIDTH\r
- else if (Y_WIDTH < `DSP_Y_MINWIDTH)\r
- wire _TECHMAP_FAIL_ = 1;\r
-`endif\r
- 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
+ genvar i;\r
+ if (A_WIDTH > `DSP_A_MAXWIDTH) begin\r
+ localparam n = (A_WIDTH-`DSP_A_MAXWIDTH+`DSP_A_MAXWIDTH_PARTIAL-sign_headroom-1) / (`DSP_A_MAXWIDTH_PARTIAL-sign_headroom);\r
+ localparam partial_Y_WIDTH = `MIN(Y_WIDTH, B_WIDTH+`DSP_A_MAXWIDTH_PARTIAL);\r
+ localparam last_A_WIDTH = A_WIDTH-n*(`DSP_A_MAXWIDTH_PARTIAL-sign_headroom);\r
+ localparam last_Y_WIDTH = B_WIDTH+last_A_WIDTH;\r
if (A_SIGNED && B_SIGNED) begin\r
- wire signed [partial_Y_WIDTH-1:0] partial [n-2:0];\r
+ wire signed [partial_Y_WIDTH-1:0] partial [n-1:0];\r
wire signed [last_Y_WIDTH-1:0] last_partial;\r
- wire signed [Y_WIDTH-1:0] partial_sum [n-1:0];\r
+ wire signed [Y_WIDTH-1:0] partial_sum [n: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
+ wire [Y_WIDTH-1:0] partial_sum [n:0];\r
end\r
\r
- \$__mul #(\r
- .A_SIGNED(sign_headroom),\r
- .B_SIGNED(B_SIGNED),\r
- .A_WIDTH(`DSP_A_MAXWIDTH),\r
- .B_WIDTH(B_WIDTH),\r
- .Y_WIDTH(partial_Y_WIDTH)\r
- ) mul_slice_first (\r
- .A({{sign_headroom{1'b0}}, A[`DSP_A_MAXWIDTH-sign_headroom-1 : 0]}),\r
- .B(B),\r
- .Y(partial[0])\r
- );\r
- assign partial_sum[0] = partial[0];\r
-\r
- for (i = 1; i < n-1; i=i+1) begin:slice\r
+ for (i = 0; i < n; i=i+1) begin:slice\r
\$__mul #(\r
.A_SIGNED(sign_headroom),\r
.B_SIGNED(B_SIGNED),\r
- .A_WIDTH(`DSP_A_MAXWIDTH),\r
+ .A_WIDTH(`DSP_A_MAXWIDTH_PARTIAL),\r
.B_WIDTH(B_WIDTH),\r
.Y_WIDTH(partial_Y_WIDTH)\r
) mul_slice (\r
- .A({{sign_headroom{1'b0}}, A[i*(`DSP_A_MAXWIDTH-sign_headroom) +: `DSP_A_MAXWIDTH-sign_headroom]}),\r
+ .A({{sign_headroom{1'b0}}, A[i*(`DSP_A_MAXWIDTH_PARTIAL-sign_headroom) +: `DSP_A_MAXWIDTH_PARTIAL-sign_headroom]}),\r
.B(B),\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
- assign partial_sum[i] = (partial[i] << i*(`DSP_A_MAXWIDTH-sign_headroom)) + partial_sum[i-1];\r
+ if (i == 0)\r
+ assign partial_sum[i] = partial[i];\r
+ else\r
+ assign partial_sum[i] = (partial[i] << i*(`DSP_A_MAXWIDTH_PARTIAL-sign_headroom)) + partial_sum[i-1];\r
end\r
\r
- localparam last_A_WIDTH = A_WIDTH-(n-1)*(`DSP_A_MAXWIDTH-sign_headroom);\r
\$__mul #(\r
.A_SIGNED(A_SIGNED),\r
.B_SIGNED(B_SIGNED),\r
.B(B),\r
.Y(last_partial)\r
);\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
+ assign partial_sum[n] = (last_partial << n*(`DSP_A_MAXWIDTH_PARTIAL-sign_headroom)) + partial_sum[n-1];\r
+ assign Y = partial_sum[n];\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
+ localparam n = (B_WIDTH-`DSP_B_MAXWIDTH+`DSP_B_MAXWIDTH_PARTIAL-sign_headroom-1) / (`DSP_B_MAXWIDTH_PARTIAL-sign_headroom);\r
+ localparam partial_Y_WIDTH = `MIN(Y_WIDTH, A_WIDTH+`DSP_B_MAXWIDTH_PARTIAL);\r
+ localparam last_B_WIDTH = B_WIDTH-n*(`DSP_B_MAXWIDTH_PARTIAL-sign_headroom);\r
+ localparam last_Y_WIDTH = A_WIDTH+last_B_WIDTH;\r
if (A_SIGNED && B_SIGNED) begin\r
- wire signed [partial_Y_WIDTH-1:0] partial [n-2:0];\r
+ wire signed [partial_Y_WIDTH-1:0] partial [n-1:0];\r
wire signed [last_Y_WIDTH-1:0] last_partial;\r
- wire signed [Y_WIDTH-1:0] partial_sum [n-1:0];\r
+ wire signed [Y_WIDTH-1:0] partial_sum [n: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
+ wire [Y_WIDTH-1:0] partial_sum [n:0];\r
end\r
\r
- \$__mul #(\r
- .A_SIGNED(A_SIGNED),\r
- .B_SIGNED(sign_headroom),\r
- .A_WIDTH(A_WIDTH),\r
- .B_WIDTH(`DSP_B_MAXWIDTH),\r
- .Y_WIDTH(partial_Y_WIDTH)\r
- ) mul_first (\r
- .A(A),\r
- .B({{sign_headroom{1'b0}}, B[`DSP_B_MAXWIDTH-sign_headroom-1 : 0]}),\r
- .Y(partial[0])\r
- );\r
- assign partial_sum[0] = partial[0];\r
-\r
- for (i = 1; i < n-1; i=i+1) begin:slice\r
+ for (i = 0; i < n; i=i+1) begin:slice\r
\$__mul #(\r
.A_SIGNED(A_SIGNED),\r
.B_SIGNED(sign_headroom),\r
.A_WIDTH(A_WIDTH),\r
- .B_WIDTH(`DSP_B_MAXWIDTH),\r
+ .B_WIDTH(`DSP_B_MAXWIDTH_PARTIAL),\r
.Y_WIDTH(partial_Y_WIDTH)\r
) mul (\r
.A(A),\r
- .B({{sign_headroom{1'b0}}, B[i*(`DSP_B_MAXWIDTH-sign_headroom) +: `DSP_B_MAXWIDTH-sign_headroom]}),\r
+ .B({{sign_headroom{1'b0}}, B[i*(`DSP_B_MAXWIDTH_PARTIAL-sign_headroom) +: `DSP_B_MAXWIDTH_PARTIAL-sign_headroom]}),\r
.Y(partial[i])\r
);\r
- // TODO: Currently a 'cascade' approach to summing the partial \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
+ if (i == 0)\r
+ assign partial_sum[i] = partial[i];\r
+ else\r
+ assign partial_sum[i] = (partial[i] << i*(`DSP_B_MAXWIDTH_PARTIAL-sign_headroom)) + partial_sum[i-1];\r
end\r
\r
- localparam last_B_WIDTH = B_WIDTH-(n-1)*(`DSP_B_MAXWIDTH-sign_headroom);\r
\$__mul #(\r
.A_SIGNED(A_SIGNED),\r
.B_SIGNED(B_SIGNED),\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
+ assign partial_sum[n] = (last_partial << n*(`DSP_B_MAXWIDTH_PARTIAL-sign_headroom)) + partial_sum[n-1];\r
+ assign Y = partial_sum[n];\r
end\r
- else begin \r
+ else begin\r
if (A_SIGNED)\r
wire signed [`DSP_A_MAXWIDTH-1:0] Aext = $signed(A);\r
else\r
.Y(Y)\r
);\r
end\r
+ end\r
endgenerate\r
endmodule\r
\r
-(* techmap_celltype = "$__mul" *)\r
-module $__soft_mul (A, B, Y); \r
+(* techmap_celltype = "$mul $__mul" *)\r
+module _90_soft_mul (A, B, Y);\r
parameter A_SIGNED = 0;\r
parameter B_SIGNED = 0;\r
parameter A_WIDTH = 1;\r
// Indirection necessary since mapping\r
// back to $mul will cause recursion\r
generate\r
- if (A_SIGNED && !B_SIGNED)\r
- \$__soft__mul #(\r
- .A_SIGNED(A_SIGNED),\r
- .B_SIGNED(1),\r
- .A_WIDTH(A_WIDTH),\r
- .B_WIDTH(B_WIDTH+1),\r
- .Y_WIDTH(Y_WIDTH)\r
- ) _TECHMAP_REPLACE_ (\r
- .A(A),\r
- .B({1'b0,B}),\r
- .Y(Y)\r
- );\r
- else if (!A_SIGNED && B_SIGNED)\r
- \$__soft_mul #(\r
- .A_SIGNED(1),\r
- .B_SIGNED(B_SIGNED),\r
- .A_WIDTH(A_WIDTH+1),\r
- .B_WIDTH(B_WIDTH),\r
- .Y_WIDTH(Y_WIDTH)\r
- ) _TECHMAP_REPLACE_ (\r
- .A({1'b0,A}),\r
- .B(B),\r
- .Y(Y)\r
- );\r
- else\r
- \$__soft_mul #(\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(A),\r
- .B(B),\r
- .Y(Y)\r
- );\r
+ if (A_SIGNED && !B_SIGNED)\r
+ \$__soft_mul #(\r
+ .A_SIGNED(A_SIGNED),\r
+ .B_SIGNED(1),\r
+ .A_WIDTH(A_WIDTH),\r
+ .B_WIDTH(B_WIDTH+1),\r
+ .Y_WIDTH(Y_WIDTH)\r
+ ) _TECHMAP_REPLACE_ (\r
+ .A(A),\r
+ .B({1'b0,B}),\r
+ .Y(Y)\r
+ );\r
+ else if (!A_SIGNED && B_SIGNED)\r
+ \$__soft_mul #(\r
+ .A_SIGNED(1),\r
+ .B_SIGNED(B_SIGNED),\r
+ .A_WIDTH(A_WIDTH+1),\r
+ .B_WIDTH(B_WIDTH),\r
+ .Y_WIDTH(Y_WIDTH)\r
+ ) _TECHMAP_REPLACE_ (\r
+ .A({1'b0,A}),\r
+ .B(B),\r
+ .Y(Y)\r
+ );\r
+ else\r
+ \$__soft_mul #(\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(A),\r
+ .B(B),\r
+ .Y(Y)\r
+ );\r
endgenerate\r
endmodule\r