Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Bob & Eugene: PopCnt64()

Author: Bas Hamstra

Date: 13:53:56 04/25/01

Go up one level in this thread


On April 25, 2001 at 14:53:00, Dann Corbit wrote:

>On April 25, 2001 at 14:38:48, Bas Hamstra wrote:
>
>>On April 25, 2001 at 14:31:27, Bas Hamstra wrote:
>>
>>>inline int PopCnt(BB M)
>>>{   unsigned char *p = (unsigned char*) &M;
>>>    return PopCnt8[p[0]]+PopCnt8[p[1]]+PopCnt8[p[2]]+PopCnt8[p[3]]
>>>           +PopCnt8[p[4]]+PopCnt8[p[5]]+PopCnt8[p[6]]+PopCnt8[p[7]];
>>>}
>>>
>>>Last time I tested, on my Celeron the above PopCnt was way faster than Crafty's
>>>asm version. Am I overlooking something? Maybe because my compiler refuses to
>>>inline asm statements?
>>
>>More accurately: my compiler refuses to inline functions that contain asm
>>statements.
>
>What compiler are you using?  Both Intel and Microsoft compilers will do it.  >you are using Borland, time to upgrade.  It is pathetic in comparison to any of
>the really good ones.  Sad, because it used to compete effectively.  Now you
>know why they are giving it away.

I know, but I love the interface especially the debugger. It is my work
compiler. I also have VC and my code compiles rightaway on both. VC is way
faster, but when I don't understand things, I need Borland.

>This works fairly well (which is {I suspect}) what is in your table:
>
>static int      inbits[256] = {
>    0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
>    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
>    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
>    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
>    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
>    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
>    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
>    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
>    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
>    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
>    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
>    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
>    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
>    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
>    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
>    4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
>};
>
>int             Count(const BITBOARD B)
>{
>    return inbits[(unsigned char) B] +
>    inbits[(unsigned char) (B >> 8)] +
>    inbits[(unsigned char) (B >> 16)] +
>    inbits[(unsigned char) (B >> 24)] +
>    inbits[(unsigned char) (B >> 32)] +
>    inbits[(unsigned char) (B >> 40)] +
>    inbits[(unsigned char) (B >> 48)] +
>    inbits[(unsigned char) (B >> 56)];
>}

Yes, that's how my code works as well.

>You might want to time this in comparison to your routine.  For that matter, I
>have a collection of bit counting routines found here:
>ftp://cap.connx.com/pub/bitcount/BITC.ZIP
>
>That might prove useful.  A benchmark routine is included.  They are for 32
>bits, but the techniques easily generalize to larger integers.

Thanks, I will certainly take a look because I use it all the time and I am not
quite satisfied with the current performance.

Best regards,
Bas.




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.