From: Kausik Datta (kausikd@cal.interrasystems.com)
Date: Tue Jun 28 2005 - 21:46:25 PDT
Hi Steven,
Thanks for your reply. For question 4 here is the section (4.1.13) of
LRM.(See the last line)
The evaluation of a conditional operator shall begin with the evaluation of
expression1. If expression1 evaluates
to false (0), then expression3 shall be evaluated and used as the result of
the conditional expression. If
expression1 evaluates to true (known value other than 0), then expression2
is evaluated and used as the
result. If expression1 evaluates to ambiguous value (x or z), then both
expression2 and expression3 shall be
evaluated and their results shall be combined, bit by bit, using Table 28 to
calculate the final result unless
expression2 or expression3 is real, in which case the result shall be 0. If
the lengths of expression2 and
expression3 are different, the shorter operand shall be lengthened to match
the longer and zero-filled from
the left (the high-order end).
Thanks
Kausik
-----Original Message-----
From: owner-etf@boyd.com [mailto:owner-etf@boyd.com] On Behalf Of Steven
Sharp
Sent: Wednesday, June 29, 2005 5:42 AM
To: etf@boyd.com; kausikd@cal.interrasystems.com
Subject: Re: Some queries related to expression type
> 1. What will be the sign type of expression : (0 || 1.234) at line 2.
> Is the logical or operator (||) treated as comparison operator?
The LRM fails to specify this. The result of the logical AND and OR
operators (|| and &&) is supposed to be the same as the result of a
comparison operator: 1 bit unsigned.
These operators are not actually comparison operators, however. Their
operands are fully self-determined, and do not affect each other's size.
The table of bit lengths for self-determined expressions has been fixed for
the 2005 revision, to put these in a different table entry from the
comparisons.
> 2. What will be the sign type of expression (3.33333 == 3.33333000) ? (0
||
> 1.234) : (4 && (1 - 1)) at line 2?
> How does it depend on (3.33333 == 3.33333000) , (0 || 1.234) or (4 &&
> (1 - 1))
It will be unsigned. The (3.33333 == 3.33333000) does not affect the result
type at all, since it is a self-determined operand of the ?:
operator. The other two operands do affect the result type. Both are
unsigned (from question 1 above), so the result is unsigned.
> 3. What will be the decimal value of 1'sb1
It has a value of -1. A 1-bit signed value can only represent two numerical
values: 0 and -1. There is no way to represent 1. This is a natural
consequence of how twos-complement is defined, applied to the degenerate
case of one bit.
> 4. Will be the value of r and r1 same? According to LRM they will be
different.
r will be 0011 and r1 will be 1111. Is it a bug in LRM?
Where does the LRM say this? Both will be 4'b1111.
In the expression "1==1 ? 2'sb11 : 1", the operand "1==1" is self-
determined, so the fact that its result is unsigned has no effect on the
result type of the conditional operator. The other two operands are
context-determined. Both are signed, so the result of the conditional
operator is signed (and 32 bits wide). So the result of 2'sb11 is coerced
to signed and extended to 32 bits.
Then the assignment truncates this back down to 4 bits, or 1111.
Steven Sharp
sharp@cadence.com
This archive was generated by hypermail 2.1.4
: Tue Jun 28 2005 - 21:18:20 PDT
and
sponsored by Boyd Technology, Inc.