Another important kind of opportunistic short-circuiting is replacing a function call expression with its returned value, if that can be determined early. As 5.1.4 says, "if the final result of an expression can be determined early, the entire expression need not be evaluated". For example, any call to the following function can be replaced with 1'b1. function f_always_true(input [31:0] dummy); begin $display(...); $display(...); f_always_true = 1'b1; end endfunction Two other sources of nondeterminism in the presence of side-effects are 1) evaluation of subroutine actuals (because no order specified) 2) assignment expressions, described in SV 8.3, which gives the example i = 10; j = i++ + (i = i - 1); "After execution, the value of j can be 18, 19, or 20 ..." -- Brad -----Original Message----- From: Steven Sharp [mailto:sharp@cadence.com] Sent: Tuesday, August 15, 2006 6:41 PM To: sv-bc@eda-stds.org; Brad.Pierce@synopsys.COM Cc: wadams@freescale.com Subject: RE: [sv-bc] [Fwd: Issues with IEEE 1364-2005] >From: "Brad Pierce" <Brad.Pierce@synopsys.com> >What's the justification for only tightening these two particular >Verilog operators, && and ||? I think there is some justification for it. However, I agree that it would be better to tighten them all up. Not only should && and || be guaranteed to short-circuit, all the other binary operators should be guaranteed not to short-circuit. (As always, an implementation is free to do actual evaluations in any order it likes, as long as it doesn't change visible behavior. So this is really only required when there are side-effects.) >There would still be nondeterminism for all of the other binary >operators in the presence of side-effecting operands, because the >evaluation order of their operands is not specified either. I think the LRM tried to specify this, but I have to concede that it did a poor job. I agree that this should be fixed. Evaluation of operands of all binary operators should be guaranteed to be done left-operand-before-right. >In for a penny, in for a pound. Absolutely. This does still leave the justification of why && and || should be short-circuiting when the other operators are not. Part of this is based on the fact that C (and Vera) work this way. But there are underlying reasons that they work this way. There are common idioms that use && and || and rely on short-circuiting to work properly. Examples have been given of these. I don't know of any such common idioms for the other operators. The logical connectives tend to be used in software-ish situations, where avoiding run-time errors is an issue. The bitwise logical operators tend to be used in hardware-ish situations, where this is not an issue. The special values where short-circuiting can be done for && and || are common (one expects about 50% of the time). The special values where short-circuiting can be done for other operators like + are rare corner cases. So from an simulation optimization perspective, you have allowed short-circuiting where it is most profitable. Steven Sharp sharp@cadence.comReceived on Wed Aug 16 10:30:35 2006
This archive was generated by hypermail 2.1.8 : Wed Aug 16 2006 - 10:30:52 PDT