public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
@ 2002-04-24 21:55 Preeti Aira
  2002-04-24 22:35 ` Alan Modra
  2002-04-24 23:08 ` Vivek Srivastava
  0 siblings, 2 replies; 14+ messages in thread
From: Preeti Aira @ 2002-04-24 21:55 UTC (permalink / raw)
  To: gcc-help, gcc

Hello every body..

Can any body give me the algo for finding number of 1's  (set bits) in a 64 
bit number. Algo with out any loop or recurson.  Should be a reasonably 
efficient and small and giving result in fixed time.

have a nice time
Pret.

_________________________________________________________________
Join the worldÂ’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
  2002-04-24 21:55 Number of 1's in 64 bit number...[don't read if not interested in algos/math...] Preeti Aira
@ 2002-04-24 22:35 ` Alan Modra
  2002-04-24 23:08 ` Vivek Srivastava
  1 sibling, 0 replies; 14+ messages in thread
From: Alan Modra @ 2002-04-24 22:35 UTC (permalink / raw)
  To: Preeti Aira; +Cc: gcc-help, gcc

On Thu, Apr 25, 2002 at 10:14:02AM +0530, Preeti Aira wrote:
> 
> Can any body give me the algo for finding number of 1's  (set bits) in a 64 
> bit number. Algo with out any loop or recurson.  Should be a reasonably 
> efficient and small and giving result in fixed time.

You can find such an algorithm in at least two places in the gcc
sources, and also in glibc.  You should be able to find it reasonably
easily using grep.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
  2002-04-24 21:55 Number of 1's in 64 bit number...[don't read if not interested in algos/math...] Preeti Aira
  2002-04-24 22:35 ` Alan Modra
@ 2002-04-24 23:08 ` Vivek Srivastava
  2002-04-24 23:51   ` Jaswant
  2002-04-25  0:39   ` Gerald Pfeifer
  1 sibling, 2 replies; 14+ messages in thread
From: Vivek Srivastava @ 2002-04-24 23:08 UTC (permalink / raw)
  To: Preeti Aira; +Cc: gcc-help, gcc

Hi Preeti,

On Thu, 25 Apr 2002, Preeti Aira wrote:
> Can any body give me the algo for finding number of 1's  (set bits) in a 64 
> bit number. Algo with out any loop or recurson.  Should be a reasonably 
> efficient and small and giving result in fixed time.

