Author: Gerd Isenberg
Date: 13:31:55 06/12/04
Go up one level in this thread
On June 12, 2004 at 15:40:39, Dieter Buerssner wrote:
>On June 12, 2004 at 15:25:03, Gerd Isenberg wrote:
>
>much snipped
>
>>UINT32 WalterFaxonsMagicBitscan(BitBoard &bb)
>
>>unsigned int MattTaylorsLastOne(BitBoard &bb)
>
>Gerd, did you test, whether those functions are faster without using a
>reference?
Dieter,
i guess you are right, for C++ routines it may be faster passing by value,
specially for AMD64. With inlined MSC inline assembler that doesn't matter.
Even bitboard parameter by value imply two pushes or moves to memory.
>Of course, one cannot clear the bit then. I always have the feeling,
>that using pointers (which references internally will be) makes the job for
>optimizers much more difficult. Can compilers optimize away the indirection when
>the functions are inlined? (I have only little experience with C++).
I'm not sure whether (future) compiler are able to optimize a loop passed by
reference into something similar with pure registers:
while (bb) {
DoSomething( bitScanAndReset(bb) ); // C/C++ routine, bb by ref
}
versus
while (bb) {
DoSomething( bitScan(bb) ); // C/C++ routine, bb by value
bb &= bb-1; // clear bit
}
or
while (bb) {
DoSomething( bitindex = bitScan(bb) ); // C/C++ routine, bb by value
bb ^= (BitBoard) 1 << bitindex;
}
Depending on "DoSomething" the whole thing may work in a few registers.
The final "and" may already set the zero flag to terminate the loop by "jz"
(don't ask me how good those jumps are predictable).
OTOH if the bitScan isolates the lsb anyway, it may save the later (cheap) reset
instruction, and under branch prediction considerations it may be faster to
reset the found bit earlier.
Actually i'm a bit short in time to do further "research" ;-)
Cheers,
Gerd
>
>Regards,
>Dieter
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.