Author: Bo Persson
Date: 09:22:00 03/04/05
Go up one level in this thread
On March 04, 2005 at 09:51:14, Antonio Senatore wrote:
>Hi friends:
>
>I'm rewriting my engine so it can use bitboards now. However, something curious
>is happening. After having implemented with quite success the use of bitboards
>in others functions, now I'm trying to apply them in my evaluation function. As
>much as possible, I attempted to make the changes statement by statement to
>observe in what way the changes affected the speed of the engine. And here is
>where I am confused.
>
>So far, to determine if a passed pawn was or not sustained by its king, I used
>the following code (for a white pawn):
>
> if ((abs(column[wking_pos]-column[wpawn_pos]) <= 1) &&
>(abs(row[wking_pos]-row[wpawn_pos]) <= 1)) {
> ....
> etc.
> }
>
> where:
> 0 <= wking_pos <= 63 // 0 = A1, 1 = B1, etc.
> 0 <= wpawn_pos <= 63
>
>
>I changed that code for the following:
>
> if (king_attack[wpawn_pos] & WhiteKing) {
> ....
> etc.
> }
>
>For my surprise, the code that uses bitboards is slower than the first one
>(according to some own bench tests), not much, but slower after all. How can it
>be possible? Because in the first case I make two comparisons and use the abs()
>function twice meanwhile in the second case I only make a bitwise-AND operation
>(of course, with 64 bit numbers in a 32 bit system, but even so, I think it
>should be faster) Can anyone tell me what I'm doing bad?
I bet you most often only do one comparison, because the && operator
short-circuits the evaluation if the first part is false.
With the 64 bit & operator you actually do two 32-bit operations, which might
bes slightly slower.
BTW, the abs() function is inlined with some trick coding, using only a very few
instructions and no jumps.
>Additionally, the same
>thing happens to me with:
>
>If (!(king_attack[wking_pos] & WhitePieces)) {
> ....
> etc.
>}
>
>that I attempted to use to see if the white king is or not surrounded for, at
>least, one own piece. Surprisingly, the code that makes the same thing by
>checking square by square (on the eight squares that surround the king) is a bit
>faster. I work with MSVC++ 6.0
Again, what are the odds that one of the first test might succeed? You only have
to do all eight comparisons if the king is all alone in the middle of the board!
>
>Many thanks in advance for any comentary that you can do.
Some bitboard code can be improved by working on one half at a time, and short
circuit when the result is known.
If your optimized code is just slightly faster than the bitboard attempt, you
are on the right track!
>
>Regards
>Antonio
Bo Persson
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.