Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: To: Gerd

Author: Bas Hamstra

Date: 02:46:37 01/21/03

Go up one level in this thread


Hi Russell,

Question: Why do you calculate KnightAttacks the way you do? Why not simply

  KnightAttacks(Sq) = KnightAttMask[Sq];

One memory lookup in a small precalculated table KnAtt[64] should be much much
faster. For the rest I am interested to test the speed of the C-style fill
routines against rotated BB. Will be slower, but how much?

Bas.



On January 20, 2003 at 23:20:01, Russell Reagan wrote:

>On January 20, 2003 at 22:28:55, Anthony Cozzie wrote:
>
>>Could you please repost your floodfill code for one of the attacks bitboards?
>>
>>anthony
>
>I don't know if you are only wanting the MMX stuff, but here is some of the same
>kind of stuff in C. It is kind of slow, and you need to make sure you aren't
>doing massive uneccessary copying of data (pass by value). I (incorrectly)
>assumed that the compiler would recursively inline these functions, but I was
>wrong. Fortunately someone pointed that out to me and helped me go way faster
>than I was going before (thanks Dann).
>
>bitboard_t shiftRight (bitboard_t b) {
>	return (b << 1) & 0xfefefefefefefefe;
>}
>
>bitboard_t shiftLeft (bitboard_t b) {
>	return (b >> 1) & 0x7f7f7f7f7f7f7f7f;
>}
>
>bitboard_t shiftUp (bitboard_t b) {
>	return b << 8;
>}
>
>bitboard_t shiftDown (bitboard_t b) {
>	return  b >> 8;
>}
>
>bitboard_t shiftUpRight (bitboard_t b) {
>	return (b << 9) & 0xfefefefefefefefe;
>}
>
>bitboard_t shiftUpLeft (bitboard_t b) {
>	return (b << 7) & 0x7f7f7f7f7f7f7f7f;
>}
>
>bitboard_t shiftDownRight (bitboard_t b) {
>	return (b >> 7) & 0xfefefefefefefefe;
>}
>
>bitboard_t shiftDownLeft (bitboard_t b) {
>	return (b >> 9) & 0x7f7f7f7f7f7f7f7f;
>}
>
>bitboard_t fillUpBlocked (bitboard_t source, bitboard_t clear) {
>	source |= clear & (source << 8);
>	clear &= clear << 8;
>	source |= clear & (source << 16);
>	clear &= clear << 16;
>	return source |= clear & (source << 32);
>}
>
>bitboard_t fillDownBlocked (bitboard_t source, bitboard_t clear) {
>	source |= clear & (source >> 8);
>	clear &= clear >> 8;
>	source |= clear & (source >> 16);
>	clear &= clear >> 16;
>	return source |= clear & (source >> 32);
>}
>
>bitboard_t fillLeftBlocked (bitboard_t source, bitboard_t clear) {
>	clear &= 0x7f7f7f7f7f7f7f7f;
>	source |= clear & (source >> 1);
>	clear &= clear >> 1;
>	source |= clear & (source >> 2);
>	clear &= clear >> 2;
>	return source |= clear & (source >> 4);
>}
>
>bitboard_t fillRightBlocked (bitboard_t source, bitboard_t clear) {
>	clear &= 0xfefefefefefefefe;
>	source |= clear & (source << 1);
>	clear &= clear << 1;
>	source |= clear & (source << 2);
>	clear &= clear << 2;
>	return source |= clear & (source << 4);
>}
>
>bitboard_t fillUpRightBlocked (bitboard_t source, bitboard_t clear) {
>	clear &= 0xfefefefefefefefe;
>	source |= clear & (source << 9);
>	clear &= clear << 9;
>	source |= clear & (source << 18);
>	clear &= clear << 18;
>	return source |= clear & (source << 36);
>}
>
>bitboard_t fillUpLeftBlocked (bitboard_t source, bitboard_t clear) {
>	clear &= 0x7f7f7f7f7f7f7f7f;
>	source |= clear & (source << 7);
>	clear &= clear << 7;
>	source |= clear & (source << 14);
>	clear &= clear << 14;
>	return source |= clear & (source << 28);
>}
>
>bitboard_t fillDownRightBlocked (bitboard_t source, bitboard_t clear) {
>	clear &= 0xfefefefefefefefe;
>	source |= clear & (source >> 7);
>	clear &= clear >> 7;
>	source |= clear & (source >> 14);
>	clear &= clear >> 14;
>	return source |= clear & (source >> 28);
>}
>
>bitboard_t fillDownLeftBlocked (bitboard_t source, bitboard_t clear) {
>	clear &= 0x7f7f7f7f7f7f7f7f;
>	source |= clear & (source >> 9);
>	clear &= clear >> 9;
>	source |= clear & (source >> 18);
>	clear &= clear >> 18;
>	return source |= clear & (source >> 36);
>}
>
>bitboard_t attacksLeft (bitboard_t source, bitboard_t clear) {
>	return shiftLeft(fillLeftBlocked(source, clear));
>}
>
>bitboard_t attacksRight (bitboard_t source, bitboard_t clear) {
>	return shiftRight(fillRightBlocked(source, clear));
>}
>
>bitboard_t attacksUp (bitboard_t source, bitboard_t clear) {
>	return shiftUp(fillUpBlocked(source, clear));
>}
>
>bitboard_t attacksDown (bitboard_t source, bitboard_t clear) {
>	return shiftDown(fillDownBlocked(source, clear));
>}
>
>bitboard_t attacksUpLeft (bitboard_t source, bitboard_t clear) {
>	return shiftUpLeft(fillUpLeftBlocked(source, clear));
>}
>
>bitboard_t attacksDownLeft (bitboard_t source, bitboard_t clear) {
>	return shiftDownLeft(fillDownLeftBlocked(source, clear));
>}
>
>bitboard_t attacksUpRight (bitboard_t source, bitboard_t clear) {
>	return shiftUpRight(fillUpRightBlocked(source, clear));
>}
>
>bitboard_t attacksDownRight (bitboard_t source, bitboard_t clear) {
>	return shiftDownRight(fillDownRightBlocked(source, clear));
>}
>
>bitboard_t pawnAttacks (bitboard_t source, color_t col) {
>	return (shiftUpLeft(source) | shiftUpRight(source)) >> (col << 4);
>}
>
>bitboard_t pawnSingleAdvances (bitboard_t source, bitboard_t clear, color_t col)
>{
>	return ((shiftUp(source) >> (col << 4)) & clear);
>}
>
>bitboard_t pawnDoubleAdvances (bitboard_t source, bitboard_t clear, color_t col)
>{
>	return pawnSingleAdvances(pawnSingleAdvances(source & (RANK2_MASK << (40 *
>col)), clear, col), clear, col);
>}
>
>bitboard_t knightAttacks (bitboard_t source) {
>	return	((source >> 17) & 0x7f7f7f7f7f7f7f7f) |
>		((source << 15) & 0x7f7f7f7f7f7f7f7f) |
>		((source >> 15) & 0xfefefefefefefefe) |
>		((source << 17) & 0xfefefefefefefefe) |
>		((source >> 10) & 0x3f3f3f3f3f3f3f3f) |
>		((source <<  6) & 0x3f3f3f3f3f3f3f3f) |
>		((source >>  6) & 0xfcfcfcfcfcfcfcfc) |
>		((source << 10) & 0xfcfcfcfcfcfcfcfc);
>}
>
>bitboard_t bishopAttacks (bitboard_t source, bitboard_t clear) {
>	return attacksUpLeft(source, clear) | attacksUpRight(source, clear) |
>		attacksDownLeft(source, clear) | attacksDownRight(source, clear);
>}
>
>bitboard_t rookAttacks (bitboard_t source, bitboard_t clear) {
>	return attacksUp(source, clear) | attacksDown(source, clear) |
>		attacksLeft(source, clear) | attacksRight(source, clear);
>}
>
>bitboard_t queenAttacks (bitboard_t source, bitboard_t clear) {
>	return bishopAttacks(source, clear) | rookAttacks(source, clear);
>}
>
>bitboard_t kingAttacks (bitboard_t source) {
>	return shiftRight(source) | shiftLeft(source) |
>		shiftUp(source) | shiftDown(source) |
>		shiftUpLeft(source) | shiftUpRight(source) |
>		shiftDownLeft(source) | shiftDownRight(source);
>}
>
>bitboard_t enemyAttacks () {
>	bitboard_t clear = emptySquares;
>	return pawnAttacks(enemyPawns, color) |
>		knightAttacks(enemyKnights) |
>		bishopAttacks(enemyBishops | enemyQueens, clear) |
>		rookAttacks(enemyRooks | enemyQueens, clear) |
>		kingAttacks(enemyKing);
>}



This page took 0.01 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.