Author: Matt Taylor
Date: 17:40:51 01/03/03
Go up one level in this thread
On January 03, 2003 at 14:15:19, Robert Hyatt wrote:
>On January 03, 2003 at 13:39:13, Uri Blass wrote:
>
>>On January 03, 2003 at 13:21:40, Robert Hyatt wrote:
>>
>>>On January 03, 2003 at 12:03:45, Uri Blass wrote:
>>>
>>>>code B is slightly faster than code A.
>>>>I know that side can get only 0 or 1(something that the compiler does not know)
>>>>and B is eqvivalent to A if you assume that side gets only 0 or 1.
>>>>
>>>>Is it possible to write a third code that will be even faster than B?
>>>>
>>>>I think that if the compiler can know that side is or 0 or 1 it can do B even
>>>>faster.
>>>>
>>>>code A:
>>>>
>>>>if (side==LIGHT)
>>>>{
>>>> if (to>=56)
>>>> {
>>>> gen_promote(from,to,bits);
>>>> return;
>>>> }
>>>>}
>>>>else
>>>>{
>>>> if (to<=7)
>>>> {
>>>> gen_promote(from,to,bits);
>>>> return;
>>>> }
>>>>}
>>>>
>>>>code B:
>>>>if ((to+side*(63-2*to))>=56)
>>>>{
>>>> gen_promote(from,to,bits);
>>>> return;
>>>>}
>>>>
>>>>Uri
>>>
>>>
>>>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();
>>
>>Not exactly because in one case I need side=0 and in another case I need side=1
>>
>
>Why? You already have "side" as a variable, just pass it to gen_promote as is.
>It doesn't matter which side is on move for the above test, as white can't move
>to
>rank 0 and black can't move to rank 7...
>
>
>>
>>I think that I will simply do one function for white and one function for black.
>>
>>I already have
>>#define rank0(i) ((i)>>3)
>>
>>Does the computer do faster if rank0(to)==0 and not if to<=7?
>
>If you want to avoid the shift, then change it to this:
>
>if (to<8 || to>55) gen_promote();
>
>Same idea.
<snip>
A good compiler won't need to shift in your original example:
; Assume al = to, edx = temp
; This code is 3 cycles on Athlon
testl $248, %al
setz %dl
subl $56, %eax
or %al, %dl
jz ...
I like best the conditional (unsigned)(to - 8) >= 48:
; Assume eax = to, eax destroyed
; This code is 2 cycle on Athlon
subl $8, %eax
cmpl $48, %eax
jb ...
The extra nice part about that code is that the compiler is not likely to make
any optimization mistakes. It is simple, and a one-line comment makes the trick
clear.
-Matt
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.