Author: Tim Foden
Date: 01:00:32 05/19/02
Go up one level in this thread
On May 18, 2002 at 15:48:52, Matthias Gemuh wrote:
>On May 18, 2002 at 13:52:57, Andrew Dados wrote:
>
>>On May 18, 2002 at 13:38:02, Matthias Gemuh wrote:
>>
>>>
>>>Hi Experts,
>>>I want to speed up my chess engine and need assembler versions of these
>>>functions. These below seem to be pentium-specific. I need something general
>>>and don't understand assembler.
>>>
>>>int FirstBit(BITBOARD a)
>>>{
>>> __asm {
>>> bsr edx, dword ptr a+4
>>> mov eax, 31
>>> jnz l6
>>> bsr edx, dword ptr a
>>> mov eax, 63
>>> jnz l6
>>> mov edx, -1
>>> l6: sub eax, edx
>>> }
>>>}
>>>
>>>int LastBit(BITBOARD a)
>>>{
>>> __asm {
>>> bsf edx, dword ptr a
>>> mov eax, 63
>>> jnz l7
>>> bsf edx, dword ptr a+4
>>> mov eax, 31
>>> jnz l7
>>> mov edx, -33
>>> l7: sub eax, edx
>>> }
>>>}
>>>
>>>Please, help me.
>>>
>>>Thanks,
>>>Matthias.
>>
>>Those functions will work on all i386 - compatible processors. They are as
>>general as assembler can get.
>>
>>-Andrew-
>
>
>Unfortunately, they even crash on my Athlon 1.4, compiled with BCB 5.0.
These look like the fucntions from Crafty? You need to take care, as they don't
nessesarily work as you expect, as they invert the bit numbers.
E.g. if bit 0 is set (a == 1), they will return 63.
Maybe you are expecting that if bit 0 is set, they return 0?
It is possible to write routines that do it this way round too.
These are from GLC, but as I don't use them much (I mostly use routines that not
only find a bit, but remove it too), they are probably not the fastest that is
possible (XX is a define for an invalid square, in GLC it is -1).
#pragma warning(disable: 4035) // disable warning about no return value
inline Square BitScanForward( UINT64 bitmap )
{
__asm
{
bsf eax, [bitmap]
jnz done
bsf eax, [bitmap + 4]
jz noBits
add eax, 32
jmp done
noBits:
mov eax, XX
done:
}
// value returned in eax
}
inline Square BitScanReverse( UINT64 bitmap )
{
__asm
{
bsr eax, [bitmap + 4]
jnz add32
bsr eax, [bitmap]
jnz done
mov eax, XX
jmp done
add32:
add eax, 32
done:
}
// value returned in eax
}
#pragma warning(default: 4035)
Cheers, Tim.
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.