A beginner's question for bitboard experts
Posted: 05 Sep 2006, 23:00
Upto now I was almost totally ignorant about bitboards, so forgive me if I am inquiring about the obvious.
I understood that people use rotated bitboards to be able to isolate a rank, file or diagonal as a group of 6 contiguous bits, so that it can be used as an index in an array (the other index being the position of the attacker on that ray). This then makes it easy to look up the accessible squares.
Why doesn't one use simple multiplication to pack the bits of a single file or diagonal in the most-significant byte of the bitboard (which was originally packed by rank)? I am thinking about something like:
This seems to work without big tables that would pollute my cache (I can use 8 x 64 plus a shift, rather than 64 x 64). Even on a 32-bit machine it should be possible to do this reasonably efficiently, since I could do with only two integer multiplies (const_L*high_word + const_H * low_word).
I understood that people use rotated bitboards to be able to isolate a rank, file or diagonal as a group of 6 contiguous bits, so that it can be used as an index in an array (the other index being the position of the attacker on that ray). This then makes it easy to look up the accessible squares.
Why doesn't one use simple multiplication to pack the bits of a single file or diagonal in the most-significant byte of the bitboard (which was originally packed by rank)? I am thinking about something like:
- Code: Select all
b = AllPieces>>FileNr; /* files are numbered 0-7 */
b &= 0x0101010101010101LL; /* isolate the file */
b *= 0x8040201008040201LL; /* pack bits */
b >>= 56; /* bring to LSB */
b = FileAttacks[RankNr][b]; /* lookup reachable squares */
b <<= FileNr; /* Move it to the relevant file */
This seems to work without big tables that would pollute my cache (I can use 8 x 64 plus a shift, rather than 64 x 64). Even on a 32-bit machine it should be possible to do this reasonably efficiently, since I could do with only two integer multiplies (const_L*high_word + const_H * low_word).