Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: just another reverse bitscan

Author: Gerd Isenberg

Date: 07:49:00 12/23/05

Go up one level in this thread


>About the assembler routine being slower :
>I found that using a call by reference instead of a call by value speeds up the
>function in Delphi a great deal because you get the adress of the bitboard
>directly in the EAX register, don't know about C though but perhaps it will be
>the same or perhaps its just a thing of the Delphi compiler.


Yes, but even if the pointer is passed via a register (fastcall calling
convention in C is via ECX or EDX in 32-bit mode) your bitboard has to be in
memory - even if it is already in a register pair.

Does Delfi inline short functions? Or is it allways a function call?


>I also try to optimize performance by doing the first bitscan on the side of the
>board where the bit is most likely to occur. For example if i have to find the
>white king, the piece is most likely to be found on the white side of the board.
>That way BSF/BSR is executed only once in most cases.
>
>Here's the code
>
>function BitScanForwardBlack(var Bitboard: TBitboard): TSquare;
>// Returns the first occupied square of a bitboard,
>// scanning forward and starting with the black side of the board
>asm
>  bsf eax, [eax]
>  jnz @End
>  bsf eax, [eax+4]
>  jz @End
>  add eax, 32
>  @End:
>end;
>
>
>function BitScanReverseWhite(var Bitboard: TBitboard): TSquare;
>// Returns the first occupied square of a bitboard,
>// scanning backward and starting with the white side of the board
>asm
>  bsr eax, [eax+4]
>  jz @Black
>  add eax, 32
>  jmp @End
>  @Black:
>  bsr eax, [eax]
>  @End:
>end;
>
>
>Fred

I see - but if i like to introduce color dependent routines for bitboard
traversal, i would make them rank-symmetric but not file-symmetric - so that
black-white mirrored (including side to move changed) positions are exactly
searched in the same manner as the original position.

Another point about inline assembly - it is a kind of deprecated for msvc - it
is not longer supported for 64-bit mode. But there are intrinsic functions for
bitscanning.

Gerd



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.