Author: Gerd Isenberg
Date: 08:40:41 10/25/02
Go up one level in this thread
On October 25, 2002 at 07:55:47, Matthias Gemuh wrote:
<snip>
>BITBOARD getQueenAttacks(BITBOARD queens, BITBOARD freeSquares)
>{
> BITBOARD attck = 0;
> BITBOARD rightup = SHIFTRIGHTUP(queens);
> BITBOARD rightdown = SHIFTRIGHTDOWN(queens);
> BITBOARD leftup = SHIFTLEFTUP(queens);
> BITBOARD leftdown = SHIFTLEFTDOWN(queens);
> BITBOARD left = SHIFTLEFT(queens);
> BITBOARD right = SHIFTRIGHT(queens);
> BITBOARD up = SHIFTUP(queens);
> BITBOARD down = SHIFTDOWN(queens);
> attck |= rightup|rightdown|leftup|leftdown|left|right|up|down;
> for (int i=0; i<7; i++) {
> rightup = SHIFTRIGHTUP(rightup&freeSquares);
> rightdown = SHIFTRIGHTDOWN(rightdown&freeSquares);
> leftup = SHIFTLEFTUP(leftup&freeSquares);
> leftdown = SHIFTLEFTDOWN(leftdown&freeSquares);
> left = SHIFTLEFT(left&freeSquares);
> right = SHIFTRIGHT(right&freeSquares);
> up = SHIFTUP(up&freeSquares);
> down = SHIFTDOWN(down&freeSquares);
> attck |= rightup|rightdown|leftup|leftdown|left|right|up|down;
> }
> return (attck);
>}
Second Point (first is unrolling the loop) make sure that all 64-bit shifts are
inlined (don't know borland c++ builder, but i fear it use subroutines to shift
64 bit wise).
To have a chance to do all in registers you may do sequences of each direction.
But I fear that even than it's not possible for the compiler to do it.
Another optimization is to combine the wrap bitboards (0x7f..., 0xfe) by "and"
with freeSquares once, and to use freeSquaresAndNotH resp. freeSquaresAndNotA
inside the (unrolled) loop. That saves one "and" per iteration and direction.
BITBOARD getQueenAttacks(BITBOARD queens, BITBOARD freeSquares)
{
register BITBOARD dir; // ecx:ebx ???
register BITBOARD attck; // edx:eax is fine here and saves the return
register BITBOARD freeSquaresButNoWrap; // edi:esi ???
// start with left from h to a file ...
dir = queens & notA;
freeSquaresButNoWrap = freeSquares & notA;
// first left fill
dir >>= 1;
attck = dir; // or use |= with proper initialized attck
dir &= freeSquaresButNoWrap;
// second left fill
dir >>= 1;
attck |= dir;
dir &= freeSquaresButNoWrap;
....
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.