Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: questions about using popcount function to count bitboard

Author: Dieter Buerssner

Date: 12:47:24 01/10/03

Go up one level in this thread


On January 10, 2003 at 15:16:52, Uri Blass wrote:

>2)I tried a code of dieter and got warning from the compiler(see the bottom of
>this post for that code)
>
>warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned long ',
>possible loss of data

I consider the warning is bogus. The mask at the end guarantees, that exactly 32
bits are used, and unsigned long is at least 32 bit. So it can never lose any
data. You can get rid of the warning by some casts - but they change exactly
nothing otherwise ...

>Note that I changed
>int PopCount(unsigned long long a)
>to
>int PopCount(BitBoard a)
>
>I also have in my code
>typedef unsigned __int64 BitBoard;
>
>I also never use the word long in my program except the code that I copied from
>Dieter and I use int for 32 bit numbers.
>
>The warning was about w=
>
>int PopCount(BitBoard a)
>{
>  unsigned long w;
>  int n = 0;
>  w = a&0xffffffffUL;

   w = (unsigned long)(a&0xffffffffUL);

>  if (w)
>    do
>    {
>      n++;
>    }
>    while ((w &= w-1) != 0);
>  w = (a>>32)&0xffffffffUL;
   w = (unsigned long)((a>>32)&0xffffffffUL);
>  if (w)
>    do
>    {
>      n++;
>    }
>    while ((w &= w-1) != 0);
>  return n;
>}

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.