Question on bit-width growth of multiplication & addition.

M

Mr. Ken

Guest
What's the right way to determine the bit-width growth of multiplication &
addition?

Assuming unsigned operations, all give me right result but fail HAL/LEDA
checks.

wire [5:0] a, b;
wire [6:0] c, d;
wire [13:0] e;
wire [7:0] f;

assign e = a * c + b * d;
assign e = {{6'd0}, a} * {{5'd0}, c} + {{6'd0}, b} * {{5'd0}, d};

assign f = a + c;
assign f = {{2'd0}, a} + {{1'd0}, c};
 
Mr. Ken wrote:
What's the right way to determine the bit-width growth of multiplication &
addition?
For multiplication, add the widths of the inputs.
For addition, add one to the width of the wider
input. This seems to be the rule you are using.

Assuming unsigned operations, all give me right result but fail HAL/LEDA
checks.

wire [5:0] a, b;
wire [6:0] c, d;
wire [13:0] e;
wire [7:0] f;

assign e = a * c + b * d;
It looks to me like this should be wide enough.
14bits = (6bits+7bits)+1
I would not expect a warning here.

assign e = {{6'd0}, a} * {{5'd0}, c} + {{6'd0}, b} * {{5'd0}, d};
Here I can imagine you could get a warning.
You are trying to do your own intermediate
extension of the operands, but the lint tools
probably won't take into account the fact
that you are zero-extending. They probably
will apply the rule to the zero-extended widths.

You are multiplying two 13-bit operands, which
requires a 26-bit result before addition. They
probably won't notice that there can only be
7 and 6 significant digits in each value, so the
result can only have 13 significant digits.

assign f = a + c;
Again, I would not expect a warning here.

assign f = {{2'd0}, a} + {{1'd0}, c};
I would expect a warning here, even though
there is not really a problem.
 

Welcome to EDABoard.com

Sponsor

Back
Top