From d9897a1bec517d3545120e8c90b2754f01c8fe5a Mon Sep 17 00:00:00 2001 From: "Andreas.Olofsson" Date: Thu, 9 Apr 2020 21:42:28 -0400 Subject: [PATCH] Multi-type multiplier working -only reference model implemented -Next, implement complete algorithm and output partial products --- common/hdl/oh_multiplier.v | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/common/hdl/oh_multiplier.v b/common/hdl/oh_multiplier.v index 45d507d..87ac704 100644 --- a/common/hdl/oh_multiplier.v +++ b/common/hdl/oh_multiplier.v @@ -9,19 +9,24 @@ module oh_multiplier #(parameter DW = 16 //multiplier width ) ( input [DW-1:0] a, // a input + input a_signed,//a operand is signed input [DW-1:0] b, // b input - input cfg_signed,//1=signed operands, 0=unsigned + input b_signed,//b oeprand is signed output [(2*DW+2)-1:0] pp1,// partial product output (carry save format) output [(2*DW+2)-1:0] pp2, // partial product output (carry save format) - output [DW-1:0] product // output + output [2*DW-1:0] product // output ); + + wire signed [2*DW+1:0] product_signed; - wire signed [DW-1:0] product_signed; - wire signed [DW-1:0] product_unsigned; + assign a_sext = a_signed & a[DW-1]; + assign b_sext = b_signed & b[DW-1]; + - assign product[DW-1:0] = cfg_signed ? $unsigned(product_signed) : - product_unsigned; + assign product_signed[2*DW+1:0] = $signed({a_sext,a[DW-1:0]}) * + $signed({b_sext,b[DW-1:0]}); + + assign product = product_signed[2*DW-1:0]; - endmodule // oh_multiplier