I don't know why do you ask for an algo without any loops or recursion. As 
far as I can see, it cannot be done without them. So if you're ready to 
incorporate them, here's one algo. It's probably the most efficient one 
possible because it gives the result in O(n) time, where 'n' is the number 
of 1 bits in the number. (Doesn't depend on the size of the number.) i.e. 
for both 10110000 and 0000101100000000, it will tell you that there are 3 
1's in just 3 steps.

Here's the algo:

	Let x be the given number.
	count <-- 0
	while (x > 0)
	do
	    	x <-- x AND (x - 1)
		count <-- count + 1


At the end of this loop, 'count' is the required answer. (Here, AND is the 
bitwise 'and' operator.)

Hope that helps.

Vivek

-- 
Vivek Srivastava
MCA II year
Department of Computer Science
University of Pune


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
  2002-04-24 23:08 ` Vivek Srivastava
@ 2002-04-24 23:51   ` Jaswant
  2002-04-25  0:39   ` Gerald Pfeifer
  1 sibling, 0 replies; 14+ messages in thread
From: Jaswant @ 2002-04-24 23:51 UTC (permalink / raw)
  To: Vivek Srivastava; +Cc: gcc-help, gcc

may be preeti is looking for something like algo below which finds 1's in 36
bit number:

//To count the ones in a 36-bit word:
unsigned count_ones(unsigned36 a)
{
  a = a - (a>>1 & 0333333333333);
  a = a - (a>>1 & 0333333333333);

  // Each octal digit is replaced by number of 1's in it

  a = ((a>>3) + a) & 0070707070707;
  return a % 63;    // casting out 63's
}


----- Original Message -----
From: "Vivek Srivastava" <u2000159@cs.unipune.ernet.in>
To: "Preeti Aira" <ms_preeti@hotmail.com>
Cc: <gcc-help@gcc.gnu.org>; <gcc@gcc.gnu.org>
Sent: Thursday, April 25, 2002 11:06 AM
Subject: Re: Number of 1's in 64 bit number...[don't read if not interested
in algos/math...]


> Hi Preeti,
>
> On Thu, 25 Apr 2002, Preeti Aira wrote:
> > Can any body give me the algo for finding number of 1's  (set bits) in a
64
> > bit number. Algo with out any loop or recurson.  Should be a reasonably
> > efficient and small and giving result in fixed time.
>
> I don't know why do you ask for an algo without any loops or recursion. As
> far as I can see, it cannot be done without them. So if you're ready to
> incorporate them, here's one algo. It's probably the most efficient one
> possible because it gives the result in O(n) time, where 'n' is the number
> of 1 bits in the number. (Doesn't depend on the size of the number.) i.e.
> for both 10110000 and 0000101100000000, it will tell you that there are 3
> 1's in just 3 steps.
>
> Here's the algo:
>
> Let x be the given number.
> count <-- 0
> while (x > 0)
> do
>     x <-- x AND (x - 1)
> count <-- count + 1
>
>
> At the end of this loop, 'count' is the required answer. (Here, AND is the
> bitwise 'and' operator.)
>
> Hope that helps.
>
> Vivek
>
> --
> Vivek Srivastava
> MCA II year
> Department of Computer Science
> University of Pune
>
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
  2002-04-24 23:08 ` Vivek Srivastava
  2002-04-24 23:51   ` Jaswant
@ 2002-04-25  0:39   ` Gerald Pfeifer
  1 sibling, 0 replies; 14+ messages in thread
From: Gerald Pfeifer @ 2002-04-25  0:39 UTC (permalink / raw)
  To: Vivek Srivastava; +Cc: Preeti Aira, gcc-help, gcc

On Thu, 25 Apr 2002, Vivek Srivastava wrote:
>> Can any body give me the algo for finding number of 1's  (set bits) in a 64
>> bit number. Algo with out any loop or recurson.  Should be a reasonably
>> efficient and small and giving result in fixed time.
> I don't know why do you ask for an algo without any loops or recursion. As
> far as I can see, it cannot be done without them.

Of course you can!  Any problem with bounded input size can be trivially
implemented without loops or recursion (though code size will increase
with O(...)).

However, this kind of questions is *not* the scope of this mailing list
which is about developing GCC, not developing *with* GCC!

Gerald
-- 
Gerald "Jerry" pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
@ 2002-04-27 12:44 David Rasmussen
  0 siblings, 0 replies; 14+ messages in thread
From: David Rasmussen @ 2002-04-27 12:44 UTC (permalink / raw)
  To: gcc

I'm amazed to read all these suggestions. The problem is old and 
wellknown. It is usually called Population Count or PopCount. It is used 
in several situations, but the use I know best is from bitboard-based 
chess programs. Do a search of "chess bitboard" in google, and read 
about. The lookup-table is the usual implementation if potability is 
required. There are usually faster methods on a given platform, and some 
CPU's have this as a native instruction.

In chess, the board is often relatively sparse and the following 
implementation is better overall than the lookup-table for such 
programs. It loops one time for each 1-bit:

int PopCount(unsigned long long bitboard)
{
         int count = 0;
         while(bitboard)
         {
                 ++count;
                 bitboard &= bitboard - 1;
         }
         return count;
}

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
  2002-04-25 10:13 ` Wei Qin
  2002-04-25 10:36   ` Nathan Sidwell
@ 2002-04-25 17:55   ` Daniel Berlin
  1 sibling, 0 replies; 14+ messages in thread
From: Daniel Berlin @ 2002-04-25 17:55 UTC (permalink / raw)
  To: Wei Qin; +Cc: kelley.r.cook, Preeti Aira, gcc, gcc-help

On Thu, 25 Apr 2002, Wei Qin wrote:

> 
> First, I see only 32 bits being counted. The top 32 bits seems missing.
> Second, this is a very slow implementation. A faster one can be
> implemented through table lookup. It takes no masking, no branching.

But unless your compiler does array based optimizations (which gcc 
doesn't, some do, some do and do a pretty darn good job, some don't), a 
table lookup will be slower than a parallelizable/vectorizable masking 
solution like:

#define TWO(c) (0x1u << (c)))
#define MASK(c) (((unsigned long)(-1)) / (TWO(TWO(c)) + 1u))
#define COUNT(x, c) ((x) & MASK(c)) + (((x) >> (TWO(c))) & MASK(c))))

int bitcount (long x)
{
	int i;
	for (i = 0; i < 5; i++)
	 x = COUNT (x, i);
	return x;

}

The macros are just computing the neat masks you normally see here.
Though gcc doesn't seem to turn them into constants (intel's compiler 
does) if you do it in a loop. It does if you just write out

x = COUNT (x, 0);
x = COUNT (x, 1); 
....

Add one iteration/adjust data types approriately for 64 bit 
integers.

You should be able to calculate how fast table lookup is versus the above 
by simply counting cycles.

Assume, best case, that the lookup table is in L1 cache.

See if the number of cycles required to compute the above is < (the 
L1 cache latency) * 8 + the cycles required for the moves and adds.


> /*need to generate the table yourself*/
> unsigned char mytable[256] = {0, 1, 1, 2, 1, ...};
> int count (long long x) {
> 
> 	int ret;
> 	union {
> 		long long val;
> 		unsigned char s[8];
> 	} a;
> 
> 	ret = mytable[a.s[0]];
> 	ret += mytable[a.s[1]];
> 	....
> 	ret += mytable[a.s[7]];
> 
> 	return ret;
> }
> 
> 
> On Thu, 25 Apr 2002 kelley.r.cook@gm.com wrote:
> 
> > int count (long long x) {
> >
> > int result;
> >
> > result =
> > (x & 0x00000001 ? 1 : 0) +
> > (x & 0x00000002 ? 1 : 0) +
> > (x & 0x00000004 ? 1 : 0) +
> > (x & 0x00000008 ? 1 : 0) +
> > (x & 0x00000010 ? 1 : 0) +
> > (x & 0x00000020 ? 1 : 0) +
> > (x & 0x00000040 ? 1 : 0) +
> > (x & 0x00000080 ? 1 : 0) +
> > (x & 0x00000100 ? 1 : 0) +
> > (x & 0x00000200 ? 1 : 0) +
> > (x & 0x00000400 ? 1 : 0) +
> > (x & 0x00000800 ? 1 : 0) +
> > (x & 0x00001000 ? 1 : 0) +
> > (x & 0x00002000 ? 1 : 0) +
> > (x & 0x00004000 ? 1 : 0) +
> > (x & 0x00008000 ? 1 : 0) +
> > (x & 0x00010000 ? 1 : 0) +
> > (x & 0x00020000 ? 1 : 0) +
> > (x & 0x00040000 ? 1 : 0) +
> > (x & 0x00080000 ? 1 : 0) +
> > (x & 0x00100000 ? 1 : 0) +
> > (x & 0x00200000 ? 1 : 0) +
> > (x & 0x00400000 ? 1 : 0) +
> > (x & 0x00800000 ? 1 : 0) +
> > (x & 0x01000000 ? 1 : 0) +
> > (x & 0x02000000 ? 1 : 0) +
> > (x & 0x04000000 ? 1 : 0) +
> > (x & 0x08000000 ? 1 : 0) +
> > (x & 0x10000000 ? 1 : 0) +
> > (x & 0x20000000 ? 1 : 0) +
> > (x & 0x40000000 ? 1 : 0) +
> > (x & 0x80000000 ? 1 : 0);
> > return result;
> > }
> >
> >
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in          algos/math...]
  2002-04-25 15:15       ` Richard Henderson
@ 2002-04-25 15:47         ` Wei Qin
  0 siblings, 0 replies; 14+ messages in thread
From: Wei Qin @ 2002-04-25 15:47 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc, gcc-help


We ran the popcount 10 million times to get the time. So cache is
hot. But we care about speed only when we have to run it a lot of times.
So for speed sensitive application, I would choose to use table
lookup. It's just 256 bytes anyway.

Wei

On Thu, 25 Apr 2002, Richard Henderson wrote:

> On Thu, Apr 25, 2002 at 03:12:07PM -0400, Wei Qin wrote:
> > On a x86 linux platform, it takes 80% more time than the table lookup one.
>
> On hot cache, maybe.  On cold cache the arithmetic will
> definitely be faster.
>
>
> r~
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in          algos/math...]
  2002-04-25 12:15     ` Wei Qin
@ 2002-04-25 15:15       ` Richard Henderson
  2002-04-25 15:47         ` Wei Qin
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2002-04-25 15:15 UTC (permalink / raw)
  To: Wei Qin; +Cc: nathan, kelley.r.cook, Preeti Aira, gcc, gcc-help

On Thu, Apr 25, 2002 at 03:12:07PM -0400, Wei Qin wrote:
> On a x86 linux platform, it takes 80% more time than the table lookup one.

On hot cache, maybe.  On cold cache the arithmetic will
definitely be faster.


r~

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in          algos/math...]
  2002-04-25 10:36   ` Nathan Sidwell
  2002-04-25 11:24     ` Gabriel Paubert
