Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Bitboards: must I rotate ?

Author: Alessandro Damiani

Date: 03:49:08 05/12/02

Go up one level in this thread


On May 12, 2002 at 02:53:12, Matthias Gemuh wrote:

>On May 12, 2002 at 00:23:07, Robert Hyatt wrote:
>
>>On May 11, 2002 at 05:48:17, Matthias Gemuh wrote:
>>
>>>
>>>Hi Experts,
>>>how much faster can I compute attacks when I rotate ? 5%? 20%? 50%?
>>>I don't understand rotation and hope the gain is 1% speed boost :-).
>>>Regards,
>>>Matthias.
>>
>>It is more than that.  The main thing is that it eliminates the loop needed
>>to find where a particular diagonal, file or rank is blocked.  Generating
>>the attacks on a particular "ray" becomes a simple table lookup...
>
>
>I don't loop. I use an idea from Crafty (blocking squares)
>
>if (((MovesAndAttacks->obstructed[k][j] & BitBoth) == 0) &&
>           (MovesAndAttacks->SlidingMoves[bishop][k]&ChsPos->Mask[j]))
>
>tells me bishop on square k can move unhindered to square j.

k is the from-square, j is the to-square. You loop over the to-squares, else you
wouldn't get the moves. ;)

Note that the if-statement above is executed in a loop. This costs. By using the
conventional approach for bitboards the cost in the loop is minimized. And since
one has to at least loop over the to-squares this is optimal.

Here is an excerpt from the move generator of my engine (Fortress):

    // bishops:
    fromSquares= Board_me->pieceBoard[Board_BISHOP];
    while (fromSquares) {
        from= Bitboard_firstOne(fromSquares);
        toSquares= Board_attackFromBishop(from) & target;
        while (toSquares) {
            to= Bitboard_firstOne(toSquares);
            *current++= Move_new(from, to, Board_BISHOP, Board[to]);
            Bitboard_clearBit(toSquares, to);
        };
        Bitboard_clearBit(fromSquares, from);
    };

The variables fromSquares, toSquares, target are bitboards, while from and to
are integers.

My code is in C. If you wonder what is up with "Board_me" and
"Bitboard_clearBit()" I am emulating object oriented languages. The dot is just
replaced with the underscore.

The loop over the to-squares is in my case the following one:

        while (toSquares) {
            to= Bitboard_firstOne(toSquares);
            *current++= Move_new(from, to, Board_BISHOP, Board[to]);
            Bitboard_clearBit(toSquares, to);
        };

I have to add that Move_new() is a macro. So, the cost is essentially getting
the to-square and going to the next to-square. My Bitboard_firstOne() uses
ffs(), which I was told uses the hardware first-bit finder. The
Bitboard_clearBit() is a macro that removes the specified bit by using an AND
operation.

Regards,

Alessandro



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.