Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question for the Crafty/Compiler experts

Author: Robert Hyatt

Date: 19:57:17 02/16/04

Go up one level in this thread


On February 16, 2004 at 18:25:41, Dieter Buerssner wrote:

>On February 15, 2004 at 16:29:51, Dann Corbit wrote:
>>FORCEINLINE int PopCnt(BITBOARD a)
>>{
>> /* Because Crafty bitboards are typically sparsely populated, we use a
>>    streamlined version of the boolean.c algorithm instead of the one in x86.s
>>*/
>>  __asm {
>>                   mov ecx, dword ptr a
>>                   xor eax, eax
>>                   test ecx, ecx
>>                   jz l1
>>         l0:       lea edx, [ecx - 1]
>>                   inc eax
>>                   and ecx, edx
>>                   jnz l0
>>         l1:       mov ecx, dword ptr a + 4
>>                   test ecx, ecx
>>                   jz l3
>>         l2:       lea edx,[ecx - 1]
>>                   inc eax
>>                   and ecx, edx
>>                   jnz l2
>>         l3:}
>>}
>
>I have seen this code many times. I also commented on it many times (never got
>any answer to the point). Why would you want to code this in inline assembly? To
>me it seems, equivalent C code (possibly micro optimized fór some environment,
>but still more general than the assembly) will run faster (I showed examples
>several times - IIRC including examples of what MSVC made of the C code and some
>reasoning about not needed "mov ecx, dword ptr a" when using C).
>
>Regards,
>Dieter

I don't do the MSVC inline stuff, obviously, since I don't use windows and MSVC.
 However, the gcc inline generalized register facility seems more appropriate
for inline asm to avoid register saves and restores.  I'm not sure the PopCnt()
inline is any better than the pure C version in Crafty.  However, the FirstOne()
and LastOne() are definitely better using bsf/bsr except that the intel C
compiler Eugene is using has intrinsics that make inline not needed (only for 64
bit version of the compiler of course).




This page took 0.01 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.