|
楼主 |
发表于 2018-9-18 11:11:47
|
显示全部楼层
今天讲一下有符号乘法运算,有符号乘法,也是可以通过例化DW实现,同时也可直接通过* 实现,Demo 代码如下:
例化 DW Verilog 有符号乘法写法:
localparam A_WIDTH;
localparam B_WIDTH;
localparam PRDCT_WIDTH = A_WIDTH + B_WIDTH;
reg signed [A_WIDTH-1:0] a; // Default declaration type is unsigned
reg signed [B_WIDTH-1:0] b; // Default declaration type is unsigned
wire signed [PRDCT_WIDTH-1:0] prdct;
DW02_MULT #(
.A_WIDTH (A_WIDTH ),
.B_WIDTH (B_WIDTH )
)
U_DW_MULT
(
.TC (1'b1 ), // 0 for unsigned, 1 for signed
.A (a ),
.B (b ),
.PRODUCT (prdct )
);
Synopsys 推荐乘法运算Verilog 代码:
localparam A_WIDTH = 8;
localparam B_WIDTH = 16;
localparam PRDCT_WIDTH = A_WIDTH + B_WIDTH;
reg signed [A_WIDTH-1:0] a; // Default declaration type is unsigned
reg signed [B_WIDTH-1:0] b; // Default declaration type is unsigned
reg signed [PRDCT_WIDTH-1:0] prdct;
always@(*) begin
prdct = $signed(a) * $signed(b);
end
。
对于一个变量,一个常量的无符号运算 :
localparam A_WIDTH = 8;
localparam B_WIDTH = 8;
localparam signed [B_WIDTH -1 : 0] B = 32;
localparam PRDCT_WIDTH = A_WIDTH + B_WIDTH;
reg signed [A_WIDTH-1:0] a; // Default declaration type is unsigned
reg signed [PRDCT_WIDTH-1:0] prdct;
always@(*) begin
prdct = $signed(a) * B_WIDTH'sdB;
end |
|