Inferring Multipliers and DSP Functions
Inferring Multipliers
module unsigned_mult (out, a, b); output [15:0] out; input [7:0] a; input [7:0] b; assign out = a * b; endmodule
Note: The signed declaration in Verilog HDL is a feature of the Verilog 2001 Standard.
module signed_mult (out, clk, a, b); output [15:0] out; input clk; input signed [7:0] a; input signed [7:0] b; reg signed [7:0] a_reg; reg signed [7:0] b_reg; reg signed [15:0] out; wire signed [15:0] mult_out; assign mult_out = a_reg * b_reg; always @ (posedge clk) begin a_reg <= a; b_reg <= b; out <= mult_out; end endmodule
Inferring Multiply‑Accumulator and Multiply-Adder
The Verilog HDL and VHDL code samples infer multiply-accumulators and multiply-adders with input, output, and pipeline registers, as well as an optional asynchronous clear signal. Using the three sets of registers provides the best performance through the function, with a latency of three. You can remove the registers in your design to reduce the latency.
module unsig_altmult_accum (dataout, dataa, datab, clk, aclr, clken); input [7:0] dataa, datab; input clk, aclr, clken; output reg[16:0] dataout; reg [7:0] dataa_reg, datab_reg; reg [15:0] multa_reg; wire [15:0] multa; wire [16:0] adder_out; assign multa = dataa_reg * datab_reg; assign adder_out = multa_reg + dataout; always @ (posedge clk or posedge aclr) begin if (aclr) begin dataa_reg <= 8'b0; datab_reg <= 8'b0; multa_reg <= 16'b0; dataout <= 17'b0; end else if (clken) begin dataa_reg <= dataa; datab_reg <= datab; multa_reg <= multa; dataout <= adder_out; end end endmodule
module sig_altmult_add (dataa, datab, datac, datad, clock, aclr, result); input signed [15:0] dataa, datab, datac, datad; input clock, aclr; output reg signed [32:0] result; reg signed [15:0] dataa_reg, datab_reg, datac_reg, datad_reg; reg signed [31:0] mult0_result, mult1_result; always @ (posedge clock or posedge aclr) begin if (aclr) begin dataa_reg <= 16'b0; datab_reg <= 16'b0; datac_reg <= 16'b0; datad_reg <= 16'b0; mult0_result <= 32'b0; mult1_result <= 32'b0; result <= 33'b0; end else begin dataa_reg <= dataa; datab_reg <= datab; datac_reg <= datac; datad_reg <= datad; mult0_result <= dataa_reg * datab_reg; mult1_result <= datac_reg * datad_reg; result <= mult0_result + mult1_result; end end endmodule