@ 2002-04-25 12:15     ` Wei Qin
  2002-04-25 15:15       ` Richard Henderson
  1 sibling, 1 reply; 14+ messages in thread
From: Wei Qin @ 2002-04-25 12:15 UTC (permalink / raw)
  To: nathan; +Cc: kelley.r.cook, Preeti Aira, gcc, gcc-help


This is very interesting code. A friend of mine tried it for 64bit
popcount and compared it with the tablelook up one. He inlines the
function and run the 32 bit bitson twice.
On a x86 linux platform, it takes 80% more time than the table lookup one.
I have seen some more interesting code which does

int popcount(unsigned long long x) {

#define TWO(k) (BIGONE << (k))
#define CYCL(k) (BIGNONE/(1 + (TWO(TWO(k)))))
#define BSUM(x,k) ((x)+=(x) >> TWO(k), (x) &= CYCL(k))

  x = (x & CYCL(0)) + ((x>>TWO(0)) & CYCL(0));
  x = (x & CYCL(1)) + ((x>>TWO(1)) & CYCL(1));
  BSUM(x,2);
  BSUM(x,3);
  BSUM(x,4);
  BSUM(x,5);
}

But it is even slower.


Wei


On Thu, 25 Apr 2002, Nathan Sidwell wrote:

> >
> I suspect something like...
> int bitson (unsigned long x)
> {
>   x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
>   x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
>   x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
>   x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF);
>   x = (x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF);
>   return x;
> }
> might be better (you can extend that to long long quite simply), and
> some of those later masks will be unnecessary as you can prove carry
> won't happen
>
> nathan
>
> --
> Dr Nathan Sidwell :: Computer Science Department :: Bristol University
>            The voices in my head told me to say this
> nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in           algos/math...]
  2002-04-25 10:36   ` Nathan Sidwell
@ 2002-04-25 11:24     ` Gabriel Paubert
  2002-04-25 12:15     ` Wei Qin
  1 sibling, 0 replies; 14+ messages in thread
From: Gabriel Paubert @ 2002-04-25 11:24 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: gcc

Nathan Sidwell wrote:

> Wei Qin wrote:
> 
>>First, I see only 32 bits being counted. The top 32 bits seems missing.
>>Second, this is a very slow implementation. A faster one can be
>>implemented through table lookup. It takes no masking, no branching.
>>
>>
> I suspect something like...
> int bitson (unsigned long x)
> {   
>   x = (x & 0x55555555) + ((x >> 1) & 0x55555555);


Actually the most clever way of implementing
that step that I know is:

x -= (x>>1)&0x55555555;

This happens to give the correct result for each
pair of bits.

Credit where credit is due: I found this trick on
IBM´s website in their PPC compiler writer´s guide.

	Regards,
	Gabriel.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in  algos/math...]
  2002-04-25 10:13 ` Wei Qin
