From: Michael McNamara (mac@verisity.com)
Date: Fri Mar 01 2002 - 10:07:34 PST
Precedence: bulk
Dennis Marsa writes:
> Precedence: bulk
>
> Kurt Baty wrote:
> >
> > 2**5
> >
> > should be the
> > (unsigned constant 2) ** (unsigned constant 5)
>
> No, 2 and 5 are signed. See section 2.5.1, page 8, 7th
> paragraph (not counting the NOTE):
>
> "Simple decimal numbers without the size and the base
> format shall be treated as signed integers..."
>
> > and thus unsigned constant 32
>
> but since 2 and 5 are signed, by the written rules, the
> result would be a real 32.0.
>
> Thus, declarations such as:
>
> reg [2**5-1:0] data;
>
> would be illegal.
>
> Dennis
>
I am not sure what the issue is here.
Indeed, if either operand is signed, or real, then inoder to in the
general case retain the highest precision, the expression X ** Y must
be calculated by first promoting each operand to real, generating a
real result. Then as would proceed usually when using a real in a
place where an unsigned quantity is needed, the final result will be
converted as necessary as a subsequent operand to the rest of the
statement.
Hence if you have:
reg [7:0] a;
...
a = 2**5;
the subexpression '2**5' would be interpreted by the tool as if it
were:
2.0 ** 5.0
the result 32.0 would be generated;
and the tool would then reduce this expression to:
a = 32.0;
Then it would apply the assignement expression rules, where the right
hand side is converted to something that will fit in the left hand
side:
As the target 'a' is unsigned 8 bit wide item, the 32.0 would be
converted to unsigned: 32'h0000_0020;
The low 8 bits would be assigned to a; and a would have the value
8'd32.
Similarily in the declaraion the real value generated by the
exponetion operator would be conferted to a 32 bit signed quantity,
32'sd32, which is correct.
OK?
This archive was generated by hypermail 2.1.4
: Mon Jul 08 2002 - 12:55:35 PDT
and
sponsored by Boyd Technology, Inc.