zoukankan      html  css  js  c++  java
  • HDL代码风格建议(2)乘法器和DSP推断

    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
    Verilog HDL Usigned Multiplier

    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
    Verilog HDL Signed Multiplier with Input and Output Regist

    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
    Verilog HDL Unsigned Multiply-Accumulator
    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
    Verilog HDL Signed Multiply-Adder
  • 相关阅读:
    Octet string 解析
    c#之process类相关整理
    C# Process.Start()方法详解(转)
    c语言字符串比较函数strcmp
    C# 启动EXE文件及带启动参数EXE
    C语言中两个相等的char值比较 结果为false
    C语言strcmp()函数:比较字符串(区分大小写)
    char数组与char指针
    (转)在.net中序列化读写xml方法的总结
    PHP实现站点pv,uv统计(三)
  • 原文地址:https://www.cnblogs.com/dashawntang/p/7209783.html
Copyright © 2011-2022 走看看