@ 2002-04-25 10:36   ` Nathan Sidwell
  2002-04-25 11:24     ` Gabriel Paubert
  2002-04-25 12:15     ` Wei Qin
  2002-04-25 17:55   ` Daniel Berlin
  1 sibling, 2 replies; 14+ messages in thread
From: Nathan Sidwell @ 2002-04-25 10:36 UTC (permalink / raw)
  To: Wei Qin; +Cc: kelley.r.cook, Preeti Aira, gcc, gcc-help

Wei Qin wrote:
> 
> First, I see only 32 bits being counted. The top 32 bits seems missing.
> Second, this is a very slow implementation. A faster one can be
> implemented through table lookup. It takes no masking, no branching.
> 
I suspect something like...
int bitson (unsigned long x)
{   
  x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
  x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
  x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF);
  x = (x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF);
  return x;
}
might be better (you can extend that to long long quite simply), and
some of those later masks will be unnecessary as you can prove carry
won't happen

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
           The voices in my head told me to say this
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
  2002-04-25  9:46 kelley.r.cook
@ 2002-04-25 10:13 ` Wei Qin
  2002-04-25 10:36   ` Nathan Sidwell
  2002-04-25 17:55   ` Daniel Berlin
  0 siblings, 2 replies; 14+ messages in thread
From: Wei Qin @ 2002-04-25 10:13 UTC (permalink / raw)
  To: kelley.r.cook; +Cc: Preeti Aira, gcc, gcc-help


First, I see only 32 bits being counted. The top 32 bits seems missing.
Second, this is a very slow implementation. A faster one can be
implemented through table lookup. It takes no masking, no branching.

/*need to generate the table yourself*/
unsigned char mytable[256] = {0, 1, 1, 2, 1, ...};
int count (long long x) {

	int ret;
	union {
		long long val;
		unsigned char s[8];
	} a;

	ret = mytable[a.s[0]];
	ret += mytable[a.s[1]];
	....
	ret += mytable[a.s[7]];

	return ret;
}


On Thu, 25 Apr 2002 kelley.r.cook@gm.com wrote:

> int count (long long x) {
>
> int result;
>
> result =
> (x & 0x00000001 ? 1 : 0) +
> (x & 0x00000002 ? 1 : 0) +
> (x & 0x00000004 ? 1 : 0) +
> (x & 0x00000008 ? 1 : 0) +
> (x & 0x00000010 ? 1 : 0) +
> (x & 0x00000020 ? 1 : 0) +
> (x & 0x00000040 ? 1 : 0) +
> (x & 0x00000080 ? 1 : 0) +
> (x & 0x00000100 ? 1 : 0) +
> (x & 0x00000200 ? 1 : 0) +
> (x & 0x00000400 ? 1 : 0) +
> (x & 0x00000800 ? 1 : 0) +
> (x & 0x00001000 ? 1 : 0) +
> (x & 0x00002000 ? 1 : 0) +
> (x & 0x00004000 ? 1 : 0) +
> (x & 0x00008000 ? 1 : 0) +
> (x & 0x00010000 ? 1 : 0) +
> (x & 0x00020000 ? 1 : 0) +
> (x & 0x00040000 ? 1 : 0) +
> (x & 0x00080000 ? 1 : 0) +
> (x & 0x00100000 ? 1 : 0) +
> (x & 0x00200000 ? 1 : 0) +
> (x & 0x00400000 ? 1 : 0) +
> (x & 0x00800000 ? 1 : 0) +
> (x & 0x01000000 ? 1 : 0) +
> (x & 0x02000000 ? 1 : 0) +
> (x & 0x04000000 ? 1 : 0) +
> (x & 0x08000000 ? 1 : 0) +
> (x & 0x10000000 ? 1 : 0) +
> (x & 0x20000000 ? 1 : 0) +
> (x & 0x40000000 ? 1 : 0) +
> (x & 0x80000000 ? 1 : 0);
> return result;
> }
>
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
@ 2002-04-25  9:46 kelley.r.cook
  2002-04-25 10:13 ` Wei Qin
  0 siblings, 1 reply; 14+ messages in thread
