From: David Rasmussen <pinkfloydhomer@yahoo.com>
To: gcc@gcc.gnu.org
Subject: Re: Number of 1's in 64 bit number...[don't read if not interested in algos/math...]
Date: Sat, 27 Apr 2002 12:44:00 -0000 [thread overview]
Message-ID: <3CCAF4CF.6090406@yahoo.com> (raw)
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;
}
next reply other threads:[~2002-04-27 18:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-27 12:44 David Rasmussen [this message]
-- strict thread matches above, loose matches on Subject: below --
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-24 21:55 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3CCAF4CF.6090406@yahoo.com \
--to=pinkfloydhomer@yahoo.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).