[sv-bc] RE: true/false

From: Steven Sharp <sharp@cadence.com>
Date: Wed Jul 27 2011 - 18:32:14 PDT

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.
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Wed Jul 27 18:32:59 2011

This archive was generated by hypermail 2.1.8 : Wed Jul 27 2011 - 18:33:05 PDT