Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: BSF/R not working well for me...

Author: Alex Boby

Date: 11:00:17 04/24/01

Go up one level in this thread


On April 24, 2001 at 13:42:18, Tony Werten wrote:

>On April 24, 2001 at 12:52:03, Dann Corbit wrote:
>
>>On April 24, 2001 at 03:27:47, Tony Werten wrote:
>>
>>>On April 23, 2001 at 19:30:20, Alex Boby wrote:
>>>
>>>>
>>>>I used to have this:
>>>>
>>>>------------
>>>>void parseBitboard (int from, struct MoveList *ml, bitboard attack)
>>>>  {
>>>>  int i;
>>>>
>>>>  for (i=0; i<64; i++)
>>>>    {
>>>>    if (attack&mask[i])
>>>>      [add move to list]
>>>>    }
>>>>  }
>>>>------------
>>>>and got this in the profile:
>>>>7301.351   3.9    37127.739  19.6   538488 _parseBitboard (pierre.obj)
>>>>
>>>>and then, figuring I would get a significant speed increase, I switched to this:
>>>
>>>As Landon pointed out in his post, chance it to a complete assembly function.
>>>
>>>I think (might be wrong ) C++ and Delphi have the same beheavior in this. By
>>>starting a function in a high language and then using asm insisde it, you get a
>>>lot of everhead (ie if asm is not the first word in the function ), plus
>>>optimization goes nuts.
>>>
>>>The instruction "int index" makes the compiler create a stack, a result variable
>>>(instead of using registers to return the value ) and more things you don't
>>>want. This way it's virtually imposible to improve the speed.
>>
>>Inline assembly does not hurt anything.  Even if you create a stack, it is just
>>a subtraction from the stack pointer (a couple cycles).
>>
>>In this case, no index variable was needed because (by convention) most Intel
>>based C compilers expect EAX to have the return value.  So whatever is in EAX
>>when the function is done is what will be expected by the compiler for a return
>>value.
>>
>>The nice thing about using inline assembly is that you can change calling
>>conventions and it gets adjusted for you automatically.
>
>Do you mean that the code below results in the same code if you remove the index
>declaration and replace the mov index,edx by move eax,edx ?
>
>(I haven't got a C++ compiler here now so I can't test)
>
>Tony
>

I took out the local variable and didn't notice any difference in speed. I also
forced the function inline but didn't notice any difference, even though it's
being called over 3 million times :)

go leafs go


>>
>>>>
>>>>-----------------
>>>>int findBitIndex(bitboard data)
>>>>  {
>>>>  int index;
>>>>
>>>>  __asm
>>>>    {
>>>>        bsr edx, dword ptr data+4
>>>>        mov eax, 32
>>>>        jnz s1
>>>>        bsr edx, dword ptr data
>>>>        mov eax, 0
>>>>        jnz s1
>>>>        mov edx, -1
>>>>    s1:	add edx, eax
>>>>        mov index, edx
>>>>    }
>>>>
>>>>  return index;
>>>>  }
>>>>
>>>>void parseBitboard (int from, struct MoveList *ml, bitboard attack)
>>>>  {
>>>>  int index;
>>>>
>>>>  while ((index = findBitIndex(attack))!=-1)
>>>>    {
>>>>      [add move to list]
>>>>      attack -= mask[index];
>>>>    }
>>>>  }
>>>>-------------
>>>>and then got this in the profile:
>>>>    6763.331   4.4    32424.707  21.1   530420 _parseBitboard (pierre.obj)
>>>>    1313.554   0.9     1313.554   0.9  3523746 _findBitIndex (pierre.obj)
>>>>
>>>>with about a 10% drop in nodes/sec.
>>>>
>>>>I thought that BSF & BSR were supposed to be fast! What am I doing wrong?
>>>>This is on an Intel P3/500 w/ win2k.



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.