Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: 64 bit 90 degree rotations -- a summary from USENET

Author: Bo Persson

Date: 13:35:14 06/12/02

Go up one level in this thread


On June 11, 2002 at 18:35:59, Gerd Isenberg wrote:

>90 degree rotation with PMOVMSKB (AMD mmx-Extension)
>
>“PMOVMSKB reg32, mmreg” performs the following operations:
>reg32 [31:8 ] =0
>reg32 [7 ] ==mmreg [63 ]
>reg32 [6 ] ==mmreg [55 ]
>reg32 [5 ] ==mmreg [47 ]
>reg32 [4 ] ==mmreg [39 ]
>reg32 [3 ] ==mmreg [31 ]
>reg32 [2 ] ==mmreg [23 ]
>reg32 [1 ] ==mmreg [15 ]
>reg32 [0 ] ==mmreg [7 ]
>
>no idea whether it is fast (i fear not, because of vector path instruction)
>
>;input mm7, output mm7
>
>	pmovmskb	edx, mm7	; get bit 7 from every byte		psllq	        mm7, 1          ;
>and shift bit i -> i+1
>	shl		edx, 8
>
>	pmovmskb	eax, mm7	; get bit 6 from every byte
>	psllq	        mm7, 1
>	or		edx, eax
>	shl		edx, 8
>
>	pmovmskb	eax, mm7	; get bit 5 from every byte
>	psllq	        mm7, 1
>	or		edx, eax
>	shl		edx, 8
>
>	pmovmskb	eax, mm7	; get bit 4 from every byte
>	psllq	        mm7, 1
>	or		edx, eax
>
>	movd	        mm6, edx	; rotated high board
>
>	pmovmskb	edx, mm7	; get bit 3 from every byte
>	psllq	        mm7, 1
>	shl		edx, 8
>
>	pmovmskb	eax, mm7	; get bit 2 from every byte
>	psllq	        mm7, 1
>	or		edx, eax
>	shl		edx, 8
>
>	pmovmskb	eax, mm7	; get bit 1 from every byte
>	psllq	        mm7, 1
>	or		edx, eax
>	shl		edx, 8
>
>	pmovmskb	eax, mm7	; get bit 0 from every byte
>	or		edx, eax
>
>	movd	        mm7, edx	; rotated low board
>	punpckldq	mm7, mm6        ; mm7 is now the rotated one
>
>
>may be PMOVMSKB is more interesting to get consecutive bits from one file.
>

Yes, you can use just one of the shift/movmask pairs to get the file you need
(when you need it). Also works for the Pentium 4.

Here is my code for VC7 getting a file from the non-rotated bitboard. Shift it
to the sign bits and extract these:

   __forceinline int Occupied90_ByteOf(Square TheSquare)
  { return _mm_movemask_pi8((MyLitePieces | MyDarkPieces) << (7 -
FileOf(TheSquare))); }


Not any faster though, just for fun.

Bo Persson
bop2@telia.com



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.