Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Bizar Question for programmers: very strange behaviour of my engine

Author: Robert Hyatt

Date: 14:56:08 01/18/06

Go up one level in this thread


On January 17, 2006 at 17:50:33, Dan Honeycutt wrote:

>On January 17, 2006 at 14:59:15, Robert Hyatt wrote:
>
>...
>>
>>if (a && b) where if a is 0, b would not even be fetched usually...
>>
>
>I thought, in this case, b _must_ not be fetched.
>
>Best
>Dan H.


I don't think so.  Compiler optimizers are good at "lifting" instructions back
up the instruction stream so that memory reads can be started well before the
data is needed.  As a result, on a Cray for example, it is likely both of those
loads would be done at the same point way back up in the code (the machine has
enough registers to make this work well) so that when we get to this point in
the code, the two comparisons can be done instantly.

Perhaps you are thinking that the two conditional tests must be done
left-to-right, and so far as I know that is correct.  But fetching the operands
left to right I am not sure about.  I am sure that there have been compilers in
the past that did what I described.  Personally I'd consider it a bad
programming practice to write something like that (for example,  if ((i < n) &&
(a[i] == 0)) where I could have a value > n, which would be outside the
subscript range for the a array).




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.