Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: To: Gerd

Author: Gerd Isenberg

Date: 00:55:42 01/21/03

Go up one level in this thread


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

Hi Anthony,

the MMX-stuff for bishops with dumb7fill and files via KoggeStone:
It looses information due to accumulating attacks of multiple directions in one
register (see Steffan Westcotts reply) but gains form parallel processing.


Cheers,
Gerd

----------------------------------------------------------------------------


// input:   mm1 bishops
//	    mm6 emptySquares
// output   mm0 bishopAttacks
//===========================
void getBishopAttacks ()
	__asm
	{
		pcmpeqd mm7, mm7	; 0xffffffffffffffff
		pxor	mm5, mm5	; 0
		movq	mm2, mm1	; leftup
		psubb	mm5, mm7	; 0x0101010101010101
		movq	mm3, mm1	; leftdown
		psubb	mm7, mm5	; 0xfefefefefefefefe notA
		movq	mm4, mm1	; rightdown
		movq	mm5, mm7	; 0xfefefefefefefefe notA
		pand	mm2, mm7	; clear leftup occupied or a file
		psrlq	mm5, 1		; 0x7f7f7f7f7f7f7f7f notH
		pand	mm3, mm7	; clear leftdown occupied or a file
		pand	mm1, mm5	; clear rightup occupied or h file
		pand	mm4, mm5	; clear rightdown occupied or h file
		pand	mm7, mm6	; to clear left occupied or a-file
		pand	mm5, mm6	; to clear left occupied or h-file
		// 1. diagonal dumbfill in each direction
		psllq	mm1, 9		; rightup
		psrlq	mm4, 7		; rightdown
		psllq	mm2, 7		; leftup
		psrlq	mm3, 9		; leftdown
		movq	mm0, mm1	; bishopAttacks |= rightup
		por	mm0, mm4	; bishopAttacks |= rightdown
		por	mm0, mm2	; bishopAttacks |= leftup
		por	mm0, mm3	; bishopAttacks |= leftdown
		pand	mm1, mm5	; clear rightup occupied or h file
		pand	mm4, mm5	; clear rightdown occupied or h file
		pand	mm2, mm7	; clear leftup occupied or a file
		pand	mm3, mm7	; clear leftdown occupied or a file
		// 2. diagonal dumbfill in each direction
		psllq	mm1, 9		; rightup
		psrlq	mm4, 7		; rightdown
		psllq	mm2, 7		; leftup
		psrlq	mm3, 9		; leftdown
		por	mm0, mm1	; bishopAttacks |= rightup
		por	mm0, mm4	; bishopAttacks |= rightdown
		por	mm0, mm2	; bishopAttacks |= leftup
		por	mm0, mm3	; bishopAttacks |= leftdown
		pand	mm1, mm5	; clear rightup occupied or h file
		pand	mm4, mm5	; clear rightdown occupied or h file
		pand	mm2, mm7	; clear leftup occupied or a file
		pand	mm3, mm7	; clear leftdown occupied or a file
		// 3. diagonal dumbfill in each direction
                //....
		// 7. diagonal dumbfill in each direction
		psllq	mm1, 9		; rightup
		psrlq	mm4, 7		; rightdown
		psllq	mm2, 7		; leftup
		psrlq	mm3, 9		; leftdown
		por	mm0, mm1	; bishopAttacks |= rightup
		por	mm0, mm4	; bishopAttacks |= rightdown
		por	mm0, mm2	; bishopAttacks |= leftup
		por	mm0, mm3	; bishopAttacks |= leftdown
	}
}


// input:   mm1 rook(s)
//	    mm6 emptySquares
// output   mm0 fileAttacks
//===========================
void getFileAttacks()
{
	__asm
	{	// up/down up/dn Kogge-Stone
		movq	mm2, mm1	; generator upg
		movq	mm4, mm1	; generator dng
		movq	mm5, mm6	; propagator upp
		movq	mm7, mm6	; propagator dnp
		psllq	mm2, 8		; upg << 8
		psrlq	mm4, 8		; dng >> 8
		psllq	mm5, 8		; upp << 8
		psrlq	mm7, 8		; dnp >> 8
		pand	mm2, mm6	; upp & (upg << 8)
		pand	mm4, mm6	; dnp & (dng >> 8)
		pand	mm5, mm6	; upp &= upp << 8
		pand	mm7, mm6	; dnp &= dnp >> 8
		por	mm2, mm1	; upg |= upp & (upg << 8)
		por	mm4, mm1	; dng |= dnp & (dng >> 8)

		movq	mm0, mm2	; upg
		movq	mm3, mm4	; dng
		psllq	mm2, 16		; upg << 16
		psrlq	mm4, 16		; dng >> 16
		pand	mm2, mm5	; upp & (upg << 16)
		pand	mm4, mm7	; dnp & (dng >> 16)
		por	mm2, mm0	; upg |= upp & (upg << 16)
		por	mm4, mm3	; dng |= dnp & (dng >> 16)
		movq	mm0, mm5	; upp
		movq	mm3, mm7	; dnp
		psllq	mm5, 16		; upp << 16
		psrlq	mm7, 16		; dnp >> 16
		pand	mm5, mm0	; upp &= p << 16
		pand	mm7, mm3	; dnp &= p >> 16

		movq	mm0, mm2	; upg
		movq	mm3, mm4	; dng
		psllq	mm0, 32		; upg << 32
		psrlq	mm4, 32		; dng >> 32
		pand	mm0, mm5	; upp & (upg << 32)
		pand	mm4, mm7	; dnp & (dng >> 32)
		por	mm0, mm2	; upg |= upp & (upg << 32)
		por	mm4, mm3	; dng |= dnp & (dng >> 32)
		psllq	mm0, 8		; final shift up
		psrlq	mm4, 8		; final shift dn
		por	mm0, mm4
	}
}

reply snipped of Steffan Westcott:

>You may remember in my previous posts I gave algorithms for finding attacks in
>just one direction, and gave an example of rook attacks moving up the board. I
>notice in your posts that you combine the attacks in all directions as they are
>calculated. Your approach is good (although uses many working variables)however
>it loses information by combining the intermediate results too early.
>
>There is a 1-1 correspondence between set bits in the bitboard returned by
>RookMovesUp() and all friendly (read: "white" or "black") rook moves (including
>captures) going up the board. This is because at most 1 upward rook move is
>possible for each square. So this bitboard can serve as part of a unsorted
>movelist.
>





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.