From: Steven Sharp (sharp@cadence.com)
Date: Thu Jul 05 2001 - 14:01:46 PDT
Precedence: bulk
>I amd not sure how expression rules apply to this example. As I read
>new Verilog 2000 LRM A has value 5'b01111, then '-' is applied to value
>producing 5'b10001 then result is widened to 6'b010001, but I think XL produces
>6'b110001. I am not sure if XL applies '-' to value of 6'b001111 or if
>there is an implied signed keyword somewhere. Also I am not sure what
>effect of signed keyword on A and/or out would be.
You need to read the rules more carefully. As stated in section 4.4.2,
interim results take the size of the largest operand, including the LHS
in an assignment. The value of A is an interim result, and is thus
extended before '-' is applied.
Section 4.5.2 describes the exact steps for evaluating an expression. First
the expression size is determined based on the standard rules of expression
size determination. In this case, the expression size is 6, due to the LHS.
Then the signedness is determined. In this case it is unsigned, since A is
unsigned. Then all operands are coerced to unsigned, which has no effect
since A was already unsigned. Then the size of each operand is extended to
the size of the expression, performing sign extension iff the operand type
after coersion is signed. In this case, the value of A is extended from
5'b01111 to 6'b001111.
After that, the '-' is applied, resulting in 6'b110001. There is no
implied signed keyword anywhere, and XL worked this way before such a
thing existed. It is also the natural answer, since A is 15, and out
is supposed to be -A and in fact 6'b110001 is -15 expressed as a
6-bit unsigned number.
The effect of a signed keyword on A would be to make A signed. It would
also make the expression -A signed. Thus the size extension of A to the
size of the expression would be done with sign extension. This would not
matter in this case, since A is positive. Since the sign bit is zero,
sign-extension is the same as zero-extension. If A were signed and negative,
then it would make a difference.
If out were signed, it would make no difference to the result of the
expression. Section 4.5.1 states that expression type does not depend
on the LHS. It would only affect places where out was referenced in an
expression. For example, if it were printed in decimal format, it would
print as -15 instead of 49.
Steven Sharp
sharp@cadence.com
This archive was generated by hypermail 2.1.4
: Mon Jul 08 2002 - 12:54:40 PDT
and
sponsored by Boyd Technology, Inc.