Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Counting Bits in BitBoard

Author: Matt Taylor

Date: 23:53:24 01/06/03

Go up one level in this thread


On January 06, 2003 at 23:25:57, Nathan Thom wrote:

>Hi all,
>
>Does anyone have a super duper algorithm to count the number of set bits in a
>64-bit number? In C, i have:
>
>int CountBits(BitBoard *b) {
>	int count=0;
>
>	while (*b) {
>		if (*b & (BitBoard)1) count++;
>		*b >>= 1;
>	}
>
>	return count;
>}
>
>But im sure it could be much faster in assembler, i just dont know how.

The algorithm you're referring to is called a population count.
AMD has an optimal assembly routine listed in their manuals.

Refer to Chapter 8.
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pdf

-Matt



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.