Computer Chess Club Archives




Subject: fast bit counting

Author: Flemming Rodler

Date: 19:44:25 04/18/00


I am trying to implement a bitboard based chess program on a Pentium or AMD
computer. I need to be able to find the following information fast:

1) The position of the first and/or last bit in a sequence of 64 bits.
2) Count the number of bits that are 1 in a sequence of 64 bits.

I know there is a method that works linear in the number of on-bits for
problem 2:

    for(count = 0; bitboard; count++, bitboard &= (bitboard -1));

Is there anything faster, ie. such lookuptables or machine code intrutions?

What about problem 1?

Thanks in advance for any reply

This page took 0.05 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.