Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Move generation question for the big boys

Author: Robert Hyatt

Date: 06:28:49 09/16/01

Go up one level in this thread


On September 15, 2001 at 22:33:18, Vincent Diepeveen wrote:

>On September 15, 2001 at 20:38:36, Robert Hyatt wrote:
>
>>On September 15, 2001 at 16:17:52, Vincent Diepeveen wrote:
>>
>>>On September 15, 2001 at 15:23:29, Bruce Moreland wrote:
>>>
>>>>On September 15, 2001 at 14:30:40, Vincent Diepeveen wrote:
>>>>
>>>>>On September 15, 2001 at 11:14:36, Sune Fischer wrote:
>>>>
>>>>>>   bb ^= mask[to_square];        // remove the bit
>>>>>>
>>>>>>   movelist[++counter].from=from_square;
>>>>>>   movelist[counter].to=to_square;
>>>>>>   movelist[counter].piece=QUEEN;
>>>>>>   movelist[counter].capturedpiece=enemy.piece[board.id[to_square]];
>>>>>
>>>>>this looks ugly. Using a pointer here would be way faster.
>>>>
>>>>Not necessarily.  If the "counter" variable is enregistered by the compiler, you
>>>>end up with about the same thing as if you used a pointer, but it also depends
>>>>upon how large the elements of "movelist" are.
>>>
>>>If compilers optimized very well, then our problems would be solved Bruce,
>>>we could go write our programs in JAVA or C++ and let the compiler handle
>>>the problems of not allocating and removing objects.
>>>
>>>Also we would be able to use old Qbasic code in a very efficient way then.
>>>
>>>That's not what happens however. Usual it's smart to NOT trust the compiler.
>>>
>>>When patterns get complex then i saw that visual c++ makes huge optimization
>>>errors.
>>>
>>>Like if i check for 2 non-array/pointer entities for being zero:
>>>
>>>if( a & b )
>>>  then do this and that;
>>>
>>>to produce some crap assembly:
>>>  CMP EAX,0
>>>  JNZ LOOP
>>>  CMP EDX,0
>>>  JNZ LOOP1
>>>
>>>Now already people will complain: "you don't need special CMP for
>>>2 different statements". Well they're right.
>>>
>>>In fact you don't need 2 compares even. All you need is something
>>>primitive like:
>>>
>>>  ADD EAX,EDX
>>>  CMP EAX,0
>>>  JNZ LOOP1
>>>
>>
>>
>>That would be terribly dangerous, and if a is 1 and b is -1 you will screw
>>up badly.  The compiler can't possibly know that it can do that unless a and
>>b are unsigned.  And it would be dangerous there as there are two non-zero
>>constants you can add and get zero in an unsigned integer.
>>
>>The compiler would need special information to be able to do the above
>>safely, otherwise the world would be debugging some of the strangest bugs
>>anyone ever saw...
>
>Yeah sorry, there were a few bugs in my example code.
>
>It should read:
>  if ( a && b )
>
>versus
>
>  if( a | b )
>

that doesn't fix a thing.  If a=1, and b=-1, then you _still_ get a zero
result which is wrong in the context of a && b.




>
>>
>>
>>>However i would need to learn assembly for this or i must rewrite
>>>my C code. The compiler isn't smart Bruce. The compiler is very stupid
>>>when talking about source connections. So i have to write:
>>>  if( a+b )
>>>    then do this and that;
>>>
>>>>Using pointers will usually help the compiler out, because it can just indirect
>>>>through a value, rather than having to deal with scaling the value and adding it
>>>>to a constant.  But in some circumstances, scaling it and adding it to a
>>>>constant is free.
>>>
>>>In general the above construction makes no sense. Optimizing it with a
>>>pointer is always safer!
>>>
>>>>bruce



This page took 0.01 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.