Author: Gerd Isenberg
Date: 09:32:03 09/21/04
Go up one level in this thread
>>Pawn are still a problem I think, since the solution is not much nicer:
>>
>>( assuming the compiler understands the a negative shl is a shr )
>
>One possible solution is using a generalized branchless shift:
>
>http://www.azillionmonkeys.com/qed/asmexample.html
>
>---------------------------------------------------------------------
>8. Generalized shift (32-bit)
>
>unsigned long gensh(unsigned long v, int x) {
>int a, b;
> a = (v << x) & -(((unsigned int)x) < 32);
> x = -x;
> b = (v >> x) & -(((unsigned int)x) < 32);
> return a|b;
>}
>
>and asssembly
>---------------------------------------------------------------------
>
>for bitboards:
>
>BitBoard gensh(BitBoard v, int x) {
// oups BitBoard not ont
> BitBoard a, b;
> a = (v << x) & -(((unsigned int)x) < 64);
> x = -x;
> b = (v >> x) & -(((unsigned int)x) < 64);
> return a|b;
>}
>
the generated assembly look really terrible for x86-32 for that routine - forget
it ;-(
So the modified method posted by Russell is much better.
BitBoard rightPawnAttacks(BitBoard pawns, int color)
{
return ((bb<<9)>>(color*16)) & notA;
}
BitBoard leftPawnAttacks(BitBoard pawns, int color)
{
return ((bb<<7)>>(color*16)) & notH;
}
Since msc generates a call for "variable" 64-bit shift,
this inline assembly is probably the fastest to get pawn attacks with color
param.
BitBoard rightPawnAttacks(BitBoard pawns, int color)
{
__asm
{
mov eax,dword ptr [pawns]
mov edx,dword ptr [pawns+4] ; bb in edx:eax
mov ecx, [color] ; white=0, black=1
shld edx,eax,9
shl ecx,4 ; white=0, black=16
shl eax,9 ; bb << 9
shrd eax,edx,cl
shr edx,cl ; bb >> white? 0 : 16
and eax,0FEFEFEFEh ; & notA low board
and edx,0FEFEFEFEh ; & notA high board
// bitboard return via edx:eax
}
}
The drawback with the assembly, if __forcedinline and color is compile time
constant: the compiler is not able to do any optimizations with that code.
Gerd
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.