[sv-bc] RE: true/false

From: Bresticker, Shalom <shalom.bresticker@intel.com>
Date: Thu Jul 28 2011 - 02:46:29 PDT

Thanks.

It is clear to me that 'logically false' means 'definitely false', for two reasons.

One, there is no discussion of context in that section. The very example that you give, 'cond = b && c;", is enough, even without the $display statement. If b is X, you still don't know the value of cond without evaluating c. That is likely just as common as the use of && in a condition.

Two, the entire section distinguishes between 'true' and 'ambiguous', as in, for example,
"The result of the evaluation of a logical operation shall be 1 (defined as true), 0 (defined as false), or, if the result is ambiguous, the unknown value (x)."

Regards,
Shalom

From: Steven Sharp [mailto:sharp@cadence.com]
Sent: Thursday, July 28, 2011 4:32 AM
To: Bresticker, Shalom; SV-BC
Subject: RE: true/false

AI: File new mantis item to request clarification of Short-circuiting
      of &&, ||, ->, ?: (11.3.5)

Comment: what was the issue here?

When we were discussing the issue of how X/Z and partially-X/Z values were treated as conditions of if-statements, the question was raised about how they were treated for && and ||. In particular, the question was what values of the first operand would cause short-circuiting of evaluation of the second operand, and whether this was the same as the treatment as true/false by an if-statement.

My answer was that it cannot be. Although && and || are most often used in conditions, where X is treated as false, they can also be used in situations where an X is treated differently from 0. For example, you can write

  cond = b && c;
  $display("%b", cond);

If b is X, you know the result is not a definite 1. But you don't know whether the result is 0 or X until you evaluate c. If c is 0, then the result is 0. But if c is nonzero (including X), then the result is X. So you cannot short-circuit the && if the first operand is X, even though that is treated as false by an if-statement. You can only short-circuit on a definite false.

The LRM text in 11.4.7 says "For &&, if the first operand value is logically false then the second operand shall not be evaluated." If "logically false" is interpreted as meaning "considered false by an if-statement", then this is wrong. If it is interpreted as meaning "definitely logically false, not uncertain", then it is fine.

I think the text for || works either way, since it has to be true to short-circuit.

And then we listed -> and ?: because those are specified to short-circuit, and might also have issues.

Thanks,
Shalom

Shalom Bresticker
Intel LAD DA, Jerusalem, Israel
+972 2 589 6582 (office)
+972 54 721 1033 (cell)
http://www.linkedin.com/in/shalombresticker

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

--
This message has been scanned for viruses and
dangerous content by MailScanner<http://www.mailscanner.info/>, and is
believed to be clean.
---------------------------------------------------------------------
Intel Israel (74) Limited
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Jul 28 02:48:22 2011

This archive was generated by hypermail 2.1.8 : Thu Jul 28 2011 - 02:48:37 PDT