Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: jsut for kicks, ehre is my popcount function

Author: Anthony Cozzie

Date: 05:54:39 12/05/03

Go up one level in this thread


On December 04, 2003 at 16:43:54, scott farrell wrote:

>this seems to work fine, but as always its a fairly big part of my eval time as
>I try to evaluate mobility of pieces to safeish squares.
>
>//this is for the count(long) method
>transient static final long ONES = 0x5555555555555555L;
>transient static final long TWOS = 0x3333333333333333L;
>transient static final int FOURS = 0x0f0f0f0f;
>
>
>// with thanks to http://www.ics.uci.edu/~eppstein/180a/projects/fanorona/
>
> public static final int count(long set) {
>	if (set ==0) return 0;
>  set = (set & ONES) + ((set >>> 1) & ONES);
>  set = (set & TWOS) + ((set >>> 2) & TWOS);
>  int result = (int) (set & 0xffffffff) + (int) (set >>> 32);
>  result = (result & FOURS) + ((result >>> 4) & FOURS);
>  return (result * 0x01010101) >>> 24;
> }
>
>Scott


actually the loop is usually faster, because most popcount bitboards are
sparsely populated.

for(i = 0; x != 0; x &= x - 1, i++) ;

anthony



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.