Computer Chess Club Archives


Search

Terms

Messages

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

Author: James Swafford

Date: 09:58:11 01/19/06

Go up one level in this thread


On January 19, 2006 at 10:54:37, Robert Hyatt wrote:

>On January 18, 2006 at 07:54:04, James Swafford wrote:
>
>>On January 18, 2006 at 03:29:48, Chan Rasjid wrote:
>>
>>>On January 17, 2006 at 17:41:03, James Swafford wrote:
>>>
>>>>On January 17, 2006 at 14:59:15, Robert Hyatt wrote:
>>>>
>>>>>On January 17, 2006 at 12:52:40, James Swafford wrote:
>>>>>
>>>>>>On January 17, 2006 at 12:29:21, JW de Kort wrote:
>>>>>>
>>>>>>>Thank you for your reply. I check the boundries of the array's but that seems to
>>>>>>>be correct.
>>>>>>>
>>>>>>>Could you please clarify your response because i'am not 100% sure what you mean.
>>>>>>>
>>>>>>
>>>>>>I'll try.  Let me preface this with this caveat: I doubt this is
>>>>>>your problem. :)  Dann's advice is pretty sound.
>>>>>>
>>>>>>Let's say you are evaluating a bitwise expression "a & b".
>>>>>>If a == 0, then ( a & b ) == 0 for any b.  So, it's not
>>>>>>necessary for the compiler to go to the trouble of figuring
>>>>>>out what b is.
>>>>>>
>>>>>>In your case, a & b represent items in an array.  What is
>>>>>>really evaluated is probably implementation specific
>>>>>>(depends on the compiler), but it wouldn't even need to fetch
>>>>>>the item from the second array to do the bitwise comparison
>>>>>>if your first item (a) is 0.  So, possibly you are skirting a
>>>>>>boundary bug when i==1 since your "a" is always 0.
>>>>>>
>>>>>>Again, I doubt that's the case in your program, but it's
>>>>>>a possiblity.
>>>>>>
>>>>>>--
>>>>>>James
>>>>>>
>>>>>
>>>>>I don't see how that would cause a problem, since it has to fetch both values,
>>>>>and then AND them to produce the final zero/non-zero result for testing.  This
>>>>>isn't the same as
>>>>
>>>>
>>>>
>>>>Why does it have to?  If you say that's what most compilers *do*, then
>>>>I believe you (I don't claim to be a compiler expert), but, mathematically,
>>>>they don't *have to*, since  0 & b == 0 for any integer b.
>>>>Please tell me what I'm missing. :)
>>>>James
>>>
>>>I can guess compiler has to have a natural degree of dumbness.
>>>You specifically ask to test if ( (a & b)== 0 ).
>>>
>>>I doubt they do extra work to add if (a == 0), ..or if (a == 0) && if (b == 0 ).
>>>Rather the expected method is fetch, a, fetch b AND them and test.
>>
>>I thought the answer would be somewhere along those lines... Bob
>>said the compiler "has to", but he must've meant it is "going to."
>>
>>It seems to me that in cases where the second operand is a complex
>>expression you could potentially save a lot of work by simply testing
>>the first operand for 0 (or vv).
>>
>>Thanks,
>>--
>>James
>
>I used the term "has to" rather than "a sane compiler ought to do this".  That
>is, doing it any other way doesn't make any sense at all and would impact
>performance by adding a second conditional test/jump...

Yes, now we're on the same page.  Thanks for the explanation.

--
James


>
>
>>
>>
>>>
>>>Rasjid



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.