Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a question about speed

Author: Robert Hyatt

Date: 12:53:07 01/03/03

Go up one level in this thread


On January 03, 2003 at 15:09:57, Vincent Diepeveen wrote:

>On January 03, 2003 at 14:42:19, Dieter Buerssner wrote:
>
>>On January 03, 2003 at 13:21:40, Robert Hyatt wrote:
>>
>>
>>>Why not something like this:
>>>
>>>rank=to>>3;  (now we know the rank and only care if it is zero or seven, and
>>>it can't be zero for white or seven for black so side to move is not important).
>>>
>>>So, you end up with one line:
>>>
>>>
>>>if (to>>3==0 || to>>3==7) gen_promote();
>
>At his beloved P4 the >> instruction is very very very very slow.

It is not "very very very very slow"...



>
>>Why should this be faster than
>>
>>if (to <=7 || to >= 56)
>>
>>?
>>
>>With some bit fiddling tricks (which I would not suggest), one test will be
>>enough and also include the side. For example
>>
>>if ((((to ^ ~((unsigned)side-1))) & 0x38) == 0x38)
>>
>>Note, that this is untested, and probably more clever ideas are possible. It
>>assumes, that side is 0 for white and 1 for black. Then side-1 will be -1 or 0.
>>-1 is all bits set in unsigned. Now reverse the bits by not. So for white, the
>>~((unsigned)side-1)) will be 0. 0x38 is binary 111000 (decimal 56). So, only
>>when to goes to the 8th rank (56-63), the 111000 bits will be set. And the
>>binary and gives 0x38. For side = 1, ~((unsigned)side-1)) will be all bits set.
>>The xor will only set the 111000 bits, when they were cleared before (so to <=
>>7). If I haven't totally failed until here, the binary and could even be
>>avoided, by
>>
>>if ((to ^ ~((unsigned)side-1)) >= ~7U)
>>
>>
>>Uri, why do you need side? Will you movegenerator generate to to squares >= 56
>>for black pawns?
>>
>>Regards,
>>Dieter



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.