From: kelley.r.cook @ 2002-04-25  9:46 UTC (permalink / raw)
  To: Preeti Aira, gcc, gcc-help

int count (long long x) {

int result;

result =
(x & 0x00000001 ? 1 : 0) +
(x & 0x00000002 ? 1 : 0) +
(x & 0x00000004 ? 1 : 0) +
(x & 0x00000008 ? 1 : 0) +
(x & 0x00000010 ? 1 : 0) +
(x & 0x00000020 ? 1 : 0) +
(x & 0x00000040 ? 1 : 0) +
(x & 0x00000080 ? 1 : 0) +
(x & 0x00000100 ? 1 : 0) +
(x & 0x00000200 ? 1 : 0) +
(x & 0x00000400 ? 1 : 0) +
(x & 0x00000800 ? 1 : 0) +
(x & 0x00001000 ? 1 : 0) +
(x & 0x00002000 ? 1 : 0) +
(x & 0x00004000 ? 1 : 0) +
(x & 0x00008000 ? 1 : 0) +
(x & 0x00010000 ? 1 : 0) +
(x & 0x00020000 ? 1 : 0) +
(x & 0x00040000 ? 1 : 0) +
(x & 0x00080000 ? 1 : 0) +
(x & 0x00100000 ? 1 : 0) +
(x & 0x00200000 ? 1 : 0) +
(x & 0x00400000 ? 1 : 0) +
(x & 0x00800000 ? 1 : 0) +
(x & 0x01000000 ? 1 : 0) +
(x & 0x02000000 ? 1 : 0) +
(x & 0x04000000 ? 1 : 0) +
(x & 0x08000000 ? 1 : 0) +
(x & 0x10000000 ? 1 : 0) +
(x & 0x20000000 ? 1 : 0) +
(x & 0x40000000 ? 1 : 0) +
(x & 0x80000000 ? 1 : 0);
return result;
}

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-04-27 18:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-24 21:55 Number of 1's in 64 bit number...[don't read if not interested in algos/math...] Preeti Aira
2002-04-24 22:35 ` Alan Modra
2002-04-24 23:08 ` Vivek Srivastava
2002-04-24 23:51   ` Jaswant
2002-04-25  0:39   ` Gerald Pfeifer
2002-04-25  9:46 kelley.r.cook
2002-04-25 10:13 ` Wei Qin
2002-04-25 10:36   ` Nathan Sidwell
2002-04-25 11:24     ` Gabriel Paubert
2002-04-25 12:15     ` Wei Qin
2002-04-25 15:15       ` Richard Henderson
2002-04-25 15:47         ` Wei Qin
2002-04-25 17:55   ` Daniel Berlin
2002-04-27 12:44 David Rasmussen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).